Commit 152a8ddd authored by Laurent Montel's avatar Laurent Montel 😁
Browse files

Move code in exportnotesjobinterface now

parent 3e7badc5
/*
/*
Copyright (C) 2013-2020 Laurent Montel <montel@kde.org>
This program is free software; you can redistribute it and/or
......@@ -28,6 +28,7 @@
#include <QDir>
#include <QTimer>
#include <QStandardPaths>
#include <resourceconverterimpl.h>
ExportNotesJobInterface::ExportNotesJobInterface(QObject *parent, Utils::StoredTypes typeSelected, ArchiveStorage *archiveStorage, int numberOfStep)
: AbstractImportExportJob(parent, archiveStorage, typeSelected, numberOfStep)
......@@ -121,3 +122,43 @@ void ExportNotesJobInterface::backupConfig()
storeDirectory(QStringLiteral("/knotes/print/theme/"));
Q_EMIT info(i18n("Config backup done."));
}
void ExportNotesJobInterface::slotNoteJobTerminated()
{
if (wasCanceled()) {
Q_EMIT jobFinished();
return;
}
mIndexIdentifier++;
QTimer::singleShot(0, this, &ExportNotesJobInterface::slotWriteNextArchiveResource);
}
void ExportNotesJobInterface::slotWriteNextArchiveResource()
{
if (mIndexIdentifier < mAkonadiInstanceInfo.count()) {
const Utils::AkonadiInstanceInfo agent = mAkonadiInstanceInfo.at(mIndexIdentifier);
const QString identifier = agent.identifier;
if (identifier.contains(QLatin1String("akonadi_akonotes_resource_"))) {
const QString archivePath = Utils::notePath() + identifier + QLatin1Char('/');
ResourceConverterImpl converter;
const QString url = converter.resourcePath(identifier);
if (!mAgentPaths.contains(url) && QDir(url).exists()) {
if (!url.isEmpty()) {
mAgentPaths << url;
exportResourceToArchive(archivePath, url, identifier);
} else {
qCDebug(PIMDATAEXPORTERCORE_LOG) << "Url is empty for " << identifier;
QTimer::singleShot(0, this, &ExportNotesJobInterface::slotNoteJobTerminated);
}
} else {
QTimer::singleShot(0, this, &ExportNotesJobInterface::slotNoteJobTerminated);
}
} else {
QTimer::singleShot(0, this, &ExportNotesJobInterface::slotNoteJobTerminated);
}
} else {
Q_EMIT info(i18n("Resources backup done."));
QTimer::singleShot(0, this, &ExportNotesJobInterface::slotCheckBackupConfig);
}
}
......@@ -34,18 +34,21 @@ public:
void start() override;
void slotCheckBackupConfig();
void slotWriteNextArchiveResource();
protected:
virtual void exportArchiveResource() = 0;
virtual void convertCollectionIdsToRealPath(KConfigGroup &selectFolderNoteGroup, const QString &selectFolderNoteGroupStr) = 0;
virtual void exportResourceToArchive(const QString &archivePath, const QString &url, const QString &identifier) = 0;
virtual Q_REQUIRED_RESULT QVector<Utils::AkonadiInstanceInfo> listOfResource() = 0;
void slotNoteJobTerminated();
private:
void slotCheckBackupResource();
void backupConfig();
void backupTheme();
int mIndexIdentifier = 0;
};
#endif // EXPORTNOTESJOBINTERFACE_H
......@@ -44,51 +44,10 @@ QVector<Utils::AkonadiInstanceInfo> ExportNotesJobInterfaceImpl::listOfResource(
{
return Utils::listOfResource();
}
void ExportNotesJobInterfaceImpl::slotNoteJobTerminated()
{
if (wasCanceled()) {
Q_EMIT jobFinished();
return;
}
mIndexIdentifier++;
QTimer::singleShot(0, this, &ExportNotesJobInterfaceImpl::slotWriteNextArchiveResource);
}
void ExportNotesJobInterfaceImpl::slotWriteNextArchiveResource()
{
if (mIndexIdentifier < mAkonadiInstanceInfo.count()) {
const Utils::AkonadiInstanceInfo agent = mAkonadiInstanceInfo.at(mIndexIdentifier);
const QString identifier = agent.identifier;
if (identifier.contains(QLatin1String("akonadi_akonotes_resource_"))) {
const QString archivePath = Utils::notePath() + identifier + QLatin1Char('/');
ResourceConverterImpl converter;
const QString url = converter.resourcePath(identifier);
if (!mAgentPaths.contains(url) && QDir(url).exists()) {
if (!url.isEmpty()) {
mAgentPaths << url;
exportResourceToArchive(archivePath, url, identifier);
} else {
qCDebug(PIMDATAEXPORTERCORE_LOG) << "Url is empty for " << identifier;
QTimer::singleShot(0, this, &ExportNotesJobInterfaceImpl::slotNoteJobTerminated);
}
} else {
QTimer::singleShot(0, this, &ExportNotesJobInterfaceImpl::slotNoteJobTerminated);
}
} else {
QTimer::singleShot(0, this, &ExportNotesJobInterfaceImpl::slotNoteJobTerminated);
}
} else {
Q_EMIT info(i18n("Resources backup done."));
QTimer::singleShot(0, this, &ExportNotesJobInterface::slotCheckBackupConfig);
}
}
void ExportNotesJobInterfaceImpl::exportArchiveResource()
{
mAkonadiInstanceInfo = listOfResource();
QTimer::singleShot(0, this, &ExportNotesJobInterfaceImpl::slotWriteNextArchiveResource);
QTimer::singleShot(0, this, &ExportNotesJobInterface::slotWriteNextArchiveResource);
}
void ExportNotesJobInterfaceImpl::convertCollectionIdsToRealPath(KConfigGroup &selectFolderNoteGroup, const QString &selectFolderNoteGroupStr)
......
......@@ -37,11 +37,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 slotNoteJobTerminated();
void slotWriteNextArchiveResource();
int mIndexIdentifier = 0;
};
#endif // EXPORTNOTESJOBINTERFACE_H
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