bluetoothengine/btui/btuidelegate/btdelegatedevsecurity.cpp
branchRCL_3
changeset 56 9386f31cc85b
parent 55 613943a21004
child 61 269724087bed
equal deleted inserted replaced
55:613943a21004 56:9386f31cc85b
     1 /*
       
     2 * Copyright (c) 2010 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: 
       
    15 *
       
    16 */
       
    17 #include "btdelegatedevsecurity.h"
       
    18 #include "btqtconstants.h"
       
    19 #include <QModelIndex>
       
    20 #include <btsettingmodel.h>
       
    21 #include <btdevicemodel.h>
       
    22 #include <btdelegatefactory.h>
       
    23 #include <hbnotificationdialog.h>
       
    24 
       
    25 BtDelegateDevSecurity::BtDelegateDevSecurity(            
       
    26         BtSettingModel* settingModel, 
       
    27         BtDeviceModel* deviceModel, 
       
    28         QObject *parent) :
       
    29     BtAbstractDelegate(settingModel, deviceModel, parent), mBtEngDevMan(0), mBtengConnMan(0), mDisconnectDelegate(0)
       
    30 {
       
    31     
       
    32 }
       
    33 
       
    34 BtDelegateDevSecurity::~BtDelegateDevSecurity()
       
    35 {
       
    36     delete mBtEngDevMan;
       
    37     delete mBtengConnMan;
       
    38     delete mDisconnectDelegate;
       
    39 }
       
    40 
       
    41 
       
    42 void BtDelegateDevSecurity::exec( const QVariant &params )
       
    43 {
       
    44     int error = KErrNone;
       
    45     QModelIndex index = params.value<QModelIndex>();
       
    46     
       
    47     QString strBtAddr = getDeviceModel()->data(index,
       
    48             BtDeviceModel::ReadableBdaddrRole).toString();
       
    49     
       
    50     mdeviceName = getDeviceModel()->data(index,BtDeviceModel::NameAliasRole).toString();
       
    51     
       
    52     TBTDevAddr symaddr;
       
    53     TBuf<KBTDevAddrSize * 2> buffer(strBtAddr.utf16());
       
    54     symaddr.SetReadable( buffer );
       
    55     
       
    56     // Disconnect if paired device was connected 
       
    57     if ( ! mBtengConnMan ){
       
    58         TRAP( error, mBtengConnMan = CBTEngConnMan::NewL(this) );
       
    59     }
       
    60     TBTEngConnectionStatus connstatus;
       
    61     if ( !error && mBtengConnMan->IsConnected(symaddr, connstatus ) == KErrNone) {
       
    62         if ( connstatus == EBTEngConnected) {
       
    63             if (! mDisconnectDelegate){
       
    64                 mDisconnectDelegate = BtDelegateFactory::newDelegate(
       
    65                                         BtDelegate::Disconnect, getSettingModel(), getDeviceModel()); 
       
    66                 connect( mDisconnectDelegate, SIGNAL(commandCompleted(int)), this, SLOT(disconnectDelegateCompleted(int)) );
       
    67                 
       
    68             }
       
    69             QList<QVariant>list;
       
    70             QVariant paramFirst;
       
    71             paramFirst.setValue(index);            
       
    72             QVariant paramSecond;
       
    73             DisconnectOption discoOpt = ServiceLevel;
       
    74             paramSecond.setValue((int)discoOpt);
       
    75             list.append(paramFirst);
       
    76             list.append(paramSecond);
       
    77             QVariant paramsList;
       
    78             paramsList.setValue(list);
       
    79             mDisconnectDelegate->exec(paramsList);
       
    80         }
       
    81     }
       
    82 
       
    83     // Set device as unpaired
       
    84     CBTDevice *symBtDevice = 0;
       
    85     TRAP( error, {
       
    86             symBtDevice = CBTDevice::NewL( symaddr );
       
    87             if( !mBtEngDevMan) {
       
    88                 mBtEngDevMan = CBTEngDevMan::NewL( this );
       
    89             }
       
    90     });
       
    91     
       
    92     if ( !error ) {
       
    93         symBtDevice->SetPaired(EFalse);
       
    94         // deleting link key for executing unpair is safe as no 
       
    95         // link key shall exist if the device has been unpaired. 
       
    96         symBtDevice->DeleteLinkKey();
       
    97         error = mBtEngDevMan->ModifyDevice( *symBtDevice );
       
    98     }
       
    99     delete symBtDevice;
       
   100     
       
   101     if ( error ) {
       
   102         emitCommandComplete(error);
       
   103     }
       
   104 }
       
   105 
       
   106 void BtDelegateDevSecurity::cancel()
       
   107 {
       
   108     
       
   109 }
       
   110 
       
   111 void BtDelegateDevSecurity::disconnectDelegateCompleted( int err )
       
   112 {
       
   113     Q_UNUSED(err);
       
   114 }
       
   115 
       
   116 void BtDelegateDevSecurity::HandleDevManComplete( TInt aErr )
       
   117 {
       
   118     emitCommandComplete(aErr);
       
   119 }
       
   120 
       
   121 void BtDelegateDevSecurity::HandleGetDevicesComplete( TInt aErr, CBTDeviceArray* aDeviceArray )
       
   122 {
       
   123     Q_UNUSED(aErr);
       
   124     Q_UNUSED(aDeviceArray);
       
   125 }
       
   126 
       
   127 void BtDelegateDevSecurity::emitCommandComplete(int error)
       
   128 {
       
   129     // no dialogs here since stack provides "unpaired to %1" dialog
       
   130     // and failures are not reported
       
   131     
       
   132     emit commandCompleted(error);
       
   133 }
       
   134 
       
   135 void BtDelegateDevSecurity::ConnectComplete( TBTDevAddr& aAddr, TInt aErr, 
       
   136                                    RBTDevAddrArray* aConflicts )
       
   137 {
       
   138     Q_UNUSED(aAddr);
       
   139     Q_UNUSED(aErr);
       
   140     Q_UNUSED(aConflicts);  
       
   141 }
       
   142 
       
   143 void BtDelegateDevSecurity::DisconnectComplete( TBTDevAddr& aAddr, TInt aErr )
       
   144 {
       
   145     Q_UNUSED(aAddr);
       
   146     Q_UNUSED(aErr);    
       
   147 }
       
   148 
       
   149 
       
   150 
       
   151