summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMontel Laurent <[email protected]>2015-11-12 13:52:15 +0100
committerMontel Laurent <[email protected]>2015-11-12 13:52:15 +0100
commit8ec99addd0e0978c6e3d6bb05cea3979cac6baa4 (patch)
tree92847ea71c52c465ac3eb84e52d2c548d0ffe87f
parent1655cd34384556e0aee0bd072d13f6b570431500 (diff)
Reduce duplicate code
-rw-r--r--pimsettingexporter/core/abstractimportexportjob.cpp44
-rw-r--r--pimsettingexporter/core/abstractimportexportjob.h2
-rw-r--r--pimsettingexporter/core/addressbook/importaddressbookjob.cpp46
-rw-r--r--pimsettingexporter/core/addressbook/importaddressbookjob.h2
-rw-r--r--pimsettingexporter/core/alarm/importalarmjob.cpp45
-rw-r--r--pimsettingexporter/core/alarm/importalarmjob.h2
-rw-r--r--pimsettingexporter/core/calendar/importcalendarjob.cpp44
-rw-r--r--pimsettingexporter/core/calendar/importcalendarjob.h2
8 files changed, 48 insertions, 139 deletions
diff --git a/pimsettingexporter/core/abstractimportexportjob.cpp b/pimsettingexporter/core/abstractimportexportjob.cpp
index 1ebaa08..3b16ae4 100644
--- a/pimsettingexporter/core/abstractimportexportjob.cpp
+++ b/pimsettingexporter/core/abstractimportexportjob.cpp
@@ -166,6 +166,50 @@ void AbstractImportExportJob::overwriteDirectory(const QString &path, const KArc
}
}
+void AbstractImportExportJob::searchAllFiles(const KArchiveDirectory *dir, const QString &prefix, const QString &searchEntryName)
+{
+ Q_FOREACH (const QString &entryName, dir->entries()) {
+ const KArchiveEntry *entry = dir->entry(entryName);
+ if (entry && entry->isDirectory()) {
+ const QString newPrefix = (prefix.isEmpty() ? prefix : prefix + QLatin1Char('/')) + entryName;
+ if (entryName == searchEntryName) {
+ storeArchiveInfoResources(static_cast<const KArchiveDirectory *>(entry), entryName);
+ } else {
+ searchAllFiles(static_cast<const KArchiveDirectory *>(entry), newPrefix, searchEntryName);
+ }
+ }
+ }
+}
+
+void AbstractImportExportJob::storeArchiveInfoResources(const KArchiveDirectory *dir, const QString &prefix)
+{
+ Q_FOREACH (const QString &entryName, dir->entries()) {
+ const KArchiveEntry *entry = dir->entry(entryName);
+ if (entry && entry->isDirectory()) {
+ const KArchiveDirectory *resourceDir = static_cast<const KArchiveDirectory *>(entry);
+ const QStringList lst = resourceDir->entries();
+
+ if (lst.count() >= 2) {
+ const QString archPath(prefix + QLatin1Char('/') + entryName + QLatin1Char('/'));
+ resourceFiles files;
+ Q_FOREACH (const QString &name, lst) {
+ if (isAConfigFile(name)) {
+ files.akonadiConfigFile = archPath + name;
+ } else if (name.startsWith(Utils::prefixAkonadiConfigFile())) {
+ files.akonadiAgentConfigFile = archPath + name;
+ } else {
+ files.akonadiResources = archPath + name;
+ }
+ }
+ files.debug();
+ mListResourceFile.append(files);
+ } else {
+ qCDebug(PIMSETTINGEXPORTERCORE_LOG) << " Problem in archive. number of file " << lst.count();
+ }
+ }
+ }
+}
+
bool AbstractImportExportJob::isAConfigFile(const QString &name) const
{
//Redefine in subclass
diff --git a/pimsettingexporter/core/abstractimportexportjob.h b/pimsettingexporter/core/abstractimportexportjob.h
index c79fafa..6ed5cd7 100644
--- a/pimsettingexporter/core/abstractimportexportjob.h
+++ b/pimsettingexporter/core/abstractimportexportjob.h
@@ -104,6 +104,8 @@ protected:
bool overwriteDirectoryMessageBox(const QString &directory) const;
void overwriteDirectory(const QString &path, const KArchiveEntry *entry);
virtual bool isAConfigFile(const QString &name) const;
+ void searchAllFiles(const KArchiveDirectory *dir, const QString &prefix, const QString &searchEntryName);
+ void storeArchiveInfoResources(const KArchiveDirectory *dir, const QString &prefix);
KZip *archive() const;
diff --git a/pimsettingexporter/core/addressbook/importaddressbookjob.cpp b/pimsettingexporter/core/addressbook/importaddressbookjob.cpp
index 7220c9e..fe929b7 100644
--- a/pimsettingexporter/core/addressbook/importaddressbookjob.cpp
+++ b/pimsettingexporter/core/addressbook/importaddressbookjob.cpp
@@ -53,7 +53,7 @@ void ImportAddressbookJob::start()
Q_EMIT title(i18n("Start import KAddressBook settings..."));
mArchiveDirectory = archive()->directory();
createProgressDialog(i18n("Import KAddressBook settings"));
- searchAllFiles(mArchiveDirectory, QString());
+ searchAllFiles(mArchiveDirectory, QString(), QStringLiteral("addressbook"));
initializeListStep();
QTimer::singleShot(0, this, SLOT(slotNextStep()));
}
@@ -163,21 +163,6 @@ void ImportAddressbookJob::addSpecificResourceSettings(KSharedConfig::Ptr resour
}
}
-void ImportAddressbookJob::searchAllFiles(const KArchiveDirectory *dir, const QString &prefix)
-{
- Q_FOREACH (const QString &entryName, dir->entries()) {
- const KArchiveEntry *entry = dir->entry(entryName);
- if (entry && entry->isDirectory()) {
- const QString newPrefix = (prefix.isEmpty() ? prefix : prefix + QLatin1Char('/')) + entryName;
- if (entryName == QLatin1String("addressbook")) {
- storeAddressBookArchiveResource(static_cast<const KArchiveDirectory *>(entry), entryName);
- } else {
- searchAllFiles(static_cast<const KArchiveDirectory *>(entry), newPrefix);
- }
- }
- }
-}
-
bool ImportAddressbookJob::isAConfigFile(const QString &name) const
{
return name.endsWith(QLatin1String("rc")) && (name.contains(QStringLiteral("akonadi_vcarddir_resource_")) ||
@@ -185,35 +170,6 @@ bool ImportAddressbookJob::isAConfigFile(const QString &name) const
name.contains(QStringLiteral("akonadi_contacts_resource_")));
}
-void ImportAddressbookJob::storeAddressBookArchiveResource(const KArchiveDirectory *dir, const QString &prefix)
-{
- Q_FOREACH (const QString &entryName, dir->entries()) {
- const KArchiveEntry *entry = dir->entry(entryName);
- if (entry && entry->isDirectory()) {
- const KArchiveDirectory *resourceDir = static_cast<const KArchiveDirectory *>(entry);
- const QStringList lst = resourceDir->entries();
-
- if (lst.count() >= 2) {
- const QString archPath(prefix + QLatin1Char('/') + entryName + QLatin1Char('/'));
- resourceFiles files;
- Q_FOREACH (const QString &name, lst) {
- if (isAConfigFile(name)) {
- files.akonadiConfigFile = archPath + name;
- } else if (name.startsWith(Utils::prefixAkonadiConfigFile())) {
- files.akonadiAgentConfigFile = archPath + name;
- } else {
- files.akonadiResources = archPath + name;
- }
- }
- files.debug();
- mListResourceFile.append(files);
- } else {
- qCDebug(PIMSETTINGEXPORTERCORE_LOG) << " Problem in archive. number of file " << lst.count();
- }
- }
- }
-}
-
void ImportAddressbookJob::restoreConfig()
{
increaseProgressDialog();
diff --git a/pimsettingexporter/core/addressbook/importaddressbookjob.h b/pimsettingexporter/core/addressbook/importaddressbookjob.h
index b2f15f3..7e408d3 100644
--- a/pimsettingexporter/core/addressbook/importaddressbookjob.h
+++ b/pimsettingexporter/core/addressbook/importaddressbookjob.h
@@ -37,8 +37,6 @@ protected Q_SLOTS:
private:
bool isAConfigFile(const QString &name) const Q_DECL_OVERRIDE;
- 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);
void restoreResources();
void restoreConfig();
diff --git a/pimsettingexporter/core/alarm/importalarmjob.cpp b/pimsettingexporter/core/alarm/importalarmjob.cpp
index dbe1510..f9e43a1 100644
--- a/pimsettingexporter/core/alarm/importalarmjob.cpp
+++ b/pimsettingexporter/core/alarm/importalarmjob.cpp
@@ -55,7 +55,7 @@ void ImportAlarmJob::start()
Q_EMIT title(i18n("Start import KAlarm settings..."));
createProgressDialog(i18n("Import KAlarm settings"));
mArchiveDirectory = archive()->directory();
- searchAllFiles(mArchiveDirectory, QString());
+ searchAllFiles(mArchiveDirectory, QString(), QStringLiteral("alarm"));
initializeListStep();
QTimer::singleShot(0, this, &ImportAlarmJob::slotNextStep);
}
@@ -143,55 +143,12 @@ void ImportAlarmJob::restoreResources()
startSynchronizeResources(listResource);
}
-void ImportAlarmJob::searchAllFiles(const KArchiveDirectory *dir, const QString &prefix)
-{
- Q_FOREACH (const QString &entryName, dir->entries()) {
- const KArchiveEntry *entry = dir->entry(entryName);
- if (entry && entry->isDirectory()) {
- const QString newPrefix = (prefix.isEmpty() ? prefix : prefix + QLatin1Char('/')) + entryName;
- if (entryName == QLatin1String("alarm")) {
- storeAlarmArchiveResource(static_cast<const KArchiveDirectory *>(entry), entryName);
- } else {
- searchAllFiles(static_cast<const KArchiveDirectory *>(entry), newPrefix);
- }
- }
- }
-}
bool ImportAlarmJob::isAConfigFile(const QString &name) const
{
return name.endsWith(QLatin1String("rc")) && (name.contains(QStringLiteral("akonadi_kalarm_resource_"))
|| name.contains(QStringLiteral("akonadi_kalarm_dir_resource_")));
}
-void ImportAlarmJob::storeAlarmArchiveResource(const KArchiveDirectory *dir, const QString &prefix)
-{
- Q_FOREACH (const QString &entryName, dir->entries()) {
- const KArchiveEntry *entry = dir->entry(entryName);
- if (entry && entry->isDirectory()) {
- const KArchiveDirectory *resourceDir = static_cast<const KArchiveDirectory *>(entry);
- const QStringList lst = resourceDir->entries();
-
- if (lst.count() >= 2) {
- const QString archPath(prefix + QLatin1Char('/') + entryName + QLatin1Char('/'));
- resourceFiles files;
- Q_FOREACH (const QString &name, lst) {
- if (isAConfigFile(name)) {
- files.akonadiConfigFile = archPath + name;
- } else if (name.startsWith(Utils::prefixAkonadiConfigFile())) {
- files.akonadiAgentConfigFile = archPath + name;
- } else {
- files.akonadiResources = archPath + name;
- }
- }
- files.debug();
- mListResourceFile.append(files);
- } else {
- qCDebug(PIMSETTINGEXPORTERCORE_LOG) << " Problem in archive. number of file " << lst.count();
- }
- }
- }
-}
-
void ImportAlarmJob::restoreConfig()
{
increaseProgressDialog();
diff --git a/pimsettingexporter/core/alarm/importalarmjob.h b/pimsettingexporter/core/alarm/importalarmjob.h
index 60d68df..f868e06 100644
--- a/pimsettingexporter/core/alarm/importalarmjob.h
+++ b/pimsettingexporter/core/alarm/importalarmjob.h
@@ -36,8 +36,6 @@ protected Q_SLOTS:
private:
bool isAConfigFile(const QString &name) const Q_DECL_OVERRIDE;
- void storeAlarmArchiveResource(const KArchiveDirectory *dir, const QString &prefix);
- void searchAllFiles(const KArchiveDirectory *dir, const QString &prefix);
void importkalarmConfig(const KArchiveFile *kalarmFile, const QString &kalarmrc, const QString &filename, const QString &prefix);
void restoreResources();
void restoreConfig();
diff --git a/pimsettingexporter/core/calendar/importcalendarjob.cpp b/pimsettingexporter/core/calendar/importcalendarjob.cpp
index 4c1ec1d..e2545f2 100644
--- a/pimsettingexporter/core/calendar/importcalendarjob.cpp
+++ b/pimsettingexporter/core/calendar/importcalendarjob.cpp
@@ -165,56 +165,12 @@ void ImportCalendarJob::addSpecificResourceSettings(KSharedConfig::Ptr resourceC
}
}
-void ImportCalendarJob::searchAllFiles(const KArchiveDirectory *dir, const QString &prefix, const QString &searchEntryName)
-{
- Q_FOREACH (const QString &entryName, dir->entries()) {
- const KArchiveEntry *entry = dir->entry(entryName);
- if (entry && entry->isDirectory()) {
- const QString newPrefix = (prefix.isEmpty() ? prefix : prefix + QLatin1Char('/')) + entryName;
- if (entryName == searchEntryName) {
- storeArchiveInfoResources(static_cast<const KArchiveDirectory *>(entry), entryName);
- } else {
- searchAllFiles(static_cast<const KArchiveDirectory *>(entry), newPrefix, searchEntryName);
- }
- }
- }
-}
-
bool ImportCalendarJob::isAConfigFile(const QString &name) const
{
return name.endsWith(QLatin1String("rc")) && (name.contains(QStringLiteral("akonadi_ical_resource_"))
|| name.contains(QStringLiteral("akonadi_icaldir_resource_")));
}
-void ImportCalendarJob::storeArchiveInfoResources(const KArchiveDirectory *dir, const QString &prefix)
-{
- Q_FOREACH (const QString &entryName, dir->entries()) {
- const KArchiveEntry *entry = dir->entry(entryName);
- if (entry && entry->isDirectory()) {
- const KArchiveDirectory *resourceDir = static_cast<const KArchiveDirectory *>(entry);
- const QStringList lst = resourceDir->entries();
-
- if (lst.count() >= 2) {
- const QString archPath(prefix + QLatin1Char('/') + entryName + QLatin1Char('/'));
- resourceFiles files;
- Q_FOREACH (const QString &name, lst) {
- if (isAConfigFile(name)) {
- files.akonadiConfigFile = archPath + name;
- } else if (name.startsWith(Utils::prefixAkonadiConfigFile())) {
- files.akonadiAgentConfigFile = archPath + name;
- } else {
- files.akonadiResources = archPath + name;
- }
- }
- files.debug();
- mListResourceFile.append(files);
- } else {
- qCDebug(PIMSETTINGEXPORTERCORE_LOG) << " Problem in archive. number of file " << lst.count();
- }
- }
- }
-}
-
void ImportCalendarJob::restoreConfig()
{
increaseProgressDialog();
diff --git a/pimsettingexporter/core/calendar/importcalendarjob.h b/pimsettingexporter/core/calendar/importcalendarjob.h
index c8e30b3..61f1e44 100644
--- a/pimsettingexporter/core/calendar/importcalendarjob.h
+++ b/pimsettingexporter/core/calendar/importcalendarjob.h
@@ -37,8 +37,6 @@ protected Q_SLOTS:
private:
bool isAConfigFile(const QString &name) const Q_DECL_OVERRIDE;
- void searchAllFiles(const KArchiveDirectory *dir, const QString &prefix, const QString &searchEntryName);
- void storeArchiveInfoResources(const KArchiveDirectory *dir, const QString &prefix);
void importkorganizerConfig(const KArchiveFile *file, const QString &config, const QString &filename, const QString &prefix);
void restoreResources();
void restoreConfig();