bluetoothengine/btui/btuidelegate/btdelegatepair.cpp
changeset 42 b72428996822
parent 31 a0ea99b6fa53
child 57 5ebadcda06cb
equal deleted inserted replaced
32:19bd632b5100 42:b72428996822
    15 *
    15 *
    16 */
    16 */
    17 
    17 
    18 #include "btdelegatepair.h"
    18 #include "btdelegatepair.h"
    19 #include "btuiutil.h"
    19 #include "btuiutil.h"
       
    20 #include "btdelegatefactory.h"
       
    21 #include "btqtconstants.h"
    20 
    22 
    21 #include <QModelIndex>
    23 #include <QModelIndex>
    22 #include <btsettingmodel.h>
    24 #include <btsettingmodel.h>
    23 #include <btdevicemodel.h>
    25 #include <btdevicemodel.h>
    24 #include <bluetoothuitrace.h>
    26 #include <bluetoothuitrace.h>
    34         BtDeviceModel* deviceModel, 
    36         BtDeviceModel* deviceModel, 
    35         QObject *parent) :
    37         QObject *parent) :
    36     BtAbstractDelegate(settingModel, deviceModel, parent), mBtengConnMan(0)
    38     BtAbstractDelegate(settingModel, deviceModel, parent), mBtengConnMan(0)
    37 {
    39 {
    38     mLoader = new HbDocumentLoader();
    40     mLoader = new HbDocumentLoader();
       
    41     mAbstractDelegate = NULL;
    39 }
    42 }
    40 
    43 
    41 BtDelegatePair::~BtDelegatePair()
    44 BtDelegatePair::~BtDelegatePair()
    42 {
    45 {
    43     delete mBtengConnMan;
    46     delete mBtengConnMan;
    44     delete mLoader;
    47     delete mLoader;
    45 }
    48 }
    46 
    49 
    47 void BtDelegatePair::exec( const QVariant &params )
    50 void BtDelegatePair::exec( const QVariant &params )
    48 {
    51 {
       
    52     
       
    53     deviceIndex = params.value<QModelIndex>();
       
    54     
       
    55     if(isBtPowerOn()) {
       
    56         exec_pair();
       
    57     }
       
    58     else {
       
    59         //If Bt Power is off, switch it on and then perform pairing.
       
    60         //todo: Do we ask for user confirmation here..?
       
    61         if (!mAbstractDelegate) { 
       
    62             mAbstractDelegate = BtDelegateFactory::newDelegate(BtDelegate::ManagePower, 
       
    63                     getSettingModel(), getDeviceModel() ); 
       
    64             connect( mAbstractDelegate, SIGNAL(commandCompleted(int)), this, SLOT(powerDelegateCompleted(int)) );
       
    65             mAbstractDelegate->exec(QVariant(BtPowerOn));
       
    66         }
       
    67     }
       
    68     
       
    69 }
       
    70 
       
    71 void BtDelegatePair::powerDelegateCompleted(int error)
       
    72 {
       
    73     if (mAbstractDelegate) {
       
    74         disconnect(mAbstractDelegate);
       
    75         delete mAbstractDelegate;
       
    76         mAbstractDelegate = 0;
       
    77     }
       
    78     if ( error == KErrNone ) {
       
    79         exec_pair();
       
    80     } 
       
    81     else {
       
    82         // error
       
    83         emitCommandComplete(error);
       
    84     }
       
    85 }
       
    86 
       
    87 void BtDelegatePair::exec_pair()
       
    88 {
    49     int error = KErrNone;
    89     int error = KErrNone;
    50     QModelIndex index = params.value<QModelIndex>();
    90     mdeviceName = getDeviceModel()->data(deviceIndex,BtDeviceModel::NameAliasRole).toString();
    51     
    91     
    52     mdeviceName = getDeviceModel()->data(index,BtDeviceModel::NameAliasRole).toString();
    92     QString strBtAddr = getDeviceModel()->data(deviceIndex,BtDeviceModel::ReadableBdaddrRole).toString();
    53     
    93     int cod = getDeviceModel()->data(deviceIndex,BtDeviceModel::CoDRole).toInt();
    54     QString strBtAddr = getDeviceModel()->data(index,BtDeviceModel::ReadableBdaddrRole).toString();
       
    55     int cod = getDeviceModel()->data(index,BtDeviceModel::CoDRole).toInt();
       
    56     
    94     
    57     if ( ! mBtengConnMan ){
    95     if ( ! mBtengConnMan ){
    58         TRAP( error, mBtengConnMan = CBTEngConnMan::NewL(this) );
    96         TRAP( error, mBtengConnMan = CBTEngConnMan::NewL(this) );
    59     }
    97     }
    60     
    98     
    67     }
   105     }
    68     
   106     
    69     if(error) {
   107     if(error) {
    70         emitCommandComplete(error);
   108         emitCommandComplete(error);
    71     }
   109     }
    72     
   110 
    73 }
   111 }
       
   112 
    74 
   113 
    75 void BtDelegatePair::launchWaitDialog()
   114 void BtDelegatePair::launchWaitDialog()
    76 {
   115 {
    77     QString headingText(hbTrId("Pairing with %1"));
   116     QString headingText(hbTrId("txt_bt_title_pairing_with_1"));
    78     HbLabel *heading;
   117     HbLabel *heading;
    79     HbProgressBar* progressBar;
   118     HbProgressBar* progressBar;
    80     
   119     
    81     bool ok = false;
   120     bool ok = false;
    82     mLoader->load( BTUI_PAIR_WAIT_DOCML, &ok );
   121     mLoader->load( BTUI_PAIR_WAIT_DOCML, &ok );
   124     emitCommandComplete(aErr);
   163     emitCommandComplete(aErr);
   125 }
   164 }
   126 
   165 
   127 void BtDelegatePair::emitCommandComplete(int error)
   166 void BtDelegatePair::emitCommandComplete(int error)
   128 {
   167 {
   129     QString str(hbTrId("Paired to %1"));
       
   130     QString err(hbTrId("Pairing with %1 Failed"));
       
   131     
       
   132     if(error != KErrNone) {
       
   133         HbNotificationDialog::launchDialog(err.arg(mdeviceName));
       
   134     }
       
   135     else {
       
   136         HbNotificationDialog::launchDialog(str.arg(mdeviceName));
       
   137     }
       
   138 
   168 
   139     emit commandCompleted(error);
   169     emit commandCompleted(error);
   140 }
   170 }
   141 
   171 
   142 void BtDelegatePair::cancel()
   172 void BtDelegatePair::cancel()