File indexing completed on 2024-05-26 05:14:10
0001 /* 0002 SPDX-FileCopyrightText: 2010 KDAB 0003 SPDX-FileContributor: Tobias Koenig <tokoe@kde.org> 0004 0005 SPDX-License-Identifier: LGPL-2.0-or-later 0006 */ 0007 0008 #pragma once 0009 0010 #include <QObject> 0011 0012 #include "item.h" 0013 0014 class KJob; 0015 0016 namespace Akonadi 0017 { 0018 class Session; 0019 0020 /** 0021 * @short A class to handle conflicts in Akonadi 0022 * 0023 * @author Tobias Koenig <tokoe@kde.org> 0024 */ 0025 class ConflictHandler : public QObject 0026 { 0027 Q_OBJECT 0028 0029 public: 0030 /** 0031 * Describes the type of conflict that should be resolved by 0032 * the conflict handler. 0033 */ 0034 enum ConflictType { 0035 LocalLocalConflict, ///< Changes of two Akonadi client applications conflict. 0036 LocalRemoteConflict, ///< Changes of an Akonadi client application and a resource conflict. 0037 BackendConflict ///< Changes of a resource and the backend data conflict. 0038 }; 0039 0040 /** 0041 * Describes the strategy that should be used for resolving the conflict. 0042 */ 0043 enum ResolveStrategy { 0044 UseLocalItem, ///< The local item overwrites the other item inside the Akonadi storage. 0045 UseOtherItem, ///< The local item is dropped and the other item from the Akonadi storage is used. 0046 UseBothItems ///< Both items are kept in the Akonadi storage. 0047 }; 0048 0049 /** 0050 * Creates a new conflict handler. 0051 * 0052 * @param type The type of the conflict that should be resolved. 0053 * @param parent The parent object. 0054 */ 0055 explicit ConflictHandler(ConflictType type, QObject *parent = nullptr); 0056 0057 /** 0058 * Sets the items that causes the conflict. 0059 * 0060 * @param changedItem The item that has been changed, it needs the complete payload set. 0061 * @param conflictingItem The item from the Akonadi storage that is conflicting. 0062 * This needs only the id set, the payload will be refetched automatically. 0063 */ 0064 void setConflictingItems(const Akonadi::Item &changedItem, const Akonadi::Item &conflictingItem); 0065 0066 public Q_SLOTS: 0067 /** 0068 * Starts the conflict handling. 0069 */ 0070 void start(); 0071 0072 Q_SIGNALS: 0073 /** 0074 * This signal is emitted whenever the conflict has been resolved 0075 * automatically or by the user. 0076 */ 0077 void conflictResolved(); 0078 0079 /** 0080 * This signal is emitted whenever an error occurred during the conflict 0081 * handling. 0082 * 0083 * @param message A user visible string that describes the error. 0084 */ 0085 void error(const QString &message); 0086 0087 private Q_SLOTS: 0088 void slotOtherItemFetched(KJob *); 0089 void slotUseLocalItemFinished(KJob *); 0090 void slotUseBothItemsFinished(KJob *); 0091 void resolve(); 0092 0093 private: 0094 void useLocalItem(); 0095 void useOtherItem(); 0096 void useBothItems(); 0097 0098 const ConflictType mConflictType; 0099 Akonadi::Item mChangedItem; 0100 Akonadi::Item mConflictingItem; 0101 0102 Session *mSession = nullptr; 0103 }; 0104 0105 }