bluetoothengine/btui/btcpplugin/btcpuideviceview.cpp
changeset 52 4545c04e61e1
parent 41 0b2439c3e397
child 63 bcf742120177
equal deleted inserted replaced
41:0b2439c3e397 52:4545c04e61e1
    50 BtCpUiDeviceView::BtCpUiDeviceView(
    50 BtCpUiDeviceView::BtCpUiDeviceView(
    51         BtSettingModel &settingModel, 
    51         BtSettingModel &settingModel, 
    52         BtDeviceModel &deviceModel, 
    52         BtDeviceModel &deviceModel, 
    53         QGraphicsItem *parent) :
    53         QGraphicsItem *parent) :
    54     BtCpUiBaseView(settingModel,deviceModel,parent),
    54     BtCpUiBaseView(settingModel,deviceModel,parent),
    55     mPairedStatus(false), mConnectedStatus(false), mTrustedStatus(false), mBlockedStatus(false), 
    55     mPairedStatus(false), mConnectedStatus(false),mPreviousConnectedStatus(false), mTrustedStatus(false), 
    56     mConnectable(false), mAbstractDelegate(0), mDeviceDetail(0)   
    56     mBlockedStatus(false), mConnectable(false), mAbstractDelegate(0), mDeviceDetail(0)   
    57 {
    57 {
    58     mDeviceIndex = QModelIndex();//is it needed to initialize mIndex???
    58     mDeviceIndex = QModelIndex();//is it needed to initialize mIndex???
    59     
    59     
    60     mMainView = (BtCpUiMainView *) parent;
    60     mMainView = (BtCpUiMainView *) parent;
    61     
    61     
   185 
   185 
   186 void BtCpUiDeviceView::switchToPreviousView()
   186 void BtCpUiDeviceView::switchToPreviousView()
   187 {
   187 {
   188     BTUI_ASSERT_X(mMainView, "BtCpUiSearchView::switchToPreviousView", "invalid mMainView");
   188     BTUI_ASSERT_X(mMainView, "BtCpUiSearchView::switchToPreviousView", "invalid mMainView");
   189     mMainView->switchToPreviousView();
   189     mMainView->switchToPreviousView();
   190     delete mDeviceDetail;
   190 
   191     mDeviceDetail = 0;
   191     if(mDeviceDetail) {
       
   192         mDeviceDetail->sendCloseEvent();
       
   193     }
       
   194     unloadDeviceDetails();
       
   195 }
       
   196 
       
   197 void BtCpUiDeviceView::loadDeviceDetails()
       
   198 {
       
   199     bool ret(false);
       
   200     
       
   201     unloadDeviceDetails();
       
   202     
       
   203     mDeviceDetail = new BtCpUiDeviceDetail();
       
   204     
       
   205     ret=connect(mDeviceDetail, SIGNAL(deviceSettingsChanged(bool)),
       
   206            this, SLOT(handleDeviceSettingsChange(bool)));
       
   207     BTUI_ASSERT_X( ret, "Btui, BtCpUiDeviceView::loadDeviceDetails", "deviceSettingsChanged() connect failed");
       
   208 
       
   209     mDeviceDetail->loadDeviceDetailPlugins(mDeviceBdAddr.toString(), mDeviceName->text());
       
   210 }
       
   211 
       
   212 void BtCpUiDeviceView::unloadDeviceDetails()
       
   213 {
       
   214     if(mDeviceDetail) {
       
   215         disconnect(mDeviceDetail);
       
   216         delete mDeviceDetail;
       
   217         mDeviceDetail = 0;
       
   218     }
   192 }
   219 }
   193 
   220 
   194 void BtCpUiDeviceView::activateView( const QVariant& value, bool fromBackButton )
   221 void BtCpUiDeviceView::activateView( const QVariant& value, bool fromBackButton )
   195 {
   222 {
       
   223     
   196     Q_UNUSED( fromBackButton );  
   224     Q_UNUSED( fromBackButton );  
   197     
   225     
       
   226     mConnectedStatus = false;
   198     setSoftkeyBack();
   227     setSoftkeyBack();
       
   228     
   199     
   229     
   200     QModelIndex index = value.value<QModelIndex>();
   230     QModelIndex index = value.value<QModelIndex>();
   201     mDeviceBdAddr = (mDeviceModel->data(index, BtDeviceModel::ReadableBdaddrRole));
   231     mDeviceBdAddr = (mDeviceModel->data(index, BtDeviceModel::ReadableBdaddrRole));
   202     
   232     
   203     //activate view is called when device is selected
   233     //activate view is called when device is selected
   204     //clearViewData();
   234     //clearViewData();
   205     updateDeviceData();
   235     updateDeviceData();
   206     
   236     
   207     mDeviceSetting->setVisible(false);
   237     mDeviceSetting->setVisible(false);
   208     
   238         
   209     mDeviceDetail = new BtCpUiDeviceDetail();
       
   210     
       
   211     bool ret(false);
   239     bool ret(false);
   212     ret=connect(mDeviceModel, SIGNAL(dataChanged(QModelIndex,QModelIndex)),
   240     ret=connect(mDeviceModel, SIGNAL(dataChanged(QModelIndex,QModelIndex)),
   213            this, SLOT(updateDeviceData()));
   241            this, SLOT(updateDeviceData()));
   214     BTUI_ASSERT_X( ret, "Btui, BtCpUiDeviceView::activateView", "dataChanged() connect failed");
   242     BTUI_ASSERT_X( ret, "Btui, BtCpUiDeviceView::activateView", "dataChanged() connect failed");
   215 
   243 
   216     ret=connect(mDeviceDetail, SIGNAL(deviceSettingsChanged(bool)),
       
   217            this, SLOT(handleDeviceSettingsChange(bool)));
       
   218     BTUI_ASSERT_X( ret, "Btui, BtCpUiDeviceView::activateView", "deviceSettingsChanged() connect failed");
       
   219 
       
   220     
       
   221     mDeviceDetail->loadDeviceDetailPlugins(mDeviceBdAddr.toString(), mDeviceName->text());
       
   222     
       
   223 }
   244 }
   224 
   245 
   225 void BtCpUiDeviceView::handleDeviceSettingsChange(bool status)
   246 void BtCpUiDeviceView::handleDeviceSettingsChange(bool status)
   226 {
   247 {
   227     mDeviceSetting->setVisible(status);        
   248     mDeviceSetting->setVisible(status);
   228 }
   249 }
   229 
   250 
   230 void BtCpUiDeviceView::handleDeviceSetting()
   251 void BtCpUiDeviceView::handleDeviceSetting()
   231 {
   252 {
   232     mDeviceDetail->loadDeviceDetailsView();
   253     if(mDeviceDetail) {
       
   254         mDeviceDetail->loadDeviceDetailsView();
       
   255     }
   233 }
   256 }
   234 
   257 
   235 void BtCpUiDeviceView::deactivateView()
   258 void BtCpUiDeviceView::deactivateView()
   236 {
   259 {
   237 }
   260 }
   255 void BtCpUiDeviceView::clearViewData()
   278 void BtCpUiDeviceView::clearViewData()
   256 {
   279 {
   257     mDeviceIcon->clear();
   280     mDeviceIcon->clear();
   258     mDeviceCategory->clear();
   281     mDeviceCategory->clear();
   259     mDeviceStatus->clear();
   282     mDeviceStatus->clear();
   260     
   283     mConnectable = false;
       
   284     /*
   261     mPairedStatus = false;
   285     mPairedStatus = false;
   262     mConnectedStatus = false;
   286     mConnectedStatus = false;
   263     mTrustedStatus = false;
   287     mTrustedStatus = false;
   264     mBlockedStatus = false;
   288     mBlockedStatus = false;
   265     
   289     
   266     mConnectable = false;
   290     mConnectable = false;
       
   291     */
   267 }
   292 }
   268     
   293     
   269 void BtCpUiDeviceView::updateDeviceData()
   294 void BtCpUiDeviceView::updateDeviceData()
   270 {
   295 {
   271     clearViewData();
   296     clearViewData();
   353 /*!
   378 /*!
   354  *  instead of using separate boolean variables we could use bitmap in single variable
   379  *  instead of using separate boolean variables we could use bitmap in single variable
   355  */
   380  */
   356 void BtCpUiDeviceView::updateStatusVariables(int majorRole)
   381 void BtCpUiDeviceView::updateStatusVariables(int majorRole)
   357 {
   382 {
       
   383     mPreviousConnectedStatus = mConnectedStatus;
       
   384     
   358     if (majorRole & BtuiDevProperty::Trusted ) {
   385     if (majorRole & BtuiDevProperty::Trusted ) {
   359         mTrustedStatus = true;
   386         mTrustedStatus = true;
   360     } 
   387     } 
   361     else {
   388     else {
   362         mTrustedStatus = false;
   389         mTrustedStatus = false;
   367     else {
   394     else {
   368         mPairedStatus = false;
   395         mPairedStatus = false;
   369     }
   396     }
   370     if (majorRole & BtuiDevProperty::Connected) {
   397     if (majorRole & BtuiDevProperty::Connected) {
   371         mConnectedStatus = true;
   398         mConnectedStatus = true;
       
   399         if (!mPreviousConnectedStatus){
       
   400             //Loading device detail plugins after successfull connection.
       
   401             loadDeviceDetails();
       
   402         }
   372     }
   403     }
   373     else {
   404     else {
   374         mConnectedStatus = false;
   405         mConnectedStatus = false;
   375     }
   406     }
   376     if (majorRole & BtuiDevProperty::Blocked) {
   407     if (majorRole & BtuiDevProperty::Blocked) {
   400         mPair_Unpair->setText(hbTrId("txt_bt_button_pair"));
   431         mPair_Unpair->setText(hbTrId("txt_bt_button_pair"));
   401     }
   432     }
   402     
   433     
   403     if (mConnectable)
   434     if (mConnectable)
   404     {
   435     {
       
   436         mConnect_Disconnect->setVisible(true);
   405         mConnect_Disconnect->setStretched(true);
   437         mConnect_Disconnect->setStretched(true);
   406         if (mConnectedStatus)
   438         if (mConnectedStatus)
   407         {
   439         {
   408             HbIcon icon("qtg_mono_speaker_off");
   440             HbIcon icon("qtg_mono_speaker_off");
   409             icon.setIconName("qtg_mono_speaker_off");
   441             icon.setIconName("qtg_mono_speaker_off");
   537     {
   569     {
   538         disconnect(mAbstractDelegate);
   570         disconnect(mAbstractDelegate);
   539         delete mAbstractDelegate;
   571         delete mAbstractDelegate;
   540         mAbstractDelegate = 0;
   572         mAbstractDelegate = 0;
   541     }   
   573     }   
   542     
       
   543     
       
   544 }
   574 }
   545 
   575 
   546 void BtCpUiDeviceView::disconnectDevice()
   576 void BtCpUiDeviceView::disconnectDevice()
   547 {
   577 {
   548     if (!mAbstractDelegate)//if there is no other delegate running
   578     if (!mAbstractDelegate)//if there is no other delegate running
   580     if (mAbstractDelegate)
   610     if (mAbstractDelegate)
   581     {
   611     {
   582         disconnect(mAbstractDelegate);
   612         disconnect(mAbstractDelegate);
   583         delete mAbstractDelegate;
   613         delete mAbstractDelegate;
   584         mAbstractDelegate = 0;
   614         mAbstractDelegate = 0;
   585     }   
   615     }
   586     
   616 }
   587     
   617 
       
   618 void BtCpUiDeviceView::setPrevBtDeviceName()
       
   619 {
       
   620     QString deviceName = (mDeviceModel->data(mDeviceIndex, 
       
   621                 BtDeviceModel::NameAliasRole)).toString(); 
       
   622    mDeviceName->setText(deviceName);
   588 }
   623 }
   589 
   624 
   590 void BtCpUiDeviceView::changeBtDeviceName(){
   625 void BtCpUiDeviceView::changeBtDeviceName(){
   591     if (!mAbstractDelegate)//if there is no other delegate running
   626     if (!mAbstractDelegate)//if there is no other delegate running
   592     { 
   627     { 
   607         mAbstractDelegate = BtDelegateFactory::newDelegate(
   642         mAbstractDelegate = BtDelegateFactory::newDelegate(
   608                 BtDelegate::RemoteDevName, mSettingModel, mDeviceModel); 
   643                 BtDelegate::RemoteDevName, mSettingModel, mDeviceModel); 
   609         connect( mAbstractDelegate, SIGNAL(commandCompleted(int, QVariant)), this, SLOT(changeDevNameDelegateCompleted(int, QVariant)) );
   644         connect( mAbstractDelegate, SIGNAL(commandCompleted(int, QVariant)), this, SLOT(changeDevNameDelegateCompleted(int, QVariant)) );
   610         mAbstractDelegate->exec(params);
   645         mAbstractDelegate->exec(params);
   611     }
   646     }
       
   647     else {
       
   648         setPrevBtDeviceName();
       
   649     }
   612     
   650     
   613 }
   651 }
   614 
   652 
   615 void BtCpUiDeviceView::changeDevNameDelegateCompleted(int status, QVariant param)
   653 void BtCpUiDeviceView::changeDevNameDelegateCompleted(int status, QVariant param)
   616 {
   654 {
   618     
   656     
   619     if(KErrNone == status) {
   657     if(KErrNone == status) {
   620         mDeviceName->setText(param.toString());
   658         mDeviceName->setText(param.toString());
   621     }
   659     }
   622     else {
   660     else {
   623         //setPrevBtLocalName();
   661         setPrevBtDeviceName();
   624     }
   662     }
   625     //TODO:Error handling has to be done.    
   663     //TODO:Error handling has to be done.    
   626     if (mAbstractDelegate)
   664     if (mAbstractDelegate)
   627     {
   665     {
   628         disconnect(mAbstractDelegate);
   666         disconnect(mAbstractDelegate);