bluetoothengine/btui/btcpplugin/btcpuideviceview.cpp
changeset 40 997690c3397a
parent 33 837dcc42fd6a
child 41 0b2439c3e397
equal deleted inserted replaced
37:91746b151f97 40:997690c3397a
     1 /*
     1 /*
     2  * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
     2  * Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
     3  * All rights reserved.
     3  * All rights reserved.
     4  * This component and the accompanying materials are made available
     4  * This component and the accompanying materials are made available
     5  * under the terms of "Eclipse Public License v1.0""
     5  * under the terms of "Eclipse Public License v1.0""
     6  * which accompanies this distribution, and is available
     6  * which accompanies this distribution, and is available
     7  * at the URL "http://www.eclipse.org/legal/epl-v10.html".
     7  * at the URL "http://www.eclipse.org/legal/epl-v10.html".
    19 #include "btuiviewutil.h"
    19 #include "btuiviewutil.h"
    20 #include <QtGui/QGraphicsLinearLayout>
    20 #include <QtGui/QGraphicsLinearLayout>
    21 #include <HbInstance>
    21 #include <HbInstance>
    22 #include <hbdocumentloader.h>
    22 #include <hbdocumentloader.h>
    23 #include <hbdataform.h>
    23 #include <hbdataform.h>
       
    24 #include <hbdataformmodel.h>
       
    25 #include <hbdataformmodelitem.h>
    24 #include <hbgroupbox.h>
    26 #include <hbgroupbox.h>
    25 #include <hbpushbutton.h>
    27 #include <hbpushbutton.h>
    26 #include <hblabel.h>
    28 #include <hblabel.h>
    27 #include <hbtextedit.h>
    29 #include <hbicon.h>
       
    30 #include <hblineedit.h>
    28 #include <hblistview.h>
    31 #include <hblistview.h>
    29 #include <hbmenu.h>
    32 #include <hbmenu.h>
    30 #include <qstring>
    33 #include <qstring>
    31 #include <qstringlist>
    34 #include <qstringlist>
    32 #include <qdebug>
    35 #include <qdebug>
    33 #include <bluetoothuitrace.h>
    36 #include <bluetoothuitrace.h>
    34 #include "btcpuimainview.h"
    37 #include "btcpuimainview.h"
    35 #include <btabstractdelegate.h>
    38 #include <btabstractdelegate.h>
    36 #include <btdelegatefactory.h>
    39 #include <btdelegatefactory.h>
    37 #include <QModelIndex>
    40 #include <QModelIndex>
       
    41 #include "btuiiconutil.h"
       
    42 #include "btuidevtypemap.h"
    38 
    43 
    39 // docml to load
    44 // docml to load
    40 const char* BTUI_DEVICEVIEW_DOCML = ":/docml/bt-device-view.docml";
    45 const char* BTUI_DEVICEVIEW_DOCML = ":/docml/bt-device-view.docml";
    41 
    46 
    42 
    47 
    43 BtCpUiDeviceView::BtCpUiDeviceView(
    48 BtCpUiDeviceView::BtCpUiDeviceView(
    44         BtSettingModel &settingModel, 
    49         BtSettingModel &settingModel, 
    45         BtDeviceModel &deviceModel, 
    50         BtDeviceModel &deviceModel, 
    46         QGraphicsItem *parent) :
    51         QGraphicsItem *parent) :
    47     BtCpUiBaseView(settingModel,deviceModel,parent),
    52     BtCpUiBaseView(settingModel,deviceModel,parent),
    48     mPairStatus(false), mConnectStatus(false), mConnectable(false), mAbstractDelegate(0)   
    53     mPairedStatus(false), mConnectedStatus(false), mTrustedStatus(false), mBlockedStatus(false), 
       
    54     mConnectable(false), mAbstractDelegate(0)   
    49 {
    55 {
    50     mDeviceIndex = QModelIndex();//is it needed to initialize mIndex???
    56     mDeviceIndex = QModelIndex();//is it needed to initialize mIndex???
    51     
    57     
    52     mMainView = (BtCpUiMainView *) parent;
    58     mMainView = (BtCpUiMainView *) parent;
    53     
    59     
    61     // Create view for the application.
    67     // Create view for the application.
    62     // Set the name for the view. The name should be same as the view's
    68     // Set the name for the view. The name should be same as the view's
    63     // name in docml.
    69     // name in docml.
    64     setObjectName("bt_device_view");
    70     setObjectName("bt_device_view");
    65 
    71 
       
    72     mLoader = new HbDocumentLoader();
       
    73     // Pass the view to documentloader. Document loader uses this view
       
    74     // when docml is parsed, instead of creating new view.
    66     QObjectList objectList;
    75     QObjectList objectList;
    67     objectList.append(this);
    76     objectList.append(this);
    68     // Pass the view to documentloader. Document loader uses this view
       
    69     // when docml is parsed, instead of creating new view.
       
    70     mLoader = new HbDocumentLoader();
       
    71     mLoader->setObjectTree(objectList);
    77     mLoader->setObjectTree(objectList);
    72     
    78     
    73     bool ret = false;
    79     bool ret = false;
    74 
    80 
    75     bool ok = false;
    81     bool ok = false;
    76     mLoader->load( BTUI_DEVICEVIEW_DOCML, &ok );
    82     mLoader->load( BTUI_DEVICEVIEW_DOCML, &ok );
    77     // Exit if the file format is invalid
    83     // Exit if the file format is invalid
    78     BTUI_ASSERT_X( ok, "bt-device-view", "Invalid docml file" );
    84     BTUI_ASSERT_X( ok, "bt-device-view", "Invalid docml file" );
    79     
    85     
    80     // Set title for the control panel
    86     mOrientation = mMainWindow->orientation();
    81     // ToDo:  check if deprecated API
    87         
    82     setTitle("Control Panel");
    88     if (mOrientation == Qt::Horizontal) {
    83 
    89         mLoader->load(BTUI_DEVICEVIEW_DOCML, "landscape", &ok);
       
    90         BTUI_ASSERT_X( ok, "bt-device-view", "Invalid docml file: landscape section problem" );
       
    91     }
       
    92     else {
       
    93         mLoader->load(BTUI_DEVICEVIEW_DOCML, "portrait", &ok);
       
    94         BTUI_ASSERT_X( ok, "bt-device-view", "Invalid docml file: landscape section problem" );        
       
    95     }
       
    96     
       
    97     // listen for orientation changes
       
    98     ret = connect(mMainWindow, SIGNAL(orientationChanged(Qt::Orientation)),
       
    99             this, SLOT(changeOrientation(Qt::Orientation)));
       
   100     BTUI_ASSERT_X( ret, "BtCpUiDeviceView::BtCpUiDeviceView()", "connect orientationChanged() failed");
       
   101 
       
   102     
    84     // assign automatically created widgets to local variables
   103     // assign automatically created widgets to local variables
    85     
   104     /*
    86     mGroupBox = 0;
   105     mGroupBox = 0;
    87     mGroupBox = qobject_cast<HbGroupBox *>( mLoader->findWidget( "groupBox_deviceView" ) );
   106     mGroupBox = qobject_cast<HbGroupBox *>( mLoader->findWidget( "groupBox_deviceView" ) );
    88     BTUI_ASSERT_X( mGroupBox != 0, "bt-device-view", "Device groupbox not found" );
   107     BTUI_ASSERT_X( mGroupBox != 0, "bt-device-view", "Device groupbox not found" );
    89     
   108     */
    90     mDeviceIcon=0;
   109     mDeviceIcon=0;
    91     //can't use qobject_cast since HbIcon is not derived from QObject!
   110     //can't use qobject_cast since HbIcon is not derived from QObject!
    92     mDeviceIcon = qobject_cast<HbLabel *>( mLoader->findWidget( "deviceIcon" ) );  
   111     mDeviceIcon = qobject_cast<HbLabel *>( mLoader->findWidget( "deviceIcon" ) );  
    93     BTUI_ASSERT_X( mDeviceIcon != 0, "bt-device-view", "Device Icon not found" );
   112     BTUI_ASSERT_X( mDeviceIcon != 0, "bt-device-view", "Device Icon not found" );
    94     
   113     
    95     mDeviceName=0;
   114     mDeviceName=0;
    96     mDeviceName = qobject_cast<HbTextEdit *>( mLoader->findWidget( "deviceName" ) );
   115     mDeviceName = qobject_cast<HbLineEdit *>( mLoader->findWidget( "deviceName" ) );
    97     BTUI_ASSERT_X( mDeviceName != 0, "bt-device-view", "Device Name not found" );
   116     BTUI_ASSERT_X( mDeviceName != 0, "bt-device-view", "Device Name not found" );
    98     ret = connect(mDeviceName, SIGNAL(editingFinished ()), this, SLOT(changeBtDeviceName()));
   117     ret = connect(mDeviceName, SIGNAL(editingFinished ()), this, SLOT(changeBtDeviceName()));
    99     
   118     
   100     mDeviceCategory=0;
   119     mDeviceCategory=0;
   101     mDeviceCategory = qobject_cast<HbLabel *>( mLoader->findWidget( "deviceCategory" ) );  
   120     mDeviceCategory = qobject_cast<HbLabel *>( mLoader->findWidget( "deviceCategory" ) );  
   102     BTUI_ASSERT_X( mDeviceCategory != 0, "bt-device-view", "Device Category not found" );
   121     BTUI_ASSERT_X( mDeviceCategory != 0, "bt-device-view", "Device Category not found" );
   103     
   122     
   104     mDeviceStatus=0;
   123     mDeviceStatus=0;
   105     mDeviceStatus = qobject_cast<HbLabel *>( mLoader->findWidget( "deviceStatus" ) );  
   124     mDeviceStatus = qobject_cast<HbLabel *>( mLoader->findWidget( "deviceStatus" ) );  
   106     BTUI_ASSERT_X( mDeviceStatus != 0, "bt-device-view", "Device status not found" );
   125     BTUI_ASSERT_X( mDeviceStatus != 0, "bt-device-view", "Device status not found" );
       
   126     
       
   127     
       
   128     mConnectionCombobox = 0;
       
   129     mConnectionCombobox = qobject_cast<HbDataForm *>( mLoader->findWidget( "connectionCombobox" ) );
       
   130     BTUI_ASSERT_X( mConnectionCombobox != 0, "bt-device-view", "connection combobox not found" );
       
   131     
       
   132     mConnectionComboboxModel = new HbDataFormModel();
   107     
   133     
   108     mPair_Unpair=0;
   134     mPair_Unpair=0;
   109     mPair_Unpair = qobject_cast<HbPushButton *>( mLoader->findWidget( "pushButton_0" ) );
   135     mPair_Unpair = qobject_cast<HbPushButton *>( mLoader->findWidget( "pushButton_0" ) );
   110     BTUI_ASSERT_X( mPair_Unpair != 0, "bt-device-view", "pair/unpair button not found" );
   136     BTUI_ASSERT_X( mPair_Unpair != 0, "bt-device-view", "pair/unpair button not found" );
   111     ret =  connect(mPair_Unpair, SIGNAL(clicked()), this, SLOT(pairUnpair()));
   137     ret =  connect(mPair_Unpair, SIGNAL(clicked()), this, SLOT(pairUnpair()));
   119       
   145       
   120     mDeviceSetting = 0;
   146     mDeviceSetting = 0;
   121     mDeviceSetting = qobject_cast<HbPushButton *>( mLoader->findWidget( "pushButton_2" ) );
   147     mDeviceSetting = qobject_cast<HbPushButton *>( mLoader->findWidget( "pushButton_2" ) );
   122     BTUI_ASSERT_X( mDeviceSetting != 0, "bt-device-view", "settings button not found" );
   148     BTUI_ASSERT_X( mDeviceSetting != 0, "bt-device-view", "settings button not found" );
   123         
   149         
   124     // read landscape orientation section from docml file if needed
   150     setConnectionCombobox();
   125     // mOrientation = ((BTUIViewManager*)parent)->orientation();
   151     
   126     mOrientation = Qt::Vertical;
       
   127     if (mOrientation == Qt::Horizontal) {
       
   128         mLoader->load(BTUI_DEVICEVIEW_DOCML, "landscape", &ok);
       
   129         BTUI_ASSERT_X( ok, "bt-device-view", "Invalid docml file: landscape section problem" );
       
   130     }
       
   131  
   152  
   132 }
   153 }
   133 
   154 
   134 BtCpUiDeviceView::~BtCpUiDeviceView()
   155 BtCpUiDeviceView::~BtCpUiDeviceView()
   135 {
   156 {
       
   157     delete mLoader; // Also deletes all widgets that it constructed.
       
   158     
       
   159     delete mConnectionComboboxModel;
       
   160     
   136     setNavigationAction(0);
   161     setNavigationAction(0);
   137     delete mSoftKeyBackAction;
   162     delete mSoftKeyBackAction;
   138     if(mAbstractDelegate)
   163     if(mAbstractDelegate)
   139     {
   164     {
   140         delete mAbstractDelegate;
   165         delete mAbstractDelegate;
   165     
   190     
   166     QModelIndex index = value.value<QModelIndex>();
   191     QModelIndex index = value.value<QModelIndex>();
   167     mDeviceBdAddr = (mDeviceModel->data(index, BtDeviceModel::ReadableBdaddrRole));
   192     mDeviceBdAddr = (mDeviceModel->data(index, BtDeviceModel::ReadableBdaddrRole));
   168     
   193     
   169     //activate view is called when device is selected
   194     //activate view is called when device is selected
   170     clearViewData();
   195     //clearViewData();
   171     updateDeviceData();
   196     updateDeviceData();
   172     
   197     
   173     bool ret(false);
   198     bool ret(false);
   174     ret=connect(mDeviceModel, SIGNAL(dataChanged(QModelIndex,QModelIndex)),
   199     ret=connect(mDeviceModel, SIGNAL(dataChanged(QModelIndex,QModelIndex)),
   175            this, SLOT(updateDeviceData()));
   200            this, SLOT(updateDeviceData()));
   178 
   203 
   179 void BtCpUiDeviceView::deactivateView()
   204 void BtCpUiDeviceView::deactivateView()
   180 {
   205 {
   181 }
   206 }
   182 
   207 
       
   208 // called due to real orientation change event coming from main window
       
   209 void BtCpUiDeviceView::changeOrientation( Qt::Orientation orientation )
       
   210 {
       
   211     bool ok = false;
       
   212     mOrientation = orientation;
       
   213     if( orientation == Qt::Vertical ) {
       
   214         // load "portrait" section
       
   215         mLoader->load( BTUI_DEVICEVIEW_DOCML, "portrait", &ok );
       
   216         BTUI_ASSERT_X( ok, "bt-device-view", "Invalid docml file: portrait section problem" );
       
   217     } else {
       
   218         // load "landscape" section
       
   219         mLoader->load( BTUI_DEVICEVIEW_DOCML, "landscape", &ok );
       
   220         BTUI_ASSERT_X( ok, "bt-device-view", "Invalid docml file: landscape section problem" );
       
   221     }
       
   222 }
       
   223 
   183 void BtCpUiDeviceView::clearViewData()
   224 void BtCpUiDeviceView::clearViewData()
   184 {
   225 {
   185     mDeviceIcon->clear();
   226     mDeviceIcon->clear();
   186     mDeviceCategory->clear();
   227     mDeviceCategory->clear();
   187     mDeviceStatus->clear();
   228     mDeviceStatus->clear();
   188     
   229     
   189     mPairStatus = false;
   230     mPairedStatus = false;
   190     mConnectStatus = false;
   231     mConnectedStatus = false;
       
   232     mTrustedStatus = false;
       
   233     mBlockedStatus = false;
       
   234     
   191     mConnectable = false;
   235     mConnectable = false;
   192 }
   236 }
   193     
   237     
   194 void BtCpUiDeviceView::updateDeviceData()
   238 void BtCpUiDeviceView::updateDeviceData()
   195 {
   239 {
   196     QModelIndex localIndex = mSettingModel->index( BtSettingModel::LocalBtNameRow, 0);
   240     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);
   197     QString localName = (mSettingModel->data(localIndex,BtSettingModel::settingDisplayRole)).toString();
   244     QString localName = (mSettingModel->data(localIndex,BtSettingModel::settingDisplayRole)).toString();
   198     QString groupBoxTitle (tr("Bluetooth-"));
   245     QString groupBoxTitle (hbTrId("txt_bt_subhead_bluetooth_1").arg(localName));
   199     mGroupBox->setHeading(groupBoxTitle.append(localName));
   246     mGroupBox->setHeading(groupBoxTitle);
       
   247     */
   200     //Get the QModelIndex of the device using the device BDAddres
   248     //Get the QModelIndex of the device using the device BDAddres
   201     QModelIndex start = mDeviceModel->index(0,0);
   249     QModelIndex start = mDeviceModel->index(0,0);
   202     QModelIndexList indexList = mDeviceModel->match(start,BtDeviceModel::ReadableBdaddrRole, mDeviceBdAddr);
   250     QModelIndexList indexList = mDeviceModel->match(start,BtDeviceModel::ReadableBdaddrRole, mDeviceBdAddr);
   203     mDeviceIndex = indexList.at(0);
   251     mDeviceIndex = indexList.at(0);
   204     
   252     
   205     //populate device view with device data fetched from UiModel
   253     //populate device view with device data fetched from UiModel
   206     QString deviceName = (mDeviceModel->data(mDeviceIndex, 
   254     QString deviceName = (mDeviceModel->data(mDeviceIndex, 
   207              BtDeviceModel::NameAliasRole)).toString(); 
   255              BtDeviceModel::NameAliasRole)).toString(); 
   208     mDeviceName->setPlainText(deviceName);
   256     mDeviceName->setText(deviceName);
   209      
   257      
   210     int cod = (mDeviceModel->data(mDeviceIndex,BtDeviceModel::CoDRole)).toInt();
   258     int cod = (mDeviceModel->data(mDeviceIndex,BtDeviceModel::CoDRole)).toInt();
   211      
   259      
   212     int majorRole = (mDeviceModel->data(mDeviceIndex,BtDeviceModel::MajorPropertyRole)).toInt();
   260     int majorRole = (mDeviceModel->data(mDeviceIndex,BtDeviceModel::MajorPropertyRole)).toInt();
   213     int minorRole = (mDeviceModel->data(mDeviceIndex,BtDeviceModel::MinorPropertyRole)).toInt();
   261     int minorRole = (mDeviceModel->data(mDeviceIndex,BtDeviceModel::MinorPropertyRole)).toInt();
   217     setTextAndVisibilityOfButtons();
   265     setTextAndVisibilityOfButtons();
   218 }
   266 }
   219 
   267 
   220 void BtCpUiDeviceView::setDeviceCategory(int cod,int majorRole, int minorRole)
   268 void BtCpUiDeviceView::setDeviceCategory(int cod,int majorRole, int minorRole)
   221 {
   269 {
   222     //TODO: change the hardcoded numeric value to enumerations
   270     mDeviceCategory->setPlainText( getDeviceTypeString( cod ));
   223     if (cod)
   271     HbIcon icon =
   224     {
   272     getBadgedDeviceTypeIcon(cod, majorRole,
   225         if (majorRole & 0x00020000)
   273                             BtuiBottomLeft | BtuiBottomRight | BtuiTopLeft | BtuiTopRight );
       
   274     mDeviceIcon->setIcon(icon);
       
   275 
       
   276     if (majorRole & BtuiDevProperty::AVDev) {  
       
   277         if ( minorRole & BtuiDevProperty::Headset){
       
   278             // this is a Headset, it is possible to connect
       
   279             mConnectable = true;
       
   280         }
       
   281     }
       
   282 }
       
   283 
       
   284 void BtCpUiDeviceView::setDeviceStatus(int majorRole)
       
   285 {
       
   286     QString deviceStatus;
       
   287     
       
   288     updateStatusVariables(majorRole);  // should we use bitmap instead??
       
   289     
       
   290     if (majorRole & BtuiDevProperty::Bonded && 
       
   291         majorRole & BtuiDevProperty::Trusted &&
       
   292         majorRole & BtuiDevProperty::Connected ) {
       
   293         mDeviceStatus->setPlainText(hbTrId("txt_bt_info_paired_trused_connected"));
       
   294     } 
       
   295     else if (majorRole & BtuiDevProperty::Bonded && 
       
   296              majorRole & BtuiDevProperty::Connected ) {
       
   297         mDeviceStatus->setPlainText(hbTrId("txt_bt_info_paired_connected"));
       
   298     }
       
   299     else if (majorRole & BtuiDevProperty::Bonded && 
       
   300              majorRole & BtuiDevProperty::Trusted ) {
       
   301         mDeviceStatus->setPlainText(hbTrId("txt_bt_info_paired_trusted"));
       
   302     } 
       
   303     else if (majorRole & BtuiDevProperty::Bonded) {
       
   304         mDeviceStatus->setPlainText(hbTrId("txt_bt_info_paired"));
       
   305     }
       
   306     else if (majorRole & BtuiDevProperty::Connected) {
       
   307         mDeviceStatus->setPlainText(hbTrId("txt_bt_info_connected"));
       
   308     }
       
   309     else if (majorRole & BtuiDevProperty::Blocked) {
       
   310         mDeviceStatus->setPlainText(hbTrId("txt_bt_info_blocked"));
       
   311     }
       
   312     else {
       
   313         // device not paired, connected, trusted or blocked.  is this ok?
       
   314     }
       
   315 
       
   316 }
       
   317 
       
   318 void BtCpUiDeviceView::setConnectionCombobox(){
       
   319     
       
   320     //create a model class
       
   321     
       
   322     mConnectionComboboxModel->appendDataFormItem(
       
   323     HbDataFormModelItem::ComboBoxItem, QString("Connection"), mConnectionComboboxModel->invisibleRootItem());
       
   324     
       
   325     //set the model to the view, once model and data class are created
       
   326     mConnectionCombobox->setModel(mConnectionComboboxModel);
       
   327 
       
   328 
       
   329 
       
   330 }
       
   331 
       
   332 
       
   333 /*!
       
   334  *  instead of using separate boolean variables we could use bitmap in single variable
       
   335  */
       
   336 void BtCpUiDeviceView::updateStatusVariables(int majorRole)
       
   337 {
       
   338     if (majorRole & BtuiDevProperty::Trusted ) {
       
   339         mTrustedStatus = true;
       
   340     } 
       
   341     else {
       
   342         mTrustedStatus = false;
       
   343     }
       
   344     if (majorRole & BtuiDevProperty::Bonded) {
       
   345         mPairedStatus = true;
       
   346     }
       
   347     else {
       
   348         mPairedStatus = false;
       
   349     }
       
   350     if (majorRole & BtuiDevProperty::Connected) {
       
   351         mConnectedStatus = true;
       
   352     }
       
   353     else {
       
   354         mConnectedStatus = false;
       
   355     }
       
   356     if (majorRole & BtuiDevProperty::Blocked) {
       
   357         mBlockedStatus = true;
       
   358     }
       
   359     else {
       
   360         mBlockedStatus = false;
       
   361     }
       
   362 }
       
   363 
       
   364 void BtCpUiDeviceView::setTextAndVisibilityOfButtons()
       
   365 {
       
   366     mPair_Unpair->setStretched(true);
       
   367     if (mPairedStatus)
       
   368     {
       
   369         HbIcon icon("qtg_mono_bt_unpair");
       
   370         icon.setIconName("qtg_mono_bt_unpair");
       
   371         mPair_Unpair->setIcon(icon);
       
   372         mPair_Unpair->setText(hbTrId("txt_bt_button_unpair"));
       
   373 				
       
   374     }
       
   375     else
       
   376     {
       
   377         HbIcon icon("qtg_mono_bt_pair");
       
   378         icon.setIconName("qtg_mono_bt_pair");
       
   379         mPair_Unpair->setIcon(icon);
       
   380         mPair_Unpair->setText(hbTrId("txt_bt_button_pair"));
       
   381     }
       
   382     
       
   383     if (mConnectable)
       
   384     {
       
   385         mConnect_Disconnect->setStretched(true);
       
   386         if (mConnectedStatus)
   226         {
   387         {
   227             //this is a phone
   388             HbIcon icon("qtg_mono_speaker_off");
   228             mDeviceCategory->setPlainText(tr("Phone"));
   389             icon.setIconName("qtg_mono_speaker_off");
   229         }
   390             mConnect_Disconnect->setIcon(icon);
   230         else if (majorRole & 0x00010000)
   391             mConnect_Disconnect->setText(hbTrId("txt_bt_button_disconnect"));
   231         {
       
   232             //this is a computer
       
   233             mDeviceCategory->setPlainText(tr("Computer"));
       
   234         
       
   235         }
       
   236         else if (majorRole & 0x00080000)
       
   237         {  
       
   238             //this is a A/V device
       
   239             //int minorRole = (mDeviceModel->data(mIndex,BtDeviceModel::MinorPropertyRole)).toInt();
       
   240             if ( minorRole & 0x00000002)
       
   241             {
       
   242                 //this is a Headset, it is possible to connect
       
   243                 mConnectable = true;
       
   244                 mDeviceCategory->setPlainText(tr("Headset"));
       
   245             }  
       
   246         }
       
   247         else 
       
   248         {
       
   249             mDeviceCategory->setPlainText(tr("Uncategorized Dev"));
       
   250         }
       
   251     
       
   252     }
       
   253     
       
   254     
       
   255 }
       
   256 void BtCpUiDeviceView::setDeviceStatus(int majorRole)
       
   257 {
       
   258     //TODO: change the hardcoded numeric value to enumerations
       
   259     QString deviceStatus;
       
   260     if (majorRole & 0x00000001)
       
   261     {
       
   262         deviceStatus = deviceStatus.append(tr("Paired"));
       
   263         mPairStatus = true;
       
   264     }
       
   265     else
       
   266     {
       
   267         mPairStatus = false;
       
   268     }
       
   269     
       
   270     if ((majorRole & 0x00000020)&& (mConnectable))
       
   271     {
       
   272         //if the device is connected and it is a headset NOTE! two phone can be paired but not be connected
       
   273         deviceStatus = deviceStatus.append(tr(", connected"));
       
   274         mConnectStatus = true;
       
   275     }
       
   276     else 
       
   277     {
       
   278         mConnectStatus = false;
       
   279     }
       
   280     mDeviceStatus->setPlainText(deviceStatus);
       
   281     
       
   282     
       
   283     
       
   284 }
       
   285 
       
   286 void BtCpUiDeviceView::setTextAndVisibilityOfButtons()
       
   287 {
       
   288     if (mPairStatus)
       
   289     {
       
   290         mPair_Unpair->setText(tr("Unpair"));
       
   291     }
       
   292     else
       
   293     {
       
   294         mPair_Unpair->setText(tr("Pair"));
       
   295     }
       
   296     
       
   297     if (mConnectable)
       
   298     {
       
   299         if (mConnectStatus)
       
   300         {
       
   301             mConnect_Disconnect->setText(tr("Disconnect"));
       
   302         }
   392         }
   303         else
   393         else
   304         {
   394         {
   305             mConnect_Disconnect->setText(tr("Connect"));
   395             HbIcon icon("qtg_mono_speaker");
       
   396             icon.setIconName("qtg_mono_speaker");
       
   397             mConnect_Disconnect->setIcon(icon);
       
   398             mConnect_Disconnect->setText(hbTrId("txt_bt_button_connect"));
   306         }
   399         }
   307         
   400         
   308     }
   401     }
   309     else
   402     else
   310     {
   403     {
   314     
   407     
   315     mDeviceSetting->setVisible(false);
   408     mDeviceSetting->setVisible(false);
   316 
   409 
   317 }
   410 }
   318 
   411 
   319 void BtCpUiDeviceView::changeBtDeviceName()
       
   320 {
       
   321     /*
       
   322     if (!mAbstractDelegate) 
       
   323     {
       
   324         mAbstractDelegate = BtDelegateFactory::newDelegate(BtDelegate::DeviceName, mModel); 
       
   325         connect( mAbstractDelegate, SIGNAL(commandCompleted(int,QVariant)), this, SLOT(btNameDelegateCompleted(int,QVariant)) );
       
   326         mAbstractDelegate->exec(mDeviceNameEdit->text ());
       
   327     }
       
   328     */
       
   329     
       
   330 }
       
   331 
   412 
   332 void BtCpUiDeviceView::pairUnpair()
   413 void BtCpUiDeviceView::pairUnpair()
   333 {
   414 {
   334     if (mPairStatus)
   415     if (mPairedStatus)
   335     {
   416     {
   336         //if the device is paired, call unpairDevice() when the button is tabbed
   417         //if the device is paired, call unpairDevice() when the button is tabbed
   337         unpairDevice();
   418         unpairDevice();
   338     }
   419     }
   339     else
   420     else
   346     
   427     
   347 }
   428 }
   348 
   429 
   349 void BtCpUiDeviceView::connectDisconnect()
   430 void BtCpUiDeviceView::connectDisconnect()
   350 {
   431 {
   351     if (mConnectStatus)
   432     if (mConnectedStatus)
   352     {
   433     {
   353         //if the device is connected, call disconnectDevice() when the button is tabbed
   434         //if the device is connected, call disconnectDevice() when the button is tabbed
   354         disconnectDevice();
   435         disconnectDevice();
   355     }
   436     }
   356     else
   437     else
   446 
   527 
   447 void BtCpUiDeviceView::disconnectDevice()
   528 void BtCpUiDeviceView::disconnectDevice()
   448 {
   529 {
   449     if (!mAbstractDelegate)//if there is no other delegate running
   530     if (!mAbstractDelegate)//if there is no other delegate running
   450         { 
   531         { 
       
   532            
       
   533             
       
   534             DisconnectOption discoOpt = ServiceLevel;
       
   535                     
       
   536             QList<QVariant>list;
       
   537             QVariant paramFirst;
       
   538             paramFirst.setValue(mDeviceIndex);
       
   539             
       
   540             QVariant paramSecond;
       
   541             paramSecond.setValue((int)discoOpt);
       
   542                     
       
   543             list.append(paramFirst);
       
   544             list.append(paramSecond);
       
   545                     
   451             QVariant params;
   546             QVariant params;
   452             params.setValue(mDeviceIndex);
   547             params.setValue(list);
       
   548             
       
   549             
       
   550             //params.setValue(mDeviceIndex);
   453             mAbstractDelegate = BtDelegateFactory::newDelegate(
   551             mAbstractDelegate = BtDelegateFactory::newDelegate(
   454                     BtDelegate::Disconnect, mSettingModel, mDeviceModel); 
   552                     BtDelegate::Disconnect, mSettingModel, mDeviceModel); 
   455             connect( mAbstractDelegate, SIGNAL(commandCompleted(int)), this, SLOT(disconnectDelegateCompleted(int)) );
   553             connect( mAbstractDelegate, SIGNAL(commandCompleted(int)), this, SLOT(disconnectDelegateCompleted(int)) );
   456             mAbstractDelegate->exec(params);
   554             mAbstractDelegate->exec(params);
   457         }
   555         }
   469     }   
   567     }   
   470     
   568     
   471     
   569     
   472 }
   570 }
   473 
   571 
       
   572 void BtCpUiDeviceView::changeBtDeviceName(){
       
   573     if (!mAbstractDelegate)//if there is no other delegate running
       
   574     { 
       
   575         QList<QVariant>list;
       
   576         
       
   577         QVariant index;
       
   578         index.setValue(mDeviceIndex);
       
   579         
       
   580         QVariant name;
       
   581         name.setValue(mDeviceName->text());
       
   582         
       
   583         list.append(index);
       
   584         list.append(name);
       
   585         
       
   586         QVariant params;
       
   587         params.setValue(list);
       
   588         
       
   589         mAbstractDelegate = BtDelegateFactory::newDelegate(
       
   590                 BtDelegate::RemoteDevName, mSettingModel, mDeviceModel); 
       
   591         connect( mAbstractDelegate, SIGNAL(commandCompleted(int, QVariant)), this, SLOT(changeDevNameDelegateCompleted(int, QVariant)) );
       
   592         mAbstractDelegate->exec(params);
       
   593     }
       
   594     
       
   595 }
       
   596 
       
   597 void BtCpUiDeviceView::changeDevNameDelegateCompleted(int status, QVariant param)
       
   598 {
       
   599     
       
   600     
       
   601     if(KErrNone == status) {
       
   602         mDeviceName->setText(param.toString());
       
   603     }
       
   604     else {
       
   605         //setPrevBtLocalName();
       
   606     }
       
   607     //TODO:Error handling has to be done.    
       
   608     if (mAbstractDelegate)
       
   609     {
       
   610         disconnect(mAbstractDelegate);
       
   611         delete mAbstractDelegate;
       
   612         mAbstractDelegate = 0;
       
   613     }
       
   614     
       
   615     
       
   616 }