1 | /* |
2 | Copyright (c) 2009 Jonathan Armond <jon.armond@gmail.com> |
3 | |
4 | This library is free software; you can redistribute it and/or modify it |
5 | under the terms of the GNU Library General Public License as published by |
6 | the Free Software Foundation; either version 2 of the License, or (at your |
7 | option) any later version. |
8 | |
9 | This library is distributed in the hope that it will be useful, but WITHOUT |
10 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
11 | FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public |
12 | License for more details. |
13 | |
14 | You should have received a copy of the GNU Library General Public License |
15 | along with this library; see the file COPYING.LIB. If not, write to the |
16 | Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA |
17 | 02110-1301, USA. |
18 | */ |
19 | |
20 | #ifndef KMIGRATORBASE_H |
21 | #define KMIGRATORBASE_H |
22 | |
23 | #include <akonadi/agentinstance.h> |
24 | |
25 | #include <QObject> |
26 | |
27 | class QFile; |
28 | class KJob; |
29 | |
30 | /** |
31 | * Base class for akonadi resource migrators. |
32 | */ |
33 | class KMigratorBase : public QObject |
34 | { |
35 | Q_OBJECT |
36 | public: |
37 | enum MigrationState { |
38 | None, |
39 | Bridged, |
40 | Complete |
41 | }; |
42 | |
43 | enum MessageType { |
44 | Success, |
45 | Skip, |
46 | Info, |
47 | Warning, |
48 | Error |
49 | }; |
50 | |
51 | Q_ENUMS( MigrationState ) |
52 | |
53 | KMigratorBase(); |
54 | virtual ~KMigratorBase(); |
55 | |
56 | /** |
57 | * Read resource migration state. |
58 | * |
59 | * @return MigrationState and None if the resource with @param identifier as identifier is not available. |
60 | */ |
61 | MigrationState migrationState( const QString &identifier ) const; |
62 | /** |
63 | * Set resource migration state. |
64 | * |
65 | * Persists migration state in the resource config. |
66 | * @param resId and @param state is registered under @param identifier. |
67 | * Additionally all bridged resources are registered in the @param type and @param identifier. |
68 | */ |
69 | void setMigrationState( const QString &identifier, MigrationState state, |
70 | const QString &resId, const QString &type ); |
71 | |
72 | virtual void migrateNext() = 0; |
73 | |
74 | protected: |
75 | KJob *createAgentInstance( const QString &typeId, QObject *receiver, const char* slot ); |
76 | virtual void migrationFailed( const QString &errorMsg, const Akonadi::AgentInstance &instance |
77 | = Akonadi::AgentInstance() ) = 0; |
78 | |
79 | signals: |
80 | void message( KMigratorBase::MessageType type, const QString &msg ); |
81 | |
82 | protected slots: |
83 | virtual void migrate() = 0; |
84 | |
85 | private slots: |
86 | void logMessage( KMigratorBase::MessageType type, const QString &msg ); |
87 | |
88 | private: |
89 | QFile* m_logFile; |
90 | }; |
91 | |
92 | #endif |
93 | |