Commit bf5ab44a authored by Pekka Vuorela's avatar Pekka Vuorela

Use QString::clear() & isEmpty() instead of empty string operations etc

parent 0d8b99f6
...@@ -292,7 +292,7 @@ void Ssu::requestFinished(QNetworkReply *reply) ...@@ -292,7 +292,7 @@ void Ssu::requestFinished(QNetworkReply *reply)
/// @TODO: indicate that the device is not registered if there's a 404 on credentials update url /// @TODO: indicate that the device is not registered if there's a 404 on credentials update url
if (settings->contains("home-url")) { if (settings->contains("home-url")) {
QString homeUrl = settings->value("home-url").toString().arg(""); QString homeUrl = settings->value("home-url").toString().arg(QString());
homeUrl.remove(QRegExp("//+$")); homeUrl.remove(QRegExp("//+$"));
if (request.url().toString().startsWith(homeUrl, Qt::CaseInsensitive)) { if (request.url().toString().startsWith(homeUrl, Qt::CaseInsensitive)) {
...@@ -401,7 +401,7 @@ void Ssu::sendRegistration(QString usernameDomain, QString password) ...@@ -401,7 +401,7 @@ void Ssu::sendRegistration(QString usernameDomain, QString password)
} }
QString IMEI = deviceInfo.deviceUid(); QString IMEI = deviceInfo.deviceUid();
if (IMEI == "") { if (IMEI.isEmpty()) {
setError("No valid UID available for your device. For phones: is your modem online?"); setError("No valid UID available for your device. For phones: is your modem online?");
return; return;
} }
...@@ -484,7 +484,7 @@ bool Ssu::setCredentials(QDomDocument *response) ...@@ -484,7 +484,7 @@ bool Ssu::setCredentials(QDomDocument *response)
credentialScopes.append(scope); credentialScopes.append(scope);
} }
} else { } else {
setError(""); setError(QString());
return false; return false;
} }
} }
...@@ -583,7 +583,7 @@ void Ssu::updateCredentials(bool force) ...@@ -583,7 +583,7 @@ void Ssu::updateCredentials(bool force)
SsuLog *ssuLog = SsuLog::instance(); SsuLog *ssuLog = SsuLog::instance();
if (deviceInfo.deviceUid() == "") { if (deviceInfo.deviceUid().isEmpty()) {
setError("No valid UID available for your device. For phones: is your modem online?"); setError("No valid UID available for your device. For phones: is your modem online?");
return; return;
} }
......
...@@ -77,8 +77,9 @@ QString SsuCoreConfig::domain(bool pretty) ...@@ -77,8 +77,9 @@ QString SsuCoreConfig::domain(bool pretty)
return value("domain").toString().replace(":", "-"); return value("domain").toString().replace(":", "-");
else else
return value("domain").toString(); return value("domain").toString();
} else } else {
return ""; return QString();
}
} }
bool SsuCoreConfig::isRegistered() bool SsuCoreConfig::isRegistered()
......
...@@ -102,9 +102,9 @@ QString SsuDeviceInfo::adaptationVariables(const QString &adaptationName, QHash< ...@@ -102,9 +102,9 @@ QString SsuDeviceInfo::adaptationVariables(const QString &adaptationName, QHash<
void SsuDeviceInfo::clearCache() void SsuDeviceInfo::clearCache()
{ {
cachedFamily = ""; cachedFamily.clear();
cachedModel = ""; cachedModel.clear();
cachedVariant = ""; cachedVariant.clear();
} }
bool SsuDeviceInfo::contains(const QString &model) bool SsuDeviceInfo::contains(const QString &model)
...@@ -153,7 +153,7 @@ QString SsuDeviceInfo::deviceVariant(bool fallback) ...@@ -153,7 +153,7 @@ QString SsuDeviceInfo::deviceVariant(bool fallback)
cachedVariant = boardMappings->value("variants/" + deviceModel()).toString(); cachedVariant = boardMappings->value("variants/" + deviceModel()).toString();
} }
if (cachedVariant == "" && fallback) if (cachedVariant.isEmpty() && fallback)
return deviceModel(); return deviceModel();
return cachedVariant; return cachedVariant;
...@@ -325,7 +325,7 @@ QString SsuDeviceInfo::deviceUid() ...@@ -325,7 +325,7 @@ QString SsuDeviceInfo::deviceUid()
} }
ssuLog->print(LOG_CRIT, "Could not read fallback UID - returning empty string"); ssuLog->print(LOG_CRIT, "Could not read fallback UID - returning empty string");
return ""; return QString();
} }
QStringList SsuDeviceInfo::disabledRepos() QStringList SsuDeviceInfo::disabledRepos()
...@@ -357,7 +357,7 @@ QString SsuDeviceInfo::displayName(const int type) ...@@ -357,7 +357,7 @@ QString SsuDeviceInfo::displayName(const int type)
key = "/deviceDesignation"; key = "/deviceDesignation";
break; break;
default: default:
return ""; return QString();
} }
/* /*
...@@ -370,7 +370,7 @@ QString SsuDeviceInfo::displayName(const int type) ...@@ -370,7 +370,7 @@ QString SsuDeviceInfo::displayName(const int type)
if (boardMappings->contains(model + key)) if (boardMappings->contains(model + key))
value = boardMappings->value(model + key).toString(); value = boardMappings->value(model + key).toString();
else if (variant != "" && boardMappings->contains(variant + key)) else if (!variant.isEmpty() && boardMappings->contains(variant + key))
value = boardMappings->value(variant + key).toString(); value = boardMappings->value(variant + key).toString();
else if (boardMappings->contains(key)) else if (boardMappings->contains(key))
value = boardMappings->value(key).toString(); value = boardMappings->value(key).toString();
...@@ -449,13 +449,13 @@ void SsuDeviceInfo::variableSection(QString section, QHash<QString, QString> *st ...@@ -449,13 +449,13 @@ void SsuDeviceInfo::variableSection(QString section, QHash<QString, QString> *st
void SsuDeviceInfo::setDeviceModel(QString model) void SsuDeviceInfo::setDeviceModel(QString model)
{ {
if (model == "") if (model.isEmpty())
cachedModel = ""; cachedModel.clear();
else else
cachedModel = model; cachedModel = model;
cachedFamily = ""; cachedFamily.clear();
cachedVariant = ""; cachedVariant.clear();
} }
QVariant SsuDeviceInfo::value(const QString &key, const QVariant &value) QVariant SsuDeviceInfo::value(const QString &key, const QVariant &value)
......
...@@ -42,7 +42,7 @@ public: ...@@ -42,7 +42,7 @@ public:
* or as variant. If no model is provided as argument the autodetected or previously * or as variant. If no model is provided as argument the autodetected or previously
* set model is used. * set model is used.
*/ */
bool contains(const QString &model = ""); bool contains(const QString &model = QString());
/** /**
* Try to find the device family for the system this is running on. This function * Try to find the device family for the system this is running on. This function
......
...@@ -68,5 +68,5 @@ QString SsuFeatureManager::url(QString repo, bool rndRepo) ...@@ -68,5 +68,5 @@ QString SsuFeatureManager::url(QString repo, bool rndRepo)
else if (featureSettings->contains("repositories/" + repo)) else if (featureSettings->contains("repositories/" + repo))
return featureSettings->value("repositories/" + repo).toString(); return featureSettings->value("repositories/" + repo).toString();
return ""; return QString();
} }
...@@ -51,7 +51,7 @@ public: ...@@ -51,7 +51,7 @@ public:
if (keys.contains("version")) { if (keys.contains("version")) {
feature.insert("version", settings.value("version").toString()); feature.insert("version", settings.value("version").toString());
} else { } else {
feature.insert("version", QString("")); feature.insert("version", QString());
} }
features.append(feature); features.append(feature);
} }
......
...@@ -45,7 +45,7 @@ void SsuLog::print(int priority, QString message) ...@@ -45,7 +45,7 @@ void SsuLog::print(int priority, QString message)
QByteArray ba = message.toUtf8(); QByteArray ba = message.toUtf8();
const char *ca = ba.constData(); const char *ca = ba.constData();
if (sd_journal_print(priority, "ssu: %s", ca) < 0 && fallbackLogPath != "") { if (sd_journal_print(priority, "ssu: %s", ca) < 0 && !fallbackLogPath.isEmpty()) {
QFile logfile; QFile logfile;
QTextStream logstream; QTextStream logstream;
logfile.setFileName(fallbackLogPath); logfile.setFileName(fallbackLogPath);
......
...@@ -38,7 +38,7 @@ int SsuRepoManager::add(QString repo, QString repoUrl) ...@@ -38,7 +38,7 @@ int SsuRepoManager::add(QString repo, QString repoUrl)
if ((ssuSettings->deviceMode() & Ssu::AppInstallMode) == Ssu::AppInstallMode) if ((ssuSettings->deviceMode() & Ssu::AppInstallMode) == Ssu::AppInstallMode)
return -1; return -1;
if (repoUrl == "") { if (repoUrl.isEmpty()) {
// just enable a repository which has URL in repos.ini // just enable a repository which has URL in repos.ini
QStringList enabledRepos; QStringList enabledRepos;
if (ssuSettings->contains("enabled-repos")) if (ssuSettings->contains("enabled-repos"))
...@@ -72,7 +72,7 @@ QString SsuRepoManager::caCertificatePath(QString domain) ...@@ -72,7 +72,7 @@ QString SsuRepoManager::caCertificatePath(QString domain)
if (settings->contains("ca-certificate")) if (settings->contains("ca-certificate"))
return settings->value("ca-certificate").toString(); return settings->value("ca-certificate").toString();
return ""; return QString();
} }
int SsuRepoManager::disable(QString repo) int SsuRepoManager::disable(QString repo)
...@@ -309,7 +309,7 @@ void SsuRepoManager::update() ...@@ -309,7 +309,7 @@ void SsuRepoManager::update()
.arg(repo) .arg(repo)
.arg(rndMode ? "rnd" : "release"); .arg(rndMode ? "rnd" : "release");
if (url(repoName, rndMode) == "") { if (url(repoName, rndMode).isEmpty()) {
// TODO, repositories should only be disabled if they're not required // TODO, repositories should only be disabled if they're not required
// for this machine. For required repositories error is better // for this machine. For required repositories error is better
QTextStream qerr(stderr); QTextStream qerr(stderr);
......
...@@ -40,7 +40,7 @@ SsuSettings::SsuSettings(const QString &fileName, const QString &settingsDirecto ...@@ -40,7 +40,7 @@ SsuSettings::SsuSettings(const QString &fileName, const QString &settingsDirecto
void SsuSettings::merge(bool keepOld) void SsuSettings::merge(bool keepOld)
{ {
if (settingsd == "") if (settingsd.isEmpty())
return; return;
bool skipMerge = true; bool skipMerge = true;
......
...@@ -33,7 +33,7 @@ QString SsuVariables::defaultSection(SsuSettings *settings, QString section) ...@@ -33,7 +33,7 @@ QString SsuVariables::defaultSection(SsuSettings *settings, QString section)
if (settings->childGroups().contains(key)) if (settings->childGroups().contains(key))
return key; return key;
else else
return ""; return QString();
} }
QString SsuVariables::resolveString(QString pattern, QHash<QString, QString> *variables, int recursionDepth) QString SsuVariables::resolveString(QString pattern, QHash<QString, QString> *variables, int recursionDepth)
...@@ -77,7 +77,7 @@ QString SsuVariables::resolveString(QString pattern, QHash<QString, QString> *va ...@@ -77,7 +77,7 @@ QString SsuVariables::resolveString(QString pattern, QHash<QString, QString> *va
QString SsuVariables::resolveVariable(QString variable, QHash<QString, QString> *variables) QString SsuVariables::resolveVariable(QString variable, QHash<QString, QString> *variables)
{ {
QString variableValue = ""; QString variableValue;
if (variable.endsWith(")")) if (variable.endsWith(")"))
variable.chop(1); variable.chop(1);
...@@ -105,12 +105,12 @@ QString SsuVariables::resolveVariable(QString variable, QHash<QString, QString> ...@@ -105,12 +105,12 @@ QString SsuVariables::resolveVariable(QString variable, QHash<QString, QString>
switch (op.toLatin1()) { switch (op.toLatin1()) {
case '-': case '-':
// substitute default value if variable is empty // substitute default value if variable is empty
if (variableValue == "") if (variableValue.isEmpty())
return variableSub.toString(); return variableSub.toString();
break; break;
case '+': case '+':
// substitute default value if variable is not empty // substitute default value if variable is not empty
if (variableValue != "") if (!variableValue.isEmpty())
return variableSub.toString(); return variableSub.toString();
break; break;
case '=': { case '=': {
......
...@@ -340,7 +340,7 @@ void SsuCli::optRepos(QStringList opt) ...@@ -340,7 +340,7 @@ void SsuCli::optRepos(QStringList opt)
SsuRepoManager repoManager; SsuRepoManager repoManager;
SsuDeviceInfo deviceInfo; SsuDeviceInfo deviceInfo;
QHash<QString, QString> repoParameters, repoOverride; QHash<QString, QString> repoParameters, repoOverride;
QString device = ""; QString device;
bool rndRepo = false; bool rndRepo = false;
int micMode = 0, flagStart = 0; int micMode = 0, flagStart = 0;
...@@ -397,7 +397,7 @@ void SsuCli::optRepos(QStringList opt) ...@@ -397,7 +397,7 @@ void SsuCli::optRepos(QStringList opt)
rndRepo = false; rndRepo = false;
} }
if (device != "") { if (!device.isEmpty()) {
deviceInfo.setDeviceModel(device); deviceInfo.setDeviceModel(device);
repoOverride.insert("model", device); repoOverride.insert("model", device);
} }
...@@ -459,7 +459,7 @@ void SsuCli::optRepos(QStringList opt) ...@@ -459,7 +459,7 @@ void SsuCli::optRepos(QStringList opt)
} }
if (i == 0) { if (i == 0) {
if (device != "") { if (!device.isEmpty()) {
repos.clear(); repos.clear();
continue; continue;
} }
...@@ -473,7 +473,7 @@ void SsuCli::optRepos(QStringList opt) ...@@ -473,7 +473,7 @@ void SsuCli::optRepos(QStringList opt)
qout << endl << "Disabled repositories (global): " << endl; qout << endl << "Disabled repositories (global): " << endl;
} else if (i == 2) { } else if (i == 2) {
repos.clear(); repos.clear();
if (device != "") if (!device.isEmpty())
continue; continue;
if (ssuSettings->contains("disabled-repos")) if (ssuSettings->contains("disabled-repos"))
repos.append(ssuSettings->value("disabled-repos").toStringList()); repos.append(ssuSettings->value("disabled-repos").toStringList());
...@@ -553,7 +553,7 @@ void SsuCli::optStatus(QStringList opt) ...@@ -553,7 +553,7 @@ void SsuCli::optStatus(QStringList opt)
qout << "Device model: " << deviceInfo.displayName(Ssu::DeviceModel) << " (" qout << "Device model: " << deviceInfo.displayName(Ssu::DeviceModel) << " ("
<< deviceInfo.deviceModel() << " / " << deviceInfo.deviceModel() << " / "
<< deviceInfo.displayName(Ssu::DeviceDesignation) << ")" << endl; << deviceInfo.displayName(Ssu::DeviceDesignation) << ")" << endl;
if (deviceInfo.deviceVariant() != "") if (!deviceInfo.deviceVariant().isEmpty())
qout << "Device variant: " << deviceInfo.deviceVariant() << endl; qout << "Device variant: " << deviceInfo.deviceVariant() << endl;
qout << "Device UID: " << deviceUid << endl; qout << "Device UID: " << deviceUid << endl;
if ((ssu.deviceMode() & Ssu::RndMode) == Ssu::RndMode) if ((ssu.deviceMode() & Ssu::RndMode) == Ssu::RndMode)
......
...@@ -112,7 +112,7 @@ QStringList SsuKickstarter::repos() ...@@ -112,7 +112,7 @@ QStringList SsuKickstarter::repos()
foreach (const QString &repo, repos) { foreach (const QString &repo, repos) {
QString repoUrl = ssu.repoUrl(repo, rndMode, QHash<QString, QString>(), repoOverride); QString repoUrl = ssu.repoUrl(repo, rndMode, QHash<QString, QString>(), repoOverride);
if (repoUrl == "") { if (repoUrl.isEmpty()) {
qerr << "Repository " << repo << " does not have an URL, ignoring" << endl; qerr << "Repository " << repo << " does not have an URL, ignoring" << endl;
continue; continue;
} }
...@@ -124,18 +124,18 @@ QStringList SsuKickstarter::repos() ...@@ -124,18 +124,18 @@ QStringList SsuKickstarter::repos()
.arg(repo) .arg(repo)
.arg(replaceSpaces(deviceModel)) .arg(replaceSpaces(deviceModel))
.arg((rndMode ? repoOverride.value("rndRelease") .arg((rndMode ? repoOverride.value("rndRelease")
: repoOverride.value("release"))) : repoOverride.value("release")))
.arg((rndMode ? "-" + repoOverride.value("flavourName") .arg((rndMode ? "-" + repoOverride.value("flavourName")
: "")) : QString()))
.arg(repoUrl) .arg(repoUrl)
); );
} else { } else {
result.append(QString("repo --name=%1-%2%3 --baseurl=%4") result.append(QString("repo --name=%1-%2%3 --baseurl=%4")
.arg(repo) .arg(repo)
.arg((rndMode ? repoOverride.value("rndRelease") .arg((rndMode ? repoOverride.value("rndRelease")
: repoOverride.value("release"))) : repoOverride.value("release")))
.arg((rndMode ? "-" + repoOverride.value("flavourName") .arg((rndMode ? "-" + repoOverride.value("flavourName")
: "")) : QString()))
.arg(repoUrl) .arg(repoUrl)
); );
} }
......
...@@ -36,7 +36,7 @@ private: ...@@ -36,7 +36,7 @@ private:
QString deviceModel; QString deviceModel;
QStringList commands(); QStringList commands();
/// read a command section from file system /// read a command section from file system
QStringList commandSection(const QString &section, const QString &description = ""); QStringList commandSection(const QString &section, const QString &description = QString());
QStringList packagesSection(QString name); QStringList packagesSection(QString name);
QString replaceSpaces(const QString &value); QString replaceSpaces(const QString &value);
QStringList repos(); QStringList repos();
......
...@@ -53,7 +53,7 @@ bool SsuUrlResolver::writeZyppCredentialsIfNeeded(QString credentialsScope) ...@@ -53,7 +53,7 @@ bool SsuUrlResolver::writeZyppCredentialsIfNeeded(QString credentialsScope)
QPair<QString, QString> credentials = ssu.credentials(credentialsScope); QPair<QString, QString> credentials = ssu.credentials(credentialsScope);
SsuLog *ssuLog = SsuLog::instance(); SsuLog *ssuLog = SsuLog::instance();
if (credentials.first == "" || credentials.second == "") { if (credentials.first.isEmpty() || credentials.second.isEmpty()) {
ssuLog->print(LOG_WARNING, "Returned credentials are empty, skip writing"); ssuLog->print(LOG_WARNING, "Returned credentials are empty, skip writing");
return false; return false;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment