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 "btcpuisearchview.h"
|
57
|
19 |
#include <HbStyleLoader>
|
29
|
20 |
#include <QtGui/QGraphicsLinearLayout>
|
57
|
21 |
#include <HbAction>
|
29
|
22 |
#include <HbInstance>
|
31
|
23 |
#include <HbDocumentLoader>
|
|
24 |
#include <HbDataForm>
|
|
25 |
#include <HbPushButton>
|
|
26 |
#include <HbLabel>
|
|
27 |
#include <HbListView>
|
|
28 |
#include <HbMenu>
|
42
|
29 |
#include <HbSelectionDialog>
|
47
|
30 |
#include <HbGroupBox>
|
31
|
31 |
#include <QString>
|
|
32 |
#include <QStringList>
|
|
33 |
#include <QDebug>
|
29
|
34 |
#include <bluetoothuitrace.h>
|
31
|
35 |
#include "btabstractdelegate.h"
|
42
|
36 |
#include "btcpuisearchlistviewitem.h"
|
|
37 |
#include "btuidevtypemap.h"
|
57
|
38 |
#include "btuimodelsortfilter.h"
|
|
39 |
#include "btuiviewutil.h"
|
|
40 |
#include "btcpuiviewmgr.h"
|
67
|
41 |
#include <btdelegatefactory.h>
|
|
42 |
#include "btqtconstants.h"
|
29
|
43 |
|
|
44 |
// docml to load
|
|
45 |
const char* BTUI_SEARCHVIEW_DOCML = ":/docml/bt-search-view.docml";
|
|
46 |
|
67
|
47 |
BtcpuiSearchView::BtcpuiSearchView(BtSettingModel &settingModel,
|
|
48 |
BtDeviceModel &deviceModel, QGraphicsItem *parent) :
|
|
49 |
BtcpuiBaseView(settingModel, deviceModel, parent), mSecondaryDelegate(0)
|
31
|
50 |
{
|
|
51 |
bool ret(false);
|
57
|
52 |
|
29
|
53 |
// Create view for the application.
|
|
54 |
// Set the name for the view. The name should be same as the view's
|
|
55 |
// name in docml.
|
|
56 |
setObjectName("bt_search_view");
|
|
57 |
|
42
|
58 |
mLoader = new HbDocumentLoader();
|
57
|
59 |
BTUI_ASSERT_X( mLoader != 0, "BtcpuiSearchView::BtcpuiSearchView", "can't create mLoader" );
|
42
|
60 |
// Pass the view to documentloader. Document loader uses this view
|
|
61 |
// when docml is parsed, instead of creating new view.
|
29
|
62 |
QObjectList objectList;
|
|
63 |
objectList.append(this);
|
|
64 |
mLoader->setObjectTree(objectList);
|
31
|
65 |
|
|
66 |
// read view info from docml file
|
29
|
67 |
bool ok = false;
|
|
68 |
mLoader->load( BTUI_SEARCHVIEW_DOCML, &ok );
|
|
69 |
// Exit if the file format is invalid
|
|
70 |
BTUI_ASSERT_X( ok, "bt-search-view", "Invalid docml file" );
|
|
71 |
|
|
72 |
// Set title for the control panel
|
|
73 |
// ToDo: check if deprecated API
|
|
74 |
setTitle("Control Panel");
|
|
75 |
|
|
76 |
// assign automatically created widgets to local variables
|
|
77 |
|
|
78 |
mDeviceIcon=0;
|
|
79 |
// can't use qobject_cast since HbIcon is not derived from QObject!
|
57
|
80 |
mDeviceIcon = qobject_cast<HbLabel *>( mLoader->findWidget( "searchIcon" ) );
|
|
81 |
BTUI_ASSERT_X( mDeviceIcon != 0, "BtcpuiSearchView::BtcpuiSearchView", "Device Icon not found" );
|
29
|
82 |
|
47
|
83 |
mDataForm=0;
|
57
|
84 |
mDataForm = qobject_cast<HbDataForm *>( mLoader->findWidget( "searchHeading" ) );
|
|
85 |
BTUI_ASSERT_X( mDataForm != 0, "BtcpuiSearchView::BtcpuiSearchView", "dataForm not found" );
|
47
|
86 |
mDataForm->setHeading(hbTrId("txt_bt_subhead_bluetooth_found_devices"));
|
31
|
87 |
|
|
88 |
mLabelSearching=0;
|
57
|
89 |
mLabelSearching = qobject_cast<HbLabel *>( mLoader->findWidget( "searchStatus" ) );
|
|
90 |
BTUI_ASSERT_X( mLabelSearching != 0, "BtcpuiSearchView::BtcpuiSearchView", "Searching not found" );
|
31
|
91 |
mLabelSearching->setPlainText(hbTrId("txt_bt_subhead_searching"));
|
|
92 |
|
29
|
93 |
mDeviceList=0;
|
|
94 |
mDeviceList = qobject_cast<HbListView *>( mLoader->findWidget( "deviceList" ) );
|
57
|
95 |
BTUI_ASSERT_X( mDeviceList != 0, "BtcpuiSearchView::BtcpuiSearchView", "Device List not found" );
|
29
|
96 |
|
57
|
97 |
ret = connect(mDeviceList,
|
|
98 |
SIGNAL(longPressed(HbAbstractViewItem*, QPointF)), this,
|
|
99 |
SLOT(showContextMenu(HbAbstractViewItem*, QPointF)));
|
67
|
100 |
BTUI_ASSERT_X( ret, "bt-search-view", "showContextMenu can't connect" );
|
57
|
101 |
|
31
|
102 |
mDeviceList->setSelectionMode( HbAbstractItemView::SingleSelection );
|
29
|
103 |
|
|
104 |
// read landscape orientation section from docml file if needed
|
31
|
105 |
mOrientation = mMainWindow->orientation();
|
|
106 |
|
29
|
107 |
if (mOrientation == Qt::Horizontal) {
|
57
|
108 |
mLoader->load(BTUI_SEARCHVIEW_DOCML, "landscape", &ok);
|
|
109 |
BTUI_ASSERT_X( ok, "BtcpuiSearchView::BtcpuiSearchView", "Invalid docml file: landscape section problem" );
|
31
|
110 |
} else {
|
57
|
111 |
mLoader->load(BTUI_SEARCHVIEW_DOCML, "portrait", &ok);
|
|
112 |
BTUI_ASSERT_X( ok, "BtcpuiSearchView::BtcpuiSearchView", "Invalid docml file: portrait section problem" );
|
29
|
113 |
}
|
|
114 |
|
31
|
115 |
// listen for orientation changes
|
|
116 |
ret = connect(mMainWindow, SIGNAL(orientationChanged(Qt::Orientation)),
|
|
117 |
this, SLOT(changeOrientation(Qt::Orientation)));
|
57
|
118 |
BTUI_ASSERT_X( ret, "BtcpuiSearchView::BtcpuiSearchView()", "connect orientationChanged() failed");
|
29
|
119 |
|
|
120 |
// load tool bar actions
|
31
|
121 |
mViewBy = static_cast<HbAction*>( mLoader->findObject( "viewByAction" ) );
|
57
|
122 |
BTUI_ASSERT_X( mViewBy, "BtcpuiSearchView::BtcpuiSearchView", "view by action missing" );
|
42
|
123 |
ret = connect(mViewBy, SIGNAL(triggered()), this, SLOT(viewByDeviceTypeDialog()));
|
57
|
124 |
BTUI_ASSERT_X( ret, "BtcpuiSearchView::BtcpuiSearchView", "viewByAction can't connect" );
|
29
|
125 |
|
31
|
126 |
mStop = static_cast<HbAction*>( mLoader->findObject( "stopAction" ) );
|
57
|
127 |
BTUI_ASSERT_X( mStop, "BtcpuiSearchView::BtcpuiSearchView", "stopAction missing" );
|
31
|
128 |
ret = connect(mStop, SIGNAL(triggered()), this, SLOT(stopSearching()));
|
57
|
129 |
BTUI_ASSERT_X( ret, "BtcpuiSearchView::BtcpuiSearchView", "stopAction can't connect" );
|
31
|
130 |
mStop->setEnabled(true);
|
|
131 |
|
|
132 |
mRetry = static_cast<HbAction*>( mLoader->findObject( "retryAction" ) );
|
57
|
133 |
BTUI_ASSERT_X( mRetry, "BtcpuiSearchView::BtcpuiSearchView", "retryAction missing" );
|
31
|
134 |
ret = connect(mRetry, SIGNAL(triggered()), this, SLOT(retrySearch()));
|
57
|
135 |
BTUI_ASSERT_X( ret, "BtcpuiSearchView::BtcpuiSearchView", "retryAction can't connect" );
|
31
|
136 |
// Disable for initial search
|
|
137 |
mRetry->setEnabled(false);
|
29
|
138 |
|
|
139 |
// load menu
|
|
140 |
HbMenu *optionsMenu = qobject_cast<HbMenu *>(mLoader->findWidget("viewMenu"));
|
57
|
141 |
BTUI_ASSERT_X( optionsMenu != 0, "BtcpuiSearchView::BtcpuiSearchView", "Options menu not found" );
|
31
|
142 |
this->setMenu(optionsMenu);
|
|
143 |
|
67
|
144 |
ret = connect(mDeviceList, SIGNAL(activated(QModelIndex)), this, SLOT(openDeviceView(QModelIndex)));
|
|
145 |
BTUI_ASSERT_X( ret, "BtcpuiSearchView::BtcpuiSearchView", "openDeviceView can't connect" );
|
42
|
146 |
|
57
|
147 |
bool regStatus(false);
|
|
148 |
regStatus = HbStyleLoader::registerFilePath(":/docml/btcpuisearchlistviewitem.widgetml");
|
|
149 |
BTUI_ASSERT_X( regStatus, "BtcpuiSearchView::BtcpuiSearchView", "registerFilePath Widgetml Failed" );
|
|
150 |
regStatus = HbStyleLoader::registerFilePath(":/docml/btcpuisearchlistviewitem.css");
|
|
151 |
BTUI_ASSERT_X( regStatus, "BtcpuiSearchView::BtcpuiSearchView", "registerFilePath CSS Failed" );
|
|
152 |
|
42
|
153 |
// initialize sort model & create
|
|
154 |
// inquiry delegate
|
|
155 |
// Sort is set to dynamic sort filter = true in the class, will sort automatically
|
|
156 |
mBtuiModelSortFilter = new BtuiModelSortFilter(this);
|
|
157 |
mBtuiModelSortFilter->setSourceModel(mDeviceModel);
|
|
158 |
mBtuiModelSortFilter->addDeviceMajorFilter(
|
|
159 |
BtuiDevProperty::InRange, BtuiModelSortFilter::AtLeastMatch);
|
|
160 |
mDeviceList->setModel(mBtuiModelSortFilter);
|
57
|
161 |
mDeviceList->setLayoutName("custom-list");
|
42
|
162 |
// add sort order to show devices in the order they are found
|
|
163 |
mBtuiModelSortFilter->setSortRole(BtDeviceModel::SeqNumRole);
|
|
164 |
// Sort according to the first column (and the only column) in the listview - sorted according SeqNumRole
|
|
165 |
mBtuiModelSortFilter->sort(0, Qt::AscendingOrder);
|
|
166 |
|
|
167 |
BtCpUiSearchListViewItem *prototype = new BtCpUiSearchListViewItem(mDeviceList);
|
|
168 |
prototype->setModelSortFilter(mBtuiModelSortFilter);
|
|
169 |
mDeviceList->setItemPrototype(prototype);
|
29
|
170 |
}
|
|
171 |
|
57
|
172 |
BtcpuiSearchView::~BtcpuiSearchView()
|
29
|
173 |
{
|
42
|
174 |
delete mLoader; // Also deletes all widgets that it constructed.
|
57
|
175 |
delete mBtuiModelSortFilter;
|
67
|
176 |
delete mSecondaryDelegate;
|
57
|
177 |
HbStyleLoader::unregisterFilePath(":/docml/btcpuisearchlistviewitem.widgetml");
|
|
178 |
HbStyleLoader::unregisterFilePath(":/docml/btcpuisearchlistviewitem.css");
|
31
|
179 |
}
|
|
180 |
|
57
|
181 |
void BtcpuiSearchView::changeOrientation( Qt::Orientation orientation )
|
31
|
182 |
{
|
42
|
183 |
// ToDo: this does not handle redrawing list view items differently for portrait/landscape
|
31
|
184 |
bool ok = false;
|
|
185 |
mOrientation = orientation;
|
42
|
186 |
|
31
|
187 |
if( orientation == Qt::Vertical ) {
|
|
188 |
// load "portrait" section
|
57
|
189 |
mLoader->load( BTUI_SEARCHVIEW_DOCML, "portrait", &ok );
|
|
190 |
BTUI_ASSERT_X( ok, "BtcpuiSearchView::changeOrientation", "Invalid docml file: portrait section problem" );
|
31
|
191 |
} else {
|
|
192 |
// load "landscape" section
|
57
|
193 |
mLoader->load( BTUI_SEARCHVIEW_DOCML, "landscape", &ok );
|
|
194 |
BTUI_ASSERT_X( ok, "BtcpuiSearchView::changeOrientation", "Invalid docml file: landscape section problem" );
|
31
|
195 |
}
|
29
|
196 |
}
|
|
197 |
|
42
|
198 |
/*!
|
|
199 |
Callback for HbSelectionDialog closing
|
57
|
200 |
ReImplemented Slot from Base class
|
42
|
201 |
|
|
202 |
*/
|
57
|
203 |
void BtcpuiSearchView::viewByDialogClosed(HbAction* action)
|
|
204 |
{
|
|
205 |
int devTypesWanted = 0;
|
|
206 |
|
|
207 |
devTypesWanted = selectedDeviceTypes(action);
|
|
208 |
|
|
209 |
if (devTypesWanted) {
|
|
210 |
mBtuiModelSortFilter->clearDeviceMajorFilters();
|
|
211 |
mBtuiModelSortFilter->addDeviceMajorFilter(BtuiDevProperty::InRange,
|
|
212 |
BtuiModelSortFilter::AtLeastMatch); // device must be in range
|
|
213 |
mBtuiModelSortFilter->addDeviceMajorFilter(devTypesWanted,
|
|
214 |
BtuiModelSortFilter::RoughMatch); // device can be any one of selected ones
|
|
215 |
}
|
|
216 |
}
|
|
217 |
|
|
218 |
void BtcpuiSearchView::stopSearching()
|
42
|
219 |
{
|
57
|
220 |
// Stop searching
|
|
221 |
if (mDelegate) {
|
|
222 |
mDelegate->cancel();
|
|
223 |
// update the states of view items
|
|
224 |
deviceSearchCompleted(KErrNone);
|
|
225 |
}
|
|
226 |
}
|
|
227 |
|
|
228 |
void BtcpuiSearchView::take(BtAbstractDelegate *delegate)
|
|
229 |
{
|
|
230 |
mDelegate = delegate;
|
|
231 |
if (mDelegate) {
|
|
232 |
disconnect(mDelegate, 0, 0, 0);
|
|
233 |
if (mDelegate->supportedEditorTypes() & BtDelegate::Inquiry) {
|
|
234 |
connect(mDelegate, SIGNAL(delegateCompleted(int,BtAbstractDelegate*)),
|
|
235 |
this, SLOT(deviceSearchCompleted(int)));
|
|
236 |
} else {
|
|
237 |
connect(mDelegate, SIGNAL(delegateCompleted(int,BtAbstractDelegate*)),
|
|
238 |
this, SLOT(handleDelegateCompleted(int)));
|
42
|
239 |
}
|
|
240 |
}
|
|
241 |
}
|
|
242 |
|
57
|
243 |
void BtcpuiSearchView::startSearchDelegate()
|
29
|
244 |
{
|
57
|
245 |
(void) createExecuteDelegate(BtDelegate::Inquiry,
|
|
246 |
this, SLOT(deviceSearchCompleted(int)), QVariant());
|
31
|
247 |
}
|
|
248 |
|
57
|
249 |
void BtcpuiSearchView::retrySearch()
|
31
|
250 |
{
|
42
|
251 |
// Retry search
|
31
|
252 |
// Change label and buttons to reflect status
|
|
253 |
mLabelSearching->setPlainText(hbTrId("txt_bt_subhead_searching"));
|
|
254 |
mRetry->setEnabled(false);
|
|
255 |
mStop->setEnabled(true);
|
|
256 |
|
|
257 |
// Make use of the delegate and start the search.
|
57
|
258 |
startSearchDelegate();
|
29
|
259 |
}
|
|
260 |
|
57
|
261 |
void BtcpuiSearchView::activateView( const QVariant& value, bool backNavi)
|
29
|
262 |
{
|
|
263 |
Q_UNUSED(value);
|
57
|
264 |
if (!backNavi) {
|
|
265 |
retrySearch();
|
|
266 |
}
|
|
267 |
|
42
|
268 |
// ToDo: consider whether orientation should be updated here rather than when orientation really changes;
|
|
269 |
// advantage: if orientation changes temporarily in another view, but returns to previous setting before
|
|
270 |
// search is reactived, there is no processing overhead
|
29
|
271 |
}
|
|
272 |
|
57
|
273 |
void BtcpuiSearchView::deactivateView()
|
29
|
274 |
{
|
57
|
275 |
stopSearching();
|
29
|
276 |
}
|
57
|
277 |
void BtcpuiSearchView::deviceSearchCompleted(int error)
|
31
|
278 |
{
|
|
279 |
Q_UNUSED(error);
|
|
280 |
mLabelSearching->setPlainText(hbTrId("txt_bt_subhead_search_done"));
|
|
281 |
mRetry->setEnabled(true);
|
47
|
282 |
mStop->setEnabled(false);
|
57
|
283 |
handleDelegateCompleted(error, mDelegate);
|
31
|
284 |
}
|
|
285 |
|
57
|
286 |
void BtcpuiSearchView::createContextMenuActions(int majorRole)
|
31
|
287 |
{
|
57
|
288 |
if (majorRole & BtuiDevProperty::Connected) {
|
|
289 |
if(majorRole & BtuiDevProperty::AVDev) {
|
|
290 |
mContextMenu->addAction(hbTrId("txt_bt_menu_disconnect_audio"));
|
|
291 |
}
|
|
292 |
else {
|
|
293 |
mContextMenu->addAction(hbTrId("txt_bt_menu_disconnect"));
|
|
294 |
}
|
|
295 |
}
|
|
296 |
else {
|
|
297 |
if(majorRole & BtuiDevProperty::AVDev) {
|
|
298 |
mContextMenu->addAction(hbTrId("txt_bt_menu_connect_audio"));
|
|
299 |
}
|
|
300 |
else {
|
|
301 |
mContextMenu->addAction(hbTrId("txt_bt_menu_connect"));
|
|
302 |
}
|
|
303 |
}
|
31
|
304 |
}
|
67
|
305 |
|
|
306 |
void BtcpuiSearchView::connectToDevice(const QModelIndex& modelIndex)
|
|
307 |
{
|
|
308 |
BOstraceFunctionEntry1( DUMMY_DEVLIST, this );
|
|
309 |
|
|
310 |
bool ok(false);
|
|
311 |
if(!mSecondaryDelegate) {
|
|
312 |
mSecondaryDelegate = BtDelegateFactory::newDelegate(
|
|
313 |
BtDelegate::ConnectService, mSettingModel, mDeviceModel);
|
|
314 |
ok = connect(mSecondaryDelegate,
|
|
315 |
SIGNAL(delegateCompleted(int,BtAbstractDelegate*)), this,
|
|
316 |
SLOT(secondaryDelegateCompleted(int,BtAbstractDelegate*)));
|
|
317 |
BOstraceExt1(TRACE_DEBUG, DUMMY_DEVLIST, "BtcpuiSearchView::connectToDevice signal connect %d", ok);
|
|
318 |
if (!ok) {
|
|
319 |
delete mSecondaryDelegate;
|
|
320 |
mSecondaryDelegate = 0;
|
|
321 |
}
|
|
322 |
else {
|
|
323 |
QModelIndex index = mBtuiModelSortFilter->mapToSource(modelIndex);
|
|
324 |
QVariant param;
|
|
325 |
param.setValue(index);
|
|
326 |
mSecondaryDelegate->exec(param);
|
|
327 |
}
|
|
328 |
}
|
|
329 |
|
|
330 |
BOstraceFunctionExit0(DUMMY_DEVLIST);
|
|
331 |
}
|
|
332 |
|
|
333 |
void BtcpuiSearchView::secondaryDelegateCompleted(int error, BtAbstractDelegate* delegate)
|
|
334 |
{
|
|
335 |
BOstraceFunctionEntryExt( DUMMY_DEVLIST, this, error );
|
|
336 |
Q_UNUSED(error);
|
|
337 |
Q_UNUSED(delegate);
|
|
338 |
|
|
339 |
delete mSecondaryDelegate;
|
|
340 |
mSecondaryDelegate = 0;
|
|
341 |
BOstraceFunctionExit0(DUMMY_DEVLIST);
|
|
342 |
}
|
|
343 |
|
|
344 |
void BtcpuiSearchView::disconnectFromDevice(const QModelIndex& modelIndex)
|
|
345 |
{
|
|
346 |
BOstraceFunctionEntry1( DUMMY_DEVLIST, this );
|
|
347 |
|
|
348 |
bool ok(false);
|
|
349 |
if(!mSecondaryDelegate) {
|
|
350 |
mSecondaryDelegate = BtDelegateFactory::newDelegate(
|
|
351 |
BtDelegate::DisconnectService, mSettingModel, mDeviceModel);
|
|
352 |
ok = connect(mSecondaryDelegate,
|
|
353 |
SIGNAL(delegateCompleted(int,BtAbstractDelegate*)), this,
|
|
354 |
SLOT(secondaryDelegateCompleted(int,BtAbstractDelegate*)));
|
|
355 |
BOstraceExt1(TRACE_DEBUG, DUMMY_DEVLIST, "BtcpuiSearchView::connectToDevice signal connect %d", ok);
|
|
356 |
if (!ok) {
|
|
357 |
delete mSecondaryDelegate;
|
|
358 |
mSecondaryDelegate = 0;
|
|
359 |
}
|
|
360 |
else {
|
|
361 |
QModelIndex index = mBtuiModelSortFilter->mapToSource(modelIndex);
|
|
362 |
QVariant deviceBtAddress = mDeviceModel->data(index, BtDeviceModel::ReadableBdaddrRole);
|
|
363 |
|
|
364 |
QList<QVariant>paramList;
|
|
365 |
paramList.append(QVariant(ServiceLevel));
|
|
366 |
paramList.append(deviceBtAddress);
|
|
367 |
|
|
368 |
mSecondaryDelegate->exec(paramList);
|
|
369 |
}
|
|
370 |
}
|
|
371 |
BOstraceFunctionExit0(DUMMY_DEVLIST);
|
|
372 |
}
|