Commit 38ef1e21 authored by Laurent Montel's avatar Laurent Montel 😁
Browse files

Add impl class here too

parent 1e2cb814
......@@ -21,7 +21,7 @@ set(pimdataexporter_mail_SRCS
set(pimdataexporter_alarm_SRCS
alarm/exportalarmjobinterface.cpp
alarm/importalarmjobinterface.cpp
alarm/importalarmjobinterfaceimpl.cpp
)
set(pimdataexporter_interfaces_SRCS
......@@ -31,6 +31,7 @@ set(pimdataexporter_interfaces_SRCS
calendar/importcalendarjobinterface.cpp
addressbook/exportaddressbookjobinterface.cpp
addressbook/importaddressbookjobinterface.cpp
alarm/importalarmjobinterface.cpp
)
set(pimdataexporter_notes_SRCS
......
......@@ -32,14 +32,7 @@
#include <QFile>
#include <QStandardPaths>
#include <QTimer>
#include "resourceconverterimpl.h"
namespace {
inline const QString storeAlarm()
{
return QStringLiteral("backupalarm/");
}
}
ImportAlarmJobInterface::ImportAlarmJobInterface(QObject *parent, Utils::StoredTypes typeSelected, ArchiveStorage *archiveStorage, int numberOfStep)
: AbstractImportExportJob(parent, archiveStorage, typeSelected, numberOfStep)
......@@ -79,71 +72,6 @@ void ImportAlarmJobInterface::slotNextStep()
}
}
void ImportAlarmJobInterface::restoreResources()
{
Q_EMIT info(i18n("Restore resources..."));
setProgressDialogLabel(i18n("Restore resources..."));
increaseProgressDialog();
QStringList listResource;
listResource << restoreResourceFile(QStringLiteral("akonadi_kalarm_resource"), Utils::alarmPath(), storeAlarm(), false);
if (!mListResourceFile.isEmpty()) {
QDir dir(mTempDirName);
dir.mkdir(Utils::alarmPath());
const QString copyToDirName(mTempDirName + QLatin1Char('/') + Utils::alarmPath());
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_kalarm_dir_resource_"))
|| value.akonadiConfigFile.contains(QLatin1String("akonadi_kalarm_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);
//TODO adapt filename otherwise it will use all the time the same filename.
qCDebug(PIMDATAEXPORTERCORE_LOG) << " filename :" << filename;
KSharedConfig::Ptr resourceConfig = KSharedConfig::openConfig(copyToDirName + QLatin1Char('/') + resourceName);
ResourceConverterImpl converter;
const QString newUrl = converter.adaptResourcePath(resourceConfig, storeAlarm());
QFileInfo newUrlInfo(newUrl);
const QString dataFile = value.akonadiResources;
const KArchiveEntry *dataResouceEntry = mArchiveDirectory->entry(dataFile);
bool isDirResource = value.akonadiConfigFile.contains(QLatin1String("akonadi_kalarm_dir_resource_"));
if (dataResouceEntry->isFile()) {
const KArchiveFile *file = static_cast<const KArchiveFile *>(dataResouceEntry);
//TODO adapt directory name too
extractZipFile(file, copyToDirName, newUrlInfo.path(), isDirResource);
}
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);
}
}
const QString archiveNameType = isDirResource ? QStringLiteral("akonadi_kalarm_dir_resource") : QStringLiteral("akonadi_kalarm_resource");
const QString newResource = mCreateResource->createResource(archiveNameType, filename, settings, true);
infoAboutNewResource(newResource);
listResource << newResource;
qCDebug(PIMDATAEXPORTERCORE_LOG) << " newResource" << newResource;
}
}
}
}
//It's maildir support. Need to add support
startSynchronizeResources(listResource);
}
bool ImportAlarmJobInterface::isAConfigFile(const QString &name) const
{
......
......@@ -35,11 +35,11 @@ public:
protected:
void slotNextStep() override;
virtual void restoreResources() = 0;
private:
Q_REQUIRED_RESULT bool isAConfigFile(const QString &name) const override;
void importkalarmConfig(const KArchiveFile *kalarmFile, const QString &kalarmrc, const QString &filename, const QString &prefix);
void restoreResources();
void restoreConfig();
};
......
/*
Copyright (C) 2012-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 "importalarmjobinterfaceimpl.h"
#include "archivestorage.h"
#include <PimCommonAkonadi/CreateResource>
#include <KArchive>
#include <KLocalizedString>
#include <KConfigGroup>
#include <KZip>
#include <KArchiveEntry>
#include <QDir>
#include <QFile>
#include <QStandardPaths>
#include <QTimer>
#include "resourceconverterimpl.h"
namespace {
inline const QString storeAlarm()
{
return QStringLiteral("backupalarm/");
}
}
ImportAlarmJobInterfaceImpl::ImportAlarmJobInterfaceImpl(QObject *parent, Utils::StoredTypes typeSelected, ArchiveStorage *archiveStorage, int numberOfStep)
: ImportAlarmJobInterface(parent, typeSelected, archiveStorage, numberOfStep)
{
}
ImportAlarmJobInterfaceImpl::~ImportAlarmJobInterfaceImpl()
{
}
void ImportAlarmJobInterfaceImpl::restoreResources()
{
Q_EMIT info(i18n("Restore resources..."));
setProgressDialogLabel(i18n("Restore resources..."));
increaseProgressDialog();
QStringList listResource;
listResource << restoreResourceFile(QStringLiteral("akonadi_kalarm_resource"), Utils::alarmPath(), storeAlarm(), false);
if (!mListResourceFile.isEmpty()) {
QDir dir(mTempDirName);
dir.mkdir(Utils::alarmPath());
const QString copyToDirName(mTempDirName + QLatin1Char('/') + Utils::alarmPath());
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_kalarm_dir_resource_"))
|| value.akonadiConfigFile.contains(QLatin1String("akonadi_kalarm_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);
//TODO adapt filename otherwise it will use all the time the same filename.
qCDebug(PIMDATAEXPORTERCORE_LOG) << " filename :" << filename;
KSharedConfig::Ptr resourceConfig = KSharedConfig::openConfig(copyToDirName + QLatin1Char('/') + resourceName);
ResourceConverterImpl converter;
const QString newUrl = converter.adaptResourcePath(resourceConfig, storeAlarm());
QFileInfo newUrlInfo(newUrl);
const QString dataFile = value.akonadiResources;
const KArchiveEntry *dataResouceEntry = mArchiveDirectory->entry(dataFile);
bool isDirResource = value.akonadiConfigFile.contains(QLatin1String("akonadi_kalarm_dir_resource_"));
if (dataResouceEntry->isFile()) {
const KArchiveFile *file = static_cast<const KArchiveFile *>(dataResouceEntry);
//TODO adapt directory name too
extractZipFile(file, copyToDirName, newUrlInfo.path(), isDirResource);
}
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);
}
}
const QString archiveNameType = isDirResource ? QStringLiteral("akonadi_kalarm_dir_resource") : QStringLiteral("akonadi_kalarm_resource");
const QString newResource = mCreateResource->createResource(archiveNameType, filename, settings, true);
infoAboutNewResource(newResource);
listResource << newResource;
qCDebug(PIMDATAEXPORTERCORE_LOG) << " newResource" << newResource;
}
}
}
}
//It's maildir support. Need to add support
startSynchronizeResources(listResource);
}
/*
Copyright (C) 2012-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 IMPORTALARMJOBINTERFACEIMPL_H
#define IMPORTALARMJOBINTERFACEIMPL_H
#include "importalarmjobinterface.h"
#include "pimdataexportercore_private_export.h"
class ArchiveStorage;
class PIMDATAEXPORTER_TESTS_EXPORT ImportAlarmJobInterfaceImpl : public ImportAlarmJobInterface
{
Q_OBJECT
public:
explicit ImportAlarmJobInterfaceImpl(QObject *parent, Utils::StoredTypes typeSelected, ArchiveStorage *archiveStorage, int numberOfStep);
~ImportAlarmJobInterfaceImpl() override;
protected:
void restoreResources() override;
};
#endif // IMPORTALARMJOBINTERFACEIMPL_H
......@@ -31,7 +31,7 @@
#include "calendar/exportcalendarjobinterfaceimpl.h"
#include "alarm/exportalarmjobinterface.h"
#include "alarm/importalarmjobinterface.h"
#include "alarm/importalarmjobinterfaceimpl.h"
#include "notes/exportnotesjobinterfaceimpl.h"
#include "notes/importnotesjobinterfaceimpl.h"
......@@ -48,6 +48,7 @@
PimDataBackupRestore::PimDataBackupRestore(QObject *parent)
: QObject(parent)
{
......@@ -219,7 +220,7 @@ void PimDataBackupRestore::restoreNextStep()
break;
case Utils::KAlarm:
if (mStoreIterator.value().numberSteps != 0) {
mImportExportData = new ImportAlarmJobInterface(this, mStoreIterator.value().types, mArchiveStorage, mStoreIterator.value().numberSteps);
mImportExportData = new ImportAlarmJobInterfaceImpl(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