1 | /* |
2 | Copyright 2009 Constantin Berzan <exit3219@gmail.com> |
3 | |
4 | This library is free software; you can redistribute it and/or modify it |
5 | under the terms of the GNU Library General Public License as published by |
6 | the Free Software Foundation; either version 2 of the License, or (at your |
7 | option) any later version. |
8 | |
9 | This library is distributed in the hope that it will be useful, but WITHOUT |
10 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
11 | FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public |
12 | License for more details. |
13 | |
14 | You should have received a copy of the GNU Library General Public License |
15 | along with this library; see the file COPYING.LIB. If not, write to the |
16 | Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA |
17 | 02110-1301, USA. |
18 | */ |
19 | |
20 | #include "sentbehaviourattribute.h" |
21 | |
22 | |
23 | #include <KDebug> |
24 | |
25 | using namespace Akonadi; |
26 | using namespace MailTransport; |
27 | |
28 | class SentBehaviourAttribute::Private |
29 | { |
30 | public: |
31 | SentBehaviour mBehaviour; |
32 | Akonadi::Collection mMoveToCollection; |
33 | }; |
34 | |
35 | SentBehaviourAttribute::SentBehaviourAttribute( SentBehaviour beh, Collection moveToCollection ) |
36 | : d( new Private ) |
37 | { |
38 | d->mBehaviour = beh; |
39 | d->mMoveToCollection = moveToCollection; |
40 | } |
41 | |
42 | SentBehaviourAttribute::~SentBehaviourAttribute() |
43 | { |
44 | delete d; |
45 | } |
46 | |
47 | SentBehaviourAttribute *SentBehaviourAttribute::clone() const |
48 | { |
49 | return new SentBehaviourAttribute( d->mBehaviour, d->mMoveToCollection ); |
50 | } |
51 | |
52 | QByteArray SentBehaviourAttribute::type() const |
53 | { |
54 | static const QByteArray sType( "SentBehaviourAttribute" ); |
55 | return sType; |
56 | } |
57 | |
58 | QByteArray SentBehaviourAttribute::serialized() const |
59 | { |
60 | switch ( d->mBehaviour ) { |
61 | case Delete: return "delete" ; |
62 | case MoveToCollection: return "moveTo" + QByteArray::number( d->mMoveToCollection.id() ); |
63 | case MoveToDefaultSentCollection: return "moveToDefault" ; |
64 | } |
65 | |
66 | Q_ASSERT( false ); |
67 | return QByteArray(); |
68 | } |
69 | |
70 | void SentBehaviourAttribute::deserialize( const QByteArray &data ) |
71 | { |
72 | d->mMoveToCollection = Akonadi::Collection( -1 ); |
73 | if ( data == "delete" ) { |
74 | d->mBehaviour = Delete; |
75 | } else if ( data == "moveToDefault" ) { |
76 | d->mBehaviour = MoveToDefaultSentCollection; |
77 | } else if ( data.startsWith( QByteArray( "moveTo" ) ) ) { |
78 | d->mBehaviour = MoveToCollection; |
79 | d->mMoveToCollection = Akonadi::Collection( data.mid( 6 ).toLongLong() ); |
80 | // NOTE: 6 is the strlen of "moveTo". |
81 | } else { |
82 | Q_ASSERT( false ); |
83 | } |
84 | } |
85 | |
86 | SentBehaviourAttribute::SentBehaviour SentBehaviourAttribute::sentBehaviour() const |
87 | { |
88 | return d->mBehaviour; |
89 | } |
90 | |
91 | void SentBehaviourAttribute::setSentBehaviour( SentBehaviour beh ) |
92 | { |
93 | d->mBehaviour = beh; |
94 | } |
95 | |
96 | Collection SentBehaviourAttribute::moveToCollection() const |
97 | { |
98 | return d->mMoveToCollection; |
99 | } |
100 | |
101 | void SentBehaviourAttribute::setMoveToCollection( Collection moveToCollection ) |
102 | { |
103 | d->mMoveToCollection = moveToCollection; |
104 | } |
105 | |
106 | |