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