Warning, file /pim/pim-data-exporter/core/akregator/exportakregatorjobinterface.cpp was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).

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 "exportakregatorjobinterface.h"
0008 #include <KLocalizedString>
0009 #include <KZip>
0010 
0011 #include <QDir>
0012 #include <QStandardPaths>
0013 #include <QTimer>
0014 
0015 ExportAkregatorJobInterface::ExportAkregatorJobInterface(QObject *parent, Utils::StoredTypes typeSelected, ArchiveStorage *archiveStorage, int numberOfStep)
0016     : AbstractImportExportJob(parent, archiveStorage, typeSelected, numberOfStep)
0017 {
0018 }
0019 
0020 ExportAkregatorJobInterface::~ExportAkregatorJobInterface() = default;
0021 
0022 void ExportAkregatorJobInterface::start()
0023 {
0024     Q_EMIT title(i18n("Start export Akregator settings..."));
0025     createProgressDialog(i18n("Export Akregator settings"));
0026     if (mTypeSelected & Utils::Config) {
0027         QTimer::singleShot(0, this, &ExportAkregatorJobInterface::slotCheckBackupConfig);
0028     } else if (mTypeSelected & Utils::Data) {
0029         QTimer::singleShot(0, this, &ExportAkregatorJobInterface::slotCheckBackupData);
0030     } else {
0031         Q_EMIT jobFinished();
0032     }
0033 }
0034 
0035 Akonadi::Collection::Id ExportAkregatorJobInterface::convertFolderPathToCollectionId(const QString &path)
0036 {
0037     Q_UNUSED(path);
0038     Q_UNREACHABLE();
0039     // Unusued
0040     return -1;
0041 }
0042 
0043 QString ExportAkregatorJobInterface::adaptNewResourceUrl(bool overwriteResources, const KSharedConfig::Ptr &resourceConfig, const QString &storePath)
0044 {
0045     Q_UNUSED(overwriteResources);
0046     Q_UNUSED(resourceConfig);
0047     Q_UNUSED(storePath);
0048     Q_UNREACHABLE();
0049     // Unused
0050     return {};
0051 }
0052 
0053 QString
0054 ExportAkregatorJobInterface::createResource(const QString &resources, const QString &name, const QMap<QString, QVariant> &settings, bool synchronizeTree)
0055 {
0056     Q_UNUSED(resources);
0057     Q_UNUSED(name);
0058     Q_UNUSED(settings);
0059     Q_UNUSED(synchronizeTree);
0060     Q_UNREACHABLE();
0061     return {};
0062 }
0063 
0064 QString ExportAkregatorJobInterface::applicationName() const
0065 {
0066     return QStringLiteral("[Akregator]");
0067 }
0068 
0069 void ExportAkregatorJobInterface::slotCheckBackupConfig()
0070 {
0071     increaseProgressDialog();
0072     setProgressDialogLabel(i18n("Backing up config..."));
0073 
0074     backupConfigFile(QStringLiteral("akregatorrc"));
0075     backupUiRcFile(QStringLiteral("akregator_part.rc"), QStringLiteral("akregator"));
0076     backupUiRcFile(QStringLiteral("akregator_shell.rc"), QStringLiteral("akregator"));
0077     backupConfigFile(QStringLiteral("akregator.notifyrc"));
0078 
0079     emitInfo(i18n("Config backup done."));
0080     QTimer::singleShot(0, this, &ExportAkregatorJobInterface::slotCheckBackupData);
0081 }
0082 
0083 void ExportAkregatorJobInterface::slotCheckBackupData()
0084 {
0085     if (mTypeSelected & Utils::Data) {
0086         increaseProgressDialog();
0087         setProgressDialogLabel(i18n("Backing up data..."));
0088 
0089         const QString akregatorDir = QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation) + QStringLiteral("/akregator");
0090         QDir akregatorDirectory(akregatorDir);
0091         if (akregatorDirectory.exists()) {
0092             const bool akregatorDirAdded = archive()->addLocalDirectory(akregatorDir, Utils::dataPath() + QStringLiteral("akregator"));
0093             if (!akregatorDirAdded) {
0094                 Q_EMIT error(i18n("\"%1\" directory cannot be added to backup file.", akregatorDir));
0095             }
0096         }
0097         emitInfo(i18n("Data backup done."));
0098     }
0099     Q_EMIT jobFinished();
0100 }
0101 
0102 #include "moc_exportakregatorjobinterface.cpp"