14 * Description: |
14 * Description: |
15 * |
15 * |
16 */ |
16 */ |
17 |
17 |
18 #include "btcpuisearchview.h" |
18 #include "btcpuisearchview.h" |
|
19 #include "btuiviewutil.h" |
19 #include <QtGui/QGraphicsLinearLayout> |
20 #include <QtGui/QGraphicsLinearLayout> |
20 #include <HbInstance> |
21 #include <HbInstance> |
21 #include <hbdocumentloader.h> |
22 #include <HbDocumentLoader> |
22 #include <hbdataform.h> |
23 #include <HbDataForm> |
23 #include <hbpushbutton.h> |
24 #include <HbPushButton> |
24 #include <hblabel.h> |
25 #include <HbLabel> |
25 #include <hblistview.h> |
26 #include <HbListView> |
26 #include <hbmenu.h> |
27 #include <HbMenu> |
27 #include <qstringlist> |
28 #include <QString> |
28 #include <qdebug> |
29 #include <QStringList> |
|
30 #include <QDebug> |
29 #include <bluetoothuitrace.h> |
31 #include <bluetoothuitrace.h> |
30 #include "btcpuimainview.h" |
32 #include "btcpuimainview.h" |
|
33 #include "btdelegatefactory.h" |
|
34 #include "btabstractdelegate.h" |
31 |
35 |
32 |
36 |
33 |
37 |
34 // docml to load |
38 // docml to load |
35 const char* BTUI_SEARCHVIEW_DOCML = ":/docml/bt-search-view.docml"; |
39 const char* BTUI_SEARCHVIEW_DOCML = ":/docml/bt-search-view.docml"; |
36 |
40 |
37 BtCpUiSearchView::BtCpUiSearchView(BtuiModel &model, QGraphicsItem *parent) : |
41 BtCpUiSearchView::BtCpUiSearchView( |
38 BtCpUiBaseView(model,parent) |
42 BtSettingModel &settingModel, |
39 /*{ |
43 BtDeviceModel &deviceModel, |
|
44 QGraphicsItem *parent) : |
|
45 BtCpUiBaseView(settingModel,deviceModel, parent), mAbstractDelegate(0), mBtuiModelSortFilter(0) |
|
46 { |
|
47 bool ret(false); |
|
48 |
|
49 mMainView = (BtCpUiMainView *) parent; |
|
50 |
|
51 mMainWindow = hbInstance->allMainWindows().first(); |
|
52 |
40 mSoftKeyBackAction = new HbAction(Hb::BackNaviAction, this); |
53 mSoftKeyBackAction = new HbAction(Hb::BackNaviAction, this); |
41 BTUI_ASSERT_X(mSoftKeyBackAction, "BtCpUiBaseView::BtCpUiBaseView", "can't create back action"); |
54 BTUI_ASSERT_X(mSoftKeyBackAction, "BtCpUiBaseView::BtCpUiBaseView", "can't create back action"); |
42 |
55 |
43 QGraphicsLinearLayout *mainLayout = new QGraphicsLinearLayout( Qt::Vertical, this ); |
|
44 // create button |
|
45 HbPushButton *button = new HbPushButton(this); |
|
46 button->setText("Press Me"); |
|
47 button->setMaximumSize(150,50); |
|
48 mainLayout->addItem(button); |
|
49 |
|
50 // (void) connect(button, SIGNAL(clicked()), this, SLOT(changePowerState())); |
|
51 |
|
52 setLayout(mainLayout); |
|
53 |
|
54 // create dummy options menu |
|
55 HbMenu *optionsMenu = new HbMenu(); |
|
56 HbAction *openGadgetGallery = optionsMenu->addAction("Open Device Gallery"); |
|
57 // connect(openGadgetGallery, SIGNAL(triggered()), this, SLOT(openGadgetGalleryView())); |
|
58 HbAction *openNewMainView = optionsMenu->addAction("Open new Main View"); |
|
59 // connect(openNewMainView, SIGNAL(triggered()), this, SLOT(openNewMainView())); |
|
60 setMenu(optionsMenu); |
|
61 |
|
62 }*/ |
|
63 |
|
64 { |
|
65 //bool ret(false); |
|
66 |
|
67 mSearchView = this; |
|
68 mMainView = (BtCpUiMainView *) parent; |
|
69 |
|
70 mMainWindow = hbInstance->allMainWindows().first(); |
|
71 |
|
72 mSoftKeyBackAction = new HbAction(Hb::BackNaviAction, this); |
|
73 BTUI_ASSERT_X(mSoftKeyBackAction, "BtCpUiBaseView::BtCpUiBaseView", "can't create back action"); |
|
74 |
|
75 |
|
76 // read view info from docml file |
|
77 |
|
78 |
|
79 // Create view for the application. |
56 // Create view for the application. |
80 // Set the name for the view. The name should be same as the view's |
57 // Set the name for the view. The name should be same as the view's |
81 // name in docml. |
58 // name in docml. |
82 setObjectName("bt_search_view"); |
59 setObjectName("bt_search_view"); |
83 |
60 |
102 mDeviceIcon=0; |
80 mDeviceIcon=0; |
103 // can't use qobject_cast since HbIcon is not derived from QObject! |
81 // can't use qobject_cast since HbIcon is not derived from QObject! |
104 mDeviceIcon = qobject_cast<HbLabel *>( mLoader->findWidget( "icon" ) ); |
82 mDeviceIcon = qobject_cast<HbLabel *>( mLoader->findWidget( "icon" ) ); |
105 BTUI_ASSERT_X( mDeviceIcon != 0, "bt-search-view", "Device Icon not found" ); |
83 BTUI_ASSERT_X( mDeviceIcon != 0, "bt-search-view", "Device Icon not found" ); |
106 |
84 |
107 mDeviceName=0; |
85 mLabelFoundDevices=0; |
108 mDeviceName = qobject_cast<HbLabel *>( mLoader->findWidget( "label_found_devices" ) ); |
86 mLabelFoundDevices = qobject_cast<HbLabel *>( mLoader->findWidget( "label_found_devices" ) ); |
109 BTUI_ASSERT_X( mDeviceName != 0, "bt-search-view", "Device Name not found" ); |
87 BTUI_ASSERT_X( mLabelFoundDevices != 0, "bt-search-view", "Found Devices not found" ); |
110 |
88 mLabelFoundDevices->setPlainText(hbTrId("txt_bt_subhead_bluetooth_found_devices")); |
|
89 |
|
90 mLabelSearching=0; |
|
91 mLabelSearching = qobject_cast<HbLabel *>( mLoader->findWidget( "label_searching" ) ); |
|
92 BTUI_ASSERT_X( mLabelSearching != 0, "bt-search-view", "Searching not found" ); |
|
93 mLabelSearching->setPlainText(hbTrId("txt_bt_subhead_searching")); |
|
94 |
111 mDeviceList=0; |
95 mDeviceList=0; |
112 mDeviceList = qobject_cast<HbListView *>( mLoader->findWidget( "deviceList" ) ); |
96 mDeviceList = qobject_cast<HbListView *>( mLoader->findWidget( "deviceList" ) ); |
113 BTUI_ASSERT_X( mDeviceList != 0, "bt-search-view", "Device List not found" ); |
97 BTUI_ASSERT_X( mDeviceList != 0, "bt-search-view", "Device List not found" ); |
114 |
98 |
115 |
99 |
116 // // set model to list view |
100 mDeviceList->setSelectionMode( HbAbstractItemView::SingleSelection ); |
117 // mDeviceList->setModel( mFilterProxy ); |
|
118 // // define settings for list view |
|
119 // mDeviceList->setSelectionMode(HbAbstractItemView::SingleSelection); |
|
120 // // set prototype item for list view |
|
121 // BtUiDevListGridItem *item = new BtUiDevListGridItem( mDeviceList ); |
|
122 // mDeviceList->setItemPrototype(item); |
|
123 // // connect to list view pressed signal |
|
124 // ret = connect( mDeviceList, SIGNAL(pressed(QModelIndex)),this, SLOT(itemActivated(QModelIndex)) ); |
|
125 // BTUI_ASSERT_X( ret, "bt-search-view", "device list can't connect" ); |
|
126 |
101 |
127 // read landscape orientation section from docml file if needed |
102 // read landscape orientation section from docml file if needed |
128 // mOrientation = ((BTUIViewManager*)parent)->orientation(); |
103 mOrientation = mMainWindow->orientation(); |
129 mOrientation = Qt::Vertical; |
104 |
130 if (mOrientation == Qt::Horizontal) { |
105 if (mOrientation == Qt::Horizontal) { |
131 mLoader->load(BTUI_SEARCHVIEW_DOCML, "landscape", &ok); |
106 mLoader->load(BTUI_SEARCHVIEW_DOCML, "landscape_ui", &ok); |
132 BTUI_ASSERT_X( ok, "bt-search-view", "Invalid docml file: landscape section problem" ); |
107 BTUI_ASSERT_X( ok, "bt-search-view", "Invalid docml file: landscape section problem" ); |
133 } |
108 } else { |
134 |
109 mLoader->load(BTUI_SEARCHVIEW_DOCML, "portrait_ui", &ok); |
|
110 BTUI_ASSERT_X( ok, "bt-search-view", "Invalid docml file: portrait section problem" ); |
|
111 } |
|
112 |
|
113 // listen for orientation changes |
|
114 ret = connect(mMainWindow, SIGNAL(orientationChanged(Qt::Orientation)), |
|
115 this, SLOT(changeOrientation(Qt::Orientation))); |
|
116 BTUI_ASSERT_X( ret, "BtCpUiSearchView::BtCpUiSearchView()", "connect orientationChanged() failed"); |
135 |
117 |
136 // load tool bar actions |
118 // load tool bar actions |
137 HbAction *viewByAction = static_cast<HbAction*>( mLoader->findObject( "viewByAction" ) ); |
119 mViewBy = static_cast<HbAction*>( mLoader->findObject( "viewByAction" ) ); |
138 BTUI_ASSERT_X( viewByAction, "bt-search-view", "view by action missing" ); |
120 BTUI_ASSERT_X( mViewBy, "bt-search-view", "view by action missing" ); |
|
121 // TODO - Need to implement the View by |
139 // ret = connect(viewByAction, SIGNAL(triggered()), this, SLOT(noOp())); |
122 // ret = connect(viewByAction, SIGNAL(triggered()), this, SLOT(noOp())); |
140 // BTUI_ASSERT_X( ret, "bt-search-view", "viewByAction can't connect" ); |
123 // BTUI_ASSERT_X( ret, "bt-search-view", "viewByAction can't connect" ); |
141 |
124 |
142 HbAction *stopAction = static_cast<HbAction*>( mLoader->findObject( "stopAction" ) ); |
125 mStop = static_cast<HbAction*>( mLoader->findObject( "stopAction" ) ); |
143 BTUI_ASSERT_X( stopAction, "bt-search-view", "view by action missing" ); |
126 BTUI_ASSERT_X( mStop, "bt-search-view", "stopAction missing" ); |
144 // ret = connect(stopAction, SIGNAL(triggered()), this, SLOT(noOp())); |
127 ret = connect(mStop, SIGNAL(triggered()), this, SLOT(stopSearching())); |
145 // BTUI_ASSERT_X( ret, "bt-search-view", "stopAction can't connect" ); |
128 BTUI_ASSERT_X( ret, "bt-search-view", "stopAction can't connect" ); |
146 |
129 mStop->setEnabled(true); |
147 HbAction *retryAction = static_cast<HbAction*>( mLoader->findObject( "retryAction" ) ); |
130 |
148 BTUI_ASSERT_X( retryAction, "bt-search-view", "view by action missing" ); |
131 mRetry = static_cast<HbAction*>( mLoader->findObject( "retryAction" ) ); |
149 // ret = connect(retryAction, SIGNAL(triggered()), this, SLOT(noOp())); |
132 BTUI_ASSERT_X( mRetry, "bt-search-view", "retryAction missing" ); |
150 // BTUI_ASSERT_X( ret, "bt-search-view", "retryAction can't connect" ); |
133 ret = connect(mRetry, SIGNAL(triggered()), this, SLOT(retrySearch())); |
151 |
134 BTUI_ASSERT_X( ret, "bt-search-view", "retryAction can't connect" ); |
|
135 // Disable for initial search |
|
136 mRetry->setEnabled(false); |
152 |
137 |
153 // load menu |
138 // load menu |
154 HbMenu *optionsMenu = qobject_cast<HbMenu *>(mLoader->findWidget("viewMenu")); |
139 HbMenu *optionsMenu = qobject_cast<HbMenu *>(mLoader->findWidget("viewMenu")); |
155 BTUI_ASSERT_X( optionsMenu != 0, "bt-search-view", "Options menu not found" ); |
140 BTUI_ASSERT_X( optionsMenu != 0, "bt-search-view", "Options menu not found" ); |
156 this->setMenu(optionsMenu); |
141 this->setMenu(optionsMenu); |
157 |
142 |
158 |
143 mExit = static_cast<HbAction*>( mLoader->findObject( "exitAction" ) ); |
159 // update display when setting data changed |
144 BTUI_ASSERT_X( mExit, "bt-search-view", "exitAction missing" ); |
160 // ret = connect(mModel, SIGNAL(dataChanged(QModelIndex,QModelIndex)), |
145 mExit->setText(hbTrId("txt_common_opt_exit")); |
161 // this, SLOT(updateSettingItems(QModelIndex,QModelIndex))); |
146 |
162 // BTUI_ASSERT_X( ret, "BtCpUiSearchView::BtCpUiSearchView", "can't connect dataChanged" ); |
147 mConnect = static_cast<HbAction*>( mLoader->findObject( "connectAction" ) ); |
163 |
148 BTUI_ASSERT_X( mConnect, "bt-search-view", "connectAction missing" ); |
164 // QModelIndex top = mModel->index( Btuim::LocalDeviceName, KDefaultColumn ); |
149 mConnect->setText(hbTrId("txt_bt_menu_connect")); |
165 // QModelIndex bottom = mModel->index( Btuim::Visibility, KDefaultColumn ); |
150 |
166 // // update name, power and visibility rows |
151 ret = connect(mDeviceList, SIGNAL(activated(QModelIndex)), this, SLOT(deviceSelected(QModelIndex))); |
167 // updateSettingItems( top, bottom ); |
152 BTUI_ASSERT_X( ret, "bt-search-view", "deviceSelected can't connect" ); |
168 |
|
169 |
|
170 } |
153 } |
171 |
154 |
172 BtCpUiSearchView::~BtCpUiSearchView() |
155 BtCpUiSearchView::~BtCpUiSearchView() |
173 { |
156 { |
174 setNavigationAction(0); |
157 setNavigationAction(0); |
175 delete mSoftKeyBackAction; |
158 delete mSoftKeyBackAction; |
176 } |
159 |
177 |
160 if(mAbstractDelegate) { |
178 void BtCpUiSearchView::deviceSelected(const QModelIndex& modelIndex) |
161 delete mAbstractDelegate; |
179 { |
162 mAbstractDelegate = 0; |
180 int row = modelIndex.row(); |
163 } |
|
164 |
|
165 if(mBtuiModelSortFilter) { |
|
166 delete mBtuiModelSortFilter; |
|
167 mBtuiModelSortFilter = 0; |
|
168 } |
|
169 } |
|
170 |
|
171 void BtCpUiSearchView::changeOrientation( Qt::Orientation orientation ) |
|
172 { |
|
173 bool ok = false; |
|
174 mOrientation = orientation; |
|
175 if( orientation == Qt::Vertical ) { |
|
176 // load "portrait" section |
|
177 mLoader->load( BTUI_SEARCHVIEW_DOCML, "portrait_ui", &ok ); |
|
178 BTUI_ASSERT_X( ok, "bt-search-view", "Invalid docml file: portrait section problem" ); |
|
179 } else { |
|
180 // load "landscape" section |
|
181 mLoader->load( BTUI_SEARCHVIEW_DOCML, "landscape_ui", &ok ); |
|
182 BTUI_ASSERT_X( ok, "bt-search-view", "Invalid docml file: landscape section problem" ); |
|
183 } |
|
184 } |
|
185 |
|
186 void BtCpUiSearchView::stopSearching() |
|
187 { |
|
188 // Stop delegate |
|
189 |
|
190 // Change label and buttons to reflect status |
|
191 mLabelSearching->setPlainText(hbTrId("txt_bt_subhead_search_done")); |
|
192 mRetry->setEnabled(true); |
|
193 mStop->setEnabled(false); |
|
194 |
|
195 // Stop delegate |
|
196 mAbstractDelegate->cancel(); |
|
197 } |
|
198 |
|
199 void BtCpUiSearchView::retrySearch() |
|
200 { |
|
201 // Retry delegate |
|
202 |
|
203 // Change label and buttons to reflect status |
|
204 mLabelSearching->setPlainText(hbTrId("txt_bt_subhead_searching")); |
|
205 mRetry->setEnabled(false); |
|
206 mStop->setEnabled(true); |
|
207 |
|
208 // Make use of the delegate and start the search. |
|
209 mAbstractDelegate->cancel(); |
|
210 mDeviceList->setModel(mBtuiModelSortFilter); |
|
211 mAbstractDelegate->exec(QVariant()); |
181 } |
212 } |
182 |
213 |
183 void BtCpUiSearchView::setSoftkeyBack() |
214 void BtCpUiSearchView::setSoftkeyBack() |
184 { |
215 { |
185 if (navigationAction() != mSoftKeyBackAction) { |
216 if (navigationAction() != mSoftKeyBackAction) { |
189 } |
220 } |
190 |
221 |
191 void BtCpUiSearchView::switchToPreviousView() |
222 void BtCpUiSearchView::switchToPreviousView() |
192 { |
223 { |
193 BTUI_ASSERT_X(mMainView, "BtCpUiSearchView::switchToPreviousView", "invalid mMainView"); |
224 BTUI_ASSERT_X(mMainView, "BtCpUiSearchView::switchToPreviousView", "invalid mMainView"); |
194 // jump to previous view of current view. |
225 mMainView->switchToPreviousView(); |
195 mSearchView->deactivateView(); |
|
196 |
|
197 // set the new current view |
|
198 mMainWindow->setCurrentView( mMainView ); |
|
199 |
|
200 // do preparation or some actions when new view is activated |
|
201 mMainView->activateView( 0, 0 ); |
|
202 |
|
203 } |
226 } |
204 |
227 |
205 void BtCpUiSearchView::activateView( const QVariant& value, int cmdId ) |
228 void BtCpUiSearchView::activateView( const QVariant& value, int cmdId ) |
206 { |
229 { |
207 Q_UNUSED(value); |
230 Q_UNUSED(value); |
208 Q_UNUSED(cmdId); |
231 Q_UNUSED(cmdId); |
209 |
232 |
210 setSoftkeyBack(); |
233 setSoftkeyBack(); |
|
234 |
|
235 bool ret(false); |
|
236 |
|
237 if(!mAbstractDelegate) { |
|
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()); |
211 } |
260 } |
212 |
261 |
213 void BtCpUiSearchView::deactivateView() |
262 void BtCpUiSearchView::deactivateView() |
214 { |
263 { |
215 } |
264 } |
|
265 |
|
266 void BtCpUiSearchView::searchDelegateCompleted(int error) |
|
267 { |
|
268 //TODO - handle error. |
|
269 Q_UNUSED(error); |
|
270 } |
|
271 |
|
272 void BtCpUiSearchView::deviceSearchCompleted(int error) |
|
273 { |
|
274 //TODO - handle error. |
|
275 Q_UNUSED(error); |
|
276 mLabelSearching->setPlainText(hbTrId("txt_bt_subhead_search_done")); |
|
277 mRetry->setEnabled(true); |
|
278 mStop->setEnabled(false); |
|
279 } |
|
280 |
|
281 void BtCpUiSearchView::deviceSelected(const QModelIndex& modelIndex) |
|
282 { |
|
283 QModelIndex index = mBtuiModelSortFilter->mapToSource(modelIndex); |
|
284 static_cast<BtCpUiMainView*>(mMainView)->goToDeviceView(index); |
|
285 } |