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