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

Move code to interface method

parent 152a8ddd
......@@ -28,6 +28,7 @@
#include <QDir>
#include <QStandardPaths>
#include <QTimer>
#include <resourceconverterimpl.h>
ExportAddressbookJobInterface::ExportAddressbookJobInterface(QObject *parent, Utils::StoredTypes typeSelected, ArchiveStorage *archiveStorage, int numberOfStep)
: AbstractImportExportJob(parent, archiveStorage, typeSelected, numberOfStep)
......@@ -71,6 +72,50 @@ 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()
{
if (mIndexIdentifier < mAkonadiInstanceInfo.count()) {
const Utils::AkonadiInstanceInfo agent = mAkonadiInstanceInfo.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)) {
if (!url.isEmpty()) {
mAgentPaths << url;
exportResourceToArchive(archivePath, url, identifier);
} 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(identifier, 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()
{
setProgressDialogLabel(i18n("Backing up config..."));
......
......@@ -32,6 +32,8 @@ public:
~ExportAddressbookJobInterface() override;
void start() override;
void slotWriteNextArchiveResource();
void slotAddressbookJobTerminated();
protected:
virtual void exportArchiveResource() = 0;
......@@ -44,6 +46,7 @@ private:
void slotCheckBackupResource();
void backupConfig();
int mIndexIdentifier = 0;
};
#endif // EXPORTADDRESSBOOKINTERFACE_H
......@@ -52,48 +52,6 @@ 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()
{
if (mIndexIdentifier < mAkonadiInstanceInfo.count()) {
const Utils::AkonadiInstanceInfo agent = mAkonadiInstanceInfo.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)) {
if (!url.isEmpty()) {
mAgentPaths << url;
exportResourceToArchive(archivePath, url, identifier);
} 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(identifier, 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);
}
}
void ExportAddressbookJobInterfaceImpl::convertCollectionToRealPath(KConfigGroup &group, const QString &currentKey)
{
......
......@@ -38,12 +38,6 @@ protected:
Q_REQUIRED_RESULT Akonadi::Collection::Id convertFolderPathToCollectionId(const QString &path) override;
void exportResourceToArchive(const QString &archivePath, const QString &url, const QString &identifier) override;
Q_REQUIRED_RESULT QVector<Utils::AkonadiInstanceInfo> listOfResource() override;
private:
void slotWriteNextArchiveResource();
void slotAddressbookJobTerminated();
void backupConfig();
int mIndexIdentifier = 0;
};
#endif // EXPORTADDRESSBOOKINTERFACEIMPL_H
......@@ -53,6 +53,59 @@ void ExportAlarmJobInterface::start()
}
}
void ExportAlarmJobInterface::slotAlarmJobTerminated()
{
if (wasCanceled()) {
Q_EMIT jobFinished();
return;
}
mIndexIdentifier++;
QTimer::singleShot(0, this, &ExportAlarmJobInterface::slotWriteNextArchiveResource);
}
void ExportAlarmJobInterface::slotWriteNextArchiveResource()
{
if (mIndexIdentifier < mAkonadiInstanceInfo.count()) {
const Utils::AkonadiInstanceInfo agent = mAkonadiInstanceInfo.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)) {
if (!url.isEmpty()) {
mAgentPaths << url;
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(identifier, 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::slotCheckBackupResource()
{
setProgressDialogLabel(i18n("Backing up resources..."));
......
......@@ -32,6 +32,8 @@ public:
~ExportAlarmJobInterface() override;
void start() override;
void slotAlarmJobTerminated();
void slotWriteNextArchiveResource();
protected:
virtual void exportArchiveResource() = 0;
void slotCheckBackupConfig();
......@@ -41,6 +43,10 @@ private:
void slotCheckBackupResource();
void backupConfig();
private:
int mIndexIdentifier = 0;
};
#endif // EXPORTALARMJOBINTERFACE_H
......@@ -46,57 +46,6 @@ QVector<Utils::AkonadiInstanceInfo> ExportAlarmJobInterfaceImpl::listOfResource(
return Utils::listOfResource();
}
void ExportAlarmJobInterfaceImpl::slotAlarmJobTerminated()
{
if (wasCanceled()) {
Q_EMIT jobFinished();
return;
}
mIndexIdentifier++;
QTimer::singleShot(0, this, &ExportAlarmJobInterfaceImpl::slotWriteNextArchiveResource);
}
void ExportAlarmJobInterfaceImpl::slotWriteNextArchiveResource()
{
if (mIndexIdentifier < mAkonadiInstanceInfo.count()) {
const Utils::AkonadiInstanceInfo agent = mAkonadiInstanceInfo.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)) {
if (!url.isEmpty()) {
mAgentPaths << url;
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(identifier, 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()
{
......
......@@ -37,11 +37,6 @@ protected:
void exportResourceToArchive(const QString &archivePath, const QString &url, const QString &identifier) override;
Q_REQUIRED_RESULT QVector<Utils::AkonadiInstanceInfo> listOfResource() override;
private:
void slotAlarmJobTerminated();
void slotWriteNextArchiveResource();
int mIndexIdentifier = 0;
};
#endif // EXPORTALARMJOBINTERFACEIMPL_H
......@@ -28,6 +28,7 @@
#include <QFile>
#include <QDir>
#include <QColor>
#include <resourceconverterimpl.h>
#include <QStandardPaths>
#include <exportresourcearchivejob.h>
......@@ -41,6 +42,49 @@ ExportCalendarJobInterface::~ExportCalendarJobInterface()
{
}
void ExportCalendarJobInterface::slotCalendarJobTerminated()
{
if (wasCanceled()) {
Q_EMIT jobFinished();
return;
}
mIndexIdentifier++;
QTimer::singleShot(0, this, &ExportCalendarJobInterface::slotWriteNextArchiveResource);
}
void ExportCalendarJobInterface::slotWriteNextArchiveResource()
{
if (mIndexIdentifier < mAkonadiInstanceInfo.count()) {
const Utils::AkonadiInstanceInfo agent = mAkonadiInstanceInfo.at(mIndexIdentifier);
const QString identifier = agent.identifier;
if (identifier.contains(QLatin1String("akonadi_icaldir_resource_"))) {
const QString archivePath = Utils::calendarPath() + identifier + QLatin1Char('/');
ResourceConverterImpl converter;
const QString url = converter.resourcePath(identifier);
if (!mAgentPaths.contains(url)) {
if (!url.isEmpty()) {
mAgentPaths << url;
exportResourceToArchive(archivePath, url, identifier);
} else {
qCDebug(PIMDATAEXPORTERCORE_LOG) << "Url is empty for " << identifier;
QTimer::singleShot(0, this, &ExportCalendarJobInterface::slotCalendarJobTerminated);
}
} else {
QTimer::singleShot(0, this, &ExportCalendarJobInterface::slotCalendarJobTerminated);
}
} else if (identifier.contains(QLatin1String("akonadi_ical_resource_"))) {
backupResourceFile(identifier, Utils::calendarPath());
QTimer::singleShot(0, this, &ExportCalendarJobInterface::slotCalendarJobTerminated);
} else {
QTimer::singleShot(0, this, &ExportCalendarJobInterface::slotCalendarJobTerminated);
}
} else {
Q_EMIT info(i18n("Resources backup done."));
QTimer::singleShot(0, this, &ExportCalendarJobInterface::slotCheckBackupConfig);
}
}
void ExportCalendarJobInterface::start()
{
Q_EMIT title(i18n("Start export KOrganizer settings..."));
......
......@@ -32,6 +32,8 @@ public:
~ExportCalendarJobInterface() override;
void start() override;
void slotCalendarJobTerminated();
void slotWriteNextArchiveResource();
protected:
virtual void exportArchiveResource() = 0;
......@@ -45,6 +47,7 @@ private:
void backupConfig();
int mIndexIdentifier = 0;
};
#endif // EXPORTCALENDARJOBINTERFACE_H
......@@ -66,49 +66,6 @@ void ExportCalendarJobInterfaceImpl::convertCollectionListToRealPath(KConfigGrou
converter.convertCollectionListToRealPath(group, currentKey);
}
void ExportCalendarJobInterfaceImpl::slotCalendarJobTerminated()
{
if (wasCanceled()) {
Q_EMIT jobFinished();
return;
}
mIndexIdentifier++;
QTimer::singleShot(0, this, &ExportCalendarJobInterfaceImpl::slotWriteNextArchiveResource);
}
void ExportCalendarJobInterfaceImpl::slotWriteNextArchiveResource()
{
if (mIndexIdentifier < mAkonadiInstanceInfo.count()) {
const Utils::AkonadiInstanceInfo agent = mAkonadiInstanceInfo.at(mIndexIdentifier);
const QString identifier = agent.identifier;
if (identifier.contains(QLatin1String("akonadi_icaldir_resource_"))) {
const QString archivePath = Utils::calendarPath() + identifier + QLatin1Char('/');
ResourceConverterImpl converter;
const QString url = converter.resourcePath(identifier);
if (!mAgentPaths.contains(url)) {
if (!url.isEmpty()) {
mAgentPaths << url;
exportResourceToArchive(archivePath, url, identifier);
} else {
qCDebug(PIMDATAEXPORTERCORE_LOG) << "Url is empty for " << identifier;
QTimer::singleShot(0, this, &ExportCalendarJobInterfaceImpl::slotCalendarJobTerminated);
}
} else {
QTimer::singleShot(0, this, &ExportCalendarJobInterfaceImpl::slotCalendarJobTerminated);
}
} else if (identifier.contains(QLatin1String("akonadi_ical_resource_"))) {
backupResourceFile(identifier, Utils::calendarPath());
QTimer::singleShot(0, this, &ExportCalendarJobInterfaceImpl::slotCalendarJobTerminated);
} else {
QTimer::singleShot(0, this, &ExportCalendarJobInterfaceImpl::slotCalendarJobTerminated);
}
} else {
Q_EMIT info(i18n("Resources backup done."));
QTimer::singleShot(0, this, &ExportCalendarJobInterfaceImpl::slotCheckBackupConfig);
}
}
QString ExportCalendarJobInterfaceImpl::convertToFullCollectionPath(const qlonglong collectionValue)
{
ResourceConverterImpl converter;
......
......@@ -38,10 +38,6 @@ protected:
void convertCollectionListToRealPath(KConfigGroup &group, const QString &currentKey) override;
void exportResourceToArchive(const QString &archivePath, const QString &url, const QString &identifier) override;
Q_REQUIRED_RESULT QVector<Utils::AkonadiInstanceInfo> listOfResource() override;
private:
void slotCalendarJobTerminated();
void slotWriteNextArchiveResource();
int mIndexIdentifier = 0;
};
#endif // EXPORTCALENDARJOBINTERFACEIMPL_H
......@@ -31,12 +31,13 @@
#include <QTemporaryFile>
#include "pimdataexportcore_debug.h"
#include <KMime/Message>
#include <QFile>
#include <QDir>
#include <QTimer>
#include <QStandardPaths>
#include <QRegularExpression>
#include <resourceconverterimpl.h>
#include <KIdentityManagement/IdentityManager>
#include <KIdentityManagement/Identity>
......@@ -581,3 +582,57 @@ void ExportMailJobInterface::backupIdentity()
}
}
}
void ExportMailJobInterface::slotMailsJobTerminated()
{
if (wasCanceled()) {
Q_EMIT jobFinished();
return;
}
mIndexIdentifier++;
exportArchiveResource();
}
void ExportMailJobInterface::slotWriteNextArchiveResource()
{
if (mIndexIdentifier < mAkonadiInstanceInfo.count()) {
const Utils::AkonadiInstanceInfo agent = mAkonadiInstanceInfo.at(mIndexIdentifier);
const QStringList capabilities(agent.capabilities);
if (agent.mimeTypes.contains(KMime::Message::mimeType())) {
if (capabilities.contains(QLatin1String("Resource"))
&& !capabilities.contains(QLatin1String("Virtual"))
&& !capabilities.contains(QLatin1String("MailTransport"))) {
const QString identifier = agent.identifier;
if (identifier.contains(QLatin1String("akonadi_maildir_resource_"))
|| identifier.contains(QLatin1String("akonadi_mixedmaildir_resource_"))) {
const QString archivePath = Utils::mailsPath() + identifier + QLatin1Char('/');
ResourceConverterImpl converter;
const QString url = converter.resourcePath(identifier);
if (!mAgentPaths.contains(url)) {
if (!url.isEmpty()) {
mAgentPaths << url;
exportResourceToArchive(archivePath, url, identifier);
} else {
qCDebug(PIMDATAEXPORTERCORE_LOG) << "Url is empty for " << identifier;
QTimer::singleShot(0, this, &ExportMailJobInterface::slotMailsJobTerminated);
}
} else {
QTimer::singleShot(0, this, &ExportMailJobInterface::slotMailsJobTerminated);
}
} else if (identifier.contains(QLatin1String("akonadi_mbox_resource_"))) {
backupResourceFile(identifier, Utils::addressbookPath());
QTimer::singleShot(0, this, &ExportMailJobInterface::slotMailsJobTerminated);
} else {
QTimer::singleShot(0, this, &ExportMailJobInterface::slotMailsJobTerminated);
}
} else {
QTimer::singleShot(0, this, &ExportMailJobInterface::slotMailsJobTerminated);
}
} else {
QTimer::singleShot(0, this, &ExportMailJobInterface::slotMailsJobTerminated);
}
} else {
QTimer::singleShot(0, this, &ExportMailJobInterface::slotCheckBackupResources);
}
}
......@@ -38,6 +38,8 @@ public:
~ExportMailJobInterface() override;
void start() override;
void slotWriteNextArchiveResource();
void slotMailsJobTerminated();
Q_SIGNALS:
void taskCanceled();
......@@ -63,6 +65,10 @@ private:
void backupTransports();
void backupConfig();
void backupIdentity();
private:
int mIndexIdentifier = 0;
};
#endif // ExportMailJob_H
......@@ -55,62 +55,51 @@ ExportMailJobInterfaceImpl::~ExportMailJobInterfaceImpl()
{
}
void ExportMailJobInterfaceImpl::slotMailsJobTerminated()
{
if (wasCanceled()) {
Q_EMIT jobFinished();
return;
}
mIndexIdentifier++;
exportArchiveResource();
}
void ExportMailJobInterfaceImpl::exportArchiveResource()
{
QTimer::singleShot(0, this, &ExportMailJobInterfaceImpl::slotWriteNextArchiveResource);
}
void ExportMailJobInterfaceImpl::slotWriteNextArchiveResource()
Akonadi::Collection::Id ExportMailJobInterfaceImpl::convertFolderPathToCollectionId(const QString &path)
{
if (mIndexIdentifier < mAkonadiInstanceInfo.count()) {
const Utils::AkonadiInstanceInfo agent = mAkonadiInstanceInfo.at(mIndexIdentifier);
const QStringList capabilities(agent.capabilities);
if (agent.mimeTypes.contains(KMime::Message::mimeType())) {
if (capabilities.contains(QLatin1String("Resource"))
&& !capabilities.contains(QLatin1String("Virtual"))
&& !capabilities.contains(QLatin1String("MailTransport"))) {
const QString identifier = agent.identifier;
if (identifier.contains(QLatin1String("akonadi_maildir_resource_"))
|| identifier.contains(QLatin1String("akonadi_mixedmaildir_resource_"))) {
const QString archivePath = Utils::mailsPath() + identifier + QLatin1Char('/');
ResourceConverterImpl converter;
const QString url = converter.resourcePath(identifier);
if (!mAgentPaths.contains(url)) {
if (!url.isEmpty()) {
mAgentPaths << url;
exportResourceToArchive(archivePath, url, identifier);
} else {
qCDebug(PIMDATAEXPORTERCORE_LOG) << "Url is empty for " << identifier;
QTimer::singleShot(0, this, &ExportMailJobInterfaceImpl::slotMailsJobTerminated);
}
} else {
QTimer::singleShot(0, this, &ExportMailJobInterfaceImpl::slotMailsJobTerminated);
}
} else if (identifier.contains(QLatin1String("akonadi_mbox_resource_"))) {
backupResourceFile(identifier, Utils::addressbookPath());
QTimer::singleShot(0, this, &ExportMailJobInterfaceImpl::slotMailsJobTerminated);
} else {
QTimer::singleShot(0, this, &ExportMailJobInterfaceImpl::slotMailsJobTerminated);
}
} else {
QTimer::singleShot(0, this, &ExportMailJobInterfaceImpl::slotMailsJobTerminated);
}