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

Allow to autotest restoring resource too

parent 7281dfc7
......@@ -35,11 +35,6 @@ ImportNotesJobInterfaceTestImpl::~ImportNotesJobInterfaceTestImpl()
{
}
void ImportNotesJobInterfaceTestImpl::restoreResources()
{
qDebug() << " not implement yet";
}
Akonadi::Collection::Id ImportNotesJobInterfaceTestImpl::convertFolderPathToCollectionId(const QString &path)
{
ResourceConverterTest resourceConverterTest;
......@@ -52,6 +47,11 @@ QString ImportNotesJobInterfaceTestImpl::createResource(const QString &resources
return {};
}
void ImportNotesJobInterfaceTestImpl::synchronizeResource(const QStringList &lst)
{
//TODO
}
ImportNotesJobInterfaceTest::ImportNotesJobInterfaceTest(QObject *parent)
: QObject(parent)
{
......@@ -74,3 +74,5 @@ void ImportNotesJobInterfaceTest::importNoteConfig()
file->start();
delete impl;
}
......@@ -34,9 +34,7 @@ public:
protected:
Q_REQUIRED_RESULT Akonadi::Collection::Id convertFolderPathToCollectionId(const QString &path) override;
Q_REQUIRED_RESULT QString createResource(const QString &resources, const QString &name, const QMap<QString, QVariant> &settings, bool synchronizeTree) override;
private:
void restoreResources() override;
void synchronizeResource(const QStringList &lst) override;
};
class ImportNotesJobInterfaceTest : public QObject
......
......@@ -31,6 +31,12 @@
#include <QStandardPaths>
#include <QDir>
#include <QTimer>
namespace {
inline const QString backupnote()
{
return QStringLiteral("backupnote/");
}
}
ImportNotesJobInterface::ImportNotesJobInterface(QObject *parent, Utils::StoredTypes typeSelected, ArchiveStorage *archiveStorage, int numberOfStep)
: AbstractImportExportJob(parent, archiveStorage, typeSelected, numberOfStep)
......@@ -136,3 +142,63 @@ void ImportNotesJobInterface::importKNoteGlobalSettings(const KArchiveFile *arch
}
globalSettingsConfig->sync();
}
void ImportNotesJobInterface::restoreResources()
{
Q_EMIT info(i18n("Restore resources..."));
setProgressDialogLabel(i18n("Restore resources..."));
QStringList listResource;
if (!mListResourceFile.isEmpty()) {
QDir dir(mTempDirName);
dir.mkdir(Utils::notePath());
const QString copyToDirName(mTempDirName + QLatin1Char('/') + Utils::notePath());
const int numberOfResourceFile = mListResourceFile.size();
for (int i = 0; i < numberOfResourceFile; ++i) {
ResourceFiles value = mListResourceFile.at(i);
QMap<QString, QVariant> settings;
if (value.akonadiConfigFile.contains(QLatin1String("akonadi_akonotes_resource_"))) {
const KArchiveEntry *fileResouceEntry = mArchiveDirectory->entry(value.akonadiConfigFile);
if (fileResouceEntry && fileResouceEntry->isFile()) {
const KArchiveFile *file = static_cast<const KArchiveFile *>(fileResouceEntry);
copyArchiveFileTo(file, copyToDirName);
QString resourceName(file->name());
QString filename(resourceName);
//TODO adapt filename otherwise it will use all the time the same filename.
qCDebug(PIMDATAEXPORTERCORE_LOG) << " filename :" << filename;
KSharedConfig::Ptr resourceConfig = KSharedConfig::openConfig(copyToDirName + QLatin1Char('/') + resourceName);
ResourceConverterImpl converter;
const QString newUrl = converter.adaptResourcePath(resourceConfig, backupnote());
QFileInfo newUrlInfo(newUrl);
const QString dataFile = value.akonadiResources;
const KArchiveEntry *dataResouceEntry = mArchiveDirectory->entry(dataFile);
if (dataResouceEntry->isFile()) {
const KArchiveFile *file = static_cast<const KArchiveFile *>(dataResouceEntry);
//TODO adapt directory name too
extractZipFile(file, copyToDirName, newUrlInfo.path());
}
settings.insert(QStringLiteral("Path"), newUrl);
const QString agentConfigFile = value.akonadiAgentConfigFile;
if (!agentConfigFile.isEmpty()) {
const KArchiveEntry *akonadiAgentConfigEntry = mArchiveDirectory->entry(agentConfigFile);
if (akonadiAgentConfigEntry->isFile()) {
const KArchiveFile *file = static_cast<const KArchiveFile *>(akonadiAgentConfigEntry);
copyArchiveFileTo(file, copyToDirName);
resourceName = file->name();
filename = Utils::akonadiAgentName(copyToDirName + QLatin1Char('/') + resourceName);
}
}
const QString newResource = createResource(QStringLiteral("akonadi_akonotes_resource"), filename, settings, true);
infoAboutNewResource(newResource);
qCDebug(PIMDATAEXPORTERCORE_LOG) << " newResource" << newResource;
listResource << newResource;
}
}
}
}
synchronizeResource(listResource);
}
......@@ -34,13 +34,14 @@ public:
void start() override;
protected:
virtual Q_REQUIRED_RESULT QString createResource(const QString &resources, const QString &name, const QMap<QString, QVariant> &settings, bool synchronizeTree = false) = 0;
virtual void synchronizeResource(const QStringList &lst) = 0;
private:
void slotNextStep() override;
private:
void importKNoteGlobalSettings(const KArchiveFile *kmailsnippet, const QString &kmail2rc, const QString &filename, const QString &prefix);
void restoreConfig();
void restoreData();
virtual void restoreResources() = 0;
void restoreResources();
};
#endif // IMPORTNOTESJOB_H
......@@ -34,12 +34,6 @@
#include <QTimer>
#include "resourceconverterimpl.h"
namespace {
inline const QString backupnote()
{
return QStringLiteral("backupnote/");
}
}
ImportNotesJobInterfaceImpl::ImportNotesJobInterfaceImpl(QObject *parent, Utils::StoredTypes typeSelected, ArchiveStorage *archiveStorage, int numberOfStep)
: ImportNotesJobInterface(parent, typeSelected, archiveStorage, numberOfStep)
......@@ -51,67 +45,6 @@ ImportNotesJobInterfaceImpl::~ImportNotesJobInterfaceImpl()
{
}
void ImportNotesJobInterfaceImpl::restoreResources()
{
Q_EMIT info(i18n("Restore resources..."));
setProgressDialogLabel(i18n("Restore resources..."));
QStringList listResource;
if (!mListResourceFile.isEmpty()) {
QDir dir(mTempDirName);
dir.mkdir(Utils::notePath());
const QString copyToDirName(mTempDirName + QLatin1Char('/') + Utils::notePath());
const int numberOfResourceFile = mListResourceFile.size();
for (int i = 0; i < numberOfResourceFile; ++i) {
ResourceFiles value = mListResourceFile.at(i);
QMap<QString, QVariant> settings;
if (value.akonadiConfigFile.contains(QLatin1String("akonadi_akonotes_resource_"))) {
const KArchiveEntry *fileResouceEntry = mArchiveDirectory->entry(value.akonadiConfigFile);
if (fileResouceEntry && fileResouceEntry->isFile()) {
const KArchiveFile *file = static_cast<const KArchiveFile *>(fileResouceEntry);
copyArchiveFileTo(file, copyToDirName);
QString resourceName(file->name());
QString filename(resourceName);
//TODO adapt filename otherwise it will use all the time the same filename.
qCDebug(PIMDATAEXPORTERCORE_LOG) << " filename :" << filename;
KSharedConfig::Ptr resourceConfig = KSharedConfig::openConfig(copyToDirName + QLatin1Char('/') + resourceName);
ResourceConverterImpl converter;
const QString newUrl = converter.adaptResourcePath(resourceConfig, backupnote());
QFileInfo newUrlInfo(newUrl);
const QString dataFile = value.akonadiResources;
const KArchiveEntry *dataResouceEntry = mArchiveDirectory->entry(dataFile);
if (dataResouceEntry->isFile()) {
const KArchiveFile *file = static_cast<const KArchiveFile *>(dataResouceEntry);
//TODO adapt directory name too
extractZipFile(file, copyToDirName, newUrlInfo.path());
}
settings.insert(QStringLiteral("Path"), newUrl);
const QString agentConfigFile = value.akonadiAgentConfigFile;
if (!agentConfigFile.isEmpty()) {
const KArchiveEntry *akonadiAgentConfigEntry = mArchiveDirectory->entry(agentConfigFile);
if (akonadiAgentConfigEntry->isFile()) {
const KArchiveFile *file = static_cast<const KArchiveFile *>(akonadiAgentConfigEntry);
copyArchiveFileTo(file, copyToDirName);
resourceName = file->name();
filename = Utils::akonadiAgentName(copyToDirName + QLatin1Char('/') + resourceName);
}
}
const QString newResource = createResource(QStringLiteral("akonadi_akonotes_resource"), filename, settings, true);
infoAboutNewResource(newResource);
qCDebug(PIMDATAEXPORTERCORE_LOG) << " newResource" << newResource;
listResource << newResource;
}
}
}
}
//It's maildir support. Need to add support
startSynchronizeResources(listResource);
}
Akonadi::Collection::Id ImportNotesJobInterfaceImpl::convertFolderPathToCollectionId(const QString &path)
{
ResourceConverterImpl converter;
......@@ -122,3 +55,9 @@ QString ImportNotesJobInterfaceImpl::createResource(const QString &resources, co
{
return mCreateResource->createResource(resources, name, settings, synchronizeTree);
}
void ImportNotesJobInterfaceImpl::synchronizeResource(const QStringList &lst)
{
//It's maildir support. Need to add support
startSynchronizeResources(lst);
}
......@@ -35,8 +35,7 @@ protected:
Q_REQUIRED_RESULT Akonadi::Collection::Id convertFolderPathToCollectionId(const QString &path) override;
Q_REQUIRED_RESULT QString createResource(const QString &resources, const QString &name, const QMap<QString, QVariant> &settings, bool synchronizeTree = false) override;
private:
void restoreResources() override;
void synchronizeResource(const QStringList &lst) override;
};
#endif // IMPORTNOTESJOB_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