--- a/bluetoothengine/btui/btcpplugin/btcpuimainview.cpp Wed May 05 09:56:48 2010 +0300
+++ b/bluetoothengine/btui/btcpplugin/btcpuimainview.cpp Mon May 17 11:06:23 2010 +0300
@@ -1,5 +1,5 @@
/*
-* Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies).
+* Copyright (c) 2009-2010 Nokia Corporation and/or its subsidiary(-ies).
* All rights reserved.
* This component and the accompanying materials are made available
* under the terms of "Eclipse Public License v1.0"
@@ -16,13 +16,14 @@
*/
#include "btcpuimainview.h"
+#include "btuiviewutil.h"
#include <QtGlobal>
#include <QGraphicsLinearLayout>
#include <HbInstance>
-//#include "btuiviewutil.h"
#include <hbdocumentloader.h>
#include <hbnotificationdialog.h>
#include <hbgridview.h>
+#include <hblistview.h>
#include <hbpushbutton.h>
#include <hblabel.h>
#include <hbicon.h>
@@ -33,6 +34,7 @@
#include <hbaction.h>
#include <hbcombobox.h>
#include "btcpuisearchview.h"
+#include "btcpuideviceview.h"
#include <bluetoothuitrace.h>
#include <btdelegatefactory.h>
#include <btabstractdelegate.h>
@@ -47,8 +49,12 @@
has been generated using Application Designer.
*/
-BtCpUiMainView::BtCpUiMainView( BtuiModel &model, QGraphicsItem *parent )
- : BtCpUiBaseView( model, parent ), mAbstractDelegate(0)
+BtCpUiMainView::BtCpUiMainView(
+ BtSettingModel &settingModel,
+ BtDeviceModel &deviceModel,
+ QGraphicsItem *parent )
+ : BtCpUiBaseView( settingModel, deviceModel, parent ),
+ mAbstractDelegate(0), mMainFilterModel(0)
{
bool ret(false);
@@ -99,9 +105,12 @@
BTUI_ASSERT_X( mVisibilityMode != 0, "bt-main-view", "visibility combobox not found" );
mDeviceList=0;
- mDeviceList = qobject_cast<HbGridView *>( mLoader->findWidget( "gridView" ) );
+ mDeviceList = qobject_cast<HbListView *>( mLoader->findWidget( "listView" ) );
BTUI_ASSERT_X( mDeviceList != 0, "bt-main-view", "Device List (grid view) not found" );
+ ret = connect(mDeviceList, SIGNAL(activated(QModelIndex)), this, SLOT(deviceSelected(QModelIndex)));
+ BTUI_ASSERT_X( ret, "bt-search-view", "deviceSelected can't connect" );
+
// listen for orientation changes
ret = connect(mMainWindow, SIGNAL(orientationChanged(Qt::Orientation)),
this, SLOT(changeOrientation(Qt::Orientation)));
@@ -113,18 +122,28 @@
ret = connect(discoverAction, SIGNAL(triggered()), this, SLOT(goToDiscoveryView()));
BTUI_ASSERT_X( ret, "bt-main-view", "orientation toggle can't connect" );
+ //*********************Testing device view START****************************//
+ HbAction *removePairedDevices = static_cast<HbAction*>( mLoader->findObject( "removePairedDevices" ) );
+ BTUI_ASSERT_X( removePairedDevices, "bt-main-view", "remove action missing" );
+ //ret = connect(removePairedDevices, SIGNAL(triggered()), this, SLOT(goToDeviceView()));
+ //BTUI_ASSERT_X( ret, "bt-main-view", "orientation toggle can't connect" );
+
+
+
+ //*********************Testing device view END****************************//
+
// load menu
HbMenu *optionsMenu = qobject_cast<HbMenu *>(mLoader->findWidget("viewMenu"));
BTUI_ASSERT_X( optionsMenu != 0, "bt-main-view", "Options menu not found" );
this->setMenu(optionsMenu);
// update display when setting data changed
- ret = connect(&mModel, SIGNAL(dataChanged(QModelIndex,QModelIndex)),
+ ret = connect(mSettingModel, SIGNAL(dataChanged(QModelIndex,QModelIndex)),
this, SLOT(updateSettingItems(QModelIndex,QModelIndex)));
BTUI_ASSERT_X( ret, "BtCpUiMainView::BtCpUiMainView", "can't connect dataChanged" );
- QModelIndex top = mModel.index( BtuiModel::LocalSettingRow, BtuiModel::BluetoothNameCol );
- QModelIndex bottom = mModel.index( BtuiModel::LocalSettingRow, BtuiModel::VisibilityCol );
+ QModelIndex top = mSettingModel->index( BtSettingModel::LocalBtNameRow, 0 );
+ QModelIndex bottom = mSettingModel->index( BtSettingModel::AllowedInOfflineRow, 0 );
// update name, power and visibility rows
updateSettingItems( top, bottom );
@@ -135,7 +154,18 @@
createViews();
mCurrentView = this;
mCurrentViewId = MainView;
+
+ mMainFilterModel = new BtuiModelSortFilter(this);
+
+ mMainFilterModel->setSourceModel( mDeviceModel );
+ // filter to match only InRegistry devices
+ mMainFilterModel->addDeviceMajorFilter(
+ BtDeviceModel::InRegistry,
+ BtuiModelSortFilter::AtLeastMatch);
+ mDeviceList->setModel(mMainFilterModel);
+
+
}
/*!
@@ -144,10 +174,14 @@
BtCpUiMainView::~BtCpUiMainView()
{
delete mLoader; // Also deletes all widgets that it constructed.
+
mMainWindow->removeView(mSearchView);
delete mSearchView;
- if (mAbstractDelegate)
- {
+
+ mMainWindow->removeView(mDeviceView);
+ delete mDeviceView;
+
+ if (mAbstractDelegate) {
delete mAbstractDelegate;
}
}
@@ -159,7 +193,7 @@
{
Q_UNUSED(value);
Q_UNUSED(cmdId);
-
+
}
/*!
@@ -180,6 +214,14 @@
changeView( SearchView, false, 0 );
}
+void BtCpUiMainView::goToDeviceView(const QModelIndex& modelIndex)
+{
+ //the QModelIndex of the selected device should be given as parameter here
+ QVariant params;
+ params.setValue(modelIndex);
+ changeView( DeviceView, false, 0, params );
+}
+
Qt::Orientation BtCpUiMainView::orientation()
{
return mOrientation;
@@ -189,7 +231,8 @@
{
//Error handling has to be done.
if (!mAbstractDelegate) {
- mAbstractDelegate = BtDelegateFactory::newDelegate(BtDelegate::DeviceName, mModel);
+ mAbstractDelegate = BtDelegateFactory::newDelegate(BtDelegate::DeviceName,
+ mSettingModel, mDeviceModel);
connect( mAbstractDelegate, SIGNAL(commandCompleted(int,QVariant)), this, SLOT(btNameDelegateCompleted(int,QVariant)) );
mAbstractDelegate->exec(mDeviceNameEdit->text ());
}
@@ -202,9 +245,10 @@
{
//Should we notify user this as Error...?
HbNotificationDialog::launchDialog(hbTrId("Error"));
- QModelIndex index = mModel.index( BtuiModel::LocalSettingRow, BtuiModel::BluetoothNameCol );
+ QModelIndex index = mSettingModel->index( BtSettingModel::LocalBtNameRow,0 );
- mDeviceNameEdit->setText( mModel.data(index,BtuiModel::settingDisplay).toString() );
+ mDeviceNameEdit->setText( mSettingModel->data(
+ index,BtSettingModel::settingDisplayRole).toString() );
}
@@ -238,7 +282,8 @@
}
//Error handling has to be done.
if (!mAbstractDelegate) {
- mAbstractDelegate = BtDelegateFactory::newDelegate(BtDelegate::Visibility, mModel);
+ mAbstractDelegate = BtDelegateFactory::newDelegate(BtDelegate::Visibility,
+ mSettingModel, mDeviceModel);
connect( mAbstractDelegate, SIGNAL(commandCompleted(int)), this, SLOT(visibilityDelegateCompleted(int)) );
mAbstractDelegate->exec(list);
}
@@ -254,14 +299,14 @@
//Should we notify this error to user..?
HbNotificationDialog::launchDialog(hbTrId("Error"));
- QModelIndex index = mModel.index( BtuiModel::LocalSettingRow, BtuiModel::VisibilityCol );
+ QModelIndex index = mSettingModel->index( BtSettingModel::VisibilityRow, 0 );
ret = disconnect(mVisibilityMode, SIGNAL(currentIndexChanged (int)),
this, SLOT(visibilityChanged (int)));
BTUI_ASSERT_X( ret, "BtCpUiMainView::setPrevVisibilityMode", "can't disconnect signal" );
- mVisibilityMode->setCurrentIndex ( visibilityModeToIndex((VisibilityMode)
- mModel.data(index,BtuiModel::SettingValue).toInt()) );
+ mVisibilityMode->setCurrentIndex ( visibilityModeToIndex((VisibilityMode)
+ mSettingModel->data(index,BtSettingModel::SettingValueRole).toInt()) );
//Handle Visibility Change User Interaction
ret = connect(mVisibilityMode, SIGNAL(currentIndexChanged (int)),
@@ -315,32 +360,31 @@
}
/*!
- Slot for receiving notification of data changes from the model.
+ Slot for receiving notification of local setting changes from the model.
Identify the setting changed and update the corresponding UI item.
*/
void BtCpUiMainView::updateSettingItems(const QModelIndex &topLeft, const QModelIndex &bottomRight)
{
// update only the part of the view specified by the model's row(s)
-
- for (int i=topLeft.column(); i <= bottomRight.column(); i++) {
- QModelIndex index = mModel.index( BtuiModel::LocalSettingRow, i);
+ for (int i=topLeft.row(); i <= bottomRight.row(); i++) {
+ QModelIndex index = mSettingModel->index( i, 0);
// Distinguish which setting value is changed.
switch ( i ) {
- case BtuiModel::BluetoothNameCol :
- mDeviceNameEdit->setText( mModel.data(index,BtuiModel::settingDisplay).toString() );
+ case BtSettingModel::LocalBtNameRow :
+ mDeviceNameEdit->setText(
+ mSettingModel->data(index,BtSettingModel::settingDisplayRole).toString() );
break;
- case BtuiModel::PowerStateCol:
- mPowerButton->setText( mModel.data(index,BtuiModel::settingDisplay).toString() );
+ case BtSettingModel::PowerStateRow:
+ mPowerButton->setText( mSettingModel->data(index,
+ BtSettingModel::settingDisplayRole).toString() );
break;
- case BtuiModel::VisibilityCol:
+ case BtSettingModel::VisibilityRow:
mVisibilityMode->setCurrentIndex ( visibilityModeToIndex((VisibilityMode)
- mModel.data(index,BtuiModel::SettingValue).toInt()) );
+ mSettingModel->data(index,BtSettingModel::SettingValueRole).toInt()) );
break;
}
- }
-
-
+ }
}
/*!
@@ -350,11 +394,12 @@
void BtCpUiMainView::changePowerState()
{
- QModelIndex index = mModel.index(BtuiModel::LocalSettingRow, BtuiModel::PowerStateCol);
- QVariant powerState = mModel.data(index, Qt::EditRole);
+ QModelIndex index = mSettingModel->index(BtSettingModel::PowerStateRow, 0);
+ QVariant powerState = mSettingModel->data(index, Qt::EditRole);
if (!mAbstractDelegate)//if there is no other delegate running
{
- mAbstractDelegate = BtDelegateFactory::newDelegate(BtDelegate::ManagePower, mModel);
+ mAbstractDelegate = BtDelegateFactory::newDelegate(BtDelegate::ManagePower,
+ mSettingModel, mDeviceModel );
connect( mAbstractDelegate, SIGNAL(commandCompleted(int)), this, SLOT(powerDelegateCompleted(int)) );
mAbstractDelegate->exec(powerState);
}
@@ -432,9 +477,11 @@
{
Qt::Orientation orientation = mMainWindow->orientation();
// Create other views
- mSearchView = new BtCpUiSearchView( mModel, this );
+ mSearchView = new BtCpUiSearchView( *mSettingModel, *mDeviceModel, this );
mMainWindow->addView(mSearchView);
- mDeviceView = 0; // ToDo: add this later
+
+ mDeviceView = new BtCpUiDeviceView( *mSettingModel, *mDeviceModel, this );
+ mMainWindow->addView(mDeviceView);
mCurrentView = this;
mCurrentViewId = MainView;
@@ -482,6 +529,16 @@
}
+void BtCpUiMainView::deviceSelected(const QModelIndex& modelIndex)
+{
+ QModelIndex index = mMainFilterModel->mapToSource(modelIndex);
+
+ QVariant params;
+ params.setValue(index);
+
+ changeView( DeviceView, false, 0, params );
+}
+
BtCpUiBaseView * BtCpUiMainView::idToView(int targetViewId)
{
switch (targetViewId) {
@@ -502,13 +559,13 @@
*/
void BtCpUiMainView::switchToPreviousViewReally()
{
- // jump to previous view of current view.
- if( (mCurrentViewId >= 0) && (mCurrentViewId < LastView)) {
- changeView( mPreviousViewIds[mCurrentViewId], true, 0 );
- }
- else {
- BTUI_ASSERT_X(false, "BtCpUiMainView::switchToPreviousViewReally", "invalid view id");
- }
+// // jump to previous view of current view.
+// if( (mCurrentViewId >= 0) && (mCurrentViewId < LastView)) {
+// changeView( mPreviousViewIds[mCurrentViewId], true, 0 );
+// }
+// else {
+// BTUI_ASSERT_X(false, "BtCpUiMainView::switchToPreviousViewReally", "invalid view id");
+// }
}
@@ -517,8 +574,19 @@
}
+/*!
+ Jump to previous view. This function is used when back button is pressed.
+ semantics slightly different than in other views, since this is called by other
+ views when a view switch is needed
+ */
void BtCpUiMainView::switchToPreviousView()
{
-
+ // jump to previous view of current view.
+ if( (mCurrentViewId >= 0) && (mCurrentViewId < LastView)) {
+ changeView( mPreviousViewIds[mCurrentViewId], true, 0 );
+ }
+ else {
+ BTUI_ASSERT_X(false, "BtCpUiMainView::switchToPreviousView", "invalid view id");
+ }
}