29
|
1 |
/*
|
|
2 |
* ============================================================================
|
|
3 |
* Name : bluetoothnotification.cpp
|
|
4 |
* Part of : bluetoothengine / btnotif
|
|
5 |
* Description : Class for managing an actual user notification or query.
|
|
6 |
* It hides UI framework-specifics in a private class.
|
|
7 |
*
|
|
8 |
* Copyright © 2009 Nokia Corporation and/or its subsidiary(-ies).
|
|
9 |
* All rights reserved.
|
|
10 |
* This component and the accompanying materials are made available
|
|
11 |
* under the terms of "Eclipse Public License v1.0"
|
|
12 |
* which accompanies this distribution, and is available
|
|
13 |
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
|
|
14 |
*
|
|
15 |
* Initial Contributors:
|
|
16 |
* Nokia Corporation - initial contribution.
|
|
17 |
*
|
|
18 |
* Contributors:
|
|
19 |
* Nokia Corporation
|
|
20 |
* ============================================================================
|
|
21 |
* Template version: 4.1
|
|
22 |
*/
|
|
23 |
|
|
24 |
#include "bluetoothnotification.h"
|
|
25 |
#include <hb/hbcore/hbsymbianvariant.h>
|
|
26 |
#include "btnotificationmanager.h"
|
|
27 |
#include "btnotifserver.h"
|
|
28 |
#include "bluetoothtrace.h"
|
|
29 |
#include <utf.h> // for debugging
|
|
30 |
|
|
31 |
/** Identifier of Bluetooth device dialog plug-in. */
|
|
32 |
_LIT( KBTDevDialogId, "com.nokia.hb.btdevicedialog/1.0" );
|
|
33 |
/** Key name of result. */
|
|
34 |
_LIT( KBTDevDialogResult, "result" );
|
|
35 |
_LIT( KBTDevDialogInput, "input" );
|
|
36 |
|
|
37 |
// ======== MEMBER FUNCTIONS ========
|
|
38 |
|
|
39 |
// ---------------------------------------------------------------------------
|
|
40 |
// C++ default constructor
|
|
41 |
// ---------------------------------------------------------------------------
|
|
42 |
//
|
|
43 |
CBluetoothNotification::CBluetoothNotification( CBTNotificationManager* aManager )
|
|
44 |
: iManager( aManager )
|
|
45 |
{
|
|
46 |
}
|
|
47 |
|
|
48 |
|
|
49 |
// ---------------------------------------------------------------------------
|
|
50 |
// Symbian 2nd-phase constructor
|
|
51 |
// ---------------------------------------------------------------------------
|
|
52 |
//
|
|
53 |
void CBluetoothNotification::ConstructL()
|
|
54 |
{
|
|
55 |
iNotificationData = CHbSymbianVariantMap::NewL();
|
|
56 |
iDialog = CHbDeviceDialogSymbian::NewL();
|
|
57 |
}
|
|
58 |
|
|
59 |
|
|
60 |
// ---------------------------------------------------------------------------
|
|
61 |
// NewL.
|
|
62 |
// ---------------------------------------------------------------------------
|
|
63 |
//
|
|
64 |
CBluetoothNotification* CBluetoothNotification::NewL(
|
|
65 |
CBTNotificationManager* aManager )
|
|
66 |
{
|
|
67 |
BOstraceFunctionEntry0( DUMMY_DEVLIST );
|
|
68 |
CBluetoothNotification* self = new( ELeave ) CBluetoothNotification( aManager );
|
|
69 |
CleanupStack::PushL( self );
|
|
70 |
self->ConstructL();
|
|
71 |
CleanupStack::Pop( self );
|
|
72 |
BOstraceFunctionExit0( DUMMY_DEVLIST );
|
|
73 |
return self;
|
|
74 |
}
|
|
75 |
|
|
76 |
|
|
77 |
// ---------------------------------------------------------------------------
|
|
78 |
// Destructor
|
|
79 |
// ---------------------------------------------------------------------------
|
|
80 |
//
|
|
81 |
CBluetoothNotification::~CBluetoothNotification()
|
|
82 |
{
|
|
83 |
BOstraceFunctionEntry1( DUMMY_DEVLIST, this );
|
|
84 |
delete iDialog;
|
|
85 |
delete iNotificationData;
|
|
86 |
delete iReturnData;
|
|
87 |
BOstraceFunctionExit1( DUMMY_DEVLIST, this )
|
|
88 |
}
|
|
89 |
|
|
90 |
|
|
91 |
// ---------------------------------------------------------------------------
|
|
92 |
// Resets the notification, clean all the internals.
|
|
93 |
// ---------------------------------------------------------------------------
|
|
94 |
//
|
|
95 |
void CBluetoothNotification::Reset()
|
|
96 |
{
|
|
97 |
BOstraceFunctionEntry1( DUMMY_DEVLIST, this );
|
|
98 |
iType = TBluetoothDialogParams::EInvalidDialog;
|
|
99 |
iResourceId = ENoResource;
|
|
100 |
iObserver = NULL;
|
|
101 |
iDialog->Cancel();
|
|
102 |
iDialog->SetObserver( NULL ); // Not interested in a callback anymore.
|
|
103 |
delete iNotificationData;
|
|
104 |
iNotificationData = NULL;
|
|
105 |
iNotificationData = CHbSymbianVariantMap::NewL();
|
|
106 |
delete iReturnData;
|
|
107 |
iReturnData = NULL;
|
|
108 |
iReturnData = CHbSymbianVariantMap::NewL();
|
|
109 |
BOstraceFunctionExit1( DUMMY_DEVLIST, this );
|
|
110 |
}
|
|
111 |
|
|
112 |
|
|
113 |
// ---------------------------------------------------------------------------
|
|
114 |
// Sets the data to be shown to the user.
|
|
115 |
// ---------------------------------------------------------------------------
|
|
116 |
//
|
|
117 |
TInt CBluetoothNotification::SetData( TInt aDataType, const TDesC& aData )
|
|
118 |
{
|
|
119 |
TRAPD( err, SetDataL( aDataType, aData ) );
|
|
120 |
return (int) err;
|
|
121 |
}
|
|
122 |
|
|
123 |
|
|
124 |
// ---------------------------------------------------------------------------
|
|
125 |
// Sets the data to be shown to the user.
|
|
126 |
// ---------------------------------------------------------------------------
|
|
127 |
//
|
|
128 |
TInt CBluetoothNotification::SetData( TInt aDataType, TInt aData )
|
|
129 |
{
|
|
130 |
TRAPD( err, SetDataL( aDataType, aData ) );
|
|
131 |
return (int) err;
|
|
132 |
}
|
|
133 |
|
|
134 |
// ---------------------------------------------------------------------------
|
|
135 |
// Updates the data to be shown to the user.
|
|
136 |
// ---------------------------------------------------------------------------
|
|
137 |
//
|
|
138 |
TInt CBluetoothNotification::Update( const TDesC& aData )
|
|
139 |
{
|
|
140 |
BOstraceFunctionEntry1( DUMMY_DEVLIST, this );
|
|
141 |
(void) aData;
|
|
142 |
int ret = iDialog->Update( *iNotificationData );
|
|
143 |
delete iNotificationData;
|
|
144 |
iNotificationData = NULL;
|
|
145 |
iNotificationData = CHbSymbianVariantMap::NewL();
|
|
146 |
BOstraceFunctionExit1( DUMMY_DEVLIST, this );
|
|
147 |
return ret;
|
|
148 |
}
|
|
149 |
|
|
150 |
|
|
151 |
// ---------------------------------------------------------------------------
|
|
152 |
// Show the notification, which means that it is added to the queue.
|
|
153 |
// ---------------------------------------------------------------------------
|
|
154 |
//
|
|
155 |
TInt CBluetoothNotification::Show()
|
|
156 |
{
|
|
157 |
BOstraceFunctionEntry1( DUMMY_DEVLIST, this );
|
|
158 |
TRAPD( err, SetDataL( TBluetoothDialogParams::EDialogType, iType ) );
|
|
159 |
if( !err )
|
|
160 |
{
|
|
161 |
TRAP( err, SetDataL( TBluetoothDialogParams::EResource, iResourceId ) );
|
|
162 |
}
|
|
163 |
delete iReturnData;
|
|
164 |
iReturnData = NULL;
|
|
165 |
if( !err )
|
|
166 |
{
|
|
167 |
TRAP( err, iReturnData = CHbSymbianVariantMap::NewL() );
|
|
168 |
}
|
|
169 |
if( !err )
|
|
170 |
{
|
|
171 |
err = iDialog->Show( KBTDevDialogId(), *iNotificationData, this );
|
|
172 |
}
|
|
173 |
delete iNotificationData;
|
|
174 |
iNotificationData = NULL;
|
|
175 |
iNotificationData = CHbSymbianVariantMap::NewL();
|
|
176 |
|
|
177 |
const TInt KPluginErr = CHbDeviceDialogSymbian::EPluginErrors + 1;
|
|
178 |
if( err == KPluginErr )
|
|
179 |
{
|
|
180 |
err = KErrNotFound;
|
|
181 |
}
|
|
182 |
BOstraceFunctionExitExt( DUMMY_DEVLIST, this, err );
|
|
183 |
return err;
|
|
184 |
}
|
|
185 |
|
|
186 |
|
|
187 |
// ---------------------------------------------------------------------------
|
|
188 |
// Stop showing the notification.
|
|
189 |
// ---------------------------------------------------------------------------
|
|
190 |
//
|
|
191 |
TInt CBluetoothNotification::Close()
|
|
192 |
{
|
|
193 |
BOstraceFunctionEntry1( DUMMY_DEVLIST, this );
|
|
194 |
iDialog->Cancel();
|
|
195 |
iManager->ReleaseNotification( this );
|
|
196 |
BOstraceFunctionExit1( DUMMY_DEVLIST, this );
|
|
197 |
return KErrNone;
|
|
198 |
}
|
|
199 |
|
|
200 |
|
|
201 |
// ---------------------------------------------------------------------------
|
|
202 |
// Sets the data to be shown to the user.
|
|
203 |
// ---------------------------------------------------------------------------
|
|
204 |
//
|
|
205 |
void CBluetoothNotification::SetDataL( TInt aType, const TDesC& aData )
|
|
206 |
{
|
|
207 |
BOstraceFunctionEntryExt( DUMMY_DEVLIST, this, aType );
|
|
208 |
TBuf16<6> key;
|
|
209 |
TInt err = 0;
|
|
210 |
CHbSymbianVariant* value = NULL;
|
|
211 |
switch( aType )
|
|
212 |
{
|
|
213 |
case TBluetoothDialogParams::EAddress:
|
|
214 |
case TBluetoothDeviceDialog::EDeviceName:
|
|
215 |
case TBluetoothDeviceDialog::EAdditionalDesc:
|
|
216 |
case TBluetoothDialogParams::EDialogTitle:
|
|
217 |
key.Num(aType);
|
|
218 |
value = CHbSymbianVariant::NewL( (TAny*) &aData, CHbSymbianVariant::EDes );
|
|
219 |
BtTraceBlock(
|
|
220 |
TBuf<32> buf;
|
|
221 |
switch (aType) {
|
|
222 |
case TBluetoothDialogParams::EAddress:
|
|
223 |
_LIT(KAddress,"EAddress");
|
|
224 |
buf.Append(KAddress);
|
|
225 |
break;
|
|
226 |
case TBluetoothDeviceDialog::EDeviceName:
|
|
227 |
_LIT(KDeviceName,"EDeviceName");
|
|
228 |
buf.Append(KDeviceName);
|
|
229 |
break;
|
|
230 |
case TBluetoothDeviceDialog::EAdditionalDesc:
|
|
231 |
_LIT(KAdditionalDesc,"EAdditionalDesc");
|
|
232 |
buf.Append(KAdditionalDesc);
|
|
233 |
break;
|
|
234 |
}
|
|
235 |
TPtrC p(buf);
|
|
236 |
TPtrC16 *ptr = (TPtrC16 *)value->Data();
|
|
237 |
BOstraceExt2( TRACE_DEBUG, DUMMY_DEVLIST, "SetData [%S] = [%S]", &p, ptr);
|
|
238 |
);
|
|
239 |
err = iNotificationData->Add( key, value ); // Takes ownership of value
|
|
240 |
if ( err )
|
|
241 |
{
|
|
242 |
// Note: need a proper exception handling.
|
|
243 |
// NOTIF_NOTHANDLED( err )
|
|
244 |
}
|
|
245 |
break;
|
|
246 |
case TBluetoothDialogParams::EResource:
|
|
247 |
case TBluetoothDeviceDialog::EDeviceClass:
|
|
248 |
case TBluetoothDeviceDialog::EAdditionalInt:
|
|
249 |
PanicServer( EBTNotifPanicBadArgument );
|
|
250 |
break;
|
|
251 |
case TBluetoothDialogParams::ENoParams:
|
|
252 |
case TBluetoothDeviceDialog::ENoParams:
|
|
253 |
default:
|
|
254 |
break;
|
|
255 |
}
|
|
256 |
BOstraceFunctionExit1( DUMMY_DEVLIST, this );
|
|
257 |
}
|
|
258 |
|
|
259 |
|
|
260 |
// ---------------------------------------------------------------------------
|
|
261 |
// Sets the data to be shown to the user.
|
|
262 |
// ---------------------------------------------------------------------------
|
|
263 |
//
|
|
264 |
void CBluetoothNotification::SetDataL( TInt aType, TInt aData )
|
|
265 |
{
|
|
266 |
BOstraceFunctionEntryExt( DUMMY_DEVLIST, this, aType );
|
|
267 |
TBuf<6> key;
|
|
268 |
TInt err = 0;
|
|
269 |
CHbSymbianVariant* value = NULL;
|
|
270 |
switch( aType )
|
|
271 |
{
|
|
272 |
case TBluetoothDialogParams::EDialogType:
|
|
273 |
case TBluetoothDialogParams::EResource:
|
|
274 |
case TBluetoothDialogParams::EDialogTitle:
|
|
275 |
case TBluetoothDeviceDialog::EDeviceClass:
|
|
276 |
case TBluetoothDeviceDialog::EAdditionalInt:
|
|
277 |
key.Num(aType);
|
|
278 |
value = CHbSymbianVariant::NewL( (TAny*) &aData, CHbSymbianVariant::EInt );
|
|
279 |
BtTraceBlock(
|
|
280 |
TBuf<32> buf;
|
|
281 |
switch (aType) {
|
|
282 |
case TBluetoothDialogParams::EDialogType:
|
|
283 |
buf = _L("EDialogType");
|
|
284 |
break;
|
|
285 |
case TBluetoothDialogParams::EResource:
|
|
286 |
buf = _L("EResource");
|
|
287 |
break;
|
|
288 |
case TBluetoothDeviceDialog::EDeviceClass:
|
|
289 |
buf = _L("EDeviceClass");
|
|
290 |
break;
|
|
291 |
case TBluetoothDeviceDialog::EAdditionalInt:
|
|
292 |
buf = _L("EAdditionalInt");
|
|
293 |
break;
|
|
294 |
}
|
|
295 |
TPtrC p(buf);
|
|
296 |
TInt *intPtr = (TInt *)value->Data();
|
|
297 |
BOstraceExt2( TRACE_DEBUG, DUMMY_DEVLIST, "SetData [%S] = [%d]", &p, *intPtr);
|
|
298 |
);
|
|
299 |
err = iNotificationData->Add( key, value ); // Takes ownership of value
|
|
300 |
if ( err )
|
|
301 |
{
|
|
302 |
// need a proper exception handling.
|
|
303 |
//NOTIF_NOTHANDLED( !err )
|
|
304 |
}
|
|
305 |
|
|
306 |
break;
|
|
307 |
case TBluetoothDialogParams::EAddress:
|
|
308 |
case TBluetoothDeviceDialog::EDeviceName:
|
|
309 |
PanicServer( EBTNotifPanicBadArgument );
|
|
310 |
break;
|
|
311 |
case TBluetoothDialogParams::ENoParams:
|
|
312 |
case TBluetoothDeviceDialog::ENoParams:
|
|
313 |
default:
|
|
314 |
break;
|
|
315 |
}
|
|
316 |
BOstraceFunctionExit1( DUMMY_DEVLIST, this );
|
|
317 |
}
|
|
318 |
|
|
319 |
// ---------------------------------------------------------------------------
|
|
320 |
// From class MHbDeviceDialogObserver.
|
|
321 |
// Callback called when data is received from a device dialog.
|
|
322 |
// ---------------------------------------------------------------------------
|
|
323 |
//
|
|
324 |
void CBluetoothNotification::DataReceived( CHbSymbianVariantMap& aData )
|
|
325 |
{
|
|
326 |
BOstraceFunctionEntry1( DUMMY_DEVLIST, this );
|
|
327 |
BtTraceBlock( debugHbSymbianVariantMap(aData); );
|
|
328 |
for( TInt i = 0; i < aData.Keys().MdcaCount(); i++ )
|
|
329 |
{
|
|
330 |
TPtrC key( aData.Keys().MdcaPoint( i ).Ptr(), aData.Keys().MdcaPoint( i ).Length() );
|
|
331 |
const CHbSymbianVariant* valueRef = aData.Get( key );
|
|
332 |
CHbSymbianVariant* value = CHbSymbianVariant::NewL( valueRef->Data(), valueRef->Type() );
|
|
333 |
TInt err = iReturnData->Add( key, value );
|
|
334 |
NOTIF_NOTHANDLED( !err )
|
|
335 |
}
|
|
336 |
iObserver->MBRDataReceived( aData );
|
|
337 |
BOstraceFunctionExit1( DUMMY_DEVLIST, this );
|
|
338 |
}
|
|
339 |
|
|
340 |
#ifdef BLUETOOTHTRACE_ENABLED
|
|
341 |
|
|
342 |
void CBluetoothNotification::debugHbSymbianVariantMap( CHbSymbianVariantMap& aData)
|
|
343 |
{
|
|
344 |
for( TInt i = 0; i < aData.Keys().MdcaCount(); i++ )
|
|
345 |
{
|
|
346 |
TBuf<128> buf;
|
|
347 |
TPtrC key( aData.Keys().MdcaPoint( i ).Ptr(), aData.Keys().MdcaPoint( i ).Length() );
|
|
348 |
buf = key;
|
|
349 |
buf.Append(_L(" = "));
|
|
350 |
const CHbSymbianVariant* value = aData.Get( key );
|
|
351 |
TBuf<16> nbr;
|
|
352 |
TBuf<32> newBuf;
|
|
353 |
switch (value->Type()) {
|
|
354 |
case CHbSymbianVariant::EInt :
|
|
355 |
buf.Append(_L("[EInt] "));
|
|
356 |
nbr.Num(*((TInt*)value->Data()));
|
|
357 |
buf.Append(nbr);
|
|
358 |
break;
|
|
359 |
case CHbSymbianVariant::EBool :
|
|
360 |
buf.Append(_L("[EBool] "));
|
|
361 |
buf.Append(*((TBool*)value->Data()) ? _L("True") : _L("False"));
|
|
362 |
break;
|
|
363 |
case CHbSymbianVariant::EUint :
|
|
364 |
buf.Append( _L("[EUint] "));
|
|
365 |
nbr.Num(*((TUint*)value->Data()));
|
|
366 |
buf.Append(nbr);
|
|
367 |
break;
|
|
368 |
case CHbSymbianVariant::EReal :
|
|
369 |
buf.Append(_L("[EReal] "));
|
|
370 |
nbr.Num(*((TReal*)value->Data()));
|
|
371 |
buf.Append(nbr);
|
|
372 |
break;
|
|
373 |
case CHbSymbianVariant::EDes : // TDesC
|
|
374 |
buf.Append(_L("[EDes] "));
|
|
375 |
buf.Append(*((TPtrC16 *)value->Data()));
|
|
376 |
break;
|
|
377 |
case CHbSymbianVariant::EBinary : // TDesC8
|
|
378 |
buf.Append(_L("[EBinary] "));
|
|
379 |
// the following function caused problems when converting this function to
|
|
380 |
// a trace function in bluetoothtrace.h
|
|
381 |
CnvUtfConverter::ConvertToUnicodeFromUtf8(newBuf,*((TPtrC8 *)value->Data()) );
|
|
382 |
buf.Append(newBuf);
|
|
383 |
break;
|
|
384 |
case CHbSymbianVariant::EChar : // a TChar
|
|
385 |
buf.Append(_L("[EChar] "));
|
|
386 |
buf.Append(*((TChar *)value->Data()));
|
|
387 |
break;
|
|
388 |
case CHbSymbianVariant::ERect : // a TRect
|
|
389 |
case CHbSymbianVariant::EPoint : // a TPoint
|
|
390 |
case CHbSymbianVariant::ESize : // a TSize
|
|
391 |
case CHbSymbianVariant::EDesArray : // a MDesCArray
|
|
392 |
break;
|
|
393 |
default:
|
|
394 |
break;
|
|
395 |
}
|
|
396 |
TPtrC p(buf);
|
|
397 |
BOstraceExt1( TRACE_DEBUG, DUMMY_DEVLIST, "HbSymbianVariantMap [%S]", &p);
|
|
398 |
}
|
|
399 |
}
|
|
400 |
#endif // BLUETOOTHTRACE_ENABLED
|
|
401 |
// ---------------------------------------------------------------------------
|
|
402 |
// From class MHbDeviceDialogObserver.
|
|
403 |
// Callback called when a device dialog is closed.
|
|
404 |
// ---------------------------------------------------------------------------
|
|
405 |
//
|
|
406 |
void CBluetoothNotification::DeviceDialogClosed( TInt aCompletionCode )
|
|
407 |
{
|
|
408 |
BOstraceFunctionEntryExt( DUMMY_DEVLIST, this, aCompletionCode );
|
|
409 |
TPckg<TBool> result( EFalse );
|
|
410 |
TPtrC8 resultPtr( result );
|
|
411 |
const CHbSymbianVariant* value = iReturnData->Get( KBTDevDialogResult );
|
|
412 |
if( value && value->IsValid() )
|
|
413 |
{
|
|
414 |
result() = *value->Value<TBool>();
|
|
415 |
}
|
|
416 |
RBuf8 resultBuf;
|
|
417 |
value = iReturnData->Get( KBTDevDialogInput );
|
|
418 |
if( value && value->IsValid() )
|
|
419 |
{
|
|
420 |
HBufC8* data = value->Value<HBufC8>();
|
|
421 |
if( !resultBuf.Create( data->Length() + result.Length() ) )
|
|
422 |
{
|
|
423 |
resultBuf = *data;
|
|
424 |
resultBuf.Insert( 0, result );
|
|
425 |
resultPtr.Set( resultBuf );
|
|
426 |
}
|
|
427 |
}
|
|
428 |
if( iObserver )
|
|
429 |
{
|
|
430 |
if( aCompletionCode == CHbDeviceDialogSymbian::ECancelledError )
|
|
431 |
{
|
|
432 |
aCompletionCode = KErrCancel;
|
|
433 |
}
|
|
434 |
iObserver->MBRNotificationClosed( aCompletionCode, resultPtr );
|
|
435 |
}
|
|
436 |
iManager->ReleaseNotification( this );
|
|
437 |
// Note that we might get deleted after releasing ourselves.
|
|
438 |
BOstraceFunctionExit1( DUMMY_DEVLIST, this );
|
|
439 |
}
|
|
440 |
|