From 4c718e33e9a0556ba9bc3be730359167d960c395 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jaakko=20Kera=CC=88nen?= Date: Mon, 30 Jul 2018 10:22:47 +0300 Subject: [PATCH] Client|Refactor: Revising the Updater --- doomsday/apps/client/include/updater.h | 8 -- doomsday/apps/client/src/updater/updater.cpp | 86 +++++++++++++------- doomsday/libs/gui/src/guiapp.cpp | 6 +- 3 files changed, 58 insertions(+), 42 deletions(-) diff --git a/doomsday/apps/client/include/updater.h b/doomsday/apps/client/include/updater.h index fc658dd3c2..ddd198589b 100644 --- a/doomsday/apps/client/include/updater.h +++ b/doomsday/apps/client/include/updater.h @@ -58,11 +58,6 @@ class Updater de::ProgressWidget &progress(); -// void gotReply(QNetworkReply *); -// void downloadProgressed(int percentage); -// void downloadCompleted(int result); -// void downloadFailed(QString); - void recheck(); /** @@ -88,9 +83,6 @@ class Updater */ void printLastUpdated(); -//protected slots: -// void downloadDialogClosed(); - private: DE_PRIVATE(d) }; diff --git a/doomsday/apps/client/src/updater/updater.cpp b/doomsday/apps/client/src/updater/updater.cpp index 6628d46c27..eec5e728df 100644 --- a/doomsday/apps/client/src/updater/updater.cpp +++ b/doomsday/apps/client/src/updater/updater.cpp @@ -9,7 +9,7 @@ * replaced with the engine's own (scriptable) UI widgets (once they are * available). * - * @authors Copyright © 2012-2017 Jaakko Keränen + * @authors Copyright © 2012-2018 Jaakko Keränen * @authors Copyright © 2013 Daniel Swanson * * @par License @@ -27,13 +27,6 @@ * 02110-1301 USA */ -//#include -//#include -//#include -//#include -//#include -//#include - #include "de_platform.h" #ifdef WIN32 @@ -46,6 +39,7 @@ #include "dd_def.h" #include "dd_types.h" #include "dd_main.h" +#include "network/net_main.h" #include "clientapp.h" #include "ui/nativeui.h" #include "ui/clientwindowsystem.h" @@ -63,8 +57,8 @@ #include #include #include -//#include #include +#include #include #include @@ -83,11 +77,11 @@ static CommandLine* installerCommand; */ static void runInstallerCommand(void) { - DE_ASSERT(installerCommand != 0); + DE_ASSERT(installerCommand != nullptr); installerCommand->execute(); delete installerCommand; - installerCommand = 0; + installerCommand = nullptr; } /** @@ -120,6 +114,8 @@ class UpdaterStatusWidget : public ProgressWidget add(_clickable); } + virtual ~UpdaterStatusWidget() = default; + void showIcon(DotPath const &path) { _icon->setImageColor(ClientApp::windowSystem().style().colors().colorf(path)); @@ -142,8 +138,10 @@ class UpdaterStatusWidget : public ProgressWidget DE_PIMPL(Updater) , DE_OBSERVES(App, StartupComplete) +, DE_OBSERVES(WebRequest, Progress) +, DE_OBSERVES(WebRequest, Finished) { -// QNetworkAccessManager *network = nullptr; + WebRequest web; UpdateDownloadDialog *download = nullptr; // not owned (in the widget tree, if exists) UniqueWidgetPtr status; UpdateAvailableDialog *availableDlg = nullptr; ///< If currently open (not owned). @@ -157,7 +155,9 @@ DE_PIMPL(Updater) Impl(Public *i) : Base(i) { -// network = new QNetworkAccessManager(thisPublic); + web.setUserAgent(Net_UserAgent()); + web.audienceForProgress() += this; + web.audienceForFinished() += this; // Delete a package installed earlier? UpdaterSettings st; @@ -177,6 +177,18 @@ DE_PIMPL(Updater) st.setPathToDeleteAtStartup(""); } + void webRequestProgress(WebRequest &, dsize current, dsize total) override + { + DE_ASSERT(status); + status->setRange(Rangei(0, 100)); + if (total) status->setProgress(current / total); + } + + void webRequestFinished(WebRequest &) override + { + + } + void setupUI() { status.reset(new UpdaterStatusWidget); @@ -241,7 +253,7 @@ DE_PIMPL(Updater) return false; } - void appStartupCompleted() + void appStartupCompleted() override { LOG_AS("Updater") LOG_DEBUG("App startup was completed"); @@ -383,7 +395,7 @@ DE_PIMPL(Updater) void execAvailableDialog() { - DE_ASSERT(availableDlg != 0); + DE_ASSERT(availableDlg != nullptr); availableDlg->setDeleteAfterDismissed(true); availableDlg->audienceForRecheck() += [this]() { self().recheck(); }; @@ -393,7 +405,7 @@ DE_PIMPL(Updater) startDownload(); download->open(); } - availableDlg = 0; + availableDlg = nullptr; } void startDownload() @@ -406,6 +418,17 @@ DE_PIMPL(Updater) LOG_MSG("Download and install update"); download = new UpdateDownloadDialog(latestPackageUri, latestPackageUri2); + download->audienceForClose() += [this]() { + if (!download || download->isFailed()) + { + if (download) + { + download->setDeleteAfterDismissed(true); + download = nullptr; + } + showNotification(false); + } + }; status->popupButton().setPopup(*download, ui::Down); // download->audienceForClose() += [this]() { self().downloadDialogClosed(); } // download->audienceForAccept() += [this]() { self().downloadCompleted(1); }; @@ -416,6 +439,22 @@ DE_PIMPL(Updater) ClientWindow::main().root().addOnTop(download); } +#if 0 + void downloadDialogClosed() +// void panelBeingClosed(PanelWidget &) + { + if (!d->download || d->download->isFailed()) + { + if (d->download) + { + d->download->setDeleteAfterDismissed(true); + d->download = 0; + } + d->showNotification(false); + } + } +#endif + /** * Starts the installation process using the provided distribution package. * The engine is first shut down gracefully (game has already been autosaved). @@ -655,18 +694,3 @@ void Updater::printLastUpdated(void) LOG_MSG("Latest update check was made %s") << ago; } } - -#if 0 -void Updater::downloadDialogClosed() -{ - if (!d->download || d->download->isFailed()) - { - if (d->download) - { - d->download->setDeleteAfterDismissed(true); - d->download = 0; - } - d->showNotification(false); - } -} -#endif diff --git a/doomsday/libs/gui/src/guiapp.cpp b/doomsday/libs/gui/src/guiapp.cpp index 0d44306004..797031aff9 100644 --- a/doomsday/libs/gui/src/guiapp.cpp +++ b/doomsday/libs/gui/src/guiapp.cpp @@ -275,8 +275,8 @@ void GuiApp::revealFile(const NativePath &fileOrFolder) // static #if defined (MACOSX) { using namespace std; - - const NativePath scriptPath = cachePath() / "reveal_path.scpt"; + + const NativePath scriptPath = cachePath() / "reveal-path.scpt"; if (ofstream f{scriptPath.toStdString()}) { // Apple Script to select a specific file. @@ -287,7 +287,7 @@ void GuiApp::revealFile(const NativePath &fileOrFolder) // static << " end tell" << endl << "end run" << endl; f.close(); - + CommandLine{{"/usr/bin/osascript", scriptPath, fileOrFolder}}.execute(); } }