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

Reduce duplicate code

parent 80f8542f
......@@ -178,6 +178,13 @@ void ImportAddressbookJob::searchAllFiles(const KArchiveDirectory *dir, const QS
}
}
bool ImportAddressbookJob::isAConfigFile(const QString &name) const
{
return name.endsWith(QLatin1String("rc")) && (name.contains(QStringLiteral("akonadi_vcarddir_resource_")) ||
name.contains(QStringLiteral("akonadi_vcard_resource_")) ||
name.contains(QStringLiteral("akonadi_contacts_resource_")));
}
void ImportAddressbookJob::storeAddressBookArchiveResource(const KArchiveDirectory *dir, const QString &prefix)
{
Q_FOREACH (const QString &entryName, dir->entries()) {
......@@ -190,9 +197,7 @@ void ImportAddressbookJob::storeAddressBookArchiveResource(const KArchiveDirecto
const QString archPath(prefix + QLatin1Char('/') + entryName + QLatin1Char('/'));
resourceFiles files;
Q_FOREACH (const QString &name, lst) {
if (name.endsWith(QLatin1String("rc")) && (name.contains(QStringLiteral("akonadi_vcarddir_resource_")) ||
name.contains(QStringLiteral("akonadi_vcard_resource_")) ||
name.contains(QStringLiteral("akonadi_contacts_resource_")))) {
if (isAConfigFile(name)) {
files.akonadiConfigFile = archPath + name;
} else if (name.startsWith(Utils::prefixAkonadiConfigFile())) {
files.akonadiAgentConfigFile = archPath + name;
......
......@@ -36,6 +36,7 @@ protected Q_SLOTS:
void slotNextStep() Q_DECL_OVERRIDE;
private:
bool isAConfigFile(const QString &name) const;
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);
......
......@@ -157,6 +157,11 @@ void ImportAlarmJob::searchAllFiles(const KArchiveDirectory *dir, const QString
}
}
}
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)
{
......@@ -170,8 +175,7 @@ void ImportAlarmJob::storeAlarmArchiveResource(const KArchiveDirectory *dir, con
const QString archPath(prefix + QLatin1Char('/') + entryName + QLatin1Char('/'));
resourceFiles files;
Q_FOREACH (const QString &name, lst) {
if (name.endsWith(QLatin1String("rc")) && (name.contains(QStringLiteral("akonadi_kalarm_resource_"))
|| name.contains(QStringLiteral("akonadi_kalarm_dir_resource_")))) {
if (isAConfigFile(name)) {
files.akonadiConfigFile = archPath + name;
} else if (name.startsWith(Utils::prefixAkonadiConfigFile())) {
files.akonadiAgentConfigFile = archPath + name;
......
......@@ -35,6 +35,7 @@ protected Q_SLOTS:
void slotNextStep() Q_DECL_OVERRIDE;
private:
bool isAConfigFile(const QString &name) const;
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);
......
......@@ -57,7 +57,7 @@ void ImportCalendarJob::start()
Q_EMIT title(i18n("Start import KOrganizer settings..."));
mArchiveDirectory = archive()->directory();
createProgressDialog(i18n("Import KOrganizer settings"));
searchAllFiles(mArchiveDirectory, QString());
searchAllFiles(mArchiveDirectory, QString(), QStringLiteral("calendar"));
initializeListStep();
QTimer::singleShot(0, this, &ImportCalendarJob::slotNextStep);
}
......@@ -165,22 +165,28 @@ void ImportCalendarJob::addSpecificResourceSettings(KSharedConfig::Ptr resourceC
}
}
void ImportCalendarJob::searchAllFiles(const KArchiveDirectory *dir, const QString &prefix)
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 == QLatin1String("calendar")) {
storeCalendarArchiveResource(static_cast<const KArchiveDirectory *>(entry), entryName);
if (entryName == searchEntryName) {
storeArchiveInfoResources(static_cast<const KArchiveDirectory *>(entry), entryName);
} else {
searchAllFiles(static_cast<const KArchiveDirectory *>(entry), newPrefix);
searchAllFiles(static_cast<const KArchiveDirectory *>(entry), newPrefix, searchEntryName);
}
}
}
}
void ImportCalendarJob::storeCalendarArchiveResource(const KArchiveDirectory *dir, const QString &prefix)
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);
......@@ -192,8 +198,7 @@ void ImportCalendarJob::storeCalendarArchiveResource(const KArchiveDirectory *di
const QString archPath(prefix + QLatin1Char('/') + entryName + QLatin1Char('/'));
resourceFiles files;
Q_FOREACH (const QString &name, lst) {
if (name.endsWith(QLatin1String("rc")) && (name.contains(QStringLiteral("akonadi_ical_resource_"))
|| name.contains(QStringLiteral("akonadi_icaldir_resource_")))) {
if (isAConfigFile(name)) {
files.akonadiConfigFile = archPath + name;
} else if (name.startsWith(Utils::prefixAkonadiConfigFile())) {
files.akonadiAgentConfigFile = archPath + name;
......
......@@ -36,8 +36,9 @@ protected Q_SLOTS:
void slotNextStep() Q_DECL_OVERRIDE;
private:
void searchAllFiles(const KArchiveDirectory *dir, const QString &prefix);
void storeCalendarArchiveResource(const KArchiveDirectory *dir, const QString &prefix);
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);
void importkorganizerConfig(const KArchiveFile *file, const QString &config, const QString &filename, const QString &prefix);
void restoreResources();
void restoreConfig();
......
......@@ -73,7 +73,7 @@ void ImportMailJob::start()
Q_EMIT title(i18n("Start import KMail settings..."));
createProgressDialog(i18n("Import KMail settings"));
mArchiveDirectory = archive()->directory();
searchAllFiles(mArchiveDirectory, QString());
searchAllMailsFiles(mArchiveDirectory, QString());
if (!mFileList.isEmpty() || !mListResourceFile.isEmpty()) {
initializeListStep();
QTimer::singleShot(0, this, &ImportMailJob::slotNextStep);
......@@ -108,7 +108,7 @@ void ImportMailJob::slotNextStep()
}
}
void ImportMailJob::searchAllFiles(const KArchiveDirectory *dir, const QString &prefix)
void ImportMailJob::searchAllMailsFiles(const KArchiveDirectory *dir, const QString &prefix)
{
Q_FOREACH (const QString &entryName, dir->entries()) {
const KArchiveEntry *entry = dir->entry(entryName);
......@@ -117,7 +117,7 @@ void ImportMailJob::searchAllFiles(const KArchiveDirectory *dir, const QString &
if (entryName == QLatin1String("mails")) {
storeMailArchiveResource(static_cast<const KArchiveDirectory *>(entry), entryName);
} else {
searchAllFiles(static_cast<const KArchiveDirectory *>(entry), newPrefix);
searchAllMailsFiles(static_cast<const KArchiveDirectory *>(entry), newPrefix);
}
} else if (entry) {
const QString fileName = prefix.isEmpty() ? entry->name() : prefix + QLatin1Char('/') + entry->name();
......
......@@ -51,7 +51,7 @@ private:
void importKmailConfig(const KArchiveFile *kmailsnippet, const QString &kmail2rc, const QString &filename, const QString &prefix);
void importArchiveConfig(const KArchiveFile *archiveconfiguration, const QString &archiveconfigurationrc, const QString &filename, const QString &prefix);
void importFolderArchiveConfig(const KArchiveFile *archiveconfiguration, const QString &archiveconfigurationrc, const QString &filename, const QString &prefix);
void searchAllFiles(const KArchiveDirectory *dir, const QString &prefix);
void searchAllMailsFiles(const KArchiveDirectory *dir, const QString &prefix);
void storeMailArchiveResource(const KArchiveDirectory *dir, const QString &prefix);
void mergeLdapConfig(const KArchiveFile *archivefile, const QString &filename, const QString &prefix);
......
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