Add Check for updates to main menu
Results will be displayed in a message box - if we have a new version or if we are running the latest version. Update check at startup will show message box only once in 5 days, other times it will be shown in the status bar. If we are already on latest version, nothing is shown.
This commit is contained in:
parent
52b522f92a
commit
dbbb7597a4
@ -38,6 +38,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>
|
||||
|
||||
#include "fileformat.pb.h"
|
||||
|
||||
#include <QDate>
|
||||
#include <QDesktopServices>
|
||||
#include <QDockWidget>
|
||||
#include <QFileDialog>
|
||||
@ -368,6 +369,14 @@ void MainWindow::on_actionDonate_triggered()
|
||||
QDesktopServices::openUrl(QUrl(jumpUrl("donate", "app", "menu")));
|
||||
}
|
||||
|
||||
void MainWindow::on_actionCheckForUpdates_triggered()
|
||||
{
|
||||
Updater *updater = new Updater();
|
||||
connect(updater, SIGNAL(latestVersion(QString)),
|
||||
this, SLOT(onLatestVersion(QString)));
|
||||
updater->checkForNewVersion();
|
||||
}
|
||||
|
||||
void MainWindow::on_actionHelpAbout_triggered()
|
||||
{
|
||||
QDialog *aboutDialog = new QDialog;
|
||||
@ -446,7 +455,12 @@ void MainWindow::reportLocalServerError()
|
||||
|
||||
void MainWindow::onNewVersion(QString newVersion)
|
||||
{
|
||||
QMessageBox::information(this, tr("Update available"),
|
||||
QDate today = QDate::currentDate();
|
||||
QDate lastChecked = QDate::fromString(
|
||||
appSettings->value(kLastUpdateCheck).toString(),
|
||||
Qt::ISODate);
|
||||
if (lastChecked.daysTo(today) >= 5) {
|
||||
QMessageBox::information(this, tr("Update check"),
|
||||
tr("<p><b>Ostinato version %1 is now available</b> (you have %2). "
|
||||
"See <a href='%3'>change log</a>.</p>"
|
||||
"<p>Visit <a href='%4'>ostinato.org</a> to download.</p>")
|
||||
@ -454,6 +468,39 @@ void MainWindow::onNewVersion(QString newVersion)
|
||||
.arg(version)
|
||||
.arg(jumpUrl("changelog", "app", "status", "update"))
|
||||
.arg(jumpUrl("download", "app", "status", "update")));
|
||||
}
|
||||
else {
|
||||
QLabel *msg = new QLabel(tr("New Ostinato version %1 available. Visit "
|
||||
"<a href='%2'>ostinato.org</a> to download")
|
||||
.arg(newVersion)
|
||||
.arg(jumpUrl("download", "app", "status", "update")));
|
||||
msg->setOpenExternalLinks(true);
|
||||
statusBar()->addPermanentWidget(msg);
|
||||
}
|
||||
|
||||
appSettings->setValue(kLastUpdateCheck, today.toString(Qt::ISODate));
|
||||
sender()->deleteLater();
|
||||
}
|
||||
|
||||
void MainWindow::onLatestVersion(QString latestVersion)
|
||||
{
|
||||
if (version != latestVersion) {
|
||||
QMessageBox::information(this, tr("Update check"),
|
||||
tr("<p><b>Ostinato version %1 is now available</b> (you have %2). "
|
||||
"See <a href='%3'>change log</a>.</p>"
|
||||
"<p>Visit <a href='%4'>ostinato.org</a> to download.</p>")
|
||||
.arg(latestVersion)
|
||||
.arg(version)
|
||||
.arg(jumpUrl("changelog", "app", "status", "update"))
|
||||
.arg(jumpUrl("download", "app", "status", "update")));
|
||||
}
|
||||
else {
|
||||
QMessageBox::information(this, tr("Update check"),
|
||||
tr("You are already running the latest Ostinato version - %1")
|
||||
.arg(version));
|
||||
}
|
||||
|
||||
sender()->deleteLater();
|
||||
}
|
||||
|
||||
//! Returns true on success (or user cancel) and false on failure
|
||||
|
@ -62,6 +62,7 @@ public slots:
|
||||
void on_actionViewRestoreDefaults_triggered();
|
||||
void on_actionHelpOnline_triggered();
|
||||
void on_actionDonate_triggered();
|
||||
void on_actionCheckForUpdates_triggered();
|
||||
void on_actionHelpAbout_triggered();
|
||||
|
||||
private slots:
|
||||
@ -70,6 +71,7 @@ private slots:
|
||||
void onLocalServerError(QProcess::ProcessError error);
|
||||
void reportLocalServerError();
|
||||
void onNewVersion(QString version);
|
||||
void onLatestVersion(QString version);
|
||||
};
|
||||
|
||||
#endif
|
||||
|
@ -35,6 +35,7 @@
|
||||
<addaction name="actionHelpOnline" />
|
||||
<addaction name="separator" />
|
||||
<addaction name="actionDonate" />
|
||||
<addaction name="actionCheckForUpdates" />
|
||||
<addaction name="separator" />
|
||||
<addaction name="actionHelpAbout" />
|
||||
<addaction name="actionAboutQt" />
|
||||
@ -122,6 +123,11 @@
|
||||
<string>Donate</string>
|
||||
</property>
|
||||
</action>
|
||||
<action name="actionCheckForUpdates" >
|
||||
<property name="text" >
|
||||
<string>Check for Updates...</string>
|
||||
</property>
|
||||
</action>
|
||||
</widget>
|
||||
<resources>
|
||||
<include location="ostinato.qrc" />
|
||||
|
@ -82,6 +82,7 @@ extern QString kUserDefaultValue;
|
||||
//
|
||||
const QString kApplicationWindowGeometryKey("LastUse/ApplicationWindowGeometry");
|
||||
const QString kApplicationWindowLayout("LastUse/ApplicationWindowLayout");
|
||||
const QString kLastUpdateCheck("LastUse/UpdateCheck");
|
||||
|
||||
#endif
|
||||
|
||||
|
@ -87,6 +87,8 @@ void Updater::parseXml(QNetworkReply *reply)
|
||||
if (!newVersion.isEmpty() && isVersionNewer(newVersion, QString(version)))
|
||||
emit newVersionAvailable(newVersion);
|
||||
|
||||
emit latestVersion(newVersion);
|
||||
|
||||
_exit:
|
||||
// Job done, time to self-destruct
|
||||
deleteLater();
|
||||
|
@ -37,6 +37,7 @@ public:
|
||||
|
||||
signals:
|
||||
void newVersionAvailable(QString);
|
||||
void latestVersion(QString);
|
||||
|
||||
private slots:
|
||||
void parseXml(QNetworkReply *reply);
|
||||
|
Loading…
Reference in New Issue
Block a user