2018-07-05 12:52:36 +02:00
|
|
|
#include "InitUpdateButton.hpp"
|
|
|
|
|
2018-07-05 16:04:39 +02:00
|
|
|
#include "widgets/dialogs/UpdateDialog.hpp"
|
2018-07-05 12:52:36 +02:00
|
|
|
#include "widgets/helper/RippleEffectButton.hpp"
|
|
|
|
|
|
|
|
namespace chatterino {
|
|
|
|
|
2018-07-05 16:04:39 +02:00
|
|
|
void initUpdateButton(RippleEffectButton &button, std::unique_ptr<UpdateDialog> &handle,
|
2018-07-05 12:52:36 +02:00
|
|
|
pajlada::Signals::SignalHolder &signalHolder)
|
|
|
|
{
|
|
|
|
button.hide();
|
|
|
|
|
|
|
|
// show update prompt when clicking the button
|
|
|
|
QObject::connect(&button, &RippleEffectButton::clicked, [&button, &handle] {
|
2018-07-05 13:25:10 +02:00
|
|
|
(void)(handle);
|
|
|
|
|
2018-07-05 16:04:39 +02:00
|
|
|
auto dialog = new UpdateDialog();
|
2018-07-05 12:52:36 +02:00
|
|
|
dialog->setActionOnFocusLoss(BaseWindow::Delete);
|
|
|
|
dialog->move(button.mapToGlobal(QPoint(int(-100 * button.getScale()), button.height())));
|
|
|
|
dialog->show();
|
|
|
|
dialog->raise();
|
|
|
|
|
|
|
|
dialog->buttonClicked.connect([&button](auto buttonType) {
|
|
|
|
switch (buttonType) {
|
2018-07-05 16:04:39 +02:00
|
|
|
case UpdateDialog::Dismiss: {
|
2018-07-05 12:52:36 +02:00
|
|
|
button.hide();
|
|
|
|
} break;
|
2018-07-05 18:17:12 +02:00
|
|
|
case UpdateDialog::Install: {
|
|
|
|
Updates::getInstance().installUpdates();
|
|
|
|
} break;
|
2018-07-05 12:52:36 +02:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2018-07-05 18:17:12 +02:00
|
|
|
// handle.reset(dialog);
|
|
|
|
// dialog->closing.connect([&handle] { handle.release(); });
|
2018-07-05 12:52:36 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
// update image when state changes
|
|
|
|
auto updateChange = [&button](auto) {
|
|
|
|
button.setVisible(Updates::getInstance().shouldShowUpdateButton());
|
|
|
|
|
|
|
|
auto imageUrl = Updates::getInstance().isError() ? ":/images/download_update_error.png"
|
|
|
|
: ":/images/download_update.png";
|
|
|
|
button.setPixmap(QPixmap(imageUrl));
|
|
|
|
};
|
|
|
|
|
|
|
|
updateChange(Updates::getInstance().getStatus());
|
|
|
|
|
|
|
|
signalHolder.managedConnect(Updates::getInstance().statusUpdated,
|
|
|
|
[updateChange](auto status) { updateChange(status); });
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace chatterino
|