Commit 1e2cb814 authored by Laurent Montel's avatar Laurent Montel 😁
Browse files

Create impl class

parent dca1d061
......@@ -10,7 +10,7 @@ set(pimdataexporter_calendar_SRCS
set(pimdataexporter_addressbook_SRCS
addressbook/exportaddressbookjobinterfaceimpl.cpp
addressbook/importaddressbookjobinterface.cpp
addressbook/importaddressbookjobinterfaceimpl.cpp
)
set(pimdataexporter_mail_SRCS
......@@ -30,6 +30,7 @@ set(pimdataexporter_interfaces_SRCS
calendar/exportcalendarjobinterface.cpp
calendar/importcalendarjobinterface.cpp
addressbook/exportaddressbookjobinterface.cpp
addressbook/importaddressbookjobinterface.cpp
)
set(pimdataexporter_notes_SRCS
......
......@@ -20,8 +20,6 @@
#include "importaddressbookjobinterface.h"
#include "archivestorage.h"
#include <PimCommonAkonadi/CreateResource>
#include <KLocalizedString>
#include <KConfigGroup>
#include <KZip>
......@@ -31,14 +29,7 @@
#include <QFile>
#include <QDir>
#include <QStandardPaths>
#include "resourceconverterimpl.h"
namespace {
inline const QString storeAddressbook()
{
return QStringLiteral("backupaddressbook/");
}
}
ImportAddressbookJobInterface::ImportAddressbookJobInterface(QObject *parent, Utils::StoredTypes typeSelected, ArchiveStorage *archiveStorage, int numberOfStep)
: AbstractImportExportJob(parent, archiveStorage, typeSelected, numberOfStep)
......@@ -75,82 +66,6 @@ void ImportAddressbookJobInterface::slotNextStep()
}
}
void ImportAddressbookJobInterface::restoreResources()
{
Q_EMIT info(i18n("Restore resources..."));
setProgressDialogLabel(i18n("Restore resources..."));
increaseProgressDialog();
QStringList listResource;
listResource
<< restoreResourceFile(QStringLiteral("akonadi_vcard_resource"), Utils::addressbookPath(), QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation) + QStringLiteral(
"/share/kaddressbook/"));
if (!mListResourceFile.isEmpty()) {
QDir dir(mTempDirName);
dir.mkdir(Utils::addressbookPath());
const QString copyToDirName(mTempDirName + QLatin1Char('/') + Utils::addressbookPath());
const int numberOfResourceFile = mListResourceFile.size();
for (int i = 0; i < numberOfResourceFile; ++i) {
resourceFiles value = mListResourceFile.at(i);
QMap<QString, QVariant> settings;
if (value.akonadiConfigFile.contains(QLatin1String("akonadi_vcarddir_resource_"))
|| value.akonadiConfigFile.contains(QLatin1String("akonadi_contacts_resource_"))) {
const KArchiveEntry *fileResouceEntry = mArchiveDirectory->entry(value.akonadiConfigFile);
if (fileResouceEntry && fileResouceEntry->isFile()) {
const KArchiveFile *file = static_cast<const KArchiveFile *>(fileResouceEntry);
copyArchiveFileTo(file, copyToDirName);
QString resourceName(file->name());
QString filename(resourceName);
KSharedConfig::Ptr resourceConfig = KSharedConfig::openConfig(copyToDirName + QLatin1Char('/') + resourceName);
//TODO fix default path
ResourceConverterImpl converter;
const QString newUrl = converter.adaptResourcePath(resourceConfig, QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation) + QStringLiteral("/contacts"));
QFileInfo newUrlInfo(newUrl);
const QString dataFile = value.akonadiResources;
const KArchiveEntry *dataResouceEntry = mArchiveDirectory->entry(dataFile);
if (dataResouceEntry->isFile()) {
const KArchiveFile *file = static_cast<const KArchiveFile *>(dataResouceEntry);
//TODO adapt directory name too
extractZipFile(file, copyToDirName, newUrlInfo.path(), value.akonadiConfigFile.contains(QLatin1String("akonadi_contacts_resource_")));
}
settings.insert(QStringLiteral("Path"), newUrl);
const QString agentConfigFile = value.akonadiAgentConfigFile;
if (!agentConfigFile.isEmpty()) {
const KArchiveEntry *akonadiAgentConfigEntry = mArchiveDirectory->entry(agentConfigFile);
if (akonadiAgentConfigEntry->isFile()) {
const KArchiveFile *file = static_cast<const KArchiveFile *>(akonadiAgentConfigEntry);
copyArchiveFileTo(file, copyToDirName);
resourceName = file->name();
filename = Utils::akonadiAgentName(copyToDirName + QLatin1Char('/') + resourceName);
}
}
QString instanceType;
if (value.akonadiConfigFile.contains(QLatin1String("akonadi_vcarddir_resource_"))) {
instanceType = QStringLiteral("akonadi_vcarddir_resource");
} else if (value.akonadiConfigFile.contains(QLatin1String("akonadi_contacts_resource_"))) {
instanceType = QStringLiteral("akonadi_contacts_resource");
} else {
qCWarning(PIMDATAEXPORTERCORE_LOG) << " not supported" << value.akonadiConfigFile;
}
const QString newResource = mCreateResource->createResource(instanceType, filename, settings, true);
infoAboutNewResource(newResource);
qCDebug(PIMDATAEXPORTERCORE_LOG) << " newResource" << newResource;
listResource << newResource;
}
}
}
}
Q_EMIT info(i18n("Resources restored."));
//It's maildir support. Need to add support
startSynchronizeResources(listResource);
}
void ImportAddressbookJobInterface::addSpecificResourceSettings(const KSharedConfig::Ptr &resourceConfig, const QString &resourceName, QMap<QString, QVariant> &settings)
{
if (resourceName == QLatin1String("akonadi_vcard_resource")) {
......
......@@ -36,11 +36,11 @@ public:
protected:
void slotNextStep() override;
virtual void restoreResources() = 0;
private:
Q_REQUIRED_RESULT bool isAConfigFile(const QString &name) const override;
void importkaddressBookConfig(const KArchiveFile *file, const QString &config, const QString &filename, const QString &prefix);
void restoreResources();
void restoreConfig();
void addSpecificResourceSettings(const KSharedConfig::Ptr &resourceConfig, const QString &resourceName, QMap<QString, QVariant> &settings) override;
};
......
/*
Copyright (C) 2020 Laurent Montel <montel@kde.org>
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; see the file COPYING. If not, write to
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA.
*/
#include "importaddressbookjobinterfaceimpl.h"
#include "archivestorage.h"
#include <PimCommonAkonadi/CreateResource>
#include <KLocalizedString>
#include <KConfigGroup>
#include <KZip>
#include <KArchiveEntry>
#include <QTimer>
#include <QFile>
#include <QDir>
#include <QStandardPaths>
#include "resourceconverterimpl.h"
namespace {
inline const QString storeAddressbook()
{
return QStringLiteral("backupaddressbook/");
}
}
ImportAddressbookJobInterfaceImpl::ImportAddressbookJobInterfaceImpl(QObject *parent, Utils::StoredTypes typeSelected, ArchiveStorage *archiveStorage, int numberOfStep)
: ImportAddressbookJobInterface(parent, typeSelected, archiveStorage, numberOfStep)
{
}
ImportAddressbookJobInterfaceImpl::~ImportAddressbookJobInterfaceImpl()
{
}
void ImportAddressbookJobInterfaceImpl::restoreResources()
{
Q_EMIT info(i18n("Restore resources..."));
setProgressDialogLabel(i18n("Restore resources..."));
increaseProgressDialog();
QStringList listResource;
listResource
<< restoreResourceFile(QStringLiteral("akonadi_vcard_resource"), Utils::addressbookPath(), QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation) + QStringLiteral(
"/share/kaddressbook/"));
if (!mListResourceFile.isEmpty()) {
QDir dir(mTempDirName);
dir.mkdir(Utils::addressbookPath());
const QString copyToDirName(mTempDirName + QLatin1Char('/') + Utils::addressbookPath());
const int numberOfResourceFile = mListResourceFile.size();
for (int i = 0; i < numberOfResourceFile; ++i) {
resourceFiles value = mListResourceFile.at(i);
QMap<QString, QVariant> settings;
if (value.akonadiConfigFile.contains(QLatin1String("akonadi_vcarddir_resource_"))
|| value.akonadiConfigFile.contains(QLatin1String("akonadi_contacts_resource_"))) {
const KArchiveEntry *fileResouceEntry = mArchiveDirectory->entry(value.akonadiConfigFile);
if (fileResouceEntry && fileResouceEntry->isFile()) {
const KArchiveFile *file = static_cast<const KArchiveFile *>(fileResouceEntry);
copyArchiveFileTo(file, copyToDirName);
QString resourceName(file->name());
QString filename(resourceName);
KSharedConfig::Ptr resourceConfig = KSharedConfig::openConfig(copyToDirName + QLatin1Char('/') + resourceName);
//TODO fix default path
ResourceConverterImpl converter;
const QString newUrl = converter.adaptResourcePath(resourceConfig, QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation) + QStringLiteral("/contacts"));
QFileInfo newUrlInfo(newUrl);
const QString dataFile = value.akonadiResources;
const KArchiveEntry *dataResouceEntry = mArchiveDirectory->entry(dataFile);
if (dataResouceEntry->isFile()) {
const KArchiveFile *file = static_cast<const KArchiveFile *>(dataResouceEntry);
//TODO adapt directory name too
extractZipFile(file, copyToDirName, newUrlInfo.path(), value.akonadiConfigFile.contains(QLatin1String("akonadi_contacts_resource_")));
}
settings.insert(QStringLiteral("Path"), newUrl);
const QString agentConfigFile = value.akonadiAgentConfigFile;
if (!agentConfigFile.isEmpty()) {
const KArchiveEntry *akonadiAgentConfigEntry = mArchiveDirectory->entry(agentConfigFile);
if (akonadiAgentConfigEntry->isFile()) {
const KArchiveFile *file = static_cast<const KArchiveFile *>(akonadiAgentConfigEntry);
copyArchiveFileTo(file, copyToDirName);
resourceName = file->name();
filename = Utils::akonadiAgentName(copyToDirName + QLatin1Char('/') + resourceName);
}
}
QString instanceType;
if (value.akonadiConfigFile.contains(QLatin1String("akonadi_vcarddir_resource_"))) {
instanceType = QStringLiteral("akonadi_vcarddir_resource");
} else if (value.akonadiConfigFile.contains(QLatin1String("akonadi_contacts_resource_"))) {
instanceType = QStringLiteral("akonadi_contacts_resource");
} else {
qCWarning(PIMDATAEXPORTERCORE_LOG) << " not supported" << value.akonadiConfigFile;
}
const QString newResource = mCreateResource->createResource(instanceType, filename, settings, true);
infoAboutNewResource(newResource);
qCDebug(PIMDATAEXPORTERCORE_LOG) << " newResource" << newResource;
listResource << newResource;
}
}
}
}
Q_EMIT info(i18n("Resources restored."));
//It's maildir support. Need to add support
startSynchronizeResources(listResource);
}
/*
Copyright (C) 2020 Laurent Montel <montel@kde.org>
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; see the file COPYING. If not, write to
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA.
*/
#ifndef IMPORTADDRESSBOOKJOBINTERFACEIMPL_H
#define IMPORTADDRESSBOOKJOBINTERFACEIMPL_H
#include "importaddressbookjobinterface.h"
#include "pimdataexportercore_private_export.h"
class ArchiveStorage;
class KArchiveFile;
class PIMDATAEXPORTER_TESTS_EXPORT ImportAddressbookJobInterfaceImpl : public ImportAddressbookJobInterface
{
Q_OBJECT
public:
explicit ImportAddressbookJobInterfaceImpl(QObject *parent, Utils::StoredTypes typeSelected, ArchiveStorage *archiveStorage, int numberOfStep);
~ImportAddressbookJobInterfaceImpl() override;
protected:
void restoreResources() override;
};
#endif // IMPORTADDRESSBOOKJOBINTERFACEIMPL_H
......@@ -25,7 +25,7 @@
#include "mail/importmailjobinterface.h"
#include "addressbook/exportaddressbookjobinterfaceimpl.h"
#include "addressbook/importaddressbookjobinterface.h"
#include "addressbook/importaddressbookjobinterfaceimpl.h"
#include "calendar/importcalendarjobinterfaceimpl.h"
#include "calendar/exportcalendarjobinterfaceimpl.h"
......@@ -47,6 +47,7 @@
#include <QLocale>
PimDataBackupRestore::PimDataBackupRestore(QObject *parent)
: QObject(parent)
{
......@@ -212,7 +213,7 @@ void PimDataBackupRestore::restoreNextStep()
break;
case Utils::KAddressBook:
if (mStoreIterator.value().numberSteps != 0) {
mImportExportData = new ImportAddressbookJobInterface(this, mStoreIterator.value().types, mArchiveStorage, mStoreIterator.value().numberSteps);
mImportExportData = new ImportAddressbookJobInterfaceImpl(this, mStoreIterator.value().types, mArchiveStorage, mStoreIterator.value().numberSteps);
executeJob();
}
break;
......
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