worked on the UpdatePromptDialog

This commit is contained in:
fourtf 2018-07-05 11:42:40 +02:00
parent f02a89690e
commit f2238729f1
10 changed files with 161 additions and 35 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 332 B

View file

@ -73,6 +73,7 @@
<file>avatars/fourtf.png</file> <file>avatars/fourtf.png</file>
<file>avatars/pajlada.png</file> <file>avatars/pajlada.png</file>
<file>images/download_update.png</file> <file>images/download_update.png</file>
<file>images/download_update_error.png</file>
</qresource> </qresource>
<qresource prefix="/qt/etc"> <qresource prefix="/qt/etc">
<file>qt.conf</file> <file>qt.conf</file>

View file

@ -141,12 +141,40 @@ void Updates::checkForUpdates()
#endif #endif
} }
Updates::UpdateStatus Updates::getStatus() const Updates::Status Updates::getStatus() const
{ {
return this->status_; 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) { if (this->status_ != status) {
this->status_ = status; this->status_ = status;

View file

@ -10,7 +10,7 @@ class Updates
Updates(); Updates();
public: public:
enum UpdateStatus { enum Status {
None, None,
Searching, Searching,
UpdateAvailable, UpdateAvailable,
@ -28,18 +28,21 @@ public:
const QString &getCurrentVersion() const; const QString &getCurrentVersion() const;
const QString &getOnlineVersion() const; const QString &getOnlineVersion() const;
void installUpdates(); void installUpdates();
UpdateStatus getStatus() const; Status getStatus() const;
pajlada::Signals::Signal<UpdateStatus> statusUpdated; bool shouldShowUpdateButton() const;
bool isError() const;
pajlada::Signals::Signal<Status> statusUpdated;
private: private:
QString currentVersion_; QString currentVersion_;
QString onlineVersion_; QString onlineVersion_;
UpdateStatus status_ = None; Status status_ = None;
QString updateUrl_; QString updateUrl_;
void setStatus_(UpdateStatus status); void setStatus_(Status status);
}; };
} // namespace chatterino } // namespace chatterino

View file

@ -409,6 +409,11 @@ void BaseWindow::resizeEvent(QResizeEvent *)
this->calcButtonsSizes(); this->calcButtonsSizes();
} }
void BaseWindow::closeEvent(QCloseEvent *)
{
this->closing.invoke();
}
void BaseWindow::moveIntoDesktopRect(QWidget *parent) void BaseWindow::moveIntoDesktopRect(QWidget *parent)
{ {
if (!this->stayInScreenRect_) if (!this->stayInScreenRect_)

View file

@ -52,6 +52,8 @@ public:
Flags getFlags(); Flags getFlags();
pajlada::Signals::NoArgSignal closing;
protected: protected:
virtual bool nativeEvent(const QByteArray &eventType, void *message, long *result) override; virtual bool nativeEvent(const QByteArray &eventType, void *message, long *result) override;
virtual void scaleChangedEvent(float) override; virtual void scaleChangedEvent(float) override;
@ -61,6 +63,7 @@ protected:
virtual void changeEvent(QEvent *) override; virtual void changeEvent(QEvent *) override;
virtual void leaveEvent(QEvent *) override; virtual void leaveEvent(QEvent *) override;
virtual void resizeEvent(QResizeEvent *) override; virtual void resizeEvent(QResizeEvent *) override;
virtual void closeEvent(QCloseEvent *) override;
virtual void themeRefreshEvent() override; virtual void themeRefreshEvent() override;
virtual bool event(QEvent *event) override; virtual bool event(QEvent *event) override;

View file

@ -6,6 +6,7 @@
#include "providers/twitch/TwitchServer.hpp" #include "providers/twitch/TwitchServer.hpp"
#include "singletons/Settings.hpp" #include "singletons/Settings.hpp"
#include "singletons/Theme.hpp" #include "singletons/Theme.hpp"
#include "singletons/Updates.hpp"
#include "singletons/WindowManager.hpp" #include "singletons/WindowManager.hpp"
#include "widgets/AccountSwitchPopupWidget.hpp" #include "widgets/AccountSwitchPopupWidget.hpp"
#include "widgets/Notebook.hpp" #include "widgets/Notebook.hpp"
@ -53,27 +54,7 @@ Window::Window(WindowType _type)
}); });
if (this->hasCustomWindowFrame() && _type == Window::Main) { if (this->hasCustomWindowFrame() && _type == Window::Main) {
// settings this->addCustomTitlebarButtons();
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())); //
});
} }
if (_type == Window::Main) { if (_type == Window::Main) {
@ -194,6 +175,54 @@ Window::Window(WindowType _type)
this->notebook.setShowAddButton(true); 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() Window::WindowType Window::getType()
{ {
return this->type; return this->type;

View file

@ -10,10 +10,12 @@
#include <pajlada/settings/setting.hpp> #include <pajlada/settings/setting.hpp>
#include <pajlada/signals/signal.hpp> #include <pajlada/signals/signal.hpp>
#include <pajlada/signals/signalholder.hpp>
namespace chatterino { namespace chatterino {
class Theme; class Theme;
class UpdatePromptDialog;
class Window : public BaseWindow class Window : public BaseWindow
{ {
@ -40,15 +42,19 @@ protected:
bool event(QEvent *event) override; bool event(QEvent *event) override;
private: private:
void addCustomTitlebarButtons();
void loadGeometry();
RippleEffectLabel *userLabel = nullptr; RippleEffectLabel *userLabel = nullptr;
std::unique_ptr<UpdatePromptDialog> updateDialogHandle_;
WindowType type; WindowType type;
float dpi; float dpi;
void loadGeometry();
SplitNotebook notebook; SplitNotebook notebook;
pajlada::Signals::SignalHolder signalHolder;
friend class Notebook; friend class Notebook;
public: public:

View file

@ -1,5 +1,6 @@
#include "UpdatePromptDialog.hpp" #include "UpdatePromptDialog.hpp"
#include "singletons/Updates.hpp"
#include "util/LayoutCreator.hpp" #include "util/LayoutCreator.hpp"
#include "widgets/Label.hpp" #include "widgets/Label.hpp"
@ -15,16 +16,53 @@ UpdatePromptDialog::UpdatePromptDialog()
{ {
auto layout = LayoutCreator<UpdatePromptDialog>(this).setLayoutType<QVBoxLayout>(); auto layout = LayoutCreator<UpdatePromptDialog>(this).setLayoutType<QVBoxLayout>();
layout.emplace<Label>("An update is available!"); layout.emplace<Label>("You shouldn't be seeing this dialog.").assign(&this->ui_.label);
layout.emplace<Label>("Do you want to download and install it?");
layout.emplace<Label>("This doesn't work yet!");
auto buttons = layout.emplace<QDialogButtonBox>(); auto buttons = layout.emplace<QDialogButtonBox>();
auto install = buttons->addButton("Install", QDialogButtonBox::AcceptRole); auto install = buttons->addButton("Install", QDialogButtonBox::AcceptRole);
this->ui_.installButton = install;
auto dismiss = buttons->addButton("Dismiss", QDialogButtonBox::RejectRole); auto dismiss = buttons->addButton("Dismiss", QDialogButtonBox::RejectRole);
QObject::connect(install, &QPushButton::clicked, this, [this] { this->close(); }); QObject::connect(install, &QPushButton::clicked, this, [this] { this->close(); });
QObject::connect(dismiss, &QPushButton::clicked, this, [this] { this->close(); }); QObject::connect(dismiss, &QPushButton::clicked, this, [this] {
this->buttonClicked.invoke(Dismiss);
this->close();
});
this->updateStatusChanged(Updates::getInstance().getStatus());
this->connections_.managedConnect(Updates::getInstance().statusUpdated,
[this](auto status) { this->updateStatusChanged(status); });
}
void UpdatePromptDialog::updateStatusChanged(Updates::Status status)
{
this->ui_.installButton->setVisible(status == Updates::UpdateAvailable);
switch (status) {
case Updates::UpdateAvailable: {
this->ui_.label->setText(QString("An update (%1) is available.")
.arg(Updates::getInstance().getOnlineVersion()));
} break;
case Updates::SearchFailed: {
this->ui_.label->setText("Failed to load version information.");
} break;
case Updates::Downloading: {
this->ui_.label->setText("Downloading updates.");
// this->setActionOnFocusLoss(BaseWindow::Nothing);
} break;
case Updates::DownloadFailed: {
this->ui_.label->setText("Failed to download the update.");
} break;
case Updates::WriteFileFailed: {
this->ui_.label->setText("Failed to save the update to disk.");
} break;
default:;
}
} }
} // namespace chatterino } // namespace chatterino

View file

@ -1,19 +1,32 @@
#pragma once #pragma once
#include "pajlada/signals/signalholder.hpp"
#include "singletons/Updates.hpp"
#include "widgets/BaseWindow.hpp" #include "widgets/BaseWindow.hpp"
#include "widgets/Label.hpp" #include "widgets/Label.hpp"
class QPushButton;
namespace chatterino { namespace chatterino {
class UpdatePromptDialog : public BaseWindow class UpdatePromptDialog : public BaseWindow
{ {
public: public:
enum Button { Dismiss };
UpdatePromptDialog(); UpdatePromptDialog();
pajlada::Signals::Signal<Button> buttonClicked;
private: private:
void updateStatusChanged(Updates::Status status);
struct { struct {
Label *label; Label *label = nullptr;
QPushButton *installButton = nullptr;
} ui_; } ui_;
pajlada::Signals::SignalHolder connections_;
}; };
} // namespace chatterino } // namespace chatterino