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

implement import note interface

parent 4b64361e
......@@ -31,6 +31,7 @@ set(pimdataexporter_interfaces_SRCS
set(pimdataexporter_notes_SRCS
notes/exportnotesjobinterfaceimpl.cpp
notes/importnotesjobinterfaceimpl.cpp
)
set(pimdataexporter_xml_SRCS
......
......@@ -19,8 +19,7 @@
#include "importnotesjobinterface.h"
#include "archivestorage.h"
#include <PimCommonAkonadi/CreateResource>
#include "resourceconverterimpl.h"
#include <KArchive>
#include <KLocalizedString>
......@@ -32,14 +31,7 @@
#include <QStandardPaths>
#include <QDir>
#include <QTimer>
#include "resourceconverterimpl.h"
namespace {
inline const QString backupnote()
{
return QStringLiteral("backupnote/");
}
}
ImportNotesJobInterface::ImportNotesJobInterface(QObject *parent, Utils::StoredTypes typeSelected, ArchiveStorage *archiveStorage, int numberOfStep)
: AbstractImportExportJob(parent, archiveStorage, typeSelected, numberOfStep)
......@@ -132,66 +124,6 @@ void ImportNotesJobInterface::restoreData()
Q_EMIT info(i18n("Data restored."));
}
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 = mCreateResource->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);
}
void ImportNotesJobInterface::importKNoteGlobalSettings(const KArchiveFile *archive, const QString &configrc, const QString &filename, const QString &prefix)
{
......
......@@ -39,7 +39,7 @@ private:
void importKNoteGlobalSettings(const KArchiveFile *kmailsnippet, const QString &kmail2rc, const QString &filename, const QString &prefix);
void restoreConfig();
void restoreData();
void restoreResources();
virtual void restoreResources() = 0;
};
#endif // IMPORTNOTESJOB_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 "importnotesjobinterfaceimpl.h"
#include "archivestorage.h"
#include <PimCommonAkonadi/CreateResource>
#include <KArchive>
#include <KLocalizedString>
#include <KZip>
#include <KConfigGroup>
#include <QFile>
#include <QStandardPaths>
#include <QDir>
#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)
{
initializeImportJob();
}
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 = mCreateResource->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);
}
/*
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 IMPORTNOTESJOBIMPLEMENTIMPL_H
#define IMPORTNOTESJOBIMPLEMENTIMPL_H
#include "importnotesjobinterface.h"
#include "pimdataexportercore_private_export.h"
class ArchiveStorage;
class PIMDATAEXPORTER_TESTS_EXPORT ImportNotesJobInterfaceImpl : public ImportNotesJobInterface
{
Q_OBJECT
public:
explicit ImportNotesJobInterfaceImpl(QObject *parent, Utils::StoredTypes typeSelected, ArchiveStorage *archiveStorage, int numberOfStep);
~ImportNotesJobInterfaceImpl() override;
private:
void restoreResources() override;
};
#endif // IMPORTNOTESJOB_H
......@@ -34,7 +34,7 @@
#include "alarm/importalarmjob.h"
#include "notes/exportnotesjobinterfaceimpl.h"
#include "notes/importnotesjobinterface.h"
#include "notes/importnotesjobinterfaceimpl.h"
#include "akregator/exportakregatorjobinterface.h"
#include "akregator/importakregatorjob.h"
......@@ -46,6 +46,7 @@
#include <QDateTime>
#include <QLocale>
PimDataBackupRestore::PimDataBackupRestore(QObject *parent)
: QObject(parent)
{
......@@ -229,7 +230,7 @@ void PimDataBackupRestore::restoreNextStep()
break;
case Utils::KNotes:
if (mStoreIterator.value().numberSteps != 0) {
mImportExportData = new ImportNotesJobInterface(this, mStoreIterator.value().types, mArchiveStorage, mStoreIterator.value().numberSteps);
mImportExportData = new ImportNotesJobInterfaceImpl(this, mStoreIterator.value().types, mArchiveStorage, mStoreIterator.value().numberSteps);
executeJob();
}
break;
......
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