• Skip to content
  • Skip to link menu
  • KDE API Reference
  • kdepimlibs-4.14.10 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 <klocalizedstring.h>
31
32using namespace Akonadi;
33
34ConflictHandler::ConflictHandler(ConflictType type, QObject *parent)
35 : QObject(parent)
36 , mConflictType(type)
37 , mSession(new Session("conflict handling session", this))
38{
39}
40
41void ConflictHandler::setConflictingItems(const Akonadi::Item &changedItem, const Akonadi::Item &conflictingItem)
42{
43 mChangedItem = changedItem;
44 mConflictingItem = conflictingItem;
45}
46
47void 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
59void 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
76void 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
96void 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
109void 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
118void ConflictHandler::useOtherItem()
119{
120 // We can just ignore the local item here and leave everything as it is.
121 emit conflictResolved();
122}
123
124void 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
132void 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::start
void start()
Starts the conflict handling.
Definition conflicthandler.cpp:47
Akonadi::ConflictHandler::ConflictHandler
ConflictHandler(ConflictType type, QObject *parent=0)
Creates a new conflict handler.
Definition conflicthandler.cpp:34
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::error
void error(const QString &message)
This signal is emitted whenever an error occurred during the conflict handling.
Akonadi::ConflictHandler::conflictResolved
void conflictResolved()
This signal is emitted whenever the conflict has been resolved automatically or by the user.
Akonadi::ConflictHandler::ConflictType
ConflictType
Describes the type of conflict that should be resolved by the conflict handler.
Definition conflicthandler_p.h:48
Akonadi::ConflictHandler::LocalLocalConflict
@ LocalLocalConflict
Changes of two Akonadi client applications conflict.
Definition conflicthandler_p.h:49
Akonadi::ConflictHandler::LocalRemoteConflict
@ LocalRemoteConflict
Changes of an Akonadi client application and a resource conflict.
Definition conflicthandler_p.h:50
Akonadi::ConflictHandler::UseOtherItem
@ UseOtherItem
The local item is dropped and the other item from the Akonadi storage is used.
Definition conflicthandler_p.h:59
Akonadi::ConflictHandler::UseBothItems
@ UseBothItems
Both items are kept in the Akonadi storage.
Definition conflicthandler_p.h:60
Akonadi::ConflictHandler::UseLocalItem
@ UseLocalItem
The local item overwrites the other item inside the Akonadi storage.
Definition conflicthandler_p.h:58
Akonadi::ConflictResolveDialog
A dialog to ask the user for a resolve strategy for conflicts.
Definition conflictresolvedialog_p.h:38
Akonadi::ConflictResolveDialog::resolveStrategy
ConflictHandler::ResolveStrategy resolveStrategy() const
Returns the resolve strategy the user choose.
Definition conflictresolvedialog.cpp:245
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::ItemCreateJob
Job that creates a new item in the Akonadi storage.
Definition itemcreatejob.h:74
Akonadi::ItemFetchJob
Job that fetches items from the Akonadi storage.
Definition itemfetchjob.h:83
Akonadi::ItemFetchJob::fetchScope
ItemFetchScope & fetchScope()
Returns the item fetch scope.
Definition itemfetchjob.cpp:261
Akonadi::ItemFetchJob::items
Item::List items() const
Returns the fetched items.
Definition itemfetchjob.cpp:233
Akonadi::ItemFetchScope::setAncestorRetrieval
void setAncestorRetrieval(AncestorRetrieval ancestorDepth)
Sets how many levels of ancestor collections should be included in the retrieval.
Definition itemfetchscope.cpp:132
Akonadi::ItemFetchScope::fetchFullPayload
void fetchFullPayload(bool fetch=true)
Sets whether the full payload shall be fetched.
Definition itemfetchscope.cpp:70
Akonadi::ItemFetchScope::Parent
@ Parent
Only retrieve the immediate parent collection.
Definition itemfetchscope.h:78
Akonadi::ItemModifyJob
Job that modifies an existing item in the Akonadi storage.
Definition itemmodifyjob.h:98
Akonadi::Session
A communication session with the Akonadi storage.
Definition session.h:60
Akonadi
FreeBusyManager::Singleton.
Definition actionstatemanager_p.h:28
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Wed Jan 24 2024 00:00:00 by doxygen 1.10.0 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
  • Related Pages

kdepimlibs-4.14.10 API Reference

Skip menu "kdepimlibs-4.14.10 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