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

akonadi

  • 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 <klocale.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"
This file is part of the KDE documentation.
Documentation copyright © 1996-2013 The KDE developers.
Generated on Sat Jul 13 2013 01:27:34 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