From f2238729f14d286aba719359e57ef28fe0b40b9b Mon Sep 17 00:00:00 2001 From: fourtf Date: Thu, 5 Jul 2018 11:42:40 +0200 Subject: [PATCH] worked on the UpdatePromptDialog --- resources/images/download_update_error.png | Bin 0 -> 332 bytes resources/resources.qrc | 1 + src/singletons/Updates.cpp | 32 +++++++++- src/singletons/Updates.hpp | 13 ++-- src/widgets/BaseWindow.cpp | 5 ++ src/widgets/BaseWindow.hpp | 3 + src/widgets/Window.cpp | 71 +++++++++++++++------ src/widgets/Window.hpp | 10 ++- src/widgets/dialogs/UpdatePromptDialog.cpp | 46 +++++++++++-- src/widgets/dialogs/UpdatePromptDialog.hpp | 15 ++++- 10 files changed, 161 insertions(+), 35 deletions(-) create mode 100644 resources/images/download_update_error.png diff --git a/resources/images/download_update_error.png b/resources/images/download_update_error.png new file mode 100644 index 0000000000000000000000000000000000000000..5c1fec1084b33cd24673c5120b8bbd51c7a78db2 GIT binary patch literal 332 zcmeAS@N?(olHy`uVBq!ia0vp^;y^6P!3HF6DQvv}q*&4&eH|GXHuiJ>Nn{1`ISV`@ ziy0XB4uLSEsD@VqP*AeOHKHUqKdq!Zu_%?HATcwqL@zJ3M8QPQK+nkVqeA9XprVtW zE{-7{-g74f@--WX9Nux{UHuimFTJX{F%jt}JzTEHi@Im$KGnO}aqy0+l;Mn{A9sbj zD6?%|ut0l}U~^=^1yP`kj>e0wj3WtRA|AiWgD{>I{T~r&HA-?zm-VD%$Tze^CcHv&}shY?Rd~T zErVD8*$MfFmnF_jJo`bjPrknOTv?&X`~}AGg>zJ1>=tk@Xxle4=eTrX?#0>s@8!1v PJ;mVZ>gTe~DWM4fwjOzE literal 0 HcmV?d00001 diff --git a/resources/resources.qrc b/resources/resources.qrc index 146c2c661..cf41c3469 100644 --- a/resources/resources.qrc +++ b/resources/resources.qrc @@ -73,6 +73,7 @@ avatars/fourtf.png avatars/pajlada.png images/download_update.png + images/download_update_error.png qt.conf diff --git a/src/singletons/Updates.cpp b/src/singletons/Updates.cpp index 4cadf2b1a..c95809390 100644 --- a/src/singletons/Updates.cpp +++ b/src/singletons/Updates.cpp @@ -141,12 +141,40 @@ void Updates::checkForUpdates() #endif } -Updates::UpdateStatus Updates::getStatus() const +Updates::Status Updates::getStatus() const { return this->status_; } -void Updates::setStatus_(UpdateStatus status) +bool Updates::shouldShowUpdateButton() const +{ + switch (this->getStatus()) { + case UpdateAvailable: + case SearchFailed: + case Downloading: + case DownloadFailed: + case WriteFileFailed: + return true; + + default: + return false; + } +} + +bool Updates::isError() const +{ + switch (this->getStatus()) { + case SearchFailed: + case DownloadFailed: + case WriteFileFailed: + return true; + + default: + return false; + } +} + +void Updates::setStatus_(Status status) { if (this->status_ != status) { this->status_ = status; diff --git a/src/singletons/Updates.hpp b/src/singletons/Updates.hpp index f760631a9..ff3df8bb5 100644 --- a/src/singletons/Updates.hpp +++ b/src/singletons/Updates.hpp @@ -10,7 +10,7 @@ class Updates Updates(); public: - enum UpdateStatus { + enum Status { None, Searching, UpdateAvailable, @@ -28,18 +28,21 @@ public: const QString &getCurrentVersion() const; const QString &getOnlineVersion() const; void installUpdates(); - UpdateStatus getStatus() const; + Status getStatus() const; - pajlada::Signals::Signal statusUpdated; + bool shouldShowUpdateButton() const; + bool isError() const; + + pajlada::Signals::Signal statusUpdated; private: QString currentVersion_; QString onlineVersion_; - UpdateStatus status_ = None; + Status status_ = None; QString updateUrl_; - void setStatus_(UpdateStatus status); + void setStatus_(Status status); }; } // namespace chatterino diff --git a/src/widgets/BaseWindow.cpp b/src/widgets/BaseWindow.cpp index c78096c5c..dfcd8b8bf 100644 --- a/src/widgets/BaseWindow.cpp +++ b/src/widgets/BaseWindow.cpp @@ -409,6 +409,11 @@ void BaseWindow::resizeEvent(QResizeEvent *) this->calcButtonsSizes(); } +void BaseWindow::closeEvent(QCloseEvent *) +{ + this->closing.invoke(); +} + void BaseWindow::moveIntoDesktopRect(QWidget *parent) { if (!this->stayInScreenRect_) diff --git a/src/widgets/BaseWindow.hpp b/src/widgets/BaseWindow.hpp index 8e6c591ea..5baf88b69 100644 --- a/src/widgets/BaseWindow.hpp +++ b/src/widgets/BaseWindow.hpp @@ -52,6 +52,8 @@ public: Flags getFlags(); + pajlada::Signals::NoArgSignal closing; + protected: virtual bool nativeEvent(const QByteArray &eventType, void *message, long *result) override; virtual void scaleChangedEvent(float) override; @@ -61,6 +63,7 @@ protected: virtual void changeEvent(QEvent *) override; virtual void leaveEvent(QEvent *) override; virtual void resizeEvent(QResizeEvent *) override; + virtual void closeEvent(QCloseEvent *) override; virtual void themeRefreshEvent() override; virtual bool event(QEvent *event) override; diff --git a/src/widgets/Window.cpp b/src/widgets/Window.cpp index 23475e9d8..5e733abb2 100644 --- a/src/widgets/Window.cpp +++ b/src/widgets/Window.cpp @@ -6,6 +6,7 @@ #include "providers/twitch/TwitchServer.hpp" #include "singletons/Settings.hpp" #include "singletons/Theme.hpp" +#include "singletons/Updates.hpp" #include "singletons/WindowManager.hpp" #include "widgets/AccountSwitchPopupWidget.hpp" #include "widgets/Notebook.hpp" @@ -53,27 +54,7 @@ Window::Window(WindowType _type) }); if (this->hasCustomWindowFrame() && _type == Window::Main) { - // settings - this->addTitleBarButton(TitleBarButton::Settings, [app] { - app->windows->showSettingsDialog(); // - }); - - // updates - auto update = this->addTitleBarButton(TitleBarButton::None, [] {}); - update->setPixmap(QPixmap(":/images/download_update.png")); - QObject::connect(update, &TitleBarButton::clicked, this, [this, update] { - auto dialog = new UpdatePromptDialog(); - dialog->setActionOnFocusLoss(BaseWindow::Delete); - dialog->move(update->mapToGlobal(QPoint(-100 * this->getScale(), update->height()))); - dialog->show(); - dialog->raise(); - }); - - // account - this->userLabel = this->addTitleBarLabel([this, app] { - app->windows->showAccountSelectPopup( - this->userLabel->mapToGlobal(this->userLabel->rect().bottomLeft())); // - }); + this->addCustomTitlebarButtons(); } if (_type == Window::Main) { @@ -194,6 +175,54 @@ Window::Window(WindowType _type) this->notebook.setShowAddButton(true); } +void Window::addCustomTitlebarButtons() +{ + // settings + this->addTitleBarButton(TitleBarButton::Settings, [] { + getApp()->windows->showSettingsDialog(); // + }); + + // updates + auto update = this->addTitleBarButton(TitleBarButton::None, [] {}); + update->hide(); + QObject::connect(update, &TitleBarButton::clicked, this, [this, update] { + auto dialog = new UpdatePromptDialog(); + dialog->setActionOnFocusLoss(BaseWindow::Delete); + dialog->move(update->mapToGlobal(QPoint(int(-100 * this->getScale()), update->height()))); + dialog->show(); + dialog->raise(); + + dialog->buttonClicked.connect([update](auto button) { + switch (button) { + case UpdatePromptDialog::Dismiss: { + update->hide(); + } break; + } + }); + + this->updateDialogHandle_.reset(dialog); + dialog->closing.connect([this] { this->updateDialogHandle_.release(); }); + }); + + auto updateChange = [update](auto) { + update->setVisible(Updates::getInstance().shouldShowUpdateButton()); + + auto imageUrl = Updates::getInstance().isError() ? ":/images/download_update_error.png" + : ":/images/download_update.png"; + update->setPixmap(QPixmap(imageUrl)); + }; + + updateChange(Updates::getInstance().getStatus()); + this->signalHolder.managedConnect(Updates::getInstance().statusUpdated, + [updateChange](auto status) { updateChange(status); }); + + // account + this->userLabel = this->addTitleBarLabel([this] { + getApp()->windows->showAccountSelectPopup( + this->userLabel->mapToGlobal(this->userLabel->rect().bottomLeft())); // + }); +} + Window::WindowType Window::getType() { return this->type; diff --git a/src/widgets/Window.hpp b/src/widgets/Window.hpp index 60bf8be8d..60ce046cd 100644 --- a/src/widgets/Window.hpp +++ b/src/widgets/Window.hpp @@ -10,10 +10,12 @@ #include #include +#include namespace chatterino { class Theme; +class UpdatePromptDialog; class Window : public BaseWindow { @@ -40,15 +42,19 @@ protected: bool event(QEvent *event) override; private: + void addCustomTitlebarButtons(); + void loadGeometry(); + RippleEffectLabel *userLabel = nullptr; + std::unique_ptr updateDialogHandle_; WindowType type; float dpi; - void loadGeometry(); - SplitNotebook notebook; + pajlada::Signals::SignalHolder signalHolder; + friend class Notebook; public: diff --git a/src/widgets/dialogs/UpdatePromptDialog.cpp b/src/widgets/dialogs/UpdatePromptDialog.cpp index 2cc4df2ae..a8b36c388 100644 --- a/src/widgets/dialogs/UpdatePromptDialog.cpp +++ b/src/widgets/dialogs/UpdatePromptDialog.cpp @@ -1,5 +1,6 @@ #include "UpdatePromptDialog.hpp" +#include "singletons/Updates.hpp" #include "util/LayoutCreator.hpp" #include "widgets/Label.hpp" @@ -15,16 +16,53 @@ UpdatePromptDialog::UpdatePromptDialog() { auto layout = LayoutCreator(this).setLayoutType(); - layout.emplace