29
|
1 |
/*
|
31
|
2 |
* Copyright (c) 2009-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: BtCpUiMainView implementation
|
|
15 |
*
|
|
16 |
*/
|
|
17 |
|
|
18 |
#include "btcpuimainview.h"
|
31
|
19 |
#include "btuiviewutil.h"
|
29
|
20 |
#include <QtGlobal>
|
|
21 |
#include <QGraphicsLinearLayout>
|
|
22 |
#include <HbInstance>
|
|
23 |
#include <hbdocumentloader.h>
|
|
24 |
#include <hbnotificationdialog.h>
|
|
25 |
#include <hbgridview.h>
|
31
|
26 |
#include <hblistview.h>
|
29
|
27 |
#include <hbpushbutton.h>
|
|
28 |
#include <hblabel.h>
|
|
29 |
#include <hbicon.h>
|
|
30 |
#include <hblineedit.h>
|
|
31 |
#include <hbtooltip.h>
|
|
32 |
#include <btengconstants.h>
|
|
33 |
#include <hbmenu.h>
|
|
34 |
#include <hbaction.h>
|
|
35 |
#include <hbcombobox.h>
|
|
36 |
#include "btcpuisearchview.h"
|
31
|
37 |
#include "btcpuideviceview.h"
|
29
|
38 |
#include <bluetoothuitrace.h>
|
|
39 |
#include <btdelegatefactory.h>
|
|
40 |
#include <btabstractdelegate.h>
|
|
41 |
#include "btqtconstants.h"
|
|
42 |
|
|
43 |
|
|
44 |
// docml to load
|
|
45 |
const char* BTUI_MAINVIEW_DOCML = ":/docml/bt-main-view.docml";
|
|
46 |
|
|
47 |
/*!
|
|
48 |
Constructs a new BtUiMainView using HBDocumentLoader. Docml (basically xml) file
|
|
49 |
has been generated using Application Designer.
|
|
50 |
|
|
51 |
*/
|
31
|
52 |
BtCpUiMainView::BtCpUiMainView(
|
|
53 |
BtSettingModel &settingModel,
|
|
54 |
BtDeviceModel &deviceModel,
|
|
55 |
QGraphicsItem *parent )
|
|
56 |
: BtCpUiBaseView( settingModel, deviceModel, parent ),
|
|
57 |
mAbstractDelegate(0), mMainFilterModel(0)
|
29
|
58 |
{
|
|
59 |
bool ret(false);
|
|
60 |
|
|
61 |
mMainWindow = hbInstance->allMainWindows().first();
|
|
62 |
mMainView = this;
|
|
63 |
|
|
64 |
// Create view for the application.
|
|
65 |
// Set the name for the view. The name should be same as the view's
|
|
66 |
// name in docml.
|
|
67 |
setObjectName("view");
|
|
68 |
|
|
69 |
QObjectList objectList;
|
|
70 |
objectList.append(this);
|
|
71 |
// Pass the view to documentloader. Document loader uses this view
|
|
72 |
// when docml is parsed, instead of creating new view.
|
|
73 |
mLoader = new HbDocumentLoader();
|
|
74 |
mLoader->setObjectTree(objectList);
|
|
75 |
|
|
76 |
bool ok = false;
|
|
77 |
mLoader->load( BTUI_MAINVIEW_DOCML, &ok );
|
|
78 |
// Exit if the file format is invalid
|
|
79 |
BTUI_ASSERT_X( ok, "bt-main-view", "Invalid docml file" );
|
|
80 |
|
|
81 |
mOrientation = mMainWindow->orientation();
|
|
82 |
|
|
83 |
if (mOrientation == Qt::Horizontal) {
|
|
84 |
mLoader->load(BTUI_MAINVIEW_DOCML, "landscape", &ok);
|
|
85 |
BTUI_ASSERT_X( ok, "bt-main-view", "Invalid docml file: landscape section problem" );
|
|
86 |
}
|
|
87 |
else {
|
|
88 |
mLoader->load(BTUI_MAINVIEW_DOCML, "portrait", &ok);
|
|
89 |
BTUI_ASSERT_X( ok, "bt-main-view", "Invalid docml file: landscape section problem" );
|
|
90 |
}
|
|
91 |
|
|
92 |
mDeviceNameEdit=0;
|
|
93 |
mDeviceNameEdit = qobject_cast<HbLineEdit *>( mLoader->findWidget( "lineEdit" ) );
|
|
94 |
BTUI_ASSERT_X( mDeviceNameEdit != 0, "bt-main-view", "Device Name not found" );
|
|
95 |
ret = connect(mDeviceNameEdit, SIGNAL(editingFinished ()), this, SLOT(changeBtLocalName()));
|
|
96 |
|
|
97 |
mPowerButton=0;
|
|
98 |
mPowerButton = qobject_cast<HbPushButton *>( mLoader->findWidget( "pushButton" ) );
|
|
99 |
BTUI_ASSERT_X( mPowerButton != 0, "bt-main-view", "power button not found" );
|
|
100 |
ret = connect(mPowerButton, SIGNAL(clicked()), this, SLOT(changePowerState()));
|
|
101 |
BTUI_ASSERT_X( ret, "BtCpUiMainView::BtCpUiMainView", "can't connect power button" );
|
|
102 |
|
|
103 |
mVisibilityMode=0;
|
|
104 |
mVisibilityMode = qobject_cast<HbComboBox *>( mLoader->findWidget( "combobox" ) );
|
|
105 |
BTUI_ASSERT_X( mVisibilityMode != 0, "bt-main-view", "visibility combobox not found" );
|
|
106 |
|
|
107 |
mDeviceList=0;
|
31
|
108 |
mDeviceList = qobject_cast<HbListView *>( mLoader->findWidget( "listView" ) );
|
29
|
109 |
BTUI_ASSERT_X( mDeviceList != 0, "bt-main-view", "Device List (grid view) not found" );
|
|
110 |
|
31
|
111 |
ret = connect(mDeviceList, SIGNAL(activated(QModelIndex)), this, SLOT(deviceSelected(QModelIndex)));
|
|
112 |
BTUI_ASSERT_X( ret, "bt-search-view", "deviceSelected can't connect" );
|
|
113 |
|
29
|
114 |
// listen for orientation changes
|
|
115 |
ret = connect(mMainWindow, SIGNAL(orientationChanged(Qt::Orientation)),
|
|
116 |
this, SLOT(changeOrientation(Qt::Orientation)));
|
|
117 |
BTUI_ASSERT_X( ret, "BtCpUiMainView::BtCpUiMainView()", "connect orientationChanged() failed");
|
|
118 |
|
|
119 |
// load tool bar actions
|
|
120 |
HbAction *discoverAction = static_cast<HbAction*>( mLoader->findObject( "discoverAction" ) );
|
|
121 |
BTUI_ASSERT_X( discoverAction, "bt-main-view", "discover action missing" );
|
|
122 |
ret = connect(discoverAction, SIGNAL(triggered()), this, SLOT(goToDiscoveryView()));
|
|
123 |
BTUI_ASSERT_X( ret, "bt-main-view", "orientation toggle can't connect" );
|
|
124 |
|
31
|
125 |
//*********************Testing device view START****************************//
|
|
126 |
HbAction *removePairedDevices = static_cast<HbAction*>( mLoader->findObject( "removePairedDevices" ) );
|
|
127 |
BTUI_ASSERT_X( removePairedDevices, "bt-main-view", "remove action missing" );
|
|
128 |
//ret = connect(removePairedDevices, SIGNAL(triggered()), this, SLOT(goToDeviceView()));
|
|
129 |
//BTUI_ASSERT_X( ret, "bt-main-view", "orientation toggle can't connect" );
|
|
130 |
|
|
131 |
|
|
132 |
|
|
133 |
//*********************Testing device view END****************************//
|
|
134 |
|
29
|
135 |
// load menu
|
|
136 |
HbMenu *optionsMenu = qobject_cast<HbMenu *>(mLoader->findWidget("viewMenu"));
|
|
137 |
BTUI_ASSERT_X( optionsMenu != 0, "bt-main-view", "Options menu not found" );
|
|
138 |
this->setMenu(optionsMenu);
|
|
139 |
|
|
140 |
// update display when setting data changed
|
31
|
141 |
ret = connect(mSettingModel, SIGNAL(dataChanged(QModelIndex,QModelIndex)),
|
29
|
142 |
this, SLOT(updateSettingItems(QModelIndex,QModelIndex)));
|
|
143 |
BTUI_ASSERT_X( ret, "BtCpUiMainView::BtCpUiMainView", "can't connect dataChanged" );
|
|
144 |
|
31
|
145 |
QModelIndex top = mSettingModel->index( BtSettingModel::LocalBtNameRow, 0 );
|
|
146 |
QModelIndex bottom = mSettingModel->index( BtSettingModel::AllowedInOfflineRow, 0 );
|
29
|
147 |
// update name, power and visibility rows
|
|
148 |
updateSettingItems( top, bottom );
|
|
149 |
|
|
150 |
//Handle Visibility Change User Interaction
|
|
151 |
ret = connect(mVisibilityMode, SIGNAL(currentIndexChanged (int)),
|
|
152 |
this, SLOT(visibilityChanged (int)));
|
|
153 |
// create other views
|
|
154 |
createViews();
|
|
155 |
mCurrentView = this;
|
|
156 |
mCurrentViewId = MainView;
|
31
|
157 |
|
|
158 |
mMainFilterModel = new BtuiModelSortFilter(this);
|
|
159 |
|
|
160 |
mMainFilterModel->setSourceModel( mDeviceModel );
|
|
161 |
// filter to match only InRegistry devices
|
|
162 |
mMainFilterModel->addDeviceMajorFilter(
|
|
163 |
BtDeviceModel::InRegistry,
|
|
164 |
BtuiModelSortFilter::AtLeastMatch);
|
29
|
165 |
|
31
|
166 |
mDeviceList->setModel(mMainFilterModel);
|
|
167 |
|
|
168 |
|
29
|
169 |
}
|
|
170 |
|
|
171 |
/*!
|
|
172 |
Destructs the BtCpUiMainView.
|
|
173 |
*/
|
|
174 |
BtCpUiMainView::~BtCpUiMainView()
|
|
175 |
{
|
|
176 |
delete mLoader; // Also deletes all widgets that it constructed.
|
31
|
177 |
|
29
|
178 |
mMainWindow->removeView(mSearchView);
|
|
179 |
delete mSearchView;
|
31
|
180 |
|
|
181 |
mMainWindow->removeView(mDeviceView);
|
|
182 |
delete mDeviceView;
|
|
183 |
|
|
184 |
if (mAbstractDelegate) {
|
29
|
185 |
delete mAbstractDelegate;
|
|
186 |
}
|
|
187 |
}
|
|
188 |
|
|
189 |
/*!
|
|
190 |
from base class, initialize the view
|
|
191 |
*/
|
|
192 |
void BtCpUiMainView::activateView(const QVariant& value, int cmdId )
|
|
193 |
{
|
|
194 |
Q_UNUSED(value);
|
|
195 |
Q_UNUSED(cmdId);
|
31
|
196 |
|
29
|
197 |
}
|
|
198 |
|
|
199 |
/*!
|
|
200 |
From base class. Handle resource before the current view is deactivated.
|
|
201 |
*/
|
|
202 |
void BtCpUiMainView::deactivateView()
|
|
203 |
{
|
|
204 |
|
|
205 |
}
|
|
206 |
|
|
207 |
void BtCpUiMainView::itemActivated(QModelIndex index)
|
|
208 |
{
|
|
209 |
Q_UNUSED(index);
|
|
210 |
}
|
|
211 |
|
|
212 |
void BtCpUiMainView::goToDiscoveryView()
|
|
213 |
{
|
|
214 |
changeView( SearchView, false, 0 );
|
|
215 |
}
|
|
216 |
|
31
|
217 |
void BtCpUiMainView::goToDeviceView(const QModelIndex& modelIndex)
|
|
218 |
{
|
|
219 |
//the QModelIndex of the selected device should be given as parameter here
|
|
220 |
QVariant params;
|
|
221 |
params.setValue(modelIndex);
|
|
222 |
changeView( DeviceView, false, 0, params );
|
|
223 |
}
|
|
224 |
|
29
|
225 |
Qt::Orientation BtCpUiMainView::orientation()
|
|
226 |
{
|
|
227 |
return mOrientation;
|
|
228 |
}
|
|
229 |
|
|
230 |
void BtCpUiMainView::changeBtLocalName()
|
|
231 |
{
|
|
232 |
//Error handling has to be done.
|
|
233 |
if (!mAbstractDelegate) {
|
31
|
234 |
mAbstractDelegate = BtDelegateFactory::newDelegate(BtDelegate::DeviceName,
|
|
235 |
mSettingModel, mDeviceModel);
|
29
|
236 |
connect( mAbstractDelegate, SIGNAL(commandCompleted(int,QVariant)), this, SLOT(btNameDelegateCompleted(int,QVariant)) );
|
|
237 |
mAbstractDelegate->exec(mDeviceNameEdit->text ());
|
|
238 |
}
|
|
239 |
else {
|
|
240 |
setPrevBtLocalName();
|
|
241 |
}
|
|
242 |
}
|
|
243 |
|
|
244 |
void BtCpUiMainView::setPrevBtLocalName()
|
|
245 |
{
|
|
246 |
//Should we notify user this as Error...?
|
|
247 |
HbNotificationDialog::launchDialog(hbTrId("Error"));
|
31
|
248 |
QModelIndex index = mSettingModel->index( BtSettingModel::LocalBtNameRow,0 );
|
29
|
249 |
|
31
|
250 |
mDeviceNameEdit->setText( mSettingModel->data(
|
|
251 |
index,BtSettingModel::settingDisplayRole).toString() );
|
29
|
252 |
}
|
|
253 |
|
|
254 |
|
|
255 |
void BtCpUiMainView::btNameDelegateCompleted(int status, QVariant param)
|
|
256 |
{
|
|
257 |
if(KErrNone == status) {
|
|
258 |
mDeviceNameEdit->setText(param.toString());
|
|
259 |
}
|
|
260 |
else {
|
|
261 |
setPrevBtLocalName();
|
|
262 |
}
|
|
263 |
//Error handling has to be done.
|
|
264 |
if (mAbstractDelegate)
|
|
265 |
{
|
|
266 |
disconnect(mAbstractDelegate);
|
|
267 |
delete mAbstractDelegate;
|
|
268 |
mAbstractDelegate = 0;
|
|
269 |
}
|
|
270 |
|
|
271 |
}
|
|
272 |
|
|
273 |
void BtCpUiMainView::visibilityChanged (int index)
|
|
274 |
{
|
|
275 |
QList<QVariant> list;
|
|
276 |
|
|
277 |
VisibilityMode mode = indexToVisibilityMode(index);
|
|
278 |
list.append(QVariant((int)mode));
|
|
279 |
if(BtTemporary == VisibilityMode(mode)) {
|
|
280 |
//Right now hardcoded to 5 Mins.
|
|
281 |
list.append(QVariant(5));
|
|
282 |
}
|
|
283 |
//Error handling has to be done.
|
|
284 |
if (!mAbstractDelegate) {
|
31
|
285 |
mAbstractDelegate = BtDelegateFactory::newDelegate(BtDelegate::Visibility,
|
|
286 |
mSettingModel, mDeviceModel);
|
29
|
287 |
connect( mAbstractDelegate, SIGNAL(commandCompleted(int)), this, SLOT(visibilityDelegateCompleted(int)) );
|
|
288 |
mAbstractDelegate->exec(list);
|
|
289 |
}
|
|
290 |
else {
|
|
291 |
setPrevVisibilityMode();
|
|
292 |
}
|
|
293 |
|
|
294 |
}
|
|
295 |
|
|
296 |
void BtCpUiMainView::setPrevVisibilityMode()
|
|
297 |
{
|
|
298 |
bool ret(false);
|
|
299 |
|
|
300 |
//Should we notify this error to user..?
|
|
301 |
HbNotificationDialog::launchDialog(hbTrId("Error"));
|
31
|
302 |
QModelIndex index = mSettingModel->index( BtSettingModel::VisibilityRow, 0 );
|
29
|
303 |
|
|
304 |
ret = disconnect(mVisibilityMode, SIGNAL(currentIndexChanged (int)),
|
|
305 |
this, SLOT(visibilityChanged (int)));
|
|
306 |
BTUI_ASSERT_X( ret, "BtCpUiMainView::setPrevVisibilityMode", "can't disconnect signal" );
|
|
307 |
|
31
|
308 |
mVisibilityMode->setCurrentIndex ( visibilityModeToIndex((VisibilityMode)
|
|
309 |
mSettingModel->data(index,BtSettingModel::SettingValueRole).toInt()) );
|
29
|
310 |
|
|
311 |
//Handle Visibility Change User Interaction
|
|
312 |
ret = connect(mVisibilityMode, SIGNAL(currentIndexChanged (int)),
|
|
313 |
this, SLOT(visibilityChanged (int)));
|
|
314 |
BTUI_ASSERT_X( ret, "BtCpUiMainView::setPrevVisibilityMode", "can't connect signal" );
|
|
315 |
|
|
316 |
}
|
|
317 |
|
|
318 |
|
|
319 |
void BtCpUiMainView::visibilityDelegateCompleted(int status)
|
|
320 |
{
|
|
321 |
|
|
322 |
//This should be mapped to Qt error
|
|
323 |
if(KErrNone != status) {
|
|
324 |
setPrevVisibilityMode();
|
|
325 |
}
|
|
326 |
|
|
327 |
//Error handling has to be done.
|
|
328 |
if (mAbstractDelegate)
|
|
329 |
{
|
|
330 |
disconnect(mAbstractDelegate);
|
|
331 |
delete mAbstractDelegate;
|
|
332 |
mAbstractDelegate = 0;
|
|
333 |
}
|
|
334 |
|
|
335 |
}
|
|
336 |
|
|
337 |
|
|
338 |
// called due to real orientation change event coming from main window
|
|
339 |
void BtCpUiMainView::changeOrientation( Qt::Orientation orientation )
|
|
340 |
{
|
|
341 |
bool ok = false;
|
|
342 |
mOrientation = orientation;
|
|
343 |
if( orientation == Qt::Vertical ) {
|
|
344 |
// load "portrait" section
|
|
345 |
mLoader->load( BTUI_MAINVIEW_DOCML, "portrait", &ok );
|
|
346 |
BTUI_ASSERT_X( ok, "bt-main-view", "Invalid docml file: portrait section problem" );
|
|
347 |
} else {
|
|
348 |
// load "landscape" section
|
|
349 |
mLoader->load( BTUI_MAINVIEW_DOCML, "landscape", &ok );
|
|
350 |
BTUI_ASSERT_X( ok, "bt-main-view", "Invalid docml file: landscape section problem" );
|
|
351 |
}
|
|
352 |
}
|
|
353 |
|
|
354 |
void BtCpUiMainView::commandCompleted( int cmdId, int err, const QString &diagnostic )
|
|
355 |
{
|
|
356 |
Q_UNUSED(cmdId);
|
|
357 |
Q_UNUSED(err);
|
|
358 |
Q_UNUSED(diagnostic);
|
|
359 |
|
|
360 |
}
|
|
361 |
|
|
362 |
/*!
|
31
|
363 |
Slot for receiving notification of local setting changes from the model.
|
29
|
364 |
Identify the setting changed and update the corresponding UI item.
|
|
365 |
*/
|
|
366 |
void BtCpUiMainView::updateSettingItems(const QModelIndex &topLeft, const QModelIndex &bottomRight)
|
|
367 |
{
|
|
368 |
|
|
369 |
// update only the part of the view specified by the model's row(s)
|
31
|
370 |
for (int i=topLeft.row(); i <= bottomRight.row(); i++) {
|
|
371 |
QModelIndex index = mSettingModel->index( i, 0);
|
29
|
372 |
// Distinguish which setting value is changed.
|
|
373 |
switch ( i ) {
|
31
|
374 |
case BtSettingModel::LocalBtNameRow :
|
|
375 |
mDeviceNameEdit->setText(
|
|
376 |
mSettingModel->data(index,BtSettingModel::settingDisplayRole).toString() );
|
29
|
377 |
break;
|
31
|
378 |
case BtSettingModel::PowerStateRow:
|
|
379 |
mPowerButton->setText( mSettingModel->data(index,
|
|
380 |
BtSettingModel::settingDisplayRole).toString() );
|
29
|
381 |
break;
|
31
|
382 |
case BtSettingModel::VisibilityRow:
|
29
|
383 |
mVisibilityMode->setCurrentIndex ( visibilityModeToIndex((VisibilityMode)
|
31
|
384 |
mSettingModel->data(index,BtSettingModel::SettingValueRole).toInt()) );
|
29
|
385 |
break;
|
|
386 |
}
|
31
|
387 |
}
|
29
|
388 |
}
|
|
389 |
|
|
390 |
/*!
|
|
391 |
Slot for receiving notification for user interaction on power state.
|
|
392 |
Manually update model data since HbPushButton is not linked to model directly.
|
|
393 |
*/
|
|
394 |
void BtCpUiMainView::changePowerState()
|
|
395 |
{
|
|
396 |
|
31
|
397 |
QModelIndex index = mSettingModel->index(BtSettingModel::PowerStateRow, 0);
|
|
398 |
QVariant powerState = mSettingModel->data(index, Qt::EditRole);
|
29
|
399 |
if (!mAbstractDelegate)//if there is no other delegate running
|
|
400 |
{
|
31
|
401 |
mAbstractDelegate = BtDelegateFactory::newDelegate(BtDelegate::ManagePower,
|
|
402 |
mSettingModel, mDeviceModel );
|
29
|
403 |
connect( mAbstractDelegate, SIGNAL(commandCompleted(int)), this, SLOT(powerDelegateCompleted(int)) );
|
|
404 |
mAbstractDelegate->exec(powerState);
|
|
405 |
}
|
|
406 |
|
|
407 |
}
|
|
408 |
|
|
409 |
void BtCpUiMainView::powerDelegateCompleted(int status)
|
|
410 |
{
|
|
411 |
Q_UNUSED(status);
|
|
412 |
//ToDo: Error handling here
|
|
413 |
if (mAbstractDelegate)
|
|
414 |
{
|
|
415 |
disconnect(mAbstractDelegate);
|
|
416 |
delete mAbstractDelegate;
|
|
417 |
mAbstractDelegate = 0;
|
|
418 |
}
|
|
419 |
//BTUI_ASSERT_X( status, "bt-main-view", "error in delegate complete" );
|
|
420 |
}
|
|
421 |
|
|
422 |
/*!
|
|
423 |
* Mapping from visibility mode UI row to VisibilityMode
|
|
424 |
*/
|
|
425 |
VisibilityMode BtCpUiMainView::indexToVisibilityMode(int index)
|
|
426 |
{
|
|
427 |
VisibilityMode mode;
|
|
428 |
switch(index) {
|
|
429 |
case UiRowBtHidden:
|
|
430 |
mode = BtHidden;
|
|
431 |
break;
|
|
432 |
case UiRowBtVisible:
|
|
433 |
mode = BtVisible;
|
|
434 |
break;
|
|
435 |
case UiRowBtTemporary:
|
|
436 |
mode = BtTemporary;
|
|
437 |
break;
|
|
438 |
default:
|
|
439 |
mode = BtUnknown;
|
|
440 |
}
|
|
441 |
return mode;
|
|
442 |
}
|
|
443 |
|
|
444 |
/*!
|
|
445 |
* Mapping from VisibilityMode to visibility mode UI row
|
|
446 |
*/
|
|
447 |
int BtCpUiMainView::visibilityModeToIndex(VisibilityMode mode)
|
|
448 |
{
|
|
449 |
int uiRow;
|
|
450 |
switch(mode) {
|
|
451 |
case BtHidden:
|
|
452 |
uiRow = UiRowBtHidden;
|
|
453 |
break;
|
|
454 |
case BtVisible:
|
|
455 |
uiRow = UiRowBtVisible;
|
|
456 |
break;
|
|
457 |
case BtTemporary:
|
|
458 |
uiRow = UiRowBtTemporary;
|
|
459 |
break;
|
|
460 |
default:
|
|
461 |
uiRow = -1; // error
|
|
462 |
}
|
|
463 |
return uiRow;
|
|
464 |
}
|
|
465 |
//////////////////////
|
|
466 |
//
|
|
467 |
// from view manager
|
|
468 |
//
|
|
469 |
//////////////////////
|
|
470 |
|
|
471 |
/*!
|
|
472 |
Create views(main view, device view and search view).
|
|
473 |
Add them to MainWindow. All views are long-lived and are deleted only when exiting the application
|
|
474 |
(or when main view is deleted).
|
|
475 |
*/
|
|
476 |
void BtCpUiMainView::createViews()
|
|
477 |
{
|
|
478 |
Qt::Orientation orientation = mMainWindow->orientation();
|
|
479 |
// Create other views
|
31
|
480 |
mSearchView = new BtCpUiSearchView( *mSettingModel, *mDeviceModel, this );
|
29
|
481 |
mMainWindow->addView(mSearchView);
|
31
|
482 |
|
|
483 |
mDeviceView = new BtCpUiDeviceView( *mSettingModel, *mDeviceModel, this );
|
|
484 |
mMainWindow->addView(mDeviceView);
|
29
|
485 |
|
|
486 |
mCurrentView = this;
|
|
487 |
mCurrentViewId = MainView;
|
|
488 |
|
|
489 |
|
|
490 |
// QList<int> stores the previous view ids for each view.
|
|
491 |
for( int i=0; i < LastView; i++ ) {
|
|
492 |
mPreviousViewIds.append( 0 );
|
|
493 |
}
|
|
494 |
}
|
|
495 |
|
|
496 |
/*!
|
|
497 |
Switch between the views.
|
|
498 |
Parameter cmdId is used for automatically executing command.
|
|
499 |
Parameter "value" is optional except for GadgetView,
|
|
500 |
which needs the BT address (QString)
|
|
501 |
*/
|
|
502 |
void BtCpUiMainView::changeView(int targetViewId, bool fromBackButton,
|
|
503 |
int cmdId, const QVariant& value )
|
|
504 |
{
|
|
505 |
mCurrentView->deactivateView();
|
|
506 |
|
|
507 |
// update the previous view Id in QList<int>
|
|
508 |
// If launching the target view from back softkey,
|
|
509 |
// the previous viewId of target view should not be changed.
|
|
510 |
// Otherwise, loop happens between two views.
|
|
511 |
if(!fromBackButton) {
|
|
512 |
if ((targetViewId == DeviceView) && (mCurrentViewId == SearchView)) {
|
|
513 |
// we don't want to return to search view after e.g. pairing a new device
|
|
514 |
mPreviousViewIds[ targetViewId ] = MainView;
|
|
515 |
}
|
|
516 |
else {
|
|
517 |
// normal case: return to previous view
|
|
518 |
mPreviousViewIds[ targetViewId ] = mCurrentViewId;
|
|
519 |
}
|
|
520 |
}
|
|
521 |
|
|
522 |
// set the new current view
|
|
523 |
mCurrentView = idToView(targetViewId);
|
|
524 |
mCurrentViewId = targetViewId;
|
|
525 |
mMainWindow->setCurrentView( mCurrentView );
|
|
526 |
|
|
527 |
// do preparation or some actions when new view is activated
|
|
528 |
mCurrentView->activateView( value, cmdId );
|
|
529 |
}
|
|
530 |
|
|
531 |
|
31
|
532 |
void BtCpUiMainView::deviceSelected(const QModelIndex& modelIndex)
|
|
533 |
{
|
|
534 |
QModelIndex index = mMainFilterModel->mapToSource(modelIndex);
|
|
535 |
|
|
536 |
QVariant params;
|
|
537 |
params.setValue(index);
|
|
538 |
|
|
539 |
changeView( DeviceView, false, 0, params );
|
|
540 |
}
|
|
541 |
|
29
|
542 |
BtCpUiBaseView * BtCpUiMainView::idToView(int targetViewId)
|
|
543 |
{
|
|
544 |
switch (targetViewId) {
|
|
545 |
case MainView:
|
|
546 |
return mMainView;
|
|
547 |
case SearchView:
|
|
548 |
return mSearchView;
|
|
549 |
case DeviceView:
|
|
550 |
return mDeviceView;
|
|
551 |
default :
|
|
552 |
BTUI_ASSERT_X(false, "BtCpUiMainView::idToView", "invalid view id");
|
|
553 |
}
|
|
554 |
return 0;
|
|
555 |
}
|
|
556 |
|
|
557 |
/*
|
|
558 |
Jump to previous view. This function is used when back button is pressed.
|
|
559 |
*/
|
|
560 |
void BtCpUiMainView::switchToPreviousViewReally()
|
|
561 |
{
|
31
|
562 |
// // jump to previous view of current view.
|
|
563 |
// if( (mCurrentViewId >= 0) && (mCurrentViewId < LastView)) {
|
|
564 |
// changeView( mPreviousViewIds[mCurrentViewId], true, 0 );
|
|
565 |
// }
|
|
566 |
// else {
|
|
567 |
// BTUI_ASSERT_X(false, "BtCpUiMainView::switchToPreviousViewReally", "invalid view id");
|
|
568 |
// }
|
29
|
569 |
}
|
|
570 |
|
|
571 |
|
|
572 |
void BtCpUiMainView::setSoftkeyBack()
|
|
573 |
{
|
|
574 |
|
|
575 |
}
|
|
576 |
|
31
|
577 |
/*!
|
|
578 |
Jump to previous view. This function is used when back button is pressed.
|
|
579 |
semantics slightly different than in other views, since this is called by other
|
|
580 |
views when a view switch is needed
|
|
581 |
*/
|
29
|
582 |
void BtCpUiMainView::switchToPreviousView()
|
|
583 |
{
|
31
|
584 |
// jump to previous view of current view.
|
|
585 |
if( (mCurrentViewId >= 0) && (mCurrentViewId < LastView)) {
|
|
586 |
changeView( mPreviousViewIds[mCurrentViewId], true, 0 );
|
|
587 |
}
|
|
588 |
else {
|
|
589 |
BTUI_ASSERT_X(false, "BtCpUiMainView::switchToPreviousView", "invalid view id");
|
|
590 |
}
|
29
|
591 |
}
|
|
592 |
|