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

Reduce duplicate code

parent 54ada3fa
......@@ -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
......
......@@ -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;
......
......@@ -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();
......
......@@ -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();
......
......@@ -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();
......
......@@ -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();
......
......@@ -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();
......
......@@ -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();
......
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