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(this); |
|
31 mDeviceModel = new BtDeviceModel(this); |
|
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 mViewTranslator; |
|
44 delete mDialogTranslator; |
|
45 } |
38 |
46 |
|
47 void BtCpUiSettingItem::loadTranslators() |
|
48 { |
|
49 mViewTranslator = new HbTranslator("btviews"); |
|
50 mDialogTranslator = new HbTranslator("btdialogs"); |
39 } |
51 } |
40 |
52 |
41 void BtCpUiSettingItem::onLaunchView() |
53 void BtCpUiSettingItem::onLaunchView() |
42 { |
54 { |
43 mSettingModel = new BtSettingModel(this); |
55 |
44 mDeviceModel = new BtDeviceModel(this); |
|
45 |
|
46 mMainWindow = hbInstance->allMainWindows().first(); |
56 mMainWindow = hbInstance->allMainWindows().first(); |
47 |
57 |
48 mBtMainView = new BtCpUiMainView(*mSettingModel, *mDeviceModel); |
58 mBtMainView = new BtCpUiMainView(*mSettingModel, *mDeviceModel); |
49 |
59 |
50 mCpView = mMainWindow->currentView(); |
60 mCpView = mMainWindow->currentView(); |
51 |
61 |
52 mMainWindow->addView(mBtMainView); |
62 mMainWindow->addView(mBtMainView); |
53 mMainWindow->setCurrentView(mBtMainView); |
63 mMainWindow->setCurrentView(mBtMainView); |
54 |
64 |
58 |
68 |
59 void BtCpUiSettingItem::handleCloseView() |
69 void BtCpUiSettingItem::handleCloseView() |
60 { |
70 { |
61 mBtMainView->deactivateView(); |
71 mBtMainView->deactivateView(); |
62 mMainWindow->setCurrentView(mCpView); |
72 mMainWindow->setCurrentView(mCpView); |
|
73 |
|
74 mMainWindow->removeView(mBtMainView); |
|
75 delete mBtMainView; |
|
76 mBtMainView = 0; |
|
77 |
63 } |
78 } |
64 |
79 |
|
80 /*! |
|
81 Slot for receiving notification of local setting changes from the model. |
|
82 Identify the setting changed and update the corresponding UI item. |
|
83 */ |
|
84 void BtCpUiSettingItem::handleDataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight) |
|
85 { |
|
86 // update only the part of the view specified by the model's row(s) |
|
87 for (int i=topLeft.row(); i <= bottomRight.row(); i++) { |
|
88 QModelIndex index = mSettingModel->index( i, 0); |
|
89 // Distinguish which setting value is changed. |
|
90 switch ( i ) { |
|
91 case BtSettingModel::PowerStateRow: |
|
92 case BtSettingModel::VisibilityRow: |
|
93 updateStatus(); |
|
94 break; |
|
95 } |
|
96 } |
|
97 } |
|
98 |
|
99 void BtCpUiSettingItem::updateStatus() |
|
100 { |
|
101 QString btStatusText; |
|
102 HbIcon btStatusIcon; |
|
103 |
|
104 //todo: Connection status is not updated right now, which is also required as per UI Spec. |
|
105 PowerStateQtValue btPower = (PowerStateQtValue)mSettingModel->data(mSettingModel->index( |
|
106 BtSettingModel::PowerStateRow, 0), |
|
107 BtSettingModel::SettingValueRole).toInt(); |
|
108 |
|
109 if(BtPowerOn == btPower) { |
|
110 VisibilityMode visibilityMode = (VisibilityMode) mSettingModel->data( |
|
111 mSettingModel->index(BtSettingModel::VisibilityRow, 0), |
|
112 BtSettingModel::SettingValueRole).toInt(); |
|
113 switch(visibilityMode) { |
|
114 case BtHidden: |
|
115 btStatusText = hbTrId("txt_cp_dblist_bluetooth_val_on_and_hidden"); |
|
116 btStatusIcon.setIconName("qtg_large_bluetooth_hide"); |
|
117 break; |
|
118 case BtVisible: |
|
119 case BtTemporary: |
|
120 btStatusText = hbTrId("txt_cp_dblist_bluetooth_val_on_and_visible"); |
|
121 btStatusIcon.setIconName("qtg_large_bluetooth"); |
|
122 break; |
|
123 default: |
|
124 BTUI_ASSERT_X(false, "BtCpUiSettingItem::updateStatus", "invalid visibility mode"); |
|
125 } |
|
126 } |
|
127 else { |
|
128 //Bt is off. |
|
129 btStatusText = hbTrId("txt_cp_dblist_bluetooth_val_off"); |
|
130 btStatusIcon.setIconName("qtg_large_bluetooth_off"); |
|
131 } |
|
132 |
|
133 this->setDescription(btStatusText); |
|
134 this->setEntryItemIcon(btStatusIcon); |
|
135 } |
65 |
136 |
66 CpBaseSettingView *BtCpUiSettingItem::createSettingView() const |
137 CpBaseSettingView *BtCpUiSettingItem::createSettingView() const |
67 { |
138 { |
68 return 0; |
139 return 0; |
69 } |
140 } |