52 public: |
53 public: |
53 QMessageStorePrivatePlatform(QMessageStorePrivate *d, QMessageStore *q) |
54 QMessageStorePrivatePlatform(QMessageStorePrivate *d, QMessageStore *q) |
54 :d_ptr(d), q_ptr(q) {} |
55 :d_ptr(d), q_ptr(q) {} |
55 QMessageStorePrivate *d_ptr; |
56 QMessageStorePrivate *d_ptr; |
56 QMessageStore *q_ptr; |
57 QMessageStore *q_ptr; |
57 //... |
58 EventLoggerEngine *el; |
58 }; |
59 }; |
59 |
60 |
60 QMessageStorePrivate::QMessageStorePrivate() |
61 QMessageStorePrivate::QMessageStorePrivate() |
61 :q_ptr(0), |
62 :q_ptr(0), |
62 p_ptr(0) |
63 p_ptr(0) |
63 { |
64 { |
|
65 |
64 } |
66 } |
65 |
67 |
66 QMessageStorePrivate::~QMessageStorePrivate() |
68 QMessageStorePrivate::~QMessageStorePrivate() |
67 { |
69 { |
68 } |
70 } |
69 |
71 |
70 void QMessageStorePrivate::initialize(QMessageStore *store) |
72 void QMessageStorePrivate::initialize(QMessageStore *store) |
71 { |
73 { |
72 q_ptr = store; |
74 q_ptr = store; |
73 p_ptr = new QMessageStorePrivatePlatform(this, store); |
75 p_ptr = new QMessageStorePrivatePlatform(this, store); |
74 } |
76 p_ptr->el= EventLoggerEngine::instance(); |
|
77 } |
|
78 |
|
79 void QMessageStorePrivate::messageNotification(QMessageStorePrivate::NotificationType type, const QMessageId& id, |
|
80 const QMessageManager::NotificationFilterIdSet &matchingFilters) |
|
81 { |
|
82 switch (type) { |
|
83 case Added: |
|
84 emit q_ptr->messageAdded(id, matchingFilters); |
|
85 break; |
|
86 case Updated: |
|
87 emit q_ptr->messageUpdated(id, matchingFilters); |
|
88 break; |
|
89 case Removed: |
|
90 emit q_ptr->messageRemoved(id, matchingFilters); |
|
91 break; |
|
92 } |
|
93 } |
|
94 |
75 |
95 |
76 Q_GLOBAL_STATIC(QMessageStorePrivate,data); |
96 Q_GLOBAL_STATIC(QMessageStorePrivate,data); |
77 |
97 |
78 QMessageStore::QMessageStore(QObject *parent) |
98 QMessageStore::QMessageStore(QObject *parent) |
79 : QObject(parent), |
99 : QObject(parent), |
80 d_ptr(data()) |
100 d_ptr(data()) |
81 { |
101 { |
82 Q_ASSERT(d_ptr != 0); |
102 Q_ASSERT(d_ptr != 0); |
83 Q_ASSERT(d_ptr->q_ptr == 0); // QMessageStore should be singleton |
103 Q_ASSERT(d_ptr->q_ptr == 0); // QMessageStore should be singleton |
84 d_ptr->initialize(this); |
104 // d_ptr->initialize(this); |
|
105 // be sure that singletons are initialized |
|
106 EventLoggerEngine::instance(); |
|
107 TelepathyEngine::instance(); |
85 } |
108 } |
86 |
109 |
87 QMessageStore::~QMessageStore() |
110 QMessageStore::~QMessageStore() |
88 { |
111 { |
89 d_ptr = 0; // should be cleaned up by automatically |
112 d_ptr = 0; // should be cleaned up by automatically |
103 return QMessageManager::NoError; |
126 return QMessageManager::NoError; |
104 } |
127 } |
105 |
128 |
106 QMessageIdList QMessageStore::queryMessages(const QMessageFilter &filter, const QMessageSortOrder &sortOrder, uint limit, uint offset) const |
129 QMessageIdList QMessageStore::queryMessages(const QMessageFilter &filter, const QMessageSortOrder &sortOrder, uint limit, uint offset) const |
107 { |
130 { |
108 Q_UNUSED(filter) |
131 QMessageIdList messageIds; |
109 Q_UNUSED(sortOrder) |
132 |
110 Q_UNUSED(limit) |
133 bool isFiltered = false; |
111 Q_UNUSED(offset) |
134 bool isSorted = false; |
112 return QMessageIdList(); // stub |
135 |
|
136 messageIds = ModestEngine::instance()->queryMessagesSync(filter, sortOrder, limit, offset, |
|
137 isFiltered, isSorted); |
|
138 |
|
139 // messageIds += d_ptr->p_ptr->el->filterAndOrderMessages(filter,sortOrder,QString(),QMessageDataComparator::MatchFlags()); |
|
140 messageIds += EventLoggerEngine::instance()->filterAndOrderMessages(filter,sortOrder,QString(),QMessageDataComparator::MatchFlags()); |
|
141 |
|
142 if (!isFiltered) { |
|
143 MessagingHelper::filterMessages(messageIds, filter); |
|
144 } |
|
145 if (!isSorted) { |
|
146 MessagingHelper::orderMessages(messageIds, sortOrder); |
|
147 } |
|
148 MessagingHelper::applyOffsetAndLimitToMessageIdList(messageIds, limit, offset); |
|
149 |
|
150 return messageIds; |
113 } |
151 } |
114 |
152 |
115 QMessageIdList QMessageStore::queryMessages(const QMessageFilter &filter, const QString &body, QMessageDataComparator::MatchFlags matchFlags, const QMessageSortOrder &sortOrder, uint limit, uint offset) const |
153 QMessageIdList QMessageStore::queryMessages(const QMessageFilter &filter, const QString &body, QMessageDataComparator::MatchFlags matchFlags, const QMessageSortOrder &sortOrder, uint limit, uint offset) const |
116 { |
154 { |
117 Q_UNUSED(filter) |
155 QMessageIdList messageIds; |
118 Q_UNUSED(sortOrder) |
156 |
119 Q_UNUSED(body) |
157 bool isFiltered = false; |
120 Q_UNUSED(matchFlags) |
158 bool isSorted = false; |
121 Q_UNUSED(limit) |
159 messageIds = ModestEngine::instance()->queryMessagesSync(filter, body, matchFlags, sortOrder, limit, offset, |
122 Q_UNUSED(offset) |
160 isFiltered, isSorted); |
123 return QMessageIdList(); // stub |
161 // messageIds +=d_ptr->p_ptr->el->filterAndOrderMessages(filter,sortOrder,body,matchFlags); |
|
162 messageIds +=EventLoggerEngine::instance()->filterAndOrderMessages(filter,sortOrder,body,matchFlags); |
|
163 |
|
164 if (!isFiltered) { |
|
165 MessagingHelper::filterMessages(messageIds, filter); |
|
166 } |
|
167 if (!isSorted) { |
|
168 MessagingHelper::orderMessages(messageIds, sortOrder); |
|
169 } |
|
170 MessagingHelper::applyOffsetAndLimitToMessageIdList(messageIds, limit, offset); |
|
171 |
|
172 return messageIds; |
124 } |
173 } |
125 |
174 |
126 QMessageFolderIdList QMessageStore::queryFolders(const QMessageFolderFilter &filter, const QMessageFolderSortOrder &sortOrder, uint limit, uint offset) const |
175 QMessageFolderIdList QMessageStore::queryFolders(const QMessageFolderFilter &filter, const QMessageFolderSortOrder &sortOrder, uint limit, uint offset) const |
127 { |
176 { |
128 Q_UNUSED(filter) |
177 QMessageFolderIdList folderIds; |
129 Q_UNUSED(sortOrder) |
178 |
130 Q_UNUSED(limit) |
179 bool isFiltered = false; |
131 Q_UNUSED(offset) |
180 bool isSorted = false; |
132 return QMessageFolderIdList(); // stub |
181 folderIds = ModestEngine::instance()->queryFolders(filter, sortOrder, limit, offset, isFiltered, isSorted); |
|
182 if (!isFiltered) { |
|
183 MessagingHelper::filterFolders(folderIds, filter); |
|
184 } |
|
185 if (!isSorted) { |
|
186 MessagingHelper::orderFolders(folderIds, sortOrder); |
|
187 } |
|
188 MessagingHelper::applyOffsetAndLimitToFolderIdList(folderIds, limit, offset); |
|
189 |
|
190 return folderIds; |
133 } |
191 } |
134 |
192 |
135 QMessageAccountIdList QMessageStore::queryAccounts(const QMessageAccountFilter &filter, const QMessageAccountSortOrder &sortOrder, uint limit, uint offset) const |
193 QMessageAccountIdList QMessageStore::queryAccounts(const QMessageAccountFilter &filter, const QMessageAccountSortOrder &sortOrder, uint limit, uint offset) const |
136 { |
194 { |
137 QMessageAccountIdList accountIds; |
195 QMessageAccountIdList accountIds; |
175 return count; |
239 return count; |
176 } |
240 } |
177 |
241 |
178 bool QMessageStore::removeMessage(const QMessageId& id, QMessageManager::RemovalOption option) |
242 bool QMessageStore::removeMessage(const QMessageId& id, QMessageManager::RemovalOption option) |
179 { |
243 { |
180 Q_UNUSED(id) |
244 if (id.toString().startsWith("MO_")) { |
181 Q_UNUSED(option) |
245 return ModestEngine::instance()->removeMessage(id, option); |
182 return false; // stub |
246 } |
|
247 return EventLoggerEngine::instance()->deleteMessage(id); |
183 } |
248 } |
184 |
249 |
185 bool QMessageStore::removeMessages(const QMessageFilter& filter, QMessageManager::RemovalOption option) |
250 bool QMessageStore::removeMessages(const QMessageFilter& filter, QMessageManager::RemovalOption option) |
186 { |
251 { |
187 Q_UNUSED(filter) |
252 QMessageIdList ids = queryMessages(filter, QMessageSortOrder(), 0, 0); |
188 Q_UNUSED(option) |
253 |
189 return true; // stub |
254 for (int i=0; i < ids.count(); i++) { |
|
255 if (ids[i].toString().startsWith("MO_")) { |
|
256 if (!ModestEngine::instance()->removeMessage(ids[i], option)) { |
|
257 return false; |
|
258 } |
|
259 } else |
|
260 if(!EventLoggerEngine::instance()->deleteMessage(ids[i])) |
|
261 return false; |
|
262 } |
|
263 return true; |
190 } |
264 } |
191 |
265 |
192 bool QMessageStore::addMessage(QMessage *m) |
266 bool QMessageStore::addMessage(QMessage *m) |
193 { |
267 { |
194 Q_UNUSED(m) |
268 bool retVal = true; |
195 return true; // stub |
269 |
|
270 QMessageAccountId accountId = m->parentAccountId(); |
|
271 QMessage::Type msgType = QMessage::NoType; |
|
272 |
|
273 // Check message type |
|
274 if (m->type() == QMessage::AnyType || m->type() == QMessage::NoType) { |
|
275 if (accountId.isValid()) { |
|
276 // ParentAccountId was defined => Message type can be read |
|
277 // from parent account |
|
278 QMessageAccount account = QMessageAccount(accountId); |
|
279 QMessage::TypeFlags types = account.messageTypes(); |
|
280 if (types & QMessage::Sms) { |
|
281 msgType = QMessage::Sms; |
|
282 } else if (account.messageTypes() & QMessage::InstantMessage) { |
|
283 msgType = QMessage::InstantMessage; |
|
284 } else if (types & QMessage::Mms) { |
|
285 msgType = QMessage::Mms; |
|
286 } else if (types & QMessage::Email) { |
|
287 msgType = QMessage::Email; |
|
288 } |
|
289 } |
|
290 if (msgType == QMessage::NoType) { |
|
291 retVal = false; |
|
292 } |
|
293 } |
|
294 |
|
295 if (retVal) { |
|
296 // Check account |
|
297 if (!accountId.isValid()) { |
|
298 accountId = QMessageAccount::defaultAccount(m->type()); |
|
299 if (!accountId.isValid()) { |
|
300 retVal = false; |
|
301 } |
|
302 } |
|
303 } |
|
304 |
|
305 QMessageAccount account(accountId); |
|
306 if (retVal) { |
|
307 // Check account/message type compatibility |
|
308 if (!(account.messageTypes() & m->type()) && (msgType == QMessage::NoType)) { |
|
309 retVal = false; |
|
310 } |
|
311 } |
|
312 |
|
313 if (retVal) { |
|
314 // Set default account if unset |
|
315 if (!m->parentAccountId().isValid()) { |
|
316 m->setParentAccountId(accountId); |
|
317 } |
|
318 |
|
319 if (account.messageTypes() & QMessage::Sms) { |
|
320 retVal = false; //TODO: |
|
321 qWarning() << "QMessageManager::add not yet implemented for SMS"; |
|
322 } else if (account.messageTypes() & QMessage::InstantMessage) { |
|
323 retVal = false; //TODO: |
|
324 qWarning() << "QMessageManager::add not yet implemented for Instant Message"; |
|
325 } else if (account.messageTypes() & QMessage::Mms) { |
|
326 retVal = false; //TODO: |
|
327 qWarning() << "QMessageManager::add not yet implemented for MMS"; |
|
328 } else if (account.messageTypes() & QMessage::Email) { |
|
329 retVal = ModestEngine::instance()->addMessage(*m); |
|
330 } |
|
331 } |
|
332 |
|
333 return retVal; |
196 } |
334 } |
197 |
335 |
198 bool QMessageStore::updateMessage(QMessage *m) |
336 bool QMessageStore::updateMessage(QMessage *m) |
199 { |
337 { |
200 Q_UNUSED(m) |
338 bool retVal = false; |
201 return true; // stub |
339 |
|
340 if (m->type() == QMessage::Sms) { |
|
341 retVal = false; //TODO: |
|
342 qWarning() << "QMessageManager::update not yet implemented for SMS"; |
|
343 } else if (m->type() == QMessage::InstantMessage) { |
|
344 retVal = false; //TODO: |
|
345 qWarning() << "QMessageManager::update not yet implemented for Instant Message"; |
|
346 } else if (m->type() == QMessage::Mms) { |
|
347 retVal = false; //TODO: |
|
348 qWarning() << "QMessageManager::update not yet implemented for Instant MMS"; |
|
349 } else if (m->type() == QMessage::Email) { |
|
350 retVal = ModestEngine::instance()->updateMessage(*m); |
|
351 } |
|
352 |
|
353 return retVal; |
202 } |
354 } |
203 |
355 |
204 QMessage QMessageStore::message(const QMessageId& id) const |
356 QMessage QMessageStore::message(const QMessageId& id) const |
205 { |
357 { |
206 Q_UNUSED(id) |
358 if (id.toString().startsWith("MO_")) { |
207 return QMessage(); // stub |
359 return ModestEngine::instance()->message(id); |
|
360 } else { |
|
361 return d_ptr->p_ptr->el->message(id); |
|
362 } |
208 } |
363 } |
209 |
364 |
210 QMessageFolder QMessageStore::folder(const QMessageFolderId& id) const |
365 QMessageFolder QMessageStore::folder(const QMessageFolderId& id) const |
211 { |
366 { |
212 Q_UNUSED(id) |
367 if (id.toString().startsWith("MO_")) { |
213 return QMessageFolder(); // stub |
368 return ModestEngine::instance()->folder(id); |
|
369 } |
|
370 |
|
371 return QMessageFolder(); |
214 } |
372 } |
215 |
373 |
216 QMessageAccount QMessageStore::account(const QMessageAccountId& id) const |
374 QMessageAccount QMessageStore::account(const QMessageAccountId& id) const |
217 { |
375 { |
218 QMessageAccount acc=ModestEngine::instance()->account(id); |
376 if (id.toString().startsWith("MO_")) { |
219 if(acc.id()==id) return acc; |
377 return ModestEngine::instance()->account(id); |
220 return TelepathyEngine::instance()->account(id); |
378 } else { |
|
379 return TelepathyEngine::instance()->account(id); |
|
380 } |
221 } |
381 } |
222 |
382 |
223 QMessageManager::NotificationFilterId QMessageStore::registerNotificationFilter(const QMessageFilter &filter) |
383 QMessageManager::NotificationFilterId QMessageStore::registerNotificationFilter(const QMessageFilter &filter) |
224 { |
384 { |
225 Q_UNUSED(filter) |
385 QMessageManager::NotificationFilterId id = d_ptr->p_ptr->el->registerNotificationFilter(*d_ptr,filter); |
226 return 0; // stub |
386 return ModestEngine::instance()->registerNotificationFilter(*data(), filter, id); |
227 } |
387 } |
228 |
388 |
229 void QMessageStore::unregisterNotificationFilter(QMessageManager::NotificationFilterId notificationFilterId) |
389 void QMessageStore::unregisterNotificationFilter(QMessageManager::NotificationFilterId notificationFilterId) |
230 { |
390 { |
231 Q_UNUSED(notificationFilterId) |
391 ModestEngine::instance()->unregisterNotificationFilter(notificationFilterId); |
|
392 d_ptr->p_ptr->el->unregisterNotificationFilter( notificationFilterId); |
232 } |
393 } |
233 |
394 |
234 |
395 |
235 QTM_END_NAMESPACE |
396 QTM_END_NAMESPACE |