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

akonadi

  • sources
  • kde-4.12
  • kdepimlibs
  • akonadi
entitydeletedattribute.cpp
1 /*
2  Copyright (c) 2011 Christian Mollekopf <chrigi_1@fastmail.fm>
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 "entitydeletedattribute.h"
21 
22 #include "imapparser_p.h"
23 
24 #include <QtCore/QByteArray>
25 #include <QtCore/QString>
26 
27 using namespace Akonadi;
28 
29 class EntityDeletedAttribute::EntityDeletedAttributePrivate
30 {
31  public:
32  EntityDeletedAttributePrivate() {};
33 
34  Collection restoreCollection;
35  QString restoreResource;
36 };
37 
38 EntityDeletedAttribute::EntityDeletedAttribute()
39  : d_ptr( new EntityDeletedAttributePrivate() )
40 {
41 
42 }
43 
44 EntityDeletedAttribute::~EntityDeletedAttribute()
45 {
46  delete d_ptr;
47 }
48 
49 void EntityDeletedAttribute::setRestoreCollection( const Akonadi::Collection &collection )
50 {
51  Q_D( EntityDeletedAttribute );
52  if ( !collection.isValid() ) {
53  kWarning() << "invalid collection" << collection;
54  }
55  Q_ASSERT( collection.isValid() );
56  d->restoreCollection = collection;
57  if ( collection.resource().isEmpty() ) {
58  kWarning() << "no resource set";
59  }
60  d->restoreResource = collection.resource();
61 }
62 
63 Collection EntityDeletedAttribute::restoreCollection() const
64 {
65  Q_D( const EntityDeletedAttribute );
66  return d->restoreCollection;
67 }
68 
69 QString EntityDeletedAttribute::restoreResource() const
70 {
71  Q_D( const EntityDeletedAttribute );
72  return d->restoreResource;
73 }
74 
75 QByteArray Akonadi::EntityDeletedAttribute::type() const
76 {
77  return "DELETED";
78 }
79 
80 EntityDeletedAttribute * EntityDeletedAttribute::clone() const
81 {
82  const Q_D( EntityDeletedAttribute );
83  EntityDeletedAttribute *attr = new EntityDeletedAttribute();
84  attr->d_ptr->restoreCollection = d->restoreCollection;
85  attr->d_ptr->restoreResource = d->restoreResource;
86  return attr;
87 }
88 
89 QByteArray EntityDeletedAttribute::serialized() const
90 {
91  const Q_D( EntityDeletedAttribute );
92 
93  QList<QByteArray> l;
94  l << ImapParser::quote( d->restoreResource.toUtf8() );
95  QList<QByteArray> components;
96  components << QByteArray::number( d->restoreCollection.id() );
97 
98  l << '(' + ImapParser::join( components, " " ) + ')';
99  return '(' + ImapParser::join( l, " " ) + ')';
100 }
101 
102 void EntityDeletedAttribute::deserialize( const QByteArray &data )
103 {
104  Q_D( EntityDeletedAttribute );
105 
106  QList<QByteArray> l;
107  ImapParser::parseParenthesizedList( data, l );
108  if ( l.size() != 2 ) {
109  kWarning() << "invalid size";
110  return;
111  }
112  d->restoreResource = QString::fromUtf8( l[0] );
113 
114  if ( !l[1].isEmpty() ) {
115  QList<QByteArray> componentData;
116  ImapParser::parseParenthesizedList( l[1], componentData );
117  if ( componentData.size() != 1 ) {
118  return;
119  }
120  QList<int> components;
121  bool ok;
122  for ( int i = 0; i < 1; ++i ) {
123  components << componentData.at( i ).toInt( &ok );
124  if ( !ok ) {
125  return;
126  }
127  }
128  d->restoreCollection = Collection( components.at( 0 ) );
129  }
130 }
Akonadi::EntityDeletedAttribute::EntityDeletedAttribute
EntityDeletedAttribute()
Creates a new entity deleted attribute.
Definition: entitydeletedattribute.cpp:38
Akonadi::EntityDeletedAttribute::restoreCollection
Collection restoreCollection() const
Returns the original collection of an item that has been moved to trash using a TrashJob.
Definition: entitydeletedattribute.cpp:63
Akonadi::Collection
Represents a collection of PIM items.
Definition: collection.h:75
Akonadi::EntityDeletedAttribute::deserialize
void deserialize(const QByteArray &data)
Reimplemented from Attribute.
Definition: entitydeletedattribute.cpp:102
Akonadi::EntityDeletedAttribute::type
QByteArray type() const
Reimplemented from Attribute.
Definition: entitydeletedattribute.cpp:75
Akonadi::EntityDeletedAttribute::clone
EntityDeletedAttribute * clone() const
Reimplemented from Attribute.
Definition: entitydeletedattribute.cpp:80
Akonadi::EntityDeletedAttribute
An Attribute that marks that an entity was marked as deleted.
Definition: entitydeletedattribute.h:49
Akonadi::EntityDeletedAttribute::restoreResource
QString restoreResource() const
Returns the resource of the restoreCollection.
Definition: entitydeletedattribute.cpp:69
Akonadi::EntityDeletedAttribute::serialized
QByteArray serialized() const
Reimplemented from Attribute.
Definition: entitydeletedattribute.cpp:89
Akonadi::EntityDeletedAttribute::~EntityDeletedAttribute
~EntityDeletedAttribute()
Destroys the entity deleted attribute.
Definition: entitydeletedattribute.cpp:44
Akonadi::Collection::resource
QString resource() const
Returns the identifier of the resource owning the collection.
Definition: collection.cpp:207
Akonadi::Entity::isValid
bool isValid() const
Returns whether the entity is valid.
Definition: entity.cpp:97
Akonadi::EntityDeletedAttribute::setRestoreCollection
void setRestoreCollection(const Collection &col)
Sets the collection used to restore items which have been moved to trash using a TrashJob If the Reso...
Definition: entitydeletedattribute.cpp:49
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 23:00:27 by doxygen 1.8.7 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 API Reference

Skip menu "kdepimlibs API Reference"
  • akonadi
  •   contact
  •   kmime
  •   socialutils
  • kabc
  • kalarmcal
  • kblog
  • kcal
  • kcalcore
  • kcalutils
  • kholidays
  • kimap
  • kldap
  • kmbox
  • kmime
  • kpimidentities
  • kpimtextedit
  • kresources
  • ktnef
  • kxmlrpcclient
  • microblog

Search



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