File indexing completed on 2024-12-22 05:05:23

0001 /*
0002    SPDX-FileCopyrightText: 2020-2024 Laurent Montel <montel@kde.org>
0003 
0004    SPDX-License-Identifier: GPL-2.0-or-later
0005 */
0006 #include "exportaddressbookjobinterfacetestimpl.h"
0007 #include "archivestorage.h"
0008 #include "resourceconvertertest.h"
0009 #include "saveresourceconfigtest.h"
0010 #include "testbackupresourcefilejob.h"
0011 
0012 ExportAddressbookJobInterfaceTestImpl::ExportAddressbookJobInterfaceTestImpl(QObject *parent,
0013                                                                              Utils::StoredTypes typeSelected,
0014                                                                              ArchiveStorage *archiveStorage,
0015                                                                              int numberOfStep)
0016     : ExportAddressbookJobInterface(parent, typeSelected, archiveStorage, numberOfStep)
0017 {
0018 }
0019 
0020 ExportAddressbookJobInterfaceTestImpl::~ExportAddressbookJobInterfaceTestImpl() = default;
0021 
0022 Akonadi::Collection::Id ExportAddressbookJobInterfaceTestImpl::convertFolderPathToCollectionId(const QString &path)
0023 {
0024     ResourceConverterTest resourceConverterTest;
0025     resourceConverterTest.setTestPath(mPathConfig);
0026     return resourceConverterTest.convertFolderPathToCollectionId(path);
0027 }
0028 
0029 void ExportAddressbookJobInterfaceTestImpl::exportResourceToArchive(const QString &archivePath, const QString &url, const QString &identifier)
0030 {
0031     SaveResourceConfigTest saveResourceConfig;
0032     saveResourceConfig.setArchive(mArchiveStorage->archive());
0033     saveResourceConfig.exportResourceToArchive(archivePath,
0034                                                url,
0035                                                identifier,
0036                                                Utils::resourceAddressbookArchiveName(),
0037                                                {QLatin1StringView("akonadi_vcarddir_resource_"), QLatin1StringView("akonadi_contacts_resource_")});
0038     slotAddressbookJobTerminated();
0039 }
0040 
0041 QList<Utils::AkonadiInstanceInfo> ExportAddressbookJobInterfaceTestImpl::listOfResource()
0042 {
0043     return mListAkonadiInstanceInfo;
0044 }
0045 
0046 void ExportAddressbookJobInterfaceTestImpl::convertCollectionToRealPath(KConfigGroup &group, const QString &currentKey)
0047 {
0048     ResourceConverterTest resourceConverter;
0049     resourceConverter.setTestPath(mPathConfig);
0050     resourceConverter.convertCollectionToRealPath(group, currentKey);
0051 }
0052 
0053 void ExportAddressbookJobInterfaceTestImpl::convertCollectionListToRealPath(KConfigGroup &group, const QString &currentKey)
0054 {
0055     ResourceConverterTest resourceConverter;
0056     resourceConverter.setTestPath(mPathConfig);
0057     resourceConverter.convertCollectionListToRealPath(group, currentKey);
0058 }
0059 
0060 QString ExportAddressbookJobInterfaceTestImpl::adaptNewResourceUrl(bool overwriteResources, const KSharedConfig::Ptr &resourceConfig, const QString &storePath)
0061 {
0062     ResourceConverterTest resourceConverterTest;
0063     resourceConverterTest.setTestPath(mPathConfig);
0064     return resourceConverterTest.adaptNewResourceUrl(overwriteResources, resourceConfig, storePath);
0065 }
0066 
0067 QString ExportAddressbookJobInterfaceTestImpl::createResource(const QString &resources,
0068                                                               const QString &name,
0069                                                               const QMap<QString, QVariant> &settings,
0070                                                               bool synchronizeTree)
0071 {
0072     Q_UNUSED(resources);
0073     Q_UNUSED(settings);
0074     Q_UNUSED(name);
0075     Q_UNUSED(synchronizeTree);
0076     Q_UNREACHABLE();
0077     return {};
0078 }
0079 
0080 QString ExportAddressbookJobInterfaceTestImpl::resourcePath(const QString &agentIdentifier, const QString &defaultPath) const
0081 {
0082     ResourceConverterTest converter;
0083     converter.setTestPath(mPathConfig);
0084     const QString url = converter.resourcePath(agentIdentifier, defaultPath);
0085     return url;
0086 }
0087 
0088 void ExportAddressbookJobInterfaceTestImpl::backupAddressBookResourceFile(const QString &agentIdentifier, const QString &defaultPath)
0089 {
0090     auto job = new TestBackupResourceFileJob(this);
0091     job->setDefaultPath(defaultPath);
0092     job->setIdentifier(agentIdentifier);
0093     job->setTestPath(mPathConfig);
0094     job->setZip(archive());
0095     connect(job, &TestBackupResourceFileJob::error, this, &ExportAddressbookJobInterfaceTestImpl::error);
0096     connect(job, &TestBackupResourceFileJob::info, this, &ExportAddressbookJobInterfaceTestImpl::info);
0097     job->start();
0098 }
0099 
0100 #include "moc_exportaddressbookjobinterfacetestimpl.cpp"