worked on the UpdatePromptDialog
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user