Commit 423de114 authored by twanvl's avatar twanvl

PackagesWindow can show just the packages from an installer.

parent 08a8ca10
......@@ -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);
......
......@@ -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
......
......@@ -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);
......
......@@ -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();
......
......@@ -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:
......
......@@ -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<DownloadableInstallerP> 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<DownloadableInstaller>(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) {
......
......@@ -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);
......
......@@ -99,14 +99,6 @@ void WelcomeWindow::onNewSet(wxCommandEvent&) {
close(new_set_window(this));
}
// TODO: MOVEME
template <typename T>
intrusive_ptr<T> open_package(const String& filename) {
intrusive_ptr<T> package(new T);
package->open(filename);
return package;
}
void WelcomeWindow::onOpenLast(wxCommandEvent&) {
wxBusyCursor wait;
assert(!settings.recent_sets.empty());
......
......@@ -17,6 +17,7 @@
#include <gui/welcome_window.hpp>
#include <gui/update_checker.hpp>
#include <gui/images_export_window.hpp>
#include <gui/packages_window.hpp>
#include <gui/set/window.hpp>
#include <gui/symbol/window.hpp>
#include <gui/thumbnail_thread.hpp>
......@@ -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<Installer>(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();
......
......@@ -247,5 +247,15 @@ class IncludePackage : public Packaged {
DECLARE_REFLECTION();
};
// ----------------------------------------------------------------------------- : Utility
/// Open a package with the given filename
template <typename T>
intrusive_ptr<T> open_package(const String& filename) {
intrusive_ptr<T> package(new T);
package->open(filename);
return package;
}
// ----------------------------------------------------------------------------- : EOF
#endif
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment