Do packagedb::prep() in ChooserPage::OnActivate(), as doing it in OnInit() is wrong, as that only gets called once (but lazily).
Make packagedb::prep() idempotent after packagedb::init(), so it doesn't do it's work again, if we come back to chooser from a later page. Re-arrange applying command line package selection, and determining the initial solution, which should only happen once, but after packagedb::prep() --- choose.cc | 81 +++++++++++++++++++++++++++++++++-------------------------- choose.h | 3 +++ package_db.cc | 30 ++++++++++++++++++++++ package_db.h | 23 +++++++++++------ 4 files changed, 93 insertions(+), 44 deletions(-) diff --git a/choose.cc b/choose.cc index 3a990d5..00e5977 100644 --- a/choose.cc +++ b/choose.cc @@ -61,7 +61,6 @@ static BoolOption UpgradeAlsoOption (false, 'g', "upgrade-also", "also upgrade i static BoolOption CleanOrphansOption (false, 'o', "delete-orphans", "remove orphaned packages"); static BoolOption ForceCurrentOption (false, 'f', "force-current", "select the current version for all packages"); static BoolOption PruneInstallOption (false, 'Y', "prune-install", "prune the installation to only the requested packages"); -static BoolOption MirrorOption (false, 'm', "mirror-mode", "Skip availability check when installing from local directory (requires local directory to be clean mirror!)"); using namespace std; @@ -89,7 +88,7 @@ static ControlAdjuster::ControlInfo ChooserControlsInfo[] = { ChooserPage::ChooserPage () : cmd_show_set (false), saved_geom (false), saw_geom_change (false), - timer_id (DEFAULT_TIMER_ID) + timer_id (DEFAULT_TIMER_ID), activated (false) { sizeProcessor.AddControlInfo (ChooserControlsInfo); @@ -150,7 +149,12 @@ ChooserPage::createListview () chooser->setViewMode (!is_new_install || UpgradeAlsoOption || hasManualSelections ? PickView::views::PackagePending : PickView::views::Category); SendMessage (GetDlgItem (IDC_CHOOSE_VIEW), CB_SETCURSEL, (WPARAM)chooser->getViewMode(), 0); + ClearBusy (); +} +void +ChooserPage::initialUpdateState() +{ // set the initial update state if (ForceCurrentOption) { @@ -171,8 +175,6 @@ ChooserPage::createListview () static int ta[] = { IDC_CHOOSE_KEEP, IDC_CHOOSE_BEST, IDC_CHOOSE_SYNC, 0 }; rbset (GetHWND (), ta, update_mode_id); - - ClearBusy (); } /* TODO: review ::overrides for possible consolidation */ @@ -263,20 +265,30 @@ ChooserPage::OnInit () SendMessage(viewlist, CB_ADDSTRING, 0, (LPARAM)PickView::mode_caption((PickView::views)view)); } - SetBusy (); - packagedb db; - db.makeBase(); - db.read(); - db.upgrade(); - db.fixup_source_package_ids(); - db.removeEmptyCategories(); + if (source == IDC_SOURCE_DOWNLOAD) + setPrompt("Select packages to download "); + else + setPrompt("Select packages to install "); - if (source == IDC_SOURCE_DOWNLOAD || source == IDC_SOURCE_LOCALDIR) - packagemeta::ScanDownloadedFiles (MirrorOption); + createListview (); - db.setExistence (); - db.fillMissingCategory (); + AddTooltip (IDC_CHOOSE_KEEP, IDS_TRUSTKEEP_TOOLTIP); + AddTooltip (IDC_CHOOSE_BEST, IDS_TRUSTCURR_TOOLTIP); + AddTooltip (IDC_CHOOSE_SYNC, IDS_TRUSTSYNC_TOOLTIP); + AddTooltip (IDC_CHOOSE_EXP, IDS_TRUSTEXP_TOOLTIP); + AddTooltip (IDC_CHOOSE_VIEW, IDS_VIEWBUTTON_TOOLTIP); + AddTooltip (IDC_CHOOSE_HIDE, IDS_HIDEOBS_TOOLTIP); + AddTooltip (IDC_CHOOSE_SEARCH_EDIT, IDS_SEARCH_TOOLTIP); + + /* Set focus to search edittext control. */ + PostMessage (GetHWND (), WM_NEXTDLGCTL, + (WPARAM) GetDlgItem (IDC_CHOOSE_SEARCH_EDIT), TRUE); +} +void +ChooserPage::applyCommandLinePackageSelection() +{ + packagedb db; for (packagedb::packagecollection::iterator i = db.packages.begin (); i != db.packages.end (); ++i) { @@ -303,32 +315,29 @@ ChooserPage::OnInit () else pkg.set_action (packagemeta::Default_action, pkg.installed); } - - ClearBusy (); - - if (source == IDC_SOURCE_DOWNLOAD) - setPrompt("Select packages to download "); - else - setPrompt("Select packages to install "); - createListview (); - - AddTooltip (IDC_CHOOSE_KEEP, IDS_TRUSTKEEP_TOOLTIP); - AddTooltip (IDC_CHOOSE_BEST, IDS_TRUSTCURR_TOOLTIP); - AddTooltip (IDC_CHOOSE_SYNC, IDS_TRUSTSYNC_TOOLTIP); - AddTooltip (IDC_CHOOSE_EXP, IDS_TRUSTEXP_TOOLTIP); - AddTooltip (IDC_CHOOSE_VIEW, IDS_VIEWBUTTON_TOOLTIP); - AddTooltip (IDC_CHOOSE_HIDE, IDS_HIDEOBS_TOOLTIP); - AddTooltip (IDC_CHOOSE_SEARCH_EDIT, IDS_SEARCH_TOOLTIP); - - /* Set focus to search edittext control. */ - PostMessage (GetHWND (), WM_NEXTDLGCTL, - (WPARAM) GetDlgItem (IDC_CHOOSE_SEARCH_EDIT), TRUE); } void ChooserPage::OnActivate() { - chooser->refresh();; + SetBusy(); + + packagedb db; + db.prep(); + + if (!activated) + { + // Do things which should only happen once, but rely on packagedb being + // ready to use, so OnInit() is too early + applyCommandLinePackageSelection(); + initialUpdateState(); + + activated = true; + } + + ClearBusy(); + + chooser->refresh(); PlaceDialog (true); } diff --git a/choose.h b/choose.h index 6839b0b..32a1650 100644 --- a/choose.h +++ b/choose.h @@ -59,6 +59,8 @@ private: void logResults(); void setPrompt(char const *aPrompt); void PlaceDialog (bool); + void applyCommandLinePackageSelection(); + void initialUpdateState(); PickView *chooser; static HWND ins_dialog; @@ -74,6 +76,7 @@ private: UINT wpi[sizeof (WINDOWPLACEMENT) / sizeof (UINT)]; }; int update_mode_id; + bool activated; }; #endif /* SETUP_CHOOSE_H */ diff --git a/package_db.cc b/package_db.cc index 8fbec44..92fe4f9 100644 --- a/package_db.cc +++ b/package_db.cc @@ -40,6 +40,9 @@ #include "resource.h" #include "libsolv.h" #include "csu_util/version_compare.h" +#include "getopt++/BoolOption.h" + +static BoolOption MirrorOption (false, 'm', "mirror-mode", "Skip availability check when installing from local directory (requires local directory to be clean mirror!)"); using namespace std; @@ -52,6 +55,8 @@ packagedb::init () { installeddbread = 0; installeddbver = 0; + prepped = false; + packages.clear(); sourcePackages.clear(); categories.clear(); @@ -382,6 +387,7 @@ packagedb::findSourceVersion (PackageSpecification const &spec) const int packagedb::installeddbread = 0; int packagedb::installeddbver = 0; +bool packagedb::prepped = false; packagedb::packagecollection packagedb::packages; packagedb::categoriesType packagedb::categories; packagedb::packagecollection packagedb::sourcePackages; @@ -717,3 +723,27 @@ packagedb::fixup_source_package_ids() } } } + +void +packagedb::prep() +{ + /* make packagedb ready for use for chooser */ + if (prepped) + return; + + makeBase(); + read(); + upgrade(); + fixup_source_package_ids(); + removeEmptyCategories(); + + /* XXX: this needs to be broken out somewhere where it can do progress + reporting, as it can take a long time... */ + if (source == IDC_SOURCE_DOWNLOAD || source ==IDC_SOURCE_LOCALDIR) + packagemeta::ScanDownloadedFiles (MirrorOption); + + setExistence (); + fillMissingCategory (); + + prepped = true; +} diff --git a/package_db.h b/package_db.h index a26c387..e500e4b 100644 --- a/package_db.h +++ b/package_db.h @@ -65,24 +65,21 @@ class packagedb public: packagedb (); void init(); - void read(); - void makeBase(); /* 0 on success */ int flush (); - void upgrade (); + void prep(); + packagemeta * findBinary (PackageSpecification const &) const; packageversion findBinaryVersion (PackageSpecification const &) const; packagemeta * findSource (PackageSpecification const &) const; packageversion findSourceVersion (PackageSpecification const &spec) const; packagemeta * addBinary (const std::string &pkgname, const SolverPool::addPackageData &pkgdata); packageversion addSource (const std::string &pkgname, const SolverPool::addPackageData &pkgdata); - void fixup_source_package_ids(); + PackageDBConnectedIterator connectedBegin(); PackageDBConnectedIterator connectedEnd(); - void fillMissingCategory(); + void defaultTrust (SolverTasks &q, SolverSolution::updateMode mode, bool test); - void setExistence(); - void removeEmptyCategories(); typedef std::map <std::string, packagemeta *> packagecollection; /* all seen binary packages */ @@ -100,11 +97,21 @@ public: static SolverSolution solution; private: + void makeBase(); + void read(); + void upgrade (); + void fixup_source_package_ids(); + void removeEmptyCategories(); + void fillMissingCategory(); + void setExistence(); + void guessUserPicked(void); + static int installeddbread; /* do we have to reread this */ static int installeddbver; + static bool prepped; + friend class ConnectedLoopFinder; static std::vector <packagemeta *> dependencyOrderedPackages; - void guessUserPicked(void); }; #endif /* SETUP_PACKAGE_DB_H */ -- 2.15.0