Add Update Dialog

This commit is contained in:
Dan Paulat 2023-04-22 23:31:23 -05:00
parent 26ea4f4771
commit c1aa34607f
4 changed files with 334 additions and 3 deletions

View file

@ -0,0 +1,71 @@
#include "update_dialog.hpp"
#include "ui_update_dialog.h"
#include <scwx/qt/main/versions.hpp>
#include <scwx/qt/manager/resource_manager.hpp>
#include <QDesktopServices>
#include <QFontDatabase>
namespace scwx
{
namespace qt
{
namespace ui
{
class UpdateDialogImpl
{
public:
explicit UpdateDialogImpl() = default;
~UpdateDialogImpl() = default;
std::string downloadUrl_ {};
};
UpdateDialog::UpdateDialog(QWidget* parent) :
QDialog(parent),
p {std::make_unique<UpdateDialogImpl>()},
ui(new Ui::UpdateDialog)
{
ui->setupUi(this);
int titleFontId =
manager::ResourceManager::FontId(types::Font::din1451alt_g);
QString titleFontFamily =
QFontDatabase::applicationFontFamilies(titleFontId).at(0);
QFont titleFont(titleFontFamily, 12);
ui->bannerLabel->setFont(titleFont);
ui->releaseNotesText->setOpenExternalLinks(true);
}
UpdateDialog::~UpdateDialog()
{
delete ui;
}
void UpdateDialog::UpdateReleaseInfo(const std::string& latestVersion,
const types::gh::Release& latestRelease)
{
ui->versionLabel->setText(tr("Supercell Wx v%1 is now available. You are "
"currently running version %2.")
.arg(latestVersion.c_str())
.arg(main::kVersionString_.c_str()));
ui->releaseNotesText->setMarkdown(
QString::fromStdString(latestRelease.body_));
p->downloadUrl_ = latestRelease.htmlUrl_;
}
void UpdateDialog::on_downloadButton_clicked()
{
if (!p->downloadUrl_.empty())
{
QDesktopServices::openUrl(QUrl {QString::fromStdString(p->downloadUrl_)});
}
}
} // namespace ui
} // namespace qt
} // namespace scwx

View file

@ -0,0 +1,43 @@
#pragma once
#include <scwx/qt/types/github_types.hpp>
#include <QDialog>
namespace Ui
{
class UpdateDialog;
}
namespace scwx
{
namespace qt
{
namespace ui
{
class UpdateDialogImpl;
class UpdateDialog : public QDialog
{
Q_OBJECT
public:
explicit UpdateDialog(QWidget* parent = nullptr);
~UpdateDialog();
void UpdateReleaseInfo(const std::string& latestVersion,
const types::gh::Release& latestRelease);
private slots:
void on_downloadButton_clicked();
private:
friend UpdateDialogImpl;
std::unique_ptr<UpdateDialogImpl> p;
Ui::UpdateDialog* ui;
};
} // namespace ui
} // namespace qt
} // namespace scwx

View file

@ -0,0 +1,214 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>UpdateDialog</class>
<widget class="QDialog" name="UpdateDialog">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>400</width>
<height>300</height>
</rect>
</property>
<property name="windowTitle">
<string>Update Available</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QFrame" name="topFrame">
<property name="frameShape">
<enum>QFrame::StyledPanel</enum>
</property>
<property name="frameShadow">
<enum>QFrame::Raised</enum>
</property>
<layout class="QHBoxLayout" name="horizontalLayout">
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<item>
<widget class="QLabel" name="iconLabel">
<property name="maximumSize">
<size>
<width>64</width>
<height>64</height>
</size>
</property>
<property name="text">
<string/>
</property>
<property name="pixmap">
<pixmap resource="../../../../scwx-qt.qrc">:/res/icons/scwx-256.png</pixmap>
</property>
<property name="scaledContents">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<widget class="QFrame" name="textFrame">
<property name="frameShape">
<enum>QFrame::StyledPanel</enum>
</property>
<property name="frameShadow">
<enum>QFrame::Raised</enum>
</property>
<layout class="QVBoxLayout" name="verticalLayout_2">
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<item>
<widget class="QLabel" name="bannerLabel">
<property name="text">
<string>A new version of Supercell Wx is available!</string>
</property>
<property name="wordWrap">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="versionLabel">
<property name="text">
<string>Supercell Wx X.Y.Z is now available. You are running version X.Y.Z.</string>
</property>
<property name="wordWrap">
<bool>true</bool>
</property>
</widget>
</item>
</layout>
</widget>
</item>
</layout>
</widget>
</item>
<item>
<widget class="QLabel" name="releaseNotesLabel">
<property name="text">
<string>Release Notes:</string>
</property>
</widget>
</item>
<item>
<widget class="QTextBrowser" name="releaseNotesText"/>
</item>
<item>
<widget class="QCheckBox" name="enableUpdatesCheckBox">
<property name="text">
<string>&amp;Enable Update Notifications</string>
</property>
</widget>
</item>
<item>
<widget class="QFrame" name="bottomFrame">
<property name="frameShape">
<enum>QFrame::StyledPanel</enum>
</property>
<property name="frameShadow">
<enum>QFrame::Raised</enum>
</property>
<layout class="QHBoxLayout" name="horizontalLayout_2">
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<item>
<widget class="QPushButton" name="downloadButton">
<property name="text">
<string>Download</string>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QDialogButtonBox" name="buttonBox">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="standardButtons">
<set>QDialogButtonBox::Ok</set>
</property>
</widget>
</item>
</layout>
</widget>
</item>
</layout>
</widget>
<resources>
<include location="../../../../scwx-qt.qrc"/>
</resources>
<connections>
<connection>
<sender>buttonBox</sender>
<signal>accepted()</signal>
<receiver>UpdateDialog</receiver>
<slot>accept()</slot>
<hints>
<hint type="sourcelabel">
<x>248</x>
<y>254</y>
</hint>
<hint type="destinationlabel">
<x>157</x>
<y>274</y>
</hint>
</hints>
</connection>
<connection>
<sender>buttonBox</sender>
<signal>rejected()</signal>
<receiver>UpdateDialog</receiver>
<slot>reject()</slot>
<hints>
<hint type="sourcelabel">
<x>316</x>
<y>260</y>
</hint>
<hint type="destinationlabel">
<x>286</x>
<y>274</y>
</hint>
</hints>
</connection>
</connections>
</ui>