bluetoothengine/btui/btuidelegate/btdelegatepair.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 "btdelegatepair.h"
       
    19 #include "btuiutil.h"
       
    20 
       
    21 #include <QModelIndex>
       
    22 #include <btsettingmodel.h>
       
    23 #include <btdevicemodel.h>
       
    24 #include <bluetoothuitrace.h>
       
    25 #include <hbnotificationdialog.h>
       
    26 #include <hblabel.h>
       
    27 #include <hbprogressbar.h>
       
    28 
       
    29 // docml to load
       
    30 const char* BTUI_PAIR_WAIT_DOCML = ":/docml/pairwaitingdialog.docml";
       
    31 
       
    32 BtDelegatePair::BtDelegatePair(
       
    33         BtSettingModel* settingModel, 
       
    34         BtDeviceModel* deviceModel, 
       
    35         QObject *parent) :
       
    36     BtAbstractDelegate(settingModel, deviceModel, parent), mBtengConnMan(0)
       
    37 {
       
    38     mLoader = new HbDocumentLoader();
       
    39 }
       
    40 
       
    41 BtDelegatePair::~BtDelegatePair()
       
    42 {
       
    43     delete mBtengConnMan;
       
    44     delete mLoader;
       
    45 }
       
    46 
       
    47 void BtDelegatePair::exec( const QVariant &params )
       
    48 {
       
    49     int error = KErrNone;
       
    50     QModelIndex index = params.value<QModelIndex>();
       
    51     
       
    52     mdeviceName = getDeviceModel()->data(index,BtDeviceModel::NameAliasRole).toString();
       
    53     
       
    54     QString strBtAddr = getDeviceModel()->data(index,BtDeviceModel::ReadableBdaddrRole).toString();
       
    55     int cod = getDeviceModel()->data(index,BtDeviceModel::CoDRole).toInt();
       
    56     
       
    57     if ( ! mBtengConnMan ){
       
    58         TRAP( error, mBtengConnMan = CBTEngConnMan::NewL(this) );
       
    59     }
       
    60     
       
    61     if ( !error ) {
       
    62         TBTDevAddr btEngddr;
       
    63         addrReadbleStringToSymbian( strBtAddr, btEngddr );
       
    64         TBTDeviceClass btEngDeviceClass(cod);
       
    65         error = mBtengConnMan->PairDevice(btEngddr, btEngDeviceClass);
       
    66         launchWaitDialog();
       
    67     }
       
    68     
       
    69     if(error) {
       
    70         emitCommandComplete(error);
       
    71     }
       
    72     
       
    73 }
       
    74 
       
    75 void BtDelegatePair::launchWaitDialog()
       
    76 {
       
    77     QString headingText(hbTrId("Pairing with %1"));
       
    78     HbLabel *heading;
       
    79     HbProgressBar* progressBar;
       
    80     
       
    81     bool ok = false;
       
    82     mLoader->load( BTUI_PAIR_WAIT_DOCML, &ok );
       
    83     // Exit if the file format is invalid
       
    84     BTUI_ASSERT_X( ok, "BTUI_PAIR_WAIT_DOCML", "Invalid docml file" );
       
    85 
       
    86     mWaitDialog = qobject_cast<HbDialog *>( mLoader->findWidget( "dialog" ) );
       
    87     BTUI_ASSERT_X( mWaitDialog != 0, "BTUI_PAIR_WAIT_DOCML", "dialog not found" );
       
    88     
       
    89     heading = qobject_cast<HbLabel *>( mLoader->findWidget( "heading" ) );
       
    90     BTUI_ASSERT_X( heading != 0, "BTUI_PAIR_WAIT_DOCML", "heading not found" );
       
    91 
       
    92     progressBar = qobject_cast<HbProgressBar *>( mLoader->findWidget( "progressBar" ) );
       
    93     BTUI_ASSERT_X( progressBar != 0, "BTUI_PAIR_WAIT_DOCML", "progressBar not found" );
       
    94     progressBar->setRange(0,0);
       
    95     
       
    96     heading->setPlainText(headingText.arg(mdeviceName));
       
    97     
       
    98     mWaitDialog->setDismissPolicy(HbPopup::NoDismiss);
       
    99     mWaitDialog->setTimeout(HbPopup::NoTimeout);
       
   100 
       
   101     mWaitDialog->show();
       
   102 }
       
   103 
       
   104 void BtDelegatePair::ConnectComplete( TBTDevAddr& aAddr, TInt aErr, 
       
   105                                    RBTDevAddrArray* aConflicts )
       
   106 {
       
   107     Q_UNUSED(aAddr);
       
   108     Q_UNUSED(aErr);    
       
   109     Q_UNUSED(aConflicts);
       
   110 
       
   111 }
       
   112 
       
   113 void BtDelegatePair::DisconnectComplete( TBTDevAddr& aAddr, TInt aErr )
       
   114 {
       
   115     Q_UNUSED(aAddr);
       
   116     Q_UNUSED(aErr);    
       
   117 }
       
   118 
       
   119 void BtDelegatePair::PairingComplete( TBTDevAddr& aAddr, TInt aErr )
       
   120 {
       
   121     Q_UNUSED(aAddr);
       
   122     
       
   123     mWaitDialog->close();
       
   124     emitCommandComplete(aErr);
       
   125 }
       
   126 
       
   127 void BtDelegatePair::emitCommandComplete(int error)
       
   128 {
       
   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 
       
   139     emit commandCompleted(error);
       
   140 }
       
   141 
       
   142 void BtDelegatePair::cancel()
       
   143 {
       
   144     if ( mBtengConnMan ) {
       
   145         mBtengConnMan->CancelPairDevice();
       
   146     }
       
   147 }
       
   148 
       
   149 
       
   150