akonadi
entitydeletedattribute.cpp
00001 /* 00002 Copyright (c) 2011 Christian Mollekopf <chrigi_1@fastmail.fm> 00003 00004 This library is free software; you can redistribute it and/or modify it 00005 under the terms of the GNU Library General Public License as published by 00006 the Free Software Foundation; either version 2 of the License, or (at your 00007 option) any later version. 00008 00009 This library is distributed in the hope that it will be useful, but WITHOUT 00010 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 00011 FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public 00012 License for more details. 00013 00014 You should have received a copy of the GNU Library General Public License 00015 along with this library; see the file COPYING.LIB. If not, write to the 00016 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 00017 02110-1301, USA. 00018 */ 00019 00020 #include "entitydeletedattribute.h" 00021 00022 #include "imapparser_p.h" 00023 00024 #include <QtCore/QByteArray> 00025 #include <QtCore/QString> 00026 00027 using namespace Akonadi; 00028 00029 class EntityDeletedAttribute::EntityDeletedAttributePrivate 00030 { 00031 public: 00032 EntityDeletedAttributePrivate() {}; 00033 00034 Collection restoreCollection; 00035 QString restoreResource; 00036 }; 00037 00038 00039 00040 00041 EntityDeletedAttribute::EntityDeletedAttribute() 00042 : d_ptr( new EntityDeletedAttributePrivate() ) 00043 { 00044 00045 } 00046 00047 EntityDeletedAttribute::~EntityDeletedAttribute() 00048 { 00049 delete d_ptr; 00050 } 00051 00052 void EntityDeletedAttribute::setRestoreCollection( const Akonadi::Collection &collection ) 00053 { 00054 Q_D( EntityDeletedAttribute ); 00055 if ( !collection.isValid() ) { 00056 kWarning() << "invalid collection" << collection; 00057 } 00058 Q_ASSERT( collection.isValid() ); 00059 d->restoreCollection = collection; 00060 if ( collection.resource().isEmpty() ) { 00061 kWarning() << "no resource set"; 00062 } 00063 d->restoreResource = collection.resource(); 00064 } 00065 00066 Collection EntityDeletedAttribute::restoreCollection() const 00067 { 00068 Q_D( const EntityDeletedAttribute ); 00069 return d->restoreCollection; 00070 } 00071 00072 QString EntityDeletedAttribute::restoreResource() const 00073 { 00074 Q_D( const EntityDeletedAttribute ); 00075 return d->restoreResource; 00076 } 00077 00078 QByteArray Akonadi::EntityDeletedAttribute::type() const 00079 { 00080 return "DELETED"; 00081 } 00082 00083 EntityDeletedAttribute * EntityDeletedAttribute::clone() const 00084 { 00085 const Q_D( EntityDeletedAttribute ); 00086 EntityDeletedAttribute *attr = new EntityDeletedAttribute(); 00087 attr->d_ptr->restoreCollection = d->restoreCollection; 00088 attr->d_ptr->restoreResource = d->restoreResource; 00089 return attr; 00090 } 00091 00092 QByteArray EntityDeletedAttribute::serialized() const 00093 { 00094 const Q_D( EntityDeletedAttribute ); 00095 00096 QList<QByteArray> l; 00097 l << ImapParser::quote( d->restoreResource.toUtf8() ); 00098 QList<QByteArray> components; 00099 components << QByteArray::number( d->restoreCollection.id() ); 00100 00101 l << '(' + ImapParser::join( components, " " ) + ')'; 00102 return '(' + ImapParser::join( l, " " ) + ')'; 00103 } 00104 00105 void EntityDeletedAttribute::deserialize( const QByteArray &data ) 00106 { 00107 Q_D( EntityDeletedAttribute ); 00108 00109 QList<QByteArray> l; 00110 ImapParser::parseParenthesizedList( data, l ); 00111 if ( l.size() != 2 ) { 00112 kWarning() << "invalid size"; 00113 return; 00114 } 00115 d->restoreResource = QString::fromUtf8( l[0] ); 00116 00117 if ( !l[1].isEmpty() ) { 00118 QList<QByteArray> componentData; 00119 ImapParser::parseParenthesizedList( l[1], componentData ); 00120 if ( componentData.size() != 1 ) 00121 return; 00122 QList<int> components; 00123 bool ok; 00124 for ( int i = 0; i < 1; ++i ) { 00125 components << componentData.at( i ).toInt( &ok ); 00126 if ( !ok ) 00127 return; 00128 } 00129 d->restoreCollection = Collection( components.at( 0 ) ); 00130 } 00131 }
This file is part of the KDE documentation.
Documentation copyright © 1996-2012 The KDE developers.
Generated on Thu May 10 2012 22:18:32 by doxygen 1.8.0 written by Dimitri van Heesch, © 1997-2006
Documentation copyright © 1996-2012 The KDE developers.
Generated on Thu May 10 2012 22:18:32 by doxygen 1.8.0 written by Dimitri van Heesch, © 1997-2006
KDE's Doxygen guidelines are available online.