43 \lib ?library |
41 \lib ?library |
44 \see StateMachine |
42 \see StateMachine |
45 */ |
43 */ |
46 |
44 |
47 /*! |
45 /*! |
48 \var HsAllCollectionsState::mSortAttribute |
|
49 Sort order |
|
50 */ |
|
51 |
|
52 /*! |
|
53 \var HsAllCollectionsState::mMenuView |
|
54 Wrapper for All Collections View. |
|
55 */ |
|
56 |
|
57 /*! |
|
58 \var HsAllCollectionsState::mAllCollectionsModel |
|
59 Item Model for the List. |
|
60 Own. |
|
61 */ |
|
62 |
|
63 /*! |
|
64 \fn void HsAllCollectionsState::sortOrderChanged(HsSortAttribute sortAttribute); |
|
65 Signal emitted when sort order is changed. |
|
66 \param sortOrder new sort order. |
|
67 */ |
|
68 |
|
69 /*! |
|
70 Constructor. |
46 Constructor. |
71 \param menuViewBuilder Menu view builder. |
47 \param menuViewBuilder Menu view builder. |
72 \param menuMode reference to object representing menu mode (add mode on/add mode off). |
48 \param menuMode reference to object representing menu mode (add mode on/add mode off). |
73 \param parent Owner. |
49 \param parent Owner. |
74 */ |
50 */ |
75 HsAllCollectionsState::HsAllCollectionsState( |
51 HsAllCollectionsState::HsAllCollectionsState( |
76 HsMenuViewBuilder &menuViewBuilder, |
52 HsMenuViewBuilder &menuViewBuilder, |
77 HsMenuModeWrapper &menuMode, |
53 HsMenuModeWrapper &menuMode, |
78 HsMainWindow &mainWindow, |
54 HsMainWindow &mainWindow, |
79 QState *parent): |
55 QState *parent): |
80 HsBaseViewState(parent), |
56 HsBaseViewState(mainWindow, menuMode, parent) |
81 mSortAttribute(CustomHsSortAttribute), |
57 { |
82 mMenuView(menuViewBuilder, HsAllCollectionsContext), |
58 initialize(menuViewBuilder, HsAllCollectionsContext); |
83 mMenuMode(menuMode), |
|
84 mAllCollectionsModel(0), |
|
85 mMainWindow(mainWindow), |
|
86 mContextModelIndex(), mContextMenu(0) |
|
87 { |
|
88 construct(); |
59 construct(); |
89 } |
60 } |
90 |
61 |
91 /*! |
62 /*! |
92 Constructs contained objects. |
63 Constructs contained objects. |
93 */ |
64 */ |
94 void HsAllCollectionsState::construct() |
65 void HsAllCollectionsState::construct() |
95 { |
66 { |
96 HSMENUTEST_FUNC_ENTRY("HsAllCollectionsState::construct"); |
67 HSMENUTEST_FUNC_ENTRY("HsAllCollectionsState::construct"); |
97 |
68 defineTransitions(); |
98 QState *initialState = new QState(this); |
|
99 setInitialState(initialState); |
|
100 |
|
101 QState *addModeState = new QState(this); |
|
102 connect(addModeState, SIGNAL(entered()),SLOT(addModeEntered())); |
|
103 |
|
104 QState *normalModeState = new QState(this); |
|
105 connect(normalModeState, SIGNAL(entered()),SLOT(normalModeEntered())); |
|
106 connect(normalModeState, SIGNAL(exited()),SLOT(normalModeExited())); |
|
107 |
|
108 initialState->addTransition(new HsMenuModeTransition( |
|
109 mMenuMode, NormalHsMenuMode, normalModeState)); |
|
110 initialState->addTransition(new HsMenuModeTransition( |
|
111 mMenuMode, AddHsMenuMode, addModeState)); |
|
112 |
|
113 const QString parentName = |
69 const QString parentName = |
114 parent() != 0 ? parent()->objectName() : QString(""); |
70 parent() != 0 ? parent()->objectName() : QString(""); |
115 setObjectName(parentName + "/allcollectionsstate"); |
71 setObjectName(parentName + "/allcollectionsstate"); |
116 connect(this, SIGNAL(entered()),SLOT(stateEntered())); |
72 |
117 connect(this, SIGNAL(exited()),SLOT(stateExited())); |
73 connect(mBackKeyAction, SIGNAL(triggered()), SIGNAL(toAppLibraryState())); |
118 |
74 |
119 mSecondarySoftkeyAction = new HbAction(Hb::BackNaviAction, this); |
75 mModel = HsMenuService::getAllCollectionsModel(); |
120 |
76 mMenuView->setModel(mModel); |
121 mMenuView.view()->setNavigationAction( |
|
122 mSecondarySoftkeyAction); |
|
123 |
|
124 connect(mSecondarySoftkeyAction, SIGNAL(triggered()), |
|
125 SIGNAL(toAppLibraryState())); |
|
126 |
|
127 mAllCollectionsModel = HsMenuService::getAllCollectionsModel( |
|
128 mSortAttribute); |
|
129 |
|
130 mMenuView.setModel(mAllCollectionsModel); |
|
131 |
77 |
132 HSMENUTEST_FUNC_EXIT("HsAllCollectionsState::construct"); |
78 HSMENUTEST_FUNC_EXIT("HsAllCollectionsState::construct"); |
133 } |
79 } |
134 |
80 |
135 /*! |
81 /*! |
136 Creates and installs menu options for the view |
82 Creates and installs menu options for the view. |
137 */ |
83 */ |
138 void HsAllCollectionsState::setMenuOptions() |
84 void HsAllCollectionsState::setMenuOptions() |
139 { |
85 { |
140 HSMENUTEST_FUNC_ENTRY("HsAllCollectionsState::setMenuOptions"); |
86 HSMENUTEST_FUNC_ENTRY("HsAllCollectionsState::setMenuOptions"); |
141 |
87 |
142 QScopedPointer<HbMenu> viewOptions(new HbMenu); |
88 mViewOptions->clearActions(); |
143 |
89 mViewOptions->addAction(hbTrId("txt_applib_opt_task_switcher"), |
144 viewOptions->addAction(hbTrId("txt_applib_opt_task_switcher"), |
90 static_cast<HsBaseViewState*>(this), |
145 this, |
|
146 SLOT(openTaskSwitcher())); |
91 SLOT(openTaskSwitcher())); |
147 viewOptions->addAction(hbTrId("txt_applib_opt_new_collection"), |
92 mViewOptions->addAction(hbTrId("txt_applib_opt_new_collection"), |
148 this, SLOT(createNewCollection())); |
93 this, SLOT(createNewCollection())); |
149 |
94 |
150 HbMenu *const sortMenu = viewOptions->addMenu( |
95 mViewOptions->addAction(hbTrId("txt_applib_opt_arrange"), |
151 hbTrId("txt_applib_opt_sort_by")); |
96 this, SLOT(createArrangeCollection())); |
152 |
|
153 //Grouped options are exclusive by default. |
|
154 QActionGroup *sortGroup = new QActionGroup(viewOptions.data()); |
|
155 sortGroup->addAction(sortMenu->addAction( |
|
156 hbTrId("txt_applib_opt_sub_custom"), |
|
157 this, SLOT(customMenuAction()))); |
|
158 sortGroup->addAction(sortMenu->addAction( |
|
159 hbTrId("txt_applib_opt_sub_ascending"), |
|
160 this, SLOT(ascendingMenuAction()))); |
|
161 sortGroup->addAction(sortMenu->addAction( |
|
162 hbTrId("txt_applib_opt_sub_descending"), |
|
163 this, SLOT(descendingMenuAction()))); |
|
164 |
|
165 if (mSortAttribute == CustomHsSortAttribute) { |
|
166 viewOptions->addAction(hbTrId("txt_applib_opt_arrange"), |
|
167 this, SLOT(createArrangeCollection())); |
|
168 } |
|
169 |
|
170 foreach(QAction *action, sortMenu->actions()) { |
|
171 action->setCheckable(true); |
|
172 } |
|
173 |
|
174 switch (mSortAttribute) { |
|
175 case AscendingNameHsSortAttribute: |
|
176 sortGroup->actions().at(1)->setChecked(true); |
|
177 break; |
|
178 case DescendingNameHsSortAttribute: |
|
179 sortGroup->actions().at(2)->setChecked(true); |
|
180 break; |
|
181 case CustomHsSortAttribute: |
|
182 default: |
|
183 sortGroup->actions().at(0)->setChecked(true); |
|
184 break; |
|
185 } |
|
186 |
|
187 mMenuView.view()->setMenu(viewOptions.take()); |
|
188 |
97 |
189 HSMENUTEST_FUNC_EXIT("HsAllCollectionsState::setMenuOptions"); |
98 HSMENUTEST_FUNC_EXIT("HsAllCollectionsState::setMenuOptions"); |
190 } |
99 } |
191 |
100 |
192 /*! |
101 /*! |
193 Destructor. |
102 Method seting context menu options. |
194 */ |
103 \param item the context menu is requested for. |
195 HsAllCollectionsState::~HsAllCollectionsState() |
104 \param flags related to \a item. |
196 { |
105 */ |
197 mMenuView.setModel(NULL); |
106 void HsAllCollectionsState::setContextMenuOptions(HbAbstractViewItem *item, EntryFlags flags) |
198 delete mAllCollectionsModel; |
107 { |
199 } |
108 Q_UNUSED(item) |
200 |
109 |
201 /*! |
110 HbAction *openAction = mContextMenu->addAction(hbTrId( |
202 Populates all folders |
111 "txt_common_menu_open")); |
203 */ |
112 openAction->setData(OpenContextAction); |
204 void HsAllCollectionsState::scrollToBeginning() |
|
205 { |
|
206 |
|
207 mMenuView.listView()->scrollTo( |
|
208 mAllCollectionsModel->index(0), HbAbstractItemView::PositionAtTop); |
|
209 } |
|
210 |
|
211 /*! |
|
212 Slot invoked when a state is entered. |
|
213 */ |
|
214 |
|
215 |
|
216 void HsAllCollectionsState::stateEntered() |
|
217 { |
|
218 qDebug("AllCollectionsState::stateEntered()"); |
|
219 HSMENUTEST_FUNC_ENTRY("HsAllCollectionsState::stateEntered"); |
|
220 |
|
221 mMainWindow.setCurrentView(mMenuView); |
|
222 mMenuView.activate(); |
|
223 |
|
224 HSMENUTEST_FUNC_EXIT("HsAllCollectionsState::stateExited"); |
|
225 } |
|
226 |
|
227 /*! |
|
228 Slot invoked when normal mode is entered. |
|
229 */ |
|
230 void HsAllCollectionsState::normalModeEntered() |
|
231 { |
|
232 setMenuOptions(); |
|
233 connect(&mMainWindow, SIGNAL(viewIsReady()), |
|
234 &mMainWindow, SLOT(saveActivity()), |
|
235 Qt::UniqueConnection); |
|
236 connect(&mMenuView, |
|
237 SIGNAL(activated(QModelIndex)), |
|
238 SLOT(listItemActivated(QModelIndex))); |
|
239 connect(&mMenuView, |
|
240 SIGNAL(longPressed(HbAbstractViewItem *, QPointF)), |
|
241 SLOT(listItemLongPressed(HbAbstractViewItem *, QPointF))); |
|
242 } |
|
243 |
|
244 /*! |
|
245 Slot invoked when normal mode is exited. |
|
246 */ |
|
247 void HsAllCollectionsState::normalModeExited() |
|
248 { |
|
249 mMenuView.view()->setMenu(NULL); |
|
250 } |
|
251 |
|
252 /*! |
|
253 Slot invoked when add mode is entered. |
|
254 */ |
|
255 void HsAllCollectionsState::addModeEntered() |
|
256 { |
|
257 connect(&mMenuView, |
|
258 SIGNAL(activated(QModelIndex)), |
|
259 SLOT(addActivated(QModelIndex))); |
|
260 connect(&mMenuView, |
|
261 SIGNAL(longPressed(HbAbstractViewItem *, QPointF)), |
|
262 SLOT(addLongPressed(HbAbstractViewItem *, QPointF))); |
|
263 } |
|
264 |
|
265 /*! |
|
266 Slot invoked when a state is exited. |
|
267 */ |
|
268 void HsAllCollectionsState::stateExited() |
|
269 { |
|
270 HSMENUTEST_FUNC_ENTRY("HsAllCollectionsState::stateExited"); |
|
271 |
|
272 disconnect(&mMainWindow, SIGNAL(viewIsReady()), |
|
273 &mMainWindow, SLOT(saveActivity())); |
|
274 |
|
275 mMenuView.setSearchPanelVisible(false); |
|
276 |
|
277 mMenuView.disconnect(this); |
|
278 |
|
279 mMenuView.inactivate(); |
|
280 |
|
281 if (mContextMenu) |
|
282 mContextMenu->close(); |
|
283 |
|
284 HsBaseViewState::stateExited(); |
|
285 |
|
286 HSMENUTEST_FUNC_EXIT("HsAllCollectionsState::stateExited"); |
|
287 qDebug("AllCollectionsState::stateExited()"); |
|
288 } |
|
289 |
|
290 /*! |
|
291 Open task switcher. |
|
292 \retval true if operation is successful. |
|
293 */ |
|
294 bool HsAllCollectionsState::openTaskSwitcher() |
|
295 { |
|
296 return HsMenuService::launchTaskSwitcher(); |
|
297 } |
|
298 |
|
299 /*! |
|
300 Slot connected to List widget in normal mode. |
|
301 \param index Model index of the activated item. |
|
302 */ |
|
303 void HsAllCollectionsState::listItemActivated(const QModelIndex &index) |
|
304 { |
|
305 HSMENUTEST_FUNC_ENTRY("HsAllCollectionsState::listItemActivated"); |
|
306 QVariant data = mAllCollectionsModel->data(index, CaItemModel::IdRole); |
|
307 int id = data.toInt(); |
|
308 QString collectionType = |
|
309 mAllCollectionsModel->data(index, CaItemModel::TypeRole).toString(); |
|
310 qDebug("AllCollectionsState::listItemActivated - MCS ID: %d", |
|
311 data.toInt()); |
|
312 |
|
313 mMenuView.setSearchPanelVisible(false); |
|
314 |
|
315 machine()->postEvent(HsMenuEventFactory::createOpenCollectionFromAppLibraryEvent(id, |
|
316 collectionType)); |
|
317 HSMENUTEST_FUNC_EXIT("HsAllCollectionsState::listItemActivated"); |
|
318 } |
|
319 |
|
320 /*! |
|
321 Slot connected to List widget in add mode. |
|
322 \param index Model index of the activated item. |
|
323 */ |
|
324 void HsAllCollectionsState::addActivated(const QModelIndex &index) |
|
325 { |
|
326 const int itemId = index.data(CaItemModel::IdRole).toInt(); |
|
327 machine()->postEvent( |
|
328 HsMenuEventFactory::createAddToHomeScreenEvent( |
|
329 itemId, mMenuMode.getHsMenuMode(), mMenuMode.getHsToken())); |
|
330 } |
|
331 |
|
332 /*! |
|
333 Slot connected to List widget in add mode. |
|
334 Called when item long pressed. |
|
335 \param item View item. |
|
336 \param coords Press point coordinates. |
|
337 */ |
|
338 void HsAllCollectionsState::addLongPressed(HbAbstractViewItem *item, |
|
339 const QPointF &coords) |
|
340 { |
|
341 Q_UNUSED(coords); |
|
342 const int itemId = item->modelIndex().data(CaItemModel::IdRole).toInt(); |
|
343 machine()->postEvent( |
|
344 HsMenuEventFactory::createAddToHomeScreenEvent(itemId, |
|
345 mMenuMode.getHsMenuMode(), mMenuMode.getHsToken())); |
|
346 } |
|
347 |
|
348 /*! |
|
349 Slot connected to List widget in normal mode. |
|
350 Called when item long pressed. |
|
351 \param item View item. |
|
352 \param coords Press point coordinates. |
|
353 */ |
|
354 void HsAllCollectionsState::listItemLongPressed(HbAbstractViewItem *item, |
|
355 const QPointF &coords) |
|
356 { |
|
357 HSMENUTEST_FUNC_ENTRY("HsAllCollectionsState::listItemLongPressed"); |
|
358 |
|
359 mContextMenu = new HbMenu; |
|
360 |
113 |
361 // create context menu |
114 // create context menu |
362 HbAction *addShortcutAction = mContextMenu->addAction(hbTrId( |
115 HbAction *addShortcutAction = mContextMenu->addAction(hbTrId( |
363 "txt_applib_menu_add_to_home_screen")); |
116 "txt_applib_menu_add_to_home_screen")); |
364 addShortcutAction->setData(AddToHomeScreenContextAction); |
117 addShortcutAction->setData(AddToHomeScreenContextAction); |
365 HbAction *renameAction = NULL; |
118 HbAction *renameAction = NULL; |
366 HbAction *deleteAction = NULL; |
119 HbAction *deleteAction = NULL; |
367 |
|
368 EntryFlags flags = item->modelIndex().data(CaItemModel::FlagsRole).value< |
|
369 EntryFlags> (); |
|
370 |
120 |
371 if ((flags & RemovableEntryFlag)) { |
121 if ((flags & RemovableEntryFlag)) { |
372 renameAction = mContextMenu->addAction( |
122 renameAction = mContextMenu->addAction( |
373 hbTrId("txt_common_menu_rename_item")); |
123 hbTrId("txt_common_menu_rename_item")); |
374 renameAction->setData(RenameContextAction); |
124 renameAction->setData(RenameContextAction); |
375 deleteAction = mContextMenu->addAction(hbTrId("txt_common_menu_delete")); |
125 deleteAction = mContextMenu->addAction(hbTrId("txt_common_menu_delete")); |
376 deleteAction->setData(DeleteContextAction); |
126 deleteAction->setData(DeleteContextAction); |
377 } |
127 } |
378 |
128 } |
379 mContextModelIndex = item->modelIndex(); |
129 |
380 mContextMenu->setPreferredPos(coords); |
130 /*! |
381 mContextMenu->setAttribute(Qt::WA_DeleteOnClose); |
131 Destructor. |
382 mContextMenu->open(this, SLOT(contextMenuAction(HbAction*))); |
132 */ |
383 |
133 HsAllCollectionsState::~HsAllCollectionsState() |
384 HSMENUTEST_FUNC_EXIT("HsAllCollectionsState::listItemLongPressed"); |
134 { |
385 } |
135 } |
386 |
136 |
387 /*! |
137 /*! |
388 Handles context menu actions |
138 Slot invoked when normal mode is entered. |
|
139 */ |
|
140 void HsAllCollectionsState::normalModeEntered() |
|
141 { |
|
142 HsBaseViewState::normalModeEntered(); |
|
143 connect(mMenuView.data(), |
|
144 SIGNAL(activated(QModelIndex)), |
|
145 static_cast<HsBaseViewState*>(this), |
|
146 SLOT(openCollection(QModelIndex))); |
|
147 } |
|
148 |
|
149 /*! |
|
150 Slot invoked when normal mode is exited. |
|
151 */ |
|
152 void HsAllCollectionsState::normalModeExited() |
|
153 { |
|
154 |
|
155 } |
|
156 |
|
157 |
|
158 /*! |
|
159 Slot invoked when a state is exited. |
|
160 */ |
|
161 void HsAllCollectionsState::stateExited() |
|
162 { |
|
163 HSMENUTEST_FUNC_ENTRY("HsAllCollectionsState::stateExited"); |
|
164 |
|
165 HsBaseViewState::stateExited(); |
|
166 |
|
167 HSMENUTEST_FUNC_EXIT("HsAllCollectionsState::stateExited"); |
|
168 qDebug("AllCollectionsState::stateExited()"); |
|
169 } |
|
170 |
|
171 /*! |
|
172 Slot connected to List widget in add mode. |
|
173 \param index Model index of the activated item. |
|
174 */ |
|
175 void HsAllCollectionsState::addActivated(const QModelIndex &index) |
|
176 { |
|
177 mMenuView->disconnect(this); |
|
178 const int itemId = index.data(CaItemModel::IdRole).toInt(); |
|
179 machine()->postEvent( |
|
180 HsMenuEventFactory::createAddToHomeScreenEvent( |
|
181 itemId, mMenuMode->getHsMenuMode(), mMenuMode->getHsToken())); |
|
182 } |
|
183 |
|
184 /*! |
|
185 Slot connected to List widget in add mode. |
|
186 Called when item long pressed. |
|
187 \param item View item. |
|
188 \param coords Press point coordinates. |
|
189 */ |
|
190 void HsAllCollectionsState::addLongPressed(HbAbstractViewItem *item, |
|
191 const QPointF &coords) |
|
192 { |
|
193 Q_UNUSED(coords); |
|
194 mMenuView->disconnect(this); |
|
195 const int itemId = item->modelIndex().data(CaItemModel::IdRole).toInt(); |
|
196 machine()->postEvent( |
|
197 HsMenuEventFactory::createAddToHomeScreenEvent(itemId, |
|
198 mMenuMode->getHsMenuMode(), mMenuMode->getHsToken())); |
|
199 } |
|
200 |
|
201 /*! |
|
202 Handles context menu actions. |
|
203 \param action to be handled. |
389 */ |
204 */ |
390 void HsAllCollectionsState::contextMenuAction(HbAction *action) |
205 void HsAllCollectionsState::contextMenuAction(HbAction *action) |
391 { |
206 { |
392 HsContextAction command = |
207 HsContextAction command = |
393 static_cast<HsContextAction>(action->data().toInt()); |
208 static_cast<HsContextAction>(action->data().toInt()); |
394 |
209 |
395 const int itemId = mContextModelIndex.data(CaItemModel::IdRole).toInt(); |
210 const int itemId = mContextModelIndex.data(CaItemModel::IdRole).toInt(); |
396 |
211 |
397 switch (command) { |
212 switch (command) { |
398 case AddToHomeScreenContextAction: |
213 case AddToHomeScreenContextAction: |
399 machine()->postEvent( |
214 machine()->postEvent( |
400 HsMenuEventFactory::createAddToHomeScreenEvent( |
215 HsMenuEventFactory::createAddToHomeScreenEvent( |
401 itemId, mMenuMode.getHsMenuMode(), mMenuMode.getHsToken())); |
216 itemId, |
|
217 mMenuMode->getHsMenuMode(), |
|
218 mMenuMode->getHsToken())); |
402 break; |
219 break; |
403 case RenameContextAction: |
220 case RenameContextAction: |
404 machine()->postEvent( |
221 machine()->postEvent( |
405 HsMenuEventFactory::createRenameCollectionEvent(itemId)); |
222 HsMenuEventFactory::createRenameCollectionEvent(itemId)); |
406 break; |
223 break; |
407 case DeleteContextAction: |
224 case DeleteContextAction: |
408 machine()->postEvent( |
225 machine()->postEvent( |
409 HsMenuEventFactory::createDeleteCollectionEvent(itemId)); |
226 HsMenuEventFactory::createDeleteCollectionEvent(itemId)); |
410 break; |
227 break; |
|
228 case OpenContextAction: |
|
229 openCollection(mContextModelIndex); |
|
230 break; |
411 default: |
231 default: |
412 break; |
232 break; |
413 } |
233 } |
414 |
234 |
415 mMenuView.setSearchPanelVisible(false); |
235 mMenuView->hideSearchPanel(); |
416 } |
236 } |
417 |
237 |
418 /*! |
238 /*! |
419 Slot connected to constructMenu. |
239 Slot connected to constructMenu. |
420 */ |
240 */ |