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

akonadi

  • sources
  • kde-4.12
  • kdepimlibs
  • akonadi
  • conflicthandling
conflicthandler.cpp
1 /*
2  Copyright (c) 2010 KDAB
3  Author: Tobias Koenig <tokoe@kde.org>
4 
5  This library is free software; you can redistribute it and/or modify it
6  under the terms of the GNU Library General Public License as published by
7  the Free Software Foundation; either version 2 of the License, or (at your
8  option) any later version.
9 
10  This library is distributed in the hope that it will be useful, but WITHOUT
11  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12  FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
13  License for more details.
14 
15  You should have received a copy of the GNU Library General Public License
16  along with this library; see the file COPYING.LIB. If not, write to the
17  Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
18  02110-1301, USA.
19 */
20 
21 #include "conflicthandler_p.h"
22 
23 #include "conflictresolvedialog_p.h"
24 
25 #include <akonadi/itemcreatejob.h>
26 #include <akonadi/itemfetchjob.h>
27 #include <akonadi/itemfetchscope.h>
28 #include <akonadi/itemmodifyjob.h>
29 #include <akonadi/session.h>
30 #include <klocalizedstring.h>
31 
32 using namespace Akonadi;
33 
34 ConflictHandler::ConflictHandler( ConflictType type, QObject *parent )
35  : QObject( parent ),
36  mConflictType( type ),
37  mSession( new Session( "conflict handling session", this ) )
38 {
39 }
40 
41 void ConflictHandler::setConflictingItems( const Akonadi::Item &changedItem, const Akonadi::Item &conflictingItem )
42 {
43  mChangedItem = changedItem;
44  mConflictingItem = conflictingItem;
45 }
46 
47 void ConflictHandler::start()
48 {
49  if ( mConflictType == LocalLocalConflict || mConflictType == LocalRemoteConflict ) {
50  ItemFetchJob *job = new ItemFetchJob( mConflictingItem, mSession );
51  job->fetchScope().fetchFullPayload();
52  job->fetchScope().setAncestorRetrieval( ItemFetchScope::Parent );
53  connect( job, SIGNAL(result(KJob*)), SLOT(slotOtherItemFetched(KJob*)) );
54  } else {
55  resolve();
56  }
57 }
58 
59 void ConflictHandler::slotOtherItemFetched( KJob *job )
60 {
61  if ( job->error() ) {
62  emit error( job->errorText() ); //TODO: extend error message
63  return;
64  }
65 
66  ItemFetchJob *fetchJob = qobject_cast<ItemFetchJob*>( job );
67  if ( fetchJob->items().isEmpty() ) {
68  emit error( i18n( "Did not find other item for conflict handling" ) );
69  return;
70  }
71 
72  mConflictingItem = fetchJob->items().first();
73  QMetaObject::invokeMethod( this, "resolve", Qt::QueuedConnection );
74 }
75 
76 void ConflictHandler::resolve()
77 {
78  ConflictResolveDialog dlg;
79  dlg.setConflictingItems( mChangedItem, mConflictingItem );
80  dlg.exec();
81 
82  const ResolveStrategy strategy = dlg.resolveStrategy();
83  switch ( strategy ) {
84  case UseLocalItem:
85  useLocalItem();
86  break;
87  case UseOtherItem:
88  useOtherItem();
89  break;
90  case UseBothItems:
91  useBothItems();
92  break;
93  }
94 }
95 
96 void ConflictHandler::useLocalItem()
97 {
98  // We have to overwrite the other item inside the Akonadi storage with the local
99  // item. To make this happen, we have to set the revision of the local item to
100  // the one of the other item to let the Akonadi server accept it.
101 
102  Item newItem( mChangedItem );
103  newItem.setRevision( mConflictingItem.revision() );
104 
105  ItemModifyJob *job = new ItemModifyJob( newItem, mSession );
106  connect( job, SIGNAL(result(KJob*)), SLOT(slotUseLocalItemFinished(KJob*)) );
107 }
108 
109 void ConflictHandler::slotUseLocalItemFinished( KJob *job )
110 {
111  if ( job->error() ) {
112  emit error( job->errorText() ); //TODO: extend error message
113  } else {
114  emit conflictResolved();
115  }
116 }
117 
118 void ConflictHandler::useOtherItem()
119 {
120  // We can just ignore the local item here and leave everything as it is.
121  emit conflictResolved();
122 }
123 
124 void ConflictHandler::useBothItems()
125 {
126  // We have to create a new item for the local item under the collection that has
127  // been retrieved when we fetched the other item.
128  ItemCreateJob *job = new ItemCreateJob( mChangedItem, mConflictingItem.parentCollection(), mSession );
129  connect( job, SIGNAL(result(KJob*)), SLOT(slotUseBothItemsFinished(KJob*)) );
130 }
131 
132 void ConflictHandler::slotUseBothItemsFinished( KJob *job )
133 {
134  if ( job->error() ) {
135  emit error( job->errorText() ); //TODO: extend error message
136  } else {
137  emit conflictResolved();
138  }
139 }
140 
141 #include "moc_conflicthandler_p.cpp"
Akonadi::ConflictHandler::ConflictHandler
ConflictHandler(ConflictType type, QObject *parent=0)
Creates a new conflict handler.
Definition: conflicthandler.cpp:34
Akonadi::ConflictHandler::UseLocalItem
The local item overwrites the other item inside the Akonadi storage.
Definition: conflicthandler_p.h:58
Akonadi::ConflictResolveDialog::setConflictingItems
void setConflictingItems(const Akonadi::Item &localItem, const Akonadi::Item &otherItem)
Sets the items that causes the conflict.
Definition: conflictresolvedialog.cpp:217
Akonadi::ConflictHandler::UseBothItems
Both items are kept in the Akonadi storage.
Definition: conflicthandler_p.h:60
Akonadi::ConflictResolveDialog::resolveStrategy
ConflictHandler::ResolveStrategy resolveStrategy() const
Returns the resolve strategy the user choose.
Definition: conflictresolvedialog.cpp:245
Akonadi::ConflictHandler::error
void error(const QString &message)
This signal is emitted whenever an error occurred during the conflict handling.
Akonadi::ItemFetchScope::fetchFullPayload
void fetchFullPayload(bool fetch=true)
Sets whether the full payload shall be fetched.
Definition: itemfetchscope.cpp:68
Akonadi::ItemFetchJob::items
Item::List items() const
Returns the fetched items.
Definition: itemfetchjob.cpp:228
Akonadi::ItemFetchJob::fetchScope
ItemFetchScope & fetchScope()
Returns the item fetch scope.
Definition: itemfetchjob.cpp:256
Akonadi::ConflictHandler::setConflictingItems
void setConflictingItems(const Akonadi::Item &changedItem, const Akonadi::Item &conflictingItem)
Sets the items that causes the conflict.
Definition: conflicthandler.cpp:41
Akonadi::ConflictHandler::LocalLocalConflict
Changes of two Akonadi client applications conflict.
Definition: conflicthandler_p.h:49
Akonadi::ItemFetchScope::Parent
Only retrieve the immediate parent collection.
Definition: itemfetchscope.h:77
Akonadi::ConflictHandler::conflictResolved
void conflictResolved()
This signal is emitted whenever the conflict has been resolved automatically or by the user...
Akonadi::Session
A communication session with the Akonadi storage.
Definition: session.h:59
Akonadi::ItemCreateJob
Job that creates a new item in the Akonadi storage.
Definition: itemcreatejob.h:73
Akonadi::ItemFetchScope::setAncestorRetrieval
void setAncestorRetrieval(AncestorRetrieval ancestorDepth)
Sets how many levels of ancestor collections should be included in the retrieval. ...
Definition: itemfetchscope.cpp:128
Akonadi::ConflictHandler::UseOtherItem
The local item is dropped and the other item from the Akonadi storage is used.
Definition: conflicthandler_p.h:59
Akonadi::ItemModifyJob
Job that modifies an existing item in the Akonadi storage.
Definition: itemmodifyjob.h:97
Akonadi::ItemFetchJob
Job that fetches items from the Akonadi storage.
Definition: itemfetchjob.h:82
Akonadi::ConflictHandler::LocalRemoteConflict
Changes of an Akonadi client application and a resource conflict.
Definition: conflicthandler_p.h:50
Akonadi::ConflictHandler::ResolveStrategy
ResolveStrategy
Describes the strategy that should be used for resolving the conflict.
Definition: conflicthandler_p.h:57
Akonadi::ConflictResolveDialog
A dialog to ask the user for a resolve strategy for conflicts.
Definition: conflictresolvedialog_p.h:37
Akonadi::ConflictHandler::ConflictType
ConflictType
Describes the type of conflict that should be resolved by the conflict handler.
Definition: conflicthandler_p.h:48
Akonadi::ConflictHandler::start
void start()
Starts the conflict handling.
Definition: conflicthandler.cpp:47
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 23:00:26 by doxygen 1.8.7 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 API Reference

Skip menu "kdepimlibs API Reference"
  • akonadi
  •   contact
  •   kmime
  •   socialutils
  • kabc
  • kalarmcal
  • kblog
  • kcal
  • kcalcore
  • kcalutils
  • kholidays
  • kimap
  • kldap
  • kmbox
  • kmime
  • kpimidentities
  • kpimtextedit
  • kresources
  • ktnef
  • kxmlrpcclient
  • microblog

Search



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