1 /*
2 SPDX-FileCopyrightText: 2020-2021 Laurent Montel <montel@kde.org>
3
4 SPDX-License-Identifier: GPL-2.0-or-later
5 */
6 #include "exportaddressbookjobinterfacetestimpl.h"
7 #include "archivestorage.h"
8 #include "resourceconvertertest.h"
9 #include "saveresourceconfigtest.h"
10 #include "testbackupresourcefilejob.h"
11
ExportAddressbookJobInterfaceTestImpl(QObject * parent,Utils::StoredTypes typeSelected,ArchiveStorage * archiveStorage,int numberOfStep)12 ExportAddressbookJobInterfaceTestImpl::ExportAddressbookJobInterfaceTestImpl(QObject *parent,
13 Utils::StoredTypes typeSelected,
14 ArchiveStorage *archiveStorage,
15 int numberOfStep)
16 : ExportAddressbookJobInterface(parent, typeSelected, archiveStorage, numberOfStep)
17 {
18 }
19
~ExportAddressbookJobInterfaceTestImpl()20 ExportAddressbookJobInterfaceTestImpl::~ExportAddressbookJobInterfaceTestImpl()
21 {
22 }
23
convertFolderPathToCollectionId(const QString & path)24 Akonadi::Collection::Id ExportAddressbookJobInterfaceTestImpl::convertFolderPathToCollectionId(const QString &path)
25 {
26 ResourceConverterTest resourceConverterTest;
27 resourceConverterTest.setTestPath(mPathConfig);
28 return resourceConverterTest.convertFolderPathToCollectionId(path);
29 }
30
exportResourceToArchive(const QString & archivePath,const QString & url,const QString & identifier)31 void ExportAddressbookJobInterfaceTestImpl::exportResourceToArchive(const QString &archivePath, const QString &url, const QString &identifier)
32 {
33 SaveResourceConfigTest saveResourceConfig;
34 saveResourceConfig.setArchive(mArchiveStorage->archive());
35 saveResourceConfig.exportResourceToArchive(archivePath,
36 url,
37 identifier,
38 Utils::resourceAddressbookArchiveName(),
39 {QLatin1String("akonadi_vcarddir_resource_"), QLatin1String("akonadi_contacts_resource_")});
40 slotAddressbookJobTerminated();
41 }
42
listOfResource()43 QVector<Utils::AkonadiInstanceInfo> ExportAddressbookJobInterfaceTestImpl::listOfResource()
44 {
45 return mListAkonadiInstanceInfo;
46 }
47
convertCollectionToRealPath(KConfigGroup & group,const QString & currentKey)48 void ExportAddressbookJobInterfaceTestImpl::convertCollectionToRealPath(KConfigGroup &group, const QString ¤tKey)
49 {
50 ResourceConverterTest resourceConverter;
51 resourceConverter.setTestPath(mPathConfig);
52 resourceConverter.convertCollectionToRealPath(group, currentKey);
53 }
54
convertCollectionListToRealPath(KConfigGroup & group,const QString & currentKey)55 void ExportAddressbookJobInterfaceTestImpl::convertCollectionListToRealPath(KConfigGroup &group, const QString ¤tKey)
56 {
57 ResourceConverterTest resourceConverter;
58 resourceConverter.setTestPath(mPathConfig);
59 resourceConverter.convertCollectionListToRealPath(group, currentKey);
60 }
61
adaptNewResourceUrl(bool overwriteResources,const KSharedConfig::Ptr & resourceConfig,const QString & storePath)62 QString ExportAddressbookJobInterfaceTestImpl::adaptNewResourceUrl(bool overwriteResources, const KSharedConfig::Ptr &resourceConfig, const QString &storePath)
63 {
64 ResourceConverterTest resourceConverterTest;
65 resourceConverterTest.setTestPath(mPathConfig);
66 return resourceConverterTest.adaptNewResourceUrl(overwriteResources, resourceConfig, storePath);
67 }
68
createResource(const QString & resources,const QString & name,const QMap<QString,QVariant> & settings,bool synchronizeTree)69 QString ExportAddressbookJobInterfaceTestImpl::createResource(const QString &resources,
70 const QString &name,
71 const QMap<QString, QVariant> &settings,
72 bool synchronizeTree)
73 {
74 Q_UNREACHABLE();
75 return {};
76 }
77
resourcePath(const QString & agentIdentifier,const QString & defaultPath) const78 QString ExportAddressbookJobInterfaceTestImpl::resourcePath(const QString &agentIdentifier, const QString &defaultPath) const
79 {
80 ResourceConverterTest converter;
81 converter.setTestPath(mPathConfig);
82 const QString url = converter.resourcePath(agentIdentifier, defaultPath);
83 return url;
84 }
85
backupAddressBookResourceFile(const QString & agentIdentifier,const QString & defaultPath)86 void ExportAddressbookJobInterfaceTestImpl::backupAddressBookResourceFile(const QString &agentIdentifier, const QString &defaultPath)
87 {
88 auto job = new TestBackupResourceFileJob(this);
89 job->setDefaultPath(defaultPath);
90 job->setIdentifier(agentIdentifier);
91 job->setTestPath(mPathConfig);
92 job->setZip(archive());
93 connect(job, &TestBackupResourceFileJob::error, this, &ExportAddressbookJobInterfaceTestImpl::error);
94 connect(job, &TestBackupResourceFileJob::info, this, &ExportAddressbookJobInterfaceTestImpl::info);
95 job->start();
96 }
97