00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #include "indexpolicyattribute.h"
00021
00022 #include <akonadi/private/imapparser_p.h>
00023
00024 #include <QtCore/QString>
00025
00026 using namespace Akonadi;
00027
00028 class IndexPolicyAttribute::Private
00029 {
00030 public:
00031 Private() : enable( true ) {}
00032 bool enable;
00033 };
00034
00035 IndexPolicyAttribute::IndexPolicyAttribute()
00036 : d( new Private )
00037 {
00038 }
00039
00040 IndexPolicyAttribute::~IndexPolicyAttribute()
00041 {
00042 delete d;
00043 }
00044
00045 bool IndexPolicyAttribute::indexingEnabled() const
00046 {
00047 return d->enable;
00048 }
00049
00050 void IndexPolicyAttribute::setIndexingEnabled(bool enable)
00051 {
00052 d->enable = enable;
00053 }
00054
00055 QByteArray IndexPolicyAttribute::type() const
00056 {
00057 return "INDEXPOLICY";
00058 }
00059
00060 Attribute* IndexPolicyAttribute::clone() const
00061 {
00062 IndexPolicyAttribute* attr = new IndexPolicyAttribute;
00063 attr->setIndexingEnabled( indexingEnabled() );
00064 return attr;
00065 }
00066
00067 QByteArray IndexPolicyAttribute::serialized() const
00068 {
00069 QList<QByteArray> l;
00070 l.append( "ENABLE" );
00071 l.append( d->enable ? "true" : "false" );
00072 return "(" + ImapParser::join( l, " " ) + ')';
00073 }
00074
00075 void IndexPolicyAttribute::deserialize(const QByteArray& data)
00076 {
00077 QList<QByteArray> l;
00078 ImapParser::parseParenthesizedList( data, l );
00079 for ( int i = 0; i < l.size() - 1; i += 2 ) {
00080 const QByteArray key = l.at( i );
00081 if ( key == "ENABLE" )
00082 d->enable = l.at( i + 1 ) == "true";
00083 }
00084 }