bluetoothengine/btui/btuidelegate/btdelegatedevsecurity.cpp
changeset 33 837dcc42fd6a
child 40 997690c3397a
child 42 b72428996822
equal deleted inserted replaced
19:43824b19ee35 33:837dcc42fd6a
       
     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 
       
    18 #include <QModelIndex>
       
    19 
       
    20 #include "btdelegatedevsecurity.h"
       
    21 #include <btsettingmodel.h>
       
    22 #include <btdevicemodel.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)
       
    30 {
       
    31     
       
    32 }
       
    33 
       
    34 BtDelegateDevSecurity::~BtDelegateDevSecurity()
       
    35 {
       
    36     delete mBtEngDevMan;
       
    37 }
       
    38 
       
    39 
       
    40 void BtDelegateDevSecurity::exec( const QVariant &params )
       
    41 {
       
    42     int error = KErrNone;
       
    43     QModelIndex index = params.value<QModelIndex>();
       
    44     
       
    45     QString strBtAddr = getDeviceModel()->data(index,
       
    46             BtDeviceModel::ReadableBdaddrRole).toString();
       
    47     
       
    48     mdeviceName = getDeviceModel()->data(index,BtDeviceModel::NameAliasRole).toString();
       
    49     
       
    50     TBTDevAddr symaddr;
       
    51     TBuf<KBTDevAddrSize * 2> buffer(strBtAddr.utf16());
       
    52     symaddr.SetReadable( buffer );
       
    53 
       
    54     CBTDevice *symBtDevice = 0;
       
    55     TRAP( error, {
       
    56             symBtDevice = CBTDevice::NewL( symaddr );
       
    57             if( !mBtEngDevMan) {
       
    58                 mBtEngDevMan = CBTEngDevMan::NewL( this );
       
    59             }
       
    60     });
       
    61     
       
    62     if ( !error ) {
       
    63         symBtDevice->SetPaired(EFalse);
       
    64         // deleting link key for executing unpair is safe as no 
       
    65         // link key shall exist if the device has been unpaired. 
       
    66         symBtDevice->DeleteLinkKey();
       
    67         error = mBtEngDevMan->ModifyDevice( *symBtDevice );
       
    68     }
       
    69     delete symBtDevice;
       
    70     
       
    71     if ( error ) {
       
    72         emitCommandComplete(error);
       
    73     }
       
    74 }
       
    75 
       
    76 void BtDelegateDevSecurity::cancel()
       
    77 {
       
    78     
       
    79 }
       
    80 
       
    81 void BtDelegateDevSecurity::HandleDevManComplete( TInt aErr )
       
    82 {
       
    83     emitCommandComplete(aErr);
       
    84 }
       
    85 
       
    86 void BtDelegateDevSecurity::HandleGetDevicesComplete( TInt aErr, CBTDeviceArray* aDeviceArray )
       
    87 {
       
    88     Q_UNUSED(aErr);
       
    89     Q_UNUSED(aDeviceArray);
       
    90 }
       
    91 
       
    92 void BtDelegateDevSecurity::emitCommandComplete(int error)
       
    93 {
       
    94     QString str(hbTrId("Unpaired to %1"));
       
    95     QString err(hbTrId("Unpairing with %1 Failed"));
       
    96     
       
    97     if(error != KErrNone) {
       
    98         HbNotificationDialog::launchDialog(err.arg(mdeviceName));
       
    99     }
       
   100     else {
       
   101         HbNotificationDialog::launchDialog(str.arg(mdeviceName));
       
   102     }
       
   103 
       
   104     emit commandCompleted(error);
       
   105 }
       
   106 
       
   107 
       
   108 
       
   109 
       
   110