56 // Create view for the application. |
59 // Create view for the application. |
57 // Set the name for the view. The name should be same as the view's |
60 // Set the name for the view. The name should be same as the view's |
58 // name in docml. |
61 // name in docml. |
59 setObjectName("bt_search_view"); |
62 setObjectName("bt_search_view"); |
60 |
63 |
|
64 mLoader = new HbDocumentLoader(); |
|
65 // Pass the view to documentloader. Document loader uses this view |
|
66 // when docml is parsed, instead of creating new view. |
61 QObjectList objectList; |
67 QObjectList objectList; |
62 objectList.append(this); |
68 objectList.append(this); |
63 // Pass the view to documentloader. Document loader uses this view |
|
64 // when docml is parsed, instead of creating new view. |
|
65 mLoader = new HbDocumentLoader(); |
|
66 mLoader->setObjectTree(objectList); |
69 mLoader->setObjectTree(objectList); |
67 |
70 |
68 // read view info from docml file |
71 // read view info from docml file |
69 bool ok = false; |
72 bool ok = false; |
70 mLoader->load( BTUI_SEARCHVIEW_DOCML, &ok ); |
73 mLoader->load( BTUI_SEARCHVIEW_DOCML, &ok ); |
116 BTUI_ASSERT_X( ret, "BtCpUiSearchView::BtCpUiSearchView()", "connect orientationChanged() failed"); |
119 BTUI_ASSERT_X( ret, "BtCpUiSearchView::BtCpUiSearchView()", "connect orientationChanged() failed"); |
117 |
120 |
118 // load tool bar actions |
121 // load tool bar actions |
119 mViewBy = static_cast<HbAction*>( mLoader->findObject( "viewByAction" ) ); |
122 mViewBy = static_cast<HbAction*>( mLoader->findObject( "viewByAction" ) ); |
120 BTUI_ASSERT_X( mViewBy, "bt-search-view", "view by action missing" ); |
123 BTUI_ASSERT_X( mViewBy, "bt-search-view", "view by action missing" ); |
121 // TODO - Need to implement the View by |
124 ret = connect(mViewBy, SIGNAL(triggered()), this, SLOT(viewByDeviceTypeDialog())); |
122 // ret = connect(viewByAction, SIGNAL(triggered()), this, SLOT(noOp())); |
125 BTUI_ASSERT_X( ret, "bt-search-view", "viewByAction can't connect" ); |
123 // BTUI_ASSERT_X( ret, "bt-search-view", "viewByAction can't connect" ); |
|
124 |
126 |
125 mStop = static_cast<HbAction*>( mLoader->findObject( "stopAction" ) ); |
127 mStop = static_cast<HbAction*>( mLoader->findObject( "stopAction" ) ); |
126 BTUI_ASSERT_X( mStop, "bt-search-view", "stopAction missing" ); |
128 BTUI_ASSERT_X( mStop, "bt-search-view", "stopAction missing" ); |
127 ret = connect(mStop, SIGNAL(triggered()), this, SLOT(stopSearching())); |
129 ret = connect(mStop, SIGNAL(triggered()), this, SLOT(stopSearching())); |
128 BTUI_ASSERT_X( ret, "bt-search-view", "stopAction can't connect" ); |
130 BTUI_ASSERT_X( ret, "bt-search-view", "stopAction can't connect" ); |
148 BTUI_ASSERT_X( mConnect, "bt-search-view", "connectAction missing" ); |
150 BTUI_ASSERT_X( mConnect, "bt-search-view", "connectAction missing" ); |
149 mConnect->setText(hbTrId("txt_bt_menu_connect")); |
151 mConnect->setText(hbTrId("txt_bt_menu_connect")); |
150 |
152 |
151 ret = connect(mDeviceList, SIGNAL(activated(QModelIndex)), this, SLOT(deviceSelected(QModelIndex))); |
153 ret = connect(mDeviceList, SIGNAL(activated(QModelIndex)), this, SLOT(deviceSelected(QModelIndex))); |
152 BTUI_ASSERT_X( ret, "bt-search-view", "deviceSelected can't connect" ); |
154 BTUI_ASSERT_X( ret, "bt-search-view", "deviceSelected can't connect" ); |
|
155 |
|
156 // initialize device type list for "view by" option |
|
157 // Note: this list needs to be in the same order as enum devTypeSelectionList |
|
158 mDevTypeList << hbTrId("txt_bt_list_audio_devices") |
|
159 << hbTrId("txt_bt_list_computers") |
|
160 << hbTrId("txt_bt_list_input_devices") |
|
161 << hbTrId("txt_bt_list_phones") |
|
162 << hbTrId("txt_bt_list_other_devices"); |
|
163 |
|
164 // initialize sort model & create |
|
165 // inquiry delegate |
|
166 // Sort is set to dynamic sort filter = true in the class, will sort automatically |
|
167 mBtuiModelSortFilter = new BtuiModelSortFilter(this); |
|
168 mBtuiModelSortFilter->setSourceModel(mDeviceModel); |
|
169 mBtuiModelSortFilter->addDeviceMajorFilter( |
|
170 BtuiDevProperty::InRange, BtuiModelSortFilter::AtLeastMatch); |
|
171 mDeviceList->setModel(mBtuiModelSortFilter); |
|
172 // add sort order to show devices in the order they are found |
|
173 mBtuiModelSortFilter->setSortRole(BtDeviceModel::SeqNumRole); |
|
174 // Sort according to the first column (and the only column) in the listview - sorted according SeqNumRole |
|
175 mBtuiModelSortFilter->sort(0, Qt::AscendingOrder); |
|
176 |
|
177 BtCpUiSearchListViewItem *prototype = new BtCpUiSearchListViewItem(mDeviceList); |
|
178 prototype->setModelSortFilter(mBtuiModelSortFilter); |
|
179 mDeviceList->setItemPrototype(prototype); |
|
180 |
|
181 // Create the inquiry delegate. |
|
182 mAbstractDelegate = BtDelegateFactory::newDelegate(BtDelegate::Inquiry, mSettingModel, mDeviceModel ); |
|
183 |
|
184 // Connect to the signal from the BtDelegateInquiry for completion of the search request |
|
185 ret = connect(mAbstractDelegate, SIGNAL(commandCompleted(int)), this, SLOT(searchDelegateCompleted(int))); |
|
186 BTUI_ASSERT_X( ret, "bt-search-view", "searchDelegateCompleted can't connect" ); |
|
187 |
|
188 // Connect to the signal from the BtuiModel when the search has been completed. |
|
189 ret = connect(mDeviceModel, SIGNAL(deviceSearchCompleted(int)), this, SLOT(deviceSearchCompleted(int))); |
|
190 BTUI_ASSERT_X( ret, "bt-search-view", "deviceSearchCompleted can't connect" ); |
153 } |
191 } |
154 |
192 |
155 BtCpUiSearchView::~BtCpUiSearchView() |
193 BtCpUiSearchView::~BtCpUiSearchView() |
156 { |
194 { |
|
195 delete mLoader; // Also deletes all widgets that it constructed. |
|
196 |
157 setNavigationAction(0); |
197 setNavigationAction(0); |
|
198 disconnect( mSoftKeyBackAction ); |
158 delete mSoftKeyBackAction; |
199 delete mSoftKeyBackAction; |
159 |
200 |
160 if(mAbstractDelegate) { |
201 if(mAbstractDelegate) { |
161 delete mAbstractDelegate; |
202 delete mAbstractDelegate; |
162 mAbstractDelegate = 0; |
203 } |
163 } |
|
164 |
|
165 if(mBtuiModelSortFilter) { |
204 if(mBtuiModelSortFilter) { |
166 delete mBtuiModelSortFilter; |
205 delete mBtuiModelSortFilter; |
167 mBtuiModelSortFilter = 0; |
206 } |
|
207 if ( mQuery ) { |
|
208 delete mQuery; |
168 } |
209 } |
169 } |
210 } |
170 |
211 |
171 void BtCpUiSearchView::changeOrientation( Qt::Orientation orientation ) |
212 void BtCpUiSearchView::changeOrientation( Qt::Orientation orientation ) |
172 { |
213 { |
|
214 // ToDo: this does not handle redrawing list view items differently for portrait/landscape |
173 bool ok = false; |
215 bool ok = false; |
174 mOrientation = orientation; |
216 mOrientation = orientation; |
|
217 |
175 if( orientation == Qt::Vertical ) { |
218 if( orientation == Qt::Vertical ) { |
176 // load "portrait" section |
219 // load "portrait" section |
177 mLoader->load( BTUI_SEARCHVIEW_DOCML, "portrait_ui", &ok ); |
220 mLoader->load( BTUI_SEARCHVIEW_DOCML, "portrait_ui", &ok ); |
178 BTUI_ASSERT_X( ok, "bt-search-view", "Invalid docml file: portrait section problem" ); |
221 BTUI_ASSERT_X( ok, "bt-search-view", "Invalid docml file: portrait section problem" ); |
179 } else { |
222 } else { |
181 mLoader->load( BTUI_SEARCHVIEW_DOCML, "landscape_ui", &ok ); |
224 mLoader->load( BTUI_SEARCHVIEW_DOCML, "landscape_ui", &ok ); |
182 BTUI_ASSERT_X( ok, "bt-search-view", "Invalid docml file: landscape section problem" ); |
225 BTUI_ASSERT_X( ok, "bt-search-view", "Invalid docml file: landscape section problem" ); |
183 } |
226 } |
184 } |
227 } |
185 |
228 |
|
229 |
|
230 void BtCpUiSearchView::viewByDeviceTypeDialog() |
|
231 { |
|
232 if ( !mQuery ) { |
|
233 mQuery = new HbSelectionDialog; |
|
234 mQuery->setStringItems(mDevTypeList, 0); |
|
235 mQuery->setSelectionMode(HbAbstractItemView::MultiSelection); |
|
236 |
|
237 QList<QVariant> current; |
|
238 current.append(QVariant(0)); |
|
239 mQuery->setSelectedItems(current); |
|
240 |
|
241 // Set the heading for the dialog. |
|
242 HbLabel *headingLabel = new HbLabel(hbTrId("txt_bt_title_show"), mQuery); |
|
243 mQuery->setHeadingWidget(headingLabel); |
|
244 } |
|
245 mQuery->open(this,SLOT(viewByDialogClosed(HbAction*))); |
|
246 } |
|
247 /*! |
|
248 Callback for HbSelectionDialog closing |
|
249 |
|
250 */ |
|
251 void BtCpUiSearchView::viewByDialogClosed(HbAction* action) |
|
252 { |
|
253 disconnect( mQuery ); // remove slot |
|
254 if (action == mQuery->actions().first()) { // user pressed "Ok" |
|
255 // Get selected items. |
|
256 QList<QVariant> selections; |
|
257 selections = mQuery->selectedItems(); |
|
258 |
|
259 int devTypesWanted = 0; |
|
260 |
|
261 for (int i=0; i < selections.count(); i++) { |
|
262 switch (selections.at(i).toInt()) { |
|
263 case BtUiDevAudioDevice: |
|
264 devTypesWanted |= BtuiDevProperty::AVDev; |
|
265 break; |
|
266 case BtUiDevComputer: |
|
267 devTypesWanted |= BtuiDevProperty::Computer; |
|
268 break; |
|
269 case BtUiDevInputDevice: |
|
270 devTypesWanted |= BtuiDevProperty::Peripheral; |
|
271 break; |
|
272 case BtUiDevPhone: |
|
273 devTypesWanted |= BtuiDevProperty::Phone; |
|
274 break; |
|
275 case BtUiDevOtherDevice: |
|
276 devTypesWanted |= (BtuiDevProperty::LANAccessDev | |
|
277 BtuiDevProperty::Toy | |
|
278 BtuiDevProperty::WearableDev | |
|
279 BtuiDevProperty::ImagingDev | |
|
280 BtuiDevProperty::HealthDev | |
|
281 BtuiDevProperty::UncategorizedDev); |
|
282 break; |
|
283 default: |
|
284 // should never get here |
|
285 BTUI_ASSERT_X(false, "BtCpUiSearchView::viewByDialogClosed()", |
|
286 "wrong device type in viewBy dialog!"); |
|
287 } |
|
288 } |
|
289 if (devTypesWanted) { |
|
290 mBtuiModelSortFilter->clearDeviceMajorFilters(); |
|
291 mBtuiModelSortFilter->addDeviceMajorFilter(BtuiDevProperty::InRange, |
|
292 BtuiModelSortFilter::AtLeastMatch); // device must be in range |
|
293 mBtuiModelSortFilter->addDeviceMajorFilter(devTypesWanted, |
|
294 BtuiModelSortFilter::RoughMatch); // device can be any one of selected ones |
|
295 } |
|
296 mBtuiModelSortFilter->sort(0, Qt::AscendingOrder); |
|
297 } |
|
298 } |
|
299 |
186 void BtCpUiSearchView::stopSearching() |
300 void BtCpUiSearchView::stopSearching() |
187 { |
301 { |
188 // Stop delegate |
302 // Stop searching |
189 |
303 |
190 // Change label and buttons to reflect status |
304 // Change label and buttons to reflect status |
191 mLabelSearching->setPlainText(hbTrId("txt_bt_subhead_search_done")); |
305 mLabelSearching->setPlainText(hbTrId("txt_bt_subhead_search_done")); |
192 mRetry->setEnabled(true); |
306 mRetry->setEnabled(true); |
193 mStop->setEnabled(false); |
307 mStop->setEnabled(false); |
194 |
308 |
195 // Stop delegate |
309 // Stop search delegate |
196 mAbstractDelegate->cancel(); |
310 mAbstractDelegate->cancel(); |
197 } |
311 } |
198 |
312 |
|
313 void BtCpUiSearchView::startSearchDelegate () |
|
314 { |
|
315 |
|
316 mAbstractDelegate->exec(QVariant()); |
|
317 } |
|
318 |
199 void BtCpUiSearchView::retrySearch() |
319 void BtCpUiSearchView::retrySearch() |
200 { |
320 { |
201 // Retry delegate |
321 // Retry search |
202 |
322 |
203 // Change label and buttons to reflect status |
323 // Change label and buttons to reflect status |
204 mLabelSearching->setPlainText(hbTrId("txt_bt_subhead_searching")); |
324 mLabelSearching->setPlainText(hbTrId("txt_bt_subhead_searching")); |
205 mRetry->setEnabled(false); |
325 mRetry->setEnabled(false); |
206 mStop->setEnabled(true); |
326 mStop->setEnabled(true); |
207 |
327 |
208 // Make use of the delegate and start the search. |
328 // Make use of the delegate and start the search. |
209 mAbstractDelegate->cancel(); |
329 startSearchDelegate (); |
210 mDeviceList->setModel(mBtuiModelSortFilter); |
|
211 mAbstractDelegate->exec(QVariant()); |
|
212 } |
330 } |
213 |
331 |
214 void BtCpUiSearchView::setSoftkeyBack() |
332 void BtCpUiSearchView::setSoftkeyBack() |
215 { |
333 { |
216 if (navigationAction() != mSoftKeyBackAction) { |
334 if (navigationAction() != mSoftKeyBackAction) { |
223 { |
341 { |
224 BTUI_ASSERT_X(mMainView, "BtCpUiSearchView::switchToPreviousView", "invalid mMainView"); |
342 BTUI_ASSERT_X(mMainView, "BtCpUiSearchView::switchToPreviousView", "invalid mMainView"); |
225 mMainView->switchToPreviousView(); |
343 mMainView->switchToPreviousView(); |
226 } |
344 } |
227 |
345 |
228 void BtCpUiSearchView::activateView( const QVariant& value, int cmdId ) |
346 void BtCpUiSearchView::activateView( const QVariant& value, bool fromBackButton ) |
229 { |
347 { |
230 Q_UNUSED(value); |
348 Q_UNUSED(value); |
231 Q_UNUSED(cmdId); |
349 |
|
350 // ToDo: consider whether orientation should be updated here rather than when orientation really changes; |
|
351 // advantage: if orientation changes temporarily in another view, but returns to previous setting before |
|
352 // search is reactived, there is no processing overhead |
232 |
353 |
233 setSoftkeyBack(); |
354 setSoftkeyBack(); |
234 |
355 |
235 bool ret(false); |
356 if ( !fromBackButton ) { |
236 |
357 startSearchDelegate(); |
237 if(!mAbstractDelegate) { |
358 } |
238 // Create the inquiry delegate. |
|
239 mAbstractDelegate = BtDelegateFactory::newDelegate( |
|
240 BtDelegate::Inquiry, mSettingModel, mDeviceModel ); |
|
241 } |
|
242 |
|
243 // Connect to the signal from the BtDelegateInquiry for completion of the search request |
|
244 ret = connect(mAbstractDelegate, SIGNAL(commandCompleted(int)), this, SLOT(searchDelegateCompleted(int))); |
|
245 BTUI_ASSERT_X( ret, "bt-search-view", "searchDelegateCompleted can't connect" ); |
|
246 |
|
247 // Connect to the signal from the BtuiModel when the search has been completed. |
|
248 ret = connect(mDeviceModel, SIGNAL(deviceSearchCompleted(int)), this, SLOT(deviceSearchCompleted(int))); |
|
249 BTUI_ASSERT_X( ret, "bt-search-view", "deviceSearchCompleted can't connect" ); |
|
250 |
|
251 if(!mBtuiModelSortFilter) { |
|
252 mBtuiModelSortFilter = new BtuiModelSortFilter(this); |
|
253 } |
|
254 mBtuiModelSortFilter->setSourceModel(mDeviceModel); |
|
255 mBtuiModelSortFilter->addDeviceMajorFilter(BtDeviceModel::InRange, BtuiModelSortFilter::AtLeastMatch); |
|
256 mDeviceList->setModel(mBtuiModelSortFilter); |
|
257 |
|
258 // Make use of the delegate and start the search. |
|
259 mAbstractDelegate->exec(QVariant()); |
|
260 } |
359 } |
261 |
360 |
262 void BtCpUiSearchView::deactivateView() |
361 void BtCpUiSearchView::deactivateView() |
263 { |
362 { |
|
363 mAbstractDelegate->cancel(); // Stop searching when leaving view |
|
364 deviceSearchCompleted(KErrNone); // reset view |
264 } |
365 } |
265 |
366 |
266 void BtCpUiSearchView::searchDelegateCompleted(int error) |
367 void BtCpUiSearchView::searchDelegateCompleted(int error) |
267 { |
368 { |
268 //TODO - handle error. |
|
269 Q_UNUSED(error); |
369 Q_UNUSED(error); |
|
370 |
270 } |
371 } |
271 |
372 |
272 void BtCpUiSearchView::deviceSearchCompleted(int error) |
373 void BtCpUiSearchView::deviceSearchCompleted(int error) |
273 { |
374 { |
274 //TODO - handle error. |
375 //TODO - handle error. |