bluetoothengine/btui/btcpplugin/btcpuisearchview.cpp
changeset 52 4545c04e61e1
parent 41 0b2439c3e397
child 63 bcf742120177
equal deleted inserted replaced
41:0b2439c3e397 52:4545c04e61e1
    24 #include <HbPushButton>
    24 #include <HbPushButton>
    25 #include <HbLabel>
    25 #include <HbLabel>
    26 #include <HbListView>
    26 #include <HbListView>
    27 #include <HbMenu>
    27 #include <HbMenu>
    28 #include <HbSelectionDialog>
    28 #include <HbSelectionDialog>
       
    29 #include <HbGroupBox>
    29 #include <QString>
    30 #include <QString>
    30 #include <QStringList>
    31 #include <QStringList>
    31 #include <QDebug>
    32 #include <QDebug>
    32 #include <bluetoothuitrace.h>
    33 #include <bluetoothuitrace.h>
    33 #include "btcpuimainview.h"
    34 #include "btcpuimainview.h"
    47     BtCpUiBaseView(settingModel,deviceModel, parent), mAbstractDelegate(0), mBtuiModelSortFilter(0)
    48     BtCpUiBaseView(settingModel,deviceModel, parent), mAbstractDelegate(0), mBtuiModelSortFilter(0)
    48 {
    49 {
    49     bool ret(false);
    50     bool ret(false);
    50     
    51     
    51     mQuery = 0;
    52     mQuery = 0;
       
    53     mLoader = 0;
       
    54     mSoftKeyBackAction = 0;
       
    55     
    52     mMainView = (BtCpUiMainView *) parent;
    56     mMainView = (BtCpUiMainView *) parent;
    53     
       
    54     mMainWindow = hbInstance->allMainWindows().first();
    57     mMainWindow = hbInstance->allMainWindows().first();
    55     
    58     
    56     mSoftKeyBackAction = new HbAction(Hb::BackNaviAction, this);
    59     mSoftKeyBackAction = new HbAction(Hb::BackNaviAction, this);
    57     BTUI_ASSERT_X(mSoftKeyBackAction, "BtCpUiBaseView::BtCpUiBaseView", "can't create back action");
    60     BTUI_ASSERT_X(mSoftKeyBackAction, "BtCpUiSearchView::BtCpUiSearchView", "can't create back action");
    58     
    61     
    59     // Create view for the application.
    62     // Create view for the application.
    60     // Set the name for the view. The name should be same as the view's
    63     // Set the name for the view. The name should be same as the view's
    61     // name in docml.
    64     // name in docml.
    62     setObjectName("bt_search_view");
    65     setObjectName("bt_search_view");
    63 
    66 
    64     mLoader = new HbDocumentLoader();
    67     mLoader = new HbDocumentLoader();
       
    68     BTUI_ASSERT_X( mLoader != 0, "BtCpUiSearchView::BtCpUiSearchView", "can't create mLoader" );
    65     // Pass the view to documentloader. Document loader uses this view
    69     // Pass the view to documentloader. Document loader uses this view
    66     // when docml is parsed, instead of creating new view.
    70     // when docml is parsed, instead of creating new view.
    67     QObjectList objectList;
    71     QObjectList objectList;
    68     objectList.append(this);
    72     objectList.append(this);
    69     mLoader->setObjectTree(objectList);
    73     mLoader->setObjectTree(objectList);
    81     // assign automatically created widgets to local variables
    85     // assign automatically created widgets to local variables
    82 
    86 
    83     mDeviceIcon=0;
    87     mDeviceIcon=0;
    84     // can't use qobject_cast since HbIcon is not derived from QObject!
    88     // can't use qobject_cast since HbIcon is not derived from QObject!
    85     mDeviceIcon = qobject_cast<HbLabel *>( mLoader->findWidget( "icon" ) );  
    89     mDeviceIcon = qobject_cast<HbLabel *>( mLoader->findWidget( "icon" ) );  
    86     BTUI_ASSERT_X( mDeviceIcon != 0, "bt-search-view", "Device Icon not found" );
    90     BTUI_ASSERT_X( mDeviceIcon != 0, "BtCpUiSearchView::BtCpUiSearchView", "Device Icon not found" );
    87     
    91     
    88     mLabelFoundDevices=0;
    92     mDataForm=0;
    89     mLabelFoundDevices = qobject_cast<HbLabel *>( mLoader->findWidget( "label_found_devices" ) );
    93     mDataForm = qobject_cast<HbDataForm *>( mLoader->findWidget( "dataForm" ) );
    90     BTUI_ASSERT_X( mLabelFoundDevices != 0, "bt-search-view", "Found Devices not found" );
    94     BTUI_ASSERT_X( mDataForm != 0, "BtCpUiSearchView::BtCpUiSearchView", "dataForm not found" );
    91     mLabelFoundDevices->setPlainText(hbTrId("txt_bt_subhead_bluetooth_found_devices"));
    95     mDataForm->setHeading(hbTrId("txt_bt_subhead_bluetooth_found_devices"));
    92 
    96 
    93     mLabelSearching=0;
    97     mLabelSearching=0;
    94     mLabelSearching = qobject_cast<HbLabel *>( mLoader->findWidget( "label_searching" ) );
    98     mLabelSearching = qobject_cast<HbLabel *>( mLoader->findWidget( "label_searching" ) );
    95     BTUI_ASSERT_X( mLabelSearching != 0, "bt-search-view", "Searching not found" );
    99     BTUI_ASSERT_X( mLabelSearching != 0, "BtCpUiSearchView::BtCpUiSearchView", "Searching not found" );
    96     mLabelSearching->setPlainText(hbTrId("txt_bt_subhead_searching"));
   100     mLabelSearching->setPlainText(hbTrId("txt_bt_subhead_searching"));
    97     
   101     
    98     mDeviceList=0;
   102     mDeviceList=0;
    99     mDeviceList = qobject_cast<HbListView *>( mLoader->findWidget( "deviceList" ) );
   103     mDeviceList = qobject_cast<HbListView *>( mLoader->findWidget( "deviceList" ) );
   100     BTUI_ASSERT_X( mDeviceList != 0, "bt-search-view", "Device List not found" );   
   104     BTUI_ASSERT_X( mDeviceList != 0, "BtCpUiSearchView::BtCpUiSearchView", "Device List not found" );   
   101     
   105     
   102     
   106     
   103     mDeviceList->setSelectionMode( HbAbstractItemView::SingleSelection );
   107     mDeviceList->setSelectionMode( HbAbstractItemView::SingleSelection );
   104     
   108     
   105     // read landscape orientation section from docml file if needed
   109     // read landscape orientation section from docml file if needed
   106     mOrientation = mMainWindow->orientation();
   110     mOrientation = mMainWindow->orientation();
   107     
   111     
   108     if (mOrientation == Qt::Horizontal) {
   112     if (mOrientation == Qt::Horizontal) {
   109         mLoader->load(BTUI_SEARCHVIEW_DOCML, "landscape_ui", &ok);
   113         mLoader->load(BTUI_SEARCHVIEW_DOCML, "landscape_ui", &ok);
   110         BTUI_ASSERT_X( ok, "bt-search-view", "Invalid docml file: landscape section problem" );
   114         BTUI_ASSERT_X( ok, "BtCpUiSearchView::BtCpUiSearchView", "Invalid docml file: landscape section problem" );
   111     } else {
   115     } else {
   112         mLoader->load(BTUI_SEARCHVIEW_DOCML, "portrait_ui", &ok);
   116         mLoader->load(BTUI_SEARCHVIEW_DOCML, "portrait_ui", &ok);
   113         BTUI_ASSERT_X( ok, "bt-search-view", "Invalid docml file: portrait section problem" );        
   117         BTUI_ASSERT_X( ok, "BtCpUiSearchView::BtCpUiSearchView", "Invalid docml file: portrait section problem" );        
   114     }
   118     }
   115 
   119 
   116     // listen for orientation changes
   120     // listen for orientation changes
   117     ret = connect(mMainWindow, SIGNAL(orientationChanged(Qt::Orientation)),
   121     ret = connect(mMainWindow, SIGNAL(orientationChanged(Qt::Orientation)),
   118             this, SLOT(changeOrientation(Qt::Orientation)));
   122             this, SLOT(changeOrientation(Qt::Orientation)));
   119     BTUI_ASSERT_X( ret, "BtCpUiSearchView::BtCpUiSearchView()", "connect orientationChanged() failed");
   123     BTUI_ASSERT_X( ret, "BtCpUiSearchView::BtCpUiSearchView()", "connect orientationChanged() failed");
   120     
   124     
   121     // load tool bar actions
   125     // load tool bar actions
   122     mViewBy = static_cast<HbAction*>( mLoader->findObject( "viewByAction" ) );
   126     mViewBy = static_cast<HbAction*>( mLoader->findObject( "viewByAction" ) );
   123     BTUI_ASSERT_X( mViewBy, "bt-search-view", "view by action missing" ); 
   127     BTUI_ASSERT_X( mViewBy, "BtCpUiSearchView::BtCpUiSearchView", "view by action missing" ); 
   124     ret = connect(mViewBy, SIGNAL(triggered()), this, SLOT(viewByDeviceTypeDialog()));
   128     ret = connect(mViewBy, SIGNAL(triggered()), this, SLOT(viewByDeviceTypeDialog()));
   125     BTUI_ASSERT_X( ret, "bt-search-view", "viewByAction can't connect" ); 
   129     BTUI_ASSERT_X( ret, "BtCpUiSearchView::BtCpUiSearchView", "viewByAction can't connect" ); 
   126 
   130 
   127     mStop = static_cast<HbAction*>( mLoader->findObject( "stopAction" ) );
   131     mStop = static_cast<HbAction*>( mLoader->findObject( "stopAction" ) );
   128     BTUI_ASSERT_X( mStop, "bt-search-view", "stopAction missing" ); 
   132     BTUI_ASSERT_X( mStop, "BtCpUiSearchView::BtCpUiSearchView", "stopAction missing" ); 
   129     ret = connect(mStop, SIGNAL(triggered()), this, SLOT(stopSearching()));
   133     ret = connect(mStop, SIGNAL(triggered()), this, SLOT(stopSearching()));
   130     BTUI_ASSERT_X( ret, "bt-search-view", "stopAction can't connect" ); 
   134     BTUI_ASSERT_X( ret, "BtCpUiSearchView::BtCpUiSearchView", "stopAction can't connect" ); 
   131     mStop->setEnabled(true);
   135     mStop->setEnabled(true);
   132     
   136     
   133     mRetry = static_cast<HbAction*>( mLoader->findObject( "retryAction" ) );
   137     mRetry = static_cast<HbAction*>( mLoader->findObject( "retryAction" ) );
   134     BTUI_ASSERT_X( mRetry, "bt-search-view", "retryAction missing" ); 
   138     BTUI_ASSERT_X( mRetry, "BtCpUiSearchView::BtCpUiSearchView", "retryAction missing" ); 
   135     ret = connect(mRetry, SIGNAL(triggered()), this, SLOT(retrySearch()));
   139     ret = connect(mRetry, SIGNAL(triggered()), this, SLOT(retrySearch()));
   136     BTUI_ASSERT_X( ret, "bt-search-view", "retryAction can't connect" ); 
   140     BTUI_ASSERT_X( ret, "BtCpUiSearchView::BtCpUiSearchView", "retryAction can't connect" ); 
   137     // Disable for initial search
   141     // Disable for initial search
   138     mRetry->setEnabled(false);
   142     mRetry->setEnabled(false);
   139     
   143     
   140     // load menu
   144     // load menu
   141     HbMenu *optionsMenu = qobject_cast<HbMenu *>(mLoader->findWidget("viewMenu"));
   145     HbMenu *optionsMenu = qobject_cast<HbMenu *>(mLoader->findWidget("viewMenu"));
   142     BTUI_ASSERT_X( optionsMenu != 0, "bt-search-view", "Options menu not found" );   
   146     BTUI_ASSERT_X( optionsMenu != 0, "BtCpUiSearchView::BtCpUiSearchView", "Options menu not found" );   
   143     this->setMenu(optionsMenu);      
   147     this->setMenu(optionsMenu);      
   144     
   148     
   145     mExit = static_cast<HbAction*>( mLoader->findObject( "exitAction" ) );
       
   146     BTUI_ASSERT_X( mExit, "bt-search-view", "exitAction missing" ); 
       
   147     mExit->setText(hbTrId("txt_common_opt_exit"));
       
   148     
       
   149     mConnect = static_cast<HbAction*>( mLoader->findObject( "connectAction" ) );
       
   150     BTUI_ASSERT_X( mConnect, "bt-search-view", "connectAction missing" ); 
       
   151     mConnect->setText(hbTrId("txt_bt_menu_connect"));
       
   152     
       
   153     ret = connect(mDeviceList, SIGNAL(activated(QModelIndex)), this, SLOT(deviceSelected(QModelIndex)));
   149     ret = connect(mDeviceList, SIGNAL(activated(QModelIndex)), this, SLOT(deviceSelected(QModelIndex)));
   154     BTUI_ASSERT_X( ret, "bt-search-view", "deviceSelected can't connect" ); 
   150     BTUI_ASSERT_X( ret, "BtCpUiSearchView::BtCpUiSearchView", "deviceSelected can't connect" ); 
   155     
   151     
   156     // initialize device type list for "view by" option
   152     // initialize device type list for "view by" option
   157     // Note:  this list needs to be in the same order as enum devTypeSelectionList
   153     // Note:  this list needs to be in the same order as enum devTypeSelectionList
   158     mDevTypeList << hbTrId("txt_bt_list_audio_devices")
   154     mDevTypeList << hbTrId("txt_bt_list_audio_devices")
   159             << hbTrId("txt_bt_list_computers") 
   155             << hbTrId("txt_bt_list_computers") 
   179     mDeviceList->setItemPrototype(prototype);
   175     mDeviceList->setItemPrototype(prototype);
   180 
   176 
   181     // Create the inquiry delegate.
   177     // Create the inquiry delegate.
   182     mAbstractDelegate = BtDelegateFactory::newDelegate(BtDelegate::Inquiry, mSettingModel, mDeviceModel );
   178     mAbstractDelegate = BtDelegateFactory::newDelegate(BtDelegate::Inquiry, mSettingModel, mDeviceModel );
   183     
   179     
   184     // Connect to the signal from the BtDelegateInquiry for completion of the search request
   180 
   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" ); 
       
   191 }
   181 }
   192 
   182 
   193 BtCpUiSearchView::~BtCpUiSearchView()
   183 BtCpUiSearchView::~BtCpUiSearchView()
   194 {
   184 {
   195     delete mLoader; // Also deletes all widgets that it constructed.
   185     delete mLoader; // Also deletes all widgets that it constructed.
   197     setNavigationAction(0);
   187     setNavigationAction(0);
   198     disconnect( mSoftKeyBackAction );
   188     disconnect( mSoftKeyBackAction );
   199     delete mSoftKeyBackAction;
   189     delete mSoftKeyBackAction;
   200     
   190     
   201     if(mAbstractDelegate) {
   191     if(mAbstractDelegate) {
       
   192         disconnect(mAbstractDelegate);   
   202         delete mAbstractDelegate;
   193         delete mAbstractDelegate;
   203     }
   194     }
   204     if(mBtuiModelSortFilter) {
   195     if(mBtuiModelSortFilter) {
   205         delete mBtuiModelSortFilter;
   196         delete mBtuiModelSortFilter;
   206     }
   197     }
   216     mOrientation = orientation;
   207     mOrientation = orientation;
   217 
   208 
   218     if( orientation == Qt::Vertical ) {
   209     if( orientation == Qt::Vertical ) {
   219         // load "portrait" section
   210         // load "portrait" section
   220         mLoader->load( BTUI_SEARCHVIEW_DOCML, "portrait_ui", &ok );
   211         mLoader->load( BTUI_SEARCHVIEW_DOCML, "portrait_ui", &ok );
   221         BTUI_ASSERT_X( ok, "bt-search-view", "Invalid docml file: portrait section problem" );
   212         BTUI_ASSERT_X( ok, "BtCpUiSearchView::changeOrientation", "Invalid docml file: portrait section problem" );
   222     } else {
   213     } else {
   223         // load "landscape" section
   214         // load "landscape" section
   224         mLoader->load( BTUI_SEARCHVIEW_DOCML, "landscape_ui", &ok );
   215         mLoader->load( BTUI_SEARCHVIEW_DOCML, "landscape_ui", &ok );
   225         BTUI_ASSERT_X( ok, "bt-search-view", "Invalid docml file: landscape section problem" );
   216         BTUI_ASSERT_X( ok, "BtCpUiSearchView::changeOrientation", "Invalid docml file: landscape section problem" );
   226     }
   217     }
   227 }
   218 }
   228 
   219 
   229 
   220 
   230 void BtCpUiSearchView::viewByDeviceTypeDialog()
   221 void BtCpUiSearchView::viewByDeviceTypeDialog()
   291             mBtuiModelSortFilter->addDeviceMajorFilter(BtuiDevProperty::InRange,
   282             mBtuiModelSortFilter->addDeviceMajorFilter(BtuiDevProperty::InRange,
   292                             BtuiModelSortFilter::AtLeastMatch);   // device must be in range
   283                             BtuiModelSortFilter::AtLeastMatch);   // device must be in range
   293             mBtuiModelSortFilter->addDeviceMajorFilter(devTypesWanted,
   284             mBtuiModelSortFilter->addDeviceMajorFilter(devTypesWanted,
   294                     BtuiModelSortFilter::RoughMatch);             // device can be any one of selected ones
   285                     BtuiModelSortFilter::RoughMatch);             // device can be any one of selected ones
   295         }
   286         }
   296         mBtuiModelSortFilter->sort(0, Qt::AscendingOrder);
       
   297     }
   287     }
   298 }
   288 }
   299 
   289 
   300 void BtCpUiSearchView::stopSearching()
   290 void BtCpUiSearchView::stopSearching()
   301 {
   291 {
   302     // Stop searching
   292     // Stop searching
   303     
       
   304     // Change label and buttons to reflect status
       
   305     mLabelSearching->setPlainText(hbTrId("txt_bt_subhead_search_done"));
       
   306     mRetry->setEnabled(true);
       
   307     mStop->setEnabled(false);    
       
   308 
   293 
   309     // Stop search delegate
   294     // Stop search delegate
   310     mAbstractDelegate->cancel();
   295     mAbstractDelegate->cancel();
       
   296     // reset view 
       
   297     deviceSearchCompleted(KErrNone);      
   311 }
   298 }
   312 
   299 
   313 void BtCpUiSearchView::startSearchDelegate ()
   300 void BtCpUiSearchView::startSearchDelegate ()
   314 {
   301 {
   315     
   302     bool ret = false;
       
   303     
       
   304     // Connect to the signal from the BtDelegateInquiry for completion of the search request
       
   305     ret = connect(mAbstractDelegate, SIGNAL(commandCompleted(int)), this, SLOT(searchDelegateCompleted(int)));
       
   306     BTUI_ASSERT_X( ret, "BtCpUiSearchView::BtCpUiSearchView", "searchDelegateCompleted can't connect" );
       
   307     
       
   308     // Connect to the signal from the BtuiModel when the search has been completed.
       
   309     ret = connect(mDeviceModel, SIGNAL(deviceSearchCompleted(int)), this, SLOT(deviceSearchCompleted(int)));
       
   310     BTUI_ASSERT_X( ret, "BtCpUiSearchView::BtCpUiSearchView", "deviceSearchCompleted can't connect" );     
       
   311 
   316     mAbstractDelegate->exec(QVariant());
   312     mAbstractDelegate->exec(QVariant());
   317 }
   313 }
   318 
   314 
   319 void BtCpUiSearchView::retrySearch()
   315 void BtCpUiSearchView::retrySearch()
   320 {
   316 {
   352     // search is reactived, there is no processing overhead
   348     // search is reactived, there is no processing overhead
   353     
   349     
   354     setSoftkeyBack();
   350     setSoftkeyBack();
   355             
   351             
   356     if ( !fromBackButton ) {
   352     if ( !fromBackButton ) {
   357         startSearchDelegate();
   353         // Sets the label and toolbar buttons
       
   354         retrySearch();
   358     }
   355     }
   359 }
   356 }
   360 
   357 
   361 void BtCpUiSearchView::deactivateView()
   358 void BtCpUiSearchView::deactivateView()
   362 {
   359 {
   372 
   369 
   373 void BtCpUiSearchView::deviceSearchCompleted(int error)
   370 void BtCpUiSearchView::deviceSearchCompleted(int error)
   374 {
   371 {
   375     //TODO - handle error.
   372     //TODO - handle error.
   376     Q_UNUSED(error);
   373     Q_UNUSED(error);
       
   374     
   377     mLabelSearching->setPlainText(hbTrId("txt_bt_subhead_search_done"));
   375     mLabelSearching->setPlainText(hbTrId("txt_bt_subhead_search_done"));
   378     mRetry->setEnabled(true);
   376     mRetry->setEnabled(true);
   379     mStop->setEnabled(false);    
   377     mStop->setEnabled(false);
       
   378     
       
   379     // disconnect signals
       
   380     disconnect(mAbstractDelegate);
       
   381     disconnect(mDeviceModel);
   380 }
   382 }
   381 
   383 
   382 void BtCpUiSearchView::deviceSelected(const QModelIndex& modelIndex)
   384 void BtCpUiSearchView::deviceSelected(const QModelIndex& modelIndex)
   383 {
   385 {
   384     QModelIndex index = mBtuiModelSortFilter->mapToSource(modelIndex);
   386     QModelIndex index = mBtuiModelSortFilter->mapToSource(modelIndex);