Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions src/gui/accountstate.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
/*
* SPDX-FileCopyrightText: 2018 Nextcloud GmbH and Nextcloud contributors
* SPDX-FileCopyrightText: 2014 ownCloud GmbH
Expand Down Expand Up @@ -30,6 +30,8 @@

#include <cmath>

using namespace Qt::StringLiterals;

namespace OCC {

Q_LOGGING_CATEGORY(lcAccountState, "nextcloud.gui.account.state", QtInfoMsg)
Expand Down Expand Up @@ -629,8 +631,8 @@
for (const QJsonValue &value : navLinks) {
auto navLink = value.toObject();

auto *app = new AccountApp(navLink.value("name").toString(), QUrl(navLink.value("href").toString()),
navLink.value("id").toString(), QUrl(navLink.value("icon").toString()));
auto *app = new AccountApp(navLink.value("name"_L1).toString(), QUrl(navLink.value("href"_L1).toString()),
navLink.value("id"_L1).toString(), QUrl(navLink.value("icon"_L1).toString()));

_apps << app;
}
Expand Down
6 changes: 4 additions & 2 deletions src/gui/folderstatusmodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@
#include <QVarLengthArray>
#include <set>

using namespace Qt::StringLiterals;

Q_DECLARE_METATYPE(QPersistentModelIndex)

Check warning on line 21 in src/gui/folderstatusmodel.cpp

View workflow job for this annotation

GitHub Actions / build

src/gui/folderstatusmodel.cpp:21:20 [cppcoreguidelines-avoid-non-const-global-variables]

variable 'QPersistentModelIndex' is non-const and globally accessible, consider making it const

namespace OCC {

Expand Down Expand Up @@ -742,8 +744,8 @@
newInfo._folder = parentInfo->_folder;
newInfo._pathIdx = parentInfo->_pathIdx;
newInfo._pathIdx << newSubs.size();
newInfo._isExternal = permissionMap.value(removeTrailingSlash(path)).toString().contains("M");
newInfo._isEncrypted = encryptionMap.value(removeTrailingSlash(path)).toString() == QStringLiteral("1");
newInfo._isExternal = permissionMap.value(removeTrailingSlash(path)).toString().contains("M"_L1);
newInfo._isEncrypted = encryptionMap.value(removeTrailingSlash(path)).toString() == "1"_L1;
newInfo._path = relativePath;

newInfo._isNonDecryptable = newInfo.isEncrypted()
Expand Down
6 changes: 4 additions & 2 deletions src/gui/macOS/fileprovidereditlocallyjob.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
#include "networkjobs.h"
#include "systray.h"

using namespace Qt::StringLiterals;

namespace OCC::Mac {

Q_LOGGING_CATEGORY(lcFileProviderEditLocallyJob, "nextcloud.gui.fileprovidereditlocally", QtInfoMsg)
Expand All @@ -34,7 +36,7 @@ void FileProviderEditLocallyJob::start()
return;
}

const auto relPathSplit = _relPath.split(QLatin1Char('/'));
const auto relPathSplit = _relPath.split(u'/');
if (relPathSplit.isEmpty()) {
showError(tr("Could not find a file for local editing. "
"Make sure its path is valid and it is synced locally."), _relPath);
Expand Down Expand Up @@ -74,7 +76,7 @@ void FileProviderEditLocallyJob::idGetError(const QNetworkReply * const reply)

void FileProviderEditLocallyJob::idGetFinished(const QVariantMap &data)
{
const auto ocId = data.value("id").toString();
const auto ocId = data.value("id"_L1).toString();
if (ocId.isEmpty()) {
qCWarning(lcFileProviderEditLocallyJob) << "Could not get file ocId.";
showError(tr("Could not get file identifier."), tr("The file identifier is empty."));
Expand Down
14 changes: 8 additions & 6 deletions src/gui/owncloudsetupwizard.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* SPDX-License-Identifier: GPL-2.0-or-later
*/

#include "accessmanager.h"

Check failure on line 7 in src/gui/owncloudsetupwizard.cpp

View workflow job for this annotation

GitHub Actions / build

src/gui/owncloudsetupwizard.cpp:7:10 [clang-diagnostic-error]

'accessmanager.h' file not found
#include "account.h"
#include "accountmanager.h"
#include "clientproxy.h"
Expand Down Expand Up @@ -37,6 +37,8 @@
#include <QDesktopServices>
#include <QApplication>

using namespace Qt::StringLiterals;

namespace OCC {

OwncloudSetupWizard::OwncloudSetupWizard(QObject *parent)
Expand Down Expand Up @@ -378,9 +380,9 @@

sender()->deleteLater();

const auto objData = json.object().value("ocs").toObject().value("data").toObject();
const auto userId = objData.value("id").toString("");
const auto displayName = objData.value("display-name").toString("");
const auto objData = json.object().value("ocs"_L1).toObject().value("data"_L1).toObject();
const auto userId = objData.value("id"_L1).toString(QString());
const auto displayName = objData.value("display-name"_L1).toString(QString());
_ocWizard->account()->setDavUser(userId);
_ocWizard->account()->setDavDisplayName(displayName);

Expand Down Expand Up @@ -442,7 +444,7 @@

// strip the expected path
QString path = redirectUrl.path();
static QString expectedPath = "/" + _ocWizard->account()->davPath();
static QString expectedPath = u'/' + _ocWizard->account()->davPath();
if (path.endsWith(expectedPath)) {
path.chop(expectedPath.size());
redirectUrl.setPath(path);
Expand Down Expand Up @@ -488,7 +490,7 @@

bool OwncloudSetupWizard::checkDowngradeAdvised(QNetworkReply *reply)
{
if (reply->url().scheme() != QLatin1String("https")) {
if (reply->url().scheme() != "https"_L1) {
return false;
}

Expand All @@ -503,8 +505,8 @@
}

// Adhere to HSTS, even though we do not parse it properly
if (reply->hasRawHeader("Strict-Transport-Security")) {
if (reply->hasRawHeader("Strict-Transport-Security"_L1)) {
return false;

Check warning on line 509 in src/gui/owncloudsetupwizard.cpp

View workflow job for this annotation

GitHub Actions / build

src/gui/owncloudsetupwizard.cpp:509:16 [readability-simplify-boolean-expr]

redundant boolean literal in conditional return statement
}
return true;
}
Expand Down
124 changes: 63 additions & 61 deletions src/gui/sharemanager.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
/*
* SPDX-FileCopyrightText: 2019 Nextcloud GmbH and Nextcloud contributors
* SPDX-FileCopyrightText: 2015 ownCloud GmbH
Expand All @@ -17,7 +17,9 @@
#include <QJsonObject>
#include <QJsonArray>

using namespace Qt::StringLiterals;

Q_LOGGING_CATEGORY(lcUserGroupShare, "nextcloud.gui.usergroupshare", QtInfoMsg)

Check warning on line 22 in src/gui/sharemanager.cpp

View workflow job for this annotation

GitHub Actions / build

src/gui/sharemanager.cpp:22:1 [cppcoreguidelines-avoid-non-const-global-variables]

variable 'Q_LOGGING_CATEGORY' is non-const and globally accessible, consider making it const

namespace OCC {

Expand Down Expand Up @@ -294,14 +296,14 @@

void LinkShare::slotExpireDateSet(const QJsonDocument &reply, const QVariant &value)
{
auto data = reply.object().value("ocs").toObject().value("data").toObject();
auto data = reply.object().value("ocs"_L1).toObject().value("data"_L1).toObject();

/*
* If the reply provides a data back (more REST style)
* they use this date.
*/
if (data.value("expiration").isString()) {
_expireDate = QDate::fromString(data.value("expiration").toString(), "yyyy-MM-dd 00:00:00");
if (data.value("expiration"_L1).isString()) {
_expireDate = QDate::fromString(data.value("expiration"_L1).toString(), "yyyy-MM-dd 00:00:00");
} else {
_expireDate = value.toDate();
}
Expand Down Expand Up @@ -391,14 +393,14 @@

void UserGroupShare::slotExpireDateSet(const QJsonDocument &reply, const QVariant &value)
{
auto data = reply.object().value("ocs").toObject().value("data").toObject();
auto data = reply.object().value("ocs"_L1).toObject().value("data"_L1).toObject();

/*
* If the reply provides a data back (more REST style)
* they use this date.
*/
if (data.value("expiration").isString()) {
_expireDate = QDate::fromString(data.value("expiration").toString(), "yyyy-MM-dd 00:00:00");
if (data.value("expiration"_L1).isString()) {
_expireDate = QDate::fromString(data.value("expiration"_L1).toString(), "yyyy-MM-dd 00:00:00");
} else {
_expireDate = value.toDate();
}
Expand Down Expand Up @@ -466,12 +468,12 @@
// Find existing share permissions (if this was shared with us)
Share::Permissions existingPermissions = SharePermissionAll;
const auto &replyObject = reply.object();
const auto &ocsObject = replyObject["ocs"].toObject();
const auto &dataArray = ocsObject["data"].toArray();
const auto &ocsObject = replyObject["ocs"_L1].toObject();
const auto &dataArray = ocsObject["data"_L1].toArray();
for (const auto &element : dataArray) {
auto map = element.toObject();
if (map["file_target"] == path)
existingPermissions = Share::Permissions(map["permissions"].toInt());
if (map["file_target"_L1] == path)
existingPermissions = Share::Permissions(map["permissions"_L1].toInt());
}

// Limit the permissions we request for a share to the ones the item
Expand Down Expand Up @@ -510,7 +512,7 @@
return;
}

Q_ASSERT(folder->remotePath() == QStringLiteral("/") ||
Q_ASSERT(folder->remotePath() == "/"_L1 ||
Utility::noLeadingSlashPath(fullRemotePath).startsWith(Utility::noLeadingSlashPath(Utility::noTrailingSlashPath(folder->remotePath()))));

const auto createE2eeShareJob = new UpdateE2eeFolderUsersMetadataJob(_account,
Expand All @@ -530,7 +532,7 @@
void ShareManager::slotShareCreated(const QJsonDocument &reply)
{
//Parse share
auto data = reply.object().value("ocs").toObject().value("data").toObject();
auto data = reply.object().value("ocs"_L1).toObject().value("data"_L1).toObject();
SharePtr share(parseShare(data));

emit shareCreated(share);
Expand All @@ -557,7 +559,7 @@
const QList<SharePtr> ShareManager::parseShares(const QJsonDocument &reply) const
{
qDebug() << reply;
const auto tmpShares = reply.object().value("ocs").toObject().value("data").toArray();
const auto tmpShares = reply.object().value("ocs"_L1).toObject().value("data"_L1).toArray();
const QString versionString = _account->serverVersion();
qCDebug(lcSharing) << versionString << "Fetched" << tmpShares.count() << "shares";

Expand All @@ -566,7 +568,7 @@
for (const auto &share : tmpShares) {
auto data = share.toObject();

auto shareType = data.value("share_type").toInt();
auto shareType = data.value("share_type"_L1).toInt();

SharePtr newShare;

Expand Down Expand Up @@ -599,29 +601,29 @@

QSharedPointer<UserGroupShare> ShareManager::parseUserGroupShare(const QJsonObject &data) const
{
ShareePtr sharee(new Sharee(data.value("share_with").toString(),
data.value("share_with_displayname").toString(),
static_cast<Sharee::Type>(data.value("share_type").toInt())));
ShareePtr sharee(new Sharee(data.value("share_with"_L1).toString(),
data.value("share_with_displayname"_L1).toString(),
static_cast<Sharee::Type>(data.value("share_type"_L1).toInt())));

QDate expireDate;
if (data.value("expiration").isString()) {
expireDate = QDate::fromString(data.value("expiration").toString(), "yyyy-MM-dd 00:00:00");
if (data.value("expiration"_L1).isString()) {
expireDate = QDate::fromString(data.value("expiration"_L1).toString(), "yyyy-MM-dd 00:00:00");
}

QString note;
if (data.value("note").isString()) {
note = data.value("note").toString();
if (data.value("note"_L1).isString()) {
note = data.value("note"_L1).toString();
}

return QSharedPointer<UserGroupShare>(new UserGroupShare(_account,
data.value("id").toVariant().toString(), // "id" used to be an integer, support both
data.value("uid_owner").toVariant().toString(),
data.value("uid_file_owner").toVariant().toString(),
data.value("displayname_owner").toVariant().toString(),
data.value("path").toString(),
static_cast<Share::ShareType>(data.value("share_type").toInt()),
!data.value("password").toString().isEmpty(),
static_cast<Share::Permissions>(data.value("permissions").toInt()),
data.value("id"_L1).toVariant().toString(), // "id" used to be an integer, support both
data.value("uid_owner"_L1).toVariant().toString(),
data.value("uid_file_owner"_L1).toVariant().toString(),
data.value("displayname_owner"_L1).toVariant().toString(),
data.value("path"_L1).toString(),
static_cast<Share::ShareType>(data.value("share_type"_L1).toInt()),
!data.value("password"_L1).toString().isEmpty(),
static_cast<Share::Permissions>(data.value("permissions"_L1).toInt()),
sharee,
expireDate,
note));
Expand All @@ -632,60 +634,60 @@
QUrl url;

// From ownCloud server 8.2 the url field is always set for public shares
if (data.contains("url")) {
url = QUrl(data.value("url").toString());
if (data.contains("url"_L1)) {
url = QUrl(data.value("url"_L1).toString());
} else if (_account->serverVersionInt() >= Account::makeServerVersion(8, 0, 0)) {
// From ownCloud server version 8 on, a different share link scheme is used.
url = QUrl(Utility::concatUrlPath(_account->url(), QLatin1String("index.php/s/") + data.value("token").toString())).toString();
url = QUrl(Utility::concatUrlPath(_account->url(), QLatin1String("index.php/s/") + data.value("token"_L1).toString())).toString();
} else {
QUrlQuery queryArgs;
queryArgs.addQueryItem(QLatin1String("service"), QLatin1String("files"));
queryArgs.addQueryItem(QLatin1String("t"), data.value("token").toString());
url = QUrl(Utility::concatUrlPath(_account->url(), QLatin1String("public.php"), queryArgs).toString());
queryArgs.addQueryItem(u"service"_s, u"files"_s);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm wondering why these strings don't use the _L1 literal here... does addQueryItem just not accept QLatin1StringViews?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's worth to use a QLatinStringView when the method takes a QAnyStringView (atm it's mostly lot of json, xml relared functions and string comparison)

In the other case, the QLatin1String will be converted first to a QString and in these cases a QStringLiteral is faster

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah, I see! thanks for the explanation :)

queryArgs.addQueryItem(u"t"_s, data.value("token"_L1).toString());
url = QUrl(Utility::concatUrlPath(_account->url(), u"public.php"_s, queryArgs).toString());
}

QDate expireDate;
if (data.value("expiration").isString()) {
expireDate = QDate::fromString(data.value("expiration").toString(), "yyyy-MM-dd 00:00:00");
if (data.value("expiration"_L1).isString()) {
expireDate = QDate::fromString(data.value("expiration"_L1).toString(), "yyyy-MM-dd 00:00:00");
}

QString note;
if (data.value("note").isString()) {
note = data.value("note").toString();
if (data.value("note"_L1).isString()) {
note = data.value("note"_L1).toString();
}

return QSharedPointer<LinkShare>(new LinkShare(_account,
data.value("id").toVariant().toString(), // "id" used to be an integer, support both
data.value("uid_owner").toString(),
data.value("uid_file_owner").toString(),
data.value("displayname_owner").toString(),
data.value("path").toString(),
data.value("name").toString(),
data.value("token").toString(),
(Share::Permissions)data.value("permissions").toInt(),
data.value("share_with").isString(), // has password?
data.value("id"_L1).toVariant().toString(), // "id" used to be an integer, support both
data.value("uid_owner"_L1).toString(),
data.value("uid_file_owner"_L1).toString(),
data.value("displayname_owner"_L1).toString(),
data.value("path"_L1).toString(),
data.value("name"_L1).toString(),
data.value("token"_L1).toString(),
(Share::Permissions)data.value("permissions"_L1).toInt(),
data.value("share_with"_L1).isString(), // has password?
url,
expireDate,
note,
data.value("label").toString(),
data.value("hide_download").toInt() == 1));
data.value("label"_L1).toString(),
data.value("hide_download"_L1).toInt() == 1));
}

SharePtr ShareManager::parseShare(const QJsonObject &data) const
{
ShareePtr sharee(new Sharee(data.value("share_with").toString(),
data.value("share_with_displayname").toString(),
(Sharee::Type)data.value("share_type").toInt()));
ShareePtr sharee(new Sharee(data.value("share_with"_L1).toString(),
data.value("share_with_displayname"_L1).toString(),
(Sharee::Type)data.value("share_type"_L1).toInt()));

return SharePtr(new Share(_account,
data.value("id").toVariant().toString(), // "id" used to be an integer, support both
data.value("uid_owner").toVariant().toString(),
data.value("uid_file_owner").toVariant().toString(),
data.value("displayname_owner").toVariant().toString(),
data.value("path").toString(),
(Share::ShareType)data.value("share_type").toInt(),
!data.value("password").toString().isEmpty(),
(Share::Permissions)data.value("permissions").toInt(),
data.value("id"_L1).toVariant().toString(), // "id" used to be an integer, support both
data.value("uid_owner"_L1).toVariant().toString(),
data.value("uid_file_owner"_L1).toVariant().toString(),
data.value("displayname_owner"_L1).toVariant().toString(),
data.value("path"_L1).toString(),
(Share::ShareType)data.value("share_type"_L1).toInt(),
!data.value("password"_L1).toString().isEmpty(),
(Share::Permissions)data.value("permissions"_L1).toInt(),
sharee));
}

Expand Down
8 changes: 5 additions & 3 deletions src/gui/socketapi/socketapi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,8 @@
// The second number should be changed when there are new features.
#define MIRALL_SOCKET_API_VERSION "1.1"

using namespace Qt::StringLiterals;

namespace {
constexpr auto encryptJobPropertyFolder = "folder";
constexpr auto encryptJobPropertyPath = "path";
Expand Down Expand Up @@ -394,7 +396,7 @@ void SocketApi::slotReadSocket()
}();

const auto argument = QString{argPos != -1 ? line.mid(argPos + 1) : QString()};
if (command.startsWith("ASYNC_")) {
if (command.startsWith("ASYNC_"_L1)) {
const auto arguments = argument.split('|');
if (arguments.size() != 2) {
listener->sendError(QStringLiteral("argument count is wrong"));
Expand Down Expand Up @@ -729,8 +731,8 @@ void SocketApi::command_EDIT(const QString &localFile, SocketListener *listener)
job->setVerb(JsonApiJob::Verb::Post);

QObject::connect(job, &JsonApiJob::jsonReceived, [](const QJsonDocument &json){
auto data = json.object().value("ocs").toObject().value("data").toObject();
auto url = QUrl(data.value("url").toString());
auto data = json.object().value("ocs"_L1).toObject().value("data"_L1).toObject();
auto url = QUrl(data.value("url"_L1).toString());

if(!url.isEmpty())
Utility::openBrowser(url);
Expand Down
Loading
Loading