2018-07-05 16:04:39 +02:00
|
|
|
#include "UpdateDialog.hpp"
|
2019-09-08 22:27:57 +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"
|
2019-09-08 22:27:57 +02:00
|
|
|
|
2018-07-04 20:42:51 +02:00
|
|
|
#include <QDialogButtonBox>
|
|
|
|
#include <QPushButton>
|
|
|
|
#include <QVBoxLayout>
|
2019-09-08 22:27:57 +02:00
|
|
|
|
2018-07-04 20:42:51 +02:00
|
|
|
namespace chatterino {
|
2019-09-08 22:27:57 +02:00
|
|
|
|
2018-07-05 16:04:39 +02:00
|
|
|
UpdateDialog::UpdateDialog()
|
2019-09-08 22:58:17 +02:00
|
|
|
: BaseWindow({BaseWindow::Frameless, BaseWindow::TopMost,
|
2022-12-03 11:50:22 +01:00
|
|
|
BaseWindow::EnableCustomFrame, BaseWindow::DisableLayoutSave})
|
2018-07-04 20:42:51 +02:00
|
|
|
{
|
2018-07-05 16:04:39 +02:00
|
|
|
auto layout =
|
|
|
|
LayoutCreator<UpdateDialog>(this).setLayoutType<QVBoxLayout>();
|
2019-09-08 22:27:57 +02:00
|
|
|
|
2018-07-05 11:42:40 +02:00
|
|
|
layout.emplace<Label>("You shouldn't be seeing this dialog.")
|
|
|
|
.assign(&this->ui_.label);
|
2019-09-08 22:27:57 +02:00
|
|
|
|
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);
|
2019-09-08 22:27:57 +02:00
|
|
|
|
2019-08-18 20:14:00 +02:00
|
|
|
QObject::connect(install, &QPushButton::clicked, this, [this] {
|
2019-10-07 22:42:34 +02:00
|
|
|
Updates::instance().installUpdates();
|
2019-08-18 20:14:00 +02:00
|
|
|
this->close();
|
|
|
|
});
|
2018-07-05 11:42:40 +02:00
|
|
|
QObject::connect(dismiss, &QPushButton::clicked, this, [this] {
|
|
|
|
this->buttonClicked.invoke(Dismiss);
|
|
|
|
this->close();
|
|
|
|
});
|
2019-09-08 22:27:57 +02:00
|
|
|
|
2019-10-07 22:42:34 +02:00
|
|
|
this->updateStatusChanged(Updates::instance().getStatus());
|
2020-11-08 12:02:19 +01:00
|
|
|
this->connections_.managedConnect(Updates::instance().statusUpdated,
|
|
|
|
[this](auto status) {
|
|
|
|
this->updateStatusChanged(status);
|
|
|
|
});
|
2019-09-08 22:27:57 +02:00
|
|
|
|
2019-08-18 20:14:00 +02:00
|
|
|
this->setScaleIndependantHeight(150);
|
2023-05-13 12:13:42 +02:00
|
|
|
this->setScaleIndependantWidth(250);
|
2018-07-05 11:42:40 +02:00
|
|
|
}
|
2019-09-08 22:27:57 +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);
|
2019-09-08 22:27:57 +02:00
|
|
|
|
2018-07-05 11:42:40 +02:00
|
|
|
switch (status)
|
|
|
|
{
|
2019-09-26 00:51:05 +02:00
|
|
|
case Updates::UpdateAvailable: {
|
2023-05-13 12:13:42 +02:00
|
|
|
this->ui_.label->setText((
|
|
|
|
Updates::instance().isDowngrade()
|
|
|
|
? QString(
|
|
|
|
"The version online (%1) seems to be\nlower than the "
|
|
|
|
"current (%2).\nEither a version was reverted or "
|
|
|
|
"you are\nrunning a newer build.\n\nDo you want to "
|
|
|
|
"download and install it?")
|
|
|
|
.arg(Updates::instance().getOnlineVersion(),
|
|
|
|
Updates::instance().getCurrentVersion())
|
|
|
|
: QString("An update (%1) is available.\n\nDo you want to "
|
|
|
|
"download and install it?")
|
|
|
|
.arg(Updates::instance().getOnlineVersion())));
|
2019-08-18 20:14:00 +02:00
|
|
|
this->updateGeometry();
|
2018-07-05 11:42:40 +02:00
|
|
|
}
|
|
|
|
break;
|
2019-09-08 22:27:57 +02:00
|
|
|
|
2019-09-26 00:51:05 +02:00
|
|
|
case Updates::SearchFailed: {
|
2018-07-05 11:42:40 +02:00
|
|
|
this->ui_.label->setText("Failed to load version information.");
|
|
|
|
}
|
|
|
|
break;
|
2019-09-08 22:27:57 +02:00
|
|
|
|
2019-09-26 00:51:05 +02:00
|
|
|
case Updates::Downloading: {
|
2018-07-05 18:17:12 +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;
|
2019-09-08 22:27:57 +02:00
|
|
|
|
2019-09-26 00:51:05 +02:00
|
|
|
case Updates::DownloadFailed: {
|
2018-07-05 11:42:40 +02:00
|
|
|
this->ui_.label->setText("Failed to download the update.");
|
|
|
|
}
|
|
|
|
break;
|
2019-09-08 22:27:57 +02:00
|
|
|
|
2019-09-26 00:51:05 +02:00
|
|
|
case Updates::WriteFileFailed: {
|
2018-07-05 11:42:40 +02:00
|
|
|
this->ui_.label->setText("Failed to save the update to disk.");
|
|
|
|
}
|
|
|
|
break;
|
2019-09-08 22:27:57 +02:00
|
|
|
|
2018-07-05 11:42:40 +02:00
|
|
|
default:;
|
|
|
|
}
|
2018-07-04 20:42:51 +02:00
|
|
|
}
|
2019-09-08 22:27:57 +02:00
|
|
|
|
2018-07-04 20:42:51 +02:00
|
|
|
} // namespace chatterino
|