Skip to content

Commit

Permalink
Improve new version dialog
Browse files Browse the repository at this point in the history
  • Loading branch information
mistic100 committed Aug 30, 2017
1 parent 79a6e86 commit c8e3457
Show file tree
Hide file tree
Showing 18 changed files with 464 additions and 229 deletions.
12 changes: 6 additions & 6 deletions installer/lang/ru_RU/custom.isl
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[CustomMessages]
DeleteSettings=Удалить файл настроек?
NewerVersionExists=Новая версия %1 установлена. %n%n Версия инсталятора: %2%n Текущая версия:
Options=Настройки:
OptionAutostart=Запустить %1 в Windows
Website=Вебсайт
[CustomMessages]
DeleteSettings=Удалить файл настроек?
NewerVersionExists=Новая версия %1 установлена. %n%n Версия инсталятора: %2%n Текущая версия:
Options=Настройки:
OptionAutostart=Запустить %1 в Windows
Website=Вебсайт
2 changes: 2 additions & 0 deletions src/UMWP_Autochanger.qrc
Original file line number Diff line number Diff line change
Expand Up @@ -61,5 +61,7 @@
<file>images/folder-overlay.png</file>
<file>images/icons/bullet_lock.png</file>
<file>images/qt-logo-16.png</file>
<file>images/icons/update.png</file>
<file>images/icon-large.png</file>
</qresource>
</RCC>
5 changes: 3 additions & 2 deletions src/constants.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
#define VERSION_H

#define APP_NAME "UMWP Autochanger"
#define APP_VERSION "2.2.1"
#define APP_VERSION_DW 2,2,1
#define APP_VERSION "2.3.0"
#define APP_VERSION_DW 2,3,0
#define APP_COMPANYNAME "StrangePlanet"
#define APP_FILEDESCRIPTION "Ultimate Monitor Wallpaper Autochanger"
#define APP_LEGALCOPYRIGHT "Copyright (c) 2013-2017 StrangePlanet"
Expand All @@ -22,6 +22,7 @@
#define APP_DOCUMENTATION_URL "https://www.strangeplanet.fr/work/umwp-autochanger/#help"
#define APP_VERSION_URL "https://www.strangeplanet.fr/work/umwp-autochanger/last-version.txt"
#define APP_ISSUES_URL "https://github.com/mistic100/UMWP-Autochanger/issues"
#define APP_CHANGELOG_URL "https://www.strangeplanet.fr/work/umwp-autochanger/changelogs/%1.html"

#define APP_INSTALLER_SIZE 12000000
#define APP_MAX_TRAVERSAL 3
Expand Down
5 changes: 3 additions & 2 deletions src/gui/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -545,8 +545,9 @@ void MainWindow::openAboutDialog()
text+= "Built with <a href=\"https://www.qt.io\"><img src=\":/images/qt-logo-16.png\" style=\"vertical-align: baseline\"></a>";

QMessageBox dialog;
dialog.setIcon(QMessageBox::Information);
dialog.setIconPixmap(QPixmap(":/images/icon-large.png").scaled(96, 96));
dialog.setWindowTitle(tr("About"));
dialog.setWindowIcon(windowIcon());
dialog.setText(text);
dialog.setStandardButtons(QMessageBox::Close | QMessageBox::Open);
dialog.setDefaultButton(QMessageBox::Close);
Expand Down Expand Up @@ -696,7 +697,7 @@ void MainWindow::onNewVersion()
{
// tray tootlip
m_trayIcon->showMessage(APP_NAME, tr("A new version is available : %1").arg(version));
connect(m_trayIcon, SIGNAL(messageClicked()), this, SLOT(toggleWindow()));
connect(m_trayIcon, &TrayIcon::messageClicked, this, [this]{ toggleWindow(); openNewVersionDialog(); });
}
else
{
Expand Down
85 changes: 72 additions & 13 deletions src/gui/newversiondialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,18 @@ NewVersionDialog::NewVersionDialog(QWidget* _parent, Controller* _ctrl) :
{
ui->setupUi(this);

setWindowFlags(UM::SimpleDialogFlag);

m_version = m_ctrl->enviro()->newVersion();

ui->progressBar->setVisible(false);
ui->label->setText(tr("A new version is available : %1").arg(m_version.code));
ui->blockDownloading->setVisible(false);
resize(size().width(), 250);

ui->title->setText(ui->title->text().arg(APP_NAME));
ui->description->setText(ui->description->text().arg(APP_NAME, m_version.code, APP_VERSION));
ui->titleDownloading->setText(ui->titleDownloading->text().arg(APP_NAME, m_version.code));

ui->buttonBox->button(QDialogButtonBox::Ok)->setText(tr("Close"));
ui->buttonBox->button(QDialogButtonBox::Cancel)->setText(tr("Close and don't show this message again"));
downloadChangelog();

setWindowFlags(UM::SimpleDialogFlag);
}

/**
Expand All @@ -39,11 +42,11 @@ NewVersionDialog::~NewVersionDialog()
/**
* @brief Launch download on click on main button
*/
void NewVersionDialog::on_updateButton_clicked()
void NewVersionDialog::on_buttonUpdate_clicked()
{
ui->updateButton->setVisible(false);
ui->progressBar->setVisible(true);
ui->buttonBox->setDisabled(true);
ui->blockInfo->setVisible(false);
ui->blockDownloading->setVisible(true);
resize(size().width(), 60);

m_file.setFileName(QDir::toNativeSeparators(QDir::tempPath() + "/" + APP_INSTALLER_FILENAME));

Expand All @@ -55,8 +58,6 @@ void NewVersionDialog::on_updateButton_clicked()
}
else
{
ui->label->setText(tr("Downloading UMWP_Autochanger_%1_Setup.exe ...").arg(m_version.code));

QLOG_DEBUG() << "Download" << m_version.link;

QNetworkAccessManager* manager = new QNetworkAccessManager();
Expand All @@ -81,7 +82,64 @@ void NewVersionDialog::on_updateButton_clicked()
void NewVersionDialog::errorMessage()
{
QMessageBox::critical(this, tr("Error"), tr("Unable to download installer file."), QMessageBox::Ok, QMessageBox::Ok);
done(0);
reject();
}

/**
* @brief Download the changelog file
*/
void NewVersionDialog::downloadChangelog()
{
QString url = QString(APP_CHANGELOG_URL).arg(m_version.code);

QNetworkAccessManager* manager = new QNetworkAccessManager();
connect(manager, SIGNAL(finished(QNetworkReply*)), this, SLOT(onChangelogFinished(QNetworkReply*)));

QNetworkRequest request = QNetworkRequest(QUrl(url));
if (url.startsWith("https"))
{
request.setSslConfiguration(QSslConfiguration::defaultConfiguration());
}

manager->get(request);
}

/**
* @brief Display the changelog file
* @param _reply
*/
void NewVersionDialog::onChangelogFinished(QNetworkReply* _reply)
{
QString html;

if (_reply->error() == QNetworkReply::NoError)
{
// Load CSS
html.append("<style>");

QFile cssFile(":/lang/changelog.css");

cssFile.open(QIODevice::ReadOnly);
QTextStream cssContent(&cssFile);
cssContent.setCodec("UTF-8");
html.append(cssContent.readAll());
cssFile.close();

html.append("</style>");

html.append(QString(_reply->readAll()));
}
else
{
QLOG_ERROR() << _reply->errorString();

html.append(_reply->errorString());
}

ui->textBrowser->setHtml(html);

_reply->manager()->deleteLater();
_reply->deleteLater();
}

/**
Expand Down Expand Up @@ -148,6 +206,7 @@ void NewVersionDialog::onDownloadFinished()
ui->progressBar->setValue(100);
ui->progressBar->setMaximum(100);

accept();
m_ctrl->launchInstaller();
}
}
Expand Down
7 changes: 4 additions & 3 deletions src/gui/newversiondialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class NewVersionDialog : public QDialog
Controller* m_ctrl;

UM::NewVersion m_version;
QFile m_file;
QFile m_file;
QNetworkReply* m_reply;

public:
Expand All @@ -35,13 +35,14 @@ class NewVersionDialog : public QDialog

private:
void errorMessage();
void downloadChangelog();

private slots:
void on_updateButton_clicked();

void onDataReady();
void onDownloadFinished();
void onDownloadProgress(qint64 _received, qint64 _total);
void onChangelogFinished(QNetworkReply *_reply);
void on_buttonUpdate_clicked();
};

#endif // NEWVERSIONDIALOG_H
Loading

0 comments on commit c8e3457

Please sign in to comment.