24 #include <HbAbstractViewItem> |
24 #include <HbAbstractViewItem> |
25 #include <HbMenu> |
25 #include <HbMenu> |
26 |
26 |
27 #include <cadefs.h> |
27 #include <cadefs.h> |
28 #include <caentry.h> |
28 #include <caentry.h> |
|
29 #include <caitemmodel.h> |
29 |
30 |
30 #include "hsapp_defs.h" |
31 #include "hsapp_defs.h" |
31 #include "hsmenuevent.h" |
32 #include "hsmenuevent.h" |
32 #include "hsmenueventfactory.h" |
33 #include "hsmenueventfactory.h" |
33 #include "hsmenuservice.h" |
34 #include "hsmenuservice.h" |
142 Slot invoked when a state is entered. |
141 Slot invoked when a state is entered. |
143 */ |
142 */ |
144 void HsCollectionState::stateEntered() |
143 void HsCollectionState::stateEntered() |
145 { |
144 { |
146 HSMENUTEST_FUNC_ENTRY("HsCollectionState::stateEntered"); |
145 HSMENUTEST_FUNC_ENTRY("HsCollectionState::stateEntered"); |
147 HsBaseViewState::stateEntered(); |
|
148 makeConnect(); |
|
149 if (!mModel) { |
146 if (!mModel) { |
150 mModel = |
147 mModel = |
151 HsMenuService::getCollectionModel( |
148 HsMenuService::getCollectionModel( |
152 mCollectionId, mSortAttribute, mCollectionType); |
149 mCollectionId, mSortAttribute, mCollectionType); |
153 } |
150 } |
154 |
151 |
155 EntryFlags flags = |
152 handleEmptyChange(mModel->rowCount() == 0); |
156 mModel->root().data(CaItemModel::FlagsRole).value< |
153 |
157 EntryFlags> (); |
154 makeConnect(); |
158 |
155 |
159 if (mModel->rowCount() == 0){ |
|
160 if (flags & RemovableEntryFlag){ |
|
161 mMenuView->setContext(HsCollectionContext,HsButtonContext); |
|
162 } else { |
|
163 mMenuView->setContext(HsCollectionContext,HsEmptyLabelContext); |
|
164 } |
|
165 mMenuView->disableSearch(true); |
|
166 } else { |
|
167 mMenuView->setContext(HsCollectionContext,HsItemViewContext); |
|
168 mMenuView->disableSearch(false); |
|
169 } |
|
170 |
|
171 connect(mModel, SIGNAL(modelReset()), SLOT(updateLabel())); |
|
172 connect(mModel, SIGNAL(empty(bool)),this, |
|
173 SLOT(handleEmptyChange(bool))); |
|
174 connect(mModel, SIGNAL(empty(bool)),this, |
|
175 SLOT(lockSearchButton(bool))); |
|
176 |
|
177 mMenuView->setModel(mModel); |
|
178 |
|
179 mMenuView->listView()->scrollTo( |
|
180 mModel->index(0), HbAbstractItemView::PositionAtTop); |
|
181 |
|
182 mMenuView->viewLabel()->setHeading( |
156 mMenuView->viewLabel()->setHeading( |
183 mModel->root().data(Qt::DisplayRole).toString()); |
157 mModel->root().data(CaItemModel::CollectionTitleRole).toString()); |
184 setMenuOptions(); |
158 |
185 |
159 HsBaseViewState::stateEntered(); |
186 HSMENUTEST_FUNC_EXIT("HsCollectionState::stateEntered"); |
160 HSMENUTEST_FUNC_EXIT("HsCollectionState::stateEntered"); |
187 } |
161 } |
188 |
162 |
189 /*! |
163 /*! |
190 Creates and installs menu options for the view |
164 Creates and installs menu options for the view |
255 Slot invoked when a state is exited. |
229 Slot invoked when a state is exited. |
256 */ |
230 */ |
257 void HsCollectionState::stateExited() |
231 void HsCollectionState::stateExited() |
258 { |
232 { |
259 HSMENUTEST_FUNC_ENTRY("HsCollectionState::stateExited"); |
233 HSMENUTEST_FUNC_ENTRY("HsCollectionState::stateExited"); |
|
234 mMenuView->disableSearch(false); |
260 makeDisconnect(); |
235 makeDisconnect(); |
261 mMenuView->disableSearch(false); |
236 |
262 disconnect(mModel, SIGNAL(empty(bool)),this, |
|
263 SLOT(handleEmptyChange(bool))); |
|
264 |
|
265 disconnect(mModel, SIGNAL(empty(bool)),this, |
|
266 SLOT(lockSearchButton(bool))); |
|
267 |
|
268 disconnect(mModel, SIGNAL(modelReset()), |
|
269 this, SLOT(updateLabel())); |
|
270 delete mModel; |
237 delete mModel; |
271 mModel = NULL; |
238 mModel = NULL; |
272 this->mSortAttribute = NoHsSortAttribute; |
239 this->mSortAttribute = NoHsSortAttribute; |
273 |
240 |
274 HsBaseViewState::stateExited(); |
241 HsBaseViewState::stateExited(); |
294 SLOT(hideSearchPanel())); |
261 SLOT(hideSearchPanel())); |
295 connect(mMenuView.data(), |
262 connect(mMenuView.data(), |
296 SIGNAL(longPressed(HbAbstractViewItem *, QPointF)), |
263 SIGNAL(longPressed(HbAbstractViewItem *, QPointF)), |
297 static_cast<HsBaseViewState*>(this), |
264 static_cast<HsBaseViewState*>(this), |
298 SLOT(showContextMenu(HbAbstractViewItem *, QPointF))); |
265 SLOT(showContextMenu(HbAbstractViewItem *, QPointF))); |
299 connect(mMenuView->collectionButton(), |
266 connect(mModel, SIGNAL(modelReset()), SLOT(updateLabel())); |
300 SIGNAL(toggled(bool)), this, SLOT(addAppsAction(bool))); |
267 connect(mModel, SIGNAL(empty(bool)),this, |
|
268 SLOT(handleEmptyChange(bool))); |
|
269 connect(mModel, SIGNAL(empty(bool)),this, |
|
270 SLOT(lockSearchButton(bool))); |
301 } |
271 } |
302 |
272 |
303 /*! |
273 /*! |
304 Perform all signal disconnections. |
274 Perform all signal disconnections. |
305 */ |
275 */ |
306 void HsCollectionState::makeDisconnect() |
276 void HsCollectionState::makeDisconnect() |
307 { |
277 { |
308 disconnect(mMenuView->collectionButton(), |
|
309 SIGNAL(toggled(bool)), this, SLOT(addAppsAction(bool))); |
|
310 |
|
311 disconnect(mBackKeyAction, SIGNAL(triggered()), |
278 disconnect(mBackKeyAction, SIGNAL(triggered()), |
312 static_cast<HsBaseViewState*>(this), SLOT(openAppLibrary())); |
279 static_cast<HsBaseViewState*>(this), SLOT(openAppLibrary())); |
313 |
280 |
314 disconnect(mMenuView.data(), |
281 disconnect(mMenuView.data(), |
315 SIGNAL(activated(QModelIndex)), |
282 SIGNAL(activated(QModelIndex)), |
321 SLOT(hideSearchPanel())); |
288 SLOT(hideSearchPanel())); |
322 disconnect(mMenuView.data(), |
289 disconnect(mMenuView.data(), |
323 SIGNAL(longPressed(HbAbstractViewItem *, QPointF)), |
290 SIGNAL(longPressed(HbAbstractViewItem *, QPointF)), |
324 static_cast<HsBaseViewState*>(this), |
291 static_cast<HsBaseViewState*>(this), |
325 SLOT(showContextMenu(HbAbstractViewItem *, QPointF))); |
292 SLOT(showContextMenu(HbAbstractViewItem *, QPointF))); |
|
293 disconnect(mModel, SIGNAL(empty(bool)),this, |
|
294 SLOT(handleEmptyChange(bool))); |
|
295 |
|
296 disconnect(mModel, SIGNAL(empty(bool)),this, |
|
297 SLOT(lockSearchButton(bool))); |
|
298 |
|
299 disconnect(mModel, SIGNAL(modelReset()), |
|
300 this, SLOT(updateLabel())); |
326 } |
301 } |
327 |
302 |
328 /*! |
303 /*! |
329 Handles context menu actions |
304 Handles context menu actions |
330 */ |
305 */ |
360 break; |
335 break; |
361 case AppDetailsContextAction: |
336 case AppDetailsContextAction: |
362 machine()->postEvent( |
337 machine()->postEvent( |
363 HsMenuEventFactory::createAppDetailsViewEvent(itemId)); |
338 HsMenuEventFactory::createAppDetailsViewEvent(itemId)); |
364 break; |
339 break; |
|
340 case OpenContextAction: |
|
341 launchItem(mContextModelIndex); |
|
342 break; |
365 default: |
343 default: |
366 break; |
344 break; |
367 } |
345 } |
368 |
346 |
369 mMenuView->setSearchPanelVisible(false); |
347 mMenuView->hideSearchPanel(); |
370 } |
348 } |
371 |
349 |
372 /*! |
350 /*! |
373 Handles button visibility |
351 Handler to be called when model becomes not empty or model becomes empty. |
374 \param empty if true set empty text label or button to add entries to collection. |
352 \param empty \a true when model becomes empty \a false otherwise. |
375 */ |
353 */ |
376 void HsCollectionState::handleEmptyChange(bool empty) |
354 void HsCollectionState::handleEmptyChange(bool empty) |
377 { |
355 { |
|
356 |
378 EntryFlags flags = |
357 EntryFlags flags = |
379 mModel->root().data(CaItemModel::FlagsRole).value< |
358 mModel->root().data(CaItemModel::FlagsRole).value< |
380 EntryFlags> (); |
359 EntryFlags> (); |
381 |
360 |
382 if (empty){ |
361 if (empty){ |
383 if (flags & RemovableEntryFlag){ |
362 if (flags & RemovableEntryFlag){ |
384 mMenuView->setContext(HsCollectionContext,HsButtonContext); |
363 mMenuView->reset(HsButtonContext); |
|
364 connect(mMenuView->contentButton(), |
|
365 SIGNAL(toggled(bool)), this, SLOT(addAppsAction(bool)), |
|
366 Qt::UniqueConnection); |
385 } else { |
367 } else { |
386 mMenuView->setContext(HsCollectionContext,HsEmptyLabelContext); |
368 mMenuView->reset(HsEmptyLabelContext); |
387 } |
369 } |
|
370 |
388 } else { |
371 } else { |
389 mMenuView->setContext(HsCollectionContext,HsItemViewContext); |
372 mMenuView->reset(HsItemViewContext); |
390 } |
373 mMenuView->setModel(mModel); |
|
374 mMenuView->listView()->scrollTo( |
|
375 mModel->index(0), HbAbstractItemView::PositionAtTop); |
|
376 } |
|
377 |
|
378 mMenuView->disableSearch(empty); |
|
379 |
|
380 mMenuView->activate(); |
|
381 |
391 setMenuOptions(); |
382 setMenuOptions(); |
392 } |
383 } |
393 |
384 |
394 |
385 |
395 /*! |
386 /*! |
474 HsMenuEventFactory::createAddToHomeScreenEvent( |
469 HsMenuEventFactory::createAddToHomeScreenEvent( |
475 entry->id(), mMenuMode->getHsMenuMode(), mMenuMode->getHsToken())); |
470 entry->id(), mMenuMode->getHsMenuMode(), mMenuMode->getHsToken())); |
476 } |
471 } |
477 |
472 |
478 /*! |
473 /*! |
479 Method seting context menu options. |
474 Method setting context menu options. |
480 */ |
475 */ |
481 void HsCollectionState::setContextMenuOptions(HbAbstractViewItem *item, EntryFlags flags) |
476 void HsCollectionState::setContextMenuOptions(HbAbstractViewItem *item, EntryFlags flags) |
482 { |
477 { |
|
478 HbAction *openAction = mContextMenu->addAction(hbTrId( |
|
479 "txt_common_menu_open")); |
|
480 openAction->setData(OpenContextAction); |
483 HbAction *addShortcutAction = mContextMenu->addAction(hbTrId( |
481 HbAction *addShortcutAction = mContextMenu->addAction(hbTrId( |
484 "txt_applib_menu_add_to_home_screen")); |
482 "txt_applib_menu_add_to_home_screen")); |
485 addShortcutAction->setData(AddToHomeScreenContextAction); |
483 addShortcutAction->setData(AddToHomeScreenContextAction); |
486 HbAction *addToCollection = mContextMenu->addAction(hbTrId( |
484 HbAction *addToCollection = mContextMenu->addAction(hbTrId( |
487 "txt_applib_menu_add_to_collection")); |
485 "txt_applib_menu_add_to_collection")); |
488 addToCollection->setData(AddToCollectionContextAction); |
486 addToCollection->setData(AddToCollectionContextAction); |
489 HbAction *removeAction(NULL); |
487 HbAction *removeAction(NULL); |
490 HbAction *uninstallAction(NULL); |
488 HbAction *uninstallAction(NULL); |
491 HbAction *appSettingsAction(NULL); |
489 HbAction *appSettingsAction(NULL); |
492 HbAction *appDetailsAction(NULL); |
490 HbAction *appDetailsAction(NULL); |
551 void HsCollectionState::createArrangeCollection() |
549 void HsCollectionState::createArrangeCollection() |
552 { |
550 { |
553 // Arrange collection via the Arrange view |
551 // Arrange collection via the Arrange view |
554 int topItemId(0); |
552 int topItemId(0); |
555 |
553 |
556 const QList<HbAbstractViewItem *> array = |
554 if (mMenuView->listView() != NULL) { |
557 mMenuView->listView()->visibleItems(); |
555 const QList<HbAbstractViewItem *> array = |
558 |
556 mMenuView->listView()->visibleItems(); |
559 if (array.count() >= 1) { |
557 |
560 QModelIndex idx = array[0]->modelIndex(); |
558 if (array.count() >= 1) { |
561 topItemId = idx.data(CaItemModel::IdRole).toInt(); |
559 QModelIndex idx = array[0]->modelIndex(); |
|
560 topItemId = idx.data(CaItemModel::IdRole).toInt(); |
|
561 } |
562 } |
562 } |
563 |
563 |
564 machine()->postEvent( |
564 machine()->postEvent( |
565 HsMenuEventFactory::createArrangeCollectionEvent( |
565 HsMenuEventFactory::createArrangeCollectionEvent( |
566 topItemId, |
566 topItemId, |