From e2f71e6fb3b5f1d48d9bd343c7c10556d2ca2fef Mon Sep 17 00:00:00 2001 From: Camila Ayres Date: Mon, 3 Jun 2024 16:08:59 +0200 Subject: [PATCH] Modernize ConfigFile::updateChannel and Updater::getQueryParams. Signed-off-by: Camila Ayres --- src/gui/updater/updater.cpp | 21 +++++++++------------ src/libsync/configfile.cpp | 8 ++++---- 2 files changed, 13 insertions(+), 16 deletions(-) diff --git a/src/gui/updater/updater.cpp b/src/gui/updater/updater.cpp index 4365ae583..6f5f3970a 100644 --- a/src/gui/updater/updater.cpp +++ b/src/gui/updater/updater.cpp @@ -75,9 +75,7 @@ QUrl Updater::updateUrl() QUrlQuery Updater::getQueryParams() { - QUrlQuery query; - Theme *theme = Theme::instance(); - QString platform = QStringLiteral("stranger"); + auto platform = QStringLiteral("stranger"); if (Utility::isLinux()) { platform = QStringLiteral("linux"); } else if (Utility::isBSD()) { @@ -88,8 +86,8 @@ QUrlQuery Updater::getQueryParams() platform = QStringLiteral("macos"); } - QString sysInfo = getSystemInfo(); - if (!sysInfo.isEmpty()) { + QUrlQuery query; + if (const auto sysInfo = getSystemInfo(); !sysInfo.isEmpty()) { query.addQueryItem(QStringLiteral("client"), sysInfo); } query.addQueryItem(QStringLiteral("version"), clientVersion()); @@ -97,21 +95,20 @@ QUrlQuery Updater::getQueryParams() query.addQueryItem(QStringLiteral("osRelease"), QSysInfo::productType()); query.addQueryItem(QStringLiteral("osVersion"), QSysInfo::productVersion()); query.addQueryItem(QStringLiteral("kernelVersion"), QSysInfo::kernelVersion()); - query.addQueryItem(QStringLiteral("oem"), theme->appName()); + query.addQueryItem(QStringLiteral("oem"), Theme::instance()->appName()); query.addQueryItem(QStringLiteral("buildArch"), QSysInfo::buildCpuArchitecture()); query.addQueryItem(QStringLiteral("currentArch"), QSysInfo::currentCpuArchitecture()); - QString suffix = QStringLiteral(MIRALL_STRINGIFY(MIRALL_VERSION_SUFFIX)); + const auto suffix = QStringLiteral(MIRALL_STRINGIFY(MIRALL_VERSION_SUFFIX)); query.addQueryItem(QStringLiteral("versionsuffix"), suffix); - auto channel = ConfigFile().updateChannel(); - if (channel != QLatin1String("stable")) { + ConfigFile config; + if (const auto channel = config.updateChannel(); + channel != QLatin1String("stable")) { query.addQueryItem(QStringLiteral("channel"), channel); } - // updateSegment (see configfile.h) - ConfigFile cfg; - auto updateSegment = cfg.updateSegment(); + const auto updateSegment = config.updateSegment(); query.addQueryItem(QLatin1String("updatesegment"), QString::number(updateSegment)); return query; diff --git a/src/libsync/configfile.cpp b/src/libsync/configfile.cpp index f70dfe2b3..ca2f3eadc 100644 --- a/src/libsync/configfile.cpp +++ b/src/libsync/configfile.cpp @@ -686,9 +686,9 @@ int ConfigFile::updateSegment() const QString ConfigFile::updateChannel() const { - QString defaultUpdateChannel = QStringLiteral("stable"); - QString suffix = QString::fromLatin1(MIRALL_STRINGIFY(MIRALL_VERSION_SUFFIX)); - if (suffix.startsWith("daily") + auto defaultUpdateChannel = QStringLiteral("stable"); + if (const auto suffix = QString::fromLatin1(MIRALL_STRINGIFY(MIRALL_VERSION_SUFFIX)); + suffix.startsWith("daily") || suffix.startsWith("nightly") || suffix.startsWith("alpha") || suffix.startsWith("rc") @@ -699,7 +699,7 @@ QString ConfigFile::updateChannel() const QSettings settings(configFile(), QSettings::IniFormat); const auto channel = settings.value(QLatin1String(updateChannelC), defaultUpdateChannel).toString(); if (!validUpdateChannels().contains(channel)) { - qCWarning(lcConfigFile()) << "Received invalid update channel from confog:" + qCWarning(lcConfigFile()) << "Received invalid update channel from config:" << channel << "defaulting to:" << defaultUpdateChannel;