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/pajlada.png</file>
<file>images/download_update.png</file>
<file>images/download_update_error.png</file>
</qresource>
<qresource prefix="/qt/etc">
<file>qt.conf</file>

View file

@ -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;

View file

@ -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<UpdateStatus> statusUpdated;
bool shouldShowUpdateButton() const;
bool isError() const;
pajlada::Signals::Signal<Status> statusUpdated;
private:
QString currentVersion_;
QString onlineVersion_;
UpdateStatus status_ = None;
Status status_ = None;
QString updateUrl_;
void setStatus_(UpdateStatus status);
void setStatus_(Status status);
};
} // namespace chatterino

View file

@ -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_)

View file

@ -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;

View file

@ -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;

View file

@ -10,10 +10,12 @@
#include <pajlada/settings/setting.hpp>
#include <pajlada/signals/signal.hpp>
#include <pajlada/signals/signalholder.hpp>
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<UpdatePromptDialog> updateDialogHandle_;
WindowType type;
float dpi;
void loadGeometry();
SplitNotebook notebook;
pajlada::Signals::SignalHolder signalHolder;
friend class Notebook;
public:

View file

@ -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<UpdatePromptDialog>(this).setLayoutType<QVBoxLayout>();
layout.emplace<Label>("An update is available!");
layout.emplace<Label>("Do you want to download and install it?");
layout.emplace<Label>("This doesn't work yet!");
layout.emplace<Label>("You shouldn't be seeing this dialog.").assign(&this->ui_.label);
auto buttons = layout.emplace<QDialogButtonBox>();
auto install = buttons->addButton("Install", QDialogButtonBox::AcceptRole);
this->ui_.installButton = install;
auto dismiss = buttons->addButton("Dismiss", QDialogButtonBox::RejectRole);
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

View file

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