diff --git a/outboxinterface/TODO b/outboxinterface/TODO index b6902daf1..d1dae8409 100644 --- a/outboxinterface/TODO +++ b/outboxinterface/TODO @@ -1,11 +1,9 @@ Design: -* Use d-pointers for the attributes? Or rely on having SomeAttrV2 in case - something needs to be added? Future: * Support volatile outbox (not stored on disk). * Support optional default folders (e.g. no sent-mail for IMAP users). Build: * Get our own debug area. diff --git a/outboxinterface/addressattribute.cpp b/outboxinterface/addressattribute.cpp index 50afb69fd..a54158f82 100644 --- a/outboxinterface/addressattribute.cpp +++ b/outboxinterface/addressattribute.cpp @@ -1,112 +1,128 @@ /* Copyright 2009 Constantin Berzan This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include "addressattribute.h" #include #include using namespace Akonadi; using namespace OutboxInterface; +/** + @internal +*/ +class AddressAttribute::Private +{ + public: + QString mFrom; + QStringList mTo; + QStringList mCc; + QStringList mBcc; +}; AddressAttribute::AddressAttribute( const QString &from, const QStringList &to, const QStringList &cc, const QStringList &bcc ) - : mFrom( from ), mTo( to ), mCc( cc ), mBcc( bcc ) + : d( new Private ) { + d->mFrom = from; + d->mTo = to; + d->mCc = cc; + d->mBcc = bcc; } AddressAttribute::~AddressAttribute() { + delete d; } AddressAttribute* AddressAttribute::clone() const { - return new AddressAttribute( mFrom, mTo, mCc, mBcc ); + return new AddressAttribute( d->mFrom, d->mTo, d->mCc, d->mBcc ); } QByteArray AddressAttribute::type() const { static const QByteArray sType( "AddressAttribute" ); return sType; } QByteArray AddressAttribute::serialized() const { QByteArray serializedData; QDataStream serializer( &serializedData, QIODevice::WriteOnly ); serializer.setVersion( QDataStream::Qt_4_5 ); - serializer << mFrom; - serializer << mTo; - serializer << mCc; - serializer << mBcc; + serializer << d->mFrom; + serializer << d->mTo; + serializer << d->mCc; + serializer << d->mBcc; return serializedData; } void AddressAttribute::deserialize( const QByteArray &data ) { QDataStream deserializer( data ); deserializer.setVersion( QDataStream::Qt_4_5 ); - deserializer >> mFrom; - deserializer >> mTo; - deserializer >> mCc; - deserializer >> mBcc; + deserializer >> d->mFrom; + deserializer >> d->mTo; + deserializer >> d->mCc; + deserializer >> d->mBcc; } QString AddressAttribute::from() const { - return mFrom; + return d->mFrom; } void AddressAttribute::setFrom( const QString &from ) { - mFrom = from; + d->mFrom = from; } QStringList AddressAttribute::to() const { - return mTo; + return d->mTo; } void AddressAttribute::setTo( const QStringList &to ) { - mTo = to; + d->mTo = to; } QStringList AddressAttribute::cc() const { - return mCc; + return d->mCc; } void AddressAttribute::setCc( const QStringList &cc ) { - mCc = cc; + d->mCc = cc; } QStringList AddressAttribute::bcc() const { - return mBcc; + return d->mBcc; } void AddressAttribute::setBcc( const QStringList &bcc ) { - mBcc = bcc; + d->mBcc = bcc; } diff --git a/outboxinterface/addressattribute.h b/outboxinterface/addressattribute.h index 0484776ca..7f4c8ac6a 100644 --- a/outboxinterface/addressattribute.h +++ b/outboxinterface/addressattribute.h @@ -1,114 +1,112 @@ /* Copyright 2009 Constantin Berzan This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #ifndef OUTBOXINTERFACE_ADDRESSATTRIBUTE_H #define OUTBOXINTERFACE_ADDRESSATTRIBUTE_H #include #include #include #include namespace MailTransport { class Transport; } namespace OutboxInterface { /** Attribute storing the From, To, Cc, Bcc addresses of a message. @author Constantin Berzan @since 4.4 */ class OUTBOXINTERFACE_EXPORT AddressAttribute : public Akonadi::Attribute { public: /** Creates a new AddressAttribute. */ explicit AddressAttribute( const QString &from = QString(), const QStringList &to = QStringList(), const QStringList &cc = QStringList(), const QStringList &bcc = QStringList() ); /** Destroys the AddressAttribute. */ virtual ~AddressAttribute(); /* reimpl */ virtual AddressAttribute* clone() const; virtual QByteArray type() const; virtual QByteArray serialized() const; virtual void deserialize( const QByteArray &data ); /** Returns the address of the sender. */ QString from() const; /** Sets the address of the sender. */ void setFrom( const QString &from ); /** Returns the addresses of the "To:" receivers. */ QStringList to() const; /** Sets the addresses of the "To:" receivers." */ void setTo( const QStringList &to ); /** Returns the addresses of the "Cc:" receivers. */ QStringList cc() const; /** Sets the addresses of the "Cc:" receivers." */ void setCc( const QStringList &cc ); /** Returns the addresses of the "Bcc:" receivers. */ QStringList bcc() const; /** Sets the addresses of the "Bcc:" receivers." */ void setBcc( const QStringList &bcc ); private: - QString mFrom; - QStringList mTo; - QStringList mCc; - QStringList mBcc; + class Private; + Private *const d; }; } // namespace OutboxInterface #endif // OUTBOXINTERFACE_ADDRESSATTRIBUTE_H diff --git a/outboxinterface/dispatchmodeattribute.cpp b/outboxinterface/dispatchmodeattribute.cpp index cbf401788..0d74e0cfa 100644 --- a/outboxinterface/dispatchmodeattribute.cpp +++ b/outboxinterface/dispatchmodeattribute.cpp @@ -1,97 +1,106 @@ /* Copyright 2009 Constantin Berzan This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include "dispatchmodeattribute.h" #include #include "akonadi/attributefactory.h" using namespace Akonadi; using namespace OutboxInterface; +class DispatchModeAttribute::Private +{ + public: + DispatchMode mMode; + QDateTime mDueDate; +}; + DispatchModeAttribute::DispatchModeAttribute( DispatchMode mode, const QDateTime &date ) - : mMode( mode ) - , mDueDate( date ) + : d( new Private ) { + d->mMode = mode; + d->mDueDate = date; } DispatchModeAttribute::~DispatchModeAttribute() { + delete d; } DispatchModeAttribute* DispatchModeAttribute::clone() const { - return new DispatchModeAttribute( mMode, mDueDate ); + return new DispatchModeAttribute( d->mMode, d->mDueDate ); } QByteArray DispatchModeAttribute::type() const { static const QByteArray sType( "DispatchModeAttribute" ); return sType; } QByteArray DispatchModeAttribute::serialized() const { - switch( mMode ) { + switch( d->mMode ) { case Immediately: return "immediately"; - case AfterDueDate: return "after" + mDueDate.toString(Qt::ISODate).toLatin1(); + case AfterDueDate: return "after" + d->mDueDate.toString(Qt::ISODate).toLatin1(); case Never: return "never"; } Q_ASSERT( false ); return QByteArray(); // suppress control-reaches-end-of-non-void-function warning } void DispatchModeAttribute::deserialize( const QByteArray &data ) { - mDueDate = QDateTime(); + d->mDueDate = QDateTime(); if ( data == "immediately" ) { - mMode = Immediately; + d->mMode = Immediately; } else if ( data == "never" ) { - mMode = Never; + d->mMode = Never; } else if ( data.startsWith( QByteArray( "after" ) ) ) { - mMode = AfterDueDate; - mDueDate = QDateTime::fromString( data.mid(5), Qt::ISODate ); + d->mMode = AfterDueDate; + d->mDueDate = QDateTime::fromString( data.mid(5), Qt::ISODate ); // NOTE: 5 is the strlen of "after". } else { kWarning() << "Failed to deserialize data [" << data << "]"; } } DispatchModeAttribute::DispatchMode DispatchModeAttribute::dispatchMode() const { - return mMode; + return d->mMode; } void DispatchModeAttribute::setDispatchMode( DispatchMode mode ) { - mMode = mode; + d->mMode = mode; } QDateTime DispatchModeAttribute::dueDate() const { - return mDueDate; + return d->mDueDate; } void DispatchModeAttribute::setDueDate( const QDateTime &date ) { - mDueDate = date; + d->mDueDate = date; } diff --git a/outboxinterface/dispatchmodeattribute.h b/outboxinterface/dispatchmodeattribute.h index fde5536de..11161c500 100644 --- a/outboxinterface/dispatchmodeattribute.h +++ b/outboxinterface/dispatchmodeattribute.h @@ -1,101 +1,101 @@ /* Copyright 2009 Constantin Berzan This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #ifndef OUTBOXINTERFACE_DISPATCHMODEATTRIBUTE_H #define OUTBOXINTERFACE_DISPATCHMODEATTRIBUTE_H #include #include #include namespace OutboxInterface { /** Attribute determining how and when a message from the outbox should be dispatched. Messages can be sent immediately, sent only when the user explicitly requests it, or sent automatically at a certain date and time. @author Constantin Berzan @since 4.4 */ class OUTBOXINTERFACE_EXPORT DispatchModeAttribute : public Akonadi::Attribute { public: /** Determines how the message is sent. */ enum DispatchMode { Immediately, ///< Send message as soon as possible. AfterDueDate, ///< Send message at a certain date/time. Never ///< Send message only when the user requests so. }; /** Creates a new DispatchModeAttribute. */ explicit DispatchModeAttribute( DispatchMode mode = Immediately, const QDateTime &date = QDateTime() ); /** Destroys the DispatchModeAttribute. */ virtual ~DispatchModeAttribute(); /* reimpl */ virtual DispatchModeAttribute* clone() const; virtual QByteArray type() const; virtual QByteArray serialized() const; virtual void deserialize( const QByteArray &data ); /** Returns the dispatch mode for the message. @see DispatchMode. */ DispatchMode dispatchMode() const; /** Sets the dispatch mode for the message. @see DispatchMode. */ void setDispatchMode( DispatchMode mode ); /** Returns the date and time when the message should be sent. Only valid if dispatchMode() is AfterDueDate. */ QDateTime dueDate() const; /** Sets the date and time when the message should be sent. Make sure you set the DispatchMode to AfterDueDate first. @see setDispatchMode. */ void setDueDate( const QDateTime &date ); private: - DispatchMode mMode; - QDateTime mDueDate; + class Private; + Private *const d; }; } // namespace OutboxInterface #endif // OUTBOXINTERFACE_DISPATCHMODEATTRIBUTE_H diff --git a/outboxinterface/errorattribute.cpp b/outboxinterface/errorattribute.cpp index 3a7b6f397..2597541b2 100644 --- a/outboxinterface/errorattribute.cpp +++ b/outboxinterface/errorattribute.cpp @@ -1,68 +1,76 @@ /* Copyright 2009 Constantin Berzan This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include "errorattribute.h" #include #include using namespace Akonadi; using namespace OutboxInterface; +class ErrorAttribute::Private +{ + public: + QString mMessage; +}; + ErrorAttribute::ErrorAttribute( const QString &msg ) - : mMessage( msg ) + : d( new Private ) { + d->mMessage = msg; } ErrorAttribute::~ErrorAttribute() { + delete d; } ErrorAttribute* ErrorAttribute::clone() const { - return new ErrorAttribute( mMessage ); + return new ErrorAttribute( d->mMessage ); } QByteArray ErrorAttribute::type() const { static const QByteArray sType( "ErrorAttribute" ); return sType; } QByteArray ErrorAttribute::serialized() const { - return mMessage.toUtf8(); + return d->mMessage.toUtf8(); } void ErrorAttribute::deserialize( const QByteArray &data ) { - mMessage = QString::fromUtf8( data ); + d->mMessage = QString::fromUtf8( data ); } QString ErrorAttribute::message() const { - return mMessage; + return d->mMessage; } void ErrorAttribute::setMessage( const QString &msg ) { - mMessage = msg; + d->mMessage = msg; } diff --git a/outboxinterface/errorattribute.h b/outboxinterface/errorattribute.h index 912553c4c..b6310d2ed 100644 --- a/outboxinterface/errorattribute.h +++ b/outboxinterface/errorattribute.h @@ -1,74 +1,75 @@ /* Copyright 2009 Constantin Berzan This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #ifndef OUTBOXINTERFACE_ERRORATTRIBUTE_H #define OUTBOXINTERFACE_ERRORATTRIBUTE_H #include #include #include namespace OutboxInterface { /** Attribute given to the messages that failed to be sent. Contains the error message encountered. @author Constantin Berzan @since 4.4 */ class OUTBOXINTERFACE_EXPORT ErrorAttribute : public Akonadi::Attribute { public: /** Creates a new ErrorAttribute. */ ErrorAttribute( const QString &msg = QString() ); /** Destroys this ErrorAttribute. */ virtual ~ErrorAttribute(); /* reimpl */ virtual ErrorAttribute* clone() const; virtual QByteArray type() const; virtual QByteArray serialized() const; virtual void deserialize( const QByteArray &data ); /** Returns the i18n'ed error message. */ QString message() const; /** Sets the error message. */ void setMessage( const QString &msg ); private: - QString mMessage; + class Private; + Private *const d; }; } // namespace OutboxInterface #endif // OUTBOXINTERFACE_ERRORATTRIBUTE_H diff --git a/outboxinterface/sentbehaviourattribute.cpp b/outboxinterface/sentbehaviourattribute.cpp index 73026f25d..3c2726804 100644 --- a/outboxinterface/sentbehaviourattribute.cpp +++ b/outboxinterface/sentbehaviourattribute.cpp @@ -1,97 +1,106 @@ /* Copyright 2009 Constantin Berzan This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include "sentbehaviourattribute.h" #include #include using namespace Akonadi; using namespace OutboxInterface; +class SentBehaviourAttribute::Private +{ + public: + SentBehaviour mBehaviour; + Akonadi::Collection::Id mMoveToCollection; +}; + SentBehaviourAttribute::SentBehaviourAttribute( SentBehaviour beh, Collection::Id moveToCollection ) - : mBehaviour( beh ) - , mMoveToCollection( moveToCollection ) + : d( new Private ) { + d->mBehaviour = beh; + d->mMoveToCollection = moveToCollection; } SentBehaviourAttribute::~SentBehaviourAttribute() { + delete d; } SentBehaviourAttribute* SentBehaviourAttribute::clone() const { - return new SentBehaviourAttribute( mBehaviour, mMoveToCollection ); + return new SentBehaviourAttribute( d->mBehaviour, d->mMoveToCollection ); } QByteArray SentBehaviourAttribute::type() const { static const QByteArray sType( "SentBehaviourAttribute" ); return sType; } QByteArray SentBehaviourAttribute::serialized() const { - switch( mBehaviour ) { + switch( d->mBehaviour ) { case Delete: return "delete"; - case MoveToCollection: return "moveTo" + QByteArray::number( mMoveToCollection ); + case MoveToCollection: return "moveTo" + QByteArray::number( d->mMoveToCollection ); case MoveToDefaultSentCollection: return "moveToDefault"; } Q_ASSERT( false ); return QByteArray(); } void SentBehaviourAttribute::deserialize( const QByteArray &data ) { - mMoveToCollection = -1; + d->mMoveToCollection = -1; if ( data == "delete" ) { - mBehaviour = Delete; + d->mBehaviour = Delete; } else if ( data == "moveToDefault" ) { - mBehaviour = MoveToDefaultSentCollection; + d->mBehaviour = MoveToDefaultSentCollection; } else if ( data.startsWith( QByteArray( "moveTo" ) ) ) { - mBehaviour = MoveToCollection; - mMoveToCollection = data.mid(6).toLongLong(); + d->mBehaviour = MoveToCollection; + d->mMoveToCollection = data.mid(6).toLongLong(); // NOTE: 6 is the strlen of "moveTo". } else { Q_ASSERT( false ); } } SentBehaviourAttribute::SentBehaviour SentBehaviourAttribute::sentBehaviour() const { - return mBehaviour; + return d->mBehaviour; } void SentBehaviourAttribute::setSentBehaviour( SentBehaviour beh ) { - mBehaviour = beh; + d->mBehaviour = beh; } Collection::Id SentBehaviourAttribute::moveToCollection() const { - return mMoveToCollection; + return d->mMoveToCollection; } void SentBehaviourAttribute::setMoveToCollection( Collection::Id moveToCollection ) { - mMoveToCollection = moveToCollection; + d->mMoveToCollection = moveToCollection; } diff --git a/outboxinterface/sentbehaviourattribute.h b/outboxinterface/sentbehaviourattribute.h index 8d063e2bd..c2db8dcf6 100644 --- a/outboxinterface/sentbehaviourattribute.h +++ b/outboxinterface/sentbehaviourattribute.h @@ -1,101 +1,101 @@ /* Copyright 2009 Constantin Berzan This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #ifndef OUTBOXINTERFACE_SENTBEHAVIOURATTRIBUTE_H #define OUTBOXINTERFACE_SENTBEHAVIOURATTRIBUTE_H #include #include #include namespace OutboxInterface { /** Attribute determining what will happen to a message after it is sent. The message can be deleted from the Outbox, moved to the default sent-mail collection, or moved to a custom collection. @author Constantin Berzan @since 4.4 */ class OUTBOXINTERFACE_EXPORT SentBehaviourAttribute : public Akonadi::Attribute { public: /** What to do with the item in the outbox after it has been sent successfully. */ enum SentBehaviour { Delete, ///< Delete the item from the outbox. MoveToCollection, ///< Move the item to the default sent-mail collection. MoveToDefaultSentCollection ///< Move the item to a custom collection. }; /** Creates a new SentBehaviourAttribute. */ explicit SentBehaviourAttribute( SentBehaviour beh = MoveToDefaultSentCollection, Akonadi::Collection::Id moveToCollection = -1 ); /** Destroys the SentBehaviourAttribute. */ virtual ~SentBehaviourAttribute(); /* reimpl */ virtual SentBehaviourAttribute* clone() const; virtual QByteArray type() const; virtual QByteArray serialized() const; virtual void deserialize( const QByteArray &data ); /** Returns the sent-behaviour of the message. @see SentBehaviour. */ SentBehaviour sentBehaviour() const; /** Sets the sent-behaviour of the message. @see SentBehaviour. */ void setSentBehaviour( SentBehaviour beh ); /** Returns the collection to which the item should be moved after it is sent. Only valid if sentBehaviour() is MoveToCollection. */ Akonadi::Collection::Id moveToCollection() const; /** Sets the collection to which the item should be moved after it is sent. Make sure you set the SentBehaviour to MoveToCollection first. @see setSentBehaviour. */ void setMoveToCollection( Akonadi::Collection::Id moveToCollection ); private: - SentBehaviour mBehaviour; - Akonadi::Collection::Id mMoveToCollection; + class Private; + Private *const d; }; } // namespace OutboxInterface #endif // OUTBOXINTERFACE_SENTBEHAVIOURATTRIBUTE_H diff --git a/outboxinterface/tests/attributetest.cpp b/outboxinterface/tests/attributetest.cpp index 03c1ede14..5dd0577d7 100644 --- a/outboxinterface/tests/attributetest.cpp +++ b/outboxinterface/tests/attributetest.cpp @@ -1,69 +1,139 @@ /* Copyright 2009 Constantin Berzan This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include "attributetest.h" #include #include #include #include #include #include #include using namespace Akonadi; using namespace OutboxInterface; void AttributeTest::initTestCase() { } void AttributeTest::testRegistrar() { // The attributes should have been registered without any effort on our part. { Attribute *a = AttributeFactory::createAttribute( "AddressAttribute" ); QVERIFY( dynamic_cast( a ) ); } { Attribute *a = AttributeFactory::createAttribute( "DispatchModeAttribute" ); QVERIFY( dynamic_cast( a ) ); } { Attribute *a = AttributeFactory::createAttribute( "ErrorAttribute" ); QVERIFY( dynamic_cast( a ) ); } { Attribute *a = AttributeFactory::createAttribute( "SentBehaviourAttribute" ); QVERIFY( dynamic_cast( a ) ); } { Attribute *a = AttributeFactory::createAttribute( "TransportAttribute" ); QVERIFY( dynamic_cast( a ) ); } } +void AttributeTest::testSerialization() +{ + { + QString from( "from@me.org" ); + QStringList to( "to1@me.org" ); + to << "to2@me.org"; + QStringList cc( "cc1@me.org" ); + cc << "cc2@me.org"; + QStringList bcc( "bcc1@me.org" ); + bcc << "bcc2@me.org"; + AddressAttribute *a = new AddressAttribute( from, to, cc, bcc ); + QByteArray data = a->serialized(); + delete a; + a = new AddressAttribute; + a->deserialize( data ); + QCOMPARE( from, a->from() ); + QCOMPARE( to, a->to() ); + QCOMPARE( cc, a->cc() ); + QCOMPARE( bcc, a->bcc() ); + } + + { + DispatchModeAttribute::DispatchMode mode = DispatchModeAttribute::AfterDueDate; + QDateTime date = QDateTime::currentDateTime(); + // The serializer does not keep track of milliseconds, so forget them. + kDebug() << "ms" << date.toString( "z" ); + int ms = date.toString( "z" ).toInt(); + date = date.addMSecs( -ms ); + DispatchModeAttribute *a = new DispatchModeAttribute( mode, date ); + QByteArray data = a->serialized(); + delete a; + a = new DispatchModeAttribute; + a->deserialize( data ); + QCOMPARE( mode, a->dispatchMode() ); + QCOMPARE( date, a->dueDate() ); + } + + { + QString msg( "The #!@$ing thing failed!" ); + ErrorAttribute *a = new ErrorAttribute( msg ); + QByteArray data = a->serialized(); + delete a; + a = new ErrorAttribute; + a->deserialize( data ); + QCOMPARE( msg, a->message() ); + } + + { + SentBehaviourAttribute::SentBehaviour beh = SentBehaviourAttribute::MoveToCollection; + Collection::Id id = 123456789012345ll; + SentBehaviourAttribute *a = new SentBehaviourAttribute( beh, id ); + QByteArray data = a->serialized(); + delete a; + a = new SentBehaviourAttribute; + a->deserialize( data ); + QCOMPARE( beh, a->sentBehaviour() ); + QCOMPARE( id, a->moveToCollection() ); + } + + { + int id = 3219; + TransportAttribute *a = new TransportAttribute( id ); + QByteArray data = a->serialized(); + delete a; + a = new TransportAttribute; + a->deserialize( data ); + QCOMPARE( id, a->transportId() ); + } +} + QTEST_AKONADIMAIN( AttributeTest, NoGUI ) #include "attributetest.moc" diff --git a/outboxinterface/tests/attributetest.h b/outboxinterface/tests/attributetest.h index 4e345f7d2..0760b38b3 100644 --- a/outboxinterface/tests/attributetest.h +++ b/outboxinterface/tests/attributetest.h @@ -1,40 +1,39 @@ /* Copyright 2009 Constantin Berzan This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #ifndef ATTRIBUTETEST_H #define ATTRIBUTETEST_H #include /** This is a test of the various attributes. */ class AttributeTest : public QObject { Q_OBJECT private Q_SLOTS: void initTestCase(); void testRegistrar(); - - // TODO test serialization / deserialization + void testSerialization(); }; #endif diff --git a/outboxinterface/transportattribute.cpp b/outboxinterface/transportattribute.cpp index da2e28022..8ea2cbdd1 100644 --- a/outboxinterface/transportattribute.cpp +++ b/outboxinterface/transportattribute.cpp @@ -1,74 +1,82 @@ /* Copyright 2009 Constantin Berzan This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include "transportattribute.h" #include #include "mailtransport/transportmanager.h" using namespace Akonadi; using namespace MailTransport; using namespace OutboxInterface; +class TransportAttribute::Private +{ + public: + int mId; +}; + TransportAttribute::TransportAttribute( int id ) - : mId( id ) + : d( new Private ) { + d->mId = id; } TransportAttribute::~TransportAttribute() { + delete d; } TransportAttribute* TransportAttribute::clone() const { - return new TransportAttribute( mId ); + return new TransportAttribute( d->mId ); } QByteArray TransportAttribute::type() const { static const QByteArray sType( "TransportAttribute" ); return sType; } QByteArray TransportAttribute::serialized() const { - return QByteArray::number( mId ); + return QByteArray::number( d->mId ); } void TransportAttribute::deserialize( const QByteArray &data ) { - mId = data.toInt(); + d->mId = data.toInt(); } int TransportAttribute::transportId() const { - return mId; + return d->mId; } Transport* TransportAttribute::transport() const { - return TransportManager::self()->transportById( mId, false ); + return TransportManager::self()->transportById( d->mId, false ); } void TransportAttribute::setTransportId( int id ) { - mId = id; + d->mId = id; } diff --git a/outboxinterface/transportattribute.h b/outboxinterface/transportattribute.h index 4c39d63ba..0f16fdd67 100644 --- a/outboxinterface/transportattribute.h +++ b/outboxinterface/transportattribute.h @@ -1,86 +1,87 @@ /* Copyright 2009 Constantin Berzan This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #ifndef OUTBOXINTERFACE_TRANSPORTATTRIBUTE_H #define OUTBOXINTERFACE_TRANSPORTATTRIBUTE_H #include #include namespace MailTransport { class Transport; } namespace OutboxInterface { /** Attribute determining which transport to use for sending a message. @see mailtransport @see TransportManager. @author Constantin Berzan @since 4.4 */ class OUTBOXINTERFACE_EXPORT TransportAttribute : public Akonadi::Attribute { public: /** Creates a new TransportAttribute. */ TransportAttribute( int id = -1 ); /** Destroys this TransportAttribute. */ virtual ~TransportAttribute(); /* reimpl */ virtual TransportAttribute* clone() const; virtual QByteArray type() const; virtual QByteArray serialized() const; virtual void deserialize( const QByteArray &data ); /** Returns the transport id to use for sending this message. @see TransportManager. */ int transportId() const; /** Returns the transport object corresponding to the transport id contained in this attribute. @see Transport. */ MailTransport::Transport* transport() const; /** Sets the transport id to use for sending this message. */ void setTransportId( int id ); private: - int mId; + class Private; + Private *const d; }; } // namespace OutboxInterface #endif // OUTBOXINTERFACE_TRANSPORTATTRIBUTE_H