2019-09-08 22:27:57 +02:00
|
|
|
#include "UpdateDialog.hpp"
|
|
|
|
|
|
|
|
#include "singletons/Updates.hpp"
|
|
|
|
#include "util/LayoutCreator.hpp"
|
|
|
|
#include "widgets/Label.hpp"
|
|
|
|
|
|
|
|
#include <QDialogButtonBox>
|
|
|
|
#include <QPushButton>
|
|
|
|
#include <QVBoxLayout>
|
|
|
|
|
|
|
|
namespace chatterino {
|
|
|
|
|
|
|
|
UpdateDialog::UpdateDialog()
|
2019-09-08 22:58:17 +02:00
|
|
|
: BaseWindow({BaseWindow::Frameless, BaseWindow::TopMost,
|
|
|
|
BaseWindow::EnableCustomFrame})
|
2019-09-08 22:27:57 +02:00
|
|
|
{
|
|
|
|
auto layout =
|
|
|
|
LayoutCreator<UpdateDialog>(this).setLayoutType<QVBoxLayout>();
|
|
|
|
|
|
|
|
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] {
|
2019-10-07 22:42:34 +02:00
|
|
|
Updates::instance().installUpdates();
|
2019-09-08 22:27:57 +02:00
|
|
|
this->close();
|
|
|
|
});
|
|
|
|
QObject::connect(dismiss, &QPushButton::clicked, this, [this] {
|
|
|
|
this->buttonClicked.invoke(Dismiss);
|
|
|
|
this->close();
|
|
|
|
});
|
|
|
|
|
2019-10-07 22:42:34 +02:00
|
|
|
this->updateStatusChanged(Updates::instance().getStatus());
|
2019-09-08 22:27:57 +02:00
|
|
|
this->connections_.managedConnect(
|
2019-10-07 22:42:34 +02:00
|
|
|
Updates::instance().statusUpdated,
|
2019-09-08 22:27:57 +02:00
|
|
|
[this](auto status) { this->updateStatusChanged(status); });
|
|
|
|
|
|
|
|
this->setScaleIndependantHeight(150);
|
|
|
|
}
|
|
|
|
|
|
|
|
void UpdateDialog::updateStatusChanged(Updates::Status status)
|
|
|
|
{
|
|
|
|
this->ui_.installButton->setVisible(status == Updates::UpdateAvailable);
|
|
|
|
|
|
|
|
switch (status)
|
|
|
|
{
|
2019-09-26 00:51:05 +02:00
|
|
|
case Updates::UpdateAvailable: {
|
2019-09-08 22:27:57 +02:00
|
|
|
this->ui_.label->setText(
|
2019-10-07 22:42:34 +02:00
|
|
|
(Updates::instance().isDowngrade()
|
2019-10-07 19:53:46 +02:00
|
|
|
? QString(
|
|
|
|
"The version online (%1) seems to be lower than the "
|
|
|
|
"current (%2).\nEither a version was reverted or "
|
|
|
|
"you are running a newer build.\n\nDo you want to "
|
|
|
|
"download and install it?")
|
2019-10-07 22:42:34 +02:00
|
|
|
.arg(Updates::instance().getOnlineVersion(),
|
|
|
|
Updates::instance().getCurrentVersion())
|
2019-10-07 19:53:46 +02:00
|
|
|
: QString("An update (%1) is available.\n\nDo you want to "
|
|
|
|
"download and install it?")
|
2019-10-07 22:42:34 +02:00
|
|
|
.arg(Updates::instance().getOnlineVersion())));
|
2019-09-08 22:27:57 +02:00
|
|
|
this->updateGeometry();
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2019-09-26 00:51:05 +02:00
|
|
|
case Updates::SearchFailed: {
|
2019-09-08 22:27:57 +02:00
|
|
|
this->ui_.label->setText("Failed to load version information.");
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2019-09-26 00:51:05 +02:00
|
|
|
case Updates::Downloading: {
|
2019-09-08 22:27:57 +02:00
|
|
|
this->ui_.label->setText(
|
|
|
|
"Downloading updates.\n\nChatterino will restart "
|
|
|
|
"automatically when the download is done.");
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2019-09-26 00:51:05 +02:00
|
|
|
case Updates::DownloadFailed: {
|
2019-09-08 22:27:57 +02:00
|
|
|
this->ui_.label->setText("Failed to download the update.");
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2019-09-26 00:51:05 +02:00
|
|
|
case Updates::WriteFileFailed: {
|
2019-09-08 22:27:57 +02:00
|
|
|
this->ui_.label->setText("Failed to save the update to disk.");
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace chatterino
|