bluetoothengine/btnotif/btdevicedialogplugin/src/btdevicesearchdialogwidget.cpp
changeset 63 bcf742120177
parent 52 4545c04e61e1
--- a/bluetoothengine/btnotif/btdevicedialogplugin/src/btdevicesearchdialogwidget.cpp	Wed Aug 18 09:59:05 2010 +0300
+++ b/bluetoothengine/btnotif/btdevicedialogplugin/src/btdevicesearchdialogwidget.cpp	Fri Sep 17 08:30:56 2010 +0300
@@ -38,14 +38,12 @@
 #define LOC_SEARCH_DONE hbTrId("txt_bt_subhead_search_done")
 #define LOC_SEARCH_STOP hbTrId("txt_common_button_stop")
 #define LOC_SEARCH_RETRY hbTrId("txt_common_button_retry")
+#define LOC_SHOW_DIALOG_TITLE hbTrId("txt_bt_title_show")
 
 
 BTDeviceSearchDialogWidget::BTDeviceSearchDialogWidget(const QVariantMap &parameters)
-    {
-//    mDeviceLstIdx = 0;
-//    mViewByChosen = false;
+{
     mSelectedDeviceType = 0;
- //   mDeviceDialogData = 0;
     mLoader = 0;
     mContentItemModel = 0;
     mStopRetryFlag = 0; // Stop 
@@ -56,24 +54,22 @@
             BtuiDevProperty::WearableDev | BtuiDevProperty::ImagingDev |
             BtuiDevProperty::HealthDev | BtuiDevProperty::UncategorizedDev);       
     constructDialog(parameters);
-    }
+}
 
 BTDeviceSearchDialogWidget::~BTDeviceSearchDialogWidget()
-    {
+{
     delete mLoader;
     delete mContentItemModel;
-    if ( mQuery ) {
+    if ( mQuery )
+    {
         delete mQuery;
     }
-    
- //   delete mRbl;
- //   delete mViewByDialog;
-    }
+}
 
 bool BTDeviceSearchDialogWidget::setDeviceDialogParameters(const QVariantMap &parameters)
+{
+    if(parameters.keys().contains("Search Completed"))
     {
-    if(parameters.keys().at(0).compare("Search Completed")==0)
-        {
         mStopRetryFlag = 1; // Retry 
         mSearchLabel->hide();
         
@@ -85,19 +81,20 @@
         mSearchDoneLabel->setPlainText(LOC_SEARCH_DONE);
         
         mStopRetryAction->setText(LOC_SEARCH_RETRY);
-        }
+    }
     else
-        {
-        double cod  = parameters.value(QString::number(TBluetoothDeviceDialog::EDeviceClass)).toDouble();
+    {
+        int cod  = parameters.value(QString::number(TBluetoothDeviceDialog::EDeviceClass)).toInt();
         int uiMajorDevice;
         int uiMinorDevice;
     
         BtuiDevProperty::mapDeiveType(uiMajorDevice, uiMinorDevice, cod);
 
         BtSendDataItem devData;
-        devData[NameAliasRole] = QVariant(parameters.value(QString::number(TBluetoothDeviceDialog::EDeviceName)).toString());
-        devData[ReadableBdaddrRole] = QVariant(parameters.value(QString::number(TBluetoothDialogParams::EAddress)).toString());
-        devData[CoDRole] = QVariant(cod);
+        //TODO Need to create string constant for Name as enum EDeviceName is not working for this
+        devData[NameAliasRole] =parameters.value("Name").toString();
+        devData[ReadableBdaddrRole] = parameters.value(QString::number(TBluetoothDeviceDialog::EAddress));
+        devData[CoDRole] = parameters.value(QString::number(TBluetoothDeviceDialog::EDeviceClass));
         devData[DeviceTypeRole] = QVariant(uiMajorDevice);
         setMajorProperty(devData,BtuiDevProperty::Bonded,
                 parameters.value("Bonded").toBool());
@@ -110,113 +107,96 @@
         mData.append(devData);
         
         if(mSelectedDeviceType & devData[DeviceTypeRole].toInt())
-            {
+        {
             QStandardItem* listitem = new QStandardItem();
             QStringList info;
             info.append(devData[NameAliasRole].toString());
             listitem->setData(info, Qt::DisplayRole);
-            HbIcon icon =  getBadgedDeviceTypeIcon(devData[CoDRole].toDouble(),
+            HbIcon icon =  getBadgedDeviceTypeIcon(devData[CoDRole].toInt(),
                     devData[MajorPropertyRole].toInt(),
                     BtuiBottomLeft | BtuiBottomRight | BtuiTopLeft | BtuiTopRight);
             listitem->setIcon(icon.qicon());
             mContentItemModel->appendRow(listitem);    
             mSelectedData.append(devData);
-            }
         }
+    }
                 
     return true;
-    }
+}
 
 int BTDeviceSearchDialogWidget::deviceDialogError() const
-    {
+{
     return 0;
-    }
+}
 
 void BTDeviceSearchDialogWidget::closeDeviceDialog(bool byClient)
-    {
+{
     Q_UNUSED(byClient);
     mSearchDevicesDialog->close();
-    //@ TODO to check below code is required which is written based on the documentation of closeDeviceDialog API
-    
- /*   QVariantMap val;
-    QVariant index(-1);
-    val.insert("selectedindex",index);
-    emit deviceDialogData(val);    
-    emit deviceDialogClosed();*/
-    }
+    if(!byClient)
+        {
+        QVariantMap val;
+        QVariant index(-1);
+        val.insert("selectedindex",index);
+        emit deviceDialogData(val);    
+        }
+    emit deviceDialogClosed();
+}
 
 HbPopup* BTDeviceSearchDialogWidget::deviceDialogWidget() const
-    {
+{
     return mSearchDevicesDialog;
-    }
+}
 
 QObject* BTDeviceSearchDialogWidget::signalSender() const
-    {
+{
     return const_cast<BTDeviceSearchDialogWidget*>(this);
-    }
+}
 
 bool BTDeviceSearchDialogWidget::constructDialog(const QVariantMap &parameters)
-    {
+{
     (void) parameters;
     bool ok = false;
     
     mLoader = new HbDocumentLoader();
     mLoader->load(DOCML_BTDEV_SEARCH_DIALOG, &ok);
     if(ok)
-        {
-        mSearchDevicesDialog = qobject_cast<HbDialog*>(mLoader->findWidget("searchdialog"));
-
- /*       HbLabel* heading = qobject_cast<HbLabel*>(mLoader->findWidget("heading"));
-        heading->setTextWrapping(Hb::TextWordWrap);
-        heading->setAlignment(Qt::AlignHCenter);
-        heading->setPlainText("Bluetooth - Found devices");
-        setHeadingWidget(heading);*/
+    {
+        mSearchDevicesDialog = qobject_cast<HbDialog*>(mLoader->findWidget("searchDialog"));
         
         mSearchLabel = qobject_cast<HbLabel*>(mLoader->findWidget("searchLabel"));
         mSearchLabel->setTextWrapping(Hb::TextWordWrap);
         mSearchLabel->setAlignment(Qt::AlignHCenter);
         mSearchLabel->setPlainText(LOC_SEARCHING_DEVICE);
  
-        mSearchIconLabel = qobject_cast<HbLabel*>(mLoader->findWidget("iconLabel"));
-        mSearchIconLabel->setIcon(QIcon(QString(":/icons/qtg_large_bluetooth.svg")));
+        mSearchIconLabel = qobject_cast<HbLabel*>(mLoader->findWidget("searchIconLabel"));
+        mSearchIconLabel->setIcon(HbIcon("qtg_large_bluetooth"));
 
         mSearchDoneLabel = qobject_cast<HbLabel*>(mLoader->findWidget("searchDoneLabel"));
         mSearchDoneLabel->hide();
         
-        
-        mSearchDevicesDialog->setFrameType(HbDialog::Strong);
-        mSearchDevicesDialog->setBackgroundFaded(false);
-
- //       mViewByBtn = qobject_cast<HbPushButton*>(mLoader->findWidget("viewby"));
-  //      mStopRetryBtn = qobject_cast<HbPushButton*>(mLoader->findWidget("stop"));
-        
-        mListView = qobject_cast<HbListView*>(mLoader->findWidget("listView"));
-        mListView->setSelectionMode(HbAbstractItemView::SingleSelection);
+        mDeviceList = qobject_cast<HbListView*>(mLoader->findWidget("deviceList"));
+        mDeviceList->setSelectionMode(HbAbstractItemView::SingleSelection);
 
         mContentItemModel = new QStandardItemModel(this);
-        mListView->setModel(mContentItemModel);//, prototype);
+        mDeviceList->setModel(mContentItemModel);//, prototype);
 
-        connect(mListView, SIGNAL(activated(QModelIndex)), this, SLOT(deviceSelected(QModelIndex)));
- //       connect(mStopRetryBtn, SIGNAL(clicked()), this, SLOT(stopRetryClicked()));
- //       connect(mViewByBtn, SIGNAL(clicked()), this, SLOT(viewByClicked()));
+        connect(mDeviceList, SIGNAL(activated(QModelIndex)), this, SLOT(deviceSelected(QModelIndex)));
         
-        mShowAction = static_cast<HbAction*>( mLoader->findObject( "viewaction" ) );
-        mShowAction->disconnect(mSearchDevicesDialog);
+        mShowAction = static_cast<HbAction*>( mLoader->findObject( "viewByAction" ) );
+        //if action is not disconnected the dialog will be closed when action is clicked 
+        mShowAction->disconnect(mSearchDevicesDialog); 
         
-        mStopRetryAction = static_cast<HbAction*>( mLoader->findObject( "stopretryaction" ) );
-        mStopRetryAction->disconnect(mSearchDevicesDialog);
         
-//        mCancelAction = static_cast<HbAction*>( mLoader->findObject( "cancelaction" ) );
-//        mCancelAction->disconnect(mSearchDevicesDialog);
+        mStopRetryAction = static_cast<HbAction*>( mLoader->findObject( "stopRetryAction" ) );
+        //if action is not disconnected the dialog will be closed when action is clicked         
+        mStopRetryAction->disconnect(mSearchDevicesDialog); 
         
         connect(mShowAction, SIGNAL(triggered()), this, SLOT(viewByClicked()));
         connect(mStopRetryAction, SIGNAL(triggered()), this, SLOT(stopRetryClicked()));
 
         connect(mSearchDevicesDialog, SIGNAL(aboutToClose()), this, SLOT(searchDialogClosed()));
-        
-//        QGraphicsWidget *widget = mLoader->findWidget(QString("container"));
-        //setContentWidget(widget);
-        }
+    }
     mSearchDevicesDialog->setBackgroundFaded(false);
     mSearchDevicesDialog->setDismissPolicy(HbPopup::NoDismiss);
     mSearchDevicesDialog->setTimeout(HbPopup::NoTimeout);
@@ -228,26 +208,22 @@
             << hbTrId("txt_bt_list_phones") 
             << hbTrId("txt_bt_list_other_devices");
     
- /*   mViewByDialog = new HbDialog();
-    mRbl = new HbRadioButtonList(mViewByDialog);
-    connect(mRbl, SIGNAL(itemSelected(int)), this, SLOT(viewByItemSelected(int)));*/
-    
     return true;
-    }
+}
 
 
 void BTDeviceSearchDialogWidget::stopRetryClicked()
-    {
+{
     QVariantMap val;
-    if(mStopRetryFlag == 1)//mStopRetryAction->text().compare(LOC_SEARCH_RETRY)==0
-        {
+    if(mStopRetryFlag == 1)
+    {
         mStopRetryFlag = 0; // Stop 
         QVariant index("Retry");
         val.insert("Retry",index); 
         emit deviceDialogData(val);
         delete mContentItemModel;
         mContentItemModel = new QStandardItemModel(this);
-        mListView->setModel(mContentItemModel);
+        mDeviceList->setModel(mContentItemModel);
         mStopRetryAction->setText(LOC_SEARCH_STOP);
         
         mSearchLabel->setTextWrapping(Hb::TextWordWrap);
@@ -260,9 +236,9 @@
         mSearchIconLabel->show();
         
         mSearchDoneLabel->hide();
-        }
+    }
     else
-        {
+    {
         mStopRetryFlag = 1; //Retry 
         mStopRetryAction->setText(LOC_SEARCH_RETRY);
         
@@ -279,26 +255,13 @@
         QVariant index("Stop");
         val.insert("Stop",index); 
         emit deviceDialogData(val);    
-        }
     }
-
-void BTDeviceSearchDialogWidget::retryClicked()
-    {
-    QVariantMap val;
-    QVariant index("Retry");
-    val.insert("Retry",index); 
-    emit deviceDialogData(val);
-    delete mContentItemModel;
-    mContentItemModel = new QStandardItemModel(this);
-    mListView->setModel(mContentItemModel);
-    
-
-    }
+}
 
 void BTDeviceSearchDialogWidget::viewByClicked()
+{
+    if ( !mQuery )
     {
-    
-    if ( !mQuery ) {
         mQuery = new HbSelectionDialog;
         mQuery->setStringItems(mDevTypeList, 0);
         mQuery->setSelectionMode(HbAbstractItemView::MultiSelection);
@@ -312,90 +275,79 @@
         
 //        mQuery->setAttribute(Qt::WA_DeleteOnClose);
         // Set the heading for the dialog.
-        HbLabel *headingLabel = new HbLabel(hbTrId("txt_bt_title_show"), mQuery);
+        HbLabel *headingLabel = new HbLabel(LOC_SHOW_DIALOG_TITLE, mQuery);
         mQuery->setHeadingWidget(headingLabel);
     }
     mQuery->open(this,SLOT(selectionDialogClosed(HbAction*)));
-
-     
-    }
+}
 
 void BTDeviceSearchDialogWidget::searchDialogClosed() 
-    {
+{
     QVariantMap val;
     QVariant index(-1);
     val.insert("selectedindex",index);
     emit deviceDialogData(val);    
     emit deviceDialogClosed();
-    }
+}
 
 void BTDeviceSearchDialogWidget::selectionDialogClosed(HbAction* action)
-    {
-    Q_UNUSED(action);
-    
-    disconnect( mQuery ); 
+{
+    disconnect( mQuery, 0, this, 0 ); 
     int devTypesWanted = 0;
 
-    if (action == mQuery->actions().first()) {  // user pressed "Ok"
+    if (action == mQuery->actions().first())
+    {  // user pressed "Ok"
         // Get selected items.
         QList<QVariant> selections;
         selections = mQuery->selectedItems();
         
-        for (int i=0; i < selections.count(); i++) {
-            switch (selections.at(i).toInt()) {
-            case BtUiDevAudioDevice:
-                devTypesWanted |= BtuiDevProperty::AVDev;
-                break;
-            case BtUiDevComputer:
-                devTypesWanted |= BtuiDevProperty::Computer;
-                break;
-            case BtUiDevInputDevice:
-                devTypesWanted |= BtuiDevProperty::Peripheral;
-                break;
-            case BtUiDevPhone:
-                devTypesWanted |= BtuiDevProperty::Phone;
-                break;
-            case BtUiDevOtherDevice:
-                devTypesWanted |= (BtuiDevProperty::LANAccessDev |
-                        BtuiDevProperty::Toy |
-                        BtuiDevProperty::WearableDev |
-                        BtuiDevProperty::ImagingDev |
-                        BtuiDevProperty::HealthDev |
-                        BtuiDevProperty::UncategorizedDev);
-                break;
-            default:
-                // should never get here
-                break;
+        for (int i=0; i < selections.count(); i++) 
+        {
+            switch (selections.at(i).toInt()) 
+            {
+                case BtUiDevAudioDevice:
+                    devTypesWanted |= BtuiDevProperty::AVDev;
+                    break;
+                case BtUiDevComputer:
+                    devTypesWanted |= BtuiDevProperty::Computer;
+                    break;
+                case BtUiDevInputDevice:
+                    devTypesWanted |= BtuiDevProperty::Peripheral;
+                    break;
+                case BtUiDevPhone:
+                    devTypesWanted |= BtuiDevProperty::Phone;
+                    break;
+                case BtUiDevOtherDevice:
+                    devTypesWanted |= (BtuiDevProperty::LANAccessDev |
+                            BtuiDevProperty::Toy |
+                            BtuiDevProperty::WearableDev |
+                            BtuiDevProperty::ImagingDev |
+                            BtuiDevProperty::HealthDev |
+                            BtuiDevProperty::UncategorizedDev);
+                    break;
+                default:
+                    // should never get here
+                    break;
             }
         }
     }
     else
-        {
+    {
         devTypesWanted = mSelectedDeviceType;
-        }
-        
-    
-
- /*   HbSelectionDialog *dlg = (HbSelectionDialog*)(sender());
-    if(dlg->actions().first() == action) {
+    }
 
-     } 
-    else if(dlg->actions().at(1) == action) {
-     }*/
-    
     if((devTypesWanted != mSelectedDeviceType) &&(devTypesWanted !=0))
-        {
+    {
         mSelectedDeviceType = devTypesWanted;
-//        mViewByChosen = true;
         delete mContentItemModel;
         mContentItemModel = new QStandardItemModel(this);
-        mListView->setModel(mContentItemModel);
+        mDeviceList->setModel(mContentItemModel);
         mSelectedData.clear();
         for(int i=0;i<mData.count();i++)
-            {
+        {
             const BtSendDataItem& qtdev = mData[i];
             if(devTypesWanted & qtdev[DeviceTypeRole].toInt() )
-                {
+            {
                 QStandardItem* listitem = new QStandardItem();
                 QStringList info;
                 info.append(qtdev[NameAliasRole].toString());
@@ -407,39 +359,24 @@
                 listitem->setIcon(icon.qicon());
                 mContentItemModel->appendRow(listitem);        
                 mSelectedData.append(qtdev);
-                }
             }
         }
     }
+}
 
 void BTDeviceSearchDialogWidget::deviceSelected(const QModelIndex& modelIndex)
-    {
+{
     int row = 0;
-    
- /*   if(mViewByChosen)
-        {
-        row = mDeviceLstOfType[modelIndex.row()].mDeviceIdx;
-        }
+    QVariantMap val;
     
-    else*/
-        {
-        row = modelIndex.row();
-        }
-    
-    QVariantMap val;
-//    QVariant index(row);
-//    val.insert("selectedindex",index);
-    
+    row = modelIndex.row();
     const BtSendDataItem& qtdev = mSelectedData.at(row);
     val.insert("selectedindex",QVariant(row));
-    val.insert("devicename",QVariant(qtdev[NameAliasRole]));
-    val.insert("deviceaddress",QVariant(qtdev[ReadableBdaddrRole]));
-    val.insert("deviceclass",QVariant(qtdev[CoDRole]));
+    val.insert("devicename",qtdev[NameAliasRole]);
+    val.insert("deviceaddress",qtdev[ReadableBdaddrRole]);
+    val.insert("deviceclass",qtdev[CoDRole]);
 
     emit deviceDialogData(val);
-//    mDeviceDialogData = 1;//flag is to say that device dialog data is emitted required when we cancel the dialog
-    //emit deviceDialogClosed();
-  //  this->close();
-    }
+}