bluetoothengine/btnotif/btnotifsrv/src/bluetoothnotification.cpp
changeset 33 837dcc42fd6a
parent 19 43824b19ee35
child 40 997690c3397a
child 42 b72428996822
equal deleted inserted replaced
19:43824b19ee35 33:837dcc42fd6a
     1 /*
     1 /*
     2 * ============================================================================
     2 * Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
     3 *  Name        : bluetoothnotification.cpp
     3 * All rights reserved.
     4 *  Part of     : bluetoothengine / btnotif
     4 * This component and the accompanying materials are made available
     5 *  Description : Class for managing an actual user notification or query.
     5 * under the terms of "Eclipse Public License v1.0"
     6 *                It hides UI framework-specifics in a private class.
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
     7 *
     8 *
     8 *  Copyright © 2009 Nokia Corporation and/or its subsidiary(-ies).
     9 * Initial Contributors:
     9 *  All rights reserved.
    10 * Nokia Corporation - initial contribution.
    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 *
    11 *
    15 *  Initial Contributors:
    12 * Contributors:
    16 *  Nokia Corporation - initial contribution.
       
    17 *
    13 *
    18 *  Contributors:
    14 * Description: Description: Class for managing an actual user notification or query.
    19 *  Nokia Corporation
    15 *              It hides UI framework-specifics in a private class.
    20 * ============================================================================
    16 *
    21 * Template version: 4.1
       
    22 */
    17 */
    23 
    18 
    24 #include "bluetoothnotification.h"
    19 #include "bluetoothnotification.h"
    25 #include <hb/hbcore/hbsymbianvariant.h>
    20 #include <hb/hbcore/hbsymbianvariant.h>
    26 #include "btnotificationmanager.h"
    21 #include "btnotificationmanager.h"
    85     delete iNotificationData;
    80     delete iNotificationData;
    86     delete iReturnData;
    81     delete iReturnData;
    87 	BOstraceFunctionExit1( DUMMY_DEVLIST, this )
    82 	BOstraceFunctionExit1( DUMMY_DEVLIST, this )
    88 }
    83 }
    89 
    84 
    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 // ---------------------------------------------------------------------------
    85 // ---------------------------------------------------------------------------
   114 // Sets the data to be shown to the user.
    86 // Sets the data to be shown to the user.
   115 // ---------------------------------------------------------------------------
    87 // ---------------------------------------------------------------------------
   116 //
    88 //
   117 TInt CBluetoothNotification::SetData( TInt aDataType, const TDesC& aData )
    89 TInt CBluetoothNotification::SetData( TInt aDataType, const TDesC& aData )
   140     BOstraceFunctionEntry1( DUMMY_DEVLIST, this );
   112     BOstraceFunctionEntry1( DUMMY_DEVLIST, this );
   141     (void) aData;
   113     (void) aData;
   142     int ret = iDialog->Update( *iNotificationData );
   114     int ret = iDialog->Update( *iNotificationData );
   143     delete iNotificationData;
   115     delete iNotificationData;
   144     iNotificationData = NULL;
   116     iNotificationData = NULL;
   145     iNotificationData = CHbSymbianVariantMap::NewL();
   117     TRAP( ret, iNotificationData = CHbSymbianVariantMap::NewL() );
   146     BOstraceFunctionExit1( DUMMY_DEVLIST, this );
   118     BOstraceFunctionExit1( DUMMY_DEVLIST, this );
   147     return ret;
   119     return ret;
   148     }
   120     }
   149 
   121 
   150 
   122 
   151 // ---------------------------------------------------------------------------
   123 // ---------------------------------------------------------------------------
   152 // Show the notification, which means that it is added to the queue.
   124 // Show the notification, which means that it is added to the queue.
   153 // ---------------------------------------------------------------------------
   125 // ---------------------------------------------------------------------------
   154 //
   126 //
   155 TInt CBluetoothNotification::Show()
   127 void CBluetoothNotification::ShowL()
   156     {
   128     {
   157 	BOstraceFunctionEntry1( DUMMY_DEVLIST, this );
   129 	BOstraceFunctionEntry1( DUMMY_DEVLIST, this );
   158     TRAPD( err, SetDataL( TBluetoothDialogParams::EDialogType, iType ) );
   130     SetDataL( TBluetoothDialogParams::EDialogType, iType );
   159     if( !err )
   131     SetDataL( TBluetoothDialogParams::EResource, iResourceId );
   160         {
       
   161         TRAP( err, SetDataL( TBluetoothDialogParams::EResource, iResourceId ) );
       
   162         }
       
   163     delete iReturnData;
   132     delete iReturnData;
   164     iReturnData = NULL;
   133     iReturnData = NULL;
   165     if( !err )
   134     iReturnData = CHbSymbianVariantMap::NewL();
   166         {
   135     iDialog->Show( KBTDevDialogId(), *iNotificationData, this );
   167         TRAP( err, iReturnData = CHbSymbianVariantMap::NewL() );
       
   168         }
       
   169     if( !err )
       
   170         {
       
   171         err = iDialog->Show( KBTDevDialogId(), *iNotificationData, this );
       
   172         }
       
   173     delete iNotificationData;
   136     delete iNotificationData;
   174     iNotificationData = NULL;
   137     iNotificationData = NULL;
   175     iNotificationData = CHbSymbianVariantMap::NewL();
   138     iNotificationData = CHbSymbianVariantMap::NewL();
   176     
   139     BOstraceFunctionExit1( DUMMY_DEVLIST, this );
   177     const TInt KPluginErr = CHbDeviceDialogSymbian::EPluginErrors + 1;
   140     }
   178     if( err == KPluginErr )
       
   179         {
       
   180         err = KErrNotFound;
       
   181         }
       
   182 	BOstraceFunctionExitExt( DUMMY_DEVLIST, this, err );
       
   183     return err;
       
   184     }
       
   185 
       
   186 
   141 
   187 // ---------------------------------------------------------------------------
   142 // ---------------------------------------------------------------------------
   188 // Stop showing the notification.
   143 // Stop showing the notification.
   189 // ---------------------------------------------------------------------------
   144 // ---------------------------------------------------------------------------
   190 //
   145 //
   323 //
   278 //
   324 void CBluetoothNotification::DataReceived( CHbSymbianVariantMap& aData )
   279 void CBluetoothNotification::DataReceived( CHbSymbianVariantMap& aData )
   325     {
   280     {
   326     BOstraceFunctionEntry1( DUMMY_DEVLIST, this );
   281     BOstraceFunctionEntry1( DUMMY_DEVLIST, this );
   327     BtTraceBlock( debugHbSymbianVariantMap(aData); );
   282     BtTraceBlock( debugHbSymbianVariantMap(aData); );
       
   283     CHbSymbianVariant* value = NULL;
   328     for( TInt i = 0; i < aData.Keys().MdcaCount(); i++ )
   284     for( TInt i = 0; i < aData.Keys().MdcaCount(); i++ )
   329         {
   285         {
   330         TPtrC key( aData.Keys().MdcaPoint( i ).Ptr(), aData.Keys().MdcaPoint( i ).Length() );
   286         TPtrC key( aData.Keys().MdcaPoint( i ).Ptr(), aData.Keys().MdcaPoint( i ).Length() );
   331         const CHbSymbianVariant* valueRef = aData.Get( key );
   287         const CHbSymbianVariant* valueRef = aData.Get( key );
   332         CHbSymbianVariant* value = CHbSymbianVariant::NewL( valueRef->Data(), valueRef->Type() );
   288         value = NULL;
   333         TInt err = iReturnData->Add( key, value );
   289         TRAP_IGNORE( value = 
   334         NOTIF_NOTHANDLED( !err )
   290                 CHbSymbianVariant::NewL( valueRef->Data(), valueRef->Type() ) );
       
   291         if ( value )
       
   292             {
       
   293             TInt err = iReturnData->Add( key, value );
       
   294             if ( err ) 
       
   295                 {
       
   296                 // todo: better exception handing than ignoring this failure?
       
   297                 }
       
   298             }
   335         }
   299         }
   336     iObserver->MBRDataReceived( aData );
   300     iObserver->MBRDataReceived( aData );
   337     BOstraceFunctionExit1( DUMMY_DEVLIST, this );
   301     BOstraceFunctionExit1( DUMMY_DEVLIST, this );
   338     }
   302     }
   339 
   303 
   431             {
   395             {
   432             aCompletionCode = KErrCancel;
   396             aCompletionCode = KErrCancel;
   433             }
   397             }
   434         iObserver->MBRNotificationClosed( aCompletionCode, resultPtr );
   398         iObserver->MBRNotificationClosed( aCompletionCode, resultPtr );
   435         }
   399         }
       
   400     resultBuf.Close();
   436     iManager->ReleaseNotification( this );
   401     iManager->ReleaseNotification( this );
   437     // Note that we might get deleted after releasing ourselves.
   402     // Note that we might get deleted after releasing ourselves.
   438     BOstraceFunctionExit1( DUMMY_DEVLIST, this );
   403     BOstraceFunctionExit1( DUMMY_DEVLIST, this );
   439     }
   404     }
   440 
   405