14 * Description: BtCpUiMainView implementation |
14 * Description: BtCpUiMainView implementation |
15 * |
15 * |
16 */ |
16 */ |
17 |
17 |
18 #include "btcpuimainview.h" |
18 #include "btcpuimainview.h" |
|
19 #include "btuiviewutil.h" |
19 #include <QtGlobal> |
20 #include <QtGlobal> |
20 #include <QGraphicsLinearLayout> |
21 #include <QGraphicsLinearLayout> |
21 #include <HbInstance> |
22 #include <HbInstance> |
22 //#include "btuiviewutil.h" |
|
23 #include <hbdocumentloader.h> |
23 #include <hbdocumentloader.h> |
24 #include <hbnotificationdialog.h> |
24 #include <hbnotificationdialog.h> |
25 #include <hbgridview.h> |
25 #include <hbgridview.h> |
|
26 #include <hblistview.h> |
26 #include <hbpushbutton.h> |
27 #include <hbpushbutton.h> |
27 #include <hblabel.h> |
28 #include <hblabel.h> |
28 #include <hbicon.h> |
29 #include <hbicon.h> |
29 #include <hblineedit.h> |
30 #include <hblineedit.h> |
30 #include <hbtooltip.h> |
31 #include <hbtooltip.h> |
31 #include <btengconstants.h> |
32 #include <btengconstants.h> |
32 #include <hbmenu.h> |
33 #include <hbmenu.h> |
33 #include <hbaction.h> |
34 #include <hbaction.h> |
34 #include <hbcombobox.h> |
35 #include <hbcombobox.h> |
35 #include "btcpuisearchview.h" |
36 #include "btcpuisearchview.h" |
|
37 #include "btcpuideviceview.h" |
36 #include <bluetoothuitrace.h> |
38 #include <bluetoothuitrace.h> |
37 #include <btdelegatefactory.h> |
39 #include <btdelegatefactory.h> |
38 #include <btabstractdelegate.h> |
40 #include <btabstractdelegate.h> |
39 #include "btqtconstants.h" |
41 #include "btqtconstants.h" |
40 |
42 |
45 /*! |
47 /*! |
46 Constructs a new BtUiMainView using HBDocumentLoader. Docml (basically xml) file |
48 Constructs a new BtUiMainView using HBDocumentLoader. Docml (basically xml) file |
47 has been generated using Application Designer. |
49 has been generated using Application Designer. |
48 |
50 |
49 */ |
51 */ |
50 BtCpUiMainView::BtCpUiMainView( BtuiModel &model, QGraphicsItem *parent ) |
52 BtCpUiMainView::BtCpUiMainView( |
51 : BtCpUiBaseView( model, parent ), mAbstractDelegate(0) |
53 BtSettingModel &settingModel, |
|
54 BtDeviceModel &deviceModel, |
|
55 QGraphicsItem *parent ) |
|
56 : BtCpUiBaseView( settingModel, deviceModel, parent ), |
|
57 mAbstractDelegate(0), mMainFilterModel(0) |
52 { |
58 { |
53 bool ret(false); |
59 bool ret(false); |
54 |
60 |
55 mMainWindow = hbInstance->allMainWindows().first(); |
61 mMainWindow = hbInstance->allMainWindows().first(); |
56 mMainView = this; |
62 mMainView = this; |
97 mVisibilityMode=0; |
103 mVisibilityMode=0; |
98 mVisibilityMode = qobject_cast<HbComboBox *>( mLoader->findWidget( "combobox" ) ); |
104 mVisibilityMode = qobject_cast<HbComboBox *>( mLoader->findWidget( "combobox" ) ); |
99 BTUI_ASSERT_X( mVisibilityMode != 0, "bt-main-view", "visibility combobox not found" ); |
105 BTUI_ASSERT_X( mVisibilityMode != 0, "bt-main-view", "visibility combobox not found" ); |
100 |
106 |
101 mDeviceList=0; |
107 mDeviceList=0; |
102 mDeviceList = qobject_cast<HbGridView *>( mLoader->findWidget( "gridView" ) ); |
108 mDeviceList = qobject_cast<HbListView *>( mLoader->findWidget( "listView" ) ); |
103 BTUI_ASSERT_X( mDeviceList != 0, "bt-main-view", "Device List (grid view) not found" ); |
109 BTUI_ASSERT_X( mDeviceList != 0, "bt-main-view", "Device List (grid view) not found" ); |
|
110 |
|
111 ret = connect(mDeviceList, SIGNAL(activated(QModelIndex)), this, SLOT(deviceSelected(QModelIndex))); |
|
112 BTUI_ASSERT_X( ret, "bt-search-view", "deviceSelected can't connect" ); |
104 |
113 |
105 // listen for orientation changes |
114 // listen for orientation changes |
106 ret = connect(mMainWindow, SIGNAL(orientationChanged(Qt::Orientation)), |
115 ret = connect(mMainWindow, SIGNAL(orientationChanged(Qt::Orientation)), |
107 this, SLOT(changeOrientation(Qt::Orientation))); |
116 this, SLOT(changeOrientation(Qt::Orientation))); |
108 BTUI_ASSERT_X( ret, "BtCpUiMainView::BtCpUiMainView()", "connect orientationChanged() failed"); |
117 BTUI_ASSERT_X( ret, "BtCpUiMainView::BtCpUiMainView()", "connect orientationChanged() failed"); |
111 HbAction *discoverAction = static_cast<HbAction*>( mLoader->findObject( "discoverAction" ) ); |
120 HbAction *discoverAction = static_cast<HbAction*>( mLoader->findObject( "discoverAction" ) ); |
112 BTUI_ASSERT_X( discoverAction, "bt-main-view", "discover action missing" ); |
121 BTUI_ASSERT_X( discoverAction, "bt-main-view", "discover action missing" ); |
113 ret = connect(discoverAction, SIGNAL(triggered()), this, SLOT(goToDiscoveryView())); |
122 ret = connect(discoverAction, SIGNAL(triggered()), this, SLOT(goToDiscoveryView())); |
114 BTUI_ASSERT_X( ret, "bt-main-view", "orientation toggle can't connect" ); |
123 BTUI_ASSERT_X( ret, "bt-main-view", "orientation toggle can't connect" ); |
115 |
124 |
|
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 |
116 // load menu |
135 // load menu |
117 HbMenu *optionsMenu = qobject_cast<HbMenu *>(mLoader->findWidget("viewMenu")); |
136 HbMenu *optionsMenu = qobject_cast<HbMenu *>(mLoader->findWidget("viewMenu")); |
118 BTUI_ASSERT_X( optionsMenu != 0, "bt-main-view", "Options menu not found" ); |
137 BTUI_ASSERT_X( optionsMenu != 0, "bt-main-view", "Options menu not found" ); |
119 this->setMenu(optionsMenu); |
138 this->setMenu(optionsMenu); |
120 |
139 |
121 // update display when setting data changed |
140 // update display when setting data changed |
122 ret = connect(&mModel, SIGNAL(dataChanged(QModelIndex,QModelIndex)), |
141 ret = connect(mSettingModel, SIGNAL(dataChanged(QModelIndex,QModelIndex)), |
123 this, SLOT(updateSettingItems(QModelIndex,QModelIndex))); |
142 this, SLOT(updateSettingItems(QModelIndex,QModelIndex))); |
124 BTUI_ASSERT_X( ret, "BtCpUiMainView::BtCpUiMainView", "can't connect dataChanged" ); |
143 BTUI_ASSERT_X( ret, "BtCpUiMainView::BtCpUiMainView", "can't connect dataChanged" ); |
125 |
144 |
126 QModelIndex top = mModel.index( BtuiModel::LocalSettingRow, BtuiModel::BluetoothNameCol ); |
145 QModelIndex top = mSettingModel->index( BtSettingModel::LocalBtNameRow, 0 ); |
127 QModelIndex bottom = mModel.index( BtuiModel::LocalSettingRow, BtuiModel::VisibilityCol ); |
146 QModelIndex bottom = mSettingModel->index( BtSettingModel::AllowedInOfflineRow, 0 ); |
128 // update name, power and visibility rows |
147 // update name, power and visibility rows |
129 updateSettingItems( top, bottom ); |
148 updateSettingItems( top, bottom ); |
130 |
149 |
131 //Handle Visibility Change User Interaction |
150 //Handle Visibility Change User Interaction |
132 ret = connect(mVisibilityMode, SIGNAL(currentIndexChanged (int)), |
151 ret = connect(mVisibilityMode, SIGNAL(currentIndexChanged (int)), |
133 this, SLOT(visibilityChanged (int))); |
152 this, SLOT(visibilityChanged (int))); |
134 // create other views |
153 // create other views |
135 createViews(); |
154 createViews(); |
136 mCurrentView = this; |
155 mCurrentView = this; |
137 mCurrentViewId = MainView; |
156 mCurrentViewId = MainView; |
138 |
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); |
|
165 |
|
166 mDeviceList->setModel(mMainFilterModel); |
|
167 |
|
168 |
139 } |
169 } |
140 |
170 |
141 /*! |
171 /*! |
142 Destructs the BtCpUiMainView. |
172 Destructs the BtCpUiMainView. |
143 */ |
173 */ |
144 BtCpUiMainView::~BtCpUiMainView() |
174 BtCpUiMainView::~BtCpUiMainView() |
145 { |
175 { |
146 delete mLoader; // Also deletes all widgets that it constructed. |
176 delete mLoader; // Also deletes all widgets that it constructed. |
|
177 |
147 mMainWindow->removeView(mSearchView); |
178 mMainWindow->removeView(mSearchView); |
148 delete mSearchView; |
179 delete mSearchView; |
149 if (mAbstractDelegate) |
180 |
150 { |
181 mMainWindow->removeView(mDeviceView); |
|
182 delete mDeviceView; |
|
183 |
|
184 if (mAbstractDelegate) { |
151 delete mAbstractDelegate; |
185 delete mAbstractDelegate; |
152 } |
186 } |
153 } |
187 } |
154 |
188 |
155 /*! |
189 /*! |
178 void BtCpUiMainView::goToDiscoveryView() |
212 void BtCpUiMainView::goToDiscoveryView() |
179 { |
213 { |
180 changeView( SearchView, false, 0 ); |
214 changeView( SearchView, false, 0 ); |
181 } |
215 } |
182 |
216 |
|
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 |
183 Qt::Orientation BtCpUiMainView::orientation() |
225 Qt::Orientation BtCpUiMainView::orientation() |
184 { |
226 { |
185 return mOrientation; |
227 return mOrientation; |
186 } |
228 } |
187 |
229 |
188 void BtCpUiMainView::changeBtLocalName() |
230 void BtCpUiMainView::changeBtLocalName() |
189 { |
231 { |
190 //Error handling has to be done. |
232 //Error handling has to be done. |
191 if (!mAbstractDelegate) { |
233 if (!mAbstractDelegate) { |
192 mAbstractDelegate = BtDelegateFactory::newDelegate(BtDelegate::DeviceName, mModel); |
234 mAbstractDelegate = BtDelegateFactory::newDelegate(BtDelegate::DeviceName, |
|
235 mSettingModel, mDeviceModel); |
193 connect( mAbstractDelegate, SIGNAL(commandCompleted(int,QVariant)), this, SLOT(btNameDelegateCompleted(int,QVariant)) ); |
236 connect( mAbstractDelegate, SIGNAL(commandCompleted(int,QVariant)), this, SLOT(btNameDelegateCompleted(int,QVariant)) ); |
194 mAbstractDelegate->exec(mDeviceNameEdit->text ()); |
237 mAbstractDelegate->exec(mDeviceNameEdit->text ()); |
195 } |
238 } |
196 else { |
239 else { |
197 setPrevBtLocalName(); |
240 setPrevBtLocalName(); |
236 //Right now hardcoded to 5 Mins. |
280 //Right now hardcoded to 5 Mins. |
237 list.append(QVariant(5)); |
281 list.append(QVariant(5)); |
238 } |
282 } |
239 //Error handling has to be done. |
283 //Error handling has to be done. |
240 if (!mAbstractDelegate) { |
284 if (!mAbstractDelegate) { |
241 mAbstractDelegate = BtDelegateFactory::newDelegate(BtDelegate::Visibility, mModel); |
285 mAbstractDelegate = BtDelegateFactory::newDelegate(BtDelegate::Visibility, |
|
286 mSettingModel, mDeviceModel); |
242 connect( mAbstractDelegate, SIGNAL(commandCompleted(int)), this, SLOT(visibilityDelegateCompleted(int)) ); |
287 connect( mAbstractDelegate, SIGNAL(commandCompleted(int)), this, SLOT(visibilityDelegateCompleted(int)) ); |
243 mAbstractDelegate->exec(list); |
288 mAbstractDelegate->exec(list); |
244 } |
289 } |
245 else { |
290 else { |
246 setPrevVisibilityMode(); |
291 setPrevVisibilityMode(); |
252 { |
297 { |
253 bool ret(false); |
298 bool ret(false); |
254 |
299 |
255 //Should we notify this error to user..? |
300 //Should we notify this error to user..? |
256 HbNotificationDialog::launchDialog(hbTrId("Error")); |
301 HbNotificationDialog::launchDialog(hbTrId("Error")); |
257 QModelIndex index = mModel.index( BtuiModel::LocalSettingRow, BtuiModel::VisibilityCol ); |
302 QModelIndex index = mSettingModel->index( BtSettingModel::VisibilityRow, 0 ); |
258 |
303 |
259 ret = disconnect(mVisibilityMode, SIGNAL(currentIndexChanged (int)), |
304 ret = disconnect(mVisibilityMode, SIGNAL(currentIndexChanged (int)), |
260 this, SLOT(visibilityChanged (int))); |
305 this, SLOT(visibilityChanged (int))); |
261 BTUI_ASSERT_X( ret, "BtCpUiMainView::setPrevVisibilityMode", "can't disconnect signal" ); |
306 BTUI_ASSERT_X( ret, "BtCpUiMainView::setPrevVisibilityMode", "can't disconnect signal" ); |
262 |
307 |
263 mVisibilityMode->setCurrentIndex ( visibilityModeToIndex((VisibilityMode) |
308 mVisibilityMode->setCurrentIndex ( visibilityModeToIndex((VisibilityMode) |
264 mModel.data(index,BtuiModel::SettingValue).toInt()) ); |
309 mSettingModel->data(index,BtSettingModel::SettingValueRole).toInt()) ); |
265 |
310 |
266 //Handle Visibility Change User Interaction |
311 //Handle Visibility Change User Interaction |
267 ret = connect(mVisibilityMode, SIGNAL(currentIndexChanged (int)), |
312 ret = connect(mVisibilityMode, SIGNAL(currentIndexChanged (int)), |
268 this, SLOT(visibilityChanged (int))); |
313 this, SLOT(visibilityChanged (int))); |
269 BTUI_ASSERT_X( ret, "BtCpUiMainView::setPrevVisibilityMode", "can't connect signal" ); |
314 BTUI_ASSERT_X( ret, "BtCpUiMainView::setPrevVisibilityMode", "can't connect signal" ); |
313 Q_UNUSED(diagnostic); |
358 Q_UNUSED(diagnostic); |
314 |
359 |
315 } |
360 } |
316 |
361 |
317 /*! |
362 /*! |
318 Slot for receiving notification of data changes from the model. |
363 Slot for receiving notification of local setting changes from the model. |
319 Identify the setting changed and update the corresponding UI item. |
364 Identify the setting changed and update the corresponding UI item. |
320 */ |
365 */ |
321 void BtCpUiMainView::updateSettingItems(const QModelIndex &topLeft, const QModelIndex &bottomRight) |
366 void BtCpUiMainView::updateSettingItems(const QModelIndex &topLeft, const QModelIndex &bottomRight) |
322 { |
367 { |
323 |
368 |
324 // update only the part of the view specified by the model's row(s) |
369 // update only the part of the view specified by the model's row(s) |
325 |
370 for (int i=topLeft.row(); i <= bottomRight.row(); i++) { |
326 for (int i=topLeft.column(); i <= bottomRight.column(); i++) { |
371 QModelIndex index = mSettingModel->index( i, 0); |
327 QModelIndex index = mModel.index( BtuiModel::LocalSettingRow, i); |
|
328 // Distinguish which setting value is changed. |
372 // Distinguish which setting value is changed. |
329 switch ( i ) { |
373 switch ( i ) { |
330 case BtuiModel::BluetoothNameCol : |
374 case BtSettingModel::LocalBtNameRow : |
331 mDeviceNameEdit->setText( mModel.data(index,BtuiModel::settingDisplay).toString() ); |
375 mDeviceNameEdit->setText( |
|
376 mSettingModel->data(index,BtSettingModel::settingDisplayRole).toString() ); |
332 break; |
377 break; |
333 case BtuiModel::PowerStateCol: |
378 case BtSettingModel::PowerStateRow: |
334 mPowerButton->setText( mModel.data(index,BtuiModel::settingDisplay).toString() ); |
379 mPowerButton->setText( mSettingModel->data(index, |
|
380 BtSettingModel::settingDisplayRole).toString() ); |
335 break; |
381 break; |
336 case BtuiModel::VisibilityCol: |
382 case BtSettingModel::VisibilityRow: |
337 mVisibilityMode->setCurrentIndex ( visibilityModeToIndex((VisibilityMode) |
383 mVisibilityMode->setCurrentIndex ( visibilityModeToIndex((VisibilityMode) |
338 mModel.data(index,BtuiModel::SettingValue).toInt()) ); |
384 mSettingModel->data(index,BtSettingModel::SettingValueRole).toInt()) ); |
339 break; |
385 break; |
340 } |
386 } |
341 } |
387 } |
342 |
|
343 |
|
344 } |
388 } |
345 |
389 |
346 /*! |
390 /*! |
347 Slot for receiving notification for user interaction on power state. |
391 Slot for receiving notification for user interaction on power state. |
348 Manually update model data since HbPushButton is not linked to model directly. |
392 Manually update model data since HbPushButton is not linked to model directly. |
349 */ |
393 */ |
350 void BtCpUiMainView::changePowerState() |
394 void BtCpUiMainView::changePowerState() |
351 { |
395 { |
352 |
396 |
353 QModelIndex index = mModel.index(BtuiModel::LocalSettingRow, BtuiModel::PowerStateCol); |
397 QModelIndex index = mSettingModel->index(BtSettingModel::PowerStateRow, 0); |
354 QVariant powerState = mModel.data(index, Qt::EditRole); |
398 QVariant powerState = mSettingModel->data(index, Qt::EditRole); |
355 if (!mAbstractDelegate)//if there is no other delegate running |
399 if (!mAbstractDelegate)//if there is no other delegate running |
356 { |
400 { |
357 mAbstractDelegate = BtDelegateFactory::newDelegate(BtDelegate::ManagePower, mModel); |
401 mAbstractDelegate = BtDelegateFactory::newDelegate(BtDelegate::ManagePower, |
|
402 mSettingModel, mDeviceModel ); |
358 connect( mAbstractDelegate, SIGNAL(commandCompleted(int)), this, SLOT(powerDelegateCompleted(int)) ); |
403 connect( mAbstractDelegate, SIGNAL(commandCompleted(int)), this, SLOT(powerDelegateCompleted(int)) ); |
359 mAbstractDelegate->exec(powerState); |
404 mAbstractDelegate->exec(powerState); |
360 } |
405 } |
361 |
406 |
362 } |
407 } |
500 /* |
557 /* |
501 Jump to previous view. This function is used when back button is pressed. |
558 Jump to previous view. This function is used when back button is pressed. |
502 */ |
559 */ |
503 void BtCpUiMainView::switchToPreviousViewReally() |
560 void BtCpUiMainView::switchToPreviousViewReally() |
504 { |
561 { |
|
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 // } |
|
569 } |
|
570 |
|
571 |
|
572 void BtCpUiMainView::setSoftkeyBack() |
|
573 { |
|
574 |
|
575 } |
|
576 |
|
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 */ |
|
582 void BtCpUiMainView::switchToPreviousView() |
|
583 { |
505 // jump to previous view of current view. |
584 // jump to previous view of current view. |
506 if( (mCurrentViewId >= 0) && (mCurrentViewId < LastView)) { |
585 if( (mCurrentViewId >= 0) && (mCurrentViewId < LastView)) { |
507 changeView( mPreviousViewIds[mCurrentViewId], true, 0 ); |
586 changeView( mPreviousViewIds[mCurrentViewId], true, 0 ); |
508 } |
587 } |
509 else { |
588 else { |
510 BTUI_ASSERT_X(false, "BtCpUiMainView::switchToPreviousViewReally", "invalid view id"); |
589 BTUI_ASSERT_X(false, "BtCpUiMainView::switchToPreviousView", "invalid view id"); |
511 } |
590 } |
512 } |
591 } |
513 |
592 |
514 |
|
515 void BtCpUiMainView::setSoftkeyBack() |
|
516 { |
|
517 |
|
518 } |
|
519 |
|
520 void BtCpUiMainView::switchToPreviousView() |
|
521 { |
|
522 |
|
523 } |
|
524 |
|