mirror-chatterino2/src/widgets/dialogs/UpdatePromptDialog.cpp

69 lines
2.4 KiB
C++
Raw Normal View History

#include "UpdatePromptDialog.hpp"
2018-07-05 11:42:40 +02:00
#include "singletons/Updates.hpp"
#include "util/LayoutCreator.hpp"
#include "widgets/Label.hpp"
#include <QDialogButtonBox>
#include <QPushButton>
#include <QVBoxLayout>
namespace chatterino {
UpdatePromptDialog::UpdatePromptDialog()
: BaseWindow(nullptr, BaseWindow::Flags(BaseWindow::Frameless | BaseWindow::TopMost |
BaseWindow::EnableCustomFrame))
{
auto layout = LayoutCreator<UpdatePromptDialog>(this).setLayoutType<QVBoxLayout>();
2018-07-05 11:42:40 +02:00
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);
2018-07-05 11:42:40 +02:00
this->ui_.installButton = install;
auto dismiss = buttons->addButton("Dismiss", QDialogButtonBox::RejectRole);
QObject::connect(install, &QPushButton::clicked, this, [this] { this->close(); });
2018-07-05 11:42:40 +02:00
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