Add check for new version
This commit is contained in:
@@ -46,3 +46,10 @@ HelpDialog::HelpDialog(QWidget *parent) : QDialog(parent)
|
|||||||
|
|
||||||
layout->addWidget(helpText);
|
layout->addWidget(helpText);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QString getVersion()
|
||||||
|
{
|
||||||
|
QString version = GITVERSION;
|
||||||
|
version.truncate(8);
|
||||||
|
return version;
|
||||||
|
}
|
||||||
|
|||||||
@@ -17,4 +17,6 @@ public:
|
|||||||
HelpDialog(QWidget *parent = nullptr);
|
HelpDialog(QWidget *parent = nullptr);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
QString getVersion();
|
||||||
|
|
||||||
#endif // ABOUT_H
|
#endif // ABOUT_H
|
||||||
|
|||||||
@@ -19,6 +19,9 @@
|
|||||||
#include <QStatusBar>
|
#include <QStatusBar>
|
||||||
#include <QImageReader>
|
#include <QImageReader>
|
||||||
#include <QMimeDatabase>
|
#include <QMimeDatabase>
|
||||||
|
#include <QDesktopServices>
|
||||||
|
#include <QJsonDocument>
|
||||||
|
#include <QNetworkReply>
|
||||||
#include "loadrunable.h"
|
#include "loadrunable.h"
|
||||||
#include "markedfiles.h"
|
#include "markedfiles.h"
|
||||||
#include "about.h"
|
#include "about.h"
|
||||||
@@ -254,6 +257,7 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent)
|
|||||||
helpMenu->addAction(tr("Help"), QKeySequence::HelpContents, [this]{ HelpDialog help(this); help.exec(); });
|
helpMenu->addAction(tr("Help"), QKeySequence::HelpContents, [this]{ HelpDialog help(this); help.exec(); });
|
||||||
helpMenu->addAction(tr("About Tenmon"), [this]{ About about(this); about.exec(); });
|
helpMenu->addAction(tr("About Tenmon"), [this]{ About about(this); about.exec(); });
|
||||||
helpMenu->addAction(tr("About Qt"), [this](){ QMessageBox::aboutQt(this); });
|
helpMenu->addAction(tr("About Qt"), [this](){ QMessageBox::aboutQt(this); });
|
||||||
|
helpMenu->addAction(tr("Check update"), this, &MainWindow::checkNewVersion);
|
||||||
|
|
||||||
setupSigterm();
|
setupSigterm();
|
||||||
QSettings settings;
|
QSettings settings;
|
||||||
@@ -692,6 +696,42 @@ void MainWindow::exportCSV()
|
|||||||
m_databaseView->exportCSV(file);
|
m_databaseView->exportCSV(file);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void MainWindow::checkNewVersion()
|
||||||
|
{
|
||||||
|
QNetworkAccessManager *manager = new QNetworkAccessManager(this);
|
||||||
|
QNetworkRequest request(QUrl("https://gitea.nouspiro.space/api/v1/repos/nou/tenmon/releases/latest"));
|
||||||
|
request.setRawHeader("accept", "application/json");
|
||||||
|
QNetworkReply *reply = manager->get(request);
|
||||||
|
connect(reply, &QNetworkReply::finished, [this, manager, reply](){
|
||||||
|
QJsonParseError error;
|
||||||
|
QJsonDocument json = QJsonDocument::fromJson(reply->readAll(), &error);
|
||||||
|
if(json.isObject() && json.object().contains("tag_name"))
|
||||||
|
{
|
||||||
|
QString tag = json.object().value("tag_name").toString();
|
||||||
|
QString version = getVersion();
|
||||||
|
if(version < tag)
|
||||||
|
QMessageBox::information(this, tr("Update check"), tr("You have newest version"));
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if(QMessageBox::question(this, tr("Update check"), tr("New version %1 is available. Do you want to download it now?").arg(tag)) == QMessageBox::Yes)
|
||||||
|
{
|
||||||
|
QUrl url(json.object().value("html_url").toString());
|
||||||
|
qDebug() << url;
|
||||||
|
if(url.host() == "gitea.nouspiro.space")
|
||||||
|
QDesktopServices::openUrl(url);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
QMessageBox::warning(this, tr("Update check"), tr("Failed to check version"));
|
||||||
|
}
|
||||||
|
|
||||||
|
reply->deleteLater();
|
||||||
|
manager->deleteLater();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
void MainWindow::updateWindowTitle()
|
void MainWindow::updateWindowTitle()
|
||||||
{
|
{
|
||||||
ImagePtr ptr = m_ringList->currentImage();
|
ImagePtr ptr = m_ringList->currentImage();
|
||||||
|
|||||||
@@ -65,6 +65,7 @@ protected slots:
|
|||||||
void showMarkFilesDialog();
|
void showMarkFilesDialog();
|
||||||
void showSettingsDialog();
|
void showSettingsDialog();
|
||||||
void exportCSV();
|
void exportCSV();
|
||||||
|
void checkNewVersion();
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // MAINWINDOW_H
|
#endif // MAINWINDOW_H
|
||||||
|
|||||||
Reference in New Issue
Block a user