• Skip to content
  • Skip to link menu
  • KDE API Reference
  • kdepimlibs-4.10.5 API Reference
  • KDE Home
  • Contact Us
 

akonadi

  • akonadi
  • calendar
incidencechanger_p.h
1 /*
2  Copyright (C) 2004 Reinhold Kainhofer <reinhold@kainhofer.com>
3 
4  Copyright (C) 2010 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.net
5  Author: Sergio Martins, <sergio.martins@kdab.com>
6 
7  Copyright (C) 2010-2012 SĂ©rgio Martins <iamsergio@gmail.com>
8 
9  This library is free software; you can redistribute it and/or modify it
10  under the terms of the GNU Library General Public License as published by
11  the Free Software Foundation; either version 2 of the License, or (at your
12  option) any later version.
13 
14  This library is distributed in the hope that it will be useful, but WITHOUT
15  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
16  FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
17  License for more details.
18 
19  You should have received a copy of the GNU Library General Public License
20  along with this library; see the file COPYING.LIB. If not, write to the
21  Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
22  02110-1301, USA.
23 */
24 #ifndef AKONADI_INCIDENCECHANGER_P_H
25 #define AKONADI_INCIDENCECHANGER_P_H
26 
27 #include "incidencechanger.h"
28 #include "invitationhandlerhelper_p.h"
29 #include "history.h"
30 
31 #include <akonadi/item.h>
32 #include <akonadi/collection.h>
33 #include <akonadi/transactionsequence.h>
34 
35 #include <QSet>
36 #include <QObject>
37 #include <QPointer>
38 #include <QVector>
39 
40 
41 class KJob;
42 class QWidget;
43 
44 namespace Akonadi {
45 
46 class TransactionSequence;
47 
48 class Change {
49 
50 public:
51  typedef QSharedPointer<Change> Ptr;
52  Change( IncidenceChanger *incidenceChanger, int changeId,
53  IncidenceChanger::ChangeType changeType, uint operationId,
54  QWidget *parent ) : id( changeId )
55  , type( changeType )
56  , recordToHistory( incidenceChanger->historyEnabled() )
57  , parentWidget( parent )
58  , atomicOperationId( operationId )
59  , resultCode( Akonadi::IncidenceChanger::ResultCodeSuccess )
60  , completed( false )
61  , queuedModification( false )
62  , changer( incidenceChanger )
63  {
64  }
65 
66  virtual ~Change()
67  {
68  if ( parentChange ) {
69  parentChange->childAboutToDie( this );
70  }
71  }
72 
73  virtual void childAboutToDie( Change *child )
74  {
75  Q_UNUSED( child );
76  }
77 
78  virtual void emitCompletionSignal() = 0;
79 
80  const int id;
81  const IncidenceChanger::ChangeType type;
82  const bool recordToHistory;
83  const QPointer<QWidget> parentWidget;
84  uint atomicOperationId;
85 
86  // If this change is internal, i.e. not initiated by the user, mParentChange will
87  // contain the non-internal change.
88  QSharedPointer<Change> parentChange;
89 
90  Akonadi::Item::List originalItems;
91  Akonadi::Item newItem;
92 
93  QString errorString;
94  IncidenceChanger::ResultCode resultCode;
95  bool completed;
96  bool queuedModification;
97 protected:
98  IncidenceChanger *const changer;
99 };
100 
101 class ModificationChange : public Change
102 {
103 public:
104  typedef QSharedPointer<ModificationChange> Ptr;
105  ModificationChange( IncidenceChanger *changer, int id, uint atomicOperationId,
106  QWidget *parent ) : Change( changer, id,
107  IncidenceChanger::ChangeTypeModify,
108  atomicOperationId, parent )
109  {
110  }
111 
112  ~ModificationChange()
113  {
114  if ( !parentChange )
115  emitCompletionSignal();
116  }
117 
119  void emitCompletionSignal();
120 };
121 
122 class CreationChange : public Change
123 {
124 public:
125  typedef QSharedPointer<CreationChange> Ptr;
126  CreationChange( IncidenceChanger *changer, int id, uint atomicOperationId,
127  QWidget *parent ) : Change( changer, id, IncidenceChanger::ChangeTypeCreate,
128  atomicOperationId, parent )
129  {
130  }
131 
132  ~CreationChange()
133  {
134  //kDebug() << "CreationChange::~ will emit signal with " << resultCode;
135  if ( !parentChange )
136  emitCompletionSignal();
137  }
138 
140  void emitCompletionSignal();
141 
142  Akonadi::Collection mUsedCol1lection;
143 };
144 
145 class DeletionChange : public Change
146 {
147 public:
148  typedef QSharedPointer<DeletionChange> Ptr;
149  DeletionChange( IncidenceChanger *changer, int id, uint atomicOperationId,
150  QWidget *parent ) : Change( changer, id, IncidenceChanger::ChangeTypeDelete,
151  atomicOperationId, parent )
152  {
153  }
154 
155  ~DeletionChange()
156  {
157  //kDebug() << "DeletionChange::~ will emit signal with " << resultCode;
158  if ( !parentChange )
159  emitCompletionSignal();
160  }
161 
163  void emitCompletionSignal();
164 
165  QVector<Akonadi::Item::Id> mItemIds;
166 };
167 
168 struct AtomicOperation {
169  uint id;
170 
171  // To make sure they are not repeated
172  QSet<Akonadi::Item::Id> mItemIdsInOperation;
173 
174  // After endAtomicOperation() is called we don't accept more changes
175  bool endCalled;
176 
177  // Number of completed changes(jobs)
178  int numCompletedChanges;
179  Akonadi::TransactionSequence *transaction;
180  QString description;
181  bool transactionCompleted;
182 
183  AtomicOperation( uint ident ) :
184  id ( ident ),
185  endCalled( false ),
186  numCompletedChanges( 0 ),
187  transaction( 0 ),
188  transactionCompleted(false),
189  wasRolledback( false )
190  {
191  Q_ASSERT( id != 0 );
192  transaction = new Akonadi::TransactionSequence;
193  transaction->setAutomaticCommittingEnabled( true );
194  }
195 
196  ~AtomicOperation()
197  {
198  //kDebug() << "AtomicOperation::~ " << wasRolledback << changes.count();
199  if ( wasRolledback ) {
200  for ( int i=0; i<changes.count(); ++i ) {
201  // When a job that can finish successfully is aborted because the transaction failed
202  // because of some other job, akonadi is returning an Unknown error
203  // which isnt very specific
204  if ( changes[i]->completed &&
205  ( changes[i]->resultCode == IncidenceChanger::ResultCodeSuccess ||
206  ( changes[i]->resultCode == IncidenceChanger::ResultCodeJobError &&
207  changes[i]->errorString == QLatin1String( "Unknown error." ) ) ) ) {
208  changes[i]->resultCode = IncidenceChanger::ResultCodeRolledback;
209  }
210  }
211  }
212  }
213 
214  // Did all jobs return ?
215  bool pendingJobs() const
216  {
217  return changes.count() > numCompletedChanges;
218  }
219 
220  void setRolledback()
221  {
222  //kDebug() << "AtomicOperation::setRolledBack()";
223  wasRolledback = true;
224  transaction->rollback();
225  }
226 
227  bool rolledback() const
228  {
229  return wasRolledback;
230  }
231 
232  void addChange( const Change::Ptr &change )
233  {
234  if ( change->type == IncidenceChanger::ChangeTypeDelete ) {
235  DeletionChange::Ptr deletion = change.staticCast<DeletionChange>();
236  foreach( Akonadi::Item::Id id, deletion->mItemIds ) {
237  Q_ASSERT( !mItemIdsInOperation.contains( id ) );
238  mItemIdsInOperation.insert( id );
239  }
240  } else if ( change->type == IncidenceChanger::ChangeTypeModify ) {
241  Q_ASSERT( !mItemIdsInOperation.contains( change->newItem.id() ) );
242  mItemIdsInOperation.insert( change->newItem.id() );
243  }
244 
245  changes << change;
246  }
247 
248 private:
249  QVector<Change::Ptr> changes;
250  bool wasRolledback;
251 };
252 
253 class IncidenceChanger::Private : public QObject
254 {
255  Q_OBJECT
256 public:
257  explicit Private( bool enableHistory, IncidenceChanger *mIncidenceChanger );
258  ~Private();
259 
264  bool deleteAlreadyCalled( Akonadi::Item::Id id ) const;
265 
266  QString showErrorDialog( Akonadi::IncidenceChanger::ResultCode, QWidget *parent );
267 
268  void setChangeInternal( int changeId );
269 
270  bool hasRights( const Akonadi::Collection &collection, IncidenceChanger::ChangeType ) const;
271  void queueModification( Change::Ptr );
272  void performModification( Change::Ptr );
273  bool atomicOperationIsValid( uint atomicOperationId ) const;
274  Akonadi::Job* parentJob( const Change::Ptr & ) const;
275  void cancelTransaction();
276  void cleanupTransaction();
277  bool allowAtomicOperation( int atomicOperationId, const Change::Ptr &change ) const;
278 
279  bool handleInvitationsBeforeChange( const Change::Ptr &change );
280  bool handleInvitationsAfterChange( const Change::Ptr &change );
281  static bool myAttendeeStatusChanged( const KCalCore::Incidence::Ptr &newIncidence,
282  const KCalCore::Incidence::Ptr &oldIncidence,
283  const QStringList &myEmails );
284 
285 public Q_SLOTS:
286  void handleCreateJobResult( KJob* );
287  void handleModifyJobResult( KJob* );
288  void handleDeleteJobResult( KJob* );
289  void handleTransactionJobResult( KJob* );
290  void performNextModification( Akonadi::Item::Id id );
291 
292 public:
293  int mLatestChangeId;
294  QHash<const KJob*,Change::Ptr> mChangeForJob;
295  bool mShowDialogsOnError;
296  Akonadi::Collection mDefaultCollection;
297  DestinationPolicy mDestinationPolicy;
298  QVector<Akonadi::Item::Id> mDeletedItemIds;
299 
300  History *mHistory;
301  bool mUseHistory;
302 
311  QHash<Akonadi::Item::Id,Change::Ptr> mQueuedModifications;
312 
316  QHash<Akonadi::Item::Id,Change::Ptr> mModificationsInProgress;
317 
318  QHash<int,Change::Ptr> mChangeById;
319 
323  QHash<uint,AtomicOperation*> mAtomicOperations;
324 
325  bool mRespectsCollectionRights;
326  bool mGroupwareCommunication;
327 
328  QHash<Akonadi::TransactionSequence*, uint> mAtomicOperationByTransaction;
329  QHash<uint,InvitationHandlerHelper::SendResult> mInvitationStatusByAtomicOperation;
330 
331  uint mLatestAtomicOperationId;
332  bool mBatchOperationInProgress;
333  Akonadi::Collection mLastCollectionUsed;
334 
335  QMap<KJob *, QSet<KCalCore::IncidenceBase::Field> > mDirtyFieldsByJob;
336 
337 private:
338  IncidenceChanger *q;
339 };
340 
341 }
342 
343 #endif
This file is part of the KDE documentation.
Documentation copyright © 1996-2013 The KDE developers.
Generated on Sat Jul 13 2013 01:27:37 by doxygen 1.8.3.1 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

akonadi

Skip menu "akonadi"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • Modules
  • Related Pages

kdepimlibs-4.10.5 API Reference

Skip menu "kdepimlibs-4.10.5 API Reference"
  • akonadi
  •   contact
  •   kmime
  •   socialutils
  • kabc
  • kalarmcal
  • kblog
  • kcal
  • kcalcore
  • kcalutils
  • kholidays
  • kimap
  • kioslave
  •   imap4
  •   mbox
  •   nntp
  • kldap
  • kmbox
  • kmime
  • kontactinterface
  • kpimidentities
  • kpimtextedit
  • kpimutils
  • kresources
  • ktnef
  • kxmlrpcclient
  • mailtransport
  • microblog
  • qgpgme
  • syndication
  •   atom
  •   rdf
  •   rss2
Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal