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