bluetoothengine/btui/btcpplugin/btcpuisearchview.cpp
changeset 67 16e4b9007960
parent 57 5ebadcda06cb
equal deleted inserted replaced
65:001a94c71129 67:16e4b9007960
    36 #include "btcpuisearchlistviewitem.h"
    36 #include "btcpuisearchlistviewitem.h"
    37 #include "btuidevtypemap.h"
    37 #include "btuidevtypemap.h"
    38 #include "btuimodelsortfilter.h"
    38 #include "btuimodelsortfilter.h"
    39 #include "btuiviewutil.h"
    39 #include "btuiviewutil.h"
    40 #include "btcpuiviewmgr.h"
    40 #include "btcpuiviewmgr.h"
       
    41 #include <btdelegatefactory.h>
       
    42 #include "btqtconstants.h"
    41 
    43 
    42 // docml to load
    44 // docml to load
    43 const char* BTUI_SEARCHVIEW_DOCML = ":/docml/bt-search-view.docml";
    45 const char* BTUI_SEARCHVIEW_DOCML = ":/docml/bt-search-view.docml";
    44 
    46 
    45 BtcpuiSearchView::BtcpuiSearchView(BtSettingModel &settingModel, 
    47 BtcpuiSearchView::BtcpuiSearchView(BtSettingModel &settingModel,
    46         BtDeviceModel &deviceModel, 
    48         BtDeviceModel &deviceModel, QGraphicsItem *parent) :
    47         QGraphicsItem *parent) :
    49     BtcpuiBaseView(settingModel, deviceModel, parent), mSecondaryDelegate(0)
    48     BtcpuiBaseView(settingModel,deviceModel, parent)
       
    49 {
    50 {
    50     bool ret(false);
    51     bool ret(false);
    51 
    52 
    52     // Create view for the application.
    53     // Create view for the application.
    53     // Set the name for the view. The name should be same as the view's
    54     // Set the name for the view. The name should be same as the view's
    94     BTUI_ASSERT_X( mDeviceList != 0, "BtcpuiSearchView::BtcpuiSearchView", "Device List not found" );   
    95     BTUI_ASSERT_X( mDeviceList != 0, "BtcpuiSearchView::BtcpuiSearchView", "Device List not found" );   
    95     
    96     
    96     ret = connect(mDeviceList,
    97     ret = connect(mDeviceList,
    97             SIGNAL(longPressed(HbAbstractViewItem*, QPointF)), this,
    98             SIGNAL(longPressed(HbAbstractViewItem*, QPointF)), this,
    98             SLOT(showContextMenu(HbAbstractViewItem*, QPointF)));
    99             SLOT(showContextMenu(HbAbstractViewItem*, QPointF)));
    99     BTUI_ASSERT_X( ret, "bt-search-view", "deviceSelected can't connect" ); 
   100     BTUI_ASSERT_X( ret, "bt-search-view", "showContextMenu can't connect" ); 
   100 
   101 
   101     mDeviceList->setSelectionMode( HbAbstractItemView::SingleSelection );
   102     mDeviceList->setSelectionMode( HbAbstractItemView::SingleSelection );
   102     
   103     
   103     // read landscape orientation section from docml file if needed
   104     // read landscape orientation section from docml file if needed
   104     mOrientation = mMainWindow->orientation();
   105     mOrientation = mMainWindow->orientation();
   138     // load menu
   139     // load menu
   139     HbMenu *optionsMenu = qobject_cast<HbMenu *>(mLoader->findWidget("viewMenu"));
   140     HbMenu *optionsMenu = qobject_cast<HbMenu *>(mLoader->findWidget("viewMenu"));
   140     BTUI_ASSERT_X( optionsMenu != 0, "BtcpuiSearchView::BtcpuiSearchView", "Options menu not found" );   
   141     BTUI_ASSERT_X( optionsMenu != 0, "BtcpuiSearchView::BtcpuiSearchView", "Options menu not found" );   
   141     this->setMenu(optionsMenu);      
   142     this->setMenu(optionsMenu);      
   142     
   143     
   143     ret = connect(mDeviceList, SIGNAL(activated(QModelIndex)), this, SLOT(deviceSelected(QModelIndex)));
   144     ret = connect(mDeviceList, SIGNAL(activated(QModelIndex)), this, SLOT(openDeviceView(QModelIndex)));
   144     BTUI_ASSERT_X( ret, "BtcpuiSearchView::BtcpuiSearchView", "deviceSelected can't connect" ); 
   145     BTUI_ASSERT_X( ret, "BtcpuiSearchView::BtcpuiSearchView", "openDeviceView can't connect" ); 
   145     
   146     
   146     bool regStatus(false);
   147     bool regStatus(false);
   147     regStatus = HbStyleLoader::registerFilePath(":/docml/btcpuisearchlistviewitem.widgetml");
   148     regStatus = HbStyleLoader::registerFilePath(":/docml/btcpuisearchlistviewitem.widgetml");
   148     BTUI_ASSERT_X( regStatus, "BtcpuiSearchView::BtcpuiSearchView", "registerFilePath Widgetml Failed" );
   149     BTUI_ASSERT_X( regStatus, "BtcpuiSearchView::BtcpuiSearchView", "registerFilePath Widgetml Failed" );
   149     regStatus = HbStyleLoader::registerFilePath(":/docml/btcpuisearchlistviewitem.css");
   150     regStatus = HbStyleLoader::registerFilePath(":/docml/btcpuisearchlistviewitem.css");
   170 
   171 
   171 BtcpuiSearchView::~BtcpuiSearchView()
   172 BtcpuiSearchView::~BtcpuiSearchView()
   172 {
   173 {
   173     delete mLoader; // Also deletes all widgets that it constructed.
   174     delete mLoader; // Also deletes all widgets that it constructed.
   174     delete mBtuiModelSortFilter;
   175     delete mBtuiModelSortFilter;
       
   176     delete mSecondaryDelegate;
   175     HbStyleLoader::unregisterFilePath(":/docml/btcpuisearchlistviewitem.widgetml");
   177     HbStyleLoader::unregisterFilePath(":/docml/btcpuisearchlistviewitem.widgetml");
   176     HbStyleLoader::unregisterFilePath(":/docml/btcpuisearchlistviewitem.css");
   178     HbStyleLoader::unregisterFilePath(":/docml/btcpuisearchlistviewitem.css");
   177 }
   179 }
   178 
   180 
   179 void BtcpuiSearchView::changeOrientation( Qt::Orientation orientation )
   181 void BtcpuiSearchView::changeOrientation( Qt::Orientation orientation )
   298         else {
   300         else {
   299             mContextMenu->addAction(hbTrId("txt_bt_menu_connect"));
   301             mContextMenu->addAction(hbTrId("txt_bt_menu_connect"));
   300         }
   302         }
   301     }  
   303     }  
   302 }
   304 }
       
   305 
       
   306 void BtcpuiSearchView::connectToDevice(const QModelIndex& modelIndex)
       
   307 {
       
   308     BOstraceFunctionEntry1( DUMMY_DEVLIST, this );
       
   309     
       
   310     bool ok(false);
       
   311     if(!mSecondaryDelegate) {
       
   312         mSecondaryDelegate = BtDelegateFactory::newDelegate(
       
   313                 BtDelegate::ConnectService, mSettingModel, mDeviceModel);
       
   314         ok = connect(mSecondaryDelegate,
       
   315                 SIGNAL(delegateCompleted(int,BtAbstractDelegate*)), this,
       
   316                 SLOT(secondaryDelegateCompleted(int,BtAbstractDelegate*)));
       
   317         BOstraceExt1(TRACE_DEBUG, DUMMY_DEVLIST, "BtcpuiSearchView::connectToDevice signal connect %d", ok);
       
   318         if (!ok) {
       
   319             delete mSecondaryDelegate;
       
   320             mSecondaryDelegate = 0;
       
   321         }
       
   322         else {
       
   323             QModelIndex index = mBtuiModelSortFilter->mapToSource(modelIndex);
       
   324             QVariant param;
       
   325             param.setValue(index);                
       
   326             mSecondaryDelegate->exec(param);
       
   327         }
       
   328     }
       
   329     
       
   330     BOstraceFunctionExit0(DUMMY_DEVLIST);
       
   331 }
       
   332 
       
   333 void BtcpuiSearchView::secondaryDelegateCompleted(int error, BtAbstractDelegate* delegate)
       
   334 {
       
   335     BOstraceFunctionEntryExt( DUMMY_DEVLIST, this, error );
       
   336     Q_UNUSED(error);
       
   337     Q_UNUSED(delegate);
       
   338     
       
   339     delete mSecondaryDelegate;
       
   340     mSecondaryDelegate = 0;
       
   341     BOstraceFunctionExit0(DUMMY_DEVLIST);
       
   342 }
       
   343 
       
   344 void BtcpuiSearchView::disconnectFromDevice(const QModelIndex& modelIndex)
       
   345 {
       
   346     BOstraceFunctionEntry1( DUMMY_DEVLIST, this );
       
   347     
       
   348     bool ok(false);
       
   349     if(!mSecondaryDelegate) {
       
   350         mSecondaryDelegate = BtDelegateFactory::newDelegate(
       
   351                 BtDelegate::DisconnectService, mSettingModel, mDeviceModel);
       
   352         ok = connect(mSecondaryDelegate,
       
   353                 SIGNAL(delegateCompleted(int,BtAbstractDelegate*)), this,
       
   354                 SLOT(secondaryDelegateCompleted(int,BtAbstractDelegate*)));
       
   355         BOstraceExt1(TRACE_DEBUG, DUMMY_DEVLIST, "BtcpuiSearchView::connectToDevice signal connect %d", ok);
       
   356         if (!ok) {
       
   357             delete mSecondaryDelegate;
       
   358             mSecondaryDelegate = 0;
       
   359         }
       
   360         else {
       
   361             QModelIndex index = mBtuiModelSortFilter->mapToSource(modelIndex);   
       
   362             QVariant deviceBtAddress = mDeviceModel->data(index, BtDeviceModel::ReadableBdaddrRole); 
       
   363                     
       
   364             QList<QVariant>paramList;
       
   365             paramList.append(QVariant(ServiceLevel));
       
   366             paramList.append(deviceBtAddress);
       
   367             
       
   368             mSecondaryDelegate->exec(paramList);
       
   369         }
       
   370     }
       
   371     BOstraceFunctionExit0(DUMMY_DEVLIST);
       
   372 }