Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[ssu] Use consistently const QString & on interfaces. Contributes to …
…JB#38781

Plus some similar other interface details.
  • Loading branch information
pvuorela committed May 24, 2017
1 parent bf5ab44 commit 309ebec
Show file tree
Hide file tree
Showing 22 changed files with 131 additions and 128 deletions.
2 changes: 1 addition & 1 deletion declarative/declarativessudeviceinfo.cpp
Expand Up @@ -26,7 +26,7 @@ QString DeclarativeSsuDeviceInfo::deviceModel()
return info.deviceModel();
}

QString DeclarativeSsuDeviceInfo::displayName(const int type)
QString DeclarativeSsuDeviceInfo::displayName(int type)
{
return info.displayName(type);
}
Expand Down
2 changes: 1 addition & 1 deletion declarative/declarativessudeviceinfo.h
Expand Up @@ -55,7 +55,7 @@ class DeclarativeSsuDeviceInfo : public QObject
* If no manufacturer is found UNKNOWN is returned.
* For an invalid type an empty string is returned.
*/
Q_INVOKABLE QString displayName(const int type);
Q_INVOKABLE QString displayName(int type);

private:
SsuDeviceInfo info;
Expand Down
20 changes: 10 additions & 10 deletions libssu/ssu.cpp
Expand Up @@ -76,13 +76,13 @@ Ssu::Ssu()

// FIXME, the whole credentials stuff needs reworking
// should probably be part of repo handling instead of core configuration
QPair<QString, QString> Ssu::credentials(QString scope)
QPair<QString, QString> Ssu::credentials(const QString &scope)
{
SsuCoreConfig *settings = SsuCoreConfig::instance();
return settings->credentials(scope);
}

QString Ssu::credentialsScope(QString repoName, bool rndRepo)
QString Ssu::credentialsScope(const QString &repoName, bool rndRepo)
{
SsuCoreConfig *settings = SsuCoreConfig::instance();
SsuSettings repoSettings(SSU_REPO_CONFIGURATION, QSettings::IniFormat);
Expand Down Expand Up @@ -125,7 +125,7 @@ QString Ssu::credentialsScope(QString repoName, bool rndRepo)
return settings->credentialsScope(repoName, rndRepo);
}

QString Ssu::credentialsUrl(QString scope)
QString Ssu::credentialsUrl(const QString &scope)
{
SsuCoreConfig *settings = SsuCoreConfig::instance();
return settings->credentialsUrl(scope);
Expand Down Expand Up @@ -179,19 +179,19 @@ void Ssu::setDeviceMode(Ssu::DeviceModeFlags mode, enum Ssu::EditMode editMode)
settings->setDeviceMode(mode, editMode);
}

void Ssu::setFlavour(QString flavour)
void Ssu::setFlavour(const QString &flavour)
{
SsuCoreConfig *settings = SsuCoreConfig::instance();
settings->setFlavour(flavour);
}

void Ssu::setRelease(QString release, bool rnd)
void Ssu::setRelease(const QString &release, bool rnd)
{
SsuCoreConfig *settings = SsuCoreConfig::instance();
settings->setRelease(release, rnd);
}

void Ssu::setDomain(QString domain)
void Ssu::setDomain(const QString &domain)
{
SsuCoreConfig *settings = SsuCoreConfig::instance();
settings->setDomain(domain);
Expand Down Expand Up @@ -259,7 +259,7 @@ bool Ssu::registerDevice(QDomDocument *response)

// RND repos have flavour (devel, testing, release), and release (latest, next)
// Release repos only have release (latest, next, version number)
QString Ssu::repoUrl(QString repoName, bool rndRepo,
QString Ssu::repoUrl(const QString &repoName, bool rndRepo,
QHash<QString, QString> repoParameters,
QHash<QString, QString> parametersOverride)
{
Expand Down Expand Up @@ -356,7 +356,7 @@ void Ssu::requestFinished(QNetworkReply *reply)
}
}

void Ssu::sendRegistration(QString usernameDomain, QString password)
void Ssu::sendRegistration(const QString &usernameDomain, const QString &password)
{
errorFlag = false;

Expand Down Expand Up @@ -496,7 +496,7 @@ bool Ssu::setCredentials(QDomDocument *response)
return true;
}

void Ssu::setError(QString errorMessage)
void Ssu::setError(const QString &errorMessage)
{
errorFlag = true;
errorString = errorMessage;
Expand All @@ -511,7 +511,7 @@ void Ssu::setError(QString errorMessage)
emit done();
}

void Ssu::storeAuthorizedKeys(QByteArray data)
void Ssu::storeAuthorizedKeys(const QByteArray &data)
{
QDir dir;
SsuLog *ssuLog = SsuLog::instance();
Expand Down
20 changes: 10 additions & 10 deletions libssu/ssu.h
Expand Up @@ -85,7 +85,7 @@ class Ssu: public QObject
* Find a username/password pair for the given scope
* @return a QPair with username and password, or an empty QPair if scope is invalid
*/
QPair<QString, QString> credentials(QString scope);
QPair<QString, QString> credentials(const QString &scope);
/**
* Get the scope for a repository, taking into account different scopes for
* release and RnD repositories
Expand All @@ -95,11 +95,11 @@ class Ssu: public QObject
*
* @return a string containing the scope; it can be used to look up login credentials using credentials()
*/
QString credentialsScope(QString repoName, bool rndRepo = false);
QString credentialsScope(const QString &repoName, bool rndRepo = false);
/**
* Return the URL for which credentials scope is valid
*/
QString credentialsUrl(QString scope);
QString credentialsUrl(const QString &scope);
/**
* Returns if the last operation was successful
* @retval true last operation was successful
Expand All @@ -116,7 +116,7 @@ class Ssu: public QObject
* Resolve a repository url
* @return the repository URL on success, an empty string on error
*/
QString repoUrl(QString repoName, bool rndRepo = false,
QString repoUrl(const QString &repoName, bool rndRepo = false,
QHash<QString, QString> repoParameters = QHash<QString, QString>(),
QHash<QString, QString> parametersOverride = QHash<QString, QString>());
/**
Expand Down Expand Up @@ -146,11 +146,11 @@ class Ssu: public QObject
/// See SsuCoreConfig::setDeviceMode
Q_INVOKABLE void setDeviceMode(DeviceModeFlags mode, enum EditMode editMode = Replace);
/// See SsuCoreConfig::setFlavour
Q_INVOKABLE void setFlavour(QString flavour);
Q_INVOKABLE void setFlavour(const QString &flavour);
/// See SsuCoreConfig::setRelease
Q_INVOKABLE void setRelease(QString release, bool rnd = false);
Q_INVOKABLE void setRelease(const QString &release, bool rnd = false);
/// See SsuCoreConfig::setDomain
Q_INVOKABLE void setDomain(QString domain);
Q_INVOKABLE void setDomain(const QString &domain);
/// See SsuCoreConfig::useSslVerify
Q_INVOKABLE bool useSslVerify();

Expand All @@ -162,15 +162,15 @@ class Ssu: public QObject
bool registerDevice(QDomDocument *response);
bool setCredentials(QDomDocument *response);
bool verifyResponse(QDomDocument *response);
void storeAuthorizedKeys(QByteArray data);
void storeAuthorizedKeys(const QByteArray &data);

private slots:
void requestFinished(QNetworkReply *reply);
/**
* Set errorString returned by lastError to errorMessage, set
* errorFlag returned by error() to true, and emit done()
*/
void setError(QString errorMessage);
void setError(const QString &errorMessage);

public slots:
/**
Expand All @@ -182,7 +182,7 @@ public slots:
* error() to check if an error occured, and use lastError() to retrieve the last
* error message.
*/
void sendRegistration(QString username, QString password);
void sendRegistration(const QString &username, const QString &password);
/**
* Try to update the RND repository credentials. The device needs to be registered
* for this to work. updateCredentials remembers the time of the last credentials
Expand Down
14 changes: 7 additions & 7 deletions libssu/ssucoreconfig.cpp
Expand Up @@ -25,7 +25,7 @@ SsuCoreConfig *SsuCoreConfig::instance()
return ssuCoreConfig;
}

QPair<QString, QString> SsuCoreConfig::credentials(QString scope)
QPair<QString, QString> SsuCoreConfig::credentials(const QString &scope)
{
QPair<QString, QString> ret;
beginGroup("credentials-" + scope);
Expand All @@ -35,7 +35,7 @@ QPair<QString, QString> SsuCoreConfig::credentials(QString scope)
return ret;
}

QString SsuCoreConfig::credentialsScope(QString repoName, bool rndRepo)
QString SsuCoreConfig::credentialsScope(const QString &repoName, bool rndRepo)
{
Q_UNUSED(repoName)
Q_UNUSED(rndRepo)
Expand All @@ -46,7 +46,7 @@ QString SsuCoreConfig::credentialsScope(QString repoName, bool rndRepo)
return "your-configuration-is-broken-and-does-not-contain-credentials-scope";
}

QString SsuCoreConfig::credentialsUrl(QString scope)
QString SsuCoreConfig::credentialsUrl(const QString &scope)
{
if (contains("credentials-url-" + scope))
return value("credentials-url-" + scope).toString();
Expand Down Expand Up @@ -120,15 +120,15 @@ void SsuCoreConfig::setDeviceMode(Ssu::DeviceModeFlags mode, enum Ssu::EditMode
sync();
}

void SsuCoreConfig::setFlavour(QString flavour)
void SsuCoreConfig::setFlavour(const QString &flavour)
{
setValue("flavour", flavour);
// flavour is RnD only, so enable RnD mode
setDeviceMode(Ssu::RndMode, Ssu::Add);
sync();
}

void SsuCoreConfig::setRelease(QString release, bool rnd)
void SsuCoreConfig::setRelease(const QString &release, bool rnd)
{
if (rnd) {
setValue("rndRelease", release);
Expand All @@ -141,11 +141,11 @@ void SsuCoreConfig::setRelease(QString release, bool rnd)
sync();
}

void SsuCoreConfig::setDomain(QString domain)
void SsuCoreConfig::setDomain(const QString &domain)
{
// - in domain messes with default section autodetection,
// so change it to :
setValue("domain", domain.replace("-", ":"));
setValue("domain", QString(domain).replace("-", ":"));
sync();
}

Expand Down
12 changes: 6 additions & 6 deletions libssu/ssucoreconfig_p.h
Expand Up @@ -34,7 +34,7 @@ class SsuCoreConfig: public SsuSettings
* Find a username/password pair for the given scope
* @return a QPair with username and password, or an empty QPair if scope is invalid
*/
QPair<QString, QString> credentials(QString scope);
QPair<QString, QString> credentials(const QString &scope);
/**
* Get the scope for a repository, taking into account different scopes for
* release and RnD repositories
Expand All @@ -44,11 +44,11 @@ class SsuCoreConfig: public SsuSettings
*
* @return a string containing the scope; it can be used to look up login credentials using credentials()
*/
QString credentialsScope(QString repoName, bool rndRepo = false);
QString credentialsScope(const QString &repoName, bool rndRepo = false);
/**
* Return the URL for which credentials scope is valid
*/
QString credentialsUrl(QString scope);
QString credentialsUrl(const QString &scope);
/**
* Get the current flavour when RnD repositories are used
* @return current flavour (usually something like testing, release, ..)
Expand Down Expand Up @@ -87,15 +87,15 @@ class SsuCoreConfig: public SsuSettings
/**
* Set the flavour used when resolving RND repositories
*/
Q_INVOKABLE void setFlavour(QString flavour);
Q_INVOKABLE void setFlavour(const QString &flavour);
/**
* Set the release version string for either a release, or a RnD snapshot
*/
Q_INVOKABLE void setRelease(QString release, bool rnd = false);
Q_INVOKABLE void setRelease(const QString &release, bool rnd = false);
/**
* Set the domain string (usually something like nemo, jolla, ..)
*/
Q_INVOKABLE void setDomain(QString domain);
Q_INVOKABLE void setDomain(const QString &domain);
/**
* Return configuration settings regarding ssl verification
* @retval true SSL verification must be used; that's the default if not configured
Expand Down
22 changes: 12 additions & 10 deletions libssu/ssudeviceinfo.cpp
Expand Up @@ -340,7 +340,7 @@ QStringList SsuDeviceInfo::disabledRepos()
return result;
}

QString SsuDeviceInfo::displayName(const int type)
QString SsuDeviceInfo::displayName(int type)
{
QString model = deviceModel();
QString variant = deviceVariant(false);
Expand Down Expand Up @@ -429,25 +429,27 @@ QStringList SsuDeviceInfo::repos(bool rnd, int filter)
return result;
}

QVariant SsuDeviceInfo::variable(QString section, const QString &key)
QVariant SsuDeviceInfo::variable(const QString &section, const QString &key)
{
/// @todo compat-setting as ssudeviceinfo guaranteed to prepend sections with var-;
/// SsuVariables does not have this guarantee. Remove from here as well.
if (!section.startsWith("var-"))
section = "var-" + section;
QString varSection(section);
if (!varSection.startsWith("var-"))
varSection = "var-" + varSection;

return SsuVariables::variable(boardMappings, section, key);
return SsuVariables::variable(boardMappings, varSection, key);
}

void SsuDeviceInfo::variableSection(QString section, QHash<QString, QString> *storageHash)
void SsuDeviceInfo::variableSection(const QString &section, QHash<QString, QString> *storageHash)
{
if (!section.startsWith("var-"))
section = "var-" + section;
QString varSection(section);
if (!varSection.startsWith("var-"))
varSection = "var-" + varSection;

SsuVariables::variableSection(boardMappings, section, storageHash);
SsuVariables::variableSection(boardMappings, varSection, storageHash);
}

void SsuDeviceInfo::setDeviceModel(QString model)
void SsuDeviceInfo::setDeviceModel(const QString &model)
{
if (model.isEmpty())
cachedModel.clear();
Expand Down
11 changes: 6 additions & 5 deletions libssu/ssudeviceinfo.h
Expand Up @@ -22,7 +22,7 @@ class SsuDeviceInfo: public QObject
/**
* Initialize with device to override autodetection
*/
SsuDeviceInfo(QString model = "");
SsuDeviceInfo(const QString &model = QString());

virtual ~SsuDeviceInfo();

Expand Down Expand Up @@ -85,7 +85,8 @@ class SsuDeviceInfo: public QObject
* If no manufacturer is found UNKNOWN is returned.
* For an invalid type an empty string is returned.
*/
Q_INVOKABLE QString displayName(const int type);
Q_INVOKABLE QString displayName(int type);

/**
* Return the complete list of repositories configured for a device.
* Depending on the filter options, all repostories (user and board),
Expand All @@ -97,21 +98,21 @@ class SsuDeviceInfo: public QObject
/**
* Override device model autodetection
*/
Q_INVOKABLE void setDeviceModel(QString model = "");
Q_INVOKABLE void setDeviceModel(const QString &model = QString());

/**
* Return a variable from the given variable section. 'var'- is automatically
* prepended to the section name if not specified already. Recursive search
* through several variable sections (specified in the section) is supported,
* returned will be the first occurence of the variable.
*/
QVariant variable(QString section, const QString &key);
QVariant variable(const QString &section, const QString &key);

/**
* Return the requested variable section. 'var-' is automatically
* prepended to the section name if not specified already.
*/
void variableSection(QString section, QHash<QString, QString> *storageHash);
void variableSection(const QString &section, QHash<QString, QString> *storageHash);

/**
* Return a value from an adaptation section. Returns an empty string
Expand Down
2 changes: 1 addition & 1 deletion libssu/ssufeaturemanager.cpp
Expand Up @@ -58,7 +58,7 @@ QStringList SsuFeatureManager::repos(bool rndRepo, int filter)
return r;
}

QString SsuFeatureManager::url(QString repo, bool rndRepo)
QString SsuFeatureManager::url(const QString &repo, bool rndRepo)
{
QString repoHeader = QString("repositories-%1/")
.arg(rndRepo ? "rnd" : "release");
Expand Down
2 changes: 1 addition & 1 deletion libssu/ssufeaturemanager.h
Expand Up @@ -22,7 +22,7 @@ class SsuFeatureManager: public QObject
public:
SsuFeatureManager();
QStringList repos(bool rndRepo, int filter = Ssu::NoFilter);
QString url(QString repo, bool rndRepo);
QString url(const QString &repo, bool rndRepo);

private:
SsuSettings *featureSettings;
Expand Down
2 changes: 1 addition & 1 deletion libssu/ssulog.cpp
Expand Up @@ -24,7 +24,7 @@ SsuLog *SsuLog::instance()
return ssuLog;
}

void SsuLog::print(int priority, QString message)
void SsuLog::print(int priority, const QString &message)
{
// directly go through qsettings here to avoid recursive invocation
// of coreconfig / ssulog
Expand Down

0 comments on commit 309ebec

Please sign in to comment.