|
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: Listen to conversation server events and parse the |
|
15 * events. These parse infomation passed to notifications and indications. |
|
16 * |
|
17 */ |
|
18 |
|
19 // SYSTEM INCLUDES |
|
20 #include <msvapi.h> |
|
21 #include <ccsclientconversation.h> |
|
22 #include <ccsrequesthandler.h> |
|
23 #include <ccsconversationentry.h> |
|
24 #include <xqservicerequest.h> |
|
25 #include <QString> |
|
26 #include <w32std.h> |
|
27 #include <apgtask.h> |
|
28 #include <XQSettingsManager> |
|
29 #include <xqaiwrequest.h> |
|
30 #include <xqappmgr.h> |
|
31 #include <xqpublishandsubscribeutils.h> |
|
32 #include <xqsystemtoneservice.h> |
|
33 #include <xqconversions.h> |
|
34 #include <QThreadPool> |
|
35 |
|
36 //USER INCLUDES |
|
37 #include "msgnotifier.h" |
|
38 #include "msgnotifier_p.h" |
|
39 #include "msgstorehandler.h" |
|
40 #include "msginfodefs.h" |
|
41 #include "conversationidpsconsts.h" |
|
42 #include "debugtraces.h" |
|
43 |
|
44 // ---------------------------------------------------------------------------- |
|
45 // MsgNotifierPrivate::MsgNotifierPrivate |
|
46 // @see MsgNotifierPrivate.h |
|
47 // ---------------------------------------------------------------------------- |
|
48 MsgNotifierPrivate::MsgNotifierPrivate(MsgNotifier* MsgNotifier) : |
|
49 q_ptr(MsgNotifier), mCvServer(NULL), iMsgStoreHandler(NULL), |
|
50 mSettingsManager(NULL),mPSUtils(NULL) |
|
51 { |
|
52 QDEBUG_WRITE("MsgNotifierPrivate::MsgNotifierPrivate : Enter") |
|
53 |
|
54 initL(); |
|
55 QDEBUG_WRITE("MsgNotifierPrivate::MsgNotifierPrivate : Exit") |
|
56 } |
|
57 |
|
58 // ---------------------------------------------------------------------------- |
|
59 // MsgNotifierPrivate::~MsgNotifierPrivate |
|
60 // @see MsgNotifierPrivate.h |
|
61 // ---------------------------------------------------------------------------- |
|
62 MsgNotifierPrivate::~MsgNotifierPrivate() |
|
63 { |
|
64 QDEBUG_WRITE("MsgNotifierPrivate::~MsgNotifierPrivate : Enter") |
|
65 if (mCvServer) { |
|
66 TRAP_IGNORE(mCvServer->RemoveConversationListChangeEventL(this)); |
|
67 delete mCvServer; |
|
68 mCvServer = NULL; |
|
69 } |
|
70 |
|
71 if (iMsgStoreHandler) { |
|
72 delete iMsgStoreHandler; |
|
73 iMsgStoreHandler = NULL; |
|
74 } |
|
75 |
|
76 if(mPSUtils) |
|
77 { |
|
78 delete mPSUtils; |
|
79 } |
|
80 |
|
81 if(mSettingsManager) |
|
82 { |
|
83 delete mSettingsManager; |
|
84 } |
|
85 |
|
86 if(mSts) |
|
87 { |
|
88 delete mSts; |
|
89 mSts = NULL; |
|
90 } |
|
91 |
|
92 QDEBUG_WRITE("MsgNotifierPrivate::~MsgNotifierPrivate : Exit") |
|
93 } |
|
94 |
|
95 // ---------------------------------------------------------------------------- |
|
96 // MsgNotifierPrivate::initL |
|
97 // @see MsgNotifierPrivate.h |
|
98 // ---------------------------------------------------------------------------- |
|
99 void MsgNotifierPrivate::initL() |
|
100 { |
|
101 QDEBUG_WRITE("MsgNotifierPrivate::initL : Enter") |
|
102 |
|
103 mCvServer = CCSRequestHandler::NewL(); |
|
104 mCvServer->RequestConversationListChangeEventL(this); |
|
105 iMsgStoreHandler = new MsgStoreHandler(this, mCvServer); |
|
106 updateUnreadIndications(true); |
|
107 updateOutboxIndications(); |
|
108 |
|
109 QT_TRYCATCH_LEAVING(mSettingsManager = new XQSettingsManager()); |
|
110 |
|
111 // define property |
|
112 QT_TRYCATCH_LEAVING(mPSUtils = new XQPublishAndSubscribeUtils(*mSettingsManager)); |
|
113 |
|
114 XQPublishAndSubscribeSettingsKey convIdKey( |
|
115 KMsgCVIdProperty, KMsgCVIdKey); |
|
116 bool success = mPSUtils->defineProperty(convIdKey, |
|
117 XQSettingsManager::TypeInt); |
|
118 |
|
119 QDEBUG_WRITE_FORMAT("MsgNotifierPrivate::initL " |
|
120 "property creation ret value",success) |
|
121 |
|
122 // write -1 initially |
|
123 success = mSettingsManager->writeItemValue(convIdKey,-1); |
|
124 |
|
125 QDEBUG_WRITE_FORMAT("MsgNotifierPrivate::initL " |
|
126 "writing ret value",success) |
|
127 |
|
128 QT_TRYCATCH_LEAVING(mSts = new XQSystemToneService()); |
|
129 |
|
130 QDEBUG_WRITE("MsgNotifierPrivate::initL : Exit") |
|
131 } |
|
132 |
|
133 // ---------------------------------------------------------------------------- |
|
134 // MsgNotifierPrivate::AddConversationList |
|
135 // @see MsgNotifierPrivate.h |
|
136 // ---------------------------------------------------------------------------- |
|
137 void MsgNotifierPrivate::AddConversationList( |
|
138 const CCsClientConversation& aClientConversation) |
|
139 { |
|
140 QCRITICAL_WRITE("MsgNotifierPrivate::AddConversationList : Enter") |
|
141 |
|
142 processListEntry(aClientConversation); |
|
143 updateUnreadIndications(); |
|
144 |
|
145 QCRITICAL_WRITE("MsgNotifierPrivate::AddConversationList : Exit") |
|
146 } |
|
147 |
|
148 // ---------------------------------------------------------------------------- |
|
149 // MsgNotifierPrivate::DeleteConversationList |
|
150 // @see MsgNotifierPrivate.h |
|
151 // ---------------------------------------------------------------------------- |
|
152 void MsgNotifierPrivate::DeleteConversationList( |
|
153 const CCsClientConversation& /*aClientConversation*/) |
|
154 { |
|
155 QDEBUG_WRITE("MsgNotifierPrivate::DeleteConversationList : Enter") |
|
156 updateUnreadIndications(); |
|
157 QDEBUG_WRITE("MsgNotifierPrivate::DeleteConversationList : Exit") |
|
158 } |
|
159 |
|
160 // ---------------------------------------------------------------------------- |
|
161 // MsgNotifierPrivate::ModifyConversationList |
|
162 // @see MsgNotifierPrivate.h |
|
163 // ---------------------------------------------------------------------------- |
|
164 void MsgNotifierPrivate::ModifyConversationList(const CCsClientConversation& aClientConversation) |
|
165 { |
|
166 QCRITICAL_WRITE("MsgNotifierPrivate::ModifyConversationList : Enter") |
|
167 |
|
168 processListEntry(aClientConversation); |
|
169 updateUnreadIndications(); |
|
170 |
|
171 QCRITICAL_WRITE("MsgNotifierPrivate::ModifyConversationList : Exit") |
|
172 } |
|
173 |
|
174 // ---------------------------------------------------------------------------- |
|
175 // MsgNotifierPrivate::RefreshConversationList |
|
176 // @see MsgNotifierPrivate.h |
|
177 // ---------------------------------------------------------------------------- |
|
178 void MsgNotifierPrivate::RefreshConversationList() |
|
179 { |
|
180 |
|
181 } |
|
182 |
|
183 // ---------------------------------------------------------------------------- |
|
184 // MsgNotifierPrivate::processListEntry |
|
185 // @see MsgNotifierPrivate.h |
|
186 // ---------------------------------------------------------------------------- |
|
187 void MsgNotifierPrivate::processListEntry( |
|
188 const CCsClientConversation& aClientConversation) |
|
189 { |
|
190 QCRITICAL_WRITE("MsgNotifierPrivate::processListEntry : Enter") |
|
191 |
|
192 CCsConversationEntry* convEntry = |
|
193 aClientConversation.GetConversationEntry(); |
|
194 |
|
195 QDEBUG_WRITE_FORMAT("MsgNotifierPrivate::processListEntry Direction", |
|
196 convEntry->ConversationDir()) |
|
197 QDEBUG_WRITE_FORMAT("MsgNotifierPrivate::processListEntry New Entry Attribute", |
|
198 convEntry->IsAttributeSet(ECsAttributeNewEntryAdded)) |
|
199 QDEBUG_WRITE_FORMAT("MsgNotifierPrivate::processListEntry Unread Attribute", |
|
200 convEntry->IsAttributeSet(ECsAttributeUnread)) |
|
201 |
|
202 if((convEntry->ConversationDir() == ECsDirectionIncoming) |
|
203 && convEntry->IsAttributeSet(ECsAttributeNewEntryAdded) |
|
204 && convEntry->IsAttributeSet(ECsAttributeUnread)) |
|
205 { |
|
206 QDEBUG_WRITE("processListEntry : Processing data for Notification") |
|
207 |
|
208 NotificationData notifData; |
|
209 notifData.msvEntryId = convEntry->EntryId(); |
|
210 notifData.mConversationId = aClientConversation.GetConversationEntryId(); |
|
211 notifData.mMsgType = static_cast<int>(convEntry->GetType()); |
|
212 |
|
213 HBufC* displayName = aClientConversation.GetDisplayName(); |
|
214 HBufC* number = convEntry->Contact(); |
|
215 HBufC* descrp = convEntry->Description(); |
|
216 |
|
217 if(displayName) |
|
218 { |
|
219 notifData.mDisplayName = |
|
220 XQConversions::s60DescToQString(*displayName); |
|
221 } |
|
222 if(number) |
|
223 { |
|
224 notifData.mContactNum = XQConversions::s60DescToQString(*number); |
|
225 } |
|
226 if(descrp) |
|
227 { |
|
228 notifData.mDescription = XQConversions::s60DescToQString(*descrp); |
|
229 } |
|
230 |
|
231 //Play new message alert tone. |
|
232 mSts->playTone(XQSystemToneService::SmsAlertTone); |
|
233 |
|
234 // check whether opened cv id and received |
|
235 // cv id are same and show notification |
|
236 if( showNotification(notifData.mConversationId )) |
|
237 { |
|
238 q_ptr->displayNewMessageNotification(notifData); |
|
239 QDEBUG_WRITE("processListEntry : Notification display called") |
|
240 } |
|
241 |
|
242 } |
|
243 |
|
244 QCRITICAL_WRITE("MsgNotifierPrivate::processListEntry : Exit") |
|
245 } |
|
246 |
|
247 // ---------------------------------------------------------------------------- |
|
248 // MsgNotifierPrivate::updateUnreadIndications |
|
249 // @see MsgNotifierPrivate.h |
|
250 // ---------------------------------------------------------------------------- |
|
251 void MsgNotifierPrivate::updateUnreadIndications(bool bootup) |
|
252 { |
|
253 QDEBUG_WRITE("MsgNotifierPrivate::updateIndicationsL : Enter") |
|
254 |
|
255 int unreadCount(0); |
|
256 if(bootup) |
|
257 { |
|
258 TRAP_IGNORE(unreadCount = iMsgStoreHandler->GetUnreadMessageCountL()); |
|
259 } |
|
260 else |
|
261 { |
|
262 TRAP_IGNORE(unreadCount = mCvServer->GetTotalUnreadCountL()); |
|
263 } |
|
264 |
|
265 QDEBUG_WRITE_FORMAT("MsgNotifierPrivate::" |
|
266 "updateIndications unreadCount = ",unreadCount ); |
|
267 |
|
268 //activate or deactivate indications based on unread count |
|
269 q_ptr->updateUnreadIndications(unreadCount); |
|
270 |
|
271 QDEBUG_WRITE("MsgNotifierPrivate::updateIndicationsL : Exit") |
|
272 } |
|
273 |
|
274 // ---------------------------------------------------------------------------- |
|
275 // MsgNotifierPrivate::updateOutboxIndications |
|
276 // @see MsgNotifierPrivate.h |
|
277 // ---------------------------------------------------------------------------- |
|
278 void MsgNotifierPrivate::updateOutboxIndications() |
|
279 { |
|
280 |
|
281 MsgInfo failedIndicatorData; |
|
282 MsgInfo pendingIndicatorData; |
|
283 TInt err = KErrNone; |
|
284 |
|
285 TRAP(err, iMsgStoreHandler->GetOutboxEntriesL(failedIndicatorData,pendingIndicatorData)); |
|
286 |
|
287 q_ptr->updateOutboxIndications(failedIndicatorData); |
|
288 q_ptr->updateOutboxIndications(pendingIndicatorData); |
|
289 } |
|
290 |
|
291 |
|
292 // ---------------------------------------------------------------------------- |
|
293 // MsgNotifierPrivate::displayOutboxIndications |
|
294 // @see MsgNotifierPrivate.h |
|
295 // ---------------------------------------------------------------------------- |
|
296 |
|
297 void MsgNotifierPrivate::displayOutboxIndications(MsgInfo data) |
|
298 { |
|
299 q_ptr->updateOutboxIndications(data); |
|
300 } |
|
301 |
|
302 // ---------------------------------------------------------------------------- |
|
303 // MsgNotifierPrivate::displayFailedNote |
|
304 // @see MsgNotifierPrivate.h |
|
305 // ---------------------------------------------------------------------------- |
|
306 void MsgNotifierPrivate::displayFailedNote(MsgInfo info) |
|
307 { |
|
308 QDEBUG_WRITE("MsgNotifierPrivate::displayFailedNote start.") |
|
309 |
|
310 // check whether opened cv id and received |
|
311 // cv id are same then dont show failed note |
|
312 if (!showNotification(info.mConversationId)) |
|
313 { |
|
314 return; |
|
315 } |
|
316 |
|
317 //Even if name string is empty we shall add name into args |
|
318 QString nameString; |
|
319 |
|
320 info.mDisplayName.removeDuplicates(); |
|
321 info.mDisplayName.sort(); |
|
322 |
|
323 nameString.append(info.mDisplayName.at(0)); |
|
324 for (int i = 1; i < info.mDisplayName.count(); ++i) |
|
325 { |
|
326 nameString.append(", "); |
|
327 nameString.append(info.mDisplayName.at(i)); |
|
328 } |
|
329 |
|
330 // create request arguments |
|
331 QVariantList args; |
|
332 args << QVariant(nameString); |
|
333 args << info.mConversationId; |
|
334 args << info.mMessageType; |
|
335 |
|
336 // TODO: use XQAiwRequest |
|
337 XQServiceRequest snd("messaging.com.nokia.symbian.MsgErrorNotifier", |
|
338 "displayErrorNote(QVariantList)", false); |
|
339 |
|
340 snd << args; |
|
341 snd.send(); |
|
342 |
|
343 QDEBUG_WRITE("MsgNotifierPrivate::displayFailedNote end.") |
|
344 } |
|
345 |
|
346 // ---------------------------------------------------------------------------- |
|
347 // MsgNotifierPrivate::showNotification |
|
348 // @see MsgNotifierPrivate.h |
|
349 // ---------------------------------------------------------------------------- |
|
350 bool MsgNotifierPrivate::showNotification(int receivedMsgConvId) |
|
351 { |
|
352 bool showNotification = true; |
|
353 |
|
354 RWsSession wsSession ; |
|
355 wsSession.Connect(); |
|
356 |
|
357 TApaTaskList taskList( wsSession ); |
|
358 TApaTask task = taskList.FindApp(KMsgAppUid); // find msgapp is running |
|
359 |
|
360 if(task.Exists()) |
|
361 { |
|
362 TApaTask foregndtask = taskList.FindByPos(0) ; // foreground app |
|
363 // compare window group id |
|
364 // if application is in foregorund, then check the currently |
|
365 // opened conversation is same as received one. |
|
366 if(task.WgId() == foregndtask.WgId() ) |
|
367 { |
|
368 // get the current conversation ID |
|
369 XQPublishAndSubscribeSettingsKey convIdKey( KMsgCVIdProperty, |
|
370 KMsgCVIdKey); |
|
371 QVariant value = mSettingsManager->readItemValue(convIdKey, |
|
372 XQSettingsManager::TypeInt); |
|
373 |
|
374 int openedConvId = value.toInt(); |
|
375 if( openedConvId == receivedMsgConvId) |
|
376 { |
|
377 showNotification = false; |
|
378 QDEBUG_WRITE("processListEntry : Notification not shown") |
|
379 } |
|
380 } |
|
381 } |
|
382 |
|
383 wsSession.Close(); |
|
384 return showNotification; |
|
385 } |
|
386 // ---------------------------------------------------------------------------- |
|
387 // MsgNotifierPrivate::PartialDeleteConversationList |
|
388 // @see mcsconversationclientchangeobserver.h |
|
389 // ---------------------------------------------------------------------------- |
|
390 void MsgNotifierPrivate::PartialDeleteConversationList( |
|
391 const CCsClientConversation& /*aClientConversation*/){/*empty implementation*/} |
|
392 |
|
393 |
|
394 // ---------------------------------------------------------------------------- |
|
395 // MsgNotifierPrivate::ShowClass0Message |
|
396 // @see msgnotifier_p.h |
|
397 // ---------------------------------------------------------------------------- |
|
398 |
|
399 void MsgNotifierPrivate::ShowClass0Message(Class0Info& class0Info) |
|
400 { |
|
401 QCRITICAL_WRITE("flashmsgnotifier BEGIN"); |
|
402 QThreadPool::globalInstance()->start(new Class0SmsServiceTask(class0Info)); |
|
403 QCRITICAL_WRITE("flashmsgnotifier END"); |
|
404 } |
|
405 |
|
406 |
|
407 |
|
408 |
|
409 // ---------------------------------------------------------------------------- |
|
410 // Class0SmsServiceTask::Class0SmsServiceTask |
|
411 // @see msgnotifier_p.h |
|
412 // ---------------------------------------------------------------------------- |
|
413 Class0SmsServiceTask::Class0SmsServiceTask(Class0Info& class0Info): |
|
414 mClass0info(class0Info) |
|
415 { |
|
416 } |
|
417 |
|
418 // ---------------------------------------------------------------------------- |
|
419 // Class0SmsServiceTask::~Class0SmsServiceTask |
|
420 // @see msgnotifier_p.h |
|
421 // ---------------------------------------------------------------------------- |
|
422 Class0SmsServiceTask::~Class0SmsServiceTask() |
|
423 { |
|
424 } |
|
425 |
|
426 // ---------------------------------------------------------------------------- |
|
427 // Class0SmsServiceTask::run |
|
428 // @see msgnotifier_p.h |
|
429 // ---------------------------------------------------------------------------- |
|
430 void Class0SmsServiceTask::run() |
|
431 { |
|
432 QList<QVariant> args; |
|
433 QString serviceName("flashmsgnotifier"); |
|
434 QString interfaceName("com.nokia.symbian.IFlashMsgNotifier"); |
|
435 QString operation("displayFlashMsg(QByteArray)"); |
|
436 XQAiwRequest* request; |
|
437 XQApplicationManager appManager; |
|
438 |
|
439 request = appManager.create(interfaceName, operation, false); //non-embedded |
|
440 |
|
441 if ( request == NULL ) |
|
442 { |
|
443 QCRITICAL_WRITE("flashmsgnotifier request == NULL"); |
|
444 return; |
|
445 } |
|
446 |
|
447 QByteArray ba; |
|
448 QDataStream stream(&ba, QIODevice::ReadWrite); |
|
449 stream << mClass0info.body; |
|
450 stream << mClass0info.address; |
|
451 stream << mClass0info.alias; |
|
452 stream << mClass0info.time; |
|
453 stream << mClass0info.messageId; |
|
454 |
|
455 args << ba; |
|
456 request->setArguments(args); |
|
457 |
|
458 if(!request->send()) |
|
459 { |
|
460 QString lastErr; |
|
461 lastErr = request->lastErrorMessage(); |
|
462 QDEBUG_WRITE_FORMAT("flashmsgnotifier launch failed", lastErr); |
|
463 } |
|
464 |
|
465 QCRITICAL_WRITE("flashmsgnotifier END"); |
|
466 delete request; |
|
467 } |
|
468 |
|
469 //EOF |