bluetoothengine/btui/btcpplugin/btcpuideviceview.cpp
changeset 70 f5508c13dfe0
parent 67 16e4b9007960
equal deleted inserted replaced
67:16e4b9007960 70:f5508c13dfe0
    18 #include "btcpuideviceview.h"
    18 #include "btcpuideviceview.h"
    19 #include "btuiviewutil.h"
    19 #include "btuiviewutil.h"
    20 #include <QtGui/QGraphicsLinearLayout>
    20 #include <QtGui/QGraphicsLinearLayout>
    21 #include <hbmainwindow.h>
    21 #include <hbmainwindow.h>
    22 #include <hbdocumentloader.h>
    22 #include <hbdocumentloader.h>
    23 #include <hbdataform.h>
    23 #include <hbcombobox.h>
    24 #include <hbdataformmodel.h>
       
    25 #include <hbdataformmodelitem.h>
       
    26 #include <hbgroupbox.h>
    24 #include <hbgroupbox.h>
    27 #include <hbpushbutton.h>
    25 #include <hbpushbutton.h>
    28 #include <hblabel.h>
    26 #include <hblabel.h>
    29 #include <hbicon.h>
    27 #include <hbicon.h>
    30 #include <hblineedit.h>
    28 #include <hblineedit.h>
    99     mDeviceStatus=0;
    97     mDeviceStatus=0;
   100     mDeviceStatus = qobject_cast<HbLabel *>( mLoader->findWidget( "deviceStatus" ) );  
    98     mDeviceStatus = qobject_cast<HbLabel *>( mLoader->findWidget( "deviceStatus" ) );  
   101     BTUI_ASSERT_X( mDeviceStatus != 0, "bt-device-view", "Device status not found" );
    99     BTUI_ASSERT_X( mDeviceStatus != 0, "bt-device-view", "Device status not found" );
   102     
   100     
   103     
   101     
   104     mConnectionDataForm = 0;
   102     mCombobox = 0;
   105     mConnectionDataForm = qobject_cast<HbDataForm *>( mLoader->findWidget( "connectionCombobox" ) );
   103     mCombobox = qobject_cast<HbComboBox *>( mLoader->findWidget( "connectionCombobox" ) );
   106     BTUI_ASSERT_X( mConnectionDataForm != 0, "bt-device-view", "connection combobox not found" );
   104     BTUI_ASSERT_X( mCombobox != 0, "bt-device-view", "connection combobox not found" );
   107     
   105     
   108     mConnectionComboboxModel = new HbDataFormModel( this );
   106     ret = connect(mCombobox, SIGNAL(currentIndexChanged (int)), 
   109     
   107                 this, SLOT(connectionPreferenceChanged(int)));
       
   108     BTUI_ASSERT_X( ret, "Btui, BtcpuiDeviceView::BtcpuiDeviceView", "currentIndexChanged() connect failed");
       
   109         
   110     mPair_Unpair=0;
   110     mPair_Unpair=0;
   111     mPair_Unpair = qobject_cast<HbPushButton *>( mLoader->findWidget( "devicePairUnpair" ) );
   111     mPair_Unpair = qobject_cast<HbPushButton *>( mLoader->findWidget( "devicePairUnpair" ) );
   112     BTUI_ASSERT_X( mPair_Unpair != 0, "bt-device-view", "pair/unpair button not found" );
   112     BTUI_ASSERT_X( mPair_Unpair != 0, "bt-device-view", "pair/unpair button not found" );
   113  
   113  
   114     mConnect_Disconnect=0;
   114     mConnect_Disconnect=0;
   120     BTUI_ASSERT_X( mDeviceSetting != 0, "bt-device-view", "settings button not found" );
   120     BTUI_ASSERT_X( mDeviceSetting != 0, "bt-device-view", "settings button not found" );
   121     ret = connect(mDeviceSetting, SIGNAL(clicked()), this,
   121     ret = connect(mDeviceSetting, SIGNAL(clicked()), this,
   122             SLOT(handleDeviceSetting()));
   122             SLOT(handleDeviceSetting()));
   123     BTUI_ASSERT_X( ret, "Btui, BtcpuiDeviceView::BtcpuiDeviceView", "clicked() connect failed");
   123     BTUI_ASSERT_X( ret, "Btui, BtcpuiDeviceView::BtcpuiDeviceView", "clicked() connect failed");
   124 
   124 
   125     setConnectionCombobox();
   125 
   126 }
   126 }
   127 
   127 
   128 BtcpuiDeviceView::~BtcpuiDeviceView()
   128 BtcpuiDeviceView::~BtcpuiDeviceView()
   129 {
   129 {
   130     BOstraceFunctionEntry1( DUMMY_DEVLIST, this );
   130     BOstraceFunctionEntry1( DUMMY_DEVLIST, this );
   309 
   309 
   310 void BtcpuiDeviceView::setDeviceStatus(int majorRole)
   310 void BtcpuiDeviceView::setDeviceStatus(int majorRole)
   311 {
   311 {
   312     BOstraceFunctionEntry1( DUMMY_DEVLIST, this );
   312     BOstraceFunctionEntry1( DUMMY_DEVLIST, this );
   313     QString deviceStatus;
   313     QString deviceStatus;
       
   314     bool ret = false;
       
   315     
   314     // Avoid unnecessary actions:
   316     // Avoid unnecessary actions:
   315     // The device model has been modified and need to be reflected
   317     // The device model has been modified and need to be reflected
   316     // in the UI however if we don't disable the signal before the UI update
   318     // in the UI however if we don't disable the signal before the UI update
   317     // the connectionPreferenceChanged function will be called and trigger
   319     // the connectionPreferenceChanged function will be called and trigger
   318     // unnecessary update of the model by the device view.
   320     // unnecessary update of the model by the device view.
   319     mConnectionDataForm->removeConnection(mCombobox, SIGNAL(currentIndexChanged (int)), 
   321     ret = disconnect(mCombobox, SIGNAL(currentIndexChanged (int)), 
   320             this, SLOT(connectionPreferenceChanged(int)));
   322             this, SLOT(connectionPreferenceChanged(int)));
       
   323     BTUI_ASSERT_X( ret, "Btui, BtcpuiDeviceView::setDeviceStatus", "currentIndexChanged() disconnect failed");
       
   324     
   321     if (majorRole & BtuiDevProperty::Bonded && 
   325     if (majorRole & BtuiDevProperty::Bonded && 
   322         majorRole & BtuiDevProperty::Trusted &&
   326         majorRole & BtuiDevProperty::Trusted &&
   323         majorRole & BtuiDevProperty::Connected ) {
   327         majorRole & BtuiDevProperty::Connected ) {
   324         mDeviceStatus->setPlainText(hbTrId("txt_bt_info_paired_trused_connected"));
   328         mDeviceStatus->setPlainText(hbTrId("txt_bt_info_paired_trused_connected"));
   325         mCombobox->setContentWidgetData("currentIndex", ConnectionAutomatic );
   329         mCombobox->setCurrentIndex(ConnectionAutomatic );
   326         mComboboxIndex = ConnectionAutomatic;
   330         mComboboxIndex = ConnectionAutomatic;
   327     } 
   331     } 
   328     else if (majorRole & BtuiDevProperty::Bonded && 
   332     else if (majorRole & BtuiDevProperty::Bonded && 
   329              majorRole & BtuiDevProperty::Connected ) {
   333              majorRole & BtuiDevProperty::Connected ) {
   330         mDeviceStatus->setPlainText(hbTrId("txt_bt_info_paired_connected"));
   334         mDeviceStatus->setPlainText(hbTrId("txt_bt_info_paired_connected"));
   331         mCombobox->setContentWidgetData("currentIndex", ConnectionAlwaysAsk );
   335         mCombobox->setCurrentIndex(ConnectionAlwaysAsk );
   332         mComboboxIndex = ConnectionAlwaysAsk;
   336         mComboboxIndex = ConnectionAlwaysAsk;
   333     }
   337     }
   334     else if (majorRole & BtuiDevProperty::Bonded && 
   338     else if (majorRole & BtuiDevProperty::Bonded && 
   335              majorRole & BtuiDevProperty::Trusted ) {
   339              majorRole & BtuiDevProperty::Trusted ) {
   336         mDeviceStatus->setPlainText(hbTrId("txt_bt_info_paired_trusted"));
   340         mDeviceStatus->setPlainText(hbTrId("txt_bt_info_paired_trusted"));
   337         mCombobox->setContentWidgetData("currentIndex", ConnectionAutomatic );
   341         mCombobox->setCurrentIndex(ConnectionAutomatic );
   338         mComboboxIndex = ConnectionAutomatic;
   342         mComboboxIndex = ConnectionAutomatic;
   339     } 
   343     } 
   340     else if (majorRole & BtuiDevProperty::Connected && 
   344     else if (majorRole & BtuiDevProperty::Connected && 
   341              majorRole & BtuiDevProperty::Trusted ) {
   345              majorRole & BtuiDevProperty::Trusted ) {
   342         mDeviceStatus->setPlainText(hbTrId("Trusted, Connected"));  // ToDo: missing textId!
   346         mDeviceStatus->setPlainText(hbTrId("Trusted, Connected"));  // ToDo: missing textId!
   343         mCombobox->setContentWidgetData("currentIndex", ConnectionAutomatic );
   347         mCombobox->setCurrentIndex(ConnectionAutomatic );
   344         mComboboxIndex = ConnectionAutomatic;
   348         mComboboxIndex = ConnectionAutomatic;
   345     } 
   349     } 
   346     else if (majorRole & BtuiDevProperty::Trusted ) {
   350     else if (majorRole & BtuiDevProperty::Trusted ) {
   347         mDeviceStatus->setPlainText(hbTrId("Trusted"));  // ToDo: missing textId!
   351         mDeviceStatus->setPlainText(hbTrId("Trusted"));  // ToDo: missing textId!
   348         mCombobox->setContentWidgetData("currentIndex", ConnectionAutomatic );
   352         mCombobox->setCurrentIndex(ConnectionAutomatic );
   349         mComboboxIndex = ConnectionAutomatic;
   353         mComboboxIndex = ConnectionAutomatic;
   350     } 
   354     } 
   351     else if (majorRole & BtuiDevProperty::Bonded) {
   355     else if (majorRole & BtuiDevProperty::Bonded) {
   352         mDeviceStatus->setPlainText(hbTrId("txt_bt_info_paired"));
   356         mDeviceStatus->setPlainText(hbTrId("txt_bt_info_paired"));
   353         mCombobox->setContentWidgetData("currentIndex", ConnectionAlwaysAsk );
   357         mCombobox->setCurrentIndex(ConnectionAlwaysAsk );
   354         mComboboxIndex = ConnectionAlwaysAsk;
   358         mComboboxIndex = ConnectionAlwaysAsk;
   355     }
   359     }
   356     else if (majorRole & BtuiDevProperty::Connected) {
   360     else if (majorRole & BtuiDevProperty::Connected) {
   357         mDeviceStatus->setPlainText(hbTrId("txt_bt_info_connected"));
   361         mDeviceStatus->setPlainText(hbTrId("txt_bt_info_connected"));
   358         mCombobox->setContentWidgetData("currentIndex", ConnectionAlwaysAsk );
   362         mCombobox->setCurrentIndex(ConnectionAlwaysAsk );
   359         mComboboxIndex = ConnectionAlwaysAsk;
   363         mComboboxIndex = ConnectionAlwaysAsk;
   360     }
   364     }
   361     else if (majorRole & BtuiDevProperty::Blocked) {
   365     else if (majorRole & BtuiDevProperty::Blocked) {
   362         mDeviceStatus->setPlainText(hbTrId("txt_bt_info_blocked"));
   366         mDeviceStatus->setPlainText(hbTrId("txt_bt_info_blocked"));
   363         mCombobox->setContentWidgetData("currentIndex", ConnectionBlocked );
   367         mCombobox->setCurrentIndex(ConnectionBlocked );
   364         mComboboxIndex = ConnectionBlocked;
   368         mComboboxIndex = ConnectionBlocked;
   365     }
   369     }
   366     else {
   370     else {
   367         // device not paired, connected, trusted or blocked.  
   371         // device not paired, connected, trusted or blocked.  
   368         mDeviceStatus->setPlainText(" ");
   372         mDeviceStatus->setPlainText(" ");
   369         mCombobox->setContentWidgetData("currentIndex", ConnectionAlwaysAsk );
   373         mCombobox->setCurrentIndex(ConnectionAlwaysAsk );
   370         mComboboxIndex = ConnectionAlwaysAsk;
   374         mComboboxIndex = ConnectionAlwaysAsk;
   371     }
   375     }
   372     mConnectionDataForm->addConnection(mCombobox, SIGNAL(currentIndexChanged (int)), 
   376     ret = connect(mCombobox, SIGNAL(currentIndexChanged (int)), 
   373             this, SLOT(connectionPreferenceChanged(int)));
   377             this, SLOT(connectionPreferenceChanged(int)));
   374     BOstraceFunctionExit0(DUMMY_DEVLIST);
   378     BTUI_ASSERT_X( ret, "Btui, BtcpuiDeviceView::setDeviceStatus", "currentIndexChanged() connect failed");
   375 }
   379     
   376 
   380     BOstraceFunctionExit0(DUMMY_DEVLIST);
   377 void BtcpuiDeviceView::setConnectionCombobox()
       
   378 {
       
   379     BOstraceFunctionEntry1( DUMMY_DEVLIST, this );
       
   380     //create a model class
       
   381     mCombobox = mConnectionComboboxModel->appendDataFormItem(
       
   382     HbDataFormModelItem::ComboBoxItem, hbTrId("txt_bt_setlabel_connection"), 
       
   383         mConnectionComboboxModel->invisibleRootItem());
       
   384     
       
   385     QStringList connList;
       
   386     connList.append( hbTrId("txt_bt_setlabel_bluetooth_val_automatic") );
       
   387     connList.append( hbTrId("txt_bt_setlabel_bluetooth_val_always_ask") );
       
   388     connList.append( hbTrId("txt_bt_setlabel_bluetooth_val_blocked") );
       
   389     mCombobox->setContentWidgetData( "items", connList );
       
   390 
       
   391     //set the model to the view, once model and data class are created
       
   392     mConnectionDataForm->setModel(mConnectionComboboxModel);
       
   393     mConnectionDataForm->addConnection(mCombobox, SIGNAL(currentIndexChanged (int)), 
       
   394             this, SLOT(connectionPreferenceChanged(int)));
       
   395     BOstraceFunctionExit0(DUMMY_DEVLIST);    
       
   396 }
   381 }
   397 
   382 
   398 void BtcpuiDeviceView::setTextAndVisibilityOfButtons(int majorProperty)
   383 void BtcpuiDeviceView::setTextAndVisibilityOfButtons(int majorProperty)
   399 {
   384 {
   400     BOstraceFunctionEntry1( DUMMY_DEVLIST, this );
   385     BOstraceFunctionEntry1( DUMMY_DEVLIST, this );
   691         
   676         
   692         QVariant params;
   677         QVariant params;
   693         params.setValue(list);
   678         params.setValue(list);
   694         
   679         
   695         mAbstractDelegate = BtDelegateFactory::newDelegate(
   680         mAbstractDelegate = BtDelegateFactory::newDelegate(
   696                 BtDelegate::ChangeDeviceFriendlyName, mSettingModel, mDeviceModel); 
   681                 BtDelegate::ChangeDeviceFriendlyName, mSettingModel, mDeviceModel);
   697         connect( mAbstractDelegate, SIGNAL(delegateCompleted(int,BtAbstractDelegate*)), 
   682         
   698                 this, SLOT(changeDevNameDelegateCompleted(int, QVariant)) );
   683         bool ok(false);
   699         mAbstractDelegate->exec(params);
   684         ok =connect( mAbstractDelegate, SIGNAL(delegateCompleted(int,BtAbstractDelegate*)), 
       
   685                 this, SLOT(changeDevNameDelegateCompleted(int)) );
       
   686         BTUI_ASSERT_X( ok, "BtcpuiDeviceView", "changeDevName: fail to connect signal" );
       
   687         
       
   688 		mAbstractDelegate->exec(params);
   700     }
   689     }
   701     else {
   690     else {
   702         setPrevBtDeviceName();
   691         setPrevBtDeviceName();
   703     }
   692     }
   704     BOstraceFunctionExit0(DUMMY_DEVLIST);
   693     BOstraceFunctionExit0(DUMMY_DEVLIST);