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

akonadi

  • akonadi
objectnotificationmessage.cpp
1 /*
2  Copyright (c) 2011 Stephen Kelly <steveire@gmail.com>
3 
4  This library is free software; you can redistribute it and/or modify it
5  under the terms of the GNU Library General Public License as published by
6  the Free Software Foundation; either version 2 of the License, or (at your
7  option) any later version.
8 
9  This library is distributed in the hope that it will be useful, but WITHOUT
10  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11  FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
12  License for more details.
13 
14  You should have received a copy of the GNU Library General Public License
15  along with this library; see the file COPYING.LIB. If not, write to the
16  Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
17  02110-1301, USA.
18 */
19 
20 #include "objectnotificationmessage.h"
21 
22 using namespace Akonadi;
23 
24 ObjectNotificationMessage::ObjectNotificationMessage(const Akonadi::NotificationMessage &message)
25  : m_parentCollection(message.parentCollection()),
26  m_parentDestCollection(message.parentDestCollection()),
27  m_message(message)
28 {
29  if ( message.type() == NotificationMessage::Collection ) {
30  Collection col( message.uid() );
31  col.setResource( QString::fromUtf8( message.resource() ) );
32  col.setRemoteId( message.remoteId() );
33  col.setParentCollection( message.operation() == NotificationMessage::Move ? m_parentDestCollection : m_parentCollection );
34 
35  if ( message.operation() == NotificationMessage::Remove ) {
36  const QString remoteRevision = QString::fromUtf8( message.itemParts().toList().first() );
37  col.setRemoteRevision( remoteRevision );
38  }
39  m_collections.append( col );
40  } else if ( message.type() == NotificationMessage::Item ) {
41  Item item( message.uid() );
42  item.setRemoteId( message.remoteId() );
43  item.setMimeType( message.mimeType() );
44  item.setParentCollection( message.operation() == NotificationMessage::Move ? m_parentDestCollection : m_parentCollection );
45 
46  // HACK: We have the remoteRevision stored in the itemParts set
47  // for delete operations to avoid protocol breakage
48  if ( message.operation() == NotificationMessage::Remove ) {
49  const QString remoteRevision = QString::fromUtf8( message.itemParts().toList().first() );
50  item.setRemoteRevision( remoteRevision );
51  }
52 
53  m_items.append( item );
54  }
55 
56  // HACK: destination resource is delivered in the parts field...
57  if ( message.operation() == NotificationMessage::Move &&
58  !message.itemParts().isEmpty() ) {
59  m_parentDestCollection.setResource( QString::fromLatin1( *( message.itemParts().begin() ) ) );
60  }
61 
62  m_parentCollection.setResource( QString::fromUtf8( message.resource() ) );
63 }
64 
65 Item::List ObjectNotificationMessage::items() const
66 {
67  return m_items;
68 }
69 
70 Collection::List ObjectNotificationMessage::collections() const
71 {
72  return m_collections;
73 }
74 
75 NotificationMessage ObjectNotificationMessage::message() const
76 {
77  return m_message;
78 }
79 
80 NotificationMessage::Operation ObjectNotificationMessage::operation() const
81 {
82  return m_message.operation();
83 }
84 
85 NotificationMessage::Type ObjectNotificationMessage::type() const
86 {
87  return m_message.type();
88 }
89 
90 QByteArray ObjectNotificationMessage::resource() const
91 {
92  return m_message.resource();
93 }
94 
95 QString ObjectNotificationMessage::remoteId() const
96 {
97  return m_message.remoteId();
98 }
99 
100 QSet<QByteArray> ObjectNotificationMessage::itemParts() const
101 {
102  return m_message.itemParts();
103 }
104 
105 QString ObjectNotificationMessage::mimeType() const
106 {
107  return m_message.mimeType();
108 }
109 
110 Collection ObjectNotificationMessage::parentCollection() const
111 {
112  return m_parentCollection;
113 }
114 
115 Collection ObjectNotificationMessage::parentDestCollection() const
116 {
117  return m_parentDestCollection;
118 }
119 
120 void ObjectNotificationMessage::appendCollections(const Akonadi::Collection::List& list)
121 {
122  m_collections.append( list );
123 }
124 
125 void ObjectNotificationMessage::appendItems(const Akonadi::Item::List& list)
126 {
127  m_items.append( list );
128 }
129 
130 template<typename Container>
131 bool do_appendAndCompress(Container &container, const Akonadi::ObjectNotificationMessage& message )
132 {
133  if ( container.isEmpty() ) {
134  container.push_back( message );
135  return true;
136  }
137  const ObjectNotificationMessage lastMessage = container.last().message();
138  if ( lastMessage.message().type() == message.message().type() &&
139  lastMessage.message().operation() == message.message().operation() &&
140  lastMessage.parentCollection() == message.parentCollection() &&
141  lastMessage.parentDestCollection() == message.parentDestCollection() ) {
142  container.last().appendCollections( message.collections() );
143  container.last().appendItems( message.items() );
144  } else {
145  container.push_back( message );
146  return true;
147  }
148  return false;
149 }
150 
151 bool ObjectNotificationMessage::appendAndCompress(QVector<ObjectNotificationMessage> &vector, const Akonadi::ObjectNotificationMessage& message )
152 {
153  return do_appendAndCompress( vector, message );
154 }
155 
156 bool ObjectNotificationMessage::appendAndCompress(QList<ObjectNotificationMessage> &list, const Akonadi::ObjectNotificationMessage& message )
157 {
158  return do_appendAndCompress( list, message );
159 }
This file is part of the KDE documentation.
Documentation copyright © 1996-2013 The KDE developers.
Generated on Sat Jul 13 2013 01:27:39 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