From 973b167031c0727bea86342dc18f858276f61970 Mon Sep 17 00:00:00 2001 From: zomfg <239811+zomfg@users.noreply.github.com> Date: Sun, 15 Nov 2020 18:34:52 +0100 Subject: [PATCH 1/4] update processor: use gh api / removed xml --- Software/src/UpdatesProcessor.cpp | 159 +++++------------------ Software/src/UpdatesProcessor.hpp | 91 +------------ Software/src/systrayicon/SysTrayIcon.cpp | 11 +- 3 files changed, 41 insertions(+), 220 deletions(-) diff --git a/Software/src/UpdatesProcessor.cpp b/Software/src/UpdatesProcessor.cpp index 468e0a09a..3f3c14a01 100644 --- a/Software/src/UpdatesProcessor.cpp +++ b/Software/src/UpdatesProcessor.cpp @@ -25,20 +25,20 @@ */ #include -#include #include +#include +#include +#include #include #include #include -#include "version.h" #include "debug.h" #include "UpdatesProcessor.hpp" #include "Settings.hpp" -//#define UPDATE_CHECK_URL "https://psieg.de/lightpack/update.xml" -#define UPDATE_CHECK_URL "https://psieg.github.io/Lightpack/update.xml" - -const AppVersion kCurVersion(VERSION_STR); +// #define UPDATE_CHECK_URL "https://psieg.de/lightpack/update.xml" +// #define UPDATE_CHECK_URL "https://psieg.github.io/Lightpack/update.xml" +#define UPDATE_CHECK_URL "https://api.github.com/repos/psieg/Lightpack/releases/latest" UpdatesProcessor::UpdatesProcessor(QObject * parent) : QObject(parent) @@ -61,37 +61,38 @@ void UpdatesProcessor::requestUpdates() } QNetworkRequest request(QUrl(UPDATE_CHECK_URL)); + request.setHeader(QNetworkRequest::UserAgentHeader, QVariant("psieg/Lightpack")); request.setSslConfiguration(QSslConfiguration::defaultConfiguration()); _reply = _networkMan.get(request); connect(_reply, SIGNAL(finished()), this, SIGNAL(readyRead())); connect(_reply, SIGNAL(error(QNetworkReply::NetworkError)), this, SLOT(error(QNetworkReply::NetworkError))); } -QList UpdatesProcessor::readUpdates() +UpdateInfo UpdatesProcessor::readUpdates() { - QList updates; - - QXmlStreamReader xmlReader(_reply->readAll()); - - if (xmlReader.readNextStartElement()) { - if (xmlReader.name() == "updates") { - readUpdates(&updates, &xmlReader); - QList::iterator it = updates.begin(); - while (it != updates.end()) { - UpdateInfo updateInfo = *it; - if (!updateInfo.softwareVersion.isEmpty() && !isVersionMatches(updateInfo.softwareVersion, kCurVersion)) { - updates.removeAll(updateInfo); - } else { - it++; - } - } - } + const QJsonObject& releaseObject = QJsonDocument::fromJson(_reply->readAll()).object(); + + UpdateInfo update; + + update.id = releaseObject.value("id").toInt(); + update.url = releaseObject.value("html_url").toString(); + update.text = releaseObject.value("body").toString(); + update.title = releaseObject.value("name").toString(); + update.softwareVersion = QVersionNumber::fromString(releaseObject.value("tag_name").toString()); + // find firmware in assets? + // update.firmwareVersion = ... + for (const QJsonValue& assetValue : releaseObject.value("assets").toArray()) { + const QJsonObject& obj = assetValue.toObject(); + if (obj.value("name").toString().endsWith(".exe")) + update.pkgUrl = obj.value("browser_download_url").toString(); + else if (obj.value("name").toString().endsWith(".exe.updater_signature")) + update.sigUrl = obj.value("browser_download_url").toString(); } - DEBUG_LOW_LEVEL << Q_FUNC_INFO << updates.size() << "updates available"; - return updates; + DEBUG_LOW_LEVEL << Q_FUNC_INFO << "latest available version" << update.softwareVersion; + return update; } -void UpdatesProcessor::loadUpdate(UpdateInfo& info) +void UpdatesProcessor::loadUpdate(const UpdateInfo& info) { #ifdef Q_OS_WIN DEBUG_MID_LEVEL << Q_FUNC_INFO << "fetching" << info.pkgUrl; @@ -121,6 +122,7 @@ void UpdatesProcessor::loadUpdate(UpdateInfo& info) connect(_reply, SIGNAL(finished()), this, SLOT(updatePgkLoaded())); connect(_reply, SIGNAL(error(QNetworkReply::NetworkError)), this, SLOT(error(QNetworkReply::NetworkError))); #else + Q_UNUSED(info) qWarning() << Q_FUNC_INFO << "Trying to load update on non-windows platform -- ignored"; #endif } @@ -189,106 +191,3 @@ void UpdatesProcessor::updateSigLoaded() } } #endif - -bool UpdatesProcessor::isVersionMatches(const QString &predicate, const AppVersion &version) -{ - enum Condition { - LT, - GT, - EQ, - LE, - GE - }; - - Condition cond; - QStringRef predicateRef(&predicate); - - QStringRef predicateVerStr = predicateRef.mid(2).trimmed(); - - QStringRef condStr = predicateRef.left(2); - - if (condStr == "lt") { - cond = LT; - } else if (condStr == "gt") { - cond = GT; - } else if (condStr == "eq") { - cond = EQ; - } else if (condStr == "le") { - cond = LE; - } else if (condStr == "ge") { - cond = GE; - } else { - cond = EQ; - predicateVerStr = predicateRef.trimmed(); - } - - AppVersion predicateVer(predicateVerStr.toString()); - - if (!version.isValid() || !predicateVer.isValid()) - return false; - - switch (cond) { - case LT: - return version < predicateVer; - break; - case GT: - return version > predicateVer; - break; - case EQ: - return version == predicateVer; - break; - case LE: - return version <= predicateVer; - break; - case GE: - return version >= predicateVer; - break; - } - - Q_ASSERT(false); - return false; -} - -QList * UpdatesProcessor::readUpdates(QList *updates, QXmlStreamReader *xmlReader) -{ - if (xmlReader->readNextStartElement()) { - while (xmlReader->name() == "update") { - UpdateInfo updateInfo; - while(xmlReader->readNextStartElement()) { - if (xmlReader->name() == "id") { - xmlReader->readNext(); - QStringRef id = xmlReader->text(); - updateInfo.id = id.toUInt(); - } else if (xmlReader->name() == "url") { - xmlReader->readNext(); - updateInfo.url = xmlReader->text().toString(); - } else if (xmlReader->name() == "pkgUrl") { - xmlReader->readNext(); - updateInfo.pkgUrl = xmlReader->text().toString(); - } else if (xmlReader->name() == "sigUrl") { - xmlReader->readNext(); - updateInfo.sigUrl = xmlReader->text().toString(); - } else if (xmlReader->name() == "title") { - xmlReader->readNext(); - updateInfo.title = xmlReader->text().toString(); - } else if (xmlReader->name() == "text") { - xmlReader->readNext(); - updateInfo.text = xmlReader->text().toString(); - } else if (xmlReader->name() == "softwareVersion") { - xmlReader->readNext(); - updateInfo.softwareVersion = xmlReader->text().toString(); - } else if (xmlReader->name() == "firmwareVersion") { - xmlReader->readNext(); - updateInfo.firmwareVersion = xmlReader->text().toString(); - } else if (xmlReader->name() == "update") { - break; - } - xmlReader->skipCurrentElement(); - } - // add updates with defined id only - if(updateInfo.id > 0) - updates->append(updateInfo); - } - } - return updates; -} diff --git a/Software/src/UpdatesProcessor.hpp b/Software/src/UpdatesProcessor.hpp index 795e55794..b74f7624a 100644 --- a/Software/src/UpdatesProcessor.hpp +++ b/Software/src/UpdatesProcessor.hpp @@ -32,87 +32,9 @@ #include #include #include +#include class QNetworkReply; -class QXmlStreamReader; - -class AppVersion -{ -public: - AppVersion() - : _major(0) - , _minor(0) - , _rc(0) - , _build(0) - {} - - AppVersion(const QString &version) - { - initWith(version); - } - - void initWith(const QString &version) - { - QStringList splittedVer = version.split("."); - if (splittedVer.size() > 4 || splittedVer.size() < 1) - { - return; - } - - _major = splittedVer[0].toInt(); - _minor = splittedVer.size() > 1 ? splittedVer[1].toInt() : 0; - _rc = splittedVer.size() > 2 ? splittedVer[2].toInt() : 0; - _build = splittedVer.size() > 3 ? splittedVer[3].toInt() : 0; - } - - bool isValid() const { - return _major != 0 || _minor != 0 || _rc != 0 || _build != 0; - } - - int compare(const AppVersion &other) const { - int dmj = this->_major - other._major; - if (dmj != 0) - return dmj; - int dmn = this->_minor - other._minor; - if (dmn != 0) - return dmn; - int drc = this->_rc - other._rc; - if (drc != 0) - return drc; - int dbuild = this->_build - other._build; - return dbuild; - } - - bool operator== (const AppVersion &other) const { - return this->compare(other) == 0; - } - - bool operator!= (const AppVersion &other) const { - return this->compare(other) != 0; - } - - bool operator< (const AppVersion &other) const { - return this->compare(other) < 0; - } - - bool operator> (const AppVersion &other) const { - return this->compare(other) > 0; - } - - bool operator>= (const AppVersion &other) const { - return *this > other || *this == other ; - } - - bool operator<= (const AppVersion &other) const { - return *this < other || *this == other ; - } - -private: - uint _major; - uint _minor; - uint _rc; - uint _build; -}; struct UpdateInfo { @@ -129,8 +51,8 @@ struct UpdateInfo QString sigUrl; QString title; QString text; - QString softwareVersion; - QString firmwareVersion; + QVersionNumber softwareVersion; + // QVersionNumber firmwareVersion; bool operator== (const UpdateInfo &other) const { return this->id == other.id; @@ -147,8 +69,8 @@ class UpdatesProcessor: public QObject public: UpdatesProcessor(QObject * parent = NULL); void requestUpdates(); - QList readUpdates(); - void loadUpdate(UpdateInfo& info); + UpdateInfo readUpdates(); + void loadUpdate(const UpdateInfo& info); signals: void readyRead(); @@ -161,9 +83,6 @@ private slots: #endif private: - QList * readUpdates(QList * readUpdates, QXmlStreamReader * xmlReader); - bool isVersionMatches(const QString &predicate, const AppVersion &version); - QNetworkAccessManager _networkMan; QNetworkReply * _reply; QString _sigUrl; diff --git a/Software/src/systrayicon/SysTrayIcon.cpp b/Software/src/systrayicon/SysTrayIcon.cpp index 2ab1a86b3..7514a207e 100644 --- a/Software/src/systrayicon/SysTrayIcon.cpp +++ b/Software/src/systrayicon/SysTrayIcon.cpp @@ -30,6 +30,7 @@ #include #include #include "Settings.hpp" +#include "version.h" SysTrayIcon::SysTrayIcon(QObject *parent) : QObject(parent) @@ -219,14 +220,16 @@ void SysTrayIcon::updateProfiles() void SysTrayIcon::onCheckUpdate_Finished() { using namespace SettingsScope; - QList updates = _updatesProcessor.readUpdates(); - if (updates.size() > 0) { - if (updates.size() > 1) { + const UpdateInfo& update = _updatesProcessor.readUpdates(); + const QVersionNumber& thisVersion = QVersionNumber::fromString(VERSION_STR); + const int versionDifference = QVersionNumber::compare(update.softwareVersion, thisVersion); + + if (versionDifference > 0) { + if (versionDifference > 1) { _trayMessage = SysTrayIcon::MessageGeneric; _trayMsgUrl = QUrl("https://github.com/psieg/Lightpack/releases"); _qsystray->showMessage("Multiple updates are available", "Click to open the downloads page"); } else { - UpdateInfo& update = updates.last(); #ifdef Q_OS_WIN if (Settings::isInstallUpdatesEnabled() && !update.pkgUrl.isEmpty() && !update.sigUrl.isEmpty()) { _trayMessage = SysTrayIcon::MessageNoAction; From 31993ceb75f8bbb91a9d551aec6201174bdbd8b2 Mon Sep 17 00:00:00 2001 From: zomfg <239811+zomfg@users.noreply.github.com> Date: Sun, 15 Nov 2020 18:35:58 +0100 Subject: [PATCH 2/4] test project: removed AppVersion --- Software/tests/AppVersionTest.cpp | 73 ------------------------------- Software/tests/AppVersionTest.hpp | 45 ------------------- Software/tests/TestsMain.cpp | 2 - Software/tests/tests.pro | 2 - 4 files changed, 122 deletions(-) delete mode 100644 Software/tests/AppVersionTest.cpp delete mode 100644 Software/tests/AppVersionTest.hpp diff --git a/Software/tests/AppVersionTest.cpp b/Software/tests/AppVersionTest.cpp deleted file mode 100644 index 4612807df..000000000 --- a/Software/tests/AppVersionTest.cpp +++ /dev/null @@ -1,73 +0,0 @@ -/* - * AppVersionTest.cpp - * - * Created on: 4/15/2014 - * Project: Prismatik - * - * Copyright (c) 2014 tim - * - * Lightpack is an open-source, USB content-driving ambient lighting - * hardware. - * - * Prismatik is a free, open-source software: you can redistribute it and/or - * modify it under the terms of the GNU General Public License as published - * by the Free Software Foundation, either version 2 of the License, or - * (at your option) any later version. - * - * Prismatik and Lightpack files is distributed in the hope that it will be - * useful, but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - * - */ - -#include "AppVersionTest.hpp" -#include -#include "../src/UpdatesProcessor.hpp" - -AppVersionTest::AppVersionTest() -{ -} - -void AppVersionTest::testCaseExplicitEquality() -{ - AppVersion a("5.10.7"); - AppVersion b("5.10.7"); - QVERIFY2(a == b, "Version explicit equality test failed"); - QVERIFY2(!(a != b), "Version explicit equality test failed"); -} - -void AppVersionTest::testCaseImplicitEquality() -{ - AppVersion a("5"); - AppVersion b("5.0.0"); - QVERIFY2(a == b, "Version implicit equality test failed"); - QVERIFY2(!(a != b), "Version implicit equality test failed"); -} - -void AppVersionTest::testCaseFalseEquality() -{ - AppVersion a("5.1"); - AppVersion b("5.0.0"); - QVERIFY2(a != b, "Version false equality test failed"); - QVERIFY2(!(a == b), "Version false equality test failed"); -} - -void AppVersionTest::testCaseLT() -{ - AppVersion a("5"); - AppVersion b("5.1.0"); - QVERIFY2(a < b, "Less than test failed"); - QVERIFY2(!(a > b), "Less than test failed"); -} - -void AppVersionTest::testCaseGT() -{ - AppVersion a("6.0.0.1"); - AppVersion b("5.1.0.2"); - QVERIFY2(a > b, "Greater than test failed"); - QVERIFY2(!(a < b), "Greater than test failed"); -} diff --git a/Software/tests/AppVersionTest.hpp b/Software/tests/AppVersionTest.hpp deleted file mode 100644 index beec0abe8..000000000 --- a/Software/tests/AppVersionTest.hpp +++ /dev/null @@ -1,45 +0,0 @@ -/* - * AppVersionTest.hpp - * - * Created on: 4/15/2014 - * Project: Prismatik - * - * Copyright (c) 2014 tim - * - * Lightpack is an open-source, USB content-driving ambient lighting - * hardware. - * - * Prismatik is a free, open-source software: you can redistribute it and/or - * modify it under the terms of the GNU General Public License as published - * by the Free Software Foundation, either version 2 of the License, or - * (at your option) any later version. - * - * Prismatik and Lightpack files is distributed in the hope that it will be - * useful, but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - * - */ - -#ifndef APPVERSIONTEST_HPP -#define APPVERSIONTEST_HPP - -#include - -class AppVersionTest: public QObject -{ - Q_OBJECT -public: - AppVersionTest(); -private Q_SLOTS: - void testCaseImplicitEquality(); - void testCaseExplicitEquality(); - void testCaseFalseEquality(); - void testCaseLT(); - void testCaseGT(); -}; - -#endif // APPVERSIONTEST_HPP diff --git a/Software/tests/TestsMain.cpp b/Software/tests/TestsMain.cpp index 738db92d6..de4ee22f8 100644 --- a/Software/tests/TestsMain.cpp +++ b/Software/tests/TestsMain.cpp @@ -2,7 +2,6 @@ #include "LightpackApiTest.hpp" #include "GrabCalculationTest.hpp" #include "lightpackmathtest.hpp" -#include "AppVersionTest.hpp" #ifdef Q_OS_WIN #include "HooksTest.h" #endif @@ -31,7 +30,6 @@ int main(int argc, char *argv[]) tests.append(new LightpackMathTest()); tests.append(new LightpackApiTest()); - tests.append(new AppVersionTest()); tests.append(new LightpackCommandLineParserTest()); for(int i=0; i < tests.size(); i++) { diff --git a/Software/tests/tests.pro b/Software/tests/tests.pro index 8d736d837..8e3b1fddd 100644 --- a/Software/tests/tests.pro +++ b/Software/tests/tests.pro @@ -60,7 +60,6 @@ HEADERS += \ GrabCalculationTest.hpp \ LightpackApiTest.hpp \ lightpackmathtest.hpp \ - AppVersionTest.hpp \ ../src/UpdatesProcessor.hpp \ LightpackCommandLineParserTest.hpp @@ -76,7 +75,6 @@ SOURCES += \ GrabCalculationTest.cpp \ lightpackmathtest.cpp \ TestsMain.cpp \ - AppVersionTest.cpp \ ../src/UpdatesProcessor.cpp \ LightpackCommandLineParserTest.cpp From d1df8aaa0f605a48d5caf4e232afd2355b948035 Mon Sep 17 00:00:00 2001 From: zomfg <239811+zomfg@users.noreply.github.com> Date: Sun, 15 Nov 2020 19:15:50 +0100 Subject: [PATCH 3/4] updates processor: revert version.h --- Software/src/UpdatesProcessor.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/Software/src/UpdatesProcessor.cpp b/Software/src/UpdatesProcessor.cpp index 3f3c14a01..05ea1825d 100644 --- a/Software/src/UpdatesProcessor.cpp +++ b/Software/src/UpdatesProcessor.cpp @@ -32,6 +32,7 @@ #include #include #include +#include "version.h" #include "debug.h" #include "UpdatesProcessor.hpp" #include "Settings.hpp" From 8007d4487fb183ff21da6a2501741d4f1e69af3b Mon Sep 17 00:00:00 2001 From: zomfg <239811+zomfg@users.noreply.github.com> Date: Sat, 21 Nov 2020 00:15:28 +0100 Subject: [PATCH 4/4] updates processor / sys try icon: QStringLiterals --- Software/src/UpdatesProcessor.cpp | 28 +++++++------- Software/src/systrayicon/SysTrayIcon.cpp | 48 ++++++++++++------------ 2 files changed, 38 insertions(+), 38 deletions(-) diff --git a/Software/src/UpdatesProcessor.cpp b/Software/src/UpdatesProcessor.cpp index 05ea1825d..19edec2b6 100644 --- a/Software/src/UpdatesProcessor.cpp +++ b/Software/src/UpdatesProcessor.cpp @@ -61,7 +61,7 @@ void UpdatesProcessor::requestUpdates() _reply = NULL; } - QNetworkRequest request(QUrl(UPDATE_CHECK_URL)); + QNetworkRequest request(QUrl(QStringLiteral(UPDATE_CHECK_URL))); request.setHeader(QNetworkRequest::UserAgentHeader, QVariant("psieg/Lightpack")); request.setSslConfiguration(QSslConfiguration::defaultConfiguration()); _reply = _networkMan.get(request); @@ -75,19 +75,19 @@ UpdateInfo UpdatesProcessor::readUpdates() UpdateInfo update; - update.id = releaseObject.value("id").toInt(); - update.url = releaseObject.value("html_url").toString(); - update.text = releaseObject.value("body").toString(); - update.title = releaseObject.value("name").toString(); - update.softwareVersion = QVersionNumber::fromString(releaseObject.value("tag_name").toString()); + update.id = releaseObject.value(QStringLiteral("id")).toInt(); + update.url = releaseObject.value(QStringLiteral("html_url")).toString(); + update.text = releaseObject.value(QStringLiteral("body")).toString(); + update.title = releaseObject.value(QStringLiteral("name")).toString(); + update.softwareVersion = QVersionNumber::fromString(releaseObject.value(QStringLiteral("tag_name")).toString()); // find firmware in assets? // update.firmwareVersion = ... - for (const QJsonValue& assetValue : releaseObject.value("assets").toArray()) { + for (const QJsonValue& assetValue : releaseObject.value(QStringLiteral("assets")).toArray()) { const QJsonObject& obj = assetValue.toObject(); - if (obj.value("name").toString().endsWith(".exe")) - update.pkgUrl = obj.value("browser_download_url").toString(); - else if (obj.value("name").toString().endsWith(".exe.updater_signature")) - update.sigUrl = obj.value("browser_download_url").toString(); + if (obj.value(QStringLiteral("name")).toString().endsWith(QStringLiteral(".exe"))) + update.pkgUrl = obj.value(QStringLiteral("browser_download_url")).toString(); + else if (obj.value(QStringLiteral("name")).toString().endsWith(QStringLiteral(".exe.updater_signature"))) + update.sigUrl = obj.value(QStringLiteral("browser_download_url")).toString(); } DEBUG_LOW_LEVEL << Q_FUNC_INFO << "latest available version" << update.softwareVersion; return update; @@ -136,7 +136,7 @@ void UpdatesProcessor::updatePgkLoaded() DEBUG_MID_LEVEL << Q_FUNC_INFO << "fetching " << _sigUrl; - QFile f(QDir::tempPath() + "\\PsiegUpdateElevate_Prismatik.exe"); + QFile f(QDir::tempPath() + QStringLiteral("\\PsiegUpdateElevate_Prismatik.exe")); if (!f.open(QIODevice::WriteOnly)) { qCritical() << Q_FUNC_INFO << "Failed to write update package"; } @@ -167,7 +167,7 @@ void UpdatesProcessor::updateSigLoaded() return; DEBUG_MID_LEVEL << Q_FUNC_INFO; - QFile f(QDir::tempPath() + "\\PsiegUpdateElevate_Prismatik.exe.sig"); + QFile f(QDir::tempPath() + QStringLiteral("\\PsiegUpdateElevate_Prismatik.exe.sig")); if (!f.open(QIODevice::WriteOnly)) { qCritical() << Q_FUNC_INFO << "Failed to write update signature"; } @@ -185,7 +185,7 @@ void UpdatesProcessor::updateSigLoaded() args.append("request"); args.append(QDir::tempPath()); args.append(QCoreApplication::applicationFilePath()); - if (QProcess::startDetached(QCoreApplication::applicationDirPath() + "\\UpdateElevate.exe", args)) { + if (QProcess::startDetached(QCoreApplication::applicationDirPath() + QStringLiteral("\\UpdateElevate.exe"), args)) { QCoreApplication::quit(); } else { qCritical() << Q_FUNC_INFO << "Failed to start UpdateElevate.exe"; diff --git a/Software/src/systrayicon/SysTrayIcon.cpp b/Software/src/systrayicon/SysTrayIcon.cpp index 7514a207e..13fe8f6e9 100644 --- a/Software/src/systrayicon/SysTrayIcon.cpp +++ b/Software/src/systrayicon/SysTrayIcon.cpp @@ -2,21 +2,21 @@ * SysTrayIcon.cpp * * Created on: 11/23/2013 - * Project: Prismatik + * Project: Prismatik * * Copyright (c) 2013 tim * * Lightpack is an open-source, USB content-driving ambient lighting * hardware. * - * Prismatik is a free, open-source software: you can redistribute it and/or - * modify it under the terms of the GNU General Public License as published + * Prismatik is a free, open-source software: you can redistribute it and/or + * modify it under the terms of the GNU General Public License as published * by the Free Software Foundation, either version 2 of the License, or * (at your option) any later version. * * Prismatik and Lightpack files is distributed in the hope that it will be * useful, but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * General Public License for more details. * * You should have received a copy of the GNU General Public License @@ -70,11 +70,11 @@ void SysTrayIcon::init() connect(&_updatesProcessor, SIGNAL(readyRead()), this, SLOT(onCheckUpdate_Finished())); - _pixmapCache.insert("lock32", new QPixmap(QPixmap(":/icons/lock.png").scaledToWidth(32, Qt::SmoothTransformation))); - _pixmapCache.insert("on32", new QPixmap(QPixmap(":/icons/on.png").scaledToWidth(32, Qt::SmoothTransformation))); - _pixmapCache.insert("off32", new QPixmap(QPixmap(":/icons/off.png").scaledToWidth(32, Qt::SmoothTransformation))); - _pixmapCache.insert("error32", new QPixmap(QPixmap(":/icons/error.png").scaledToWidth(32, Qt::SmoothTransformation))); - _pixmapCache.insert("persist32", new QPixmap(QPixmap(":/icons/persist.png").scaledToWidth(32, Qt::SmoothTransformation))); + _pixmapCache.insert(QStringLiteral("lock32"), new QPixmap(QPixmap(QStringLiteral(":/icons/lock.png")).scaledToWidth(32, Qt::SmoothTransformation))); + _pixmapCache.insert(QStringLiteral("on32"), new QPixmap(QPixmap(QStringLiteral(":/icons/on.png")).scaledToWidth(32, Qt::SmoothTransformation))); + _pixmapCache.insert(QStringLiteral("off32"), new QPixmap(QPixmap(QStringLiteral(":/icons/off.png")).scaledToWidth(32, Qt::SmoothTransformation))); + _pixmapCache.insert(QStringLiteral("error32"), new QPixmap(QPixmap(QStringLiteral(":/icons/error.png")).scaledToWidth(32, Qt::SmoothTransformation))); + _pixmapCache.insert(QStringLiteral("persist32"), new QPixmap(QPixmap(QStringLiteral(":/icons/persist.png")).scaledToWidth(32, Qt::SmoothTransformation))); setStatus(SysTrayIcon::StatusOn); _qsystray->show(); @@ -163,7 +163,7 @@ void SysTrayIcon::setStatus(const Status status, const QString *arg) case SysTrayIcon::StatusOn: _switchOnBacklightAction->setEnabled(false); _switchOffBacklightAction->setEnabled(true); - _qsystray->setIcon(QIcon(*_pixmapCache["on32"])); + _qsystray->setIcon(QIcon(*_pixmapCache[QStringLiteral("on32")])); if (SettingsScope::Settings::isProfileLoaded()) _qsystray->setToolTip(tr("Enabled profile: %1").arg(SettingsScope::Settings::getCurrentProfileName())); @@ -172,31 +172,31 @@ void SysTrayIcon::setStatus(const Status status, const QString *arg) case SysTrayIcon::StatusLockedByApi: _switchOnBacklightAction->setEnabled(false); _switchOffBacklightAction->setEnabled(true); - _qsystray->setIcon(QIcon(*_pixmapCache["lock32"])); + _qsystray->setIcon(QIcon(*_pixmapCache[QStringLiteral("lock32")])); _qsystray->setToolTip(tr("Device locked via API")); break; case SysTrayIcon::StatusLockedByPlugin: - _qsystray->setIcon(QIcon(*_pixmapCache["lock32"])); + _qsystray->setIcon(QIcon(*_pixmapCache[QStringLiteral("lock32")])); _qsystray->setToolTip(tr("Device locked via Plugin") + " (" + (*arg) + ")"); break; case SysTrayIcon::StatusApiPersist: _switchOnBacklightAction->setEnabled(true); _switchOffBacklightAction->setEnabled(true); - _qsystray->setIcon(QIcon(*_pixmapCache["persist32"])); + _qsystray->setIcon(QIcon(*_pixmapCache[QStringLiteral("persist32")])); _qsystray->setToolTip(tr("API colors persisted")); break; case SysTrayIcon::StatusOff: _switchOnBacklightAction->setEnabled(true); _switchOffBacklightAction->setEnabled(false); - _qsystray->setIcon(QIcon(*_pixmapCache["off32"])); + _qsystray->setIcon(QIcon(*_pixmapCache[QStringLiteral("off32")])); _qsystray->setToolTip(tr("Disabled")); break; case SysTrayIcon::StatusError: _switchOnBacklightAction->setEnabled(false); _switchOffBacklightAction->setEnabled(true); - _qsystray->setIcon(QIcon(*_pixmapCache["error32"])); + _qsystray->setIcon(QIcon(*_pixmapCache[QStringLiteral("error32")])); _qsystray->setToolTip(tr("Error with connection device, verbose in logs")); break; default: @@ -221,20 +221,20 @@ void SysTrayIcon::onCheckUpdate_Finished() { using namespace SettingsScope; const UpdateInfo& update = _updatesProcessor.readUpdates(); - const QVersionNumber& thisVersion = QVersionNumber::fromString(VERSION_STR); + const QVersionNumber& thisVersion = QVersionNumber::fromString(QStringLiteral(VERSION_STR)); const int versionDifference = QVersionNumber::compare(update.softwareVersion, thisVersion); if (versionDifference > 0) { if (versionDifference > 1) { _trayMessage = SysTrayIcon::MessageGeneric; - _trayMsgUrl = QUrl("https://github.com/psieg/Lightpack/releases"); - _qsystray->showMessage("Multiple updates are available", "Click to open the downloads page"); + _trayMsgUrl = QUrl(QStringLiteral("https://github.com/psieg/Lightpack/releases")); + _qsystray->showMessage(QStringLiteral("Multiple updates are available"), QStringLiteral("Click to open the downloads page")); } else { #ifdef Q_OS_WIN if (Settings::isInstallUpdatesEnabled() && !update.pkgUrl.isEmpty() && !update.sigUrl.isEmpty()) { _trayMessage = SysTrayIcon::MessageNoAction; _trayMsgUrl = QUrl(""); - _qsystray->showMessage("Prismatik Update", "An update is being downloaded and will be applied shortly."); + _qsystray->showMessage(QStringLiteral("Prismatik Update"), QStringLiteral("An update is being downloaded and will be applied shortly.")); _updatesProcessor.loadUpdate(update); return; } @@ -263,7 +263,7 @@ void SysTrayIcon::onTrayIcon_MessageClicked() if (SettingsScope::Settings::getConnectedDevice() == SupportedDevices::DeviceTypeLightpack) { // Open lightpack downloads page - QDesktopServices::openUrl(QUrl("https://github.com/psieg/Lightpack/releases", QUrl::TolerantMode)); + QDesktopServices::openUrl(QUrl(QStringLiteral("https://github.com/psieg/Lightpack/releases"), QUrl::TolerantMode)); } break; case SysTrayIcon::MessageGeneric: @@ -326,20 +326,20 @@ void SysTrayIcon::createActions() { DEBUG_LOW_LEVEL << Q_FUNC_INFO; - _switchOnBacklightAction = new QAction(QIcon(":/icons/on.png"), tr("&Turn on"), this); + _switchOnBacklightAction = new QAction(QIcon(QStringLiteral(":/icons/on.png")), tr("&Turn on"), this); _switchOnBacklightAction->setIconVisibleInMenu(true); connect(_switchOnBacklightAction, SIGNAL(triggered()), this, SIGNAL(backlightOn())); - _switchOffBacklightAction = new QAction(QIcon(":/icons/off.png"), tr("&Turn off"), this); + _switchOffBacklightAction = new QAction(QIcon(QStringLiteral(":/icons/off.png")), tr("&Turn off"), this); _switchOffBacklightAction->setIconVisibleInMenu(true); connect(_switchOffBacklightAction, SIGNAL(triggered()), this, SIGNAL(backlightOff())); _profilesMenu = new QMenu(tr("&Profiles")); - _profilesMenu->setIcon(QIcon(":/icons/profiles.png")); + _profilesMenu->setIcon(QIcon(QStringLiteral(":/icons/profiles.png"))); _profilesMenu->clear(); - _settingsAction = new QAction(QIcon(":/icons/settings.png"), tr("&Settings"), this); + _settingsAction = new QAction(QIcon(QStringLiteral(":/icons/settings.png")), tr("&Settings"), this); _settingsAction->setIconVisibleInMenu(true); connect(_settingsAction, SIGNAL(triggered()), this, SIGNAL(showSettings()));