mailtransport
sentbehaviourattribute.cpp
00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #include "sentbehaviourattribute.h"
00021
00022 #include <QDataStream>
00023
00024 #include <KDebug>
00025
00026 using namespace Akonadi;
00027 using namespace MailTransport;
00028
00029 class SentBehaviourAttribute::Private
00030 {
00031 public:
00032 SentBehaviour mBehaviour;
00033 Akonadi::Collection mMoveToCollection;
00034 };
00035
00036 SentBehaviourAttribute::SentBehaviourAttribute( SentBehaviour beh, Collection moveToCollection )
00037 : d( new Private )
00038 {
00039 d->mBehaviour = beh;
00040 d->mMoveToCollection = moveToCollection;
00041 }
00042
00043 SentBehaviourAttribute::~SentBehaviourAttribute()
00044 {
00045 delete d;
00046 }
00047
00048 SentBehaviourAttribute *SentBehaviourAttribute::clone() const
00049 {
00050 return new SentBehaviourAttribute( d->mBehaviour, d->mMoveToCollection );
00051 }
00052
00053 QByteArray SentBehaviourAttribute::type() const
00054 {
00055 static const QByteArray sType( "SentBehaviourAttribute" );
00056 return sType;
00057 }
00058
00059 QByteArray SentBehaviourAttribute::serialized() const
00060 {
00061 switch( d->mBehaviour ) {
00062 case Delete: return "delete";
00063 case MoveToCollection: return "moveTo" + QByteArray::number( d->mMoveToCollection.id() );
00064 case MoveToDefaultSentCollection: return "moveToDefault";
00065 }
00066
00067 Q_ASSERT( false );
00068 return QByteArray();
00069 }
00070
00071 void SentBehaviourAttribute::deserialize( const QByteArray &data )
00072 {
00073 d->mMoveToCollection = Akonadi::Collection( -1 );
00074 if ( data == "delete" ) {
00075 d->mBehaviour = Delete;
00076 } else if ( data == "moveToDefault" ) {
00077 d->mBehaviour = MoveToDefaultSentCollection;
00078 } else if ( data.startsWith( QByteArray( "moveTo" ) ) ) {
00079 d->mBehaviour = MoveToCollection;
00080 d->mMoveToCollection = Akonadi::Collection( data.mid( 6 ).toLongLong() );
00081
00082 } else {
00083 Q_ASSERT( false );
00084 }
00085 }
00086
00087 SentBehaviourAttribute::SentBehaviour SentBehaviourAttribute::sentBehaviour() const
00088 {
00089 return d->mBehaviour;
00090 }
00091
00092 void SentBehaviourAttribute::setSentBehaviour( SentBehaviour beh )
00093 {
00094 d->mBehaviour = beh;
00095 }
00096
00097 Collection SentBehaviourAttribute::moveToCollection() const
00098 {
00099 return d->mMoveToCollection;
00100 }
00101
00102 void SentBehaviourAttribute::setMoveToCollection( Collection moveToCollection )
00103 {
00104 d->mMoveToCollection = moveToCollection;
00105 }
00106