mailtransport
dispatchmodeattribute.cpp
00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #include "dispatchmodeattribute.h"
00021
00022 #include <KDebug>
00023
00024 #include "akonadi/attributefactory.h"
00025
00026 using namespace Akonadi;
00027 using namespace MailTransport;
00028
00029 class DispatchModeAttribute::Private
00030 {
00031 public:
00032 DispatchMode mMode;
00033 QDateTime mDueDate;
00034 };
00035
00036 DispatchModeAttribute::DispatchModeAttribute( DispatchMode mode )
00037 : d( new Private )
00038 {
00039 d->mMode = mode;
00040 }
00041
00042 DispatchModeAttribute::~DispatchModeAttribute()
00043 {
00044 delete d;
00045 }
00046
00047 DispatchModeAttribute *DispatchModeAttribute::clone() const
00048 {
00049 DispatchModeAttribute * const cloned = new DispatchModeAttribute( d->mMode );
00050 cloned->setSendAfter( d->mDueDate );
00051 return cloned;
00052 }
00053
00054 QByteArray DispatchModeAttribute::type() const
00055 {
00056 static const QByteArray sType( "DispatchModeAttribute" );
00057 return sType;
00058 }
00059
00060 QByteArray DispatchModeAttribute::serialized() const
00061 {
00062 switch( d->mMode ) {
00063 case Automatic:
00064 {
00065 if ( !d->mDueDate.isValid() ) {
00066 return "immediately";
00067 }
00068 else {
00069 return "after" + d->mDueDate.toString( Qt::ISODate ).toLatin1();
00070 }
00071 }
00072 case Manual: return "never";
00073 }
00074
00075 Q_ASSERT( false );
00076 return QByteArray();
00077 }
00078
00079 void DispatchModeAttribute::deserialize( const QByteArray &data )
00080 {
00081 d->mDueDate = QDateTime();
00082 if ( data == "immediately" ) {
00083 d->mMode = Automatic;
00084 } else if ( data == "never" ) {
00085 d->mMode = Manual;
00086 } else if ( data.startsWith( QByteArray( "after" ) ) ) {
00087 d->mMode = Automatic;
00088 d->mDueDate = QDateTime::fromString( QString::fromLatin1( data.mid(5) ), Qt::ISODate );
00089
00090 } else {
00091 kWarning() << "Failed to deserialize data [" << data << "]";
00092 }
00093 }
00094
00095 DispatchModeAttribute::DispatchMode DispatchModeAttribute::dispatchMode() const
00096 {
00097 return d->mMode;
00098 }
00099
00100 void DispatchModeAttribute::setDispatchMode( DispatchMode mode )
00101 {
00102 d->mMode = mode;
00103 }
00104
00105 QDateTime DispatchModeAttribute::sendAfter() const
00106 {
00107 return d->mDueDate;
00108 }
00109
00110 void DispatchModeAttribute::setSendAfter( const QDateTime &date )
00111 {
00112 d->mDueDate = date;
00113 }
00114