7 * |
7 * |
8 * Contributors: |
8 * Contributors: |
9 * Nokia Corporation - initial implementation |
9 * Nokia Corporation - initial implementation |
10 *******************************************************************************/ |
10 *******************************************************************************/ |
11 |
11 |
12 |
|
13 #include <w32std.h> |
|
14 #include <apgtask.h> |
12 #include <apgtask.h> |
15 #include <hbdevicenotificationdialogsymbian.h> |
13 #include <hbdevicenotificationdialogsymbian.h> |
16 #include <hbsymbianvariant.h> |
14 #include <hbsymbianvariant.h> |
|
15 |
|
16 #include <memory> |
|
17 #include <javastorageentry.h> |
|
18 #include <javastorage.h> |
|
19 #include <javastoragenames.h> |
|
20 #include <JavaCommonUtils.h> |
|
21 #include <logger.h> |
|
22 |
17 #include "CSoftNotification.h" |
23 #include "CSoftNotification.h" |
18 |
24 |
19 _LIT(KMidletId, "MidletId"); |
25 _LIT(KMidletId, "MidletId"); |
20 _LIT(KNotificationId, "NotificationId"); |
26 _LIT(KNotificationId, "NotificationId"); |
21 _LIT(KIndicatorTypeJavaSoftNote,"com.nokia.javasoftnotification.indicatorplugin/1.0_%u_%i"); |
27 _LIT(KIndicatorTypeJavaSoftNote,"com.nokia.javasoftnotification.indicatorplugin/1.0_%u_%i"); |
22 const TInt KIndicatorTypeStringLength = 250; |
28 const TInt KIndicatorTypeStringLength = 250; |
23 const TInt KMidletUidLength = 50; |
29 const TInt KMidletUidLength = 50; |
24 |
30 |
25 // Event id when user accepted notification |
31 // Event id when user accepted notification |
26 const TInt KEventNoteAccepted = 1; |
32 const TInt KEventNoteAccepted = 1; |
|
33 |
|
34 using namespace std; |
|
35 using namespace java::storage; |
|
36 using namespace java::util; |
27 |
37 |
28 // ============================ MEMBER FUNCTIONS =============================== |
38 // ============================ MEMBER FUNCTIONS =============================== |
29 // ----------------------------------------------------------------------------- |
39 // ----------------------------------------------------------------------------- |
30 // CSoftNotification::NewLC |
40 // CSoftNotification::NewLC |
31 // Static constructor |
41 // Static constructor |
46 // C++ default constructor can NOT contain any code, that |
56 // C++ default constructor can NOT contain any code, that |
47 // might leave. |
57 // might leave. |
48 // ----------------------------------------------------------------------------- |
58 // ----------------------------------------------------------------------------- |
49 // |
59 // |
50 CSoftNotification::CSoftNotification(TInt aAppId, TInt aNotificationId) : |
60 CSoftNotification::CSoftNotification(TInt aAppId, TInt aNotificationId) : |
51 iNotificationId(aNotificationId) |
61 iNotificationId(aNotificationId),iIsNoteExist(EFalse) |
52 { |
62 { |
53 iMidletId = TUid::Uid(aAppId); |
63 iMidletId = TUid::Uid(aAppId); |
54 } |
64 } |
55 |
65 |
56 // ----------------------------------------------------------------------------- |
66 // ----------------------------------------------------------------------------- |
58 // Symbian 2nd phase constructor can leave. |
68 // Symbian 2nd phase constructor can leave. |
59 // ----------------------------------------------------------------------------- |
69 // ----------------------------------------------------------------------------- |
60 // |
70 // |
61 void CSoftNotification::ConstructL() |
71 void CSoftNotification::ConstructL() |
62 { |
72 { |
63 iIndicator = CHbIndicatorSymbian::NewL(); |
73 std::auto_ptr<JavaStorage> js(JavaStorage::createInstance()); |
64 iIndicator->SetObserver(this); |
74 TInt maxValue = 0; |
|
75 try |
|
76 { |
|
77 js->open(JAVA_DATABASE_NAME); |
|
78 JavaStorageEntry attribute; |
|
79 JavaStorageApplicationEntry_t findPattern; |
|
80 JavaStorageApplicationList_t foundEntries; |
|
81 |
|
82 std::wstring midletId = JavaCommonUtils::intToWstring(iMidletId.iUid); |
|
83 attribute.setEntry(SOFTNOTE_MIDLET_ID, midletId); |
|
84 findPattern.insert(attribute); |
|
85 |
|
86 js->search(JAVA_SOFTNOTE_TABLE, findPattern, foundEntries); |
|
87 js->close(); |
|
88 findPattern.clear(); |
|
89 |
|
90 // like to know softnote id. |
|
91 attribute.setEntry(SOFTNOTE_ID, L""); |
|
92 // Iterate through all rows matched with search patterns. |
|
93 JavaStorageApplicationList_t::const_iterator applications; |
|
94 for(applications = foundEntries.begin(); applications !=foundEntries.end(); applications++) |
|
95 { |
|
96 // Get softnote ID from its parameters. |
|
97 JavaStorageApplicationEntry_t::const_iterator findIterator = (*applications).find(attribute); |
|
98 if (findIterator != (*applications).end()) |
|
99 { |
|
100 TInt id = JavaCommonUtils::wstringToInt((*findIterator).entryValue()); |
|
101 if(iNotificationId == id) |
|
102 { |
|
103 iIsNoteExist = true; |
|
104 } |
|
105 if(maxValue<id) |
|
106 { |
|
107 maxValue = id; |
|
108 } |
|
109 } |
|
110 } |
|
111 foundEntries.clear(); |
|
112 } |
|
113 catch (JavaStorageException& ex) |
|
114 { |
|
115 LOG1(EJavaStorage, EInfo," JavaSoftNote Exception %s", ex.toString()); |
|
116 } |
|
117 |
|
118 if(!iIsNoteExist && iNotificationId == 0) |
|
119 { |
|
120 iNotificationId = maxValue + 1; |
|
121 } |
|
122 if(iIndicator == NULL) |
|
123 { |
|
124 iIndicator = CHbIndicatorSymbian::NewL(); |
|
125 iIndicator->SetObserver(this); |
|
126 } |
65 } |
127 } |
66 |
128 |
67 // ----------------------------------------------------------------------------- |
129 // ----------------------------------------------------------------------------- |
68 // Destructor |
130 // Destructor |
69 // ----------------------------------------------------------------------------- |
131 // ----------------------------------------------------------------------------- |
108 // Displays a soft notification |
176 // Displays a soft notification |
109 // ----------------------------------------------------------------------------- |
177 // ----------------------------------------------------------------------------- |
110 // |
178 // |
111 bool CSoftNotification::ShowSoftNotificationL() |
179 bool CSoftNotification::ShowSoftNotificationL() |
112 { |
180 { |
113 CHbDeviceNotificationDialogSymbian* dialog = |
181 AddorUpdateSoftNotificationToStorage(); |
114 CHbDeviceNotificationDialogSymbian::NewL(); |
182 |
115 CleanupStack::PushL(dialog); |
183 if(iNotificationDialog == NULL) |
|
184 { |
|
185 iNotificationDialog = CHbDeviceNotificationDialogSymbian::NewL(this); |
|
186 } |
116 |
187 |
117 if(iPrimaryText != NULL) |
188 if(iPrimaryText != NULL) |
118 { |
189 { |
119 dialog->SetTitleL(iPrimaryText->Des()); |
190 iNotificationDialog->SetTitleL(iPrimaryText->Des()); |
120 } |
191 } |
121 |
192 |
122 if(iSecondaryText != NULL) |
193 if(iSecondaryText != NULL) |
123 { |
194 { |
124 dialog->SetTextL(iSecondaryText->Des()); |
195 iNotificationDialog->SetTextL(iSecondaryText->Des()); |
125 } |
196 } |
126 |
197 |
127 if (iImagePath != NULL) |
198 if (iImagePath != NULL) |
128 { |
199 { |
129 dialog->SetIconNameL(iImagePath->Des()); |
200 iNotificationDialog->SetIconNameL(iImagePath->Des()); |
130 } |
201 } |
131 |
202 iNotificationDialog->EnableTouchActivation(ETrue); |
132 dialog->ShowL(); |
203 iNotificationDialog->ShowL(); |
133 |
204 |
|
205 // reading Softnote data |
134 CHbSymbianVariant* varValues = NotificationParamsL(); |
206 CHbSymbianVariant* varValues = NotificationParamsL(); |
135 CleanupStack::PushL(varValues); |
207 CleanupStack::PushL(varValues); |
136 |
208 |
|
209 // creating indicator in status menu |
137 TBuf<KIndicatorTypeStringLength> indicatorType; |
210 TBuf<KIndicatorTypeStringLength> indicatorType; |
138 indicatorType.Format(KIndicatorTypeJavaSoftNote, iMidletId, iNotificationId); |
211 indicatorType.Format(KIndicatorTypeJavaSoftNote, iMidletId, iNotificationId); |
139 bool indStatus = iIndicator->Activate(indicatorType, varValues); |
212 bool indStatus = iIndicator->Activate(indicatorType, varValues); |
140 |
213 |
141 CleanupStack::PopAndDestroy(varValues); |
214 CleanupStack::PopAndDestroy(varValues); |
142 CleanupStack::PopAndDestroy(dialog); |
|
143 return indStatus; |
215 return indStatus; |
144 } |
216 } |
145 |
217 |
146 // ----------------------------------------------------------------------------- |
218 // ----------------------------------------------------------------------------- |
147 // CSoftNotification::RemoveSoftNotificationL |
219 // CSoftNotification::RemoveSoftNotificationL |
230 } |
302 } |
231 } |
303 } |
232 } |
304 } |
233 |
305 |
234 // ----------------------------------------------------------------------------- |
306 // ----------------------------------------------------------------------------- |
|
307 // CSoftNotification::NotificationDialogActivated |
|
308 // Dynamic soft notification was accepted by user. |
|
309 // ----------------------------------------------------------------------------- |
|
310 // |
|
311 void CSoftNotification::NotificationDialogActivated(const CHbDeviceNotificationDialogSymbian* /*aDialog*/) |
|
312 { |
|
313 RWsSession ws; |
|
314 User::LeaveIfError(ws.Connect() == KErrNone); |
|
315 TApaTaskList tasklist(ws); |
|
316 TApaTask task = tasklist.FindApp(iMidletId); |
|
317 if (task.Exists()) |
|
318 { |
|
319 task.BringToForeground(); |
|
320 ws.Close(); |
|
321 } |
|
322 } |
|
323 |
|
324 // ----------------------------------------------------------------------------- |
|
325 // CSoftNotification::NotificationDialogClosed |
|
326 // Dynamic soft notification was closed. |
|
327 // ----------------------------------------------------------------------------- |
|
328 // |
|
329 void CSoftNotification::NotificationDialogClosed(const CHbDeviceNotificationDialogSymbian* /*aDialog*/, |
|
330 TInt /*aCompletionCode*/) |
|
331 { |
|
332 |
|
333 } |
|
334 |
|
335 // ----------------------------------------------------------------------------- |
235 // CSoftNotification::FillNotificationParams |
336 // CSoftNotification::FillNotificationParams |
236 // ----------------------------------------------------------------------------- |
337 // ----------------------------------------------------------------------------- |
237 // |
338 // |
238 CHbSymbianVariant* CSoftNotification::NotificationParamsL() |
339 CHbSymbianVariant* CSoftNotification::NotificationParamsL() |
239 { |
340 { |
240 //only five parameter, so creat the array |
341 //only five parameter, so creat the array with size 5. |
241 //for five parameters to fit and append them |
|
242 CDesC16ArrayFlat* array = new CDesC16ArrayFlat(5); |
342 CDesC16ArrayFlat* array = new CDesC16ArrayFlat(5); |
243 CleanupStack::PushL(array); |
343 CleanupStack::PushL(array); |
244 TBuf<KMidletUidLength> midletId; |
344 TBuf<KMidletUidLength> midletId; |
245 _LIT(MidletId,"%u"); |
345 _LIT(MidletId,"%u"); |
246 midletId.Format(MidletId,iMidletId); |
346 midletId.Format(MidletId,iMidletId); |
247 array->AppendL(midletId); |
347 array->AppendL(midletId); |
248 array->AppendL(reinterpret_cast<TDesC16&>(iNotificationId)); |
348 |
|
349 TBuf<10> noteId; |
|
350 _LIT(NoteId,"%d"); |
|
351 noteId.Format(NoteId,iNotificationId); |
|
352 array->AppendL(noteId); |
|
353 |
249 if(iPrimaryText != NULL) |
354 if(iPrimaryText != NULL) |
250 { |
355 { |
251 array->AppendL(iPrimaryText->Des()); |
356 array->AppendL(iPrimaryText->Des()); |
252 } |
357 } |
253 else |
358 else |
275 MDesCArray* marray = static_cast<MDesCArray*>(array); |
380 MDesCArray* marray = static_cast<MDesCArray*>(array); |
276 CHbSymbianVariant* varValues = CHbSymbianVariant::NewL( marray, CHbSymbianVariant::EDesArray); |
381 CHbSymbianVariant* varValues = CHbSymbianVariant::NewL( marray, CHbSymbianVariant::EDesArray); |
277 CleanupStack::PopAndDestroy(array); |
382 CleanupStack::PopAndDestroy(array); |
278 return varValues; |
383 return varValues; |
279 } |
384 } |
|
385 |
|
386 // ----------------------------------------------------------------------------- |
|
387 // CSoftNotification::AddSoftNotificationToStorage |
|
388 // ----------------------------------------------------------------------------- |
|
389 // |
|
390 void CSoftNotification::AddorUpdateSoftNotificationToStorage() |
|
391 { |
|
392 std::auto_ptr<JavaStorage> js(JavaStorage::createInstance()); |
|
393 try |
|
394 { |
|
395 js->open(JAVA_DATABASE_NAME); |
|
396 JavaStorageApplicationEntry_t newEntries; |
|
397 JavaStorageApplicationEntry_t matchEntries; |
|
398 JavaStorageEntry attribute; |
|
399 |
|
400 if (!iIsNoteExist) |
|
401 { |
|
402 // if Softnote is not created, add midletId and notificationId to storage |
|
403 std::wstring midletId = JavaCommonUtils::intToWstring( |
|
404 iMidletId.iUid); |
|
405 attribute.setEntry(SOFTNOTE_MIDLET_ID, midletId, |
|
406 JavaStorageEntry::STRING); |
|
407 newEntries.insert(attribute); |
|
408 |
|
409 std::wstring notificationId = JavaCommonUtils::intToWstring( |
|
410 iNotificationId); |
|
411 attribute.setEntry(SOFTNOTE_ID, notificationId, |
|
412 JavaStorageEntry::INT); |
|
413 newEntries.insert(attribute); |
|
414 } |
|
415 else |
|
416 { |
|
417 // if Softnote is already in the storage, just aupdate the data. |
|
418 std::wstring midletId = JavaCommonUtils::intToWstring( |
|
419 iMidletId.iUid); |
|
420 attribute.setEntry(SOFTNOTE_MIDLET_ID, midletId, |
|
421 JavaStorageEntry::STRING); |
|
422 matchEntries.insert(attribute); |
|
423 |
|
424 std::wstring notificationId = JavaCommonUtils::intToWstring( |
|
425 iNotificationId); |
|
426 attribute.setEntry(SOFTNOTE_ID, notificationId, |
|
427 JavaStorageEntry::INT); |
|
428 matchEntries.insert(attribute); |
|
429 } |
|
430 |
|
431 if (iPrimaryText) |
|
432 { |
|
433 std::wstring primaryText((wchar_t*) iPrimaryText->Ptr(), |
|
434 iPrimaryText->Length()); |
|
435 attribute.setEntry(SOFTNOTE_PRIMARY_TEXT, primaryText, |
|
436 JavaStorageEntry::STRING); |
|
437 newEntries.insert(attribute); |
|
438 } |
|
439 if (iSecondaryText) |
|
440 { |
|
441 std::wstring secondaryText((wchar_t*) iSecondaryText->Ptr(), |
|
442 iSecondaryText->Length()); |
|
443 attribute.setEntry(SOFTNOTE_SECONDARY_TEXT, secondaryText, |
|
444 JavaStorageEntry::STRING); |
|
445 newEntries.insert(attribute); |
|
446 } |
|
447 if (iImagePath) |
|
448 { |
|
449 std::wstring imagePath((wchar_t*) iImagePath->Ptr(), |
|
450 iImagePath->Length()); |
|
451 attribute.setEntry(SOFTNOTE_IMAGE_PATH, imagePath, |
|
452 JavaStorageEntry::STRING); |
|
453 newEntries.insert(attribute); |
|
454 } |
|
455 |
|
456 if (!iIsNoteExist) |
|
457 { |
|
458 // create new entry in storage if softnote is not created earlier |
|
459 js->write(JAVA_SOFTNOTE_TABLE, newEntries); |
|
460 } |
|
461 else |
|
462 { |
|
463 // update data for softNote. |
|
464 js->update(JAVA_SOFTNOTE_TABLE, newEntries, matchEntries); |
|
465 } |
|
466 js->close(); |
|
467 newEntries.clear(); |
|
468 matchEntries.clear(); |
|
469 } |
|
470 catch (JavaStorageException& ex) |
|
471 { |
|
472 LOG1(EJavaStorage, EInfo," JavaSoftNote Exception %s", ex.toString()); |
|
473 } |
|
474 } |