• Skip to content
  • Skip to link menu
KDE 4.4 API Reference
  • KDE API Reference
  • KDE-PIM Libraries
  • Sitemap
  • 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       }
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(); // suppress control-reaches-end-of-non-void-function warning
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     // NOTE: 5 is the strlen of "after".
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 

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
  • kholidays
  • kimap
  • kioslave
  •   imap4
  •   mbox
  •   nntp
  • kldap
  • kmime
  • kontactinterface
  • kpimidentities
  • kpimtextedit
  •   richtextbuilders
  • kpimutils
  • kresources
  • ktnef
  • kxmlrpcclient
  • mailtransport
  • microblog
  • qgpgme
  • syndication
  •   atom
  •   rdf
  •   rss2
Generated for KDE-PIM Libraries by doxygen 1.6.1
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