bluetoothengine/btui/btcpplugin/btcpuisearchview.cpp
changeset 41 0b2439c3e397
parent 40 997690c3397a
child 52 4545c04e61e1
equal deleted inserted replaced
40:997690c3397a 41:0b2439c3e397
    46         QGraphicsItem *parent) :
    46         QGraphicsItem *parent) :
    47     BtCpUiBaseView(settingModel,deviceModel, parent), mAbstractDelegate(0), mBtuiModelSortFilter(0)
    47     BtCpUiBaseView(settingModel,deviceModel, parent), mAbstractDelegate(0), mBtuiModelSortFilter(0)
    48 {
    48 {
    49     bool ret(false);
    49     bool ret(false);
    50     
    50     
    51     mLastSelectionIndex = 0;
    51     mQuery = 0;
    52     mMainView = (BtCpUiMainView *) parent;
    52     mMainView = (BtCpUiMainView *) parent;
    53     
    53     
    54     mMainWindow = hbInstance->allMainWindows().first();
    54     mMainWindow = hbInstance->allMainWindows().first();
    55     
    55     
    56     mSoftKeyBackAction = new HbAction(Hb::BackNaviAction, this);
    56     mSoftKeyBackAction = new HbAction(Hb::BackNaviAction, this);
   119     BTUI_ASSERT_X( ret, "BtCpUiSearchView::BtCpUiSearchView()", "connect orientationChanged() failed");
   119     BTUI_ASSERT_X( ret, "BtCpUiSearchView::BtCpUiSearchView()", "connect orientationChanged() failed");
   120     
   120     
   121     // load tool bar actions
   121     // load tool bar actions
   122     mViewBy = static_cast<HbAction*>( mLoader->findObject( "viewByAction" ) );
   122     mViewBy = static_cast<HbAction*>( mLoader->findObject( "viewByAction" ) );
   123     BTUI_ASSERT_X( mViewBy, "bt-search-view", "view by action missing" ); 
   123     BTUI_ASSERT_X( mViewBy, "bt-search-view", "view by action missing" ); 
   124 //    TODO - Need to implement the View by
       
   125     ret = connect(mViewBy, SIGNAL(triggered()), this, SLOT(viewByDeviceTypeDialog()));
   124     ret = connect(mViewBy, SIGNAL(triggered()), this, SLOT(viewByDeviceTypeDialog()));
   126     BTUI_ASSERT_X( ret, "bt-search-view", "viewByAction can't connect" ); 
   125     BTUI_ASSERT_X( ret, "bt-search-view", "viewByAction can't connect" ); 
   127 
   126 
   128     mStop = static_cast<HbAction*>( mLoader->findObject( "stopAction" ) );
   127     mStop = static_cast<HbAction*>( mLoader->findObject( "stopAction" ) );
   129     BTUI_ASSERT_X( mStop, "bt-search-view", "stopAction missing" ); 
   128     BTUI_ASSERT_X( mStop, "bt-search-view", "stopAction missing" ); 
   159     mDevTypeList << hbTrId("txt_bt_list_audio_devices")
   158     mDevTypeList << hbTrId("txt_bt_list_audio_devices")
   160             << hbTrId("txt_bt_list_computers") 
   159             << hbTrId("txt_bt_list_computers") 
   161             << hbTrId("txt_bt_list_input_devices") 
   160             << hbTrId("txt_bt_list_input_devices") 
   162             << hbTrId("txt_bt_list_phones") 
   161             << hbTrId("txt_bt_list_phones") 
   163             << hbTrId("txt_bt_list_other_devices");
   162             << hbTrId("txt_bt_list_other_devices");
       
   163     
       
   164     // initialize sort model & create
       
   165     // inquiry delegate
       
   166     // Sort is set to dynamic sort filter = true in the class, will sort automatically
       
   167     mBtuiModelSortFilter = new BtuiModelSortFilter(this);
       
   168     mBtuiModelSortFilter->setSourceModel(mDeviceModel);
       
   169     mBtuiModelSortFilter->addDeviceMajorFilter(
       
   170             BtuiDevProperty::InRange, BtuiModelSortFilter::AtLeastMatch);
       
   171     mDeviceList->setModel(mBtuiModelSortFilter);
       
   172     // add sort order to show devices in the order they are found
       
   173     mBtuiModelSortFilter->setSortRole(BtDeviceModel::SeqNumRole);
       
   174     // Sort according to the first column (and the only column) in the listview - sorted according SeqNumRole
       
   175     mBtuiModelSortFilter->sort(0, Qt::AscendingOrder);
       
   176 
       
   177     BtCpUiSearchListViewItem *prototype = new BtCpUiSearchListViewItem(mDeviceList);
       
   178     prototype->setModelSortFilter(mBtuiModelSortFilter);
       
   179     mDeviceList->setItemPrototype(prototype);
       
   180 
       
   181     // Create the inquiry delegate.
       
   182     mAbstractDelegate = BtDelegateFactory::newDelegate(BtDelegate::Inquiry, mSettingModel, mDeviceModel );
       
   183     
       
   184     // Connect to the signal from the BtDelegateInquiry for completion of the search request
       
   185     ret = connect(mAbstractDelegate, SIGNAL(commandCompleted(int)), this, SLOT(searchDelegateCompleted(int)));
       
   186     BTUI_ASSERT_X( ret, "bt-search-view", "searchDelegateCompleted can't connect" );
       
   187     
       
   188     // Connect to the signal from the BtuiModel when the search has been completed.
       
   189     ret = connect(mDeviceModel, SIGNAL(deviceSearchCompleted(int)), this, SLOT(deviceSearchCompleted(int)));
       
   190     BTUI_ASSERT_X( ret, "bt-search-view", "deviceSearchCompleted can't connect" ); 
   164 }
   191 }
   165 
   192 
   166 BtCpUiSearchView::~BtCpUiSearchView()
   193 BtCpUiSearchView::~BtCpUiSearchView()
   167 {
   194 {
   168     delete mLoader; // Also deletes all widgets that it constructed.
   195     delete mLoader; // Also deletes all widgets that it constructed.
   172     delete mSoftKeyBackAction;
   199     delete mSoftKeyBackAction;
   173     
   200     
   174     if(mAbstractDelegate) {
   201     if(mAbstractDelegate) {
   175         delete mAbstractDelegate;
   202         delete mAbstractDelegate;
   176     }
   203     }
   177     
       
   178     if(mBtuiModelSortFilter) {
   204     if(mBtuiModelSortFilter) {
   179         delete mBtuiModelSortFilter;
   205         delete mBtuiModelSortFilter;
   180     }
   206     }
       
   207     if ( mQuery ) {
       
   208         delete mQuery;
       
   209     }
   181 }
   210 }
   182 
   211 
   183 void BtCpUiSearchView::changeOrientation( Qt::Orientation orientation )
   212 void BtCpUiSearchView::changeOrientation( Qt::Orientation orientation )
   184 {
   213 {
       
   214     // ToDo:  this does not handle redrawing list view items differently for portrait/landscape
   185     bool ok = false;
   215     bool ok = false;
   186     mOrientation = orientation;
   216     mOrientation = orientation;
       
   217 
   187     if( orientation == Qt::Vertical ) {
   218     if( orientation == Qt::Vertical ) {
   188         // load "portrait" section
   219         // load "portrait" section
   189         mLoader->load( BTUI_SEARCHVIEW_DOCML, "portrait_ui", &ok );
   220         mLoader->load( BTUI_SEARCHVIEW_DOCML, "portrait_ui", &ok );
   190         BTUI_ASSERT_X( ok, "bt-search-view", "Invalid docml file: portrait section problem" );
   221         BTUI_ASSERT_X( ok, "bt-search-view", "Invalid docml file: portrait section problem" );
   191     } else {
   222     } else {
   196 }
   227 }
   197 
   228 
   198 
   229 
   199 void BtCpUiSearchView::viewByDeviceTypeDialog()
   230 void BtCpUiSearchView::viewByDeviceTypeDialog()
   200 {
   231 {
   201     HbSelectionDialog *query = new HbSelectionDialog;
   232     if ( !mQuery ) {
   202     query->setStringItems(mDevTypeList, mLastSelectionIndex);
   233         mQuery = new HbSelectionDialog;
   203     query->setSelectionMode(HbAbstractItemView::MultiSelection);
   234         mQuery->setStringItems(mDevTypeList, 0);
   204 
   235         mQuery->setSelectionMode(HbAbstractItemView::MultiSelection);
   205     QList<QVariant> current;
   236     
   206     current.append(QVariant(0));
   237         QList<QVariant> current;
   207     query->setSelectedItems(current);
   238         current.append(QVariant(0));
   208 
   239         mQuery->setSelectedItems(current);
   209     query->setAttribute(Qt::WA_DeleteOnClose);
   240     
   210     
   241         // Set the heading for the dialog.
   211     // Set the heading for the dialog.
   242         HbLabel *headingLabel = new HbLabel(hbTrId("txt_bt_title_show"), mQuery);
   212     HbLabel *headingLabel = new HbLabel(hbTrId("txt_bt_title_show"), query);
   243         mQuery->setHeadingWidget(headingLabel);
   213     query->setHeadingWidget(headingLabel);
   244     }
   214 
   245     mQuery->open(this,SLOT(viewByDialogClosed(HbAction*)));
   215 
       
   216     query->open(this,SLOT(viewByDialogClosed(HbAction*)));
       
   217 }
   246 }
   218 /*!
   247 /*!
   219    Callback for dialog closing
   248    Callback for HbSelectionDialog closing
   220      ToDo:  this API might change in the future, see e-mails in Orbit-dev list, 
   249 
   221          e.g. 27.4.2010 Raju Abhilash 
       
   222  */
   250  */
   223 void BtCpUiSearchView::viewByDialogClosed(HbAction* action)
   251 void BtCpUiSearchView::viewByDialogClosed(HbAction* action)
   224 {
   252 {
   225     HbSelectionDialog *dlg = (HbSelectionDialog*)(sender());
   253     disconnect( mQuery );  // remove slot
   226     bool first = true;
   254     if (action == mQuery->actions().first()) {  // user pressed "Ok"
   227 
       
   228     if (action == dlg->actions().first()) {  // user pressed "Ok"
       
   229         // Get selected items.
   255         // Get selected items.
   230         QList<QVariant> selections;
   256         QList<QVariant> selections;
   231         selections = dlg->selectedItems();
   257         selections = mQuery->selectedItems();
   232 //        QString result;
   258         
   233         int devTypesWanted = 0;
   259         int devTypesWanted = 0;
       
   260         
   234         for (int i=0; i < selections.count(); i++) {
   261         for (int i=0; i < selections.count(); i++) {
   235 //            result += mDevTypeList.at(selections.at(i).toInt()) + " ";
       
   236             if (first) {
       
   237                 // this will be used as default value when opening dialog again
       
   238                 // there is no way to specify multiple default values with HbSelectionDialog
       
   239                 mLastSelectionIndex = selections.at(i).toInt();
       
   240                 first = false;
       
   241             }
       
   242             switch (selections.at(i).toInt()) {
   262             switch (selections.at(i).toInt()) {
   243             case BtUiDevAudioDevice:
   263             case BtUiDevAudioDevice:
   244                 devTypesWanted |= BtuiDevProperty::AVDev;
   264                 devTypesWanted |= BtuiDevProperty::AVDev;
   245                 break;
   265                 break;
   246             case BtUiDevComputer:
   266             case BtUiDevComputer:
   264                 // should never get here
   284                 // should never get here
   265                 BTUI_ASSERT_X(false, "BtCpUiSearchView::viewByDialogClosed()", 
   285                 BTUI_ASSERT_X(false, "BtCpUiSearchView::viewByDialogClosed()", 
   266                         "wrong device type in viewBy dialog!");
   286                         "wrong device type in viewBy dialog!");
   267             }
   287             }
   268         }
   288         }
   269 //        qDebug() << result << "bits " << devTypesWanted;
       
   270         if (devTypesWanted) {
   289         if (devTypesWanted) {
   271             mBtuiModelSortFilter->clearDeviceMajorFilters();
   290             mBtuiModelSortFilter->clearDeviceMajorFilters();
   272             mBtuiModelSortFilter->addDeviceMajorFilter(BtuiDevProperty::InRange,
   291             mBtuiModelSortFilter->addDeviceMajorFilter(BtuiDevProperty::InRange,
   273                             BtuiModelSortFilter::AtLeastMatch);   // device must be in range
   292                             BtuiModelSortFilter::AtLeastMatch);   // device must be in range
   274             mBtuiModelSortFilter->addDeviceMajorFilter(devTypesWanted,
   293             mBtuiModelSortFilter->addDeviceMajorFilter(devTypesWanted,
   275                     BtuiModelSortFilter::RoughMatch);             // device can be any one of selected ones
   294                     BtuiModelSortFilter::RoughMatch);             // device can be any one of selected ones
   276         }
   295         }
       
   296         mBtuiModelSortFilter->sort(0, Qt::AscendingOrder);
   277     }
   297     }
   278 }
   298 }
   279 
   299 
   280 void BtCpUiSearchView::stopSearching()
   300 void BtCpUiSearchView::stopSearching()
   281 {
   301 {
   282     // Stop delegate
   302     // Stop searching
   283     
   303     
   284     // Change label and buttons to reflect status
   304     // Change label and buttons to reflect status
   285     mLabelSearching->setPlainText(hbTrId("txt_bt_subhead_search_done"));
   305     mLabelSearching->setPlainText(hbTrId("txt_bt_subhead_search_done"));
   286     mRetry->setEnabled(true);
   306     mRetry->setEnabled(true);
   287     mStop->setEnabled(false);    
   307     mStop->setEnabled(false);    
   288 
   308 
   289     // Stop delegate
   309     // Stop search delegate
   290     mAbstractDelegate->cancel();
   310     mAbstractDelegate->cancel();
   291 }
   311 }
   292 
   312 
   293 void BtCpUiSearchView::startSearchDelegate ()
   313 void BtCpUiSearchView::startSearchDelegate ()
   294 {
   314 {
   295     bool ret(false);
       
   296     
       
   297     if(mAbstractDelegate) {
       
   298         mAbstractDelegate->cancel();
       
   299         disconnect( mAbstractDelegate );
       
   300         delete mAbstractDelegate;
       
   301 		mAbstractDelegate = 0;
       
   302     }
       
   303     // Create the inquiry delegate.
       
   304     mAbstractDelegate = BtDelegateFactory::newDelegate(BtDelegate::Inquiry, mSettingModel, mDeviceModel );
       
   305     
       
   306     // Connect to the signal from the BtDelegateInquiry for completion of the search request
       
   307     ret = connect(mAbstractDelegate, SIGNAL(commandCompleted(int)), this, SLOT(searchDelegateCompleted(int)));
       
   308     BTUI_ASSERT_X( ret, "bt-search-view", "searchDelegateCompleted can't connect" );
       
   309     
       
   310     // Connect to the signal from the BtuiModel when the search has been completed.
       
   311     ret = connect(mDeviceModel, SIGNAL(deviceSearchCompleted(int)), this, SLOT(deviceSearchCompleted(int)));
       
   312     BTUI_ASSERT_X( ret, "bt-search-view", "deviceSearchCompleted can't connect" ); 
       
   313     
   315     
   314     mAbstractDelegate->exec(QVariant());
   316     mAbstractDelegate->exec(QVariant());
   315 }
   317 }
   316 
   318 
   317 void BtCpUiSearchView::retrySearch()
   319 void BtCpUiSearchView::retrySearch()
   318 {
   320 {
   319     // Retry delegate
   321     // Retry search
   320 
   322 
   321     // Change label and buttons to reflect status
   323     // Change label and buttons to reflect status
   322     mLabelSearching->setPlainText(hbTrId("txt_bt_subhead_searching"));
   324     mLabelSearching->setPlainText(hbTrId("txt_bt_subhead_searching"));
   323     mRetry->setEnabled(false);
   325     mRetry->setEnabled(false);
   324     mStop->setEnabled(true);
   326     mStop->setEnabled(true);
   325     
   327     
   326     BtCpUiSearchListViewItem *prototype = new BtCpUiSearchListViewItem(mDeviceList);
       
   327     prototype->setModelSortFilter(mBtuiModelSortFilter);
       
   328     mDeviceList->setItemPrototype(prototype);
       
   329 
       
   330     // Make use of the delegate and start the search.
   328     // Make use of the delegate and start the search.
   331     startSearchDelegate ();
   329     startSearchDelegate ();
   332 }
   330 }
   333 
   331 
   334 void BtCpUiSearchView::setSoftkeyBack()
   332 void BtCpUiSearchView::setSoftkeyBack()
   343 {
   341 {
   344     BTUI_ASSERT_X(mMainView, "BtCpUiSearchView::switchToPreviousView", "invalid mMainView");
   342     BTUI_ASSERT_X(mMainView, "BtCpUiSearchView::switchToPreviousView", "invalid mMainView");
   345     mMainView->switchToPreviousView();
   343     mMainView->switchToPreviousView();
   346 }
   344 }
   347 
   345 
   348 void BtCpUiSearchView::activateView( const QVariant& value, int cmdId )
   346 void BtCpUiSearchView::activateView( const QVariant& value, bool fromBackButton )
   349 {
   347 {
   350     Q_UNUSED(value);
   348     Q_UNUSED(value);
   351     Q_UNUSED(cmdId);  
   349 
       
   350     // ToDo:  consider whether orientation should be updated here rather than when orientation really changes;
       
   351     // advantage:  if orientation changes temporarily in another view, but returns to previous setting before
       
   352     // search is reactived, there is no processing overhead
   352     
   353     
   353     setSoftkeyBack();
   354     setSoftkeyBack();
   354             
   355             
   355     if(!mBtuiModelSortFilter) {
   356     if ( !fromBackButton ) {
   356         mBtuiModelSortFilter = new BtuiModelSortFilter(this);
   357         startSearchDelegate();
   357     }
   358     }
   358     mBtuiModelSortFilter->setSourceModel(mDeviceModel);
       
   359     mBtuiModelSortFilter->addDeviceMajorFilter(
       
   360             BtuiDevProperty::InRange, BtuiModelSortFilter::AtLeastMatch);
       
   361     mDeviceList->setModel(mBtuiModelSortFilter);
       
   362 
       
   363     BtCpUiSearchListViewItem *prototype = new BtCpUiSearchListViewItem(mDeviceList);
       
   364     prototype->setModelSortFilter(mBtuiModelSortFilter);
       
   365     mDeviceList->setItemPrototype(prototype);
       
   366 
       
   367     // Make use of the delegate and start the search.
       
   368     startSearchDelegate ();
       
   369 }
   359 }
   370 
   360 
   371 void BtCpUiSearchView::deactivateView()
   361 void BtCpUiSearchView::deactivateView()
   372 {
   362 {
   373     if( mAbstractDelegate ) {
   363     mAbstractDelegate->cancel();          // Stop searching when leaving view
   374        disconnect( mAbstractDelegate ); 
   364     deviceSearchCompleted(KErrNone);      // reset view 
   375     }
       
   376     disconnect( mDeviceModel );
       
   377 }
   365 }
   378 
   366 
   379 void BtCpUiSearchView::searchDelegateCompleted(int error)
   367 void BtCpUiSearchView::searchDelegateCompleted(int error)
   380 {
   368 {
   381     //TODO - handle error.
       
   382     Q_UNUSED(error);
   369     Q_UNUSED(error);
       
   370     
   383 }
   371 }
   384 
   372 
   385 void BtCpUiSearchView::deviceSearchCompleted(int error)
   373 void BtCpUiSearchView::deviceSearchCompleted(int error)
   386 {
   374 {
   387     //TODO - handle error.
   375     //TODO - handle error.