bluetoothengine/btui/btcpplugin/btcpuibaseview.cpp
changeset 67 16e4b9007960
parent 57 5ebadcda06cb
equal deleted inserted replaced
65:001a94c71129 67:16e4b9007960
    23 #include <HbSelectionDialog>
    23 #include <HbSelectionDialog>
    24 #include <HbLabel>
    24 #include <HbLabel>
    25 #include "btuidevtypemap.h"
    25 #include "btuidevtypemap.h"
    26 #include <btabstractdelegate.h>
    26 #include <btabstractdelegate.h>
    27 #include <btdelegatefactory.h>
    27 #include <btdelegatefactory.h>
       
    28 #include "btqtconstants.h"
       
    29 
    28 
    30 
    29 /*!
    31 /*!
    30     This constructor constructs new setting and device models.
    32     This constructor constructs new setting and device models.
    31  */
    33  */
    32 BtcpuiBaseView::BtcpuiBaseView(QGraphicsItem *parent) :
    34 BtcpuiBaseView::BtcpuiBaseView(QGraphicsItem *parent) :
    33     CpBaseSettingView(0, parent), mViewMgr(0), mDelegate(0), mPreviousView(0),
    35     CpBaseSettingView(0, parent), mViewMgr(0), mDelegate(0), mPreviousView(0),
    34             mBack(0), mQuery(0), mContextMenu(0), mBtuiModelSortFilter(0)
    36             mBack(0), mQuery(0), mContextMenu(0), mBtuiModelSortFilter(0)
    35 {
    37 {
       
    38     BOstraceFunctionEntry1( DUMMY_DEVLIST, this );
    36     mSettingModel = new BtSettingModel(this);
    39     mSettingModel = new BtSettingModel(this);
    37     mDeviceModel = new BtDeviceModel(this);
    40     mDeviceModel = new BtDeviceModel(this);
    38     initialise();
    41     initialise();
       
    42     BOstraceFunctionExit1(DUMMY_DEVLIST, this);
    39 }
    43 }
    40 
    44 
    41 /*!
    45 /*!
    42     This constructor constructs models from the given setting and device models.
    46     This constructor constructs models from the given setting and device models.
    43     This implies the model impl and data structure are shared.
    47     This implies the model impl and data structure are shared.
    46         BtDeviceModel &deviceModel,
    50         BtDeviceModel &deviceModel,
    47         QGraphicsItem *parent) :
    51         QGraphicsItem *parent) :
    48     CpBaseSettingView(0, parent), mViewMgr(0), mDelegate(0), mPreviousView(0),
    52     CpBaseSettingView(0, parent), mViewMgr(0), mDelegate(0), mPreviousView(0),
    49             mBack(0), mQuery(0), mContextMenu(0), mBtuiModelSortFilter(0)
    53             mBack(0), mQuery(0), mContextMenu(0), mBtuiModelSortFilter(0)
    50 {
    54 {
       
    55     BOstraceFunctionEntry1( DUMMY_DEVLIST, this );
    51     mSettingModel = new BtSettingModel(settingModel, this);
    56     mSettingModel = new BtSettingModel(settingModel, this);
    52     mDeviceModel = new BtDeviceModel(deviceModel, this);
    57     mDeviceModel = new BtDeviceModel(deviceModel, this);
    53     initialise();
    58     initialise();
       
    59     BOstraceFunctionExit1(DUMMY_DEVLIST, this);
    54 }
    60 }
    55 
    61 
    56 /*!
    62 /*!
    57     Destructor.
    63     Destructor.
    58  */
    64  */
    65     if(mContextMenu) {
    71     if(mContextMenu) {
    66         mContextMenu->clearActions();
    72         mContextMenu->clearActions();
    67         delete mContextMenu;
    73         delete mContextMenu;
    68     }
    74     }
    69 
    75 
    70     BOstraceFunctionExit0(DUMMY_DEVLIST);
    76     BOstraceFunctionExit1(DUMMY_DEVLIST, this);
    71 }
    77 }
    72 
    78 
    73 void BtcpuiBaseView::initialise()
    79 void BtcpuiBaseView::initialise()
    74 {
    80 {
       
    81     BOstraceFunctionEntry1( DUMMY_DEVLIST, this );
    75     bool ret(false); 
    82     bool ret(false); 
    76     mMainWindow = hbInstance->allMainWindows().first();
    83     mMainWindow = hbInstance->allMainWindows().first();
    77     mContextMenu = new HbMenu();
    84     mContextMenu = new HbMenu();
    78     ret = connect(mContextMenu, SIGNAL(triggered(HbAction *)), this, SLOT(contextMenuTriggered(HbAction *)));
    85     ret = connect(mContextMenu, SIGNAL(triggered(HbAction *)), this, SLOT(contextMenuTriggered(HbAction *)));
    79     BTUI_ASSERT_X( ret, "bt-main-view", "Context Menu can't connect" );
    86     BTUI_ASSERT_X( ret, "BtcpuiBaseView::initialise()", "Context Menu can't connect" );
       
    87     BOstraceFunctionExit1(DUMMY_DEVLIST, this);
    80 }
    88 }
    81 
    89 
    82 void BtcpuiBaseView::setPreviousView(BtcpuiBaseView *view)
    90 void BtcpuiBaseView::setPreviousView(BtcpuiBaseView *view)
    83 {
    91 {
    84     BOstraceFunctionEntry1( DUMMY_DEVLIST, this );
    92     BOstraceFunctionEntry1( DUMMY_DEVLIST, this );
    97         }
   105         }
    98     }
   106     }
    99     else {
   107     else {
   100         setNavigationAction(0);
   108         setNavigationAction(0);
   101     }
   109     }
   102     BOstraceFunctionExit0(DUMMY_DEVLIST);
   110     BOstraceFunctionExit1(DUMMY_DEVLIST, this);
   103 }
   111 }
   104 
   112 
   105 void BtcpuiBaseView::setViewMgr(BtcpuiViewMgr *mgr)
   113 void BtcpuiBaseView::setViewMgr(BtcpuiViewMgr *mgr)
   106 {
   114 {
   107     mViewMgr = mgr;
   115     mViewMgr = mgr;
   111 {
   119 {
   112     BOstraceFunctionEntry1( DUMMY_DEVLIST, this );
   120     BOstraceFunctionEntry1( DUMMY_DEVLIST, this );
   113     if ( mPreviousView ) {
   121     if ( mPreviousView ) {
   114         viewMgr()->switchView(this, mPreviousView, QVariant(), true);
   122         viewMgr()->switchView(this, mPreviousView, QVariant(), true);
   115     }
   123     }
   116     BOstraceFunctionExit0(DUMMY_DEVLIST);
   124     BOstraceFunctionExit1(DUMMY_DEVLIST, this);
   117 }
   125 }
   118 
   126 
   119 BtSettingModel *BtcpuiBaseView::settingModel()
   127 BtSettingModel *BtcpuiBaseView::settingModel()
   120 {
   128 {
   121     return mSettingModel;
   129     return mSettingModel;
   137     bool ok(false);
   145     bool ok(false);
   138     if(!mDelegate) {
   146     if(!mDelegate) {
   139         mDelegate = BtDelegateFactory::newDelegate(type, mSettingModel, mDeviceModel); 
   147         mDelegate = BtDelegateFactory::newDelegate(type, mSettingModel, mDeviceModel); 
   140         ok = connect(mDelegate, SIGNAL(delegateCompleted(int,BtAbstractDelegate*)),
   148         ok = connect(mDelegate, SIGNAL(delegateCompleted(int,BtAbstractDelegate*)),
   141                 receiver, member);
   149                 receiver, member);
   142         BOstraceExt1(TRACE_DEBUG, DUMMY_DEVLIST, "BtcpuiBaseView::createDelegate signal connect %d", ok);
   150         BOstraceExt1(TRACE_DEBUG, DUMMY_DEVLIST, "BtcpuiBaseView::createDelegate new: signal connect %d", ok);
   143         if (!ok) {
   151         if (!ok) {
   144             delete mDelegate;
   152             delete mDelegate;
   145             mDelegate = 0;
   153             mDelegate = 0;
   146         }
   154         }
   147     }
   155     }
   148     BOstraceExt2(TRACE_DEBUG, DUMMY_DEVLIST, "BtcpuiBaseView::createDelegate: mDe: 0x%08X, ret %d", mDelegate, ok);
   156     BOstraceExt2(TRACE_DEBUG, DUMMY_DEVLIST, "BtcpuiBaseView::createDelegate(): mDe: 0x%08X, ret %d", mDelegate, ok);
   149     return ok;
   157     return ok;
   150 }
   158 }
   151 
   159 
   152 bool BtcpuiBaseView::createExecuteDelegate(BtDelegate::EditorType type,
   160 bool BtcpuiBaseView::createExecuteDelegate(BtDelegate::EditorType type,
   153         QObject *receiver, const char *member, const QVariant &param)
   161         QObject *receiver, const char *member, const QVariant &param)
   154 {
   162 {
       
   163     BOstraceFunctionEntry1( DUMMY_DEVLIST, this );
   155     bool ok = createDelegate(type, receiver, member);
   164     bool ok = createDelegate(type, receiver, member);
   156     if (ok) {
   165     if (ok) {
   157         mDelegate->exec(param);
   166         mDelegate->exec(param);
   158     }
   167     }
       
   168     BOstraceFunctionExitExt(DUMMY_DEVLIST, this, ok);
   159     return ok;
   169     return ok;
   160 }
   170 }
   161 
   171 
   162 void BtcpuiBaseView::viewByDeviceTypeDialog()
   172 void BtcpuiBaseView::viewByDeviceTypeDialog()
   163 {
   173 {
       
   174     BOstraceFunctionEntry1( DUMMY_DEVLIST, this );
   164     if ( !mQuery ) {
   175     if ( !mQuery ) {
   165         mQuery = new HbSelectionDialog();
   176         mQuery = new HbSelectionDialog();
   166         QStringList devTypeList;
   177         QStringList devTypeList;
   167         devTypeList << hbTrId("txt_bt_list_audio_devices")
   178         devTypeList << hbTrId("txt_bt_list_audio_devices")
   168                 << hbTrId("txt_bt_list_computers") 
   179                 << hbTrId("txt_bt_list_computers") 
   181         // Set the heading for the dialog.
   192         // Set the heading for the dialog.
   182         HbLabel *headingLabel = new HbLabel(hbTrId("txt_bt_title_show"), mQuery);
   193         HbLabel *headingLabel = new HbLabel(hbTrId("txt_bt_title_show"), mQuery);
   183         mQuery->setHeadingWidget(headingLabel);
   194         mQuery->setHeadingWidget(headingLabel);
   184     }
   195     }
   185     mQuery->open(this,SLOT(viewByDialogClosed(HbAction*)));
   196     mQuery->open(this,SLOT(viewByDialogClosed(HbAction*)));
       
   197     BOstraceFunctionExit1(DUMMY_DEVLIST, this);
   186 }
   198 }
   187 
   199 
   188 void BtcpuiBaseView::viewByDialogClosed(HbAction* action)
   200 void BtcpuiBaseView::viewByDialogClosed(HbAction* action)
   189 {
   201 {
   190     Q_UNUSED(action)
   202     Q_UNUSED(action)
   191     //ReImpemented in derived classes.
   203     //ReImpemented in derived classes.
   192 }
   204 }
   193 
   205 
   194 int BtcpuiBaseView::selectedDeviceTypes(HbAction* action)
   206 int BtcpuiBaseView::selectedDeviceTypes(HbAction* action)
   195 {
   207 {
       
   208     BOstraceFunctionEntry1( DUMMY_DEVLIST, this );
   196     int devTypesWanted = 0;
   209     int devTypesWanted = 0;
   197     
   210     
   198     disconnect( mQuery, 0, this, 0);  // remove signal
   211     disconnect( mQuery, 0, this, 0);  // remove signal
   199     if (action == mQuery->actions().first()) {  // user pressed "Ok"
   212     if (action == mQuery->actions().first()) {  // user pressed "Ok"
   200         // Get selected items.
   213         // Get selected items.
   229                         "wrong device type in viewBy dialog!");
   242                         "wrong device type in viewBy dialog!");
   230             }
   243             }
   231         }
   244         }
   232     }
   245     }
   233     
   246     
       
   247     BOstraceFunctionExitExt(DUMMY_DEVLIST, this, devTypesWanted);
   234     return devTypesWanted;
   248     return devTypesWanted;
   235 }
   249 }
   236 
   250 
   237 void BtcpuiBaseView::deviceSelected(const QModelIndex& modelIndex)
   251 void BtcpuiBaseView::openDeviceView(const QModelIndex& modelIndex)
   238 {
   252 {
   239     BOstraceFunctionEntry1( DUMMY_DEVLIST, this );
   253     BOstraceFunctionEntry1( DUMMY_DEVLIST, this );
   240     BtcpuiBaseView *devView = viewMgr()->deviceView();
   254     BtcpuiBaseView *devView = viewMgr()->deviceView();
   241     // For navigating back to this view:
   255     // For navigating back to this view:
   242     devView->setPreviousView( this );
   256     devView->setPreviousView( this );
   243     QModelIndex index = mBtuiModelSortFilter->mapToSource(modelIndex);
   257     QModelIndex index = mBtuiModelSortFilter->mapToSource(modelIndex);
   244     QVariant params;
   258     QVariant params;
   245     params.setValue(index);
   259     params.setValue(index);
   246     viewMgr()->switchView(this, devView, params, false);
   260     viewMgr()->switchView(this, devView, params, false);
   247     BOstraceFunctionExit0(DUMMY_DEVLIST);
   261     BOstraceFunctionExit1(DUMMY_DEVLIST, this);
   248 }
   262 }
   249 
   263 
   250 void BtcpuiBaseView::createContextMenuActions(int majorRole)
   264 void BtcpuiBaseView::createContextMenuActions(int majorRole)
   251 {
   265 {
   252     //Re-Implemented in derived classes.
   266     //Re-Implemented in derived classes.
   253     Q_UNUSED(majorRole)
   267     Q_UNUSED(majorRole)
   254 }
   268 }
   255 
   269 
   256 void BtcpuiBaseView::take(BtAbstractDelegate *delegate)
   270 void BtcpuiBaseView::take(BtAbstractDelegate *delegate)
   257 {
   271 {
       
   272     BOstraceFunctionEntry1( DUMMY_DEVLIST, this );
   258     mDelegate = delegate;
   273     mDelegate = delegate;
   259     if (mDelegate) {
   274     if (mDelegate) {
   260         disconnect(mDelegate, 0, 0, 0);
   275         disconnect(mDelegate, 0, 0, 0);
   261         connect(mDelegate, SIGNAL(delegateCompleted(int,BtAbstractDelegate*)),
   276         connect(mDelegate, SIGNAL(delegateCompleted(int,BtAbstractDelegate*)),
   262                 this, SLOT(handleDelegateCompleted(int)));
   277                 this, SLOT(handleDelegateCompleted(int)));
   263     }
   278     }
   264 }
   279     BOstraceFunctionExit1(DUMMY_DEVLIST, this);
   265 
   280 }
       
   281 
       
   282 //  this could be made virtual if derived classes need different functionality
   266 void BtcpuiBaseView::contextMenuTriggered(HbAction *action)
   283 void BtcpuiBaseView::contextMenuTriggered(HbAction *action)
   267 {
   284 {
       
   285     BOstraceFunctionEntry1( DUMMY_DEVLIST, this );
   268     if(!(action->text().compare(hbTrId("txt_common_menu_open")))) {
   286     if(!(action->text().compare(hbTrId("txt_common_menu_open")))) {
   269             deviceSelected(mLongPressedItem->modelIndex());
   287         openDeviceView(mLongPressedItem->modelIndex());
   270         }
   288     } 
   271 }
   289     else if (!(action->text().compare(hbTrId("txt_bt_menu_connect_audio")))
       
   290             || !(action->text().compare(hbTrId("txt_bt_menu_connect"))))  {
       
   291         connectToDevice(mLongPressedItem->modelIndex());
       
   292     }
       
   293     else if (!(action->text().compare(hbTrId("txt_bt_menu_disconnect_audio")))
       
   294             || !(action->text().compare(hbTrId("txt_bt_menu_disconnect"))))  {
       
   295         disconnectFromDevice(mLongPressedItem->modelIndex());
       
   296     }
       
   297     BOstraceFunctionExit1(DUMMY_DEVLIST, this);
       
   298 }
       
   299 
   272 
   300 
   273 void BtcpuiBaseView::showContextMenu(HbAbstractViewItem *item, const QPointF &coords)
   301 void BtcpuiBaseView::showContextMenu(HbAbstractViewItem *item, const QPointF &coords)
   274 {
   302 {
       
   303     BOstraceFunctionEntry1( DUMMY_DEVLIST, this );
   275     mLongPressedItem = item;
   304     mLongPressedItem = item;
   276     mContextMenu->clearActions();
   305     mContextMenu->clearActions();
   277     
   306     
   278     mContextMenu->addAction(hbTrId("txt_common_menu_open"));
   307     mContextMenu->addAction(hbTrId("txt_common_menu_open"));
   279     
   308     
   283     if (majorPropRole & BtuiDevProperty::Connectable ) {
   312     if (majorPropRole & BtuiDevProperty::Connectable ) {
   284         createContextMenuActions(majorPropRole);
   313         createContextMenuActions(majorPropRole);
   285     }
   314     }
   286     mContextMenu->setPreferredPos(coords);
   315     mContextMenu->setPreferredPos(coords);
   287     mContextMenu->open();
   316     mContextMenu->open();
       
   317     
       
   318     BOstraceFunctionExit1(DUMMY_DEVLIST, this);
       
   319 }
       
   320 
       
   321 void BtcpuiBaseView::connectToDevice(const QModelIndex& modelIndex)
       
   322 {
       
   323     BOstraceFunctionEntry1( DUMMY_DEVLIST, this );
       
   324     QModelIndex index = mBtuiModelSortFilter->mapToSource(modelIndex);
       
   325     
       
   326     QVariant param;
       
   327     param.setValue(index);
       
   328 
       
   329     (void) createExecuteDelegate(BtDelegate::ConnectService, 
       
   330             this, SLOT(handleDelegateCompleted(int,BtAbstractDelegate*)), param);    
       
   331     
       
   332     BOstraceFunctionExit1(DUMMY_DEVLIST, this);
       
   333 }
       
   334 
       
   335 void BtcpuiBaseView::disconnectFromDevice(const QModelIndex& modelIndex)
       
   336 {
       
   337     BOstraceFunctionEntry1( DUMMY_DEVLIST, this );
       
   338     QModelIndex index = mBtuiModelSortFilter->mapToSource(modelIndex);   
       
   339     QVariant deviceBtAddress = mDeviceModel->data(index, BtDeviceModel::ReadableBdaddrRole); 
       
   340             
       
   341     QList<QVariant>paramList;
       
   342     paramList.append(QVariant(ServiceLevel));
       
   343     paramList.append(deviceBtAddress);
       
   344 
       
   345     (void) createExecuteDelegate(BtDelegate::DisconnectService, 
       
   346             this, SLOT(handleDelegateCompleted(int,BtAbstractDelegate*)), QVariant(paramList));
       
   347     
       
   348     BOstraceFunctionExit1(DUMMY_DEVLIST, this);
   288 }
   349 }
   289 
   350 
   290 void BtcpuiBaseView::handleDelegateCompleted(int error, BtAbstractDelegate* delegate)
   351 void BtcpuiBaseView::handleDelegateCompleted(int error, BtAbstractDelegate* delegate)
   291 {
   352 {
   292     BOstraceFunctionEntryExt( DUMMY_DEVLIST, this, error );
   353     BOstraceFunctionEntryExt( DUMMY_DEVLIST, this, error );
       
   354     Q_UNUSED(delegate);
   293     Q_UNUSED(error);
   355     Q_UNUSED(error);
   294     delete mDelegate;
   356     delete mDelegate;
   295     mDelegate = 0;
   357     mDelegate = 0;
   296     BOstraceFunctionExit0(DUMMY_DEVLIST);
   358     BOstraceFunctionExit1(DUMMY_DEVLIST, this);
   297 }
   359 }