|
1 /* |
|
2 * Copyright (c) 2008 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: Controls the native soft notifications. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 // INCLUDE FILES |
|
20 #include "CSoftNotification.h" |
|
21 #include "CSoftNotificationEvent.h" |
|
22 #include "CSoftNotificationEventSource.h" |
|
23 |
|
24 #include <AknDynamicSoftNotifier.h> |
|
25 #include <AknDynamicSoftNotificationParams.h> |
|
26 #include <jdebug.h> |
|
27 |
|
28 #ifdef SYMBIAN_ENABLE_SPLIT_HEADERS |
|
29 #include <vwsdefpartner.h> |
|
30 #endif |
|
31 |
|
32 |
|
33 // CONSTANTS |
|
34 namespace |
|
35 { |
|
36 /// Default soft notification priority (range: 1000...3000) |
|
37 const TInt KSoftNotificationPriority = 1000; |
|
38 /// Event id when user accepted notification |
|
39 const TInt KEventNoteAccepted = 1; |
|
40 /// Event id when user canceled notification |
|
41 const TInt KEventNoteCanceled = 2; |
|
42 } |
|
43 |
|
44 // ============================ MEMBER FUNCTIONS =============================== |
|
45 // ----------------------------------------------------------------------------- |
|
46 // CSoftNotification::NewLC |
|
47 // Static constructor |
|
48 // ----------------------------------------------------------------------------- |
|
49 // |
|
50 CSoftNotification* CSoftNotification::NewL( |
|
51 TInt aAppId, |
|
52 TInt aNotificationId, |
|
53 CSoftNotificationEventSource& aEventSource) |
|
54 { |
|
55 DEBUG("CSoftNotification::NewL"); |
|
56 |
|
57 CSoftNotification* self = |
|
58 new(ELeave) CSoftNotification(aAppId, |
|
59 aNotificationId, |
|
60 aEventSource); |
|
61 CleanupStack::PushL(self); |
|
62 |
|
63 self->ConstructL(); |
|
64 CleanupStack::Pop(self); |
|
65 |
|
66 return self; |
|
67 } |
|
68 |
|
69 // ----------------------------------------------------------------------------- |
|
70 // Destructor |
|
71 // ----------------------------------------------------------------------------- |
|
72 // |
|
73 CSoftNotification::~CSoftNotification() |
|
74 { |
|
75 DEBUG("CSoftNotification::~CSoftNotification +"); |
|
76 |
|
77 delete iSoftkey1; |
|
78 delete iSoftkey2; |
|
79 |
|
80 delete iLabel; |
|
81 delete iGroupLabel; |
|
82 |
|
83 delete iImageData; |
|
84 |
|
85 delete iNotifier; |
|
86 |
|
87 DEBUG("CSoftNotification::~CSoftNotification -"); |
|
88 } |
|
89 |
|
90 // ----------------------------------------------------------------------------- |
|
91 // CSoftNotification::NotificationAccepted |
|
92 // Dynamic soft notification was accepted by user. |
|
93 // ----------------------------------------------------------------------------- |
|
94 // |
|
95 void CSoftNotification::NotificationAccepted(TInt aIdentifier) |
|
96 { |
|
97 DEBUG_INT("CSoftNotification::NotificationAccepted +, id=%d", aIdentifier); |
|
98 |
|
99 if (iNotificationId == aIdentifier && iPeer) |
|
100 { |
|
101 // Error ignored since there is no other way to get the error to |
|
102 // the Java side than posting. |
|
103 TRAP_IGNORE(PostEventL(KEventNoteAccepted)); |
|
104 } |
|
105 |
|
106 DEBUG("CSoftNotification::NotificationAccepted -"); |
|
107 } |
|
108 |
|
109 // ----------------------------------------------------------------------------- |
|
110 // CSoftNotification::NotificationCanceled |
|
111 // Dynamic soft notification was canceled by user. |
|
112 // ----------------------------------------------------------------------------- |
|
113 // |
|
114 void CSoftNotification::NotificationCanceled(TInt aIdentifier) |
|
115 { |
|
116 DEBUG_INT("CSoftNotification::NotificationCanceled +, id=%d", aIdentifier); |
|
117 |
|
118 if (iNotificationId == aIdentifier && iPeer) |
|
119 { |
|
120 // Error ignored since there is no other way to get the error to |
|
121 // the Java side than posting. |
|
122 TRAP_IGNORE(PostEventL(KEventNoteCanceled)); |
|
123 } |
|
124 |
|
125 DEBUG("CSoftNotification::NotificationCanceled -"); |
|
126 } |
|
127 |
|
128 // ----------------------------------------------------------------------------- |
|
129 // CSoftNotification::ShowSoftNotificationL |
|
130 // Displays a soft notification |
|
131 // ----------------------------------------------------------------------------- |
|
132 // |
|
133 void CSoftNotification::ShowSoftNotificationL() |
|
134 { |
|
135 DEBUG("CSoftNotification::ShowSoftNotificationL +"); |
|
136 |
|
137 TAknDynamicSoftNotificationParams param(KSoftNotificationPriority); |
|
138 FillNotificationParams(param); |
|
139 |
|
140 TInt oldId = iNotificationId; |
|
141 iNotificationId = |
|
142 iNotifier->SetDynamicNotificationCountL(param, iNotificationId, 1); |
|
143 |
|
144 // Stop observing the removed note (=id changed). |
|
145 if (oldId != iNotificationId) |
|
146 { |
|
147 iNotifier->StopObserving(oldId); |
|
148 iNotifier->StartObservingL(iNotificationId, this); |
|
149 } |
|
150 |
|
151 DEBUG("CSoftNotification::ShowSoftNotificationL -"); |
|
152 } |
|
153 |
|
154 // ----------------------------------------------------------------------------- |
|
155 // CSoftNotification::RemoveSoftNotificationL |
|
156 // Cancels and removes the soft notification |
|
157 // ----------------------------------------------------------------------------- |
|
158 // |
|
159 void CSoftNotification::RemoveSoftNotificationL() |
|
160 { |
|
161 DEBUG("CSoftNotification::RemoveSoftNotificationL +"); |
|
162 |
|
163 iNotifier->CancelDynamicNotificationL(iNotificationId); |
|
164 |
|
165 DEBUG("CSoftNotification::RemoveSoftNotificationL -"); |
|
166 } |
|
167 |
|
168 // ----------------------------------------------------------------------------- |
|
169 // CSoftNotification::SetTextL |
|
170 // Sets a text for a soft notification |
|
171 // ----------------------------------------------------------------------------- |
|
172 // |
|
173 void CSoftNotification::SetTextL(const TDesC& aText, const TDesC& aGroupText) |
|
174 { |
|
175 DEBUG("CSoftNotification::SetTextL +"); |
|
176 |
|
177 HBufC* txt = aText.AllocL(); |
|
178 delete iLabel; |
|
179 iLabel = txt; |
|
180 |
|
181 txt = aGroupText.AllocL(); |
|
182 delete iGroupLabel; |
|
183 iGroupLabel = txt; |
|
184 |
|
185 DEBUG("CSoftNotification::SetTextL -"); |
|
186 } |
|
187 |
|
188 // ----------------------------------------------------------------------------- |
|
189 // CSoftNotification::SetSoftkeyLabelsL |
|
190 // Sets new labels for softkeys |
|
191 // ----------------------------------------------------------------------------- |
|
192 // |
|
193 void CSoftNotification::SetSoftkeyLabelsL( |
|
194 const TDesC& aSoftkey1Label, |
|
195 const TDesC& aSoftkey2Label) |
|
196 { |
|
197 DEBUG("CSoftNotification::SetSoftkeyLabelsL +"); |
|
198 |
|
199 HBufC* txt = aSoftkey1Label.AllocL(); |
|
200 delete iSoftkey1; |
|
201 iSoftkey1 = txt; |
|
202 |
|
203 txt = aSoftkey2Label.AllocL(); |
|
204 delete iSoftkey2; |
|
205 iSoftkey2 = txt; |
|
206 |
|
207 DEBUG("CSoftNotification::SetSoftkeyLabelsL -"); |
|
208 } |
|
209 |
|
210 // ----------------------------------------------------------------------------- |
|
211 // CSoftNotification::SetImageL |
|
212 // Sets an image for a soft notification |
|
213 // ----------------------------------------------------------------------------- |
|
214 // |
|
215 void CSoftNotification::SetImageL( |
|
216 const TDesC8& aImage) |
|
217 { |
|
218 DEBUG("CSoftNotification::SetImageL +"); |
|
219 |
|
220 HBufC8* image = aImage.AllocL(); |
|
221 delete iImageData; |
|
222 iImageData = image; |
|
223 |
|
224 DEBUG("CSoftNotification::SetImageL -"); |
|
225 } |
|
226 |
|
227 // ----------------------------------------------------------------------------- |
|
228 // CSoftNotification::Id |
|
229 // Notification Id |
|
230 // ----------------------------------------------------------------------------- |
|
231 // |
|
232 TInt CSoftNotification::Id() |
|
233 { |
|
234 DEBUG("CSoftNotification::Id"); |
|
235 |
|
236 return iNotificationId; |
|
237 } |
|
238 |
|
239 // ----------------------------------------------------------------------------- |
|
240 // CSoftNotification::SetPeerObserverL |
|
241 // ----------------------------------------------------------------------------- |
|
242 // |
|
243 void CSoftNotification::SetPeerObserver(jobject aPeer, jmethodID aMethodId) |
|
244 { |
|
245 DEBUG("CSoftNotification::SetPeerObserver"); |
|
246 |
|
247 iPeer = aPeer; |
|
248 iMethodId = aMethodId; |
|
249 } |
|
250 |
|
251 // ----------------------------------------------------------------------------- |
|
252 // CSoftNotification::RemovePeerObserverL |
|
253 // ----------------------------------------------------------------------------- |
|
254 // |
|
255 void CSoftNotification::RemovePeerObserver(JNIEnv& aJniEnv) |
|
256 { |
|
257 DEBUG("CSoftNotification::RemovePeerObserver +"); |
|
258 |
|
259 // The stored global reference has to be deleted since it is not |
|
260 // used anymore. |
|
261 if (iPeer) |
|
262 { |
|
263 aJniEnv.DeleteWeakGlobalRef((jweak)iPeer); |
|
264 } |
|
265 |
|
266 iPeer = NULL; |
|
267 iMethodId = NULL; |
|
268 |
|
269 DEBUG("CSoftNotification::RemovePeerObserver -"); |
|
270 } |
|
271 |
|
272 // ----------------------------------------------------------------------------- |
|
273 // CSoftNotification::ConstructL |
|
274 // Symbian 2nd phase constructor can leave. |
|
275 // ----------------------------------------------------------------------------- |
|
276 // |
|
277 void CSoftNotification::ConstructL() |
|
278 { |
|
279 DEBUG("CSoftNotification::ConstructL +"); |
|
280 |
|
281 iNotifier = CAknDynamicSoftNotifier::NewL(); |
|
282 |
|
283 // Try to start observing. Ignore the leave, it means that the note is |
|
284 // already observed by another instance of this class or the note is not |
|
285 // valid anymore. |
|
286 // The observing has to be started after creation so that notifications |
|
287 // are observed in every case (use case: an instance of this class is |
|
288 // created by using an id to a notification already visible on the screen). |
|
289 TRAP_IGNORE(iNotifier->StartObservingL(iNotificationId, this)); |
|
290 |
|
291 DEBUG("CSoftNotification::ConstructL -"); |
|
292 } |
|
293 |
|
294 // ----------------------------------------------------------------------------- |
|
295 // CSoftNotification::PostEventL |
|
296 // Posts an event to the Java side. |
|
297 // ----------------------------------------------------------------------------- |
|
298 // |
|
299 void CSoftNotification::PostEventL(TInt aEventId) |
|
300 { |
|
301 DEBUG("CSoftNotification::PostEventL +"); |
|
302 |
|
303 CSoftNotificationEvent* javaEvent = |
|
304 new(ELeave) CSoftNotificationEvent(iPeer, iMethodId, aEventId); |
|
305 |
|
306 // Event source takes the ownership to the event. |
|
307 iEventSource.PostEvent(javaEvent, CJavaEventBase::EEventPriority); |
|
308 |
|
309 DEBUG("CSoftNotification::PostEventL -"); |
|
310 } |
|
311 |
|
312 // ----------------------------------------------------------------------------- |
|
313 // CSoftNotification::CSoftNotification |
|
314 // C++ default constructor can NOT contain any code, that |
|
315 // might leave. |
|
316 // ----------------------------------------------------------------------------- |
|
317 // |
|
318 CSoftNotification::CSoftNotification( |
|
319 TInt aAppId, |
|
320 TInt aNotificationId, |
|
321 CSoftNotificationEventSource& aEventSource) : |
|
322 iNotificationId(aNotificationId), |
|
323 iEventSource(aEventSource) |
|
324 { |
|
325 DEBUG("CSoftNotification::CSoftNotification"); |
|
326 |
|
327 iAppId = TUid::Uid(aAppId); |
|
328 } |
|
329 |
|
330 // ----------------------------------------------------------------------------- |
|
331 // CSoftNotification::FillNotificationParams |
|
332 // ----------------------------------------------------------------------------- |
|
333 // |
|
334 void CSoftNotification::FillNotificationParams( |
|
335 TAknDynamicSoftNotificationParams& aParam) |
|
336 { |
|
337 DEBUG("CSoftNotification::FillNotificationParams +"); |
|
338 |
|
339 if (iSoftkey1 && iSoftkey2) |
|
340 { |
|
341 aParam.SetSoftkeys(*iSoftkey1, *iSoftkey2); |
|
342 } |
|
343 |
|
344 if (iLabel) |
|
345 { |
|
346 aParam.SetNoteLabels(*iLabel, *iLabel); |
|
347 } |
|
348 |
|
349 if (iGroupLabel) |
|
350 { |
|
351 aParam.SetGroupLabels(*iGroupLabel, *iGroupLabel); |
|
352 } |
|
353 |
|
354 if (iImageData) |
|
355 { |
|
356 aParam.SetImageData(*iImageData); |
|
357 } |
|
358 |
|
359 TVwsViewId view(iAppId, iAppId); |
|
360 aParam.SetViewActivationParams(view); |
|
361 aParam.EnableObserver(); |
|
362 |
|
363 DEBUG("CSoftNotification::FillNotificationParams -"); |
|
364 } |
|
365 |
|
366 // End of File |