23 #include <hbabstractviewitem.h> |
23 #include <hbabstractviewitem.h> |
24 #include <hsmenueventfactory.h> |
24 #include <hsmenueventfactory.h> |
25 #include <hbinstance.h> |
25 #include <hbinstance.h> |
26 #include <caentry.h> |
26 #include <caentry.h> |
27 #include <hbsearchpanel.h> |
27 #include <hbsearchpanel.h> |
|
28 #include <HbScrollBar> |
|
29 #include <HbIndexFeedback> |
28 |
30 |
29 #include "hsmenuitemmodel.h" |
31 #include "hsmenuitemmodel.h" |
30 #include "cadefs.h" |
32 #include "cadefs.h" |
31 #include "hsallappsstate.h" |
33 #include "hsallappsstate.h" |
32 #include "hsaddappstocollectionstate.h" |
34 #include "hsaddappstocollectionstate.h" |
76 */ |
78 */ |
77 HsAllAppsState::HsAllAppsState(HsMenuViewBuilder &menuViewBuilder, |
79 HsAllAppsState::HsAllAppsState(HsMenuViewBuilder &menuViewBuilder, |
78 HsMenuModeWrapper &menuMode, |
80 HsMenuModeWrapper &menuMode, |
79 HsMainWindow &mainWindow, |
81 HsMainWindow &mainWindow, |
80 QState *parent) : |
82 QState *parent) : |
81 QState(parent), mSortAttribute(AscendingNameHsSortAttribute), |
83 HsBaseViewState(parent), mSortAttribute(AscendingNameHsSortAttribute), |
82 mCollectionsSortAttribute(LatestOnTopHsSortAttribute), |
84 mCollectionsSortAttribute(LatestOnTopHsSortAttribute), |
83 mMenuView(menuViewBuilder, HsAllAppsContext), |
85 mMenuView(menuViewBuilder, HsAllAppsContext), |
84 mMenuMode(menuMode), |
86 mMenuMode(menuMode), |
85 mAllAppsModel(0), |
87 mAllAppsModel(0), |
86 mMainWindow(mainWindow), |
88 mMainWindow(mainWindow), |
125 connect(mSecondarySoftkeyAction, SIGNAL(triggered()), |
127 connect(mSecondarySoftkeyAction, SIGNAL(triggered()), |
126 SIGNAL(toAppLibraryState())); |
128 SIGNAL(toAppLibraryState())); |
127 |
129 |
128 mAllAppsModel = HsMenuService::getAllApplicationsModel(mSortAttribute); |
130 mAllAppsModel = HsMenuService::getAllApplicationsModel(mSortAttribute); |
129 mMenuView.setModel(mAllAppsModel); |
131 mMenuView.setModel(mAllAppsModel); |
|
132 |
|
133 mMenuView.listView()->verticalScrollBar()->setInteractive(true); |
|
134 HbIndexFeedback *indexFeedback = new HbIndexFeedback(mMenuView.view()); |
|
135 indexFeedback->setIndexFeedbackPolicy(HbIndexFeedback::IndexFeedbackSingleCharacter); |
|
136 indexFeedback->setItemView(mMenuView.listView()); |
130 |
137 |
131 HSMENUTEST_FUNC_EXIT("HsAllAppsState::construct"); |
138 HSMENUTEST_FUNC_EXIT("HsAllAppsState::construct"); |
132 } |
139 } |
133 |
140 |
134 /*! |
141 /*! |
208 |
215 |
209 void HsAllAppsState::stateEntered() |
216 void HsAllAppsState::stateEntered() |
210 { |
217 { |
211 qDebug("AllAppsState::stateEntered()"); |
218 qDebug("AllAppsState::stateEntered()"); |
212 HSMENUTEST_FUNC_ENTRY("HsAllAppsState::stateEntered"); |
219 HSMENUTEST_FUNC_ENTRY("HsAllAppsState::stateEntered"); |
213 |
220 |
214 mMainWindow.setCurrentView(mMenuView); |
221 mMainWindow.setCurrentView(mMenuView); |
215 mMenuView.activate(); |
222 mMenuView.activate(); |
216 |
223 |
217 HSMENUTEST_FUNC_EXIT("HsAllAppsState::stateEntered"); |
224 HSMENUTEST_FUNC_EXIT("HsAllAppsState::stateEntered"); |
218 } |
225 } |
219 |
226 |
220 /*! |
227 /*! |
221 Slot invoked when add mode entered. |
228 Slot invoked when add mode entered. |
222 */ |
229 */ |
223 void HsAllAppsState::normalModeEntered() |
230 void HsAllAppsState::normalModeEntered() |
224 { |
231 { |
225 setMenuOptions(); |
232 setMenuOptions(); |
226 |
233 connect(&mMainWindow, SIGNAL(viewIsReady()), |
|
234 &mMainWindow, SLOT(saveActivity()), |
|
235 Qt::UniqueConnection); |
227 connect(&mMenuView, |
236 connect(&mMenuView, |
228 SIGNAL(activated(QModelIndex)), |
237 SIGNAL(activated(QModelIndex)), |
229 SLOT(listItemActivated(QModelIndex))); |
238 SLOT(listItemActivated(QModelIndex))); |
230 connect(&mMenuView, |
239 connect(&mMenuView, |
231 SIGNAL(longPressed(HbAbstractViewItem *, QPointF)), |
240 SIGNAL(longPressed(HbAbstractViewItem *, QPointF)), |
291 void HsAllAppsState::listItemActivated(const QModelIndex &index) |
310 void HsAllAppsState::listItemActivated(const QModelIndex &index) |
292 { |
311 { |
293 HSMENUTEST_FUNC_ENTRY("HsAllAppsState::listItemActivated"); |
312 HSMENUTEST_FUNC_ENTRY("HsAllAppsState::listItemActivated"); |
294 |
313 |
295 QSharedPointer<const CaEntry> entry = mAllAppsModel->entry(index); |
314 QSharedPointer<const CaEntry> entry = mAllAppsModel->entry(index); |
296 |
315 |
297 if (entry->entryTypeName() == widgetTypeName()) { |
316 if (entry->entryTypeName() == widgetTypeName()) { |
298 machine()->postEvent( |
317 EntryFlags flags = index.data(CaItemModel::FlagsRole).value< |
299 HsMenuEventFactory::createPreviewHSWidgetEvent( |
318 EntryFlags> (); |
300 entry->id(), entry->entryTypeName(), entry->attribute( |
319 if (!(flags & UninstallEntryFlag)) { |
301 widgetUriAttributeName()), entry->attribute( |
320 machine()->postEvent( |
302 widgetLibraryAttributeName()))); |
321 HsMenuEventFactory::createPreviewHSWidgetEvent( |
303 |
322 entry->id(), entry->entryTypeName(), entry->attribute( |
304 const int itemId = index.data(CaItemModel::IdRole).toInt(); |
323 widgetUriAttributeName()), entry->attribute( |
305 HsMenuService::touch(itemId); |
324 widgetLibraryAttributeName()))); |
|
325 |
|
326 const int itemId = index.data(CaItemModel::IdRole).toInt(); |
|
327 HsMenuService::touch(itemId); |
|
328 } |
306 } else { |
329 } else { |
307 QVariant data = mAllAppsModel->data(index, CaItemModel::IdRole); |
330 QVariant data = mAllAppsModel->data(index, CaItemModel::IdRole); |
308 HsMenuService::executeAction(data.toInt()); |
331 int errCode = HsMenuService::executeAction(data.toInt()); |
309 } |
332 if (errCode != 0) { |
310 |
333 createApplicationLaunchFailMessage(errCode,index.data(CaItemModel::IdRole).toInt()); |
|
334 } |
|
335 } |
|
336 |
311 mMenuView.setSearchPanelVisible(false); |
337 mMenuView.setSearchPanelVisible(false); |
312 |
338 |
313 HSMENUTEST_FUNC_EXIT("HsAllAppsState::listItemActivated"); |
339 HSMENUTEST_FUNC_EXIT("HsAllAppsState::listItemActivated"); |
314 } |
340 } |
315 |
341 |
332 void HsAllAppsState::listItemLongPressed(HbAbstractViewItem *item, |
358 void HsAllAppsState::listItemLongPressed(HbAbstractViewItem *item, |
333 const QPointF &coords) |
359 const QPointF &coords) |
334 { |
360 { |
335 HSMENUTEST_FUNC_ENTRY("HsAllAppsState::listItemLongPressed"); |
361 HSMENUTEST_FUNC_ENTRY("HsAllAppsState::listItemLongPressed"); |
336 |
362 |
337 |
|
338 // create context menu |
|
339 mContextMenu = new HbMenu; |
|
340 |
|
341 HbAction *addToHomeScreenAction = mContextMenu->addAction(hbTrId( |
|
342 "txt_applib_menu_add_to_home_screen")); |
|
343 addToHomeScreenAction->setData(AddToHomeScreenContextAction); |
|
344 |
|
345 HbAction *addToCollectionAction = mContextMenu->addAction(hbTrId( |
|
346 "txt_applib_menu_add_to_collection")); |
|
347 addToCollectionAction->setData(AddToCollectionContextAction); |
|
348 |
|
349 HbAction *uninstallAction = mContextMenu->addAction(hbTrId( |
|
350 "txt_common_menu_delete")); |
|
351 uninstallAction->setData(UninstallContextAction); |
|
352 HbAction *appSettingsAction(NULL); |
|
353 HbAction *appDetailsAction(NULL); |
|
354 |
|
355 // check conditions and hide irrelevant menu items |
|
356 |
|
357 QSharedPointer<const CaEntry> entry = mAllAppsModel->entry(item->modelIndex()); |
|
358 EntryFlags flags = item->modelIndex().data( |
363 EntryFlags flags = item->modelIndex().data( |
359 CaItemModel::FlagsRole).value<EntryFlags> (); |
364 CaItemModel::FlagsRole).value<EntryFlags> (); |
360 |
365 |
361 if (!(entry->attribute(appSettingsPlugin()).isEmpty())) { |
366 if (!(flags & UninstallEntryFlag)) { |
362 appSettingsAction = mContextMenu->addAction(hbTrId( |
367 // create context menu |
363 "txt_common_menu_settings")); |
368 mContextMenu = new HbMenu; |
364 appSettingsAction->setData(AppSettingContextAction); |
369 |
365 } |
370 HbAction *addToHomeScreenAction = mContextMenu->addAction( |
366 if (!(entry->attribute(componentIdAttributeName()).isEmpty()) && |
371 hbTrId("txt_applib_menu_add_to_home_screen")); |
367 (flags & RemovableEntryFlag) ) { |
372 addToHomeScreenAction->setData(AddToHomeScreenContextAction); |
368 appDetailsAction = mContextMenu->addAction(hbTrId( |
373 |
369 "txt_common_menu_details")); |
374 HbAction *addToCollectionAction = mContextMenu->addAction( |
370 appDetailsAction->setData(AppDetailsContextAction); |
375 hbTrId("txt_applib_menu_add_to_collection")); |
371 } |
376 addToCollectionAction->setData(AddToCollectionContextAction); |
372 |
377 |
373 if (!(flags & RemovableEntryFlag)) { |
378 HbAction *uninstallAction = mContextMenu->addAction( |
374 uninstallAction->setVisible(false); |
379 hbTrId("txt_common_menu_delete")); |
375 } |
380 uninstallAction->setData(UninstallContextAction); |
376 |
381 HbAction *appSettingsAction(NULL); |
377 mContextModelIndex = item->modelIndex(); |
382 HbAction *appDetailsAction(NULL); |
378 mContextMenu->setPreferredPos(coords); |
383 |
379 mContextMenu->setAttribute(Qt::WA_DeleteOnClose); |
384 // check conditions and hide irrelevant menu items |
380 mContextMenu->open(this, SLOT(contextMenuAction(HbAction*))); |
385 QSharedPointer<const CaEntry> entry = mAllAppsModel->entry(item->modelIndex()); |
|
386 |
|
387 if (!(entry->attribute(appSettingsPlugin()).isEmpty())) { |
|
388 appSettingsAction = mContextMenu->addAction( |
|
389 hbTrId("txt_common_menu_settings")); |
|
390 appSettingsAction->setData(AppSettingContextAction); |
|
391 } |
|
392 if (!(entry->attribute(componentIdAttributeName()).isEmpty()) && |
|
393 (flags & RemovableEntryFlag) ) { |
|
394 appDetailsAction = mContextMenu->addAction( |
|
395 hbTrId("txt_common_menu_details")); |
|
396 appDetailsAction->setData(AppDetailsContextAction); |
|
397 } |
|
398 |
|
399 if (!(flags & RemovableEntryFlag)) { |
|
400 uninstallAction->setVisible(false); |
|
401 } |
|
402 |
|
403 mContextModelIndex = item->modelIndex(); |
|
404 mContextMenu->setPreferredPos(coords); |
|
405 mContextMenu->setAttribute(Qt::WA_DeleteOnClose); |
|
406 mContextMenu->open(this, SLOT(contextMenuAction(HbAction*))); |
|
407 } |
381 |
408 |
382 |
409 |
383 HSMENUTEST_FUNC_EXIT("HsAllAppsState::listItemLongPressed"); |
410 HSMENUTEST_FUNC_EXIT("HsAllAppsState::listItemLongPressed"); |
384 } |
411 } |
385 |
412 |
404 HsMenuEventFactory::createAddAppsFromApplicationsViewEvent( |
431 HsMenuEventFactory::createAddAppsFromApplicationsViewEvent( |
405 mSortAttribute, mCollectionsSortAttribute, itemId)); |
432 mSortAttribute, mCollectionsSortAttribute, itemId)); |
406 break; |
433 break; |
407 case UninstallContextAction: |
434 case UninstallContextAction: |
408 machine()->postEvent( |
435 machine()->postEvent( |
409 HsMenuEventFactory::createUninstallApplicationEvent( |
436 HsMenuEventFactory::createUninstallApplicationEvent(itemId)); |
410 itemId)); |
|
411 break; |
437 break; |
412 case AppSettingContextAction: |
438 case AppSettingContextAction: |
413 machine()->postEvent( |
439 machine()->postEvent( |
414 HsMenuEventFactory::createAppSettingsViewEvent(itemId)); |
440 HsMenuEventFactory::createAppSettingsViewEvent(itemId)); |
415 break; |
441 break; |