Commit 34c8b547 authored by Nicolas Fella's avatar Nicolas Fella
Browse files

Build with KDEFrameworkCompilerSettings

These are a bit stricter than the regular KDE settings.

In particular they enforce not using raw strings for QString stuff.

Also replace 0 with nullptr where appropriate.
parent cb50d66c
......@@ -26,7 +26,7 @@ include(KDEInstallDirs)
include(KDECMakeSettings)
include(FeatureSummary)
include(ECMInstallIcons)
include(KDECompilerSettings NO_POLICY_SCOPE)
include(KDEFrameworkCompilerSettings NO_POLICY_SCOPE)
include(KDEClangFormat)
add_subdirectory(services)
......
......@@ -12,7 +12,7 @@ QUrl createStatusUrl(const QString &input)
{
QString fixedUrl;
if (!input.startsWith(QLatin1String("http://")) && !input.startsWith(QLatin1String("https://"))) {
fixedUrl.append("https://");
fixedUrl.append(QLatin1String("https://"));
fixedUrl.append(input);
} else {
fixedUrl = input;
......@@ -21,10 +21,10 @@ QUrl createStatusUrl(const QString &input)
QUrl url(fixedUrl);
if (!url.path().endsWith(QLatin1Char('/'))) {
url.setPath(url.path() + '/');
url.setPath(url.path() + QLatin1Char('/'));
}
url.setPath(url.path() + "status.php");
url.setPath(url.path() + QLatin1String("status.php"));
return url;
}
......@@ -30,7 +30,7 @@ NextcloudWizard::~NextcloudWizard()
void NextcloudWizard::init(KAccountsUiPlugin::UiType type)
{
if (type == KAccountsUiPlugin::NewAccountDialog) {
const QString packagePath("org.kde.kaccounts.nextcloud");
const QString packagePath(QStringLiteral("org.kde.kaccounts.nextcloud"));
m_object = new KDeclarative::QmlObject();
m_object->setTranslationDomain(packagePath);
......@@ -49,7 +49,7 @@ void NextcloudWizard::init(KAccountsUiPlugin::UiType type)
Q_EMIT canceled();
});
m_object->engine()->rootContext()->setContextProperty("helper", helper);
m_object->engine()->rootContext()->setContextProperty(QStringLiteral("helper"), helper);
m_object->completeInitialization();
......
......@@ -26,7 +26,7 @@ class NextcloudWizard : public KAccountsUiPlugin
Q_INTERFACES(KAccountsUiPlugin)
public:
explicit NextcloudWizard(QObject *parent = 0);
explicit NextcloudWizard(QObject *parent = nullptr);
virtual ~NextcloudWizard();
virtual void init(KAccountsUiPlugin::UiType type) override;
......
......@@ -31,7 +31,7 @@ NextcloudController::NextcloudController(QObject *parent)
m_webengineProfile->setUrlRequestInterceptor(&m_urlIntercepter);
m_webengineProfile->setHttpUserAgent(QStringLiteral("KAccounts Nextcloud Login"));
QDesktopServices::setUrlHandler("nc", this, "finalUrlHandler");
QDesktopServices::setUrlHandler(QStringLiteral("nc"), this, "finalUrlHandler");
}
NextcloudController::~NextcloudController()
......@@ -53,7 +53,7 @@ void NextcloudController::checkServer(const QUrl &url)
{
setWorking(true);
KIO::TransferJob *job = KIO::get(url, KIO::NoReload, KIO::HideProgressInfo);
job->setUiDelegate(0);
job->setUiDelegate(nullptr);
connect(job, &KIO::DavJob::data, this, &NextcloudController::dataReceived);
connect(job, &KIO::DavJob::finished, this, &NextcloudController::fileChecked);
}
......@@ -74,7 +74,7 @@ void NextcloudController::fileChecked(KJob *job)
QJsonDocument parser = QJsonDocument::fromJson(m_json);
QJsonObject map = parser.object();
if (!map.contains("version")) {
if (!map.contains(QStringLiteral("version"))) {
wrongUrlDetected();
return;
}
......@@ -103,14 +103,14 @@ void NextcloudController::finalUrlHandler(const QUrl &url)
{
// To fetch m_username and m_password from final url
QString finalURLtoString = url.toString();
int username_ini_pos = finalURLtoString.indexOf("&user:") + 6;
int password_ini_pos = finalURLtoString.indexOf("&password:") + 10;
int username_ini_pos = finalURLtoString.indexOf(QLatin1String("&user:")) + 6;
int password_ini_pos = finalURLtoString.indexOf(QLatin1String("&password:")) + 10;
int username_size = password_ini_pos - username_ini_pos - 10;
QString username = finalURLtoString.mid(username_ini_pos, username_size);
QString password = finalURLtoString.mid(password_ini_pos);
// To replace %40 with @
int position = username.indexOf("%40");
username.replace(position, 3, "@");
int position = username.indexOf(QLatin1String("%40"));
username.replace(position, 3, QStringLiteral("@"));
m_username = username;
m_password = password;
......@@ -137,7 +137,7 @@ void NextcloudController::serverCheckResult()
url.setUserName(m_username);
url.setPassword(m_password);
url = url.adjusted(QUrl::StripTrailingSlash);
url.setPath(url.path() + '/' + "remote.php/webdav");
url.setPath(url.path() + QLatin1Char('/') + QLatin1String("remote.php/webdav"));
// Send a basic PROPFIND command to test access
const QString requestStr = QStringLiteral(
"<d:propfind xmlns:d=\"DAV:\">"
......@@ -146,14 +146,17 @@ void NextcloudController::serverCheckResult()
"</d:prop>"
"</d:propfind>");
KIO::DavJob *job = KIO::davPropFind(url, QDomDocument(requestStr), "1", KIO::HideProgressInfo);
KIO::DavJob *job = KIO::davPropFind(url, QDomDocument(requestStr), QStringLiteral("1"), KIO::HideProgressInfo);
connect(job, &KIO::DavJob::finished, this, &NextcloudController::authCheckResult);
connect(job, &KIO::DavJob::data, this, &NextcloudController::dataReceived);
QVariantMap metadata{{"cookies", "none"}, {"no-cache", true}};
QVariantMap metadata{
{QStringLiteral("cookies"), QStringLiteral("none")},
{QStringLiteral("no-cache"), true},
};
job->setMetaData(metadata);
job->setUiDelegate(0);
job->setUiDelegate(nullptr);
job->start();
Q_EMIT errorMessageChanged();
......@@ -194,16 +197,16 @@ void NextcloudController::cancel()
void NextcloudController::finish(const QStringList disabledServices)
{
QVariantMap data;
data.insert("server", m_server);
data.insert(QStringLiteral("server"), m_server);
QUrl serverUrl(m_server);
data.insert("dav/host", serverUrl.host());
data.insert("dav/storagePath", QStringLiteral("/remote.php/dav/files/%1").arg(m_username));
data.insert("dav/contactsPath", QStringLiteral("/remote.php/dav/addressbooks/users/%1").arg(m_username));
data.insert(QStringLiteral("dav/host"), serverUrl.host());
data.insert(QStringLiteral("dav/storagePath"), QStringLiteral("/remote.php/dav/files/%1").arg(m_username));
data.insert(QStringLiteral("dav/contactsPath"), QStringLiteral("/remote.php/dav/addressbooks/users/%1").arg(m_username));
for (const QString &service : disabledServices) {
data.insert("__service/" + service, false);
data.insert(QStringLiteral("__service/") + service, false);
}
Q_EMIT wizardFinished(m_username, m_password, data);
......
......@@ -17,7 +17,7 @@
namespace KIO
{
class Job;
};
}
class KJob;
......@@ -26,7 +26,7 @@ class Service
Q_GADGET
Q_PROPERTY(QString id MEMBER m_id)
Q_PROPERTY(QString name MEMBER m_name)
Q_PROPERTY(QString description MEMBER m_description);
Q_PROPERTY(QString description MEMBER m_description)
public:
QString m_id;
......@@ -57,7 +57,7 @@ public:
};
Q_ENUM(State)
NextcloudController(QObject *parent = 0);
NextcloudController(QObject *parent = nullptr);
~NextcloudController();
Q_INVOKABLE void checkServer(const QString &server);
......
......@@ -28,7 +28,7 @@ OwnCloudWizard::~OwnCloudWizard()
void OwnCloudWizard::init(KAccountsUiPlugin::UiType type)
{
if (type == KAccountsUiPlugin::NewAccountDialog) {
const QString packagePath("org.kde.kaccounts.owncloud");
const QString packagePath(QStringLiteral("org.kde.kaccounts.owncloud"));
m_object = new KDeclarative::QmlObject();
m_object->setTranslationDomain(packagePath);
......@@ -47,7 +47,7 @@ void OwnCloudWizard::init(KAccountsUiPlugin::UiType type)
Q_EMIT canceled();
});
m_object->engine()->rootContext()->setContextProperty("helper", helper);
m_object->engine()->rootContext()->setContextProperty(QStringLiteral("helper"), helper);
m_object->completeInitialization();
......
......@@ -25,7 +25,7 @@ class OwnCloudWizard : public KAccountsUiPlugin
Q_INTERFACES(KAccountsUiPlugin)
public:
explicit OwnCloudWizard(QObject *parent = 0);
explicit OwnCloudWizard(QObject *parent = nullptr);
virtual ~OwnCloudWizard();
virtual void init(KAccountsUiPlugin::UiType type) override;
......
......@@ -44,7 +44,7 @@ void OwncloudController::checkServer(const QUrl &url)
qDebug() << "Checking for ownCloud instance at" << url;
setWorking(true);
KIO::TransferJob *job = KIO::get(url, KIO::NoReload, KIO::HideProgressInfo);
job->setUiDelegate(0);
job->setUiDelegate(nullptr);
connect(job, SIGNAL(data(KIO::Job *, QByteArray)), SLOT(dataReceived(KIO::Job *, QByteArray)));
connect(job, SIGNAL(finished(KJob *)), this, SLOT(fileChecked(KJob *)));
}
......@@ -62,7 +62,7 @@ void OwncloudController::figureOutServer(const QUrl &url)
// This needs 2x up cause first it just removes the status.php
// and only the second call actually moves up
QUrl urlUp = KIO::upUrl(KIO::upUrl(url));
urlUp.setPath(urlUp.path() + '/' + "status.php");
urlUp.setPath(urlUp.path() + QLatin1Char('/') + QStringLiteral("status.php"));
if (urlUp != url) {
checkServer(urlUp.adjusted(QUrl::NormalizePathSegments));
......@@ -89,7 +89,7 @@ void OwncloudController::fileChecked(KJob *job)
QJsonDocument parser = QJsonDocument::fromJson(m_json);
QJsonObject map = parser.object();
if (!map.contains("version")) {
if (!map.contains(QStringLiteral("version"))) {
figureOutServer(kJob->url());
qDebug() << "No json";
return;
......@@ -128,10 +128,10 @@ void OwncloudController::serverCheckResult(bool result)
url.setPassword(m_password);
if (!url.path().endsWith(QLatin1String("/"))) {
url.setPath(url.path() + '/');
url.setPath(url.path() + QLatin1Char('/'));
}
url.setPath(url.path() + "remote.php/webdav");
url.setPath(url.path() + QLatin1String("remote.php/webdav"));
// Send a basic PROPFIND command to test access
const QString requestStr = QStringLiteral(
......@@ -141,14 +141,17 @@ void OwncloudController::serverCheckResult(bool result)
"</d:prop>"
"</d:propfind>");
KIO::DavJob *job = KIO::davPropFind(url, QDomDocument(requestStr), "1", KIO::HideProgressInfo);
KIO::DavJob *job = KIO::davPropFind(url, QDomDocument(requestStr), QStringLiteral("1"), KIO::HideProgressInfo);
connect(job, SIGNAL(finished(KJob *)), this, SLOT(authCheckResult(KJob *)));
connect(job, SIGNAL(data(KIO::Job *, QByteArray)), SLOT(dataReceived(KIO::Job *, QByteArray)));
QVariantMap metadata{{"cookies", "none"}, {"no-cache", true}};
QVariantMap metadata{
{QStringLiteral("cookies"), QStringLiteral("none")},
{QStringLiteral("no-cache"), true},
};
job->setMetaData(metadata);
job->setUiDelegate(0);
job->setUiDelegate(nullptr);
job->start();
}
......@@ -194,18 +197,18 @@ QString OwncloudController::errorMessage() const
void OwncloudController::finish(const QStringList &disabledServices)
{
QVariantMap data;
data.insert("server", m_server);
data.insert(QStringLiteral("server"), m_server);
for (const QString &service : disabledServices) {
data.insert("__service/" + service, false);
data.insert(QStringLiteral("__service/") + service, false);
}
QUrl carddavUrl(m_server);
carddavUrl.setPath(carddavUrl.path() + QString("/remote.php/carddav/addressbooks/%1").arg(m_username));
carddavUrl.setPath(carddavUrl.path() + QStringLiteral("/remote.php/carddav/addressbooks/%1").arg(m_username));
data.insert("carddavUrl", carddavUrl);
data.insert("dav/host", carddavUrl.host());
data.insert("dav/storagePath", QStringLiteral("/remote.php/webdav"));
data.insert(QStringLiteral("carddavUrl"), carddavUrl);
data.insert(QStringLiteral("dav/host"), carddavUrl.host());
data.insert(QStringLiteral("dav/storagePath"), QStringLiteral("/remote.php/webdav"));
Q_EMIT wizardFinished(m_username, m_password, data);
}
......
......@@ -14,7 +14,7 @@
namespace KIO
{
class Job;
};
}
class KJob;
class Service
......@@ -45,7 +45,7 @@ public:
};
Q_ENUM(State)
explicit OwncloudController(QObject *parent = 0);
explicit OwncloudController(QObject *parent = nullptr);
~OwncloudController();
Q_INVOKABLE void checkServer(const QString &username, const QString &password, const QString &server);
......
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