File indexing completed on 2024-06-16 05:00:29

0001 /*
0002    SPDX-FileCopyrightText: 2013-2024 Laurent Montel <montel@kde.org>
0003 
0004    SPDX-License-Identifier: GPL-2.0-or-later
0005 */
0006 
0007 #include "importakregatorjobinterface.h"
0008 #include "archivestorage.h"
0009 
0010 #include <PimCommonAkonadi/CreateResource>
0011 
0012 #include <KArchive>
0013 #include <KLocalizedString>
0014 #include <KZip>
0015 #include <QTimer>
0016 
0017 #include <QStandardPaths>
0018 
0019 ImportAkregatorJobInterface::ImportAkregatorJobInterface(QObject *parent, Utils::StoredTypes typeSelected, ArchiveStorage *archiveStorage, int numberOfStep)
0020     : AbstractImportExportJob(parent, archiveStorage, typeSelected, numberOfStep)
0021 {
0022     initializeImportJob();
0023 }
0024 
0025 ImportAkregatorJobInterface::~ImportAkregatorJobInterface() = default;
0026 
0027 void ImportAkregatorJobInterface::start()
0028 {
0029     Q_EMIT title(i18n("Starting to import Akregator settings..."));
0030     mArchiveDirectory = archive()->directory();
0031     initializeListStep();
0032     createProgressDialog(i18n("Import Akregator settings"));
0033     QTimer::singleShot(0, this, &ImportAkregatorJobInterface::slotNextStep);
0034 }
0035 
0036 Akonadi::Collection::Id ImportAkregatorJobInterface::convertFolderPathToCollectionId(const QString &path)
0037 {
0038     Q_UNUSED(path);
0039     Q_UNREACHABLE();
0040     // Unused here.
0041     return -1;
0042 }
0043 
0044 QString
0045 ImportAkregatorJobInterface::createResource(const QString &resources, const QString &name, const QMap<QString, QVariant> &settings, bool synchronizeTree)
0046 {
0047     Q_UNUSED(resources);
0048     Q_UNUSED(name);
0049     Q_UNUSED(settings);
0050     Q_UNUSED(synchronizeTree);
0051 
0052     Q_UNREACHABLE();
0053     return {};
0054 }
0055 
0056 QString ImportAkregatorJobInterface::applicationName() const
0057 {
0058     return QStringLiteral("[Akregator]");
0059 }
0060 
0061 QString ImportAkregatorJobInterface::adaptNewResourceUrl(bool overwriteResources, const KSharedConfig::Ptr &resourceConfig, const QString &storePath)
0062 {
0063     Q_UNUSED(overwriteResources);
0064     Q_UNUSED(resourceConfig);
0065     Q_UNUSED(storePath);
0066     Q_UNREACHABLE();
0067     // Unused
0068     return {};
0069 }
0070 
0071 void ImportAkregatorJobInterface::slotNextStep()
0072 {
0073     ++mIndex;
0074     if (mIndex < mListStep.count()) {
0075         const Utils::StoredType type = mListStep.at(mIndex);
0076         if (type == Utils::Config) {
0077             restoreConfig();
0078         } else if (type == Utils::Data) {
0079             restoreData();
0080         } else {
0081             qCDebug(PIMDATAEXPORTERCORE_LOG) << Q_FUNC_INFO << " not supported type " << type;
0082             slotNextStep();
0083         }
0084     } else {
0085         Q_EMIT jobFinished();
0086     }
0087 }
0088 
0089 void ImportAkregatorJobInterface::restoreConfig()
0090 {
0091     const QString akregatorStr(QStringLiteral("akregatorrc"));
0092     increaseProgressDialog();
0093     setProgressDialogLabel(i18n("Restore configs..."));
0094     restoreConfigFile(akregatorStr);
0095     restoreUiRcFile(QStringLiteral("akregator_part.rc"), QStringLiteral("akregator"));
0096     restoreUiRcFile(QStringLiteral("akregator_shell.rc"), QStringLiteral("akregator"));
0097     restoreConfigFile(QStringLiteral("akregator.notifyrc"));
0098 
0099     emitInfo(i18n("Config restored."));
0100     QTimer::singleShot(0, this, &ImportAkregatorJobInterface::slotNextStep);
0101 }
0102 
0103 void ImportAkregatorJobInterface::restoreData()
0104 {
0105     increaseProgressDialog();
0106     setProgressDialogLabel(i18n("Restore data..."));
0107     const KArchiveEntry *akregatorEntry = mArchiveDirectory->entry(Utils::dataPath() + QStringLiteral("akregator/"));
0108     if (akregatorEntry && akregatorEntry->isDirectory()) {
0109         const QString akregatorPath = QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation) + QLatin1Char('/') + QStringLiteral("akregator/");
0110         overwriteDirectory(akregatorPath, akregatorEntry);
0111     }
0112     emitInfo(i18n("Data restored."));
0113     QTimer::singleShot(0, this, &ImportAkregatorJobInterface::slotNextStep);
0114 }
0115 
0116 #include "moc_importakregatorjobinterface.cpp"