20 #include "objectnotificationmessage.h"
22 using namespace Akonadi;
24 ObjectNotificationMessage::ObjectNotificationMessage(
const Akonadi::NotificationMessage &message)
25 : m_parentCollection(message.parentCollection()),
26 m_parentDestCollection(message.parentDestCollection()),
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 );
35 if ( message.operation() == NotificationMessage::Remove ) {
36 const QString remoteRevision = QString::fromUtf8( message.itemParts().toList().first() );
37 col.setRemoteRevision( remoteRevision );
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 );
48 if ( message.operation() == NotificationMessage::Remove ) {
49 const QString remoteRevision = QString::fromUtf8( message.itemParts().toList().first() );
50 item.setRemoteRevision( remoteRevision );
53 m_items.append( item );
57 if ( message.operation() == NotificationMessage::Move && !message.itemParts().isEmpty() )
58 m_parentDestCollection.setResource( QString::fromLatin1( *(message.itemParts().begin()) ) );
60 m_parentCollection.setResource( QString::fromUtf8( message.resource() ) );
63 Item::List ObjectNotificationMessage::items()
const
68 Collection::List ObjectNotificationMessage::collections()
const
73 NotificationMessage ObjectNotificationMessage::message()
const
78 NotificationMessage::Operation ObjectNotificationMessage::operation()
const
80 return m_message.operation();
83 NotificationMessage::Type ObjectNotificationMessage::type()
const
85 return m_message.type();
88 QByteArray ObjectNotificationMessage::resource()
const
90 return m_message.resource();
93 QString ObjectNotificationMessage::remoteId()
const
95 return m_message.remoteId();
98 QSet<QByteArray> ObjectNotificationMessage::itemParts()
const
100 return m_message.itemParts();
103 QString ObjectNotificationMessage::mimeType()
const
105 return m_message.mimeType();
108 Collection ObjectNotificationMessage::parentCollection()
const
110 return m_parentCollection;
113 Collection ObjectNotificationMessage::parentDestCollection()
const
115 return m_parentDestCollection;
118 void ObjectNotificationMessage::appendCollections(
const Akonadi::Collection::List& list)
120 m_collections.append(list);
123 void ObjectNotificationMessage::appendItems(
const Akonadi::Item::List& list)
125 m_items.append(list);
128 template<
typename Container>
129 bool do_appendAndCompress(Container &container,
const Akonadi::ObjectNotificationMessage& message )
131 if ( container.isEmpty() ) {
132 container.push_back(message);
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());
143 container.push_back(message);
149 bool ObjectNotificationMessage::appendAndCompress(QVector<ObjectNotificationMessage> &vector,
const Akonadi::ObjectNotificationMessage& message )
151 return do_appendAndCompress(vector, message);
154 bool ObjectNotificationMessage::appendAndCompress(QList<ObjectNotificationMessage> &list,
const Akonadi::ObjectNotificationMessage& message )
156 return do_appendAndCompress(list, message);