Commit a2018f67 authored by Igor Poboiko's avatar Igor Poboiko
Browse files

[resources] Use "/" instead of QDir::separator

Summary:
As Qt documentation states (https://doc.qt.io/qt-5/qdir.html#separator),
`QDir::separator()` should not be used to build file paths.

Note to reviewers: I might have confused `QStringLiteral` vs `QLatin1String` vs `QLatin1Char`
in some places, please correct me if I'm wrong

Test Plan: It compiles

Reviewers: dvratil, mlaurent

Reviewed By: mlaurent

Subscribers: kde-pim

Tags: #kde_pim

Differential Revision: https://phabricator.kde.org/D28634
parent 2b3664e1
......@@ -170,7 +170,7 @@ void ContactsResource::retrieveItems(const Akonadi::Collection &collection)
bool ContactsResource::retrieveItem(const Akonadi::Item &item, const QSet<QByteArray> &)
{
const QString filePath = directoryForCollection(item.parentCollection()) + QDir::separator() + item.remoteId();
const QString filePath = directoryForCollection(item.parentCollection()) + QLatin1Char('/') + item.remoteId();
Item newItem(item);
......@@ -227,7 +227,7 @@ void ContactsResource::itemAdded(const Akonadi::Item &item, const Akonadi::Colle
if (item.hasPayload<KContacts::Addressee>()) {
const KContacts::Addressee contact = item.payload<KContacts::Addressee>();
const QString fileName = directoryPath + QDir::separator() + contact.uid() + QLatin1String(".vcf");
const QString fileName = directoryPath + QLatin1Char('/') + contact.uid() + QStringLiteral(".vcf");
KContacts::VCardConverter converter;
const QByteArray content = converter.createVCard(contact);
......@@ -241,11 +241,11 @@ void ContactsResource::itemAdded(const Akonadi::Item &item, const Akonadi::Colle
file.write(content);
file.close();
newItem.setRemoteId(contact.uid() + QLatin1String(".vcf"));
newItem.setRemoteId(contact.uid() + QStringLiteral(".vcf"));
} else if (item.hasPayload<KContacts::ContactGroup>()) {
const KContacts::ContactGroup group = item.payload<KContacts::ContactGroup>();
const QString fileName = directoryPath + QDir::separator() + group.id() + QLatin1String(".ctg");
const QString fileName = directoryPath + QLatin1Char('/') + group.id() + QStringLiteral(".ctg");
QFile file(fileName);
if (!file.open(QIODevice::WriteOnly)) {
......@@ -274,7 +274,7 @@ void ContactsResource::itemChanged(const Akonadi::Item &item, const QSet<QByteAr
Item newItem(item);
const QString fileName = directoryForCollection(item.parentCollection()) + QDir::separator() + item.remoteId();
const QString fileName = directoryForCollection(item.parentCollection()) + QLatin1Char('/') + item.remoteId();
if (item.hasPayload<KContacts::Addressee>()) {
const KContacts::Addressee contact = item.payload<KContacts::Addressee>();
......@@ -328,7 +328,7 @@ void ContactsResource::itemRemoved(const Akonadi::Item &item)
return;
}
const QString fileName = directoryForCollection(item.parentCollection()) + QDir::separator() + item.remoteId();
const QString fileName = directoryForCollection(item.parentCollection()) + QLatin1Char('/') + item.remoteId();
if (!QFile::remove(fileName)) {
cancelTask(i18n("Unable to remove file '%1'", fileName));
......@@ -345,7 +345,7 @@ void ContactsResource::collectionAdded(const Akonadi::Collection &collection, co
return;
}
const QString dirName = directoryForCollection(parent) + QDir::separator() + collection.name();
const QString dirName = directoryForCollection(parent) + QLatin1Char('/') + collection.name();
if (!QDir::root().mkpath(dirName)) {
cancelTask(i18n("Unable to create folder '%1'.", dirName));
......@@ -382,7 +382,7 @@ void ContactsResource::collectionChanged(const Akonadi::Collection &collection)
const QString dirName = directoryForCollection(collection);
QFileInfo oldDirectory(dirName);
if (!QDir::root().rename(dirName, oldDirectory.absolutePath() + QDir::separator() + collection.name())) {
if (!QDir::root().rename(dirName, oldDirectory.absolutePath() + QLatin1Char('/') + collection.name())) {
cancelTask(i18n("Unable to rename folder '%1'.", collection.name()));
return;
}
......@@ -414,8 +414,8 @@ void ContactsResource::collectionRemoved(const Akonadi::Collection &collection)
void ContactsResource::itemMoved(const Akonadi::Item &item, const Akonadi::Collection &collectionSource, const Akonadi::Collection &collectionDestination)
{
const QString sourceFileName = directoryForCollection(collectionSource) + QDir::separator() + item.remoteId();
const QString targetFileName = directoryForCollection(collectionDestination) + QDir::separator() + item.remoteId();
const QString sourceFileName = directoryForCollection(collectionSource) + QLatin1Char('/') + item.remoteId();
const QString targetFileName = directoryForCollection(collectionDestination) + QLatin1Char('/') + item.remoteId();
if (QFile::rename(sourceFileName, targetFileName)) {
changeProcessed();
......@@ -426,8 +426,8 @@ void ContactsResource::itemMoved(const Akonadi::Item &item, const Akonadi::Colle
void ContactsResource::collectionMoved(const Akonadi::Collection &collection, const Akonadi::Collection &collectionSource, const Akonadi::Collection &collectionDestination)
{
const QString sourceDirectoryName = directoryForCollection(collectionSource) + QDir::separator() + collection.remoteId();
const QString targetDirectoryName = directoryForCollection(collectionDestination) + QDir::separator() + collection.remoteId();
const QString sourceDirectoryName = directoryForCollection(collectionSource) + QLatin1Char('/') + collection.remoteId();
const QString targetDirectoryName = directoryForCollection(collectionDestination) + QLatin1Char('/') + collection.remoteId();
if (QFile::rename(sourceDirectoryName, targetDirectoryName)) {
changeProcessed();
......@@ -449,7 +449,7 @@ void ContactsResource::initializeDirectory(const QString &path) const
QDir::root().mkpath(dir.absolutePath());
// check whether warning file is in place...
QFile file(dir.absolutePath() + QDir::separator() + QLatin1String("WARNING_README.txt"));
QFile file(dir.absolutePath() + QStringLiteral("/WARNING_README.txt"));
if (!file.exists()) {
// ... if not, create it
file.open(QIODevice::WriteOnly);
......@@ -500,7 +500,7 @@ QString ContactsResource::directoryForCollection(const Collection &collection) c
QString directory = parentDirectory;
if (!directory.endsWith(QLatin1Char('/'))) {
directory += QDir::separator() + collection.remoteId();
directory += QLatin1Char('/') + collection.remoteId();
} else {
directory += collection.remoteId();
}
......
......@@ -291,7 +291,7 @@ QString ICalDirResource::iCalDirectoryName() const
QString ICalDirResource::iCalDirectoryFileName(const QString &file) const
{
return IcalDirResourceSettings::self()->path() + QDir::separator() + file;
return IcalDirResourceSettings::self()->path() + QLatin1Char('/') + file;
}
void ICalDirResource::initializeICalDirectory() const
......@@ -304,7 +304,7 @@ void ICalDirResource::initializeICalDirectory() const
}
// check whether warning file is in place...
QFile file(dir.absolutePath() + QDir::separator() + QStringLiteral("WARNING_README.txt"));
QFile file(dir.absolutePath() + QStringLiteral("/WARNING_README.txt"));
if (!file.exists()) {
// ... if not, create it
file.open(QIODevice::WriteOnly);
......
......@@ -1050,7 +1050,7 @@ void KAlarmDirResource::initializeDirectory() const
}
// Check whether warning file is in place...
QFile file(dirPath + QDir::separator() + QLatin1String(warningFile));
QFile file(dirPath + QLatin1Char('/') + QStringLiteral(warningFile));
if (!file.exists()) {
// ... if not, create it
file.open(QIODevice::WriteOnly);
......@@ -1072,7 +1072,7 @@ QString KAlarmDirResource::directoryName() const
*/
QString KAlarmDirResource::filePath(const QString &file) const
{
return mSettings->path() + QDir::separator() + file;
return mSettings->path() + QLatin1Char('/') + file;
}
/******************************************************************************
......
......@@ -163,7 +163,7 @@ public:
return false;
}
path = dest.path() + QDir::separator() + newName;
path = dest.path() + QLatin1Char('/') + newName;
return true;
}
......@@ -430,7 +430,7 @@ QString Maildir::subDirPath() const
{
QDir dir(d->path);
dir.cdUp();
return dir.path() + QDir::separator() + d->subDirPath();
return dir.path() + QLatin1Char('/') + d->subDirPath();
}
QStringList Maildir::subFolderList() const
......@@ -794,7 +794,7 @@ QString Maildir::moveEntryTo(const QString &key, const Maildir &destination)
}
QFile f(realKey);
// ### is this safe regarding the maildir locking scheme?
const QString targetKey = destination.path() + QDir::separator() + QLatin1String("new") + QDir::separator() + key;
const QString targetKey = destination.path() + QStringLiteral("/new/") + key;
if (!f.rename(targetKey)) {
qCDebug(LIBMAILDIR_LOG) << "Failed to rename" << realKey << "to" << targetKey << "! Error: " << f.errorString();
d->lastError = f.errorString();
......
......@@ -465,8 +465,8 @@ void MaildirResource::itemRemoved(const Akonadi::Item &item)
Collection::List MaildirResource::listRecursive(const Collection &root, const Maildir &dir)
{
if (mSettings->monitorFilesystem()) {
mFsWatcher->addDir(dir.path() + QDir::separator() + QLatin1String("new"));
mFsWatcher->addDir(dir.path() + QDir::separator() + QLatin1String("cur"));
mFsWatcher->addDir(dir.path() + QStringLiteral("/new"));
mFsWatcher->addDir(dir.path() + QStringLiteral("/cur"));
mFsWatcher->addDir(dir.subDirPath());
if (dir.isRoot()) {
mFsWatcher->addDir(dir.path());
......@@ -576,7 +576,7 @@ void MaildirResource::collectionAdded(const Collection &collection, const Collec
changeProcessed();
return;
} else {
const QString collectionName(collection.name().remove(QDir::separator()));
const QString collectionName(collection.name().remove(QLatin1Char('/')));
const QString newFolderPath = md.addSubFolder(collectionName);
if (newFolderPath.isEmpty()) {
changeProcessed();
......@@ -621,7 +621,7 @@ void MaildirResource::collectionChanged(const Collection &collection)
md.create();
}
const QString collectionName(collection.name().remove(QDir::separator()));
const QString collectionName(collection.name().remove(QLatin1Char('/')));
if (!md.rename(collectionName)) {
Q_EMIT error(i18n("Unable to rename maildir folder '%1'.", collection.name()));
changeProcessed();
......
......@@ -1027,7 +1027,7 @@ bool MixedMaildirStore::Private::visit(FileStore::CollectionCreateJob *job)
return false;
}
const QString collectionName = job->collection().name().remove(QDir::separator());
const QString collectionName = job->collection().name().remove(QLatin1Char('/'));
Maildir md;
if (folderType == MBoxFolder) {
const QString subDirPath = Maildir::subDirPathForFolderPath(path);
......@@ -1209,7 +1209,7 @@ static Collection updateMBoxCollectionTree(const Collection &collection, const C
bool MixedMaildirStore::Private::visit(FileStore::CollectionModifyJob *job)
{
const Collection collection = job->collection();
const QString collectionName = collection.name().remove(QDir::separator());
const QString collectionName = collection.name().remove(QLatin1Char('/'));
// we also only do renames
if (collection.remoteId() == collection.name()) {
......
......@@ -239,7 +239,7 @@ void SingleFileResourceBase::fileChanged(const QString &fileName)
const QUrl prevUrl = mCurrentUrl;
int i = 0;
do {
lostFoundFileName = QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation) + QLatin1Char('/') + identifier() + QDir::separator() + prevUrl.fileName() + QLatin1Char('-')
lostFoundFileName = QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation) + QLatin1Char('/') + identifier() + QLatin1Char('/') + prevUrl.fileName() + QLatin1Char('-')
+ QString::number(++i);
} while (QFileInfo::exists(lostFoundFileName));
......
......@@ -248,7 +248,7 @@ QString VCardDirResource::vCardDirectoryName() const
QString VCardDirResource::vCardDirectoryFileName(const QString &file) const
{
return VcardDirResourceSettings::self()->path() + QDir::separator() + file;
return VcardDirResourceSettings::self()->path() + QLatin1Char('/') + file;
}
void VCardDirResource::initializeVCardDirectory() const
......@@ -261,7 +261,7 @@ void VCardDirResource::initializeVCardDirectory() const
}
// check whether warning file is in place...
QFile file(dir.absolutePath() + QDir::separator() + QLatin1String("WARNING_README.txt"));
QFile file(dir.absolutePath() + QStringLiteral("/WARNING_README.txt"));
if (!file.exists()) {
// ... if not, create it
file.open(QIODevice::WriteOnly);
......
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