bluetoothengine/btui/btuidelegate/btdelegateInquiry.cpp
changeset 40 997690c3397a
parent 33 837dcc42fd6a
child 41 0b2439c3e397
equal deleted inserted replaced
37:91746b151f97 40:997690c3397a
    15 *
    15 *
    16 */
    16 */
    17 
    17 
    18 
    18 
    19 #include "btdelegateinquiry.h"
    19 #include "btdelegateinquiry.h"
       
    20 #include "btdelegatefactory.h"
       
    21 #include "btqtconstants.h"
       
    22 
    20 #include <btsettingmodel.h>
    23 #include <btsettingmodel.h>
    21 #include <btdevicemodel.h>
    24 #include <btdevicemodel.h>
    22 #include <bluetoothuitrace.h>
    25 #include <bluetoothuitrace.h>
    23 
    26 
    24 
    27 
    25 BtDelegateInquiry::BtDelegateInquiry(
    28 BtDelegateInquiry::BtDelegateInquiry(
    26         BtSettingModel* settingModel, 
    29         BtSettingModel* settingModel, 
    27         BtDeviceModel* deviceModel, QObject* parent )
    30         BtDeviceModel* deviceModel, QObject* parent )
    28     :BtAbstractDelegate( settingModel, deviceModel, parent )
    31     :BtAbstractDelegate( settingModel, deviceModel, parent )
    29 {
    32 {
       
    33     mAbstractDelegate = NULL;
    30 }
    34 }
    31 
    35 
    32 BtDelegateInquiry::~BtDelegateInquiry()
    36 BtDelegateInquiry::~BtDelegateInquiry()
    33 {
    37 {
    34 
    38 
    36 
    40 
    37 void BtDelegateInquiry::exec( const QVariant& params )
    41 void BtDelegateInquiry::exec( const QVariant& params )
    38 {
    42 {
    39     Q_UNUSED(params);
    43     Q_UNUSED(params);
    40     
    44     
       
    45     if(isBtPowerOn()) {
       
    46         exec_inquiry();
       
    47     }
       
    48     else {
       
    49         //If Bt Power is off, switch it on and then perform pairing.
       
    50         //todo: Do we ask for user confirmation here..?
       
    51         if (!mAbstractDelegate) { 
       
    52             mAbstractDelegate = BtDelegateFactory::newDelegate(BtDelegate::ManagePower, 
       
    53                     getSettingModel(), getDeviceModel() ); 
       
    54             connect( mAbstractDelegate, SIGNAL(commandCompleted(int)), this, SLOT(powerDelegateCompleted(int)) );
       
    55             mAbstractDelegate->exec(QVariant(BtPowerOn));
       
    56         }
       
    57     }
       
    58 }
       
    59 
       
    60 void BtDelegateInquiry::powerDelegateCompleted(int error)
       
    61 {
       
    62     if (mAbstractDelegate) {
       
    63         disconnect(mAbstractDelegate);
       
    64         delete mAbstractDelegate;
       
    65         mAbstractDelegate = 0;
       
    66     }
       
    67     if ( error == KErrNone ) {
       
    68         exec_inquiry();
       
    69     } 
       
    70     else {
       
    71         // error
       
    72         emit commandCompleted(error);
       
    73     }
       
    74 }
       
    75 
       
    76 void BtDelegateInquiry::exec_inquiry()
       
    77 {
    41     bool err = getDeviceModel()->searchDevice();
    78     bool err = getDeviceModel()->searchDevice();
    42     if (!err) {
    79     if (!err) {
    43         // TODO - Verify the error code to be used.
    80         // TODO - Verify the error code to be used.
    44         // Complete command with error
    81         // Complete command with error
    45         emit commandCompleted(KErrNotSupported);
    82         emit commandCompleted(KErrNotSupported);