2018-07-05 16:04:39 +02:00
|
|
|
#include "UpdateDialog.hpp"
|
2018-07-04 20:42:51 +02:00
|
|
|
|
2018-07-05 11:42:40 +02:00
|
|
|
#include "singletons/Updates.hpp"
|
2018-07-04 20:42:51 +02:00
|
|
|
#include "util/LayoutCreator.hpp"
|
|
|
|
#include "widgets/Label.hpp"
|
|
|
|
|
|
|
|
#include <QDialogButtonBox>
|
|
|
|
#include <QPushButton>
|
|
|
|
#include <QVBoxLayout>
|
|
|
|
|
|
|
|
namespace chatterino {
|
|
|
|
|
2018-07-05 16:04:39 +02:00
|
|
|
UpdateDialog::UpdateDialog()
|
2018-08-06 21:17:03 +02:00
|
|
|
: BaseWindow(nullptr,
|
|
|
|
BaseWindow::Flags(BaseWindow::Frameless | BaseWindow::TopMost |
|
|
|
|
BaseWindow::EnableCustomFrame))
|
2018-07-04 20:42:51 +02:00
|
|
|
{
|
2018-08-06 21:17:03 +02:00
|
|
|
auto layout =
|
|
|
|
LayoutCreator<UpdateDialog>(this).setLayoutType<QVBoxLayout>();
|
2018-07-04 20:42:51 +02:00
|
|
|
|
2018-08-06 21:17:03 +02:00
|
|
|
layout.emplace<Label>("You shouldn't be seeing this dialog.")
|
|
|
|
.assign(&this->ui_.label);
|
2018-07-04 20:42:51 +02:00
|
|
|
|
|
|
|
auto buttons = layout.emplace<QDialogButtonBox>();
|
|
|
|
auto install = buttons->addButton("Install", QDialogButtonBox::AcceptRole);
|
2018-07-05 11:42:40 +02:00
|
|
|
this->ui_.installButton = install;
|
2018-07-04 20:42:51 +02:00
|
|
|
auto dismiss = buttons->addButton("Dismiss", QDialogButtonBox::RejectRole);
|
|
|
|
|
2018-08-06 21:17:03 +02:00
|
|
|
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());
|
2018-08-06 21:17:03 +02:00
|
|
|
this->connections_.managedConnect(
|
|
|
|
Updates::getInstance().statusUpdated,
|
|
|
|
[this](auto status) { this->updateStatusChanged(status); });
|
2018-07-05 11:42:40 +02:00
|
|
|
}
|
|
|
|
|
2018-07-05 16:04:39 +02:00
|
|
|
void UpdateDialog::updateStatusChanged(Updates::Status status)
|
2018-07-05 11:42:40 +02:00
|
|
|
{
|
|
|
|
this->ui_.installButton->setVisible(status == Updates::UpdateAvailable);
|
|
|
|
|
|
|
|
switch (status) {
|
|
|
|
case Updates::UpdateAvailable: {
|
2018-07-05 18:17:12 +02:00
|
|
|
this->ui_.label->setText(
|
2018-08-06 21:17:03 +02:00
|
|
|
QString("An update (%1) is available.\n\nDo you want to "
|
|
|
|
"download and install it?")
|
2018-07-05 18:17:12 +02:00
|
|
|
.arg(Updates::getInstance().getOnlineVersion()));
|
2018-07-05 11:42:40 +02:00
|
|
|
} break;
|
|
|
|
|
|
|
|
case Updates::SearchFailed: {
|
|
|
|
this->ui_.label->setText("Failed to load version information.");
|
|
|
|
} break;
|
|
|
|
|
|
|
|
case Updates::Downloading: {
|
2018-08-06 21:17:03 +02:00
|
|
|
this->ui_.label->setText(
|
|
|
|
"Downloading updates.\n\nChatterino will restart "
|
|
|
|
"automatically when the download is done.");
|
2018-07-05 11:42:40 +02:00
|
|
|
} 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:;
|
|
|
|
}
|
2018-07-04 20:42:51 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace chatterino
|