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