|
1 /* |
|
2 * Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: |
|
15 * Email message related operations |
|
16 */ |
|
17 |
|
18 #include "nmapiheaders.h" |
|
19 |
|
20 |
|
21 namespace EmailClientApi |
|
22 { |
|
23 |
|
24 NmApiMessageManagerPrivate::NmApiMessageManagerPrivate(quint64 mailboxId,QObject *parent) |
|
25 : QObject(parent), |
|
26 mState(NmApiMessageManagerPrivate::EIdle), mMailboxId(mailboxId) |
|
27 { |
|
28 NM_FUNCTION; |
|
29 |
|
30 mFactory = NmApiDataPluginFactory::instance(); |
|
31 mPlugin = mFactory->plugin(); |
|
32 if(mPlugin) { |
|
33 connect(mPlugin, |
|
34 SIGNAL(messageEvent(NmMessageEvent, |
|
35 const NmId&, |
|
36 const QList<NmId>&, |
|
37 const NmId&)), |
|
38 this, |
|
39 SLOT(messageEventHandler(NmMessageEvent, |
|
40 const NmId&, |
|
41 const QList<NmId>&, |
|
42 const NmId&))); |
|
43 } |
|
44 NmDataPluginInterface *interface = mFactory->interfaceInstance(); |
|
45 interface->subscribeMailboxEvents(mailboxId); |
|
46 |
|
47 } |
|
48 |
|
49 NmApiMessageManagerPrivate::~NmApiMessageManagerPrivate() |
|
50 { |
|
51 NM_FUNCTION; |
|
52 NmDataPluginInterface *interface = mFactory->interfaceInstance(); |
|
53 interface->unsubscribeMailboxEvents(mMailboxId); |
|
54 NmApiDataPluginFactory::releaseInstance(mFactory); |
|
55 } |
|
56 |
|
57 /*! |
|
58 \fn moveMessages |
|
59 \param messageIds Id list of source messages. |
|
60 \param sourceFolderId Id of the source folder. |
|
61 \param targetFolderId Id of the target folder. |
|
62 \return true if operation was successfully started. |
|
63 |
|
64 Starts async move operation for given messages. |
|
65 Completion signalled with messagesMoved(int result). |
|
66 */ |
|
67 bool NmApiMessageManagerPrivate::moveMessages(const QList<quint64> messageIds, |
|
68 quint64 sourceFolder, |
|
69 quint64 targetFolder) |
|
70 { |
|
71 NM_FUNCTION; |
|
72 Q_UNUSED(messageIds); |
|
73 Q_UNUSED(sourceFolder); |
|
74 Q_UNUSED(targetFolder); |
|
75 return false; |
|
76 } |
|
77 |
|
78 /*! |
|
79 \fn copyMessages |
|
80 \param messageIds Id list of source messages. |
|
81 \param sourceFolder Id of the source folder. |
|
82 \param targetFolder Id of the target folder. |
|
83 \return true if operation was successfully started. |
|
84 |
|
85 Starts async copy operation for given messages. |
|
86 Completion signalled with messagesCopied(int result). |
|
87 */ |
|
88 bool NmApiMessageManagerPrivate::copyMessages(const QList<quint64> messageIds, |
|
89 const quint64 sourceFolder, |
|
90 const quint64 targetFolder) |
|
91 { |
|
92 NM_FUNCTION; |
|
93 bool ret = false; |
|
94 NmId targetFolderNmId(targetFolder); |
|
95 NmId sourceFolderNmId(sourceFolder); |
|
96 mTarget = targetFolderNmId; |
|
97 mMessages = messageIds; |
|
98 |
|
99 NmDataPluginInterface *interface = mFactory->interfaceInstance(); |
|
100 |
|
101 if (interface) { |
|
102 mState = NmApiMessageManagerPrivate::ECopyPending; |
|
103 if (interface->copyMessages(mMailboxId, |
|
104 messageIds, |
|
105 sourceFolderNmId, |
|
106 targetFolderNmId)==0) { |
|
107 ret = true; |
|
108 } |
|
109 } |
|
110 mState = NmApiMessageManagerPrivate::EIdle; |
|
111 return ret; |
|
112 } |
|
113 |
|
114 /*! |
|
115 \fn messageEventHandler |
|
116 \param event Event type. |
|
117 \param folder Folder id. |
|
118 \param messages Id list of messages involved. |
|
119 \param mailBox Id of mailbox. |
|
120 |
|
121 Handler for plugin originated messageEvent. |
|
122 */ |
|
123 void NmApiMessageManagerPrivate::messageEventHandler(NmMessageEvent event, |
|
124 const NmId &folder, |
|
125 const QList<NmId> &messages, |
|
126 const NmId &mailBox) |
|
127 { |
|
128 if(mMailboxId == mailBox && |
|
129 mTarget == folder) { |
|
130 switch(event) |
|
131 { |
|
132 case NmMessageCreated: { |
|
133 if (mState==NmApiMessageManagerPrivate::ECopyPending) { |
|
134 if(messages.count()==mMessages.count()) { |
|
135 emit messagesCopied(0); |
|
136 } |
|
137 else { |
|
138 emit messagesCopied(-1); |
|
139 } |
|
140 } |
|
141 break; |
|
142 } |
|
143 |
|
144 case NmMessageChanged: { |
|
145 break; |
|
146 } |
|
147 |
|
148 case NmMessageDeleted: { |
|
149 break; |
|
150 } |
|
151 |
|
152 case NmMessageFound: { |
|
153 break; |
|
154 } |
|
155 |
|
156 default: { |
|
157 break; |
|
158 } |
|
159 } |
|
160 mState = NmApiMessageManagerPrivate::EIdle; |
|
161 } |
|
162 } |
|
163 } //namespace |
|
164 |
|
165 |