13 * |
13 * |
14 * Description: Base for menu view states. |
14 * Description: Base for menu view states. |
15 * |
15 * |
16 */ |
16 */ |
17 |
17 |
18 #include <hbmessagebox.h> |
18 #include <QScopedPointer> |
|
19 #include <QStateMachine> |
|
20 #include <HbMessageBox> |
19 #include <HbParameterLengthLimiter> |
21 #include <HbParameterLengthLimiter> |
20 #include <hbaction.h> |
22 #include <HbAction> |
|
23 #include <HbMenu> |
|
24 #include <HbAbstractViewItem> |
|
25 #include <HbView> |
|
26 #include <HbListView> |
|
27 |
21 #include <canotifier.h> |
28 #include <canotifier.h> |
22 |
29 |
23 #include "hsbaseviewstate.h" |
30 #include "hsbaseviewstate.h" |
|
31 #include "hsmenueventfactory.h" |
|
32 #include "hsmenudialogfactory.h" |
|
33 #include "hsmenuitemmodel.h" |
|
34 #include "hsmenumodetransition.h" |
|
35 #include "hsmenuentryremovedhandler.h" |
|
36 #include "hsmainwindow.h" |
|
37 |
24 |
38 |
25 /*! |
39 /*! |
26 Constructor. |
40 Constructor. |
27 */ |
41 \param mainWindow main window wrapper object. |
28 HsBaseViewState::HsBaseViewState( |
42 \param parent Owner. |
|
43 */ |
|
44 HsBaseViewState::HsBaseViewState(HsMainWindow &mainWindow, QState *parent): |
|
45 QState(parent), |
|
46 mApplicationLaunchFailMessage(0), |
|
47 mModel(0), |
|
48 mContextMenu(0), |
|
49 mContextModelIndex(), |
|
50 mBackKeyAction(0), |
|
51 mMenuView(0), |
|
52 mMenuMode(0), |
|
53 mMainWindow(mainWindow) |
|
54 { |
|
55 mBackKeyAction = new HbAction(Hb::BackNaviAction, this); |
|
56 mViewOptions = new HbMenu; |
|
57 } |
|
58 |
|
59 /*! |
|
60 Constructor. |
|
61 \param mainWindow main window wrapper object. |
|
62 \param menuMode menu mode object. |
|
63 \param parent Owner. |
|
64 */ |
|
65 HsBaseViewState::HsBaseViewState(HsMainWindow &mainWindow, |
|
66 HsMenuModeWrapper& menuMode, |
29 QState *parent): |
67 QState *parent): |
30 QState(parent), |
68 QState(parent), |
31 mNotifier(0), |
69 mApplicationLaunchFailMessage(0), |
32 mMessageRelatedItemId(0), |
70 mModel(0), |
33 mApplicationLaunchFailMessage(0) |
71 mContextMenu(0), |
34 { |
72 mContextModelIndex(), |
35 construct(); |
73 mBackKeyAction(0), |
36 } |
74 mMenuView(0), |
37 |
75 mMenuMode(&menuMode), |
38 /*! |
76 mMainWindow(mainWindow) |
39 Constructs contained objects. |
77 { |
40 */ |
78 mBackKeyAction = new HbAction(Hb::BackNaviAction, this); |
41 void HsBaseViewState::construct() |
79 mViewOptions = new HbMenu; |
42 { |
80 } |
|
81 /*! |
|
82 Initialize contained objects. |
|
83 \param menuViewBuilder object providing widgets for menu view. |
|
84 \param stateContext state context of the view the builder |
|
85 is to provide widgets for. |
|
86 */ |
|
87 void HsBaseViewState::initialize(HsMenuViewBuilder &menuViewBuilder, |
|
88 HsStateContext stateContext) |
|
89 { |
|
90 mMenuView.reset(new HsMenuView(menuViewBuilder, stateContext, mMainWindow)); |
|
91 mMenuView->view()->setNavigationAction(mBackKeyAction); |
|
92 mMenuView->view()->setMenu(mViewOptions); |
|
93 |
|
94 connect(this, SIGNAL(entered()),SLOT(stateEntered())); |
|
95 connect(this, SIGNAL(exited()),SLOT(stateExited())); |
43 } |
96 } |
44 |
97 |
45 /*! |
98 /*! |
46 Creates and open application launch fail message. |
99 Creates and open application launch fail message. |
47 \param errorCode eroor code to display. |
100 \param errorCode eroor code to display. |
48 */ |
101 \param itemId id of the launched item. |
49 void HsBaseViewState::createApplicationLaunchFailMessage(int errorCode,int itemId) |
102 */ |
|
103 void HsBaseViewState::createApplicationLaunchFailMessage(int errorCode, |
|
104 int itemId) |
50 { |
105 { |
51 QString message; |
106 QString message; |
52 message.append( |
107 message.append( |
53 HbParameterLengthLimiter("txt_applib_info_launching_the_application_failed").arg( |
108 HbParameterLengthLimiter("txt_applib_info_launching_the_application_failed").arg( |
54 errorCode)); |
109 errorCode)); |
55 |
|
56 mMessageRelatedItemId = itemId; |
|
57 |
110 |
58 // create and show message box |
111 // create and show message box |
59 mApplicationLaunchFailMessage = new HbMessageBox(HbMessageBox::MessageTypeInformation); |
112 mApplicationLaunchFailMessage = HsMenuDialogFactory().create( |
60 mApplicationLaunchFailMessage->setAttribute(Qt::WA_DeleteOnClose); |
113 message, HsMenuDialogFactory::Close); |
61 |
114 |
62 mApplicationLaunchFailMessage->setText(message); |
115 QScopedPointer<HsMenuEntryRemovedHandler> entryObserver( |
63 |
116 new HsMenuEntryRemovedHandler(itemId, mApplicationLaunchFailMessage.data(), SLOT(close()))); |
64 mApplicationLaunchFailMessage->clearActions(); |
117 |
65 HbAction *mClosemAction = new HbAction(hbTrId("txt_common_button_close"), |
118 entryObserver.take()->setParent(mApplicationLaunchFailMessage.data()); |
66 mApplicationLaunchFailMessage); |
119 |
67 mApplicationLaunchFailMessage->addAction(mClosemAction); |
120 mApplicationLaunchFailMessage->open(); |
68 |
121 } |
69 mApplicationLaunchFailMessage->open(this, SLOT(applicationLaunchFailMessageFinished(HbAction*))); |
122 |
70 |
123 /*! |
71 subscribeForMemoryCardRemove(); |
124 Slot invoked when a state is entered. |
72 } |
125 */ |
73 |
126 void HsBaseViewState::stateEntered() |
74 /*! |
127 { |
75 Subscribe for memory card remove. |
128 qDebug("HsBaseViewState::stateEntered()"); |
76 */ |
129 HSMENUTEST_FUNC_ENTRY("HsBaseViewState::stateEntered"); |
77 void HsBaseViewState::subscribeForMemoryCardRemove() |
130 mMenuView->activate(); |
78 { |
131 connect(mMenuView.data(), SIGNAL(listViewChange()), |
79 if (mMessageRelatedItemId !=0 ) { |
132 this, SLOT(closeContextMenu())); |
80 CaNotifierFilter filter; |
133 HSMENUTEST_FUNC_EXIT("HsBaseViewState::stateEntered"); |
81 filter.setIds(QList<int>() << mMessageRelatedItemId); |
134 } |
82 mNotifier = CaService::instance()->createNotifier(filter); |
135 |
83 mNotifier->setParent(this); |
136 /*! |
84 connect(mNotifier, |
137 Slot invoked when a state is exited. |
85 SIGNAL(entryChanged(CaEntry,ChangeType)), |
138 */ |
86 SLOT(cleanUpApplicationLaunchFailMessage())); |
139 void HsBaseViewState::stateExited() |
|
140 { |
|
141 HSMENUTEST_FUNC_ENTRY("HsBaseViewState::stateExited"); |
|
142 |
|
143 mMenuView->hideSearchPanel(); |
|
144 mMenuView->disconnect(this); |
|
145 |
|
146 mMenuView->inactivate(); |
|
147 if (!mApplicationLaunchFailMessage.isNull()) { |
|
148 mApplicationLaunchFailMessage->close(); |
87 } |
149 } |
88 } |
150 closeContextMenu(); |
89 |
151 HSMENUTEST_FUNC_EXIT("HsBaseViewState::stateExited"); |
90 /*! |
152 } |
91 Clean up application launch fail message box. |
153 |
92 \retval void |
154 /*! |
93 */ |
155 Add mode entered. |
94 void HsBaseViewState::cleanUpApplicationLaunchFailMessage() |
156 */ |
95 { |
157 void HsBaseViewState::addModeEntered() |
96 if (mApplicationLaunchFailMessage) { |
158 { |
97 mApplicationLaunchFailMessage->close(); |
159 mViewOptions = mMenuView->view()->takeMenu(); |
98 mApplicationLaunchFailMessage = NULL; |
160 connect(mMenuView.data(), |
|
161 SIGNAL(activated(QModelIndex)), |
|
162 SLOT(addActivated(QModelIndex))); |
|
163 connect(mMenuView.data(), |
|
164 SIGNAL(longPressed(HbAbstractViewItem *, QPointF)), |
|
165 SLOT(addLongPressed(HbAbstractViewItem *, QPointF))); |
|
166 } |
|
167 |
|
168 /*! |
|
169 Add mode exited. |
|
170 */ |
|
171 void HsBaseViewState::addModeExited() |
|
172 { |
|
173 mMenuView->view()->setMenu(mViewOptions); |
|
174 } |
|
175 |
|
176 /*! |
|
177 Slot invoked when normal mode entered. |
|
178 */ |
|
179 void HsBaseViewState::normalModeEntered() |
|
180 { |
|
181 setMenuOptions(); |
|
182 connect(mMenuView.data(), |
|
183 SIGNAL(activated(QModelIndex)), |
|
184 mMenuView.data(), |
|
185 SLOT(hideSearchPanel())); |
|
186 connect(mMenuView.data(), |
|
187 SIGNAL(longPressed(HbAbstractViewItem *, QPointF)), |
|
188 SLOT(showContextMenu(HbAbstractViewItem *, QPointF))); |
|
189 } |
|
190 |
|
191 /*! |
|
192 Destructor. |
|
193 */ |
|
194 HsBaseViewState::~HsBaseViewState() |
|
195 { |
|
196 delete mModel; |
|
197 mViewOptions = mMenuView->view()->takeMenu(); |
|
198 delete mViewOptions; |
|
199 } |
|
200 |
|
201 /*! |
|
202 Slot connected to List widget in normal mode. |
|
203 \param index Model index of the activated item. |
|
204 */ |
|
205 void HsBaseViewState::launchItem(const QModelIndex &index) |
|
206 { |
|
207 HSMENUTEST_FUNC_ENTRY("HsBaseViewState::launchItem"); |
|
208 |
|
209 QSharedPointer<const CaEntry> entry = mModel->entry(index); |
|
210 if (!entry.isNull() && !(entry->flags() & UninstallEntryFlag)) { |
|
211 if (entry->entryTypeName() == widgetTypeName()) { |
|
212 machine()->postEvent(HsMenuEventFactory::createPreviewHSWidgetEvent(entry->id(), |
|
213 entry->entryTypeName(), entry->attribute(widgetUriAttributeName()), |
|
214 entry->attribute(widgetLibraryAttributeName()))); |
|
215 HsMenuService::touch(entry->id()); |
|
216 } |
|
217 else { |
|
218 int errCode = HsMenuService::executeAction(entry->id()); |
|
219 if (errCode != 0) { |
|
220 createApplicationLaunchFailMessage(errCode, entry->id()); |
|
221 } |
|
222 } |
99 } |
223 } |
100 if (mNotifier) { |
224 HSMENUTEST_FUNC_EXIT("HsBaseViewState::launchItem"); |
101 delete mNotifier; |
225 } |
102 mNotifier = NULL; |
226 |
|
227 /*! |
|
228 Slot connected to List widget in normal mode. |
|
229 \param index Model index of the activated item. |
|
230 */ |
|
231 void HsBaseViewState::openCollection(const QModelIndex &index) |
|
232 { |
|
233 HSMENUTEST_FUNC_ENTRY("HsBaseViewState::openCollection"); |
|
234 QVariant data = mModel->data(index, CaItemModel::IdRole); |
|
235 int id = data.toInt(); |
|
236 QString collectionType = mModel->data( |
|
237 index, CaItemModel::TypeRole).toString(); |
|
238 qDebug("HsBaseViewState::openCollection - MCS ID: %d", data.toInt()); |
|
239 |
|
240 machine()->postEvent( |
|
241 HsMenuEventFactory::createOpenCollectionFromAppLibraryEvent( |
|
242 id, collectionType)); |
|
243 HSMENUTEST_FUNC_EXIT("HsBaseViewState::openCollection"); |
|
244 } |
|
245 |
|
246 /*! |
|
247 Slot connected to List widget in normal mode. |
|
248 \param index Model index of the activated item. |
|
249 */ |
|
250 void HsBaseViewState::showContextMenu(HbAbstractViewItem *item, const QPointF &coords) |
|
251 { |
|
252 HSMENUTEST_FUNC_ENTRY("HsBaseViewState::showContextMenu"); |
|
253 |
|
254 EntryFlags flags = item->modelIndex().data( |
|
255 CaItemModel::FlagsRole).value<EntryFlags> (); |
|
256 |
|
257 if (!(flags & UninstallEntryFlag)) { |
|
258 mContextMenu = new HbMenu; |
|
259 setContextMenuOptions(item,flags); |
|
260 mContextModelIndex = item->modelIndex(); |
|
261 mContextMenu->setPreferredPos(coords); |
|
262 mContextMenu->setAttribute(Qt::WA_DeleteOnClose); |
|
263 mContextMenu->open(this, SLOT(contextMenuAction(HbAction*))); |
103 } |
264 } |
104 mMessageRelatedItemId = 0; |
265 HSMENUTEST_FUNC_EXIT("HsBaseViewState::showContextMenu"); |
105 } |
266 |
106 |
267 } |
107 /*! |
268 |
108 Action after closed application launch fail dialog. |
269 /*! |
109 \param finishedAction chosen action. |
270 Open task switcher. |
110 \retval void |
271 \retval true if operation is successful. |
111 */ |
272 */ |
112 void HsBaseViewState::applicationLaunchFailMessageFinished(HbAction*) |
273 bool HsBaseViewState::openTaskSwitcher() |
113 { |
274 { |
114 mApplicationLaunchFailMessage = NULL; |
275 return HsMenuService::launchTaskSwitcher(); |
115 cleanUpApplicationLaunchFailMessage(); |
276 } |
116 } |
277 |
117 |
278 /*! |
118 /*! |
279 Menu softkey back action slot |
119 Slot invoked when a state is exited. |
280 */ |
120 */ |
281 void HsBaseViewState::openAppLibrary() |
121 void HsBaseViewState::stateExited() |
282 { |
122 { |
283 machine()->postEvent(HsMenuEventFactory::createOpenAppLibraryEvent()); |
123 HSMENUTEST_FUNC_ENTRY("HsBaseViewState::stateExited"); |
284 } |
124 cleanUpApplicationLaunchFailMessage(); |
285 |
125 HSMENUTEST_FUNC_EXIT("HsBaseViewState::stateExited"); |
286 /*! |
126 } |
287 Check software updates. |
127 |
288 \retval 0 if operation is successful. |
128 /*! |
289 */ |
129 Destructor. |
290 int HsBaseViewState::checkSoftwareUpdates() |
130 */ |
291 { |
131 HsBaseViewState::~HsBaseViewState() |
292 int errCode = HsMenuService::launchSoftwareUpdate(); |
132 { |
293 if (errCode != 0){ |
133 } |
294 createApplicationLaunchFailMessage(errCode,0); |
|
295 } |
|
296 return errCode; |
|
297 } |
|
298 |
|
299 /*! |
|
300 close context menu |
|
301 */ |
|
302 void HsBaseViewState::closeContextMenu() |
|
303 { |
|
304 if (mContextMenu) { |
|
305 mContextMenu->close(); |
|
306 } |
|
307 } |
|
308 /*! |
|
309 Scrolls view to first item at top |
|
310 */ |
|
311 void HsBaseViewState::scrollToBeginning() |
|
312 { |
|
313 mMenuView->listView()->scrollTo( |
|
314 mModel->index(0), HbAbstractItemView::PositionAtTop); |
|
315 } |
|
316 |
|
317 /*! |
|
318 Normal mode exited dummy implementation. |
|
319 */ |
|
320 void HsBaseViewState::normalModeExited() |
|
321 { |
|
322 } |
|
323 |
|
324 /*! |
|
325 Defines transitions |
|
326 */ |
|
327 void HsBaseViewState::defineTransitions() |
|
328 { |
|
329 QState *initialState = new QState(this); |
|
330 setInitialState(initialState); |
|
331 |
|
332 QState *addModeState = new QState(this); |
|
333 connect(addModeState, SIGNAL(entered()),SLOT(addModeEntered())); |
|
334 connect(addModeState, SIGNAL(exited()),SLOT(addModeExited())); |
|
335 |
|
336 QState *normalModeState = new QState(this); |
|
337 connect(normalModeState, SIGNAL(entered()),SLOT(normalModeEntered())); |
|
338 connect(normalModeState, SIGNAL(exited()),SLOT(normalModeExited())); |
|
339 |
|
340 initialState->addTransition(new HsMenuModeTransition( |
|
341 *mMenuMode, NormalHsMenuMode, normalModeState)); |
|
342 initialState->addTransition(new HsMenuModeTransition( |
|
343 *mMenuMode, AddHsMenuMode, addModeState)); |
|
344 } |