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