64 HsMenuModeWrapper &menuMode, |
64 HsMenuModeWrapper &menuMode, |
65 HsMainWindow &mainWindow, |
65 HsMainWindow &mainWindow, |
66 QState *parent) : |
66 QState *parent) : |
67 HsBaseViewState(mainWindow, menuMode, parent), |
67 HsBaseViewState(mainWindow, menuMode, parent), |
68 mAddModeProxyModel(0), |
68 mAddModeProxyModel(0), |
69 mSortAttribute(AscendingNameHsSortAttribute) |
69 mSortAttribute(Hs::AscendingNameHsSortAttribute) |
70 { |
70 { |
71 initialize(menuViewBuilder, HsAllAppsContext); |
71 initialize(menuViewBuilder, HsAllAppsContext); |
72 construct(); |
72 construct(); |
73 mAddModeProxyModel = new HsAddModeProxyModel(this); |
73 mAddModeProxyModel = new HsAddModeProxyModel(this); |
74 mAddModeProxyModel->setSourceModel(mModel); |
74 mAddModeProxyModel->setSourceModel(mModel); |
75 } |
75 } |
76 |
76 |
77 /*! |
77 /*! |
78 Constructs contained objects. |
78 Constructs contained objects. |
135 foreach(QAction *action, sortMenu->actions()) { |
135 foreach(QAction *action, sortMenu->actions()) { |
136 action->setCheckable(true); |
136 action->setCheckable(true); |
137 } |
137 } |
138 int currentSortingPosition(-1); |
138 int currentSortingPosition(-1); |
139 switch (mSortAttribute) { |
139 switch (mSortAttribute) { |
140 case AscendingNameHsSortAttribute: |
140 case Hs::AscendingNameHsSortAttribute: |
141 currentSortingPosition = 0; |
141 currentSortingPosition = 0; |
142 break; |
142 break; |
143 case DescendingNameHsSortAttribute: |
143 case Hs::DescendingNameHsSortAttribute: |
144 currentSortingPosition = 1; |
144 currentSortingPosition = 1; |
145 break; |
145 break; |
146 default: |
146 default: |
147 break; |
147 break; |
148 } |
148 } |
166 Slot invoked when normal mode entered. |
166 Slot invoked when normal mode entered. |
167 */ |
167 */ |
168 void HsAllAppsState::normalModeEntered() |
168 void HsAllAppsState::normalModeEntered() |
169 { |
169 { |
170 HsBaseViewState::normalModeEntered(); |
170 HsBaseViewState::normalModeEntered(); |
171 if (mMenuView->model() != mModel) { |
|
172 mMenuView->setModel(mModel); |
|
173 } |
|
174 connect(mMenuView.data(), |
171 connect(mMenuView.data(), |
175 SIGNAL(activated(QModelIndex)), |
172 SIGNAL(activated(QModelIndex)), |
176 static_cast<HsBaseViewState*>(this), SLOT(launchItem(QModelIndex))); |
173 static_cast<HsBaseViewState*>(this), SLOT(launchItem(QModelIndex))); |
177 } |
174 } |
178 |
175 |
179 /*! |
176 /*! |
180 Slot invoked when add mode entered. |
177 Sets model for this view in depends on menuMode. |
181 */ |
178 \param menuMode menu mode |
182 void HsAllAppsState::addModeEntered() |
179 */ |
183 { |
180 void HsAllAppsState::setModel(Hs::HsMenuMode menuMode) |
184 HsBaseViewState::addModeEntered(); |
181 { |
185 if (mMenuView->model() != mAddModeProxyModel) { |
182 if (menuMode == Hs::AddHsMenuMode) { |
186 mMenuView->setModel(mAddModeProxyModel); |
183 if (mMenuView->model() != mAddModeProxyModel) { |
|
184 mMenuView->setModel(mAddModeProxyModel); |
|
185 } |
|
186 } else { |
|
187 if (mMenuView->model() != mModel) { |
|
188 mMenuView->setModel(mModel); |
|
189 } |
|
190 } |
|
191 } |
|
192 |
|
193 |
|
194 /*! |
|
195 Scrolls view to first item at top |
|
196 */ |
|
197 void HsAllAppsState::scrollToBeginning() |
|
198 { |
|
199 QAbstractItemModel* model = mMenuView->model(); |
|
200 if (model != NULL ) { |
|
201 mMenuView->listView()->scrollTo( |
|
202 model->index(0,0), HbAbstractItemView::PositionAtTop); |
187 } |
203 } |
188 } |
204 } |
189 |
205 |
190 /*! |
206 /*! |
191 Slot invoked when a state is exited. |
207 Slot invoked when a state is exited. |
196 |
212 |
197 HsBaseViewState::stateExited(); |
213 HsBaseViewState::stateExited(); |
198 |
214 |
199 HSMENUTEST_FUNC_EXIT("HsAllAppsState::stateExited"); |
215 HSMENUTEST_FUNC_EXIT("HsAllAppsState::stateExited"); |
200 qDebug("AllAppsState::stateExited()"); |
216 qDebug("AllAppsState::stateExited()"); |
201 } |
|
202 |
|
203 /*! |
|
204 Slot connected to List widget in add mode. |
|
205 \param index Model index of the activated item. |
|
206 */ |
|
207 void HsAllAppsState::addActivated(const QModelIndex &index) |
|
208 { |
|
209 mMenuView->disconnect(this); |
|
210 HSMENUTEST_FUNC_ENTRY("HsAllAppsState::addActivated"); |
|
211 addToHomeScreen(index); |
|
212 HSMENUTEST_FUNC_EXIT("HsAllAppsState::addActivated"); |
|
213 } |
|
214 |
|
215 |
|
216 /*! |
|
217 Handles context menu actions |
|
218 */ |
|
219 void HsAllAppsState::contextMenuAction(HbAction *action) |
|
220 { |
|
221 HsContextAction command = |
|
222 static_cast<HsContextAction>(action->data().toInt()); |
|
223 |
|
224 const int itemId = mContextModelIndex.data(CaItemModel::IdRole).toInt(); |
|
225 |
|
226 switch (command) { |
|
227 case AddToHomeScreenContextAction: |
|
228 addToHomeScreen(mContextModelIndex); |
|
229 break; |
|
230 case AddToCollectionContextAction: |
|
231 // Addding a specific application to |
|
232 // an existing collection via item specific menu. |
|
233 machine()->postEvent( |
|
234 HsMenuEventFactory::createAddAppsFromApplicationsViewEvent( |
|
235 mSortAttribute, itemId)); |
|
236 break; |
|
237 case UninstallContextAction: |
|
238 machine()->postEvent( |
|
239 HsMenuEventFactory::createUninstallApplicationEvent(itemId)); |
|
240 break; |
|
241 case AppSettingContextAction: |
|
242 machine()->postEvent( |
|
243 HsMenuEventFactory::createAppSettingsViewEvent(itemId)); |
|
244 break; |
|
245 case AppDetailsContextAction: |
|
246 machine()->postEvent( |
|
247 HsMenuEventFactory::createAppDetailsViewEvent(itemId)); |
|
248 break; |
|
249 case OpenContextAction: |
|
250 launchItem(mContextModelIndex); |
|
251 break; |
|
252 default: |
|
253 break; |
|
254 } |
|
255 mMenuView->hideSearchPanel(); |
|
256 } |
|
257 |
|
258 /*! |
|
259 Slot connected to List widget in add mode. |
|
260 Called when item long pressed. |
|
261 \param item View item. |
|
262 \param coords Press point coordinates. |
|
263 */ |
|
264 void HsAllAppsState::addLongPressed(HbAbstractViewItem *item, |
|
265 const QPointF &coords) |
|
266 { |
|
267 Q_UNUSED(coords); |
|
268 mMenuView->disconnect(this); |
|
269 HSMENUTEST_FUNC_ENTRY("HsAllAppsState::addLongPressed"); |
|
270 addToHomeScreen(item->modelIndex()); |
|
271 HSMENUTEST_FUNC_EXIT("HsAllAppsState::addLongPressed"); |
|
272 |
|
273 } |
217 } |
274 |
218 |
275 /*! |
219 /*! |
276 Slot called when application is adding to collection. |
220 Slot called when application is adding to collection. |
277 */ |
221 */ |
298 #ifdef COVERAGE_MEASUREMENT |
242 #ifdef COVERAGE_MEASUREMENT |
299 #pragma CTC ENDSKIP |
243 #pragma CTC ENDSKIP |
300 #endif //COVERAGE_MEASUREMENT |
244 #endif //COVERAGE_MEASUREMENT |
301 |
245 |
302 /*! |
246 /*! |
303 Triggers event so that a state adding to Home Screen is reached |
|
304 \param index of an item to be added to homescreen. |
|
305 \retval void |
|
306 */ |
|
307 void HsAllAppsState::addToHomeScreen(const QModelIndex &index) |
|
308 { |
|
309 HSMENUTEST_FUNC_ENTRY("HsAllAppsState::addToHomeScreen"); |
|
310 QSharedPointer<const CaEntry> entry = mModel->entry(index); |
|
311 |
|
312 machine()-> postEvent(HsMenuEventFactory::createAddToHomeScreenEvent( |
|
313 entry->id(), mMenuMode->getHsMenuMode(), |
|
314 mMenuMode->getHsToken())); |
|
315 |
|
316 HSMENUTEST_FUNC_EXIT("HsAllAppsState::addToHomeScreen"); |
|
317 } |
|
318 |
|
319 /*! |
|
320 Method seting context menu options. |
247 Method seting context menu options. |
321 */ |
248 */ |
322 void HsAllAppsState::setContextMenuOptions(HbAbstractViewItem *item, EntryFlags flags) |
249 void HsAllAppsState::setContextMenuOptions(HbAbstractViewItem *item, EntryFlags flags) |
323 { |
250 { |
324 HbAction *openAction = mContextMenu->addAction(hbTrId( |
251 HbAction *openAction = mContextMenu->addAction(hbTrId( |
325 "txt_common_menu_open")); |
252 "txt_common_menu_open")); |
326 openAction->setData(OpenContextAction); |
253 openAction->setData(Hs::OpenAppContextAction); |
327 |
254 |
328 HbAction *addToHomeScreenAction = mContextMenu->addAction( |
255 HbAction *addToHomeScreenAction = mContextMenu->addAction( |
329 hbTrId("txt_applib_menu_add_to_home_screen")); |
256 hbTrId("txt_applib_menu_add_to_home_screen")); |
330 addToHomeScreenAction->setData(AddToHomeScreenContextAction); |
257 addToHomeScreenAction->setData(Hs::AddToHomeScreenContextAction); |
331 |
258 |
332 HbAction *addToCollectionAction = mContextMenu->addAction( |
259 HbAction *addToCollectionAction = mContextMenu->addAction( |
333 hbTrId("txt_applib_menu_add_to_collection")); |
260 hbTrId("txt_applib_menu_add_to_collection")); |
334 addToCollectionAction->setData(AddToCollectionContextAction); |
261 |
|
262 addToCollectionAction->setData( |
|
263 Hs::AddToCollectionFromApplicationsViewContextAction); |
335 |
264 |
336 HbAction *uninstallAction = mContextMenu->addAction( |
265 HbAction *uninstallAction = mContextMenu->addAction( |
337 hbTrId("txt_common_menu_delete")); |
266 hbTrId("txt_common_menu_delete")); |
338 uninstallAction->setData(UninstallContextAction); |
267 uninstallAction->setData(Hs::UninstallContextAction); |
339 HbAction *appSettingsAction(NULL); |
268 HbAction *appSettingsAction(NULL); |
340 HbAction *appDetailsAction(NULL); |
269 HbAction *appDetailsAction(NULL); |
341 |
270 |
342 // check conditions and hide irrelevant menu items |
271 // check conditions and hide irrelevant menu items |
343 QSharedPointer<const CaEntry> entry = mModel->entry(item->modelIndex()); |
272 QSharedPointer<const CaEntry> entry = mModel->entry(item->modelIndex()); |
344 |
273 |
345 if (!(entry->attribute(appSettingsPlugin()).isEmpty())) { |
274 if (!(entry->attribute(Hs::appSettingsPlugin).isEmpty())) { |
346 appSettingsAction = mContextMenu->addAction( |
275 appSettingsAction = mContextMenu->addAction( |
347 hbTrId("txt_common_menu_settings")); |
276 hbTrId("txt_common_menu_settings")); |
348 appSettingsAction->setData(AppSettingContextAction); |
277 appSettingsAction->setData(Hs::AppSettingContextAction); |
349 } |
278 } |
350 if (!(entry->attribute(componentIdAttributeName()).isEmpty()) && |
279 if (!(entry->attribute(Hs::componentIdAttributeName).isEmpty()) && |
351 (flags & RemovableEntryFlag) ) { |
280 (flags & RemovableEntryFlag) ) { |
352 appDetailsAction = mContextMenu->addAction( |
281 appDetailsAction = mContextMenu->addAction( |
353 hbTrId("txt_common_menu_details")); |
282 hbTrId("txt_common_menu_details")); |
354 appDetailsAction->setData(AppDetailsContextAction); |
283 appDetailsAction->setData(Hs::AppDetailsContextAction); |
355 } |
284 } |
356 |
285 |
357 if (!(flags & RemovableEntryFlag)) { |
286 if (!(flags & RemovableEntryFlag)) { |
358 uninstallAction->setVisible(false); |
287 uninstallAction->setVisible(false); |
359 } |
288 } |
366 Menu ascending sort action slot. |
295 Menu ascending sort action slot. |
367 */ |
296 */ |
368 void HsAllAppsState::ascendingMenuAction() |
297 void HsAllAppsState::ascendingMenuAction() |
369 { |
298 { |
370 HSMENUTEST_FUNC_ENTRY("HsAllAppsState::ascendingMenuAction"); |
299 HSMENUTEST_FUNC_ENTRY("HsAllAppsState::ascendingMenuAction"); |
371 mSortAttribute = AscendingNameHsSortAttribute; |
300 mSortAttribute = Hs::AscendingNameHsSortAttribute; |
372 mModel->setSort(mSortAttribute); |
301 mModel->setSort(mSortAttribute); |
373 HSMENUTEST_FUNC_EXIT("HsAllAppsState::ascendingMenuAction"); |
302 HSMENUTEST_FUNC_EXIT("HsAllAppsState::ascendingMenuAction"); |
374 } |
303 } |
375 |
304 |
376 /*! |
305 /*! |
377 Menu descending sort action slot. |
306 Menu descending sort action slot. |
378 */ |
307 */ |
379 void HsAllAppsState::descendingMenuAction() |
308 void HsAllAppsState::descendingMenuAction() |
380 { |
309 { |
381 HSMENUTEST_FUNC_ENTRY("HsAllAppsState::descendingMenuAction"); |
310 HSMENUTEST_FUNC_ENTRY("HsAllAppsState::descendingMenuAction"); |
382 mSortAttribute = DescendingNameHsSortAttribute; |
311 mSortAttribute = Hs::DescendingNameHsSortAttribute; |
383 mModel->setSort(mSortAttribute); |
312 mModel->setSort(mSortAttribute); |
384 HSMENUTEST_FUNC_EXIT("HsAllAppsState::descendingMenuAction"); |
313 HSMENUTEST_FUNC_EXIT("HsAllAppsState::descendingMenuAction"); |
385 |
314 |
386 } |
315 } |