|
1 /* |
|
2 * Copyright (c) 2002 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: Bluetooth visibility timeout notifier class. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 // INCLUDE FILES |
|
20 |
|
21 #include <StringLoader.h> // Localisation stringloader |
|
22 #include <SecondaryDisplay/BTnotifSecondaryDisplayAPI.h> |
|
23 #include <e32cmn.h> |
|
24 #include <BTNotif.rsg> // Own resources |
|
25 #include <btengsettings.h> |
|
26 #include "BTNGenericQueryNotifier.h" // Own class definition |
|
27 #include "btNotifDebug.h" // Debugging macros |
|
28 |
|
29 #ifdef __SERIES60_HELP |
|
30 #include <hlplch.h> |
|
31 #include <csxhelp/bt.hlp.hrh> // The bt hrh info is needed, for help launching |
|
32 #endif |
|
33 |
|
34 // ================= MEMBER FUNCTIONS ======================= |
|
35 |
|
36 // ---------------------------------------------------------- |
|
37 // CBTGenericQueryNotifier::NewL |
|
38 // Two-phased constructor. |
|
39 // ---------------------------------------------------------- |
|
40 // |
|
41 CBTGenericQueryNotifier* CBTGenericQueryNotifier::NewL() |
|
42 { |
|
43 CBTGenericQueryNotifier* self=new (ELeave) CBTGenericQueryNotifier(); |
|
44 CleanupStack::PushL(self); |
|
45 self->ConstructL(); |
|
46 CleanupStack::Pop(); |
|
47 return self; |
|
48 } |
|
49 |
|
50 // ---------------------------------------------------------- |
|
51 // CBTGenericQueryNotifier::CBTGenericQueryNotifier |
|
52 // C++ default constructor can NOT contain any code, that |
|
53 // might leave. |
|
54 // ---------------------------------------------------------- |
|
55 // |
|
56 CBTGenericQueryNotifier::CBTGenericQueryNotifier() |
|
57 { |
|
58 } |
|
59 |
|
60 // ---------------------------------------------------------- |
|
61 // Destructor |
|
62 // ---------------------------------------------------------- |
|
63 // |
|
64 CBTGenericQueryNotifier::~CBTGenericQueryNotifier() |
|
65 { |
|
66 Cancel(); // Free own resources |
|
67 delete iName; |
|
68 delete iQueryMessage; |
|
69 delete iQueryHeader; |
|
70 } |
|
71 |
|
72 // ---------------------------------------------------------- |
|
73 // CBTGenericQueryNotifier::RegisterL |
|
74 // Register notifier. |
|
75 // ---------------------------------------------------------- |
|
76 // |
|
77 CBTGenericQueryNotifier::TNotifierInfo CBTGenericQueryNotifier::RegisterL() |
|
78 { |
|
79 iInfo.iUid=KBTGenericQueryNotifierUid; |
|
80 iInfo.iChannel=KBTGenericQueryNotifierUid; |
|
81 iInfo.iPriority=ENotifierPriorityHigh; |
|
82 return iInfo; |
|
83 } |
|
84 |
|
85 |
|
86 // ---------------------------------------------------------- |
|
87 // CBTGenericQueryNotifier::StartL |
|
88 // Synchronic notifier launch. Contructs and shows a global |
|
89 // note, no parameters need here. |
|
90 // ---------------------------------------------------------- |
|
91 // |
|
92 TPtrC8 CBTGenericQueryNotifier::StartL( const TDesC8& /*aBuffer*/ ) |
|
93 { |
|
94 FLOG(_L("[BTNOTIF]\t CBTGenericQueryNotifier::StartL()")); |
|
95 |
|
96 TPtrC8 ret(KNullDesC8); |
|
97 return (ret); |
|
98 |
|
99 } |
|
100 |
|
101 // ---------------------------------------------------------- |
|
102 // CBTGenericQueryNotifier::GetParamsL |
|
103 // Mandatory for BT Notifiers when using asynchronous launch. |
|
104 // This notifier is synchronous so no implementation is needed. |
|
105 // ---------------------------------------------------------- |
|
106 // |
|
107 void CBTGenericQueryNotifier::GetParamsL(const TDesC8& aBuffer, |
|
108 TInt aReplySlot, |
|
109 const RMessagePtr2& aMessage) |
|
110 { |
|
111 FLOG(_L("[BTNOTIF]\t CBTGenericQueryNotifier::GetParamsL")); |
|
112 |
|
113 if (iMessage.Handle()) |
|
114 { |
|
115 aMessage.Complete(KErrInUse); |
|
116 return; |
|
117 } |
|
118 |
|
119 ProcessParamBufferL(aBuffer); |
|
120 |
|
121 iMessage = aMessage; |
|
122 iReplySlot = aReplySlot; |
|
123 |
|
124 ShowQueryAndCompleteL(); |
|
125 |
|
126 FLOG(_L("[BTNOTIF]\t CBTGenericQueryNotifier::GetParamsL Complete")); |
|
127 } |
|
128 |
|
129 // ---------------------------------------------------------- |
|
130 // CBTGenericQueryNotifier::ProcessParamBufferL |
|
131 // Parse the data out of the message that is sent by the |
|
132 // client of the notifier. |
|
133 // ---------------------------------------------------------- |
|
134 void CBTGenericQueryNotifier::ProcessParamBufferL(const TDesC8& aBuffer) |
|
135 { |
|
136 |
|
137 TBTGenericQueryNotifierParams bParams; |
|
138 TPckgC<TBTGenericQueryNotifierParams> bPckg(bParams); |
|
139 bPckg.Set( aBuffer ); |
|
140 |
|
141 if( bPckg().iMessageType == EBTNameQuery ) |
|
142 { |
|
143 iIsNameQuery = ETrue; |
|
144 return; |
|
145 } |
|
146 iSecondaryDisplayCommand = ECmdBTnotifUnavailable; |
|
147 switch (bPckg().iMessageType) |
|
148 { |
|
149 case EBTReceiveMessageQuery: |
|
150 iIsMessageQuery=EFalse; |
|
151 iMessageResourceId=R_BT_RECEIVE_MESSAGE ; |
|
152 iSecondaryDisplayCommand=ECmdShowReceiveMessageFromDeviceDlg; |
|
153 break; |
|
154 case EBTReceiveMessagePairedQuery: |
|
155 iIsMessageQuery=EFalse; |
|
156 iMessageResourceId=R_BT_RECEIVE_MESSAGE_PAIRED; |
|
157 iSecondaryDisplayCommand= ECmdShowReceiveMessageFromPairedDeviceDlg; |
|
158 break; |
|
159 case EBTIsOffQuery: |
|
160 iIsMessageQuery=EFalse; |
|
161 iMessageResourceId=R_BT_POWER_IS_OFF ; |
|
162 iSecondaryDisplayCommand=ECmdShowBtIsOffDlg; |
|
163 break; |
|
164 case EBTActivateOffLineQuery: |
|
165 iIsMessageQuery=EFalse; |
|
166 iMessageResourceId=R_BT_ACTIVATE_IN_OFFLINE; |
|
167 iSecondaryDisplayCommand=ECmdShowBtActivateInOfflineDlg; |
|
168 break; |
|
169 case EBTNoDevicesFoundQuery: |
|
170 iIsMessageQuery=EFalse; |
|
171 iMessageResourceId=R_BT_NO_DEVICES_FOUND; |
|
172 break; |
|
173 case EBTAcceptRequestQuery: |
|
174 iIsMessageQuery=EFalse; |
|
175 iMessageResourceId=R_BT_AUTHORISATION_NAME ; |
|
176 iSecondaryDisplayCommand=ECmdShowAcceptConnRequestDlg; |
|
177 break; |
|
178 |
|
179 case EBTIsOffJavaQuery: |
|
180 iIsMessageQuery=ETrue; |
|
181 if( bPckg().iNameExists ) |
|
182 { |
|
183 iMessageResourceId=R_BT_IS_OFF_JAVA_APPNAME; // when caller provide Java application name. |
|
184 } |
|
185 else |
|
186 { |
|
187 iMessageResourceId=R_BT_IS_OFF_JAVA; //r_bt_is_hidden_java |
|
188 } |
|
189 iSecondaryDisplayCommand=ECmdShowBtBtIsOffJavaDlg; |
|
190 iQueryHeader=StringLoader::LoadL( R_BT_IS_OFF_JAVA_HEADER); |
|
191 break; |
|
192 |
|
193 case EBTIsNotShownQuery: |
|
194 iIsMessageQuery=ETrue; |
|
195 if( bPckg().iNameExists ) |
|
196 { |
|
197 iMessageResourceId=R_BT_IS_HIDDEN_JAVA_APPNAME; // when caller provide Java application name. |
|
198 } |
|
199 else |
|
200 { |
|
201 iMessageResourceId=R_BT_IS_HIDDEN_JAVA; //r_bt_is_hidden_java |
|
202 } |
|
203 iSecondaryDisplayCommand=ECmdShowBtIsNotVisibleDlg; |
|
204 iQueryHeader=StringLoader::LoadL( R_BT_IS_HIDDEN_JAVA_HEADER); |
|
205 break; |
|
206 |
|
207 case EBTBlockConnectionQuery: |
|
208 case EBTBlockPairedConnectionQuery: |
|
209 iIsMessageQuery=ETrue; |
|
210 if( bPckg().iMessageType == EBTBlockConnectionQuery ) |
|
211 iMessageResourceId = R_BT_BLOCK_DEVICE_NOHELP; |
|
212 else |
|
213 iMessageResourceId = R_BT_BLOCK_PAIRED_DEVICE_NOHELP ; |
|
214 |
|
215 iQueryHeader= StringLoader::LoadL( R_BT_BLOCK_DEVICE_HEADER ); |
|
216 break; |
|
217 |
|
218 case EBTSwitchOffAnyway: |
|
219 iIsMessageQuery=EFalse; |
|
220 iMessageResourceId=R_BT_SWITCH_OFF_ANYWAY; |
|
221 break; |
|
222 |
|
223 default: |
|
224 FLOG(_L("[BTNOTIF]\t CBTGenericQueryNotifier:: Unkown messageType! ")); |
|
225 User::Leave(KErrNotFound); |
|
226 } |
|
227 |
|
228 // if the logic string contains substitute indicator "%U", replace it with device name: |
|
229 // |
|
230 iQueryMessage = StringLoader::LoadL( iMessageResourceId); |
|
231 _LIT(PU,"%U"); |
|
232 if( iQueryMessage->Find(PU) != KErrNotFound) |
|
233 { |
|
234 delete iQueryMessage; |
|
235 iQueryMessage=NULL; |
|
236 |
|
237 //if no device name provided, default name will be used: |
|
238 if( !bPckg().iNameExists ) |
|
239 iName=StringLoader::LoadL(R_BT_DIALOG_DEF_NAME); |
|
240 else |
|
241 { |
|
242 iName=HBufC::NewL(bPckg().iName.Length() ); |
|
243 iName->Des().Copy(bPckg().iName); |
|
244 } |
|
245 iQueryMessage = StringLoader::LoadL( iMessageResourceId,*iName); |
|
246 } |
|
247 else |
|
248 { |
|
249 iName=NULL; |
|
250 } |
|
251 } |
|
252 |
|
253 // ---------------------------------------------------------- |
|
254 // CBTGenericQueryNotifier::UpdateL |
|
255 // Update notifier according to new data |
|
256 // ---------------------------------------------------------- |
|
257 // |
|
258 TPtrC8 CBTGenericQueryNotifier::UpdateL(const TDesC8& aBuffer) |
|
259 { |
|
260 FLOG(_L("[BTNOTIF]\t CBTGenericQueryNotifier::UpdateL")); |
|
261 delete iQueryMessage; |
|
262 iQueryMessage = NULL; |
|
263 ProcessParamBufferL(aBuffer); |
|
264 if( !iNotifUiUtil->IsQueryReleased() ) |
|
265 { |
|
266 if(iIsMessageQuery ) |
|
267 { |
|
268 iNotifUiUtil->UpdateMessageQueryDlgL(*iQueryMessage); |
|
269 } |
|
270 else |
|
271 { |
|
272 iNotifUiUtil->UpdateQueryDlgL(*iQueryMessage); |
|
273 } |
|
274 } |
|
275 FLOG(_L("[BTNOTIF]\t CBTGenericQueryNotifier::UpdateL complete")); |
|
276 |
|
277 TPtrC8 ret(KNullDesC8); |
|
278 return (ret); |
|
279 } |
|
280 |
|
281 // ---------------------------------------------------------- |
|
282 // CBTGenericQueryNotifier::ShowQueryAndCompleteL |
|
283 // Shows the notifier in backround and complete message |
|
284 // ---------------------------------------------------------- |
|
285 // |
|
286 void CBTGenericQueryNotifier::ShowQueryAndCompleteL() |
|
287 { |
|
288 FLOG(_L("[BTNOTIF]\t CBTGenericQueryNotifier::ShowQueryAndCompleteL")); |
|
289 |
|
290 // Turn lights on and deactivate apps -key |
|
291 // |
|
292 iNotifUiUtil->TurnLightsOn(); |
|
293 if( iIsNameQuery ) |
|
294 { |
|
295 TBool nameStatus = IsLocalNameModifiedL(); |
|
296 if( !nameStatus ) |
|
297 { |
|
298 (void) AskLocalBTNameQueryL(); |
|
299 } |
|
300 // Check if Local name is set again before turn BT on. |
|
301 // Turn BT on only when there is local name, since user still has chance |
|
302 // to ignore the asking name query - like pressing End-key |
|
303 // |
|
304 TBTDeviceName localName; |
|
305 localName.Zero(); |
|
306 TInt err = iBTEngSettings->GetLocalName(localName); |
|
307 |
|
308 if (localName.Length() <= 0) |
|
309 { |
|
310 err = KErrCancel; |
|
311 } |
|
312 |
|
313 CompleteMessage( (!err) ? ETrue : EFalse, KErrNone ); |
|
314 |
|
315 FLOG(_L("[BTNOTIF]\t CBTGenericQueryNotifier::ShowQueryAndCompleteL iIsNameQuery complete")); |
|
316 return; |
|
317 } |
|
318 |
|
319 TInt keypress; |
|
320 TBTDeviceName name(KNullDesC); |
|
321 if( iName ) |
|
322 { |
|
323 name.Copy( *iName ); |
|
324 } |
|
325 if( iIsMessageQuery ) |
|
326 { |
|
327 |
|
328 keypress = iNotifUiUtil->ShowMessageQueryL(*iQueryMessage, *iQueryHeader, |
|
329 R_BT_GENERIC_MESSAGE_QUERY, CAknQueryDialog::EConfirmationTone ); |
|
330 } |
|
331 else |
|
332 { |
|
333 keypress = iNotifUiUtil->ShowQueryL( *iQueryMessage, R_BT_GENERIC_QUERY, |
|
334 iSecondaryDisplayCommand, name, CAknQueryDialog::EConfirmationTone ); |
|
335 } |
|
336 |
|
337 CompleteMessage( (keypress) ? ETrue: EFalse, KErrNone ); |
|
338 |
|
339 FLOG(_L("[BTNOTIF]\t CBTGenericQueryNotifier::ShowQueryAndCompleteL complete")); |
|
340 } |
|
341 |
|
342 // End of File |