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

Reduce duplicate code

parent db7b663f
......@@ -543,3 +543,28 @@ void AbstractImportExportJob::storeDirectory(const QString &subDirectory)
}
}
}
void AbstractImportExportJob::importDataSubdirectory(const QString &subdirectoryRelativePath)
{
const KArchiveEntry *themeEntry = mArchiveDirectory->entry(Utils::dataPath() + subdirectoryRelativePath);
if (themeEntry && themeEntry->isDirectory()) {
const KArchiveDirectory *themeDir = static_cast<const KArchiveDirectory *>(themeEntry);
Q_FOREACH (const QString &entryName, themeDir->entries()) {
const KArchiveEntry *entry = themeDir->entry(entryName);
if (entry && entry->isDirectory()) {
QString subFolderName = entryName;
QDir themeDirectory(QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation) + QLatin1Char('/') + subdirectoryRelativePath + QStringLiteral("/%1").arg(entryName));
int i = 1;
while (themeDirectory.exists()) {
subFolderName = entryName + QStringLiteral("_%1").arg(i);
themeDirectory = QDir(QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation) + QLatin1Char('/') + subdirectoryRelativePath + QStringLiteral("/%1").arg(subFolderName));
++i;
}
copyToDirectory(entry, QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation) + QLatin1Char('/') + subdirectoryRelativePath + QStringLiteral("/%1").arg(subFolderName));
}
}
}
}
......@@ -111,6 +111,8 @@ protected:
void setProgressDialogLabel(const QString &text);
void storeDirectory(const QString &subDirectory);
void importDataSubdirectory(const QString &subdirectoryRelativePath);
QHash<QString, Akonadi::Collection::Id> mHashConvertPathCollectionId;
QVector<resourceFiles> mListResourceFile;
......
......@@ -278,31 +278,7 @@ void ImportAddressbookJob::importkaddressBookConfig(const KArchiveFile *file, co
}
importSubdirectory(QStringLiteral("/kaddressbook/viewertemplates/"));
importSubdirectory(QStringLiteral("/kaddressbook/printing/"));
importDataSubdirectory(QStringLiteral("/kaddressbook/viewertemplates/"));
importDataSubdirectory(QStringLiteral("/kaddressbook/printing/"));
kaddressBookConfig->sync();
}
void ImportAddressbookJob::importSubdirectory(const QString &subdirectoryRelativePath)
{
const KArchiveEntry *themeEntry = mArchiveDirectory->entry(Utils::dataPath() + subdirectoryRelativePath);
if (themeEntry && themeEntry->isDirectory()) {
const KArchiveDirectory *themeDir = static_cast<const KArchiveDirectory *>(themeEntry);
Q_FOREACH (const QString &entryName, themeDir->entries()) {
const KArchiveEntry *entry = themeDir->entry(entryName);
if (entry && entry->isDirectory()) {
QString subFolderName = entryName;
QDir themeDirectory(QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation) + QLatin1Char('/') + subdirectoryRelativePath + QStringLiteral("/%1").arg(entryName));
int i = 1;
while (themeDirectory.exists()) {
subFolderName = entryName + QStringLiteral("_%1").arg(i);
themeDirectory = QDir(QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation) + QLatin1Char('/') + subdirectoryRelativePath + QStringLiteral("/%1").arg(subFolderName));
++i;
}
copyToDirectory(entry, QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation) + QLatin1Char('/') + subdirectoryRelativePath + QStringLiteral("/%1").arg(subFolderName));
}
}
}
}
......@@ -36,7 +36,6 @@ protected Q_SLOTS:
void slotNextStep() Q_DECL_OVERRIDE;
private:
void importSubdirectory(const QString &subdirectoryRelativePath);
void searchAllFiles(const KArchiveDirectory *dir, const QString &prefix);
void storeAddressBookArchiveResource(const KArchiveDirectory *dir, const QString &prefix);
void importkaddressBookConfig(const KArchiveFile *file, const QString &config, const QString &filename, const QString &prefix);
......
......@@ -163,5 +163,6 @@ void ExportNotesJob::backupConfig()
backupFile(tmp.fileName(), Utils::configsPath(), globalNoteSettingsStr);
delete knoteConfig;
}
storeDirectory(QStringLiteral("/knotes/print/theme/"));
Q_EMIT info(i18n("Config backup done."));
}
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