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

0001 /*
0002    SPDX-FileCopyrightText: 2020-2024 Laurent Montel <montel@kde.org>
0003 
0004    SPDX-License-Identifier: GPL-2.0-or-later
0005 */
0006 
0007 #include "exportmailjobinterfacetestimpl.h"
0008 #include "archivestorage.h"
0009 #include "exportmailfolderattributejobtestimpl.h"
0010 #include "resourceconvertertest.h"
0011 #include "saveresourceconfigtest.h"
0012 #include "testbackupresourcefilejob.h"
0013 #include <QDebug>
0014 
0015 ExportMailJobInterfaceTestImpl::ExportMailJobInterfaceTestImpl(QObject *parent,
0016                                                                Utils::StoredTypes typeSelected,
0017                                                                ArchiveStorage *archiveStorage,
0018                                                                int numberOfStep)
0019     : ExportMailJobInterface(parent, typeSelected, archiveStorage, numberOfStep)
0020 {
0021 }
0022 
0023 ExportMailJobInterfaceTestImpl::~ExportMailJobInterfaceTestImpl() = default;
0024 
0025 void ExportMailJobInterfaceTestImpl::convertCollectionToRealPath(KConfigGroup &group, const QString &currentKey)
0026 {
0027     ResourceConverterTest resourceConverter;
0028     resourceConverter.setTestPath(mPathConfig);
0029     resourceConverter.convertCollectionToRealPath(group, currentKey);
0030 }
0031 
0032 void ExportMailJobInterfaceTestImpl::convertCollectionListToRealPath(KConfigGroup &group, const QString &currentKey)
0033 {
0034     ResourceConverterTest resourceConverter;
0035     resourceConverter.setTestPath(mPathConfig);
0036     resourceConverter.convertCollectionListToRealPath(group, currentKey);
0037 }
0038 
0039 void ExportMailJobInterfaceTestImpl::convertCollectionIdsToRealPath(KConfigGroup &group, const QString &currentKey, const QString &prefixCollection)
0040 {
0041     ResourceConverterTest resourceConverter;
0042     resourceConverter.setTestPath(mPathConfig);
0043     resourceConverter.convertCollectionIdsToRealPath(group, currentKey, prefixCollection);
0044 }
0045 
0046 Akonadi::Collection::Id ExportMailJobInterfaceTestImpl::convertFolderPathToCollectionId(const QString &path)
0047 {
0048     ResourceConverterTest resourceConverterTest;
0049     resourceConverterTest.setTestPath(mPathConfig);
0050     return resourceConverterTest.convertFolderPathToCollectionId(path);
0051 }
0052 
0053 QList<MailCommon::MailFilter *> ExportMailJobInterfaceTestImpl::filters()
0054 {
0055     return {};
0056 }
0057 
0058 void ExportMailJobInterfaceTestImpl::exportResourceToArchive(const QString &archivePath, const QString &url, const QString &identifier)
0059 {
0060     // qDebug() << " void ExportMailJobInterfaceTestImpl::exportResourceToArchive(const QString &archivePath, const QString &url, const QString &identifier)" <<
0061     // identifier;
0062     SaveResourceConfigTest saveResourceConfig;
0063     saveResourceConfig.setArchive(mArchiveStorage->archive());
0064     saveResourceConfig.exportResourceToArchive(archivePath,
0065                                                url,
0066                                                identifier,
0067                                                Utils::resourceMailArchiveName(),
0068                                                {QLatin1StringView("akonadi_maildir_resource_"), QLatin1StringView("akonadi_mixedmaildir_resource_")});
0069     slotMailsJobTerminated();
0070 }
0071 
0072 QList<Utils::AkonadiInstanceInfo> ExportMailJobInterfaceTestImpl::listOfResource()
0073 {
0074     return mListAkonadiInstanceInfo;
0075 }
0076 
0077 QString ExportMailJobInterfaceTestImpl::storeResources(KZip *archive, const QString &identifier, const QString &path)
0078 {
0079     ResourceConverterTest converter;
0080     converter.setTestPath(mPathConfig);
0081     return converter.storeResources(archive, identifier, path);
0082 }
0083 
0084 QString ExportMailJobInterfaceTestImpl::convertToFullCollectionPath(const qlonglong collectionValue)
0085 {
0086     ResourceConverterTest converter;
0087     converter.setTestPath(mPathConfig);
0088     return converter.convertToFullCollectionPath(collectionValue);
0089 }
0090 
0091 QString ExportMailJobInterfaceTestImpl::resourcePath(const QString &identifier) const
0092 {
0093     ResourceConverterTest converter;
0094     converter.setTestPath(mPathConfig);
0095     const QString url = converter.resourcePath(identifier);
0096     return url;
0097 }
0098 
0099 void ExportMailJobInterfaceTestImpl::backupMailResourceFile(const QString &agentIdentifier, const QString &defaultPath)
0100 {
0101     auto job = new TestBackupResourceFileJob(this);
0102     job->setDefaultPath(defaultPath);
0103     job->setIdentifier(agentIdentifier);
0104     job->setTestPath(mPathConfig);
0105     job->setZip(archive());
0106     connect(job, &TestBackupResourceFileJob::error, this, &ExportMailJobInterfaceTestImpl::error);
0107     connect(job, &TestBackupResourceFileJob::info, this, &ExportMailJobInterfaceTestImpl::info);
0108     job->start();
0109 }
0110 
0111 QString ExportMailJobInterfaceTestImpl::adaptNewResourceUrl(bool overwriteResources, const KSharedConfig::Ptr &resourceConfig, const QString &storePath)
0112 {
0113     ResourceConverterTest resourceConverterTest;
0114     resourceConverterTest.setTestPath(mPathConfig);
0115     return resourceConverterTest.adaptNewResourceUrl(overwriteResources, resourceConfig, storePath);
0116 }
0117 
0118 QString
0119 ExportMailJobInterfaceTestImpl::createResource(const QString &resources, const QString &name, const QMap<QString, QVariant> &settings, bool synchronizeTree)
0120 {
0121     Q_UNUSED(resources);
0122     Q_UNUSED(settings);
0123     Q_UNUSED(name);
0124     Q_UNUSED(synchronizeTree);
0125     Q_UNREACHABLE();
0126     return {};
0127 }
0128 
0129 QList<uint> ExportMailJobInterfaceTestImpl::listIdentityUoid() const
0130 {
0131     return {10, 11, 12, 13, 14};
0132 }
0133 
0134 void ExportMailJobInterfaceTestImpl::exportFilters()
0135 {
0136     const QString filename = mPathConfig + QLatin1StringView("filters");
0137     const bool fileAdded = archive()->addLocalFile(filename, Utils::configsPath() + QStringLiteral("filters"));
0138     if (fileAdded) {
0139         emitInfo(QStringLiteral("Filters backup done."));
0140     } else {
0141         Q_EMIT error(QStringLiteral("Filters cannot be exported."));
0142     }
0143 }
0144 
0145 void ExportMailJobInterfaceTestImpl::exportFolderAttributes()
0146 {
0147     auto job = new ExportMailFolderAttributeJobTestImpl(this);
0148     job->setArchive(archive());
0149     job->setExportInterface(this);
0150     connect(job, &ExportMailFolderAttributeJobTestImpl::successed, this, [this]() {
0151         emitInfo(QStringLiteral("Backing up Folder Attributes done."));
0152         Q_EMIT exportAttributeDone();
0153     });
0154     connect(job, &ExportMailFolderAttributeJobTestImpl::failed, this, [this]() {
0155         Q_EMIT error(QStringLiteral("Folder Attributes cannot be exported."));
0156         Q_EMIT exportAttributeDone();
0157     });
0158     job->start();
0159 }
0160 
0161 #include "moc_exportmailjobinterfacetestimpl.cpp"