24 #ifndef AKONADI_INCIDENCECHANGER_P_H
25 #define AKONADI_INCIDENCECHANGER_P_H
27 #include "incidencechanger.h"
28 #include "itiphandlerhelper_p.h"
31 #include <akonadi/item.h>
32 #include <akonadi/collection.h>
33 #include <akonadi/transactionsequence.h>
45 class TransactionSequence;
46 class CollectionFetchJob;
51 typedef QSharedPointer<Change> Ptr;
52 typedef QList<Ptr> List;
53 Change(IncidenceChanger *incidenceChanger,
int changeId,
54 IncidenceChanger::ChangeType changeType, uint operationId,
55 QWidget *parent) : id(changeId)
57 , recordToHistory(incidenceChanger->historyEnabled())
58 , parentWidget(parent)
59 , atomicOperationId(operationId)
60 , resultCode(Akonadi::IncidenceChanger::ResultCodeSuccess)
62 , queuedModification(false)
63 , useGroupwareCommunication(incidenceChanger->groupwareCommunication())
64 , changer(incidenceChanger)
71 parentChange->childAboutToDie(
this);
75 virtual void childAboutToDie(Change *child)
80 virtual void emitCompletionSignal() = 0;
83 const IncidenceChanger::ChangeType type;
84 const bool recordToHistory;
85 const QPointer<QWidget> parentWidget;
86 uint atomicOperationId;
90 QSharedPointer<Change> parentChange;
92 Akonadi::Item::List originalItems;
93 Akonadi::Item newItem;
96 IncidenceChanger::ResultCode resultCode;
98 bool queuedModification;
99 bool useGroupwareCommunication;
101 IncidenceChanger *
const changer;
104 class ModificationChange :
public Change
107 typedef QSharedPointer<ModificationChange> Ptr;
108 ModificationChange(IncidenceChanger *changer,
int id, uint atomicOperationId,
109 QWidget *parent) : Change(changer, id,
110 IncidenceChanger::ChangeTypeModify,
111 atomicOperationId, parent)
115 ~ModificationChange()
118 emitCompletionSignal();
122 void emitCompletionSignal();
125 class CreationChange :
public Change
128 typedef QSharedPointer<CreationChange> Ptr;
129 CreationChange(IncidenceChanger *changer,
int id, uint atomicOperationId,
130 QWidget *parent) : Change(changer, id, IncidenceChanger::ChangeTypeCreate,
131 atomicOperationId, parent)
139 emitCompletionSignal();
143 void emitCompletionSignal();
148 class DeletionChange :
public Change
151 typedef QSharedPointer<DeletionChange> Ptr;
152 DeletionChange(IncidenceChanger *changer,
int id, uint atomicOperationId,
153 QWidget *parent) : Change(changer, id, IncidenceChanger::ChangeTypeDelete,
154 atomicOperationId, parent)
162 emitCompletionSignal();
166 void emitCompletionSignal();
168 QVector<Akonadi::Item::Id> mItemIds;
171 class AtomicOperation {
176 QSet<Akonadi::Item::Id> m_itemIdsInOperation;
182 int m_numCompletedChanges;
183 QString m_description;
184 bool m_transactionCompleted;
186 AtomicOperation(IncidenceChanger::Private *icp, uint ident);
191 if (m_wasRolledback) {
192 for (
int i=0; i<m_changes.count(); ++i) {
196 if (m_changes[i]->completed &&
197 (m_changes[i]->resultCode == IncidenceChanger::ResultCodeSuccess ||
198 (m_changes[i]->resultCode == IncidenceChanger::ResultCodeJobError &&
199 m_changes[i]->errorString == QLatin1String(
"Unknown error.")))) {
200 m_changes[i]->resultCode = IncidenceChanger::ResultCodeRolledback;
207 bool pendingJobs()
const
209 return m_changes.count() > m_numCompletedChanges;
215 m_wasRolledback =
true;
216 transaction()->rollback();
219 bool rolledback()
const
221 return m_wasRolledback;
224 void addChange(
const Change::Ptr &change)
226 if (change->type == IncidenceChanger::ChangeTypeDelete) {
227 DeletionChange::Ptr deletion = change.staticCast<DeletionChange>();
228 foreach(Akonadi::Item::Id
id, deletion->mItemIds) {
229 Q_ASSERT(!m_itemIdsInOperation.contains(
id));
230 m_itemIdsInOperation.insert(
id);
232 }
else if (change->type == IncidenceChanger::ChangeTypeModify) {
233 Q_ASSERT(!m_itemIdsInOperation.contains(change->newItem.id()));
234 m_itemIdsInOperation.insert(change->newItem.id());
243 QVector<Change::Ptr> m_changes;
244 bool m_wasRolledback;
246 IncidenceChanger::Private *m_incidenceChangerPrivate;
249 class IncidenceChanger::Private :
public QObject
253 explicit Private(
bool enableHistory, IncidenceChanger *mIncidenceChanger);
256 void loadCollections();
257 bool isLoadingCollections()
const;
261 void step1DetermineDestinationCollection(
const Change::Ptr &change,
const Collection &collection);
262 void step2CreateIncidence(
const Change::Ptr &change,
const Collection &collection);
270 bool deleteAlreadyCalled(Akonadi::Item::Id
id)
const;
272 QString showErrorDialog(Akonadi::IncidenceChanger::ResultCode, QWidget *parent);
274 void setChangeInternal(
int changeId);
276 void adjustRecurrence(
const KCalCore::Incidence::Ptr &originalIncidence,
277 const KCalCore::Incidence::Ptr &incidence);
280 void queueModification(Change::Ptr);
281 void performModification(Change::Ptr);
282 bool atomicOperationIsValid(uint atomicOperationId)
const;
284 void cancelTransaction();
285 void cleanupTransaction();
286 bool allowAtomicOperation(
int atomicOperationId,
const Change::Ptr &change)
const;
288 bool handleInvitationsBeforeChange(
const Change::Ptr &change);
289 bool handleInvitationsAfterChange(
const Change::Ptr &change);
290 static bool myAttendeeStatusChanged(
const KCalCore::Incidence::Ptr &newIncidence,
291 const KCalCore::Incidence::Ptr &oldIncidence,
292 const QStringList &myEmails);
295 void handleCreateJobResult(KJob*);
296 void handleModifyJobResult(KJob*);
297 void handleDeleteJobResult(KJob*);
298 void handleTransactionJobResult(KJob*);
299 void performNextModification(Akonadi::Item::Id
id);
300 void onCollectionsLoaded(KJob*);
304 QHash<const KJob*,Change::Ptr> mChangeForJob;
305 bool mShowDialogsOnError;
307 DestinationPolicy mDestinationPolicy;
308 QVector<Akonadi::Item::Id> mDeletedItemIds;
309 Change::List mPendingCreations;
322 QHash<Akonadi::Item::Id,Change::Ptr> mQueuedModifications;
327 QHash<Akonadi::Item::Id,Change::Ptr> mModificationsInProgress;
329 QHash<int,Change::Ptr> mChangeById;
334 QHash<uint,AtomicOperation*> mAtomicOperations;
336 bool mRespectsCollectionRights;
337 bool mGroupwareCommunication;
339 QHash<Akonadi::TransactionSequence*, uint> mAtomicOperationByTransaction;
340 QHash<uint,ITIPHandlerHelper::SendResult> mInvitationStatusByAtomicOperation;
342 uint mLatestAtomicOperationId;
343 bool mBatchOperationInProgress;
345 bool mAutoAdjustRecurrence;
349 QMap<KJob *, QSet<KCalCore::IncidenceBase::Field> > mDirtyFieldsByJob;
351 IncidenceChanger::InvitationPolicy m_invitationPolicy;
Represents a collection of PIM items.
Job that fetches collections from the Akonadi storage.
Base class for all actions in the Akonadi storage.
Base class for jobs that need to run a sequence of sub-jobs in a transaction.
QList< Collection > List
Describes a list of collections.