32 #include "caentry.h" |
32 #include "caentry.h" |
33 #include "hscollectionstate.h" |
33 #include "hscollectionstate.h" |
34 #include "hsaddappstocollectionstate.h" |
34 #include "hsaddappstocollectionstate.h" |
35 #include "hsapp_defs.h" |
35 #include "hsapp_defs.h" |
36 |
36 |
37 // --------------------------------------------------------------------------- |
37 /*! |
38 // --------------------------------------------------------------------------- |
38 Constructor. |
39 // |
39 \param menuView Menu view. |
|
40 \param parent Owner. |
|
41 */ |
40 HsCollectionState::HsCollectionState(HsMenuView &menuView, QState *parent) : |
42 HsCollectionState::HsCollectionState(HsMenuView &menuView, QState *parent) : |
41 QState(parent), |
43 QState(parent), |
42 mSortAttribute(LatestOnTopHsSortAttribute), |
44 mSortAttribute(LatestOnTopHsSortAttribute), |
43 mCollectionsSortAttribute(CustomHsSortAttribute), |
45 mCollectionsSortAttribute(CustomHsSortAttribute), |
44 mCollectionId(-1), mMenuView(menuView), |
46 mCollectionId(-1), mMenuView(menuView), |
45 mCollectionModel(0), mOptions(0) |
47 mCollectionModel(0), mOptions(0) |
46 { |
48 { |
47 construct(); |
49 construct(); |
48 } |
50 } |
49 |
51 |
50 // --------------------------------------------------------------------------- |
52 /*! |
51 // --------------------------------------------------------------------------- |
53 Constructs contained objects. |
52 // |
54 */ |
53 void HsCollectionState::construct() |
55 void HsCollectionState::construct() |
54 { |
56 { |
55 HSMENUTEST_FUNC_ENTRY("HsCollectionState::construct"); |
57 HSMENUTEST_FUNC_ENTRY("HsCollectionState::construct"); |
56 setObjectName(this->parent()->objectName() + "/collectionstate"); |
58 const QString parentName = |
|
59 parent() != 0 ? parent()->objectName() : QString(""); |
|
60 setObjectName(parentName + "/collectionstate"); |
57 |
61 |
58 //new action for backstepping |
62 //new action for backstepping |
59 mSecondarySoftkeyAction = new HbAction(Hb::BackAction, this); |
63 mSecondarySoftkeyAction = new HbAction(Hb::BackAction, this); |
60 connect(this, SIGNAL(entered()),SLOT(stateEntered())); |
64 connect(this, SIGNAL(entered()),SLOT(stateEntered())); |
61 connect(this, SIGNAL(exited()),SLOT(stateExited())); |
65 connect(this, SIGNAL(exited()),SLOT(stateExited())); |
62 HSMENUTEST_FUNC_EXIT("HsCollectionState::construct"); |
66 HSMENUTEST_FUNC_EXIT("HsCollectionState::construct"); |
63 } |
67 } |
64 |
68 |
65 // --------------------------------------------------------------------------- |
69 /*! |
66 // --------------------------------------------------------------------------- |
70 Destructor. |
67 // |
71 */ |
68 HsCollectionState::~HsCollectionState() |
72 HsCollectionState::~HsCollectionState() |
69 { |
73 { |
70 delete mCollectionModel; |
74 delete mCollectionModel; |
71 } |
75 } |
72 |
76 |
73 |
77 |
74 // --------------------------------------------------------------------------- |
78 /*! |
75 // --------------------------------------------------------------------------- |
79 Sets entry event. |
76 // |
80 \param event entry event. |
|
81 */ |
77 void HsCollectionState::onEntry(QEvent *event) |
82 void HsCollectionState::onEntry(QEvent *event) |
78 { |
83 { |
79 qDebug("HsCollectionState::onEntry()"); |
84 qDebug("HsCollectionState::onEntry()"); |
80 HSMENUTEST_FUNC_ENTRY("HsCollectionState::onEntry"); |
85 HSMENUTEST_FUNC_ENTRY("HsCollectionState::onEntry"); |
81 QState::onEntry(event); |
86 QState::onEntry(event); |
88 } |
93 } |
89 |
94 |
90 HSMENUTEST_FUNC_EXIT("HsCollectionState::onEntry"); |
95 HSMENUTEST_FUNC_EXIT("HsCollectionState::onEntry"); |
91 } |
96 } |
92 |
97 |
93 // --------------------------------------------------------------------------- |
98 /*! |
94 // --------------------------------------------------------------------------- |
99 Slot invoked when a state is entered. |
95 // |
100 */ |
96 void HsCollectionState::stateEntered() |
101 void HsCollectionState::stateEntered() |
97 { |
102 { |
98 HSMENUTEST_FUNC_ENTRY("HsCollectionState::stateEntered"); |
103 HSMENUTEST_FUNC_ENTRY("HsCollectionState::stateEntered"); |
99 if (!mCollectionModel) { |
104 if (!mCollectionModel) { |
100 mCollectionModel = HsMenuService::getCollectionModel(mCollectionId, |
105 mCollectionModel = HsMenuService::getCollectionModel(mCollectionId, |
173 mOptions->setParent(this); |
178 mOptions->setParent(this); |
174 mMenuView.view()->setMenu(mOptions); |
179 mMenuView.view()->setMenu(mOptions); |
175 } |
180 } |
176 mOldNavigationAction = mMenuView.view()->navigationAction(); |
181 mOldNavigationAction = mMenuView.view()->navigationAction(); |
177 mMenuView.view()->setNavigationAction(mSecondarySoftkeyAction); |
182 mMenuView.view()->setNavigationAction(mSecondarySoftkeyAction); |
178 |
183 |
179 makeConnect(); |
184 makeConnect(); |
180 HSMENUTEST_FUNC_EXIT("HsCollectionState::stateEntered"); |
185 HSMENUTEST_FUNC_EXIT("HsCollectionState::stateEntered"); |
181 } |
186 } |
182 |
187 |
183 // --------------------------------------------------------------------------- |
188 /*! |
184 // --------------------------------------------------------------------------- |
189 Slot invoked when a state is exited. |
185 // |
190 */ |
186 void HsCollectionState::stateExited() |
191 void HsCollectionState::stateExited() |
187 { |
192 { |
188 HSMENUTEST_FUNC_ENTRY("HsCollectionState::stateExited"); |
193 HSMENUTEST_FUNC_ENTRY("HsCollectionState::stateExited"); |
|
194 mMenuView.setSearchPanelVisible(false); |
|
195 |
189 makeDisconnect(); |
196 makeDisconnect(); |
190 |
197 |
191 mOptions = NULL; |
198 mOptions = NULL; |
192 |
199 |
193 mMenuView.view()->setMenu(NULL); |
200 mMenuView.view()->setMenu(NULL); |
198 |
205 |
199 HSMENUTEST_FUNC_EXIT("HsCollectionState::stateExited"); |
206 HSMENUTEST_FUNC_EXIT("HsCollectionState::stateExited"); |
200 qDebug("CollectionState::stateExited()"); |
207 qDebug("CollectionState::stateExited()"); |
201 } |
208 } |
202 |
209 |
203 // --------------------------------------------------------------------------- |
210 /*! |
204 // --------------------------------------------------------------------------- |
211 Perform all signal connections. |
205 // |
212 */ |
206 void HsCollectionState::makeConnect() |
213 void HsCollectionState::makeConnect() |
207 { |
214 { |
208 connect(mSecondarySoftkeyAction, SIGNAL(triggered()), |
215 connect(mSecondarySoftkeyAction, SIGNAL(triggered()), |
209 SLOT(backSteppingAction())); |
216 SLOT(backSteppingAction())); |
210 connect(&mMenuView, SIGNAL(activated(QModelIndex)), |
217 connect(&mMenuView, SIGNAL(activated(QModelIndex)), |
212 connect(&mMenuView, SIGNAL(longPressed(HbAbstractViewItem *, QPointF)), |
219 connect(&mMenuView, SIGNAL(longPressed(HbAbstractViewItem *, QPointF)), |
213 SLOT(listItemLongPressed(HbAbstractViewItem *, QPointF))); |
220 SLOT(listItemLongPressed(HbAbstractViewItem *, QPointF))); |
214 connect(mCollectionModel, SIGNAL(modelReset()),SLOT(updateLabel())); |
221 connect(mCollectionModel, SIGNAL(modelReset()),SLOT(updateLabel())); |
215 } |
222 } |
216 |
223 |
217 // --------------------------------------------------------------------------- |
224 /*! |
218 // --------------------------------------------------------------------------- |
225 Perform all signal disconnections. |
219 // |
226 */ |
220 void HsCollectionState::makeDisconnect() |
227 void HsCollectionState::makeDisconnect() |
221 { |
228 { |
222 disconnect(mSecondarySoftkeyAction, SIGNAL(triggered()), |
229 disconnect(mSecondarySoftkeyAction, SIGNAL(triggered()), |
223 this, SLOT(backSteppingAction())); |
230 this, SLOT(backSteppingAction())); |
224 |
231 |
239 bool HsCollectionState::openTaskSwitcher() |
246 bool HsCollectionState::openTaskSwitcher() |
240 { |
247 { |
241 return HsMenuService::launchTaskSwitcher(); |
248 return HsMenuService::launchTaskSwitcher(); |
242 } |
249 } |
243 |
250 |
244 // --------------------------------------------------------------------------- |
251 /*! |
245 // --------------------------------------------------------------------------- |
252 Slot connected to List widget. |
246 // |
253 \param index Model index of the activated item. |
|
254 */ |
247 void HsCollectionState::listItemActivated(const QModelIndex &index) |
255 void HsCollectionState::listItemActivated(const QModelIndex &index) |
248 { |
256 { |
249 HSMENUTEST_FUNC_ENTRY("HsCollectionState::listItemActivated"); |
257 HSMENUTEST_FUNC_ENTRY("HsCollectionState::listItemActivated"); |
250 |
258 |
251 const CaEntry *entry = mCollectionModel->entry(index); |
259 QSharedPointer<const CaEntry> entry = mCollectionModel->entry(index); |
252 |
260 |
253 if (entry->entryTypeName() == widgetTypeName()) { |
261 if (entry->entryTypeName() == widgetTypeName()) { |
254 machine()->postEvent( |
262 machine()->postEvent( |
255 HsMenuEventFactory::createPreviewHSWidgetEvent( |
263 HsMenuEventFactory::createPreviewHSWidgetEvent( |
256 entry->id(), entry->entryTypeName(), entry->attribute( |
264 entry->id(), entry->entryTypeName(), entry->attribute( |
269 } |
277 } |
270 |
278 |
271 /*! |
279 /*! |
272 Handles long-item-pressed event in all apps view by showing context menu |
280 Handles long-item-pressed event in all apps view by showing context menu |
273 \param item the event pertains to |
281 \param item the event pertains to |
274 \param position at which context menu is shown |
282 \param coords press point coordinates. |
275 \retval void |
283 \retval void |
276 */ |
284 */ |
277 void HsCollectionState::listItemLongPressed(HbAbstractViewItem *item, |
285 void HsCollectionState::listItemLongPressed(HbAbstractViewItem *item, |
278 const QPointF &coords) |
286 const QPointF &coords) |
279 { |
287 { |
280 Q_UNUSED(item); |
288 Q_UNUSED(item); |
281 HSMENUTEST_FUNC_ENTRY("HsCollectionState::listItemLongPressed"); |
289 HSMENUTEST_FUNC_ENTRY("HsCollectionState::listItemLongPressed"); |
282 mMenuView.setSearchPanelVisible(false); |
|
283 int itemId = item->modelIndex().data(CaItemModel::IdRole).toInt(); |
290 int itemId = item->modelIndex().data(CaItemModel::IdRole).toInt(); |
284 // create context menu |
291 // create context menu |
285 HbMenu *menu = new HbMenu(); |
292 HbMenu *menu = new HbMenu(); |
286 |
293 |
287 HbAction *addShortcutAction = menu->addAction(hbTrId( |
294 HbAction *addShortcutAction = menu->addAction(hbTrId( |
288 "txt_applib_menu_add_to_home_screen")); |
295 "txt_applib_menu_add_to_home_screen")); |
289 HbAction *addToCollection = menu->addAction(hbTrId( |
296 HbAction *addToCollection = menu->addAction(hbTrId( |
290 "txt_applib_menu_add_to_collection")); |
297 "txt_applib_menu_add_to_collection")); |
291 HbAction *removeAction(NULL); |
298 HbAction *removeAction(NULL); |
292 HbAction *uninstallAction(NULL); |
299 HbAction *uninstallAction(NULL); |
|
300 HbAction *appSettingsAction(NULL); |
293 // we do not add remove option in collection download menu |
301 // we do not add remove option in collection download menu |
294 // check conditions and hide irrelevant menu items |
302 // check conditions and hide irrelevant menu items |
295 if (mCollectionType != collectionDownloadedTypeName()) { |
303 if (mCollectionType != collectionDownloadedTypeName()) { |
296 removeAction = menu->addAction( |
304 removeAction = menu->addAction( |
297 hbTrId("txt_applib_menu_remove_from_collection")); |
305 hbTrId("txt_applib_menu_remove_from_collection")); |
301 EntryFlags> (); |
309 EntryFlags> (); |
302 |
310 |
303 if ((flags & RemovableEntryFlag)) { |
311 if ((flags & RemovableEntryFlag)) { |
304 uninstallAction = menu->addAction(hbTrId("txt_common_menu_delete")); |
312 uninstallAction = menu->addAction(hbTrId("txt_common_menu_delete")); |
305 } |
313 } |
306 |
314 QSharedPointer<const CaEntry> entry = mCollectionModel->entry(item->modelIndex()); |
|
315 |
|
316 if (!(entry->attribute(appSettingsPlugin()).isEmpty())) { |
|
317 appSettingsAction = menu->addAction(hbTrId( |
|
318 "txt_common_menu_settings")); |
|
319 } |
307 // choose proper action |
320 // choose proper action |
308 if (HbAction *selectedAction = menu->exec(coords)) { |
321 if (HbAction *selectedAction = menu->exec(coords)) { |
|
322 |
309 if (selectedAction == addShortcutAction) { |
323 if (selectedAction == addShortcutAction) { |
310 addElementToHomeScreen(item->modelIndex()); |
324 addElementToHomeScreen(item->modelIndex()); |
311 } else if (selectedAction == addToCollection) { |
325 } else if (selectedAction == addToCollection) { |
312 machine()->postEvent( |
326 machine()->postEvent( |
313 HsMenuEventFactory::createAddAppsFromCallectionViewEvent( |
327 HsMenuEventFactory::createAddAppsFromCallectionViewEvent( |
316 HsMenuService::executeAction(itemId, removeActionIdentifier()); |
330 HsMenuService::executeAction(itemId, removeActionIdentifier()); |
317 } else if (selectedAction == removeAction) { |
331 } else if (selectedAction == removeAction) { |
318 machine()->postEvent( |
332 machine()->postEvent( |
319 HsMenuEventFactory::createRemoveAppFromCollectionEvent( |
333 HsMenuEventFactory::createRemoveAppFromCollectionEvent( |
320 itemId, mCollectionId)); |
334 itemId, mCollectionId)); |
|
335 } else if (selectedAction == appSettingsAction) { |
|
336 const int itemId = |
|
337 item->modelIndex().data(CaItemModel::IdRole).toInt(); |
|
338 QMap<QString, QString> attributes = entry->attributes(); |
|
339 machine()->postEvent( |
|
340 HsMenuEventFactory::createAppSettingsViewEvent(itemId)); |
321 } |
341 } |
|
342 |
|
343 mMenuView.setSearchPanelVisible(false); |
322 } |
344 } |
323 delete menu; |
345 delete menu; |
324 HSMENUTEST_FUNC_EXIT("HsCollectionState::listItemLongPressed"); |
346 HSMENUTEST_FUNC_EXIT("HsCollectionState::listItemLongPressed"); |
325 } |
347 } |
326 |
348 |
327 // --------------------------------------------------------------------------- |
349 /*! |
328 // --------------------------------------------------------------------------- |
350 Menu add applications action slot |
329 // |
351 */ |
330 void HsCollectionState::addAppsAction() |
352 void HsCollectionState::addAppsAction() |
331 { |
353 { |
332 // Add applications |
354 // Add applications |
333 machine()->postEvent( |
355 machine()->postEvent( |
334 HsMenuEventFactory::createAddAppsFromCallectionViewEvent( |
356 HsMenuEventFactory::createAddAppsFromCallectionViewEvent( |
335 mCollectionId)); |
357 mCollectionId)); |
336 } |
358 } |
337 |
359 |
338 // --------------------------------------------------------------------------- |
360 /*! |
339 // --------------------------------------------------------------------------- |
361 Menu add shortcut action slot |
340 // |
362 */ |
341 void HsCollectionState::addCollectionShortcutToHomeScreenAction() |
363 void HsCollectionState::addCollectionShortcutToHomeScreenAction() |
342 { |
364 { |
343 machine()->postEvent(HsMenuEventFactory::createAddToHomeScreenEvent( |
365 machine()->postEvent(HsMenuEventFactory::createAddToHomeScreenEvent( |
344 mCollectionId)); |
366 mCollectionId)); |
345 } |
367 } |
346 |
368 |
347 // --------------------------------------------------------------------------- |
369 /*! |
348 // --------------------------------------------------------------------------- |
370 Menu rename action slot |
349 // |
371 */ |
350 void HsCollectionState::renameAction() |
372 void HsCollectionState::renameAction() |
351 { |
373 { |
352 machine()->postEvent(HsMenuEventFactory::createRenameCollectionEvent( |
374 machine()->postEvent(HsMenuEventFactory::createRenameCollectionEvent( |
353 mCollectionId)); |
375 mCollectionId)); |
354 } |
376 } |
355 |
377 |
356 // --------------------------------------------------------------------------- |
378 /*! |
357 // --------------------------------------------------------------------------- |
379 Menu delete action slot |
358 // |
380 */ |
359 void HsCollectionState::deleteAction() |
381 void HsCollectionState::deleteAction() |
360 { |
382 { |
361 machine()->postEvent(HsMenuEventFactory::createDeleteCollectionEvent( |
383 machine()->postEvent(HsMenuEventFactory::createDeleteCollectionEvent( |
362 mCollectionId)); |
384 mCollectionId)); |
363 } |
385 } |
364 |
386 |
365 // --------------------------------------------------------------------------- |
387 /*! |
366 // --------------------------------------------------------------------------- |
388 Menu softkey back action slot |
367 // |
389 */ |
368 void HsCollectionState::backSteppingAction() |
390 void HsCollectionState::backSteppingAction() |
369 { |
391 { |
370 machine()->postEvent(HsMenuEventFactory::createOpenAppLibraryEvent()); |
392 machine()->postEvent(HsMenuEventFactory::createOpenAppLibraryEvent()); |
371 } |
393 } |
372 |
394 |
373 // --------------------------------------------------------------------------- |
395 /*! |
374 // --------------------------------------------------------------------------- |
396 Updates label |
375 // |
397 */ |
376 void HsCollectionState::updateLabel() |
398 void HsCollectionState::updateLabel() |
377 { |
399 { |
378 HSMENUTEST_FUNC_ENTRY("HsCollectionState::updateLabel"); |
400 HSMENUTEST_FUNC_ENTRY("HsCollectionState::updateLabel"); |
379 if (mCollectionModel) { |
401 if (mCollectionModel) { |
380 mMenuView.setLabel( |
402 mMenuView.setLabel( |
388 \param index of an item to be added to homescreen |
410 \param index of an item to be added to homescreen |
389 \retval void |
411 \retval void |
390 */ |
412 */ |
391 void HsCollectionState::addElementToHomeScreen(const QModelIndex &index) |
413 void HsCollectionState::addElementToHomeScreen(const QModelIndex &index) |
392 { |
414 { |
393 const CaEntry *entry = mCollectionModel->entry(index); |
415 QSharedPointer<const CaEntry> entry = mCollectionModel->entry(index); |
394 |
416 |
395 QMap<QString, QString> attributes = entry->attributes(); |
417 QMap<QString, QString> attributes = entry->attributes(); |
396 |
418 |
397 machine()->postEvent( |
419 machine()->postEvent( |
398 HsMenuEventFactory::createAddToHomeScreenEvent( |
420 HsMenuEventFactory::createAddToHomeScreenEvent( |
399 entry->id(), |
421 entry->id())); |
400 entry->entryTypeName(), |
|
401 entry->attribute(widgetUriAttributeName()), |
|
402 entry->attribute(widgetLibraryAttributeName()), |
|
403 &attributes)); |
|
404 } |
422 } |
405 |
423 |
406 /*! |
424 /*! |
407 A Slot called when an action for sorting (latest |
425 A Slot called when an action for sorting (latest |
408 on top) is invoked for Downloaded collection. |
426 on top) is invoked for Downloaded collection. |