File indexing completed on 2024-05-19 05:16:11

0001 /*
0002     SPDX-FileCopyrightText: 2009 Jonathan Armond <jon.armond@gmail.com>
0003 
0004     SPDX-License-Identifier: LGPL-2.0-or-later
0005 */
0006 
0007 #pragma once
0008 
0009 #include <Akonadi/AgentInstance>
0010 #include <QEventLoopLocker>
0011 #include <QObject>
0012 
0013 class QFile;
0014 class KJob;
0015 
0016 /**
0017  * Base class for akonadi resource migrators.
0018  */
0019 class KMigratorBase : public QObject
0020 {
0021     Q_OBJECT
0022 public:
0023     enum MigrationState {
0024         None,
0025         Bridged,
0026         Complete,
0027     };
0028 
0029     enum MessageType {
0030         Success,
0031         Skip,
0032         Info,
0033         Warning,
0034         Error,
0035     };
0036 
0037     Q_ENUM(MigrationState)
0038 
0039     KMigratorBase();
0040     ~KMigratorBase() override;
0041 
0042     /**
0043      * Read resource migration state.
0044      *
0045      * @return MigrationState and None if the resource with @param identifier as identifier is not available.
0046      */
0047     MigrationState migrationState(const QString &identifier) const;
0048     /**
0049      * Set resource migration state.
0050      *
0051      * Persists migration state in the resource config.
0052      * @param resId and @param state is registered under @param identifier.
0053      * Additionally all bridged resources are registered in the @param type and @param identifier.
0054      */
0055     void setMigrationState(const QString &identifier, MigrationState state, const QString &resId, const QString &type);
0056 
0057     virtual void migrateNext() = 0;
0058 
0059 protected:
0060     KJob *createAgentInstance(const QString &typeId, QObject *receiver, const char *slot);
0061     virtual void migrationFailed(const QString &errorMsg, const Akonadi::AgentInstance &instance = Akonadi::AgentInstance()) = 0;
0062 
0063 Q_SIGNALS:
0064     void message(KMigratorBase::MessageType type, const QString &msg);
0065 
0066 protected Q_SLOTS:
0067     virtual void migrate() = 0;
0068 
0069 private:
0070     void logMessage(KMigratorBase::MessageType type, const QString &msg);
0071     QFile *m_logFile = nullptr;
0072     QEventLoopLocker eventLoopLocker;
0073 };