Commit 3972d67d authored by Laurent Montel's avatar Laurent Montel 😁
Browse files

Start to implement exportaddressbookjobinterfaceimpl

parent 5bcd6a4c
......@@ -9,7 +9,7 @@ set(pimdataexporter_calendar_SRCS
)
set(pimdataexporter_addressbook_SRCS
addressbook/exportaddressbookjobinterface.cpp
addressbook/exportaddressbookjobinterfaceimpl.cpp
addressbook/importaddressbookjobinterface.cpp
)
......@@ -29,6 +29,7 @@ set(pimdataexporter_interfaces_SRCS
notes/importnotesjobinterface.cpp
calendar/exportcalendarjobinterface.cpp
calendar/importcalendarjobinterface.cpp
addressbook/exportaddressbookjobinterface.cpp
)
set(pimdataexporter_notes_SRCS
......
......@@ -20,8 +20,6 @@
#include "exportaddressbookjobinterface.h"
#include "exportresourcearchivejob.h"
#include <AkonadiCore/AgentManager>
#include <KLocalizedString>
#include <QTemporaryFile>
......@@ -58,9 +56,10 @@ void ExportAddressbookJobInterface::slotCheckBackupResource()
{
setProgressDialogLabel(i18n("Backing up resources..."));
increaseProgressDialog();
QTimer::singleShot(0, this, &ExportAddressbookJobInterface::slotWriteNextArchiveResource);
exportArchiveResource();
}
void ExportAddressbookJobInterface::slotCheckBackupConfig()
{
if (mTypeSelected & Utils::Config) {
......@@ -74,59 +73,6 @@ void ExportAddressbookJobInterface::slotCheckBackupConfig()
Q_EMIT jobFinished();
}
void ExportAddressbookJobInterface::slotAddressbookJobTerminated()
{
if (wasCanceled()) {
Q_EMIT jobFinished();
return;
}
mIndexIdentifier++;
QTimer::singleShot(0, this, &ExportAddressbookJobInterface::slotWriteNextArchiveResource);
}
void ExportAddressbookJobInterface::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_vcarddir_resource_")) || identifier.contains(QLatin1String("akonadi_contacts_resource_"))) {
const QString archivePath = Utils::addressbookPath() + identifier + QLatin1Char('/');
ResourceConverterImpl converter;
const QString url = converter.resourcePath(identifier, QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation) + QStringLiteral("/contacts/"));
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("addressbook.zip"));
connect(resourceJob, &ExportResourceArchiveJob::error, this, &ExportAddressbookJobInterface::error);
connect(resourceJob, &ExportResourceArchiveJob::info, this, &ExportAddressbookJobInterface::info);
connect(resourceJob, &ExportResourceArchiveJob::terminated, this, &ExportAddressbookJobInterface::slotAddressbookJobTerminated);
resourceJob->start();
} else {
qCDebug(PIMDATAEXPORTERCORE_LOG) << "Url is empty for " << identifier;
QTimer::singleShot(0, this, &ExportAddressbookJobInterface::slotAddressbookJobTerminated);
}
} else {
QTimer::singleShot(0, this, &ExportAddressbookJobInterface::slotAddressbookJobTerminated);
}
} else if (identifier.contains(QLatin1String("akonadi_vcard_resource_"))) {
backupResourceFile(agent, Utils::addressbookPath());
QTimer::singleShot(0, this, &ExportAddressbookJobInterface::slotAddressbookJobTerminated);
} else {
QTimer::singleShot(0, this, &ExportAddressbookJobInterface::slotAddressbookJobTerminated);
}
} else {
Q_EMIT info(i18n("Resources backup done."));
QTimer::singleShot(0, this, &ExportAddressbookJobInterface::slotCheckBackupConfig);
}
}
void ExportAddressbookJobInterface::backupConfig()
{
......
......@@ -17,8 +17,8 @@
Boston, MA 02110-1301, USA.
*/
#ifndef EXPORTADDRESSBOOKJOB_H
#define EXPORTADDRESSBOOKJOB_H
#ifndef EXPORTADDRESSBOOKINTERFACE_H
#define EXPORTADDRESSBOOKINTERFACE_H
#include "abstractimportexportjob.h"
#include "pimdataexportercore_private_export.h"
......@@ -33,14 +33,13 @@ public:
void start() override;
private:
protected:
virtual void exportArchiveResource() = 0;
void slotCheckBackupConfig();
private:
void slotCheckBackupResource();
void slotWriteNextArchiveResource();
void slotAddressbookJobTerminated();
void backupConfig();
int mIndexIdentifier = 0;
};
#endif // EXPORTADDRESSBOOKJOB_H
#endif // EXPORTADDRESSBOOKINTERFACE_H
/*
Copyright (C) 2013-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 "exportaddressbookjobinterfaceimpl.h"
#include "exportresourcearchivejob.h"
#include <AkonadiCore/AgentManager>
#include <KLocalizedString>
#include <QTemporaryFile>
#include <KConfigGroup>
#include <QDir>
#include <QStandardPaths>
#include <QTimer>
#include "resourceconverterimpl.h"
ExportAddressbookJobInterfaceImpl::ExportAddressbookJobInterfaceImpl(QObject *parent, Utils::StoredTypes typeSelected, ArchiveStorage *archiveStorage, int numberOfStep)
: ExportAddressbookJobInterface(parent, typeSelected, archiveStorage, numberOfStep)
{
}
ExportAddressbookJobInterfaceImpl::~ExportAddressbookJobInterfaceImpl()
{
}
void ExportAddressbookJobInterfaceImpl::exportArchiveResource()
{
QTimer::singleShot(0, this, &ExportAddressbookJobInterfaceImpl::slotWriteNextArchiveResource);
}
void ExportAddressbookJobInterfaceImpl::slotAddressbookJobTerminated()
{
if (wasCanceled()) {
Q_EMIT jobFinished();
return;
}
mIndexIdentifier++;
QTimer::singleShot(0, this, &ExportAddressbookJobInterfaceImpl::slotWriteNextArchiveResource);
}
void ExportAddressbookJobInterfaceImpl::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_vcarddir_resource_")) || identifier.contains(QLatin1String("akonadi_contacts_resource_"))) {
const QString archivePath = Utils::addressbookPath() + identifier + QLatin1Char('/');
ResourceConverterImpl converter;
const QString url = converter.resourcePath(identifier, QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation) + QStringLiteral("/contacts/"));
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("addressbook.zip"));
connect(resourceJob, &ExportResourceArchiveJob::error, this, &ExportAddressbookJobInterfaceImpl::error);
connect(resourceJob, &ExportResourceArchiveJob::info, this, &ExportAddressbookJobInterfaceImpl::info);
connect(resourceJob, &ExportResourceArchiveJob::terminated, this, &ExportAddressbookJobInterfaceImpl::slotAddressbookJobTerminated);
resourceJob->start();
} else {
qCDebug(PIMDATAEXPORTERCORE_LOG) << "Url is empty for " << identifier;
QTimer::singleShot(0, this, &ExportAddressbookJobInterfaceImpl::slotAddressbookJobTerminated);
}
} else {
QTimer::singleShot(0, this, &ExportAddressbookJobInterfaceImpl::slotAddressbookJobTerminated);
}
} else if (identifier.contains(QLatin1String("akonadi_vcard_resource_"))) {
backupResourceFile(agent, Utils::addressbookPath());
QTimer::singleShot(0, this, &ExportAddressbookJobInterfaceImpl::slotAddressbookJobTerminated);
} else {
QTimer::singleShot(0, this, &ExportAddressbookJobInterfaceImpl::slotAddressbookJobTerminated);
}
} else {
Q_EMIT info(i18n("Resources backup done."));
QTimer::singleShot(0, this, &ExportAddressbookJobInterfaceImpl::slotCheckBackupConfig);
}
}
/*
Copyright (C) 2013-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 EXPORTADDRESSBOOKINTERFACEIMPL_H
#define EXPORTADDRESSBOOKINTERFACEIMPL_H
#include "exportaddressbookjobinterface.h"
#include "pimdataexportercore_private_export.h"
class ArchiveStorage;
class PIMDATAEXPORTER_TESTS_EXPORT ExportAddressbookJobInterfaceImpl : public ExportAddressbookJobInterface
{
Q_OBJECT
public:
explicit ExportAddressbookJobInterfaceImpl(QObject *parent, Utils::StoredTypes typeSelected, ArchiveStorage *archiveStorage, int numberOfStep);
~ExportAddressbookJobInterfaceImpl() override;
protected:
void exportArchiveResource() override;
private:
void slotWriteNextArchiveResource();
void slotAddressbookJobTerminated();
void backupConfig();
int mIndexIdentifier = 0;
};
#endif // EXPORTADDRESSBOOKINTERFACEIMPL_H
......@@ -24,7 +24,7 @@
#include "mail/exportmailjobinterface.h"
#include "mail/importmailjobinterface.h"
#include "addressbook/exportaddressbookjobinterface.h"
#include "addressbook/exportaddressbookjobinterfaceimpl.h"
#include "addressbook/importaddressbookjobinterface.h"
#include "calendar/importcalendarjobinterfaceimpl.h"
......@@ -46,6 +46,7 @@
#include <QDateTime>
#include <QLocale>
PimDataBackupRestore::PimDataBackupRestore(QObject *parent)
: QObject(parent)
{
......@@ -140,7 +141,7 @@ void PimDataBackupRestore::backupNextStep()
break;
case Utils::KAddressBook:
if (mStoreIterator.value().numberSteps != 0) {
mImportExportData = new ExportAddressbookJobInterface(this, mStoreIterator.value().types, mArchiveStorage, mStoreIterator.value().numberSteps);
mImportExportData = new ExportAddressbookJobInterfaceImpl(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