bluetoothengine/btui/btcpplugin/btcpuideviceview.cpp
changeset 41 0b2439c3e397
parent 40 997690c3397a
child 52 4545c04e61e1
equal deleted inserted replaced
40:997690c3397a 41:0b2439c3e397
    39 #include <btdelegatefactory.h>
    39 #include <btdelegatefactory.h>
    40 #include <QModelIndex>
    40 #include <QModelIndex>
    41 #include "btuiiconutil.h"
    41 #include "btuiiconutil.h"
    42 #include "btuidevtypemap.h"
    42 #include "btuidevtypemap.h"
    43 
    43 
       
    44 #include "btcpuidevicedetail.h"
       
    45 
    44 // docml to load
    46 // docml to load
    45 const char* BTUI_DEVICEVIEW_DOCML = ":/docml/bt-device-view.docml";
    47 const char* BTUI_DEVICEVIEW_DOCML = ":/docml/bt-device-view.docml";
    46 
    48 
    47 
    49 
    48 BtCpUiDeviceView::BtCpUiDeviceView(
    50 BtCpUiDeviceView::BtCpUiDeviceView(
    49         BtSettingModel &settingModel, 
    51         BtSettingModel &settingModel, 
    50         BtDeviceModel &deviceModel, 
    52         BtDeviceModel &deviceModel, 
    51         QGraphicsItem *parent) :
    53         QGraphicsItem *parent) :
    52     BtCpUiBaseView(settingModel,deviceModel,parent),
    54     BtCpUiBaseView(settingModel,deviceModel,parent),
    53     mPairedStatus(false), mConnectedStatus(false), mTrustedStatus(false), mBlockedStatus(false), 
    55     mPairedStatus(false), mConnectedStatus(false), mTrustedStatus(false), mBlockedStatus(false), 
    54     mConnectable(false), mAbstractDelegate(0)   
    56     mConnectable(false), mAbstractDelegate(0), mDeviceDetail(0)   
    55 {
    57 {
    56     mDeviceIndex = QModelIndex();//is it needed to initialize mIndex???
    58     mDeviceIndex = QModelIndex();//is it needed to initialize mIndex???
    57     
    59     
    58     mMainView = (BtCpUiMainView *) parent;
    60     mMainView = (BtCpUiMainView *) parent;
    59     
    61     
   144     BTUI_ASSERT_X( ret, "BtCpUiDeviceView::BtCpUiDeviceView", "can't connect disconnect button" );
   146     BTUI_ASSERT_X( ret, "BtCpUiDeviceView::BtCpUiDeviceView", "can't connect disconnect button" );
   145       
   147       
   146     mDeviceSetting = 0;
   148     mDeviceSetting = 0;
   147     mDeviceSetting = qobject_cast<HbPushButton *>( mLoader->findWidget( "pushButton_2" ) );
   149     mDeviceSetting = qobject_cast<HbPushButton *>( mLoader->findWidget( "pushButton_2" ) );
   148     BTUI_ASSERT_X( mDeviceSetting != 0, "bt-device-view", "settings button not found" );
   150     BTUI_ASSERT_X( mDeviceSetting != 0, "bt-device-view", "settings button not found" );
   149         
   151     
       
   152     
       
   153     ret = connect(mDeviceSetting, SIGNAL(clicked()), this,
       
   154             SLOT(handleDeviceSetting()));
       
   155     BTUI_ASSERT_X( ret, "Btui, BtCpUiDeviceView::BtCpUiDeviceView", "clicked() connect failed");
       
   156 
   150     setConnectionCombobox();
   157     setConnectionCombobox();
   151     
   158      
   152  
       
   153 }
   159 }
   154 
   160 
   155 BtCpUiDeviceView::~BtCpUiDeviceView()
   161 BtCpUiDeviceView::~BtCpUiDeviceView()
   156 {
   162 {
   157     delete mLoader; // Also deletes all widgets that it constructed.
   163     delete mLoader; // Also deletes all widgets that it constructed.
   163     if(mAbstractDelegate)
   169     if(mAbstractDelegate)
   164     {
   170     {
   165         delete mAbstractDelegate;
   171         delete mAbstractDelegate;
   166         mAbstractDelegate = 0;
   172         mAbstractDelegate = 0;
   167     }
   173     }
       
   174 
   168 }
   175 }
   169 
   176 
   170 
   177 
   171 void BtCpUiDeviceView::setSoftkeyBack()
   178 void BtCpUiDeviceView::setSoftkeyBack()
   172 {
   179 {
   178 
   185 
   179 void BtCpUiDeviceView::switchToPreviousView()
   186 void BtCpUiDeviceView::switchToPreviousView()
   180 {
   187 {
   181     BTUI_ASSERT_X(mMainView, "BtCpUiSearchView::switchToPreviousView", "invalid mMainView");
   188     BTUI_ASSERT_X(mMainView, "BtCpUiSearchView::switchToPreviousView", "invalid mMainView");
   182     mMainView->switchToPreviousView();
   189     mMainView->switchToPreviousView();
   183 }
   190     delete mDeviceDetail;
   184 
   191     mDeviceDetail = 0;
   185 void BtCpUiDeviceView::activateView( const QVariant& value, int cmdId )
   192 }
   186 {
   193 
   187     Q_UNUSED(cmdId);  
   194 void BtCpUiDeviceView::activateView( const QVariant& value, bool fromBackButton )
       
   195 {
       
   196     Q_UNUSED( fromBackButton );  
   188     
   197     
   189     setSoftkeyBack();
   198     setSoftkeyBack();
   190     
   199     
   191     QModelIndex index = value.value<QModelIndex>();
   200     QModelIndex index = value.value<QModelIndex>();
   192     mDeviceBdAddr = (mDeviceModel->data(index, BtDeviceModel::ReadableBdaddrRole));
   201     mDeviceBdAddr = (mDeviceModel->data(index, BtDeviceModel::ReadableBdaddrRole));
   193     
   202     
   194     //activate view is called when device is selected
   203     //activate view is called when device is selected
   195     //clearViewData();
   204     //clearViewData();
   196     updateDeviceData();
   205     updateDeviceData();
       
   206     
       
   207     mDeviceSetting->setVisible(false);
       
   208     
       
   209     mDeviceDetail = new BtCpUiDeviceDetail();
   197     
   210     
   198     bool ret(false);
   211     bool ret(false);
   199     ret=connect(mDeviceModel, SIGNAL(dataChanged(QModelIndex,QModelIndex)),
   212     ret=connect(mDeviceModel, SIGNAL(dataChanged(QModelIndex,QModelIndex)),
   200            this, SLOT(updateDeviceData()));
   213            this, SLOT(updateDeviceData()));
   201     BTUI_ASSERT_X( ret, "Btui, BtCpUiDeviceView::activateView", "dataChanged() connect failed");
   214     BTUI_ASSERT_X( ret, "Btui, BtCpUiDeviceView::activateView", "dataChanged() connect failed");
       
   215 
       
   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 }
       
   224 
       
   225 void BtCpUiDeviceView::handleDeviceSettingsChange(bool status)
       
   226 {
       
   227     mDeviceSetting->setVisible(status);        
       
   228 }
       
   229 
       
   230 void BtCpUiDeviceView::handleDeviceSetting()
       
   231 {
       
   232     mDeviceDetail->loadDeviceDetailsView();
   202 }
   233 }
   203 
   234 
   204 void BtCpUiDeviceView::deactivateView()
   235 void BtCpUiDeviceView::deactivateView()
   205 {
   236 {
   206 }
   237 }
   236 }
   267 }
   237     
   268     
   238 void BtCpUiDeviceView::updateDeviceData()
   269 void BtCpUiDeviceView::updateDeviceData()
   239 {
   270 {
   240     clearViewData();
   271     clearViewData();
   241     // ToDo:  the groupbox header should only say "Bluetooth", ie. without device name;
       
   242     // check new TextMap file for the right TextId
       
   243     /*QModelIndex localIndex = mSettingModel->index( BtSettingModel::LocalBtNameRow, 0);
       
   244     QString localName = (mSettingModel->data(localIndex,BtSettingModel::settingDisplayRole)).toString();
       
   245     QString groupBoxTitle (hbTrId("txt_bt_subhead_bluetooth_1").arg(localName));
       
   246     mGroupBox->setHeading(groupBoxTitle);
       
   247     */
       
   248     //Get the QModelIndex of the device using the device BDAddres
   272     //Get the QModelIndex of the device using the device BDAddres
   249     QModelIndex start = mDeviceModel->index(0,0);
   273     QModelIndex start = mDeviceModel->index(0,0);
   250     QModelIndexList indexList = mDeviceModel->match(start,BtDeviceModel::ReadableBdaddrRole, mDeviceBdAddr);
   274     QModelIndexList indexList = mDeviceModel->match(start,BtDeviceModel::ReadableBdaddrRole, mDeviceBdAddr);
   251     mDeviceIndex = indexList.at(0);
   275     mDeviceIndex = indexList.at(0);
   252     
   276     
   256     mDeviceName->setText(deviceName);
   280     mDeviceName->setText(deviceName);
   257      
   281      
   258     int cod = (mDeviceModel->data(mDeviceIndex,BtDeviceModel::CoDRole)).toInt();
   282     int cod = (mDeviceModel->data(mDeviceIndex,BtDeviceModel::CoDRole)).toInt();
   259      
   283      
   260     int majorRole = (mDeviceModel->data(mDeviceIndex,BtDeviceModel::MajorPropertyRole)).toInt();
   284     int majorRole = (mDeviceModel->data(mDeviceIndex,BtDeviceModel::MajorPropertyRole)).toInt();
   261     int minorRole = (mDeviceModel->data(mDeviceIndex,BtDeviceModel::MinorPropertyRole)).toInt();
   285     
   262     
   286 	setDeviceCategory(cod, majorRole);
   263 	setDeviceCategory(cod, majorRole, minorRole);
       
   264     setDeviceStatus(majorRole);
   287     setDeviceStatus(majorRole);
   265     setTextAndVisibilityOfButtons();
   288     setTextAndVisibilityOfButtons();
   266 }
   289 }
   267 
   290 
   268 void BtCpUiDeviceView::setDeviceCategory(int cod,int majorRole, int minorRole)
   291 void BtCpUiDeviceView::setDeviceCategory(int cod,int majorRole)
   269 {
   292 {
   270     mDeviceCategory->setPlainText( getDeviceTypeString( cod ));
   293     mDeviceCategory->setPlainText( getDeviceTypeString( cod ));
   271     HbIcon icon =
   294     HbIcon icon =
   272     getBadgedDeviceTypeIcon(cod, majorRole,
   295     getBadgedDeviceTypeIcon(cod, majorRole,
   273                             BtuiBottomLeft | BtuiBottomRight | BtuiTopLeft | BtuiTopRight );
   296                             BtuiBottomLeft | BtuiBottomRight | BtuiTopLeft | BtuiTopRight );
   274     mDeviceIcon->setIcon(icon);
   297     mDeviceIcon->setIcon(icon);
   275 
   298 
   276     if (majorRole & BtuiDevProperty::AVDev) {  
   299     if (majorRole & BtuiDevProperty::Connectable ) {
   277         if ( minorRole & BtuiDevProperty::Headset){
   300         mConnectable = true;
   278             // this is a Headset, it is possible to connect
   301     } 
   279             mConnectable = true;
       
   280         }
       
   281     }
       
   282 }
   302 }
   283 
   303 
   284 void BtCpUiDeviceView::setDeviceStatus(int majorRole)
   304 void BtCpUiDeviceView::setDeviceStatus(int majorRole)
   285 {
   305 {
   286     QString deviceStatus;
   306     QString deviceStatus;
   403     {
   423     {
   404         //it is not possible to connect, set the button invisible
   424         //it is not possible to connect, set the button invisible
   405         mConnect_Disconnect->setVisible(false);
   425         mConnect_Disconnect->setVisible(false);
   406     }
   426     }
   407     
   427     
   408     mDeviceSetting->setVisible(false);
       
   409 
       
   410 }
   428 }
   411 
   429 
   412 
   430 
   413 void BtCpUiDeviceView::pairUnpair()
   431 void BtCpUiDeviceView::pairUnpair()
   414 {
   432 {