Commit 71d468b4 authored by Laurent Montel's avatar Laurent Montel 😁
Browse files

Create Implement class for alarm method too

parent 38ef1e21
......@@ -20,7 +20,7 @@ set(pimdataexporter_mail_SRCS
)
set(pimdataexporter_alarm_SRCS
alarm/exportalarmjobinterface.cpp
alarm/exportalarmjobinterfaceimpl.cpp
alarm/importalarmjobinterfaceimpl.cpp
)
......@@ -32,6 +32,7 @@ set(pimdataexporter_interfaces_SRCS
addressbook/exportaddressbookjobinterface.cpp
addressbook/importaddressbookjobinterface.cpp
alarm/importalarmjobinterface.cpp
alarm/exportalarmjobinterface.cpp
)
set(pimdataexporter_notes_SRCS
......
......@@ -18,8 +18,7 @@
*/
#include "exportalarmjobinterface.h"
#include <AkonadiCore/AgentManager>
#include "exportresourcearchivejob.h"
#include <KLocalizedString>
......@@ -30,7 +29,6 @@
#include <QFile>
#include <QDir>
#include <QStandardPaths>
#include <exportresourcearchivejob.h>
#include "resourceconverterimpl.h"
ExportAlarmJobInterface::ExportAlarmJobInterface(QObject *parent, Utils::StoredTypes typeSelected, ArchiveStorage *archiveStorage, int numberOfStep)
......@@ -59,7 +57,7 @@ void ExportAlarmJobInterface::slotCheckBackupResource()
{
setProgressDialogLabel(i18n("Backing up resources..."));
increaseProgressDialog();
QTimer::singleShot(0, this, &ExportAlarmJobInterface::slotWriteNextArchiveResource);
exportArchiveResource();
}
void ExportAlarmJobInterface::slotCheckBackupConfig()
......@@ -75,59 +73,6 @@ void ExportAlarmJobInterface::slotCheckBackupConfig()
Q_EMIT jobFinished();
}
void ExportAlarmJobInterface::slotAlarmJobTerminated()
{
if (wasCanceled()) {
Q_EMIT jobFinished();
return;
}
mIndexIdentifier++;
QTimer::singleShot(0, this, &ExportAlarmJobInterface::slotWriteNextArchiveResource);
}
void ExportAlarmJobInterface::slotWriteNextArchiveResource()
{
Akonadi::AgentManager *manager = Akonadi::AgentManager::self();
const Akonadi::AgentInstance::List list = manager->instances();
if (mIndexIdentifier < list.count()) {
const Akonadi::AgentInstance agent = list.at(mIndexIdentifier);
const QString identifier = agent.identifier();
if (identifier.contains(QLatin1String("akonadi_kalarm_dir_resource_"))) {
const QString archivePath = Utils::alarmPath() + identifier + QLatin1Char('/');
ResourceConverterImpl converter;
const QString url = converter.resourcePath(identifier);
if (!mAgentPaths.contains(url)) {
mAgentPaths << url;
if (!url.isEmpty()) {
ExportResourceArchiveJob *resourceJob = new ExportResourceArchiveJob(this);
resourceJob->setArchivePath(archivePath);
resourceJob->setUrl(url);
resourceJob->setIdentifier(identifier);
resourceJob->setArchive(archive());
resourceJob->setArchiveName(QStringLiteral("alarm.zip"));
connect(resourceJob, &ExportResourceArchiveJob::error, this, &ExportAlarmJobInterface::error);
connect(resourceJob, &ExportResourceArchiveJob::info, this, &ExportAlarmJobInterface::info);
connect(resourceJob, &ExportResourceArchiveJob::terminated, this, &ExportAlarmJobInterface::slotAlarmJobTerminated);
resourceJob->start();
} else {
qCDebug(PIMDATAEXPORTERCORE_LOG) << "Url is empty for " << identifier;
QTimer::singleShot(0, this, &ExportAlarmJobInterface::slotAlarmJobTerminated);
}
} else {
QTimer::singleShot(0, this, &ExportAlarmJobInterface::slotAlarmJobTerminated);
}
} else if (identifier.contains(QLatin1String("akonadi_kalarm_resource_"))) {
backupResourceFile(agent, Utils::alarmPath());
QTimer::singleShot(0, this, &ExportAlarmJobInterface::slotAlarmJobTerminated);
} else {
QTimer::singleShot(0, this, &ExportAlarmJobInterface::slotAlarmJobTerminated);
}
} else {
Q_EMIT info(i18n("Resources backup done."));
QTimer::singleShot(0, this, &ExportAlarmJobInterface::slotCheckBackupConfig);
}
}
void ExportAlarmJobInterface::backupConfig()
{
......
......@@ -32,15 +32,14 @@ public:
~ExportAlarmJobInterface() override;
void start() override;
protected:
virtual void exportArchiveResource() = 0;
void slotCheckBackupConfig();
private:
void slotCheckBackupResource();
void slotCheckBackupConfig();
void slotAlarmJobTerminated();
void slotWriteNextArchiveResource();
void backupConfig();
int mIndexIdentifier = 0;
};
#endif // EXPORTALARMJOBINTERFACE_H
/*
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 "exportalarmjobinterfaceimpl.h"
#include <AkonadiCore/AgentManager>
#include <KLocalizedString>
#include <QTemporaryFile>
#include <QTimer>
#include <KConfigGroup>
#include <QFile>
#include <QDir>
#include <QStandardPaths>
#include <exportresourcearchivejob.h>
#include "resourceconverterimpl.h"
ExportAlarmJobInterfaceImpl::ExportAlarmJobInterfaceImpl(QObject *parent, Utils::StoredTypes typeSelected, ArchiveStorage *archiveStorage, int numberOfStep)
: ExportAlarmJobInterface(parent, typeSelected, archiveStorage, numberOfStep)
{
}
ExportAlarmJobInterfaceImpl::~ExportAlarmJobInterfaceImpl()
{
}
void ExportAlarmJobInterfaceImpl::slotAlarmJobTerminated()
{
if (wasCanceled()) {
Q_EMIT jobFinished();
return;
}
mIndexIdentifier++;
QTimer::singleShot(0, this, &ExportAlarmJobInterfaceImpl::slotWriteNextArchiveResource);
}
void ExportAlarmJobInterfaceImpl::slotWriteNextArchiveResource()
{
Akonadi::AgentManager *manager = Akonadi::AgentManager::self();
const Akonadi::AgentInstance::List list = manager->instances();
if (mIndexIdentifier < list.count()) {
const Akonadi::AgentInstance agent = list.at(mIndexIdentifier);
const QString identifier = agent.identifier();
if (identifier.contains(QLatin1String("akonadi_kalarm_dir_resource_"))) {
const QString archivePath = Utils::alarmPath() + identifier + QLatin1Char('/');
ResourceConverterImpl converter;
const QString url = converter.resourcePath(identifier);
if (!mAgentPaths.contains(url)) {
mAgentPaths << url;
if (!url.isEmpty()) {
ExportResourceArchiveJob *resourceJob = new ExportResourceArchiveJob(this);
resourceJob->setArchivePath(archivePath);
resourceJob->setUrl(url);
resourceJob->setIdentifier(identifier);
resourceJob->setArchive(archive());
resourceJob->setArchiveName(QStringLiteral("alarm.zip"));
connect(resourceJob, &ExportResourceArchiveJob::error, this, &ExportAlarmJobInterfaceImpl::error);
connect(resourceJob, &ExportResourceArchiveJob::info, this, &ExportAlarmJobInterfaceImpl::info);
connect(resourceJob, &ExportResourceArchiveJob::terminated, this, &ExportAlarmJobInterfaceImpl::slotAlarmJobTerminated);
resourceJob->start();
} else {
qCDebug(PIMDATAEXPORTERCORE_LOG) << "Url is empty for " << identifier;
QTimer::singleShot(0, this, &ExportAlarmJobInterfaceImpl::slotAlarmJobTerminated);
}
} else {
QTimer::singleShot(0, this, &ExportAlarmJobInterfaceImpl::slotAlarmJobTerminated);
}
} else if (identifier.contains(QLatin1String("akonadi_kalarm_resource_"))) {
backupResourceFile(agent, Utils::alarmPath());
QTimer::singleShot(0, this, &ExportAlarmJobInterfaceImpl::slotAlarmJobTerminated);
} else {
QTimer::singleShot(0, this, &ExportAlarmJobInterfaceImpl::slotAlarmJobTerminated);
}
} else {
Q_EMIT info(i18n("Resources backup done."));
QTimer::singleShot(0, this, &ExportAlarmJobInterfaceImpl::slotCheckBackupConfig);
}
}
void ExportAlarmJobInterfaceImpl::exportArchiveResource()
{
QTimer::singleShot(0, this, &ExportAlarmJobInterfaceImpl::slotWriteNextArchiveResource);
}
/*
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 EXPORTALARMJOBINTERFACEIMPL_H
#define EXPORTALARMJOBINTERFACEIMPL_H
#include "exportalarmjobinterface.h"
#include "pimdataexportercore_private_export.h"
class ArchiveStorage;
class PIMDATAEXPORTER_TESTS_EXPORT ExportAlarmJobInterfaceImpl : public ExportAlarmJobInterface
{
Q_OBJECT
public:
explicit ExportAlarmJobInterfaceImpl(QObject *parent, Utils::StoredTypes typeSelected, ArchiveStorage *archiveStorage, int numberOfStep);
~ExportAlarmJobInterfaceImpl() override;
protected:
void exportArchiveResource() override;
private:
void slotAlarmJobTerminated();
void slotWriteNextArchiveResource();
int mIndexIdentifier = 0;
};
#endif // EXPORTALARMJOBINTERFACEIMPL_H
......@@ -30,7 +30,7 @@
#include "calendar/importcalendarjobinterfaceimpl.h"
#include "calendar/exportcalendarjobinterfaceimpl.h"
#include "alarm/exportalarmjobinterface.h"
#include "alarm/exportalarmjobinterfaceimpl.h"
#include "alarm/importalarmjobinterfaceimpl.h"
#include "notes/exportnotesjobinterfaceimpl.h"
......@@ -46,9 +46,6 @@
#include <QDateTime>
#include <QLocale>
PimDataBackupRestore::PimDataBackupRestore(QObject *parent)
: QObject(parent)
{
......@@ -149,7 +146,7 @@ void PimDataBackupRestore::backupNextStep()
break;
case Utils::KAlarm:
if (mStoreIterator.value().numberSteps != 0) {
mImportExportData = new ExportAlarmJobInterface(this, mStoreIterator.value().types, mArchiveStorage, mStoreIterator.value().numberSteps);
mImportExportData = new ExportAlarmJobInterfaceImpl(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