• Skip to content
  • Skip to link menu
  • KDE API Reference
  • kdepimlibs-4.9.3 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 && !message.itemParts().isEmpty() )
58  m_parentDestCollection.setResource( QString::fromLatin1( *(message.itemParts().begin()) ) );
59 
60  m_parentCollection.setResource( QString::fromUtf8( message.resource() ) );
61 }
62 
63 Item::List ObjectNotificationMessage::items() const
64 {
65  return m_items;
66 }
67 
68 Collection::List ObjectNotificationMessage::collections() const
69 {
70  return m_collections;
71 }
72 
73 NotificationMessage ObjectNotificationMessage::message() const
74 {
75  return m_message;
76 }
77 
78 NotificationMessage::Operation ObjectNotificationMessage::operation() const
79 {
80  return m_message.operation();
81 }
82 
83 NotificationMessage::Type ObjectNotificationMessage::type() const
84 {
85  return m_message.type();
86 }
87 
88 QByteArray ObjectNotificationMessage::resource() const
89 {
90  return m_message.resource();
91 }
92 
93 QString ObjectNotificationMessage::remoteId() const
94 {
95  return m_message.remoteId();
96 }
97 
98 QSet<QByteArray> ObjectNotificationMessage::itemParts() const
99 {
100  return m_message.itemParts();
101 }
102 
103 QString ObjectNotificationMessage::mimeType() const
104 {
105  return m_message.mimeType();
106 }
107 
108 Collection ObjectNotificationMessage::parentCollection() const
109 {
110  return m_parentCollection;
111 }
112 
113 Collection ObjectNotificationMessage::parentDestCollection() const
114 {
115  return m_parentDestCollection;
116 }
117 
118 void ObjectNotificationMessage::appendCollections(const Akonadi::Collection::List& list)
119 {
120  m_collections.append(list);
121 }
122 
123 void ObjectNotificationMessage::appendItems(const Akonadi::Item::List& list)
124 {
125  m_items.append(list);
126 }
127 
128 template<typename Container>
129 bool do_appendAndCompress(Container &container, const Akonadi::ObjectNotificationMessage& message )
130 {
131  if ( container.isEmpty() ) {
132  container.push_back(message);
133  return true;
134  }
135  const ObjectNotificationMessage lastMessage = container.last().message();
136  if (lastMessage.message().type() == message.message().type()
137  && lastMessage.message().operation() == message.message().operation()
138  && lastMessage.parentCollection() == message.parentCollection()
139  && lastMessage.parentDestCollection() == message.parentDestCollection() ) {
140  container.last().appendCollections(message.collections());
141  container.last().appendItems(message.items());
142  } else {
143  container.push_back(message);
144  return true;
145  }
146  return false;
147 }
148 
149 bool ObjectNotificationMessage::appendAndCompress(QVector<ObjectNotificationMessage> &vector, const Akonadi::ObjectNotificationMessage& message )
150 {
151  return do_appendAndCompress(vector, message);
152 }
153 
154 bool ObjectNotificationMessage::appendAndCompress(QList<ObjectNotificationMessage> &list, const Akonadi::ObjectNotificationMessage& message )
155 {
156  return do_appendAndCompress(list, message);
157 }
This file is part of the KDE documentation.
Documentation copyright © 1996-2012 The KDE developers.
Generated on Mon Nov 26 2012 16:48:20 by doxygen 1.8.1.2 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.9.3 API Reference

Skip menu "kdepimlibs-4.9.3 API Reference"
  • akonadi
  •   contact
  •   kmime
  • kabc
  • kalarmcal
  • kblog
  • kcal
  • kcalcore
  • kcalutils
  • kholidays
  • kimap
  • kioslave
  •   imap4
  •   mbox
  •   nntp
  • kldap
  • kmbox
  • kmime
  • kontactinterface
  • kpimidentities
  • kpimtextedit
  •   richtextbuilders
  • 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