|
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: Declares Utility to show UI notes and queries. |
|
15 * |
|
16 */ |
|
17 |
|
18 #include <bautils.h> // BAFL utils (for language file) |
|
19 #include "btnotifuiutil.h" |
|
20 #include "btNotifDebug.h" // Debugging macros |
|
21 #include <StringLoader.h> // Localisation stringloader |
|
22 #include <aknnotewrappers.h> // Information note |
|
23 #include <aknmessagequerydialog.h> // for the blocking query |
|
24 #include <AknMediatorFacade.h> // CoverUI |
|
25 #include <coreapplicationuisdomainpskeys.h> // Backlight control |
|
26 #include <AknNotiferAppServerApplication.h> // Application Key enable/disable |
|
27 |
|
28 CBTNotifUIUtil* CBTNotifUIUtil::NewL( TBool aCoverDisplayEnabled ) |
|
29 { |
|
30 CBTNotifUIUtil* self = new (ELeave) CBTNotifUIUtil( aCoverDisplayEnabled ); |
|
31 CleanupStack::PushL( self ); |
|
32 self->ConstructL(); |
|
33 CleanupStack::Pop( self ); |
|
34 return self; |
|
35 } |
|
36 |
|
37 CBTNotifUIUtil::CBTNotifUIUtil( TBool aCoverDisplayEnabled ) : |
|
38 iCoverDisplayEnabled( aCoverDisplayEnabled ), |
|
39 iSystemCancel( EFalse ), |
|
40 iAppKeyBlocked( EFalse ) |
|
41 { |
|
42 } |
|
43 |
|
44 void CBTNotifUIUtil::ConstructL() |
|
45 { |
|
46 iEikEnv = CEikonEnv::Static(); |
|
47 |
|
48 TFileName filename; |
|
49 filename += KFileDrive; |
|
50 filename += KDC_RESOURCE_FILES_DIR; |
|
51 filename += KResourceFileName; |
|
52 BaflUtils::NearestLanguageFile(iEikEnv->FsSession(),filename); |
|
53 iResourceFileFlag=iEikEnv->AddResourceFileL(filename); |
|
54 } |
|
55 |
|
56 CBTNotifUIUtil::~CBTNotifUIUtil() |
|
57 { |
|
58 iSystemCancel = ETrue; |
|
59 delete iQueryDlg; |
|
60 delete iWaitDlg; |
|
61 // Activate apps key again before exit, in case any interruption happens before activation |
|
62 if( iAppKeyBlocked ) |
|
63 { |
|
64 FLOG(_L("[BTNOTIF]\t CBTNotifUIUtil destructor Activate apps key before exiting. ")); |
|
65 (void) ((CAknNotifierAppServerAppUi*)iEikEnv->EikAppUi())->SuppressAppSwitching(EFalse); |
|
66 } |
|
67 iEikEnv->DeleteResourceFile(iResourceFileFlag); |
|
68 } |
|
69 // ---------------------------------------------------------- |
|
70 // CBTNotifierBase::TurnLightsOn |
|
71 // ---------------------------------------------------------- |
|
72 // |
|
73 void CBTNotifUIUtil::TurnLightsOn() |
|
74 { |
|
75 // Change the bit on and off. SysAp will detect that |
|
76 // the lights should be switched on for the specified time. |
|
77 // |
|
78 TInt err = KErrNone; |
|
79 |
|
80 err = RProperty::Set(KPSUidCoreApplicationUIs, KLightsControl, ELightsOn); |
|
81 err = RProperty::Set(KPSUidCoreApplicationUIs, KLightsControl, ELightsOff); |
|
82 |
|
83 if ( err != KErrNone ) |
|
84 { |
|
85 FTRACE(FPrint(_L("[BTNOTIF]\t CBTNotifUIUtil::TurnLightsOn() RProperty::Set return error %d"), err )); |
|
86 } |
|
87 |
|
88 FLOG(_L("[BTNOTIF]\t CBTNotifUIUtil::TurnLightsOn() <<")); |
|
89 } |
|
90 |
|
91 // ---------------------------------------------------------- |
|
92 // CBTNotifierBase::LocalEikonEnv |
|
93 // ---------------------------------------------------------- |
|
94 // |
|
95 CEikonEnv& CBTNotifUIUtil::LocalEikonEnv() |
|
96 { |
|
97 return *iEikEnv; |
|
98 } |
|
99 |
|
100 // ---------------------------------------------------------- |
|
101 // CBTNotifierBase::ShowQueryL |
|
102 // ---------------------------------------------------------- |
|
103 // |
|
104 TInt CBTNotifUIUtil::ShowQueryL(TInt aPromptResource, TInt aExecuteResource, |
|
105 TSecondaryDisplayBTnotifDialogs aDialogId, CAknQueryDialog::TTone aTone ) |
|
106 { |
|
107 TInt ret; |
|
108 TBTDeviceName name( KNullDesC ); |
|
109 if ( aPromptResource ) |
|
110 { |
|
111 HBufC* prompt = StringLoader::LoadLC( aPromptResource ); |
|
112 ret = ShowQueryL(*prompt, aExecuteResource, aDialogId, name, aTone ); |
|
113 CleanupStack::PopAndDestroy( prompt ); |
|
114 } |
|
115 else |
|
116 { |
|
117 ret = ShowQueryL(KNullDesC, aExecuteResource, aDialogId, name, aTone ); |
|
118 } |
|
119 return ret; |
|
120 } |
|
121 |
|
122 TInt CBTNotifUIUtil::ShowQueryL(const TDesC& aPrompt, TInt aExecuteResource, |
|
123 TSecondaryDisplayBTnotifDialogs aDialogId, const TBTDeviceName& aDevNameInCoverUi, CAknQueryDialog::TTone aTone ) |
|
124 { |
|
125 FLOG(_L("[BTNOTIF]\t CBTNotifUIUtil::ShowQueryL >>")); |
|
126 __ASSERT_DEBUG( iQueryDlg == NULL, |
|
127 User::Panic(_L("CBTNotifier iQueryDlg not released!"),KErrAlreadyExists)); |
|
128 |
|
129 iQueryDlg = CAknQueryDialog::NewL(aTone); |
|
130 if( iCoverDisplayEnabled && aDialogId != ECmdBTnotifUnavailable) |
|
131 { |
|
132 // initializes cover support |
|
133 iQueryDlg->PublishDialogL(aDialogId, KUidCoverUiCategoryBTnotif ); |
|
134 CoverUIDisplayL( iQueryDlg, aDevNameInCoverUi ); |
|
135 } |
|
136 |
|
137 // Deactivate apps key |
|
138 // we can do nothing if this operation fails |
|
139 (void) ((CAknNotifierAppServerAppUi*)iEikEnv->EikAppUi())->SuppressAppSwitching(ETrue); |
|
140 iAppKeyBlocked = ETrue; |
|
141 TurnLightsOn(); |
|
142 iQueryDlg->SetFocus( ETrue ); |
|
143 |
|
144 TInt keypress; |
|
145 if ( aPrompt.Length() ) |
|
146 { |
|
147 keypress = iQueryDlg->ExecuteLD(aExecuteResource, aPrompt ); |
|
148 } |
|
149 else |
|
150 { |
|
151 keypress = iQueryDlg->ExecuteLD( aExecuteResource ); |
|
152 } |
|
153 |
|
154 iQueryDlg = NULL; |
|
155 if( !iSystemCancel ) |
|
156 { // Activate apps key when no external cancellation happens |
|
157 (void) ((CAknNotifierAppServerAppUi*)iEikEnv->EikAppUi())->SuppressAppSwitching(EFalse); |
|
158 iAppKeyBlocked = EFalse; |
|
159 } |
|
160 |
|
161 FTRACE(FPrint(_L("[BTNOTIF]\t CBTNotifUIUtil::ShowQueryL keypress %d <<"), keypress ) ); |
|
162 return keypress; |
|
163 } |
|
164 |
|
165 TInt CBTNotifUIUtil::ShowMessageQueryL(TDesC& aMessage, const TDesC& aHeader, |
|
166 TInt aResourceId, CAknQueryDialog::TTone aTone ) |
|
167 { |
|
168 FLOG(_L("[BTNOTIF]\t CBTNotifUIUtil::ShowMessageQueryL >>")); |
|
169 __ASSERT_DEBUG( iQueryDlg == NULL, |
|
170 User::Panic(_L("CBTNotifier iQueryDlg not released!"),KErrAlreadyExists)); |
|
171 |
|
172 iQueryDlg = CAknMessageQueryDialog::NewL( aMessage, aTone ); |
|
173 iQueryDlg->PrepareLC( aResourceId ); |
|
174 if( aHeader.Length() ) |
|
175 { |
|
176 static_cast<CAknMessageQueryDialog*>(iQueryDlg)->Heading()->SetTextL( aHeader ); |
|
177 } |
|
178 |
|
179 // Deactivate apps key |
|
180 // we can do nothing if this operation fails |
|
181 (void) ((CAknNotifierAppServerAppUi*)iEikEnv->EikAppUi())->SuppressAppSwitching(ETrue); |
|
182 iAppKeyBlocked = ETrue; |
|
183 TurnLightsOn(); |
|
184 iQueryDlg->SetFocus( ETrue ); |
|
185 TInt keypress = iQueryDlg->RunLD(); |
|
186 iQueryDlg = NULL; |
|
187 |
|
188 if( !iSystemCancel ) |
|
189 { // Activate apps key when no external cancellation happens |
|
190 (void) ((CAknNotifierAppServerAppUi*)iEikEnv->EikAppUi())->SuppressAppSwitching(EFalse); |
|
191 iAppKeyBlocked = EFalse; |
|
192 } |
|
193 |
|
194 FTRACE(FPrint(_L("[BTNOTIF]\t CBTNotifUIUtil::ShowMessageQueryL keypress %d <<"), keypress ) ); |
|
195 return keypress; |
|
196 } |
|
197 |
|
198 |
|
199 TInt CBTNotifUIUtil::ShowTextInputQueryL(TDes& aText, TInt aExecuteResource, |
|
200 TSecondaryDisplayBTnotifDialogs aDialogId, |
|
201 CAknQueryDialog::TTone aTone ) |
|
202 { |
|
203 return ShowTextInputQueryL(aText, KNullDesC, aExecuteResource, aDialogId, aTone); |
|
204 } |
|
205 |
|
206 TInt CBTNotifUIUtil::ShowTextInputQueryL(TDes& aText, const TDesC& aPrompt, TInt aExecuteResource, |
|
207 TSecondaryDisplayBTnotifDialogs aDialogId, |
|
208 CAknQueryDialog::TTone aTone ) |
|
209 { |
|
210 FLOG(_L("[BTNOTIF]\t CBTNotifUIUtil::ShowTextInputQueryL >>")); |
|
211 |
|
212 __ASSERT_DEBUG( iQueryDlg == NULL, |
|
213 User::Panic(_L("CBTNotifier iQueryDlg not released!"),KErrAlreadyExists)); |
|
214 |
|
215 iQueryDlg = CAknTextQueryDialog::NewL( aText, aTone ); |
|
216 if( iCoverDisplayEnabled && aDialogId != ECmdBTnotifUnavailable) |
|
217 { |
|
218 // initializes cover support |
|
219 iQueryDlg->PublishDialogL(aDialogId, KUidCoverUiCategoryBTnotif ); |
|
220 } |
|
221 if ( aPrompt.Length() ) |
|
222 { |
|
223 iQueryDlg->SetPromptL( aPrompt ); |
|
224 } |
|
225 |
|
226 // Deactivate apps key |
|
227 // we can do nothing if this operation fails |
|
228 (void) ((CAknNotifierAppServerAppUi*)iEikEnv->EikAppUi())->SuppressAppSwitching(ETrue); |
|
229 iAppKeyBlocked = ETrue; |
|
230 TurnLightsOn(); |
|
231 iQueryDlg->SetFocus( ETrue ); |
|
232 TInt keypress = iQueryDlg->ExecuteLD( aExecuteResource ); |
|
233 iQueryDlg = NULL; |
|
234 |
|
235 if( !iSystemCancel ) |
|
236 { // Activate apps key when no external cancellation happens |
|
237 (void) ((CAknNotifierAppServerAppUi*)iEikEnv->EikAppUi())->SuppressAppSwitching(EFalse); |
|
238 iAppKeyBlocked = EFalse; |
|
239 } |
|
240 |
|
241 FTRACE(FPrint(_L("[BTNOTIF]\t CBTNotifUIUtil::ShowTextInputQueryL txt '%S' keypress %d <<"), |
|
242 &aText, keypress ) ); |
|
243 return keypress; |
|
244 } |
|
245 |
|
246 void CBTNotifUIUtil::ShowInfoNoteL( |
|
247 TInt aResourceId, TSecondaryDisplayBTnotifDialogs aDialogId ) |
|
248 { |
|
249 // Load a string, create and show a note |
|
250 HBufC* stringHolder = StringLoader::LoadLC( aResourceId ); |
|
251 ShowInfoNoteL( *stringHolder, aDialogId ); |
|
252 CleanupStack::PopAndDestroy(); //stringHolder |
|
253 } |
|
254 |
|
255 |
|
256 void CBTNotifUIUtil::ShowInfoNoteL( |
|
257 const TDesC& aResource, TSecondaryDisplayBTnotifDialogs aDialogId ) |
|
258 { |
|
259 FTRACE(FPrint(_L("[BTNOTIF]\t CBTNotifUIUtil::ShowInfoNoteL '%S' >> "), |
|
260 &aResource ) ); |
|
261 CAknInformationNote* note = new (ELeave) CAknInformationNote(); |
|
262 if(iCoverDisplayEnabled && aDialogId != ECmdBTnotifUnavailable) |
|
263 { |
|
264 CleanupStack::PushL( note ); |
|
265 // initializes cover support |
|
266 note->PublishDialogL(aDialogId, KUidCoverUiCategoryBTnotif ); |
|
267 CleanupStack::Pop(note); |
|
268 } |
|
269 note->ExecuteLD( aResource ); |
|
270 FLOG(_L("[BTNOTIF]\t CBTNotifUIUtil::ShowInfoNoteL done <<")); |
|
271 } |
|
272 |
|
273 void CBTNotifUIUtil::ShowConfirmationNoteL( TBool aWaitingDlg, const TDesC& aResource, |
|
274 TSecondaryDisplayBTnotifDialogs aDialogId, const TBTDeviceName& aDevNameInCoverUi ) |
|
275 { |
|
276 FLOG(_L("[BTNOTIF]\t CBTNotifUIUtil::ShowConfirmationNoteL >>")); |
|
277 CAknConfirmationNote* note = new (ELeave) CAknConfirmationNote( aWaitingDlg ); |
|
278 |
|
279 if(iCoverDisplayEnabled && aDialogId != ECmdBTnotifUnavailable) |
|
280 { |
|
281 CleanupStack::PushL( note ); |
|
282 // initializes cover support |
|
283 note->PublishDialogL(aDialogId, KUidCoverUiCategoryBTnotif ); |
|
284 CoverUIDisplayL( note, aDevNameInCoverUi ); |
|
285 CleanupStack::Pop(note); |
|
286 } |
|
287 TurnLightsOn(); |
|
288 note->ExecuteLD( aResource ); |
|
289 FLOG(_L("[BTNOTIF]\t CBTNotifUIUtil::ShowConfirmationNoteL done <<")); |
|
290 } |
|
291 |
|
292 void CBTNotifUIUtil::ShowErrorNoteL( TBool aWaitingDlg, const TDesC& aResource, |
|
293 TSecondaryDisplayBTnotifDialogs aDialogId, TBTDeviceName aDevNameInCoverUi ) |
|
294 { |
|
295 FLOG(_L("[BTNOTIF]\t CBTNotifUIUtil::ShowErrorNoteL >>")); |
|
296 CAknErrorNote* note = new (ELeave) CAknErrorNote( aWaitingDlg ); |
|
297 if(iCoverDisplayEnabled && aDialogId != ECmdBTnotifUnavailable) |
|
298 { |
|
299 CleanupStack::PushL( note ); |
|
300 // initializes cover support |
|
301 note->PublishDialogL(aDialogId, KUidCoverUiCategoryBTnotif ); |
|
302 CoverUIDisplayL( note, aDevNameInCoverUi ); |
|
303 CleanupStack::Pop(note); |
|
304 } |
|
305 TurnLightsOn(); |
|
306 note->ExecuteLD( aResource ); |
|
307 FLOG(_L("[BTNOTIF]\t CBTNotifUIUtil::ShowErrorNoteL done <<")); |
|
308 } |
|
309 |
|
310 // ---------------------------------------------------------- |
|
311 // CBTNotifUIUtil::IsQueryReleased |
|
312 // Check if iQueryDlg is NULL |
|
313 // ---------------------------------------------------------- |
|
314 // |
|
315 TBool CBTNotifUIUtil::IsQueryReleased() |
|
316 { |
|
317 return ( iQueryDlg ) ? EFalse : ETrue; |
|
318 } |
|
319 |
|
320 // ---------------------------------------------------------- |
|
321 // CBTNotifUIUtil::UpdateQueryDlgL |
|
322 // Update Query with specified info, called by UpdateL() |
|
323 // ---------------------------------------------------------- |
|
324 // |
|
325 void CBTNotifUIUtil::UpdateQueryDlgL( TDesC& aMessage ) |
|
326 { |
|
327 __ASSERT_DEBUG( iQueryDlg != NULL, |
|
328 User::Panic(_L("CBTNotifier iQueryDlg not exist to update!"),KErrNotFound)); |
|
329 iQueryDlg->SetPromptL( aMessage ); |
|
330 iQueryDlg->DrawDeferred(); |
|
331 } |
|
332 |
|
333 // ---------------------------------------------------------- |
|
334 // CBTNotifUIUtil::UpdateMessageQueryDlgL |
|
335 // Update message query when RNotifier::UpdateL() is called |
|
336 // ---------------------------------------------------------- |
|
337 // |
|
338 void CBTNotifUIUtil::UpdateMessageQueryDlgL( TDesC& aMessage ) |
|
339 { |
|
340 __ASSERT_DEBUG( iQueryDlg != NULL, |
|
341 User::Panic(_L("CBTNotifier CAknTextQueryDialog iQueryDlg not exist to update!"),KErrNotFound)); |
|
342 static_cast<CAknMessageQueryDialog*>(iQueryDlg)->SetMessageTextL( aMessage ); |
|
343 iQueryDlg->DrawDeferred(); |
|
344 FLOG(_L("[BTNOTIF]\t CBTNotifUIUtil::UpdateMessageQueryDlg ")); |
|
345 } |
|
346 |
|
347 // ---------------------------------------------------------- |
|
348 // CBTNotifUIUtil::UpdateCoverUiL |
|
349 // Update secondary display |
|
350 // ---------------------------------------------------------- |
|
351 // |
|
352 void CBTNotifUIUtil::UpdateCoverUiL( const TDesC8& aMessage ) |
|
353 { |
|
354 FLOG(_L("[BTNOTIF]\t CBTNotifUIUtil::UpdateCoverUiL >>")); |
|
355 __ASSERT_DEBUG( iQueryDlg != NULL, |
|
356 User::Panic(_L("CBTNotifier iQueryDlg not exist to update!"),KErrNotFound)); |
|
357 if(iCoverDisplayEnabled ) |
|
358 { |
|
359 CAknMediatorFacade* coverData = AknMediatorFacade(iQueryDlg); |
|
360 if(coverData) |
|
361 { |
|
362 coverData->ResetBuffer(); |
|
363 coverData->BufStream() << aMessage; // insert your buffer here |
|
364 coverData->BufStream().CommitL(); |
|
365 coverData->PostUpdatedDataL(); |
|
366 } |
|
367 } |
|
368 FLOG(_L("[BTNOTIF]\t CBTNotifUIUtil::UpdateCoverUiL done <<")); |
|
369 } |
|
370 |
|
371 void CBTNotifUIUtil::DismissDialog() |
|
372 { |
|
373 if( !IsQueryReleased() ) |
|
374 { |
|
375 delete iQueryDlg; |
|
376 iQueryDlg = NULL; |
|
377 } |
|
378 } |
|
379 |
|
380 void CBTNotifUIUtil::CoverUIDisplayL( const MObjectProvider* aMop, |
|
381 const TBTDeviceName& aDevNameInCoverUi ) |
|
382 { |
|
383 FLOG(_L("[BTNOTIF]\t CBTNotifUIUtil::CoverUIDisplayL() >>")); |
|
384 |
|
385 CAknMediatorFacade* covercl = AknMediatorFacade( aMop ); |
|
386 if( covercl && aDevNameInCoverUi.Length() ) |
|
387 { |
|
388 covercl->BufStream() << aDevNameInCoverUi; |
|
389 covercl->BufStream().CommitL(); // no more data to send so commit buf |
|
390 } |
|
391 |
|
392 FLOG(_L("[BTNOTIF]\t CBTNotifUIUtil::CoverUIDisplayL() <<")); |
|
393 } |
|
394 |
|
395 TInt CBTNotifUIUtil::ShowWaitDlgL( TInt aResourceId ) |
|
396 { |
|
397 FLOG(_L("[BTNOTIF]\t CBTNotifUIUtil::ShowWaitDlgL() >>")); |
|
398 iWaitDlg = new(ELeave) CAknWaitDialog((REINTERPRET_CAST(CEikDialog**,&iWaitDlg)), ETrue ); |
|
399 TInt ret = iWaitDlg->ExecuteLD(aResourceId); |
|
400 FLOG(_L("[BTNOTIF]\t CBTNotifUIUtil::ShowWaitDlgL() <<")); |
|
401 return ret; |
|
402 } |
|
403 |
|
404 void CBTNotifUIUtil::CompleteWaitDlgL() |
|
405 { |
|
406 FLOG(_L("[BTNOTIF]\t CBTNotifUIUtil::CompleteWaitDlgL() >>")); |
|
407 if(iWaitDlg) |
|
408 { |
|
409 iWaitDlg->ProcessFinishedL(); |
|
410 } |
|
411 FLOG(_L("[BTNOTIF]\t CBTNotifUIUtil::CompleteWaitDlgL() <<")); |
|
412 } |