From c8d8d72abc4324629d0531a3d68358909103a71a Mon Sep 17 00:00:00 2001 From: twanvl Date: Sat, 31 May 2008 14:36:23 +0000 Subject: [PATCH] PackagesWindow can show just the packages from an installer. git-svn-id: svn://svn.code.sf.net/p/magicseteditor/code/trunk@905 0fc631ac-6414-0410-93d0-97cfa31319b6 --- src/data/installer.cpp | 6 ++++ src/gui/control/tree_list.cpp | 9 ++++++ src/gui/control/tree_list.hpp | 2 ++ src/gui/package_update_list.cpp | 7 +++-- src/gui/package_update_list.hpp | 5 +++- src/gui/packages_window.cpp | 51 ++++++++++++++++++++++----------- src/gui/packages_window.hpp | 8 ++++-- src/gui/welcome_window.cpp | 8 ------ src/main.cpp | 8 +++++- src/util/io/package.hpp | 10 +++++++ 10 files changed, 82 insertions(+), 32 deletions(-) diff --git a/src/data/installer.cpp b/src/data/installer.cpp index 3e00eba3..bf383c50 100644 --- a/src/data/installer.cpp +++ b/src/data/installer.cpp @@ -246,6 +246,12 @@ IMPLEMENT_REFLECTION_NO_SCRIPT(DownloadableInstaller) { REFLECT(packages); } +DownloadableInstaller::DownloadableInstaller(const InstallerP& installer) + : installer(installer) + , downloadable(false) + , packages(installer->packages) +{} + DownloadableInstaller::~DownloadableInstaller() { if (!installer_file.empty()) { wxRemoveFile(installer_file); diff --git a/src/gui/control/tree_list.cpp b/src/gui/control/tree_list.cpp index 1165233c..92ffad17 100644 --- a/src/gui/control/tree_list.cpp +++ b/src/gui/control/tree_list.cpp @@ -34,6 +34,15 @@ void TreeList::expand(size_t item, bool expand) { } } +void TreeList::expandAll(bool expand) { + for (size_t item = 0 ; item < items.size() ; ++item) { + if (hasChildren(item)) { + items[item]->expanded = expand; + } + } + rebuild(false); +} + void TreeList::select(size_t item, bool event) { if (item >= items.size() || selection == item) return; // select diff --git a/src/gui/control/tree_list.hpp b/src/gui/control/tree_list.hpp index 0031db4e..0288bb48 100644 --- a/src/gui/control/tree_list.hpp +++ b/src/gui/control/tree_list.hpp @@ -21,6 +21,8 @@ class TreeList : public wxPanel { /// Expand/collapse an item void expand(size_t item, bool expand = true); + /// Expand/collapse all items + void expandAll(bool expand = true); /// Select an item void select(size_t item, bool event = true); diff --git a/src/gui/package_update_list.cpp b/src/gui/package_update_list.cpp index f4859f1e..9c3867c3 100644 --- a/src/gui/package_update_list.cpp +++ b/src/gui/package_update_list.cpp @@ -189,8 +189,9 @@ class PackageIconRequest : public ThumbnailRequest { // ----------------------------------------------------------------------------- : PackageUpdateList : implementation -PackageUpdateList::PackageUpdateList(Window* parent, const InstallablePackages& packages, int id) +PackageUpdateList::PackageUpdateList(Window* parent, const InstallablePackages& packages, bool show_only_installable, int id) : TreeList(parent, id) + , show_only_installable(show_only_installable) , packages(packages) { item_height = max(item_height,17); @@ -206,7 +207,9 @@ void PackageUpdateList::initItems() { FOR_EACH_CONST(ip, packages) { String group = ip->description->installer_group; if (group.empty()) group = _("custom"); - root.add(ip, group); + if (!show_only_installable || ip->installer) { + root.add(ip, group); + } } // tree to treelist items items.clear(); diff --git a/src/gui/package_update_list.hpp b/src/gui/package_update_list.hpp index e9390fa9..7c45c7b3 100644 --- a/src/gui/package_update_list.hpp +++ b/src/gui/package_update_list.hpp @@ -18,7 +18,7 @@ /// A list of installed and downloadable packages class PackageUpdateList : public TreeList { public: - PackageUpdateList(Window* parent, const InstallablePackages& packages, int id = wxID_ANY); + PackageUpdateList(Window* parent, const InstallablePackages& packages, bool show_only_installable, int id = wxID_ANY); ~PackageUpdateList(); inline InstallablePackageP getSelection() const { @@ -39,7 +39,10 @@ class PackageUpdateList : public TreeList { virtual int columnWidth(size_t column) const; private: + /// The list of packages we are displaying const InstallablePackages& packages; + /// Show only packages with an installer? + bool show_only_installable; class TreeItem; public: diff --git a/src/gui/packages_window.cpp b/src/gui/packages_window.cpp index 8977ed95..00350a19 100644 --- a/src/gui/packages_window.cpp +++ b/src/gui/packages_window.cpp @@ -48,8 +48,8 @@ class DownloadableInstallerList { public: DownloadableInstallerList() : status(NONE) {} - /// are we done? if not, start downloading - bool done(); + /// start downloading, return true if we are done + bool download(); vector installers; @@ -65,7 +65,7 @@ class DownloadableInstallerList { /// The global installer downloader DownloadableInstallerList downloadable_installers; -bool DownloadableInstallerList::done() { +bool DownloadableInstallerList::download() { if (status == DONE) return true; if (status == NONE) { status = DOWNLOADING; @@ -157,12 +157,29 @@ END_EVENT_TABLE() // ----------------------------------------------------------------------------- : PackagesWindow PackagesWindow::PackagesWindow(Window* parent, bool download_package_list) - : wxDialog(parent, wxID_ANY, _TITLE_("packages window"), wxDefaultPosition, wxSize(640,480), wxDEFAULT_DIALOG_STYLE | wxCLIP_CHILDREN | wxRESIZE_BORDER) - , where(is_install_local(settings.install_type) ? PACKAGE_LOCAL : PACKAGE_GLOBAL) - , waiting_for_list(download_package_list) + : waiting_for_list(download_package_list) { // request download before searching disk so we do two things at once - if (download_package_list) downloadable_installers.done(); + if (download_package_list) downloadable_installers.download(); + init(parent, false); +} +PackagesWindow::PackagesWindow(Window* parent, const InstallerP& installer) + : waiting_for_list(false) +{ + init(parent, true); + // add installer + merge(installable_packages, new_intrusive1(installer)); + // TODO: mark all packages in the installer for installation + // update window + package_list->rebuild(); + package_list->expandAll(); + UpdateWindowUI(wxUPDATE_UI_RECURSE); +} + +void PackagesWindow::init(Window* parent, bool show_only_installable) { + where = is_install_local(settings.install_type) ? PACKAGE_LOCAL : PACKAGE_GLOBAL; + Create(parent, wxID_ANY, _TITLE_("packages window"), wxDefaultPosition, wxSize(640,480), wxDEFAULT_DIALOG_STYLE | wxCLIP_CHILDREN | wxRESIZE_BORDER); + // get packages wxBusyCursor busy; packages.installedPackages(installable_packages); @@ -171,7 +188,7 @@ PackagesWindow::PackagesWindow(Window* parent, bool download_package_list) // ui elements SetIcon(wxIcon()); - package_list = new PackageUpdateList(this, installable_packages, ID_PACKAGE_LIST); + package_list = new PackageUpdateList(this, installable_packages, show_only_installable, ID_PACKAGE_LIST); package_info = new PackageInfoPanel(this); //wxToolbar* buttons = new wxToolbar @@ -231,18 +248,18 @@ void PackagesWindow::onOk(wxCommandEvent& ev) { int total = (int)installable_packages.size(); wxProgressDialog progress( _TITLE_("installing updates"), - String::Format(_ERROR_("downloading updates"), 0, 2*total), - total, + String::Format(_ERROR_("downloading updates"), 0, total), + 2*total, this, wxPD_AUTO_HIDE | wxPD_APP_MODAL | wxPD_CAN_ABORT | wxPD_SMOOTH ); // Clear package list packages.reset(); // Download installers - int n = 0; + int package_pos = 0, progress = 0; FOR_EACH(ip, installable_packages) { - ++n; - if (!progress.Update(n, String::Format(_ERROR_("downloading updates"), n, total))) { + ++package_pos; ++progress; + if (!progress.Update(progress, String::Format(_ERROR_("downloading updates"), package_pos, total))) { return; // aborted } if ((ip->action & PACKAGE_INSTALL) && ip->installer && !ip->installer->installer) { @@ -262,10 +279,10 @@ void PackagesWindow::onOk(wxCommandEvent& ev) { } } // Install stuff - int n2 = 0 ; + package_pos = 0 ; FOR_EACH(ip, installable_packages) { - ++n; ++n2; - if (!progress.Update(n, String::Format(_ERROR_("installing updates"), n2, total))) { + ++package_pos; ++progress; + if (!progress.Update(progress, String::Format(_ERROR_("installing updates"), package_pos, total))) { // don't allow abort. } packages.install(*ip); @@ -303,7 +320,7 @@ void PackagesWindow::onIdle(wxIdleEvent& ev) { bool PackagesWindow::checkInstallerList(bool refresh) { if (!waiting_for_list) return true; - if (!downloadable_installers.done()) return false; + if (!downloadable_installers.download()) return false; waiting_for_list = false; // merge installer lists FOR_EACH(inst, downloadable_installers.installers) { diff --git a/src/gui/packages_window.hpp b/src/gui/packages_window.hpp index a3afc306..282ef0f5 100644 --- a/src/gui/packages_window.hpp +++ b/src/gui/packages_window.hpp @@ -26,13 +26,12 @@ class PackagesWindow : public wxDialog { PackagesWindow(Window* parent, const InstallerP& installer); ~PackagesWindow(); - /// List of the packages shown in this window - InstallablePackages installable_packages; - private: PackageUpdateList* package_list; ///< List of available packages PackageInfoPanel* package_info; ///< Description of the selected package + /// List of the packages shown in this window + InstallablePackages installable_packages; InstallablePackageP package; ///< Selected package PackageAction where; ///< Where to install? (PACKAGE_LOCAL or PACKAGE_GLOBAL) @@ -46,6 +45,9 @@ class PackagesWindow : public wxDialog { void onUpdateUI(wxUpdateUIEvent&); void onIdle(wxIdleEvent&); + /// Window initialization + void init(Window* parent, bool show_only_installable); + /// Check whether we have downloaded the list of installers /** If the download is (partially) complete, update the installable_packages list */ bool checkInstallerList(bool refresh = true); diff --git a/src/gui/welcome_window.cpp b/src/gui/welcome_window.cpp index 43644630..8a7db7b1 100644 --- a/src/gui/welcome_window.cpp +++ b/src/gui/welcome_window.cpp @@ -99,14 +99,6 @@ void WelcomeWindow::onNewSet(wxCommandEvent&) { close(new_set_window(this)); } -// TODO: MOVEME -template -intrusive_ptr open_package(const String& filename) { - intrusive_ptr package(new T); - package->open(filename); - return package; -} - void WelcomeWindow::onOpenLast(wxCommandEvent&) { wxBusyCursor wait; assert(!settings.recent_sets.empty()); diff --git a/src/main.cpp b/src/main.cpp index fb4b11ad..008a80fb 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -17,6 +17,7 @@ #include #include #include +#include #include #include #include @@ -108,8 +109,13 @@ int MSE::OnRun() { parse_enum(String(argv[2]).substr(2), type); } } -//%%% Installer::installFrom(argv[1], true, isInstallLocal(type)); + InstallerP installer = open_package(argv[1]); + PackagesWindow wnd(nullptr, installer); + wnd.ShowModal(); + //return wxApp::OnRun(); return EXIT_SUCCESS; +//%%% Installer::installFrom(argv[1], true, isInstallLocal(type)); +//%%% return EXIT_SUCCESS; } else if (arg == _("--symbol-editor")) { Window* wnd = new SymbolWindow(nullptr); wnd->Show(); diff --git a/src/util/io/package.hpp b/src/util/io/package.hpp index b730cdee..55488a9e 100644 --- a/src/util/io/package.hpp +++ b/src/util/io/package.hpp @@ -247,5 +247,15 @@ class IncludePackage : public Packaged { DECLARE_REFLECTION(); }; +// ----------------------------------------------------------------------------- : Utility + +/// Open a package with the given filename +template +intrusive_ptr open_package(const String& filename) { + intrusive_ptr package(new T); + package->open(filename); + return package; +} + // ----------------------------------------------------------------------------- : EOF #endif