|
1 /* |
|
2 * Copyright (c) 2009 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 * |
|
16 */ |
|
17 |
|
18 #include "nmuiengineheaders.h" |
|
19 |
|
20 /*! |
|
21 \class NmDataManager |
|
22 \brief The NmDataManager class provides access to abstract list models and meta data for |
|
23 mailboxes, folders and messages. If the dataplugin can't be loaded, fatal assert is called. |
|
24 |
|
25 */ |
|
26 |
|
27 /*! |
|
28 Constructor |
|
29 */ |
|
30 NmDataManager::NmDataManager() |
|
31 :mFactory(NULL) |
|
32 { |
|
33 mFactory = NmDataPluginFactory::instance(); |
|
34 } |
|
35 |
|
36 /*! |
|
37 Destructor |
|
38 */ |
|
39 NmDataManager::~NmDataManager() |
|
40 { |
|
41 NmDataPluginFactory::releaseInstance(mFactory); |
|
42 } |
|
43 |
|
44 /*! |
|
45 list mailbox ids in \a mailboxIdList array |
|
46 */ |
|
47 void NmDataManager::listMailboxIds(QList<NmId> &mailboxIdList) |
|
48 { |
|
49 int count(mFactory->pluginInstances()->count()); |
|
50 for (int i(0); i < count; i++) { |
|
51 NmDataPluginInterface *instance = |
|
52 mFactory->interfaceInstance(mFactory->pluginInstances()->at(i)); |
|
53 if (instance) { |
|
54 instance->listMailboxIds(mailboxIdList); |
|
55 } |
|
56 } |
|
57 } |
|
58 |
|
59 /*! |
|
60 Creates mailbox instances and fill \a mailboxList array, |
|
61 caller is responsible deletion of objects in the array |
|
62 */ |
|
63 void NmDataManager::listMailboxes(QList<NmMailbox*> &mailboxList) |
|
64 { |
|
65 int count = mFactory->pluginInstances()->count(); |
|
66 for (int i(0); i < count; i++) { |
|
67 NmDataPluginInterface *instance = |
|
68 mFactory->interfaceInstance(mFactory->pluginInstances()->at(i)); |
|
69 if (instance) { |
|
70 instance->listMailboxes(mailboxList); |
|
71 } |
|
72 } |
|
73 } |
|
74 |
|
75 /*! |
|
76 Creates folder instances from mailbox folder, Mailbox is identified with |
|
77 \a mailboxId Function fills \a folderList array, |
|
78 caller is responsible deletion of objects in the array |
|
79 */ |
|
80 void NmDataManager::listFolders(const NmId mailboxId, QList<NmFolder*> &folderList) |
|
81 { |
|
82 NmDataPluginInterface *instance = mFactory->interfaceInstance(mailboxId); |
|
83 if (instance) { |
|
84 instance->listFolders(mailboxId, folderList); |
|
85 } |
|
86 } |
|
87 |
|
88 /*! |
|
89 Creates message instances under folder which id is \a folderId |
|
90 Function fills \a messageList array, caller is responsible deletion of |
|
91 instances in the array |
|
92 */ |
|
93 void NmDataManager::listMessages( |
|
94 const NmId &mailboxId, |
|
95 const NmId &folderId, |
|
96 QList<NmMessageEnvelope*> &messageEnvelopeList) |
|
97 { |
|
98 NmDataPluginInterface *instance = mFactory->interfaceInstance(folderId); |
|
99 if (instance) { |
|
100 instance->listMessages(mailboxId, folderId, messageEnvelopeList); |
|
101 } |
|
102 } |
|
103 |
|
104 /*! |
|
105 Returns folder meta data from mailbox which id is \a mailboxId. |
|
106 Ownership of NmFolderMetaData is transferred. NULL pointer is |
|
107 returned if folder by id is not found |
|
108 */ |
|
109 NmFolderMetaData *NmDataManager::folderById( |
|
110 const NmId &mailboxId, |
|
111 const NmId &folderId) |
|
112 { |
|
113 NMLOG("nmuiengine: getFolderById"); |
|
114 NmFolderMetaData *folderMetaData(NULL); |
|
115 QList<NmFolder*> folderList; |
|
116 listFolders(mailboxId, folderList); |
|
117 const int folderListCount(folderList.count()); |
|
118 for (int i(0); i < folderListCount; i++) { |
|
119 if (folderList[i]->folderId() == folderId) { |
|
120 // Folder by id found, fill in new metadata |
|
121 folderMetaData = new NmFolderMetaData(); |
|
122 folderMetaData->setId(folderList[i]->folderId()); |
|
123 folderMetaData->setName(folderList[i]->name()); |
|
124 break; |
|
125 } |
|
126 } |
|
127 folderList.clear(); |
|
128 return folderMetaData; |
|
129 } |
|
130 |
|
131 /*! |
|
132 Returns mailbox meta data. Ownership of NmMailboxMetaData is transferred. |
|
133 NULL pointer is returned if mailbox by id is not found |
|
134 */ |
|
135 NmMailboxMetaData *NmDataManager::mailboxById(const NmId &mailboxId) |
|
136 { |
|
137 NMLOG("nmuiengine: getMailboxById"); |
|
138 NmMailboxMetaData *mailboxMetaData(NULL); |
|
139 NmMailbox* mbox = mailbox(mailboxId); |
|
140 |
|
141 if (mbox) { |
|
142 mailboxMetaData = new NmMailboxMetaData(); |
|
143 mailboxMetaData->setId(mbox->id()); |
|
144 mailboxMetaData->setName(mbox->name()); |
|
145 // Icon id should be set also |
|
146 } |
|
147 delete mbox; |
|
148 mbox = NULL; |
|
149 return mailboxMetaData; |
|
150 } |
|
151 |
|
152 |
|
153 /*! |
|
154 Get new NmMessageEnvelope object by id \a messageId from any folder. |
|
155 Ownership is transferred to the caller. NULL pointer is returned if |
|
156 message id is not found. |
|
157 */ |
|
158 NmMessageEnvelope *NmDataManager::envelopeById( |
|
159 const NmId &mailboxId, |
|
160 const NmId &folderId, |
|
161 const NmId &messageId) |
|
162 { |
|
163 NMLOG("nmuiengine: getMessageById"); |
|
164 |
|
165 NmMessageEnvelope *msgEnvelope(NULL); |
|
166 NmMessage* msg = message(mailboxId, folderId, messageId); |
|
167 |
|
168 if (msg) { |
|
169 msgEnvelope = new NmMessageEnvelope(msg->envelope()); |
|
170 } |
|
171 delete msg; |
|
172 msg = NULL; |
|
173 return msgEnvelope; |
|
174 } |
|
175 |
|
176 /*! |
|
177 Get new NmMailbox object by id. Ownership is transferred to the caller. |
|
178 NULL pointer is returned if message id is not found from plugin. |
|
179 */ |
|
180 NmMailbox *NmDataManager::mailbox(const NmId &mailboxId) |
|
181 { |
|
182 NmMailbox *newMailboxObject(NULL); |
|
183 NmDataPluginInterface *instance = mFactory->interfaceInstance(mailboxId); |
|
184 int retVal(NmNotFoundError); |
|
185 |
|
186 if (instance) { |
|
187 retVal = instance->getMailboxById(mailboxId, newMailboxObject); |
|
188 } |
|
189 |
|
190 if (retVal < NmNoError) { |
|
191 delete newMailboxObject; |
|
192 newMailboxObject = NULL; |
|
193 } |
|
194 |
|
195 return newMailboxObject; |
|
196 } |
|
197 |
|
198 /*! |
|
199 Get new NmFolder object by id. Ownership is transferred to the caller. |
|
200 NULL pointer is returned if message id is not found from plugin. |
|
201 */ |
|
202 NmFolder *NmDataManager::folder( |
|
203 const NmId &mailboxId, |
|
204 const NmId &folderId) |
|
205 { |
|
206 NmFolder* newFolderObject(NULL); |
|
207 QList<NmFolder*> folderList; |
|
208 listFolders(mailboxId, folderList); |
|
209 for (int i(0); i < folderList.count(); i++) { |
|
210 if (folderList[i]->folderId() == folderId) { |
|
211 newFolderObject = new NmFolder(*folderList[i]); |
|
212 break; |
|
213 } |
|
214 } |
|
215 folderList.clear(); |
|
216 return newFolderObject; |
|
217 } |
|
218 |
|
219 /*! |
|
220 Get new NmMessage object by id from any folder. |
|
221 Ownership is transferred to the caller. NULL pointer is returned if |
|
222 message id is not found from plugin. |
|
223 */ |
|
224 NmMessage *NmDataManager::message( |
|
225 const NmId &mailboxId, |
|
226 const NmId &folderId, |
|
227 const NmId &messageId) |
|
228 { |
|
229 NmMessage *newMessageObject(NULL); |
|
230 NmDataPluginInterface *instance = mFactory->interfaceInstance(mailboxId); |
|
231 |
|
232 int retVal(NmNotFoundError); |
|
233 if (instance) { |
|
234 retVal = instance-> |
|
235 getMessageById(mailboxId, folderId, messageId, newMessageObject); |
|
236 } |
|
237 |
|
238 if (retVal < NmNoError) { |
|
239 // Return null object if fetching failed |
|
240 delete newMessageObject; |
|
241 newMessageObject = NULL; |
|
242 } |
|
243 return newMessageObject; |
|
244 } |
|
245 |
|
246 /*! |
|
247 Get content to message part. Parameter messagePart must |
|
248 contain messagePartId. |
|
249 */ |
|
250 int NmDataManager::contentToMessagePart( |
|
251 const NmId &mailboxId, |
|
252 const NmId &folderId, |
|
253 const NmId &messageId, |
|
254 NmMessagePart &messagePart) |
|
255 { |
|
256 int retVal(NmNotFoundError); |
|
257 NmDataPluginInterface *instance = mFactory->interfaceInstance(mailboxId); |
|
258 if (instance) { |
|
259 retVal = |
|
260 instance->contentToMessagePart(mailboxId, folderId, messageId, messagePart); |
|
261 } |
|
262 return retVal; |
|
263 } |
|
264 |
|
265 /*! |
|
266 Function for getting standard folder id from plugin |
|
267 */ |
|
268 NmId NmDataManager::getStandardFolderId( |
|
269 const NmId &mailboxId, |
|
270 NmFolderType folderType ) |
|
271 { |
|
272 NmId folderId; |
|
273 NmDataPluginInterface *instance = mFactory->interfaceInstance(mailboxId); |
|
274 if (instance) { |
|
275 folderId = |
|
276 instance->getStandardFolderId(mailboxId, folderType); |
|
277 } |
|
278 return folderId; |
|
279 } |
|
280 |
|
281 |
|
282 |