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 } else {
00068 return "after" + d->mDueDate.toString( Qt::ISODate ).toLatin1();
00069 }
00070 }
00071 case Manual: return "never";
00072 }
00073
00074 Q_ASSERT( false );
00075 return QByteArray();
00076 }
00077
00078 void DispatchModeAttribute::deserialize( const QByteArray &data )
00079 {
00080 d->mDueDate = QDateTime();
00081 if ( data == "immediately" ) {
00082 d->mMode = Automatic;
00083 } else if ( data == "never" ) {
00084 d->mMode = Manual;
00085 } else if ( data.startsWith( QByteArray( "after" ) ) ) {
00086 d->mMode = Automatic;
00087 d->mDueDate = QDateTime::fromString( QString::fromLatin1( data.mid(5) ), Qt::ISODate );
00088
00089 } else {
00090 kWarning() << "Failed to deserialize data [" << data << "]";
00091 }
00092 }
00093
00094 DispatchModeAttribute::DispatchMode DispatchModeAttribute::dispatchMode() const
00095 {
00096 return d->mMode;
00097 }
00098
00099 void DispatchModeAttribute::setDispatchMode( DispatchMode mode )
00100 {
00101 d->mMode = mode;
00102 }
00103
00104 QDateTime DispatchModeAttribute::sendAfter() const
00105 {
00106 return d->mDueDate;
00107 }
00108
00109 void DispatchModeAttribute::setSendAfter( const QDateTime &date )
00110 {
00111 d->mDueDate = date;
00112 }
00113