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