00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #include "persistentsearchattribute.h"
00021
00022 #include <akonadi/private/imapparser_p.h>
00023
00024 #include <QtCore/QString>
00025
00026 using namespace Akonadi;
00027
00028 class PersistentSearchAttribute::Private
00029 {
00030 public:
00031 QString queryLanguage;
00032 QString queryString;
00033 };
00034
00035 PersistentSearchAttribute::PersistentSearchAttribute()
00036 : d( new Private )
00037 {
00038 }
00039
00040 PersistentSearchAttribute::~PersistentSearchAttribute()
00041 {
00042 delete d;
00043 }
00044
00045 QString PersistentSearchAttribute::queryLanguage() const
00046 {
00047 return d->queryLanguage;
00048 }
00049
00050 void PersistentSearchAttribute::setQueryLanguage(const QString& language)
00051 {
00052 d->queryLanguage = language;
00053 }
00054
00055 QString PersistentSearchAttribute::queryString() const
00056 {
00057 return d->queryString;
00058 }
00059
00060 void PersistentSearchAttribute::setQueryString(const QString& query)
00061 {
00062 d->queryString = query;
00063 }
00064
00065 QByteArray PersistentSearchAttribute::type() const
00066 {
00067 return "PERSISTENTSEARCH";
00068 }
00069
00070 Attribute* PersistentSearchAttribute::clone() const
00071 {
00072 PersistentSearchAttribute* attr = new PersistentSearchAttribute;
00073 attr->setQueryLanguage( queryLanguage() );
00074 attr->setQueryString( queryString() );
00075 return attr;
00076 }
00077
00078 QByteArray PersistentSearchAttribute::serialized() const
00079 {
00080 QList<QByteArray> l;
00081
00082 l.append( "QUERYLANGUAGE" );
00083 l.append( d->queryLanguage.toLatin1() );
00084 l.append( "QUERYSTRING" );
00085 l.append( ImapParser::quote( d->queryString.toUtf8() ) );
00086 return "(" + ImapParser::join( l, " " ) + ')';
00087 }
00088
00089 void PersistentSearchAttribute::deserialize(const QByteArray& data)
00090 {
00091 QList<QByteArray> l;
00092 ImapParser::parseParenthesizedList( data, l );
00093 for ( int i = 0; i < l.size() - 1; i += 2 ) {
00094 const QByteArray key = l.at( i );
00095 if ( key == "QUERYLANGUAGE" )
00096 d->queryLanguage = QString::fromLatin1( l.at( i + 1 ) );
00097 else if ( key == "QUERYSTRING" )
00098 d->queryString = QString::fromUtf8( l.at( i + 1 ) );
00099 }
00100 }