Commit e1fe4151 authored by Laurent Montel's avatar Laurent Montel 😁
Browse files

Start to look at how we can create more autotest

parent 81d5302b
......@@ -26,6 +26,7 @@ set(pimdataexporter_alarm_SRCS
set(pimdataexporter_notes_SRCS
notes/exportnotesjob.cpp
#notes/exportnotesjobinterfaceimpl.cpp
notes/importnotesjob.cpp
)
......
......@@ -18,6 +18,7 @@
*/
#include "exportnotesjob.h"
#include "exportresourcearchivejob.h"
#include <AkonadiCore/AgentManager>
......@@ -29,7 +30,6 @@
#include <QDir>
#include <QTimer>
#include <QStandardPaths>
#include <exportresourcearchivejob.h>
ExportNotesJob::ExportNotesJob(QObject *parent, Utils::StoredTypes typeSelected, ArchiveStorage *archiveStorage, int numberOfStep)
: AbstractImportExportJob(parent, archiveStorage, typeSelected, numberOfStep)
......
/*
Copyright (C) 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 EXPORTNOTESJOBINTERFACE_H
#define EXPORTNOTESJOBINTERFACE_H
#include <QObject>
class ExportNotesJobInterface
{
Q_OBJECT
public:
explicit ExportNotesJobInterface(QObject *parent = nullptr)
: QObject(parent)
{}
virtual void writeNextArchiveResource() = 0;
};
#endif // EXPORTNOTESJOBINTERFACE_H
/*
Copyright (C) 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 "exportnotesjobinterfaceimpl.h"
#include "core/utils.h"
#include <AkonadiCore/AgentInstance>
#include <AkonadiCore/AgentManager>
#include <QDir>
#include <QTimer>
#include <exportresourcearchivejob.h>
ExportNotesJobInterfaceImpl::ExportNotesJobInterfaceImpl(QObject *parent)
: ExportNotesJobInterface(parent)
{
}
ExportNotesJobInterfaceImpl::~ExportNotesJobInterfaceImpl()
{
}
void ExportNotesJobInterfaceImpl::writeNextArchiveResource()
{
QTimer::singleShot(0, this, &ExportNotesJobInterfaceImpl::slotWriteNextArchiveResource);
}
void ExportNotesJobInterfaceImpl::slotWriteNextArchiveResource()
{
Akonadi::AgentManager *manager = Akonadi::AgentManager::self();
const Akonadi::AgentInstance::List list = manager->instances();
if (mIndexIdentifier < list.count()) {
Akonadi::AgentInstance agent = list.at(mIndexIdentifier);
const QString identifier = agent.identifier();
if (identifier.contains(QLatin1String("akonadi_akonotes_resource_"))) {
const QString archivePath = Utils::notePath() + identifier + QLatin1Char('/');
QString url = Utils::resourcePath(agent);
if (!mAgentPaths.contains(url) && QDir(url).exists()) {
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("notes.zip"));
connect(resourceJob, &ExportResourceArchiveJob::error, this, &ExportNotesJob::error);
connect(resourceJob, &ExportResourceArchiveJob::info, this, &ExportNotesJob::info);
connect(resourceJob, &ExportResourceArchiveJob::terminated, this, &ExportNotesJobInterfaceImpl::slotNoteJobTerminated);
resourceJob->start();
} 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, &ExportNotesJobInterfaceImpl::slotCheckBackupConfig);
}
}
void ExportNotesJobInterfaceImpl::slotNoteJobTerminated()
{
if (wasCanceled()) {
Q_EMIT jobFinished();
return;
}
mIndexIdentifier++;
QTimer::singleShot(0, this, &ExportNotesJobInterfaceImpl::slotWriteNextArchiveResource);
}
/*
Copyright (C) 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 EXPORTNOTESJOBINTERFACEIMPL_H
#define EXPORTNOTESJOBINTERFACEIMPL_H
#include "exportnotesjobinterface.h"
class ExportNotesJobInterfaceImpl : public ExportNotesJobInterface
{
Q_OBJECT
public:
explicit ExportNotesJobInterfaceImpl(QObject *parent = nullptr);
~ExportNotesJobInterfaceImpl();
void writeNextArchiveResource() override;
private:
void slotWriteNextArchiveResource();
void slotNoteJobTerminated();
int mIndexIdentifier = 0;
};
#endif // EXPORTNOTESJOBINTERFACEIMPL_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