bluetoothengine/btui/btcpplugin/btcpuisearchview.cpp
changeset 40 997690c3397a
parent 33 837dcc42fd6a
child 41 0b2439c3e397
--- a/bluetoothengine/btui/btcpplugin/btcpuisearchview.cpp	Fri Jun 11 13:48:51 2010 +0300
+++ b/bluetoothengine/btui/btcpplugin/btcpuisearchview.cpp	Wed Jun 23 18:23:52 2010 +0300
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2009-2010 Nokia Corporation and/or its subsidiary(-ies).
+ * Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
  * All rights reserved.
  * This component and the accompanying materials are made available
  * under the terms of "Eclipse Public License v1.0""
@@ -25,6 +25,7 @@
 #include <HbLabel>
 #include <HbListView>
 #include <HbMenu>
+#include <HbSelectionDialog>
 #include <QString>
 #include <QStringList>
 #include <QDebug>
@@ -32,7 +33,8 @@
 #include "btcpuimainview.h"
 #include "btdelegatefactory.h"
 #include "btabstractdelegate.h"
-
+#include "btcpuisearchlistviewitem.h"
+#include "btuidevtypemap.h"
 
 
 // docml to load
@@ -46,6 +48,7 @@
 {
     bool ret(false);
     
+    mLastSelectionIndex = 0;
     mMainView = (BtCpUiMainView *) parent;
     
     mMainWindow = hbInstance->allMainWindows().first();
@@ -58,11 +61,11 @@
     // name in docml.
     setObjectName("bt_search_view");
 
+    mLoader = new HbDocumentLoader();
+    // Pass the view to documentloader. Document loader uses this view
+    // when docml is parsed, instead of creating new view.
     QObjectList objectList;
     objectList.append(this);
-    // Pass the view to documentloader. Document loader uses this view
-    // when docml is parsed, instead of creating new view.
-    mLoader = new HbDocumentLoader();
     mLoader->setObjectTree(objectList);
     
     // read view info from docml file
@@ -119,8 +122,8 @@
     mViewBy = static_cast<HbAction*>( mLoader->findObject( "viewByAction" ) );
     BTUI_ASSERT_X( mViewBy, "bt-search-view", "view by action missing" ); 
 //    TODO - Need to implement the View by
-//    ret = connect(viewByAction, SIGNAL(triggered()), this, SLOT(noOp()));
-//    BTUI_ASSERT_X( ret, "bt-search-view", "viewByAction can't connect" ); 
+    ret = connect(mViewBy, SIGNAL(triggered()), this, SLOT(viewByDeviceTypeDialog()));
+    BTUI_ASSERT_X( ret, "bt-search-view", "viewByAction can't connect" ); 
 
     mStop = static_cast<HbAction*>( mLoader->findObject( "stopAction" ) );
     BTUI_ASSERT_X( mStop, "bt-search-view", "stopAction missing" ); 
@@ -150,21 +153,30 @@
     
     ret = connect(mDeviceList, SIGNAL(activated(QModelIndex)), this, SLOT(deviceSelected(QModelIndex)));
     BTUI_ASSERT_X( ret, "bt-search-view", "deviceSelected can't connect" ); 
+    
+    // initialize device type list for "view by" option
+    // Note:  this list needs to be in the same order as enum devTypeSelectionList
+    mDevTypeList << hbTrId("txt_bt_list_audio_devices")
+            << hbTrId("txt_bt_list_computers") 
+            << hbTrId("txt_bt_list_input_devices") 
+            << hbTrId("txt_bt_list_phones") 
+            << hbTrId("txt_bt_list_other_devices");
 }
 
 BtCpUiSearchView::~BtCpUiSearchView()
 {
+    delete mLoader; // Also deletes all widgets that it constructed.
+    
     setNavigationAction(0);
+    disconnect( mSoftKeyBackAction );
     delete mSoftKeyBackAction;
     
     if(mAbstractDelegate) {
         delete mAbstractDelegate;
-        mAbstractDelegate = 0;
     }
     
     if(mBtuiModelSortFilter) {
         delete mBtuiModelSortFilter;
-        mBtuiModelSortFilter = 0; 
     }
 }
 
@@ -183,6 +195,88 @@
     }
 }
 
+
+void BtCpUiSearchView::viewByDeviceTypeDialog()
+{
+    HbSelectionDialog *query = new HbSelectionDialog;
+    query->setStringItems(mDevTypeList, mLastSelectionIndex);
+    query->setSelectionMode(HbAbstractItemView::MultiSelection);
+
+    QList<QVariant> current;
+    current.append(QVariant(0));
+    query->setSelectedItems(current);
+
+    query->setAttribute(Qt::WA_DeleteOnClose);
+    
+    // Set the heading for the dialog.
+    HbLabel *headingLabel = new HbLabel(hbTrId("txt_bt_title_show"), query);
+    query->setHeadingWidget(headingLabel);
+
+
+    query->open(this,SLOT(viewByDialogClosed(HbAction*)));
+}
+/*!
+   Callback for dialog closing
+     ToDo:  this API might change in the future, see e-mails in Orbit-dev list, 
+         e.g. 27.4.2010 Raju Abhilash 
+ */
+void BtCpUiSearchView::viewByDialogClosed(HbAction* action)
+{
+    HbSelectionDialog *dlg = (HbSelectionDialog*)(sender());
+    bool first = true;
+
+    if (action == dlg->actions().first()) {  // user pressed "Ok"
+        // Get selected items.
+        QList<QVariant> selections;
+        selections = dlg->selectedItems();
+//        QString result;
+        int devTypesWanted = 0;
+        for (int i=0; i < selections.count(); i++) {
+//            result += mDevTypeList.at(selections.at(i).toInt()) + " ";
+            if (first) {
+                // this will be used as default value when opening dialog again
+                // there is no way to specify multiple default values with HbSelectionDialog
+                mLastSelectionIndex = selections.at(i).toInt();
+                first = false;
+            }
+            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
+                BTUI_ASSERT_X(false, "BtCpUiSearchView::viewByDialogClosed()", 
+                        "wrong device type in viewBy dialog!");
+            }
+        }
+//        qDebug() << result << "bits " << devTypesWanted;
+        if (devTypesWanted) {
+            mBtuiModelSortFilter->clearDeviceMajorFilters();
+            mBtuiModelSortFilter->addDeviceMajorFilter(BtuiDevProperty::InRange,
+                            BtuiModelSortFilter::AtLeastMatch);   // device must be in range
+            mBtuiModelSortFilter->addDeviceMajorFilter(devTypesWanted,
+                    BtuiModelSortFilter::RoughMatch);             // device can be any one of selected ones
+        }
+    }
+}
+
 void BtCpUiSearchView::stopSearching()
 {
     // Stop delegate
@@ -196,6 +290,30 @@
     mAbstractDelegate->cancel();
 }
 
+void BtCpUiSearchView::startSearchDelegate ()
+{
+    bool ret(false);
+    
+    if(mAbstractDelegate) {
+        mAbstractDelegate->cancel();
+        disconnect( mAbstractDelegate );
+        delete mAbstractDelegate;
+		mAbstractDelegate = 0;
+    }
+    // Create the inquiry delegate.
+    mAbstractDelegate = BtDelegateFactory::newDelegate(BtDelegate::Inquiry, mSettingModel, mDeviceModel );
+    
+    // Connect to the signal from the BtDelegateInquiry for completion of the search request
+    ret = connect(mAbstractDelegate, SIGNAL(commandCompleted(int)), this, SLOT(searchDelegateCompleted(int)));
+    BTUI_ASSERT_X( ret, "bt-search-view", "searchDelegateCompleted can't connect" );
+    
+    // Connect to the signal from the BtuiModel when the search has been completed.
+    ret = connect(mDeviceModel, SIGNAL(deviceSearchCompleted(int)), this, SLOT(deviceSearchCompleted(int)));
+    BTUI_ASSERT_X( ret, "bt-search-view", "deviceSearchCompleted can't connect" ); 
+    
+    mAbstractDelegate->exec(QVariant());
+}
+
 void BtCpUiSearchView::retrySearch()
 {
     // Retry delegate
@@ -205,10 +323,12 @@
     mRetry->setEnabled(false);
     mStop->setEnabled(true);
     
+    BtCpUiSearchListViewItem *prototype = new BtCpUiSearchListViewItem(mDeviceList);
+    prototype->setModelSortFilter(mBtuiModelSortFilter);
+    mDeviceList->setItemPrototype(prototype);
+
     // Make use of the delegate and start the search.
-    mAbstractDelegate->cancel();
-    mDeviceList->setModel(mBtuiModelSortFilter);
-    mAbstractDelegate->exec(QVariant());
+    startSearchDelegate ();
 }
 
 void BtCpUiSearchView::setSoftkeyBack()
@@ -231,36 +351,29 @@
     Q_UNUSED(cmdId);  
     
     setSoftkeyBack();
-    
-    bool ret(false);
-    
-    if(!mAbstractDelegate) {
-        // Create the inquiry delegate.
-        mAbstractDelegate = BtDelegateFactory::newDelegate(
-                BtDelegate::Inquiry, mSettingModel, mDeviceModel );
-    }
-    
-    // Connect to the signal from the BtDelegateInquiry for completion of the search request
-    ret = connect(mAbstractDelegate, SIGNAL(commandCompleted(int)), this, SLOT(searchDelegateCompleted(int)));
-    BTUI_ASSERT_X( ret, "bt-search-view", "searchDelegateCompleted can't connect" );
-    
-    // Connect to the signal from the BtuiModel when the search has been completed.
-    ret = connect(mDeviceModel, SIGNAL(deviceSearchCompleted(int)), this, SLOT(deviceSearchCompleted(int)));
-    BTUI_ASSERT_X( ret, "bt-search-view", "deviceSearchCompleted can't connect" ); 
-    
+            
     if(!mBtuiModelSortFilter) {
         mBtuiModelSortFilter = new BtuiModelSortFilter(this);
     }
     mBtuiModelSortFilter->setSourceModel(mDeviceModel);
-    mBtuiModelSortFilter->addDeviceMajorFilter(BtDeviceModel::InRange, BtuiModelSortFilter::AtLeastMatch);
+    mBtuiModelSortFilter->addDeviceMajorFilter(
+            BtuiDevProperty::InRange, BtuiModelSortFilter::AtLeastMatch);
     mDeviceList->setModel(mBtuiModelSortFilter);
 
+    BtCpUiSearchListViewItem *prototype = new BtCpUiSearchListViewItem(mDeviceList);
+    prototype->setModelSortFilter(mBtuiModelSortFilter);
+    mDeviceList->setItemPrototype(prototype);
+
     // Make use of the delegate and start the search.
-    mAbstractDelegate->exec(QVariant());
+    startSearchDelegate ();
 }
 
 void BtCpUiSearchView::deactivateView()
 {
+    if( mAbstractDelegate ) {
+       disconnect( mAbstractDelegate ); 
+    }
+    disconnect( mDeviceModel );
 }
 
 void BtCpUiSearchView::searchDelegateCompleted(int error)