bluetoothengine/btui/btcpplugin/btcpuimainview.cpp
changeset 47 9e2a905b887f
parent 42 b72428996822
child 57 5ebadcda06cb
equal deleted inserted replaced
45:b0aebde9b1fb 47:9e2a905b887f
    32 #include <btengconstants.h>
    32 #include <btengconstants.h>
    33 #include <hbmenu.h>
    33 #include <hbmenu.h>
    34 #include <hbaction.h>
    34 #include <hbaction.h>
    35 #include <hbcombobox.h>
    35 #include <hbcombobox.h>
    36 #include <hbgroupbox.h>
    36 #include <hbgroupbox.h>
       
    37 #include <hbdataform.h>
    37 #include "btcpuisearchview.h"
    38 #include "btcpuisearchview.h"
    38 #include "btcpuideviceview.h"
    39 #include "btcpuideviceview.h"
    39 #include <bluetoothuitrace.h>
    40 #include <bluetoothuitrace.h>
    40 #include <btdelegatefactory.h>
    41 #include <btdelegatefactory.h>
    41 #include <btabstractdelegate.h>
    42 #include <btabstractdelegate.h>
   142     mPairAction = static_cast<HbAction*>( mLoader->findObject( "pairedAction" ) );
   143     mPairAction = static_cast<HbAction*>( mLoader->findObject( "pairedAction" ) );
   143     BTUI_ASSERT_X( mPairAction, "bt-main-view", "Pair action missing" ); 
   144     BTUI_ASSERT_X( mPairAction, "bt-main-view", "Pair action missing" ); 
   144     ret = connect(mPairAction, SIGNAL(triggered()), this, SLOT(pairActionTriggered()));
   145     ret = connect(mPairAction, SIGNAL(triggered()), this, SLOT(pairActionTriggered()));
   145     BTUI_ASSERT_X( ret, "bt-main-view", "pair action can't connect" ); 
   146     BTUI_ASSERT_X( ret, "bt-main-view", "pair action can't connect" ); 
   146 
   147 
   147     mGroupBox = qobject_cast<HbGroupBox *>( mLoader->findWidget( "groupBox" ) );
   148     mDataForm = qobject_cast<HbDataForm *>( mLoader->findWidget( "dataForm" ) );
   148     BTUI_ASSERT_X( mGroupBox != 0, "bt-main-view", "Group Box not found" ); 
   149     BTUI_ASSERT_X( mDataForm != 0, "bt-main-view", "dataForm not found" ); 
   149     
   150     
   150     //*********************Testing device view START****************************//
       
   151     HbAction *removePairedDevices = static_cast<HbAction*>( mLoader->findObject( "removePairedDevices" ) );
       
   152     BTUI_ASSERT_X( removePairedDevices, "bt-main-view", "remove action missing" ); 
       
   153     //ret = connect(removePairedDevices, SIGNAL(triggered()), this, SLOT(goToDeviceView()));
       
   154     //BTUI_ASSERT_X( ret, "bt-main-view", "orientation toggle can't connect" ); 
       
   155         
       
   156     
       
   157     
       
   158     //*********************Testing device view END****************************//
       
   159         
   151         
   160     // load menu
   152     // load menu
   161     HbMenu *optionsMenu = qobject_cast<HbMenu *>(mLoader->findWidget("viewMenu"));
   153     HbMenu *optionsMenu = qobject_cast<HbMenu *>(mLoader->findWidget("viewMenu"));
   162     BTUI_ASSERT_X( optionsMenu != 0, "bt-main-view", "Options menu not found" );   
   154     BTUI_ASSERT_X( optionsMenu != 0, "bt-main-view", "Options menu not found" );   
   163     this->setMenu(optionsMenu);
   155     this->setMenu(optionsMenu);
       
   156     
       
   157     HbMenu *menu = this->menu();
       
   158     mRemovePairedDevices = menu->addAction(hbTrId("txt_bt_opt_remove_paired_devices"));
       
   159     
       
   160     mSubMenu = new HbMenu(hbTrId("txt_bt_opt_remove"));
       
   161     mSubMenu->addAction(hbTrId("txt_bt_opt_remove_sub_all_devices"));
       
   162     mSubMenu->addAction(hbTrId("txt_bt_opt_remove_sub_paired_devices"));
       
   163     mSubMenu->addAction(hbTrId("txt_bt_opt_remove_sub_blocked_devices"));
   164     
   164     
   165     // update display when setting data changed
   165     // update display when setting data changed
   166     ret = connect(mSettingModel, SIGNAL(dataChanged(QModelIndex,QModelIndex)), 
   166     ret = connect(mSettingModel, SIGNAL(dataChanged(QModelIndex,QModelIndex)), 
   167             this, SLOT(updateSettingItems(QModelIndex,QModelIndex)));
   167             this, SLOT(updateSettingItems(QModelIndex,QModelIndex)));
   168     BTUI_ASSERT_X( ret, "BtCpUiMainView::BtCpUiMainView", "can't connect dataChanged" );
   168     BTUI_ASSERT_X( ret, "BtCpUiMainView::BtCpUiMainView", "can't connect dataChanged" );
   181     mCurrentViewId = MainView;
   181     mCurrentViewId = MainView;
   182     
   182     
   183     mMainFilterModel = new BtuiModelSortFilter(this);
   183     mMainFilterModel = new BtuiModelSortFilter(this);
   184     
   184     
   185     mMainFilterModel->setSourceModel( mDeviceModel );
   185     mMainFilterModel->setSourceModel( mDeviceModel );
       
   186     mDeviceList->setModel(mMainFilterModel);
   186     updateDeviceListFilter(BtuiPaired);
   187     updateDeviceListFilter(BtuiPaired);
   187 	    // List view item
   188 	    // List view item
   188     BtCpUiMainListViewItem *prototype = new BtCpUiMainListViewItem(mDeviceList);
   189     BtCpUiMainListViewItem *prototype = new BtCpUiMainListViewItem(mDeviceList);
   189     prototype->setModelSortFilter(mMainFilterModel);
   190     prototype->setModelSortFilter(mMainFilterModel);
   190     mDeviceList->setItemPrototype(prototype);
   191     mDeviceList->setItemPrototype(prototype);
   191 
   192 
   192     mDeviceList->setModel(mMainFilterModel);
       
   193 
       
   194 }
   193 }
   195 
   194 
   196 /*!
   195 /*!
   197     Destructs the BtCpUiMainView.
   196     Destructs the BtCpUiMainView.
   198  */
   197  */
   202     mMainWindow->removeView(mSearchView);
   201     mMainWindow->removeView(mSearchView);
   203     mMainWindow->removeView(mDeviceView);
   202     mMainWindow->removeView(mDeviceView);
   204 	if (mAbstractDelegate) {
   203 	if (mAbstractDelegate) {
   205         delete mAbstractDelegate;
   204         delete mAbstractDelegate;
   206     }
   205     }
       
   206 
   207 }
   207 }
   208 
   208 
   209 /*! 
   209 /*! 
   210     from base class, initialize the view
   210     from base class, initialize the view
   211  */
   211  */
   212 void BtCpUiMainView::activateView(const QVariant& value, bool fromBackButton )
   212 void BtCpUiMainView::activateView(const QVariant& value, bool fromBackButton )
   213 {
   213 {
   214     Q_UNUSED(value);
   214     Q_UNUSED(value);
   215     Q_UNUSED(fromBackButton);
   215     Q_UNUSED(fromBackButton);
   216     
   216     
       
   217     //Reset the device list when returning to the view, as it may have been invalidated by the device view
       
   218     mMainFilterModel->setSourceModel( mDeviceModel );
       
   219     mDeviceList->setModel(mMainFilterModel);
   217 }
   220 }
   218 
   221 
   219 /*! 
   222 /*! 
   220     From base class. Handle resource before the current view is deactivated.
   223     From base class. Handle resource before the current view is deactivated.
   221  */
   224  */
   319 }
   322 }
   320 
   323 
   321 
   324 
   322 void BtCpUiMainView::allActionTriggered()
   325 void BtCpUiMainView::allActionTriggered()
   323 {
   326 {
       
   327     HbMenu *menu = this->menu();
       
   328     menu->removeAction(mRemovePairedDevices);
       
   329     mRemoveDevices = menu->addMenu( mSubMenu );
       
   330 
   324     updateDeviceListFilter(BtuiAll);
   331     updateDeviceListFilter(BtuiAll);
   325 }
   332 }
   326 
   333 
   327 void BtCpUiMainView::pairActionTriggered()
   334 void BtCpUiMainView::pairActionTriggered()
   328 {
   335 {
       
   336     HbMenu *menu = this->menu();
       
   337     menu->removeAction(mRemoveDevices);
       
   338     mRemovePairedDevices = menu->addAction(hbTrId("txt_bt_opt_remove_paired_devices"));
   329     updateDeviceListFilter(BtuiPaired);
   339     updateDeviceListFilter(BtuiPaired);
   330 }
   340 }
   331 
   341 
   332 void BtCpUiMainView::updateDeviceListFilter(BtCpUiMainView::filterType filter)
   342 void BtCpUiMainView::updateDeviceListFilter(BtCpUiMainView::filterType filter)
   333 {
   343 {
   334     mMainFilterModel->clearDeviceMajorFilters();
   344     mMainFilterModel->clearDeviceMajorFilters();
   335     
   345     
   336     switch (filter) {
   346     switch (filter) {
   337         case BtuiAll:
   347         case BtuiAll:
   338             mGroupBox->setHeading(hbTrId("txt_bt_subhead_bluetooth_all_devices"));
   348             mDataForm->setHeading(hbTrId("txt_bt_subhead_bluetooth_all_devices"));
   339             mPairAction->setEnabled(true);
   349             mPairAction->setEnabled(true);
   340             mAllAction->setEnabled(false);
   350             mAllAction->setEnabled(false);
   341             mMainFilterModel->addDeviceMajorFilter(
   351             mMainFilterModel->addDeviceMajorFilter(
   342                     BtuiDevProperty::InRegistry, 
   352                     BtuiDevProperty::InRegistry, 
   343                     BtuiModelSortFilter::AtLeastMatch);
   353                     BtuiModelSortFilter::AtLeastMatch);
   344 
   354 
   345             break;
   355             break;
   346         case BtuiPaired:
   356         case BtuiPaired:
   347             mGroupBox->setHeading(hbTrId("txt_bt_subhead_bluetooth_paired_devices"));
   357             mDataForm->setHeading(hbTrId("txt_bt_subhead_bluetooth_paired_devices"));
   348             mPairAction->setEnabled(false);
   358             mPairAction->setEnabled(false);
   349             mAllAction->setEnabled(true);
   359             mAllAction->setEnabled(true);
   350             mMainFilterModel->addDeviceMajorFilter(
   360             mMainFilterModel->addDeviceMajorFilter(
   351                     BtuiDevProperty::InRegistry | BtuiDevProperty::Bonded, 
   361                     BtuiDevProperty::InRegistry | BtuiDevProperty::Bonded, 
   352                     BtuiModelSortFilter::AtLeastMatch);
   362                     BtuiModelSortFilter::AtLeastMatch);