--- a/bluetoothengine/btui/btcpplugin/btcpuisettingitem.cpp Fri Jun 11 13:48:51 2010 +0300
+++ b/bluetoothengine/btui/btcpplugin/btcpuisettingitem.cpp Wed Jun 23 18:23:52 2010 +0300
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
+ * Copyright (c) 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""
@@ -17,36 +17,49 @@
#include "btcpuisettingitem.h"
#include <cpitemdatahelper.h>
+#include <bluetoothuitrace.h>
#include <HbInstance>
+#include <HbTranslator>
-BtCpUiSettingItem::BtCpUiSettingItem(CpItemDataHelper &itemDataHelper,
- const QString &text /*= QString()*/,
- const QString &description /*= QString()*/,
- const HbIcon &icon /*= HbIcon()*/,
- const HbDataFormModelItem *parent /*= 0*/)
- : CpSettingFormEntryItemData(itemDataHelper,
- text,
- description,
- icon,
- parent)
+BtCpUiSettingItem::BtCpUiSettingItem(CpItemDataHelper &itemDataHelper) :
+ CpSettingFormEntryItemData(itemDataHelper)
{
+ bool ret(false);
+ loadTranslators();
+ mSettingModel = new BtSettingModel();
+ mDeviceModel = new BtDeviceModel();
+
+ ret = connect(mSettingModel, SIGNAL(dataChanged(QModelIndex,QModelIndex)),
+ this, SLOT(handleDataChanged(QModelIndex,QModelIndex)));
+ BTUI_ASSERT_X( ret, "BtCpUiSettingItem::BtCpUiSettingItem", "can't connect dataChanged" );
+
+ this->setDescription(hbTrId("txt_cp_dblist_bluetooth"));
+ updateStatus();
}
BtCpUiSettingItem::~BtCpUiSettingItem()
{
+ delete mSettingModel;
+ delete mDeviceModel;
+
+ delete mViewTranslator;
+ delete mDialogTranslator;
+}
+void BtCpUiSettingItem::loadTranslators()
+{
+ mViewTranslator = new HbTranslator("btviews");
+ mDialogTranslator = new HbTranslator("btdialogs");
}
void BtCpUiSettingItem::onLaunchView()
{
- mSettingModel = new BtSettingModel(this);
- mDeviceModel = new BtDeviceModel(this);
-
+
mMainWindow = hbInstance->allMainWindows().first();
mBtMainView = new BtCpUiMainView(*mSettingModel, *mDeviceModel);
-
+
mCpView = mMainWindow->currentView();
mMainWindow->addView(mBtMainView);
@@ -60,8 +73,69 @@
{
mBtMainView->deactivateView();
mMainWindow->setCurrentView(mCpView);
+
+ mMainWindow->removeView(mBtMainView);
+ delete mBtMainView;
+ mBtMainView = 0;
+
+}
+
+/*!
+ Slot for receiving notification of local setting changes from the model.
+ Identify the setting changed and update the corresponding UI item.
+ */
+void BtCpUiSettingItem::handleDataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight)
+{
+ // update only the part of the view specified by the model's row(s)
+ for (int i=topLeft.row(); i <= bottomRight.row(); i++) {
+ QModelIndex index = mSettingModel->index( i, 0);
+ // Distinguish which setting value is changed.
+ switch ( i ) {
+ case BtSettingModel::PowerStateRow:
+ case BtSettingModel::VisibilityRow:
+ updateStatus();
+ break;
+ }
+ }
}
+void BtCpUiSettingItem::updateStatus()
+{
+ QString btStatusText;
+ HbIcon btStatusIcon;
+
+ //todo: Connection status is not updated right now, which is also required as per UI Spec.
+ PowerStateQtValue btPower = (PowerStateQtValue)mSettingModel->data(mSettingModel->index(
+ BtSettingModel::PowerStateRow, 0),
+ BtSettingModel::SettingValueRole).toInt();
+
+ if(BtPowerOn == btPower) {
+ VisibilityMode visibilityMode = (VisibilityMode) mSettingModel->data(
+ mSettingModel->index(BtSettingModel::VisibilityRow, 0),
+ BtSettingModel::SettingValueRole).toInt();
+ switch(visibilityMode) {
+ case BtHidden:
+ btStatusText = hbTrId("txt_cp_dblist_bluetooth_val_on_and_hidden");
+ btStatusIcon.setIconName("qtg_large_bluetooth_hide");
+ break;
+ case BtVisible:
+ case BtTemporary:
+ btStatusText = hbTrId("txt_cp_dblist_bluetooth_val_on_and_visible");
+ btStatusIcon.setIconName("qtg_large_bluetooth");
+ break;
+ default:
+ BTUI_ASSERT_X(false, "BtCpUiSettingItem::updateStatus", "invalid visibility mode");
+ }
+ }
+ else {
+ //Bt is off.
+ btStatusText = hbTrId("txt_cp_dblist_bluetooth_val_off");
+ btStatusIcon.setIconName("qtg_large_bluetooth_off");
+ }
+
+ this->setDescription(btStatusText);
+ this->setEntryItemIcon(btStatusIcon);
+}
CpBaseSettingView *BtCpUiSettingItem::createSettingView() const
{