00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #include "messagethreadingattribute.h"
00021
00022 using namespace Akonadi;
00023
00024 class Akonadi::MessageThreadingAttribute::Private
00025 {
00026 public:
00027 QList<Item::Id> perfectParents;
00028 QList<Item::Id> unperfectParents;
00029 QList<Item::Id> subjectParents;
00030 };
00031
00032 MessageThreadingAttribute::MessageThreadingAttribute() :
00033 d( new Private )
00034 {
00035 }
00036
00037 MessageThreadingAttribute::MessageThreadingAttribute(const MessageThreadingAttribute & other) :
00038 Attribute( other ),
00039 d( new Private( *(other.d) ) )
00040 {
00041 }
00042
00043 MessageThreadingAttribute::~ MessageThreadingAttribute()
00044 {
00045 delete d;
00046 }
00047
00048 QByteArray MessageThreadingAttribute::type() const
00049 {
00050 return "MESSAGETHREADING";
00051 }
00052
00053 MessageThreadingAttribute * MessageThreadingAttribute::clone() const
00054 {
00055 return new MessageThreadingAttribute( *this );
00056 }
00057
00058 QByteArray MessageThreadingAttribute::serialized() const
00059 {
00060 QByteArray rv;
00061 foreach ( const Item::Id id, d->perfectParents )
00062 rv += QByteArray::number( id ) + ',';
00063 if ( !d->perfectParents.isEmpty() )
00064 rv[rv.size() - 1] = ';';
00065 else
00066 rv += ';';
00067 foreach ( const Item::Id id, d->unperfectParents )
00068 rv += QByteArray::number( id ) + ',';
00069 if ( !d->unperfectParents.isEmpty() )
00070 rv[rv.size() - 1] = ';';
00071 else
00072 rv += ';';
00073 foreach ( const Item::Id id, d->subjectParents )
00074 rv += QByteArray::number( id ) + ',';
00075 if ( !d->perfectParents.isEmpty() )
00076 rv.chop( 1 );
00077
00078 return rv;
00079 }
00080
00081 static void parseIdList( const QByteArray &data, QList<Item::Id> &result )
00082 {
00083 bool ok = false;
00084 foreach( const QByteArray &s, data.split( ',' ) ) {
00085 Item::Id id = s.toLongLong( &ok );
00086 if( !ok )
00087 continue;
00088 result << id;
00089 }
00090 }
00091
00092 void MessageThreadingAttribute::deserialize(const QByteArray & data)
00093 {
00094 d->perfectParents.clear();
00095 d->unperfectParents.clear();
00096 d->subjectParents.clear();
00097
00098 QList<QByteArray> lists = data.split( ';' );
00099 if ( lists.size() != 3 )
00100 return;
00101
00102 parseIdList( lists[0], d->perfectParents );
00103 parseIdList( lists[1], d->unperfectParents );
00104 parseIdList( lists[2], d->subjectParents );
00105 }
00106
00107 QList< Item::Id > MessageThreadingAttribute::perfectParents() const
00108 {
00109 return d->perfectParents;
00110 }
00111
00112 void MessageThreadingAttribute::setPerfectParents(const QList< Item::Id > & parents)
00113 {
00114 d->perfectParents = parents;
00115 }
00116
00117 QList< Item::Id > MessageThreadingAttribute::unperfectParents() const
00118 {
00119 return d->unperfectParents;
00120 }
00121
00122 void MessageThreadingAttribute::setUnperfectParents(const QList< Item::Id > & parents)
00123 {
00124 d->unperfectParents = parents;
00125 }
00126
00127 QList< Item::Id > MessageThreadingAttribute::subjectParents() const
00128 {
00129 return d->subjectParents;
00130 }
00131
00132 void MessageThreadingAttribute::setSubjectParents(const QList< Item::Id > & parents)
00133 {
00134 d->subjectParents = parents;
00135 }