Commit fe4c206e authored by Laurent Montel's avatar Laurent Montel 😁
Browse files

USe static method QFileInfo::exists(...) optimization

parent 945b54d4
......@@ -113,7 +113,7 @@ void AbstractImportExportJob::backupUiRcFile(const QString &configFileName, cons
{
const QString configrcStr(configFileName);
const QString configrc = QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation) + QLatin1String("/kxmlgui5/") + application + QLatin1Char('/') + configrcStr;
if (QFile(configrc).exists()) {
if (QFileInfo::exists(configrc)) {
backupFile(configrc, Utils::configsPath(), configrcStr);
}
}
......@@ -122,14 +122,14 @@ void AbstractImportExportJob::backupConfigFile(const QString &configFileName)
{
const QString configrcStr(configFileName);
const QString configrc = QStandardPaths::writableLocation(QStandardPaths::ConfigLocation) + QLatin1Char('/') + configrcStr;
if (QFile(configrc).exists()) {
if (QFileInfo::exists(configrc)) {
backupFile(configrc, Utils::configsPath(), configrcStr);
}
}
void AbstractImportExportJob::backupFile(const QString &filename, const QString &path, const QString &storedName)
{
if (QFile(filename).exists()) {
if (QFileInfo::exists(filename)) {
const bool fileAdded = archive()->addLocalFile(filename, path + storedName);
if (fileAdded) {
Q_EMIT info(i18n("\"%1\" backup done.", path + storedName));
......@@ -487,7 +487,7 @@ void AbstractImportExportJob::restoreUiRcFile(const QString &configNameStr, cons
if (configNameentry && configNameentry->isFile()) {
const KArchiveFile *configNameconfiguration = static_cast<const KArchiveFile *>(configNameentry);
const QString configNamerc = QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation) + QLatin1String("/kxmlgui5/") + applicationName + QLatin1Char('/') + configNameStr;
if (QFile(configNamerc).exists()) {
if (QFileInfo::exists(configNamerc)) {
if (overwriteConfigMessageBox(configNameStr)) {
copyToFile(configNameconfiguration, configNamerc, configNameStr, Utils::configsPath());
}
......@@ -503,7 +503,7 @@ void AbstractImportExportJob::restoreConfigFile(const QString &configNameStr)
if (configNameentry && configNameentry->isFile()) {
const KArchiveFile *configNameconfiguration = static_cast<const KArchiveFile *>(configNameentry);
const QString configNamerc = QStandardPaths::writableLocation(QStandardPaths::ConfigLocation) + QLatin1Char('/') + configNameStr;
if (QFile(configNamerc).exists()) {
if (QFileInfo::exists(configNamerc)) {
//TODO 4.12 allow to merge config.
if (overwriteConfigMessageBox(configNameStr)) {
copyToFile(configNameconfiguration, configNamerc, configNameStr, Utils::configsPath());
......
......@@ -133,7 +133,7 @@ void ExportAddressbookJob::backupConfig()
const QString kaddressbookStr(QStringLiteral("kaddressbookrc"));
const QString kaddressbookrc = QStandardPaths::writableLocation(QStandardPaths::ConfigLocation) + QLatin1Char('/') + kaddressbookStr;
if (QFile(kaddressbookrc).exists()) {
if (QFileInfo::exists(kaddressbookrc)) {
KSharedConfigPtr kaddressbook = KSharedConfig::openConfig(kaddressbookrc);
QTemporaryFile tmp;
......
......@@ -182,7 +182,7 @@ void ImportAddressbookJob::restoreConfig()
if (kaddressbookrcentry && kaddressbookrcentry->isFile()) {
const KArchiveFile *kaddressbookrcFile = static_cast<const KArchiveFile *>(kaddressbookrcentry);
const QString kaddressbookrc = QStandardPaths::writableLocation(QStandardPaths::ConfigLocation) + QLatin1Char('/') + kaddressbookStr;
if (QFile(kaddressbookrc).exists()) {
if (QFileInfo::exists(kaddressbookrc)) {
if (overwriteConfigMessageBox(kaddressbookStr)) {
importkaddressBookConfig(kaddressbookrcFile, kaddressbookrc, kaddressbookStr, Utils::configsPath());
}
......@@ -230,7 +230,7 @@ void ImportAddressbookJob::importkaddressBookConfig(const KArchiveFile *file, co
const KArchiveFile *csvTemplateFile = static_cast<const KArchiveFile *>(entry);
const QString name = csvTemplateFile->name();
QString autocorrectionPath = QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation) + cvsTemplateDirName;
if (QFile(autocorrectionPath).exists()) {
if (QFileInfo::exists(autocorrectionPath)) {
if (overwriteConfigMessageBox(name)) {
copyToFile(csvTemplateFile, autocorrectionPath + QLatin1Char('/') + name, name, Utils::dataPath() + cvsTemplateDirName);
}
......
......@@ -135,7 +135,7 @@ void ExportAlarmJob::backupConfig()
const QString kalarmStr(QStringLiteral("kalarmrc"));
const QString kalarmrc = QStandardPaths::writableLocation(QStandardPaths::ConfigLocation) + QLatin1Char('/') + kalarmStr;
if (QFile(kalarmrc).exists()) {
if (QFileInfo::exists(kalarmrc)) {
KSharedConfigPtr kalarm = KSharedConfig::openConfig(kalarmrc);
QTemporaryFile tmp;
......
......@@ -160,7 +160,7 @@ void ImportAlarmJob::restoreConfig()
if (kalarmrcentry && kalarmrcentry->isFile()) {
const KArchiveFile *kalarmrcFile = static_cast<const KArchiveFile *>(kalarmrcentry);
const QString kalarmrc = QStandardPaths::writableLocation(QStandardPaths::ConfigLocation) + QLatin1Char('/') + kalarmStr;
if (QFile(kalarmrc).exists()) {
if (QFileInfo::exists(kalarmrc)) {
if (overwriteConfigMessageBox(kalarmStr)) {
importkalarmConfig(kalarmrcFile, kalarmrc, kalarmStr, Utils::configsPath());
}
......
......@@ -136,7 +136,7 @@ void ExportCalendarJob::backupConfig()
const QString korganizerStr(QStringLiteral("korganizerrc"));
const QString korganizerrc = QStandardPaths::writableLocation(QStandardPaths::ConfigLocation) + QLatin1Char('/') + korganizerStr;
if (QFile(korganizerrc).exists()) {
if (QFileInfo::exists(korganizerrc)) {
KSharedConfigPtr korganizer = KSharedConfig::openConfig(korganizerrc);
QTemporaryFile tmp;
......@@ -161,7 +161,7 @@ void ExportCalendarJob::backupConfig()
const QString freebusyurlsStr(QStringLiteral("korganizer/freebusyurls"));
const QString freebusyurls = QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation) + QLatin1Char('/') + freebusyurlsStr;
if (QFile(freebusyurls).exists()) {
if (QFileInfo::exists(freebusyurls)) {
backupFile(freebusyurls, Utils::dataPath(), freebusyurlsStr);
}
......
......@@ -183,7 +183,7 @@ void ImportCalendarJob::restoreConfig()
if (oldKorganizerPrinterEntry && oldKorganizerPrinterEntry->isFile()) {
const KArchiveFile *korganizerFile = static_cast<const KArchiveFile *>(oldKorganizerPrinterEntry);
const QString oldKorganizerPrintrrc = QStandardPaths::writableLocation(QStandardPaths::ConfigLocation) + QLatin1Char('/') + korganizerPrinterrcStr;
if (QFile(oldKorganizerPrintrrc).exists()) {
if (QFileInfo::exists(oldKorganizerPrintrrc)) {
if (overwriteConfigMessageBox(oldKorganizerPrintrrc)) {
copyToFile(korganizerFile, oldKorganizerPrintrrc, oldKorganizerPrintrrcStr, Utils::configsPath());
}
......@@ -195,7 +195,7 @@ void ImportCalendarJob::restoreConfig()
if (korganizerPrinterEntry && korganizerPrinterEntry->isFile()) {
const KArchiveFile *korganizerFile = static_cast<const KArchiveFile *>(korganizerPrinterEntry);
const QString korganizerPrinterrc = QStandardPaths::writableLocation(QStandardPaths::ConfigLocation) + QLatin1Char('/') + korganizerPrinterrcStr;
if (QFile(korganizerPrinterrc).exists()) {
if (QFileInfo::exists(korganizerPrinterrc)) {
if (overwriteConfigMessageBox(korganizerPrinterrcStr)) {
copyToFile(korganizerFile, korganizerPrinterrc, korganizerPrinterrcStr, Utils::configsPath());
}
......@@ -210,7 +210,7 @@ void ImportCalendarJob::restoreConfig()
if (korganizerrcentry && korganizerrcentry->isFile()) {
const KArchiveFile *korganizerrcFile = static_cast<const KArchiveFile *>(korganizerrcentry);
const QString korganizerrc = QStandardPaths::writableLocation(QStandardPaths::ConfigLocation) + QLatin1Char('/') + korganizerStr;
if (QFile(korganizerrc).exists()) {
if (QFileInfo::exists(korganizerrc)) {
if (overwriteConfigMessageBox(korganizerStr)) {
importkorganizerConfig(korganizerrcFile, korganizerrc, korganizerStr, Utils::configsPath());
}
......@@ -224,7 +224,7 @@ void ImportCalendarJob::restoreConfig()
if (korgacrcentry && korgacrcentry->isFile()) {
const KArchiveFile *korgacrcFile = static_cast<const KArchiveFile *>(korgacrcentry);
const QString korgacrc = QStandardPaths::writableLocation(QStandardPaths::ConfigLocation) + QLatin1Char('/') + korgacStr;
if (QFile(korgacrc).exists()) {
if (QFileInfo::exists(korgacrc)) {
if (overwriteConfigMessageBox(korgacStr)) {
copyToFile(korgacrcFile, korgacrc, korgacStr, Utils::configsPath());
}
......@@ -239,7 +239,7 @@ void ImportCalendarJob::restoreConfig()
const KArchiveFile *freebusyrcFile = static_cast<const KArchiveFile *>(freebusyentry);
const QString freebusypath = QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation) + QLatin1String("/korganizer/") + freebusyStr;
if (QFile(freebusypath).exists()) {
if (QFileInfo::exists(freebusypath)) {
//TODO 4.12 merge it.
if (overwriteConfigMessageBox(freebusyStr)) {
copyToFile(freebusyrcFile, freebusypath, freebusyStr, Utils::dataPath());
......
......@@ -204,7 +204,7 @@ void ExportMailJob::backupTransports()
const QString mailtransportsStr(QStringLiteral("mailtransports"));
const QString maitransportsrc = QStandardPaths::writableLocation(QStandardPaths::ConfigLocation) + QLatin1Char('/') + mailtransportsStr;
if (!QFile(maitransportsrc).exists()) {
if (!QFileInfo::exists(maitransportsrc)) {
Q_EMIT info(i18n("Transports backup done."));
} else {
KSharedConfigPtr mailtransportsConfig = KSharedConfig::openConfig(mailtransportsStr);
......@@ -328,7 +328,7 @@ void ExportMailJob::backupConfig()
const QString folderMailArchiveStr(QStringLiteral("foldermailarchiverc"));
const QString folderMailArchiverc = QStandardPaths::writableLocation(QStandardPaths::ConfigLocation) + QLatin1Char('/') + folderMailArchiveStr;
if (QFile(folderMailArchiverc).exists()) {
if (QFileInfo::exists(folderMailArchiverc)) {
KSharedConfigPtr archivemailrc = KSharedConfig::openConfig(folderMailArchiveStr);
QTemporaryFile tmp;
......@@ -355,7 +355,7 @@ void ExportMailJob::backupConfig()
const QString archiveMailAgentConfigurationStr(QStringLiteral("akonadi_archivemail_agentrc"));
const QString archiveMailAgentconfigurationrc = QStandardPaths::writableLocation(QStandardPaths::ConfigLocation) + QLatin1Char('/') + archiveMailAgentConfigurationStr;
if (QFile(archiveMailAgentconfigurationrc).exists()) {
if (QFileInfo::exists(archiveMailAgentconfigurationrc)) {
KSharedConfigPtr archivemailrc = KSharedConfig::openConfig(archiveMailAgentConfigurationStr);
QTemporaryFile tmp;
......@@ -388,7 +388,7 @@ void ExportMailJob::backupConfig()
const QString templatesconfigurationrcStr(QStringLiteral("templatesconfigurationrc"));
const QString templatesconfigurationrc = QStandardPaths::writableLocation(QStandardPaths::ConfigLocation) + QLatin1Char('/') + templatesconfigurationrcStr;
if (QFile(templatesconfigurationrc).exists()) {
if (QFileInfo::exists(templatesconfigurationrc)) {
KSharedConfigPtr templaterc = KSharedConfig::openConfig(templatesconfigurationrcStr);
QTemporaryFile tmp;
......@@ -543,7 +543,7 @@ void ExportMailJob::backupIdentity()
const QString emailidentitiesStr(QStringLiteral("emailidentities"));
const QString emailidentitiesrc = QStandardPaths::writableLocation(QStandardPaths::ConfigLocation) + QLatin1Char('/') + emailidentitiesStr;
if (QFile(emailidentitiesrc).exists()) {
if (QFileInfo::exists(emailidentitiesrc)) {
KSharedConfigPtr identity = KSharedConfig::openConfig(emailidentitiesrc);
......
......@@ -665,7 +665,7 @@ void ImportMailJob::restoreConfig()
if (kmailsnippetentry && kmailsnippetentry->isFile()) {
const KArchiveFile *kmailsnippet = static_cast<const KArchiveFile *>(kmailsnippetentry);
const QString kmailsnippetrc = QStandardPaths::writableLocation(QStandardPaths::ConfigLocation) + QLatin1Char('/') + kmailsnippetrcStr;
if (QFile(kmailsnippetrc).exists()) {
if (QFileInfo::exists(kmailsnippetrc)) {
//TODO 4.13 allow to merge config.
if (overwriteConfigMessageBox(kmailsnippetrcStr)) {
copyToFile(kmailsnippet, kmailsnippetrc, kmailsnippetrcStr, Utils::configsPath());
......@@ -680,7 +680,7 @@ void ImportMailJob::restoreConfig()
if (kabldapentry && kabldapentry->isFile()) {
const KArchiveFile *kabldap = static_cast<const KArchiveFile *>(kabldapentry);
const QString kabldaprc = QStandardPaths::writableLocation(QStandardPaths::ConfigLocation) + QLatin1Char('/') + labldaprcStr;
if (QFile(kabldaprc).exists()) {
if (QFileInfo::exists(kabldaprc)) {
const int result = mergeConfigMessageBox(labldaprcStr);
if (result == KMessageBox::Yes) {
copyToFile(kabldap, kabldaprc, labldaprcStr, Utils::configsPath());
......@@ -696,7 +696,7 @@ void ImportMailJob::restoreConfig()
if (archiveconfigurationentry && archiveconfigurationentry->isFile()) {
const KArchiveFile *archiveconfiguration = static_cast<const KArchiveFile *>(archiveconfigurationentry);
const QString archiveconfigurationrc = QStandardPaths::writableLocation(QStandardPaths::ConfigLocation) + QLatin1Char('/') + archiveconfigurationrcStr;
if (QFile(archiveconfigurationrc).exists()) {
if (QFileInfo::exists(archiveconfigurationrc)) {
const int result = mergeConfigMessageBox(archiveconfigurationrcStr);
if (result == KMessageBox::Yes) {
importArchiveConfig(archiveconfiguration, archiveconfigurationrc, archiveconfigurationrcStr, Utils::configsPath());
......@@ -713,7 +713,7 @@ void ImportMailJob::restoreConfig()
if (templatesconfigurationentry && templatesconfigurationentry->isFile()) {
const KArchiveFile *templatesconfiguration = static_cast<const KArchiveFile *>(templatesconfigurationentry);
const QString templatesconfigurationrc = QStandardPaths::writableLocation(QStandardPaths::ConfigLocation) + QLatin1Char('/') + templatesconfigurationrcStr;
if (QFile(templatesconfigurationrc).exists()) {
if (QFileInfo::exists(templatesconfigurationrc)) {
//TODO 4.13 allow to merge config.
if (overwriteConfigMessageBox(templatesconfigurationrcStr)) {
importTemplatesConfig(templatesconfiguration, templatesconfigurationrc, templatesconfigurationrcStr, Utils::configsPath());
......@@ -728,7 +728,7 @@ void ImportMailJob::restoreConfig()
if (kmail2rcentry && kmail2rcentry->isFile()) {
const KArchiveFile *kmailrc = static_cast<const KArchiveFile *>(kmail2rcentry);
const QString kmail2rc = QStandardPaths::writableLocation(QStandardPaths::ConfigLocation) + QLatin1Char('/') + kmailStr;
if (QFile(kmail2rc).exists()) {
if (QFileInfo::exists(kmail2rc)) {
if (overwriteConfigMessageBox(kmailStr)) {
importKmailConfig(kmailrc, kmail2rc, kmailStr, Utils::configsPath());
}
......@@ -742,7 +742,7 @@ void ImportMailJob::restoreConfig()
if (sievetemplatentry && sievetemplatentry->isFile()) {
const KArchiveFile *sievetemplateconfiguration = static_cast<const KArchiveFile *>(sievetemplatentry);
const QString sievetemplaterc = QStandardPaths::writableLocation(QStandardPaths::ConfigLocation) + QLatin1Char('/') + sievetemplatercStr;
if (QFile(sievetemplaterc).exists()) {
if (QFileInfo::exists(sievetemplaterc)) {
const int result = mergeConfigMessageBox(sievetemplatercStr);
if (result == KMessageBox::Yes) {
copyToFile(sievetemplateconfiguration, sievetemplaterc, sievetemplatercStr, Utils::configsPath());
......@@ -759,7 +759,7 @@ void ImportMailJob::restoreConfig()
if (customtemplatentry && customtemplatentry->isFile()) {
const KArchiveFile *customtemplateconfiguration = static_cast<const KArchiveFile *>(customtemplatentry);
const QString customtemplaterc = QStandardPaths::writableLocation(QStandardPaths::ConfigLocation) + QLatin1Char('/') + customTemplateStr;
if (QFile(customtemplaterc).exists()) {
if (QFileInfo::exists(customtemplaterc)) {
//TODO 4.13 allow to merge config.
if (overwriteConfigMessageBox(customTemplateStr)) {
copyToFile(customtemplateconfiguration, customtemplaterc, customTemplateStr, Utils::configsPath());
......@@ -774,7 +774,7 @@ void ImportMailJob::restoreConfig()
if (adblockentry && adblockentry->isFile()) {
const KArchiveFile *adblockconfiguration = static_cast<const KArchiveFile *>(adblockentry);
const QString adblockrc = QStandardPaths::writableLocation(QStandardPaths::ConfigLocation) + QLatin1Char('/') + adblockStr;
if (QFile(adblockrc).exists()) {
if (QFileInfo::exists(adblockrc)) {
//TODO 4.13 allow to merge config.
if (overwriteConfigMessageBox(adblockStr)) {
copyToFile(adblockconfiguration, adblockrc, adblockStr, Utils::configsPath());
......@@ -833,7 +833,7 @@ void ImportMailJob::restoreConfig()
if (kmail2Entry && kmail2Entry->isFile()) {
const KArchiveFile *entry = static_cast<const KArchiveFile *>(kmail2Entry);
const QString adblockPath = QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation) + QLatin1Char('/') + QLatin1String("kmail2/adblockrules_local");
if (QFile(adblockPath).exists()) {
if (QFileInfo::exists(adblockPath)) {
if (overwriteConfigMessageBox(QStringLiteral("adblockrules_local"))) {
copyToFile(entry, QString(QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation) + QLatin1String("/") + QLatin1String("kmail2/adblockrules_local")), QStringLiteral("adblockrules_local"), Utils::dataPath() + QLatin1String("kmail2/"));
}
......@@ -861,7 +861,7 @@ void ImportMailJob::importSimpleFilesInDirectory(const QString &relativePath)
const KArchiveFile *autocorrectionFile = static_cast<const KArchiveFile *>(entry);
const QString name = autocorrectionFile->name();
QString autocorrectionPath = QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation) + QLatin1Char('/') + relativePath + QLatin1Char('/') + name;
if (QFile(autocorrectionPath).exists()) {
if (QFileInfo::exists(autocorrectionPath)) {
if (overwriteConfigMessageBox(name)) {
copyToFile(autocorrectionFile, autocorrectionPath, name, Utils::dataPath() + relativePath);
}
......@@ -923,7 +923,7 @@ void ImportMailJob::restoreIdentity()
const KArchiveFile *vcardFile = static_cast<const KArchiveFile *>(vcardEntry);
QString vcardFilePath = QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation) + QLatin1Char('/') + QStringLiteral("kmail2/%1").arg(fileInfo.fileName());
int i = 1;
while (QFile(vcardFileName).exists()) {
while (QFileInfo::exists(vcardFileName)) {
vcardFilePath = QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation) + QLatin1Char('/') + QStringLiteral("kmail2/%1_%2").arg(i).arg(fileInfo.fileName());
++i;
}
......
......@@ -150,7 +150,7 @@ void ExportNotesJob::backupConfig()
const QString globalNoteSettingsStr(QStringLiteral("globalnotesettings"));
const QString globalNoteSettingsrc = QStandardPaths::writableLocation(QStandardPaths::ConfigLocation) + QLatin1Char('/') + globalNoteSettingsStr;
if (QFile(globalNoteSettingsrc).exists()) {
if (QFileInfo::exists(globalNoteSettingsrc)) {
KSharedConfigPtr globalnotesettingsrc = KSharedConfig::openConfig(globalNoteSettingsrc);
QTemporaryFile tmp;
......
......@@ -96,7 +96,7 @@ void ImportNotesJob::restoreConfig()
if (globalNotecentry && globalNotecentry->isFile()) {
const KArchiveFile *globalNotecentryrc = static_cast<const KArchiveFile *>(globalNotecentry);
const QString globalNoterc = QStandardPaths::writableLocation(QStandardPaths::ConfigLocation) + QLatin1Char('/') + globalNoteStr;
if (QFile(globalNoterc).exists()) {
if (QFileInfo::exists(globalNoterc)) {
if (overwriteConfigMessageBox(globalNoteStr)) {
importKNoteGlobalSettings(globalNotecentryrc, globalNoterc, globalNoteStr, Utils::configsPath());
}
......
......@@ -127,13 +127,13 @@ QString Utils::adaptResourcePath(KSharedConfigPtr resourceConfig, const QString
QDir().mkdir(currentPath);
}
}
if (QFile(newUrl).exists()) {
if (QFileInfo::exists(newUrl)) {
QString newFileName = newUrl;
QFileInfo fileInfo(newFileName);
for (int i = 0;; ++i) {
const QString currentPath = fileInfo.path() + QLatin1Char('/') + QString::number(i) + QLatin1Char('/');
newFileName = currentPath + fileInfo.fileName();
if (!QFile(newFileName).exists()) {
if (!QFileInfo::exists(newFileName)) {
QDir().mkdir(currentPath);
break;
}
......@@ -296,7 +296,7 @@ KZip *Utils::openZip(const QString &filename, QString &errorMsg)
void Utils::storeDataExportInfo(const QString &filename, KZip *archive)
{
if (QFile(filename).exists()) {
if (QFileInfo::exists(filename)) {
const bool fileAdded = archive->addLocalFile(filename, Utils::infoPath() + Utils::exportDataTypeFileName());
if (fileAdded) {
qCDebug(PIMSETTINGEXPORTERCORE_LOG) << "exporteddata file can not add to archive" << filename;
......
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