mirror of
https://github.com/arcan1s/awesome-widgets.git
synced 2025-04-25 07:57:19 +00:00
replace own workaround for version checking to QVersionNumber
QVersionNumber has been introduced since Qt-5.6 and it is better to use it instead of custom version checking
This commit is contained in:
parent
fa795121aa
commit
7d1e035240
@ -37,7 +37,7 @@ AWUpdateHelper::AWUpdateHelper(QObject *parent)
|
|||||||
{
|
{
|
||||||
qCDebug(LOG_AW) << __PRETTY_FUNCTION__;
|
qCDebug(LOG_AW) << __PRETTY_FUNCTION__;
|
||||||
|
|
||||||
m_foundVersion = QString(VERSION);
|
m_foundVersion = QVersionNumber::fromString(VERSION);
|
||||||
m_genericConfig = QString("%1/awesomewidgets/general.ini")
|
m_genericConfig = QString("%1/awesomewidgets/general.ini")
|
||||||
.arg(QStandardPaths::writableLocation(
|
.arg(QStandardPaths::writableLocation(
|
||||||
QStandardPaths::GenericDataLocation));
|
QStandardPaths::GenericDataLocation));
|
||||||
@ -69,14 +69,14 @@ void AWUpdateHelper::checkUpdates(const bool showAnyway)
|
|||||||
bool AWUpdateHelper::checkVersion()
|
bool AWUpdateHelper::checkVersion()
|
||||||
{
|
{
|
||||||
QSettings settings(m_genericConfig, QSettings::IniFormat);
|
QSettings settings(m_genericConfig, QSettings::IniFormat);
|
||||||
QString version
|
QVersionNumber version
|
||||||
= settings.value(QString("Version"), QString(VERSION)).toString();
|
= QVersionNumber::fromString(settings.value(QString("Version"), QString(VERSION)).toString());
|
||||||
// update version
|
// update version
|
||||||
settings.setValue(QString("Version"), QString(VERSION));
|
settings.setValue(QString("Version"), QString(VERSION));
|
||||||
settings.sync();
|
settings.sync();
|
||||||
|
|
||||||
qCInfo(LOG_AW) << "Found version" << version << "actual one is" << VERSION;
|
qCInfo(LOG_AW) << "Found version" << version << "actual one is" << VERSION;
|
||||||
if (version != QString(VERSION)) {
|
if (version != QVersionNumber::fromString(VERSION)) {
|
||||||
genMessageBox(i18n("Changelog of %1", QString(VERSION)),
|
genMessageBox(i18n("Changelog of %1", QString(VERSION)),
|
||||||
QString(CHANGELOG).replace(QChar('@'), QChar('\n')),
|
QString(CHANGELOG).replace(QChar('@'), QChar('\n')),
|
||||||
QMessageBox::Ok)
|
QMessageBox::Ok)
|
||||||
@ -90,11 +90,11 @@ bool AWUpdateHelper::checkVersion()
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void AWUpdateHelper::showInfo(const QString version)
|
void AWUpdateHelper::showInfo(const QVersionNumber version)
|
||||||
{
|
{
|
||||||
qCDebug(LOG_AW) << "Version" << version;
|
qCDebug(LOG_AW) << "Version" << version;
|
||||||
|
|
||||||
QString text = i18n("You are using the actual version %1", version);
|
QString text = i18n("You are using the actual version %1", version.toString());
|
||||||
if (!QString(COMMIT_SHA).isEmpty())
|
if (!QString(COMMIT_SHA).isEmpty())
|
||||||
text += QString(" (%1)").arg(QString(COMMIT_SHA));
|
text += QString(" (%1)").arg(QString(COMMIT_SHA));
|
||||||
return genMessageBox(i18n("No new version found"), text, QMessageBox::Ok)
|
return genMessageBox(i18n("No new version found"), text, QMessageBox::Ok)
|
||||||
@ -102,7 +102,7 @@ void AWUpdateHelper::showInfo(const QString version)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void AWUpdateHelper::showUpdates(const QString version)
|
void AWUpdateHelper::showUpdates(const QVersionNumber version)
|
||||||
{
|
{
|
||||||
qCDebug(LOG_AW) << "Version" << version;
|
qCDebug(LOG_AW) << "Version" << version;
|
||||||
|
|
||||||
@ -111,7 +111,7 @@ void AWUpdateHelper::showUpdates(const QString version)
|
|||||||
text += QString(COMMIT_SHA).isEmpty()
|
text += QString(COMMIT_SHA).isEmpty()
|
||||||
? QString("\n")
|
? QString("\n")
|
||||||
: QString(" (%1)\n").arg(QString(COMMIT_SHA));
|
: QString(" (%1)\n").arg(QString(COMMIT_SHA));
|
||||||
text += i18n("New version : %1", version) + QString("\n\n");
|
text += i18n("New version : %1", version.toString()) + QString("\n\n");
|
||||||
text += i18n("Click \"Ok\" to download");
|
text += i18n("Click \"Ok\" to download");
|
||||||
|
|
||||||
genMessageBox(i18n("There are updates"), text,
|
genMessageBox(i18n("There are updates"), text,
|
||||||
@ -127,7 +127,7 @@ void AWUpdateHelper::userReplyOnUpdates(QAbstractButton *button)
|
|||||||
|
|
||||||
switch (ret) {
|
switch (ret) {
|
||||||
case QMessageBox::Ok:
|
case QMessageBox::Ok:
|
||||||
QDesktopServices::openUrl(QString(RELEASES) + m_foundVersion);
|
QDesktopServices::openUrl(QString(RELEASES) + m_foundVersion.toString());
|
||||||
break;
|
break;
|
||||||
case QMessageBox::Cancel:
|
case QMessageBox::Cancel:
|
||||||
default:
|
default:
|
||||||
@ -155,23 +155,14 @@ void AWUpdateHelper::versionReplyRecieved(QNetworkReply *reply,
|
|||||||
QVariantMap firstRelease = jsonDoc.toVariant().toList().first().toMap();
|
QVariantMap firstRelease = jsonDoc.toVariant().toList().first().toMap();
|
||||||
QString version = firstRelease[QString("tag_name")].toString();
|
QString version = firstRelease[QString("tag_name")].toString();
|
||||||
version.remove(QString("V."));
|
version.remove(QString("V."));
|
||||||
m_foundVersion = version;
|
m_foundVersion = QVersionNumber::fromString(version);
|
||||||
qCInfo(LOG_AW) << "Update found version to" << m_foundVersion;
|
qCInfo(LOG_AW) << "Update found version to" << m_foundVersion;
|
||||||
|
|
||||||
// FIXME: possible there is a better way to check versions
|
QVersionNumber oldVersion = QVersionNumber::fromString(VERSION);
|
||||||
int old_major = QString(VERSION).split(QChar('.')).at(0).toInt();
|
if (oldVersion < m_foundVersion)
|
||||||
int old_minor = QString(VERSION).split(QChar('.')).at(1).toInt();
|
return showUpdates(m_foundVersion);
|
||||||
int old_patch = QString(VERSION).split(QChar('.')).at(2).toInt();
|
|
||||||
int new_major = version.split(QChar('.')).at(0).toInt();
|
|
||||||
int new_minor = version.split(QChar('.')).at(1).toInt();
|
|
||||||
int new_patch = version.split(QChar('.')).at(2).toInt();
|
|
||||||
if ((old_major < new_major)
|
|
||||||
|| ((old_major == new_major) && (old_minor < new_minor))
|
|
||||||
|| ((old_major == new_major) && (old_minor == new_minor)
|
|
||||||
&& (old_patch < new_patch)))
|
|
||||||
return showUpdates(version);
|
|
||||||
else if (showAnyway)
|
else if (showAnyway)
|
||||||
return showInfo(version);
|
return showInfo(m_foundVersion);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -21,6 +21,7 @@
|
|||||||
|
|
||||||
#include <QMessageBox>
|
#include <QMessageBox>
|
||||||
#include <QObject>
|
#include <QObject>
|
||||||
|
#include <QVersionNumber>
|
||||||
|
|
||||||
|
|
||||||
class QNetworkReply;
|
class QNetworkReply;
|
||||||
@ -36,15 +37,15 @@ public:
|
|||||||
bool checkVersion();
|
bool checkVersion();
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void showInfo(const QString version);
|
void showInfo(const QVersionNumber version);
|
||||||
void showUpdates(const QString version);
|
void showUpdates(const QVersionNumber version);
|
||||||
void userReplyOnUpdates(QAbstractButton *button);
|
void userReplyOnUpdates(QAbstractButton *button);
|
||||||
void versionReplyRecieved(QNetworkReply *reply, const bool showAnyway);
|
void versionReplyRecieved(QNetworkReply *reply, const bool showAnyway);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QMessageBox *genMessageBox(const QString title, const QString body,
|
QMessageBox *genMessageBox(const QString title, const QString body,
|
||||||
const QMessageBox::StandardButtons buttons);
|
const QMessageBox::StandardButtons buttons);
|
||||||
QString m_foundVersion;
|
QVersionNumber m_foundVersion;
|
||||||
QString m_genericConfig;
|
QString m_genericConfig;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user