• Skip to content
  • Skip to link menu
KDE 4.6 API Reference
  • KDE API Reference
  • KDE-PIM Libraries
  • KDE Home
  • Contact Us
 

mailtransport

dispatchmodeattribute.cpp
00001 /*
00002     Copyright 2009 Constantin Berzan <exit3219@gmail.com>
00003 
00004     This library is free software; you can redistribute it and/or modify it
00005     under the terms of the GNU Library General Public License as published by
00006     the Free Software Foundation; either version 2 of the License, or (at your
00007     option) any later version.
00008 
00009     This library is distributed in the hope that it will be useful, but WITHOUT
00010     ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00011     FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Library General Public
00012     License for more details.
00013 
00014     You should have received a copy of the GNU Library General Public License
00015     along with this library; see the file COPYING.LIB.  If not, write to the
00016     Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
00017     02110-1301, USA.
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(); // suppress control-reaches-end-of-non-void-function warning
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     // NOTE: 5 is the strlen of "after".
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 

mailtransport

Skip menu "mailtransport"
  • Main Page
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Class Members
  • Related Pages

KDE-PIM Libraries

Skip menu "KDE-PIM Libraries"
  • akonadi
  •   contact
  •   kmime
  • kabc
  • kblog
  • kcal
  • kcalcore
  • kcalutils
  • kholidays
  • kimap
  • kioslave
  •   imap4
  •   mbox
  •   nntp
  • kldap
  • kmbox
  • kmime
  • kontactinterface
  • kpimidentities
  • kpimtextedit
  •   richtextbuilders
  • kpimutils
  • kresources
  • ktnef
  • kxmlrpcclient
  • mailtransport
  • microblog
  • qgpgme
  • syndication
  •   atom
  •   rdf
  •   rss2
Generated for KDE-PIM Libraries by doxygen 1.7.4
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal