29
|
1 |
/*
|
42
|
2 |
* Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
|
|
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 |
*/
|
29
|
17 |
|
|
18 |
#include "btcpuibaseview.h"
|
31
|
19 |
#include <hbaction.h>
|
57
|
20 |
#include <HbInstance>
|
|
21 |
#include <bluetoothuitrace.h>
|
|
22 |
#include "btcpuiviewmgr.h"
|
|
23 |
#include <HbSelectionDialog>
|
|
24 |
#include <HbLabel>
|
|
25 |
#include "btuidevtypemap.h"
|
|
26 |
#include <btabstractdelegate.h>
|
|
27 |
#include <btdelegatefactory.h>
|
29
|
28 |
|
|
29 |
/*!
|
42
|
30 |
This constructor constructs new setting and device models.
|
|
31 |
*/
|
57
|
32 |
BtcpuiBaseView::BtcpuiBaseView(QGraphicsItem *parent) :
|
|
33 |
CpBaseSettingView(0, parent), mViewMgr(0), mDelegate(0), mPreviousView(0),
|
|
34 |
mBack(0), mQuery(0), mContextMenu(0), mBtuiModelSortFilter(0)
|
42
|
35 |
{
|
|
36 |
mSettingModel = new BtSettingModel(this);
|
|
37 |
mDeviceModel = new BtDeviceModel(this);
|
57
|
38 |
initialise();
|
42
|
39 |
}
|
|
40 |
|
|
41 |
/*!
|
|
42 |
This constructor constructs models from the given setting and device models.
|
57
|
43 |
This implies the model impl and data structure are shared.
|
29
|
44 |
*/
|
57
|
45 |
BtcpuiBaseView::BtcpuiBaseView(BtSettingModel &settingModel,
|
|
46 |
BtDeviceModel &deviceModel,
|
|
47 |
QGraphicsItem *parent) :
|
|
48 |
CpBaseSettingView(0, parent), mViewMgr(0), mDelegate(0), mPreviousView(0),
|
|
49 |
mBack(0), mQuery(0), mContextMenu(0), mBtuiModelSortFilter(0)
|
29
|
50 |
{
|
42
|
51 |
mSettingModel = new BtSettingModel(settingModel, this);
|
57
|
52 |
mDeviceModel = new BtDeviceModel(deviceModel, this);
|
|
53 |
initialise();
|
29
|
54 |
}
|
|
55 |
|
|
56 |
/*!
|
|
57 |
Destructor.
|
|
58 |
*/
|
57
|
59 |
BtcpuiBaseView::~BtcpuiBaseView()
|
|
60 |
{
|
|
61 |
BOstraceFunctionEntry1( DUMMY_DEVLIST, this );
|
|
62 |
delete mDelegate;
|
|
63 |
delete mQuery;
|
|
64 |
|
|
65 |
if(mContextMenu) {
|
|
66 |
mContextMenu->clearActions();
|
|
67 |
delete mContextMenu;
|
|
68 |
}
|
|
69 |
|
|
70 |
BOstraceFunctionExit0(DUMMY_DEVLIST);
|
|
71 |
}
|
|
72 |
|
|
73 |
void BtcpuiBaseView::initialise()
|
|
74 |
{
|
|
75 |
bool ret(false);
|
|
76 |
mMainWindow = hbInstance->allMainWindows().first();
|
|
77 |
mContextMenu = new HbMenu();
|
|
78 |
ret = connect(mContextMenu, SIGNAL(triggered(HbAction *)), this, SLOT(contextMenuTriggered(HbAction *)));
|
|
79 |
BTUI_ASSERT_X( ret, "bt-main-view", "Context Menu can't connect" );
|
|
80 |
}
|
|
81 |
|
|
82 |
void BtcpuiBaseView::setPreviousView(BtcpuiBaseView *view)
|
|
83 |
{
|
|
84 |
BOstraceFunctionEntry1( DUMMY_DEVLIST, this );
|
|
85 |
mPreviousView = view;
|
|
86 |
// when a non-null previous view is set, it means this view is navigated from an existing
|
|
87 |
// view. And the back-action should navigate to the previous view.
|
|
88 |
if (mPreviousView) {
|
|
89 |
// Back action is created on demand.
|
|
90 |
if (!mBack) {
|
|
91 |
mBack = new HbAction(Hb::BackNaviAction, this);
|
|
92 |
BTUI_ASSERT_X(mBack, "BtcpuiBaseView::setPreviousView", "can't create back action");
|
|
93 |
connect(mBack, SIGNAL(triggered()), this, SLOT(backToPreviousView()));
|
|
94 |
}
|
|
95 |
if (navigationAction() != mBack) {
|
|
96 |
setNavigationAction(mBack);
|
|
97 |
}
|
|
98 |
}
|
|
99 |
else {
|
|
100 |
setNavigationAction(0);
|
|
101 |
}
|
|
102 |
BOstraceFunctionExit0(DUMMY_DEVLIST);
|
|
103 |
}
|
|
104 |
|
|
105 |
void BtcpuiBaseView::setViewMgr(BtcpuiViewMgr *mgr)
|
29
|
106 |
{
|
57
|
107 |
mViewMgr = mgr;
|
|
108 |
}
|
29
|
109 |
|
57
|
110 |
void BtcpuiBaseView::backToPreviousView()
|
|
111 |
{
|
|
112 |
BOstraceFunctionEntry1( DUMMY_DEVLIST, this );
|
|
113 |
if ( mPreviousView ) {
|
|
114 |
viewMgr()->switchView(this, mPreviousView, QVariant(), true);
|
|
115 |
}
|
|
116 |
BOstraceFunctionExit0(DUMMY_DEVLIST);
|
|
117 |
}
|
|
118 |
|
|
119 |
BtSettingModel *BtcpuiBaseView::settingModel()
|
|
120 |
{
|
|
121 |
return mSettingModel;
|
|
122 |
}
|
|
123 |
|
|
124 |
BtDeviceModel *BtcpuiBaseView::deviceModel()
|
|
125 |
{
|
|
126 |
return mDeviceModel;
|
|
127 |
}
|
|
128 |
|
|
129 |
BtcpuiViewMgr *BtcpuiBaseView::viewMgr()
|
|
130 |
{
|
|
131 |
return mViewMgr;
|
|
132 |
}
|
|
133 |
|
|
134 |
bool BtcpuiBaseView::createDelegate(BtDelegate::EditorType type,
|
|
135 |
QObject *receiver, const char *member)
|
|
136 |
{
|
|
137 |
bool ok(false);
|
|
138 |
if(!mDelegate) {
|
|
139 |
mDelegate = BtDelegateFactory::newDelegate(type, mSettingModel, mDeviceModel);
|
|
140 |
ok = connect(mDelegate, SIGNAL(delegateCompleted(int,BtAbstractDelegate*)),
|
|
141 |
receiver, member);
|
|
142 |
BOstraceExt1(TRACE_DEBUG, DUMMY_DEVLIST, "BtcpuiBaseView::createDelegate signal connect %d", ok);
|
|
143 |
if (!ok) {
|
|
144 |
delete mDelegate;
|
|
145 |
mDelegate = 0;
|
|
146 |
}
|
|
147 |
}
|
|
148 |
BOstraceExt2(TRACE_DEBUG, DUMMY_DEVLIST, "BtcpuiBaseView::createDelegate: mDe: 0x%08X, ret %d", mDelegate, ok);
|
|
149 |
return ok;
|
|
150 |
}
|
|
151 |
|
|
152 |
bool BtcpuiBaseView::createExecuteDelegate(BtDelegate::EditorType type,
|
|
153 |
QObject *receiver, const char *member, const QVariant ¶m)
|
|
154 |
{
|
|
155 |
bool ok = createDelegate(type, receiver, member);
|
|
156 |
if (ok) {
|
|
157 |
mDelegate->exec(param);
|
|
158 |
}
|
|
159 |
return ok;
|
29
|
160 |
}
|
|
161 |
|
57
|
162 |
void BtcpuiBaseView::viewByDeviceTypeDialog()
|
|
163 |
{
|
|
164 |
if ( !mQuery ) {
|
|
165 |
mQuery = new HbSelectionDialog();
|
|
166 |
QStringList devTypeList;
|
|
167 |
devTypeList << hbTrId("txt_bt_list_audio_devices")
|
|
168 |
<< hbTrId("txt_bt_list_computers")
|
|
169 |
<< hbTrId("txt_bt_list_input_devices")
|
|
170 |
<< hbTrId("txt_bt_list_phones")
|
|
171 |
<< hbTrId("txt_bt_list_other_devices");
|
29
|
172 |
|
57
|
173 |
|
|
174 |
mQuery->setStringItems(devTypeList, 0);
|
|
175 |
mQuery->setSelectionMode(HbAbstractItemView::MultiSelection);
|
|
176 |
|
|
177 |
QList<QVariant> current;
|
|
178 |
current.append(QVariant(0));
|
|
179 |
mQuery->setSelectedItems(current);
|
|
180 |
|
|
181 |
// Set the heading for the dialog.
|
|
182 |
HbLabel *headingLabel = new HbLabel(hbTrId("txt_bt_title_show"), mQuery);
|
|
183 |
mQuery->setHeadingWidget(headingLabel);
|
|
184 |
}
|
|
185 |
mQuery->open(this,SLOT(viewByDialogClosed(HbAction*)));
|
|
186 |
}
|
|
187 |
|
|
188 |
void BtcpuiBaseView::viewByDialogClosed(HbAction* action)
|
|
189 |
{
|
|
190 |
Q_UNUSED(action)
|
|
191 |
//ReImpemented in derived classes.
|
|
192 |
}
|
29
|
193 |
|
57
|
194 |
int BtcpuiBaseView::selectedDeviceTypes(HbAction* action)
|
|
195 |
{
|
|
196 |
int devTypesWanted = 0;
|
|
197 |
|
|
198 |
disconnect( mQuery, 0, this, 0); // remove signal
|
|
199 |
if (action == mQuery->actions().first()) { // user pressed "Ok"
|
|
200 |
// Get selected items.
|
|
201 |
QList<QVariant> selections;
|
|
202 |
selections = mQuery->selectedItems();
|
|
203 |
|
|
204 |
for (int i=0; i < selections.count(); i++) {
|
|
205 |
switch (selections.at(i).toInt()) {
|
|
206 |
case BtUiDevAudioDevice:
|
|
207 |
devTypesWanted |= BtuiDevProperty::AVDev;
|
|
208 |
break;
|
|
209 |
case BtUiDevComputer:
|
|
210 |
devTypesWanted |= BtuiDevProperty::Computer;
|
|
211 |
break;
|
|
212 |
case BtUiDevInputDevice:
|
|
213 |
devTypesWanted |= BtuiDevProperty::Peripheral;
|
|
214 |
break;
|
|
215 |
case BtUiDevPhone:
|
|
216 |
devTypesWanted |= BtuiDevProperty::Phone;
|
|
217 |
break;
|
|
218 |
case BtUiDevOtherDevice:
|
|
219 |
devTypesWanted |= (BtuiDevProperty::LANAccessDev |
|
|
220 |
BtuiDevProperty::Toy |
|
|
221 |
BtuiDevProperty::WearableDev |
|
|
222 |
BtuiDevProperty::ImagingDev |
|
|
223 |
BtuiDevProperty::HealthDev |
|
|
224 |
BtuiDevProperty::UncategorizedDev);
|
|
225 |
break;
|
|
226 |
default:
|
|
227 |
// should never get here
|
|
228 |
BTUI_ASSERT_X(false, "BtcpuiSearchView::viewByDialogClosed()",
|
|
229 |
"wrong device type in viewBy dialog!");
|
|
230 |
}
|
|
231 |
}
|
|
232 |
}
|
|
233 |
|
|
234 |
return devTypesWanted;
|
|
235 |
}
|
29
|
236 |
|
57
|
237 |
void BtcpuiBaseView::deviceSelected(const QModelIndex& modelIndex)
|
|
238 |
{
|
|
239 |
BOstraceFunctionEntry1( DUMMY_DEVLIST, this );
|
|
240 |
BtcpuiBaseView *devView = viewMgr()->deviceView();
|
|
241 |
// For navigating back to this view:
|
|
242 |
devView->setPreviousView( this );
|
|
243 |
QModelIndex index = mBtuiModelSortFilter->mapToSource(modelIndex);
|
|
244 |
QVariant params;
|
|
245 |
params.setValue(index);
|
|
246 |
viewMgr()->switchView(this, devView, params, false);
|
|
247 |
BOstraceFunctionExit0(DUMMY_DEVLIST);
|
|
248 |
}
|
|
249 |
|
|
250 |
void BtcpuiBaseView::createContextMenuActions(int majorRole)
|
|
251 |
{
|
|
252 |
//Re-Implemented in derived classes.
|
|
253 |
Q_UNUSED(majorRole)
|
|
254 |
}
|
|
255 |
|
|
256 |
void BtcpuiBaseView::take(BtAbstractDelegate *delegate)
|
|
257 |
{
|
|
258 |
mDelegate = delegate;
|
|
259 |
if (mDelegate) {
|
|
260 |
disconnect(mDelegate, 0, 0, 0);
|
|
261 |
connect(mDelegate, SIGNAL(delegateCompleted(int,BtAbstractDelegate*)),
|
|
262 |
this, SLOT(handleDelegateCompleted(int)));
|
|
263 |
}
|
|
264 |
}
|
|
265 |
|
|
266 |
void BtcpuiBaseView::contextMenuTriggered(HbAction *action)
|
|
267 |
{
|
|
268 |
if(!(action->text().compare(hbTrId("txt_common_menu_open")))) {
|
|
269 |
deviceSelected(mLongPressedItem->modelIndex());
|
|
270 |
}
|
|
271 |
}
|
|
272 |
|
|
273 |
void BtcpuiBaseView::showContextMenu(HbAbstractViewItem *item, const QPointF &coords)
|
|
274 |
{
|
|
275 |
mLongPressedItem = item;
|
|
276 |
mContextMenu->clearActions();
|
|
277 |
|
|
278 |
mContextMenu->addAction(hbTrId("txt_common_menu_open"));
|
|
279 |
|
|
280 |
QModelIndex index = mBtuiModelSortFilter->mapToSource(mLongPressedItem->modelIndex());
|
|
281 |
|
|
282 |
int majorPropRole = (mDeviceModel->data(index,BtDeviceModel::MajorPropertyRole)).toInt();
|
|
283 |
if (majorPropRole & BtuiDevProperty::Connectable ) {
|
|
284 |
createContextMenuActions(majorPropRole);
|
|
285 |
}
|
|
286 |
mContextMenu->setPreferredPos(coords);
|
|
287 |
mContextMenu->open();
|
|
288 |
}
|
|
289 |
|
|
290 |
void BtcpuiBaseView::handleDelegateCompleted(int error, BtAbstractDelegate* delegate)
|
|
291 |
{
|
|
292 |
BOstraceFunctionEntryExt( DUMMY_DEVLIST, this, error );
|
|
293 |
Q_UNUSED(error);
|
|
294 |
delete mDelegate;
|
|
295 |
mDelegate = 0;
|
|
296 |
BOstraceFunctionExit0(DUMMY_DEVLIST);
|
|
297 |
}
|