29
|
1 |
/*
|
42
|
2 |
* Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
|
29
|
3 |
* All rights reserved.
|
|
4 |
* This component and the accompanying materials are made available
|
|
5 |
* under the terms of "Eclipse Public License v1.0""
|
|
6 |
* which accompanies this distribution, and is available
|
|
7 |
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
|
|
8 |
*
|
|
9 |
* Initial Contributors:
|
|
10 |
* Nokia Corporation - initial contribution.
|
|
11 |
*
|
|
12 |
* Contributors:
|
|
13 |
*
|
|
14 |
* Description:
|
|
15 |
*
|
|
16 |
*/
|
|
17 |
|
|
18 |
#include "btcpuisettingitem.h"
|
|
19 |
#include <cpitemdatahelper.h>
|
42
|
20 |
#include <bluetoothuitrace.h>
|
57
|
21 |
#include <btsettingmodel.h>
|
|
22 |
#include <btdevicemodel.h>
|
29
|
23 |
#include <HbInstance>
|
42
|
24 |
#include <HbTranslator>
|
57
|
25 |
#include <HbView>
|
|
26 |
#include "btcpuimainview.h"
|
29
|
27 |
|
57
|
28 |
BtcpuiSettingItem::BtcpuiSettingItem(CpItemDataHelper &itemDataHelper) :
|
|
29 |
CpSettingFormEntryItemData(itemDataHelper), mMainView(0)
|
29
|
30 |
{
|
42
|
31 |
bool ret(false);
|
|
32 |
loadTranslators();
|
|
33 |
mSettingModel = new BtSettingModel(this);
|
|
34 |
mDeviceModel = new BtDeviceModel(this);
|
57
|
35 |
mMainWindow = hbInstance->allMainWindows().first();
|
42
|
36 |
ret = connect(mSettingModel, SIGNAL(dataChanged(QModelIndex,QModelIndex)),
|
|
37 |
this, SLOT(handleDataChanged(QModelIndex,QModelIndex)));
|
57
|
38 |
BTUI_ASSERT_X( ret, "BtcpuiSettingItem::BtcpuiSettingItem", "can't connect dataChanged" );
|
42
|
39 |
|
|
40 |
this->setDescription(hbTrId("txt_cp_dblist_bluetooth"));
|
|
41 |
updateStatus();
|
29
|
42 |
}
|
|
43 |
|
57
|
44 |
BtcpuiSettingItem::~BtcpuiSettingItem()
|
29
|
45 |
{
|
57
|
46 |
delete mMainView;
|
42
|
47 |
delete mViewTranslator;
|
|
48 |
delete mDialogTranslator;
|
|
49 |
}
|
29
|
50 |
|
57
|
51 |
void BtcpuiSettingItem::onLaunchView()
|
42
|
52 |
{
|
57
|
53 |
// Main view will be launched when the user clicked the Bluetooth setting item in CP.
|
|
54 |
|
|
55 |
// We need to save the pointer of the view from which the main view is launched,
|
|
56 |
// for navigating back to CP when the main view is closed.
|
|
57 |
mCpView = mMainWindow->currentView();
|
|
58 |
mMainView = new BtcpuiMainView(*mSettingModel, *mDeviceModel);
|
|
59 |
mMainWindow->addView(mMainView);
|
|
60 |
connect(mMainView, SIGNAL(aboutToClose()), this, SLOT(handleCloseMainView()));
|
|
61 |
mMainWindow->setCurrentView(mMainView);
|
29
|
62 |
}
|
|
63 |
|
57
|
64 |
void BtcpuiSettingItem::handleCloseMainView()
|
29
|
65 |
{
|
57
|
66 |
if (mMainView) {
|
|
67 |
mMainWindow->removeView(mMainView);
|
|
68 |
delete mMainView;
|
|
69 |
mMainView = 0;
|
|
70 |
}
|
29
|
71 |
mMainWindow->setCurrentView(mCpView);
|
42
|
72 |
}
|
|
73 |
|
|
74 |
/*!
|
|
75 |
Slot for receiving notification of local setting changes from the model.
|
|
76 |
Identify the setting changed and update the corresponding UI item.
|
|
77 |
*/
|
57
|
78 |
void BtcpuiSettingItem::handleDataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight)
|
42
|
79 |
{
|
|
80 |
// update only the part of the view specified by the model's row(s)
|
|
81 |
for (int i=topLeft.row(); i <= bottomRight.row(); i++) {
|
|
82 |
QModelIndex index = mSettingModel->index( i, 0);
|
|
83 |
// Distinguish which setting value is changed.
|
|
84 |
switch ( i ) {
|
|
85 |
case BtSettingModel::PowerStateRow:
|
|
86 |
case BtSettingModel::VisibilityRow:
|
|
87 |
updateStatus();
|
|
88 |
break;
|
|
89 |
}
|
|
90 |
}
|
29
|
91 |
}
|
|
92 |
|
57
|
93 |
CpBaseSettingView *BtcpuiSettingItem::createSettingView() const
|
|
94 |
{
|
|
95 |
return 0;
|
|
96 |
}
|
|
97 |
|
|
98 |
void BtcpuiSettingItem::updateStatus()
|
42
|
99 |
{
|
|
100 |
QString btStatusText;
|
|
101 |
HbIcon btStatusIcon;
|
|
102 |
|
|
103 |
//todo: Connection status is not updated right now, which is also required as per UI Spec.
|
|
104 |
PowerStateQtValue btPower = (PowerStateQtValue)mSettingModel->data(mSettingModel->index(
|
|
105 |
BtSettingModel::PowerStateRow, 0),
|
|
106 |
BtSettingModel::SettingValueRole).toInt();
|
|
107 |
|
|
108 |
if(BtPowerOn == btPower) {
|
|
109 |
VisibilityMode visibilityMode = (VisibilityMode) mSettingModel->data(
|
|
110 |
mSettingModel->index(BtSettingModel::VisibilityRow, 0),
|
|
111 |
BtSettingModel::SettingValueRole).toInt();
|
|
112 |
switch(visibilityMode) {
|
|
113 |
case BtHidden:
|
|
114 |
btStatusText = hbTrId("txt_cp_dblist_bluetooth_val_on_and_hidden");
|
|
115 |
btStatusIcon.setIconName("qtg_large_bluetooth_hide");
|
|
116 |
break;
|
|
117 |
case BtVisible:
|
|
118 |
case BtTemporary:
|
|
119 |
btStatusText = hbTrId("txt_cp_dblist_bluetooth_val_on_and_visible");
|
|
120 |
btStatusIcon.setIconName("qtg_large_bluetooth");
|
|
121 |
break;
|
|
122 |
default:
|
57
|
123 |
BTUI_ASSERT_X(false, "BtcpuiSettingItem::updateStatus", "invalid visibility mode");
|
42
|
124 |
}
|
|
125 |
}
|
|
126 |
else {
|
|
127 |
//Bt is off.
|
|
128 |
btStatusText = hbTrId("txt_cp_dblist_bluetooth_val_off");
|
|
129 |
btStatusIcon.setIconName("qtg_large_bluetooth_off");
|
|
130 |
}
|
|
131 |
this->setDescription(btStatusText);
|
|
132 |
this->setEntryItemIcon(btStatusIcon);
|
|
133 |
}
|
29
|
134 |
|
57
|
135 |
|
|
136 |
void BtcpuiSettingItem::loadTranslators()
|
29
|
137 |
{
|
57
|
138 |
mViewTranslator = new HbTranslator("btviews");
|
|
139 |
mDialogTranslator = new HbTranslator("btdialogs");
|
29
|
140 |
}
|
57
|
141 |
|