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

continue to implement backupresourcejob

parent ba375555
......@@ -75,7 +75,8 @@ set(pimdataexporter_LIB_SRCS
resourceconverterbase.cpp
resourceconverterimpl.cpp
storeresourcejob.cpp
backupresourcefilejob.cpp
backupresourcefilejobbase.cpp
backupresourcefilejobimpl.cpp
)
ecm_qt_declare_logging_category(pimdataexporter_LIB_SRCS HEADER pimdataexportcore_debug.h IDENTIFIER PIMDATAEXPORTERCORE_LOG CATEGORY_NAME org.kde.pim.pimdataexportercore
......
......@@ -19,7 +19,7 @@
#include "abstractimportexportjob.h"
#include "archivestorage.h"
#include "backupresourcefilejob.h"
#include "backupresourcefilejobbase.h"
#include "importexportprogressindicatorbase.h"
#include "resourceconverterimpl.h"
#include "storeresourcejob.h"
......@@ -315,12 +315,12 @@ void AbstractImportExportJob::copyToFile(const KArchiveFile *archivefile, const
void AbstractImportExportJob::backupResourceFile(const QString &identifier, const QString &defaultPath)
{
BackupResourceFileJob *job = new BackupResourceFileJob(this);
BackupResourceFileJobBase *job = new BackupResourceFileJobBase(this);
job->setDefaultPath(defaultPath);
job->setIdentifier(identifier);
job->setZip(archive());
connect(job, &BackupResourceFileJob::error, this, &AbstractImportExportJob::error);
connect(job, &BackupResourceFileJob::info, this, &AbstractImportExportJob::info);
connect(job, &BackupResourceFileJobBase::error, this, &AbstractImportExportJob::error);
connect(job, &BackupResourceFileJobBase::info, this, &AbstractImportExportJob::info);
job->start();
}
......
......@@ -90,7 +90,9 @@ protected:
Q_REQUIRED_RESULT int mergeConfigMessageBox(const QString &configName) const;
Q_REQUIRED_RESULT bool overwriteConfigMessageBox(const QString &configName) const;
Q_REQUIRED_RESULT Akonadi::Collection::Id convertPathToId(const QString &path);
void backupResourceFile(const QString &agentIdentifier, const QString &defaultPath);
virtual void backupResourceFile(const QString &agentIdentifier, const QString &defaultPath);
Q_REQUIRED_RESULT QStringList restoreResourceFile(const QString &resourceName, const QString &defaultPath, const QString &storePath, bool overwriteResources = false);
virtual void addSpecificResourceSettings(const KSharedConfig::Ptr &resourceConfig, const QString &resourceName, QMap<QString, QVariant> &settings);
void restoreConfigFile(const QString &configNameStr);
......
......@@ -19,6 +19,7 @@ add_library(test_resourceconverter STATIC
exportimportutil.cpp
saveresourceconfigtest.cpp
compareloggingfile.cpp
testbackupresourcefilejob.cpp
)
target_link_libraries(test_resourceconverter PUBLIC KF5::ConfigCore pimdataexporterprivate KF5::Archive Qt5::Test KF5::AkonadiCore)
......
......@@ -18,7 +18,7 @@
*/
#include "backupresourcefilejobtest.h"
#include "backupresourcefilejob.h"
#include "backupresourcefilejobbase.h"
#include <QTest>
QTEST_MAIN(BackupResourceFileJobTest)
BackupResourceFileJobTest::BackupResourceFileJobTest(QObject *parent)
......@@ -29,7 +29,7 @@ BackupResourceFileJobTest::BackupResourceFileJobTest(QObject *parent)
void BackupResourceFileJobTest::shouldHaveDefaultValue()
{
BackupResourceFileJob *job = new BackupResourceFileJob;
BackupResourceFileJobBase *job = new BackupResourceFileJobBase;
QVERIFY(!job->canStart());
QVERIFY(job->identifier().isEmpty());
QVERIFY(!job->zip());
......
/*
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 "testbackupresourcefilejob.h"
#include "resourceconvertertest.h"
TestBackupResourceFileJob::TestBackupResourceFileJob(QObject *parent)
: BackupResourceFileJobBase(parent)
{
}
TestBackupResourceFileJob::~TestBackupResourceFileJob()
{
}
QString TestBackupResourceFileJob::resourcePath(const QString &identifier) const
{
ResourceConverterTest converter;
const QString url = converter.resourcePath(identifier);
return url;
}
/*
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 TESTBACKUPRESOURCEFILEJOB_H
#define TESTBACKUPRESOURCEFILEJOB_H
#include <backupresourcefilejobbase.h>
class TestBackupResourceFileJob : public BackupResourceFileJobBase
{
Q_OBJECT
public:
explicit TestBackupResourceFileJob(QObject *parent = nullptr);
~TestBackupResourceFileJob();
Q_REQUIRED_RESULT QString resourcePath(const QString &identifier) const override;
};
#endif // TESTBACKUPRESOURCEFILEJOB_H
......@@ -17,7 +17,7 @@
Boston, MA 02110-1301, USA.
*/
#include "backupresourcefilejob.h"
#include "backupresourcefilejobbase.h"
#include "resourceconverterimpl.h"
#include "storeresourcejob.h"
#include "pimdataexportcore_debug.h"
......@@ -26,18 +26,25 @@
#include <QFileInfo>
BackupResourceFileJob::BackupResourceFileJob(QObject *parent)
BackupResourceFileJobBase::BackupResourceFileJobBase(QObject *parent)
: QObject(parent)
{
}
BackupResourceFileJob::~BackupResourceFileJob()
BackupResourceFileJobBase::~BackupResourceFileJobBase()
{
}
void BackupResourceFileJob::start()
QString BackupResourceFileJobBase::resourcePath(const QString &identifier) const
{
ResourceConverterImpl converter;
const QString url = converter.resourcePath(identifier);
return url;
}
void BackupResourceFileJobBase::start()
{
if (!canStart()) {
qCWarning(PIMDATAEXPORTERCORE_LOG) << "Impossible to start backupResourceFileJob";
......@@ -47,8 +54,7 @@ void BackupResourceFileJob::start()
const QString archivePath = mDefaultPath + mIdentifier + QLatin1Char('/');
ResourceConverterImpl converter;
const QString url = converter.resourcePath(mIdentifier);
const QString url = resourcePath(mIdentifier);
if (!url.isEmpty()) {
QFileInfo fi(url);
QString filename = fi.fileName();
......@@ -57,8 +63,8 @@ void BackupResourceFileJob::start()
Q_EMIT info(i18n("\"%1\" was backed up.", filename));
StoreResourceJob *job = new StoreResourceJob(this);
connect(job, &StoreResourceJob::error, this, &BackupResourceFileJob::error);
connect(job, &StoreResourceJob::info, this, &BackupResourceFileJob::info);
connect(job, &StoreResourceJob::error, this, &BackupResourceFileJobBase::error);
connect(job, &StoreResourceJob::info, this, &BackupResourceFileJobBase::info);
job->setArchivePath(archivePath);
job->setZip(mZip);
job->setIdentifier(mIdentifier);
......@@ -70,37 +76,37 @@ void BackupResourceFileJob::start()
deleteLater();
}
bool BackupResourceFileJob::canStart() const
bool BackupResourceFileJobBase::canStart() const
{
return mZip && !mDefaultPath.isEmpty() && !mIdentifier.isEmpty();
}
QString BackupResourceFileJob::identifier() const
QString BackupResourceFileJobBase::identifier() const
{
return mIdentifier;
}
void BackupResourceFileJob::setIdentifier(const QString &identifier)
void BackupResourceFileJobBase::setIdentifier(const QString &identifier)
{
mIdentifier = identifier;
}
KZip *BackupResourceFileJob::zip() const
KZip *BackupResourceFileJobBase::zip() const
{
return mZip;
}
void BackupResourceFileJob::setZip(KZip *zip)
void BackupResourceFileJobBase::setZip(KZip *zip)
{
mZip = zip;
}
QString BackupResourceFileJob::defaultPath() const
QString BackupResourceFileJobBase::defaultPath() const
{
return mDefaultPath;
}
void BackupResourceFileJob::setDefaultPath(const QString &defaultPath)
void BackupResourceFileJobBase::setDefaultPath(const QString &defaultPath)
{
mDefaultPath = defaultPath;
}
......@@ -18,19 +18,19 @@
*/
#ifndef BACKUPRESOURCEFILEJOB_H
#define BACKUPRESOURCEFILEJOB_H
#ifndef BACKUPRESOURCEFILEJOBBASE_H
#define BACKUPRESOURCEFILEJOBBASE_H
#include <QObject>
#include <KZip>
#include "pimdataexporter_export.h"
class PIMDATAEXPORTER_EXPORT BackupResourceFileJob : public QObject
class PIMDATAEXPORTER_EXPORT BackupResourceFileJobBase : public QObject
{
Q_OBJECT
public:
explicit BackupResourceFileJob(QObject *parent = nullptr);
~BackupResourceFileJob();
explicit BackupResourceFileJobBase(QObject *parent = nullptr);
~BackupResourceFileJobBase();
void start();
......@@ -46,6 +46,7 @@ public:
Q_REQUIRED_RESULT QString defaultPath() const;
void setDefaultPath(const QString &defaultPath);
virtual Q_REQUIRED_RESULT QString resourcePath(const QString &identifier) const;
Q_SIGNALS:
void error(const QString &);
void info(const QString &);
......@@ -56,4 +57,4 @@ private:
KZip *mZip = nullptr;
};
#endif // BACKUPRESOURCEFILEJOB_H
#endif // BACKUPRESOURCEFILEJOBBASE_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 "backupresourcefilejobimpl.h"
#include "resourceconverterimpl.h"
BackupResourceFileJobImpl::BackupResourceFileJobImpl(QObject *parent)
: BackupResourceFileJobBase(parent)
{
}
BackupResourceFileJobImpl::~BackupResourceFileJobImpl()
{
}
QString BackupResourceFileJobImpl::resourcePath(const QString &identifier) const
{
ResourceConverterImpl converter;
const QString url = converter.resourcePath(identifier);
return url;
}
/*
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 BACKUPRESOURCEFILEJOBIMPL_H
#define BACKUPRESOURCEFILEJOBIMPL_H
#include "backupresourcefilejobbase.h"
class BackupResourceFileJobImpl : public BackupResourceFileJobBase
{
Q_OBJECT
public:
explicit BackupResourceFileJobImpl(QObject *parent = nullptr);
~BackupResourceFileJobImpl();
Q_REQUIRED_RESULT QString resourcePath(const QString &identifier) const override;
};
#endif // BACKUPRESOURCEFILEJOBIMPL_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