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 |
|
69
|
18 |
#include <QScopedPointer>
|
63
|
19 |
#include <QStateMachine>
|
|
20 |
#include <HbMessageBox>
|
62
|
21 |
#include <HbParameterLengthLimiter>
|
63
|
22 |
#include <HbAction>
|
|
23 |
#include <HbMenu>
|
|
24 |
#include <HbAbstractViewItem>
|
|
25 |
#include <HbView>
|
|
26 |
#include <HbListView>
|
|
27 |
|
62
|
28 |
#include <canotifier.h>
|
|
29 |
|
|
30 |
#include "hsbaseviewstate.h"
|
63
|
31 |
#include "hsmenueventfactory.h"
|
|
32 |
#include "hsmenudialogfactory.h"
|
|
33 |
#include "hsmenuitemmodel.h"
|
|
34 |
#include "hsmenumodetransition.h"
|
69
|
35 |
#include "hsmenuentryremovedhandler.h"
|
63
|
36 |
#include "hsmainwindow.h"
|
81
|
37 |
#include "hsmenumodewrapper.h"
|
63
|
38 |
|
62
|
39 |
|
|
40 |
/*!
|
|
41 |
Constructor.
|
63
|
42 |
\param mainWindow main window wrapper object.
|
|
43 |
\param parent Owner.
|
62
|
44 |
*/
|
63
|
45 |
HsBaseViewState::HsBaseViewState(HsMainWindow &mainWindow, QState *parent):
|
|
46 |
QState(parent),
|
|
47 |
mApplicationLaunchFailMessage(0),
|
|
48 |
mModel(0),
|
|
49 |
mContextMenu(0),
|
|
50 |
mContextModelIndex(),
|
|
51 |
mBackKeyAction(0),
|
|
52 |
mMenuView(0),
|
|
53 |
mMenuMode(0),
|
|
54 |
mMainWindow(mainWindow)
|
|
55 |
{
|
|
56 |
mBackKeyAction = new HbAction(Hb::BackNaviAction, this);
|
71
|
57 |
mViewOptions = new HbMenu;
|
63
|
58 |
}
|
|
59 |
|
|
60 |
/*!
|
|
61 |
Constructor.
|
|
62 |
\param mainWindow main window wrapper object.
|
|
63 |
\param menuMode menu mode object.
|
|
64 |
\param parent Owner.
|
|
65 |
*/
|
69
|
66 |
HsBaseViewState::HsBaseViewState(HsMainWindow &mainWindow,
|
|
67 |
HsMenuModeWrapper& menuMode,
|
62
|
68 |
QState *parent):
|
|
69 |
QState(parent),
|
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);
|
71
|
80 |
mViewOptions = new HbMenu;
|
62
|
81 |
}
|
63
|
82 |
/*!
|
|
83 |
Initialize contained objects.
|
|
84 |
\param menuViewBuilder object providing widgets for menu view.
|
69
|
85 |
\param stateContext state context of the view the builder
|
|
86 |
is to provide widgets for.
|
63
|
87 |
*/
|
69
|
88 |
void HsBaseViewState::initialize(HsMenuViewBuilder &menuViewBuilder,
|
|
89 |
HsStateContext stateContext)
|
63
|
90 |
{
|
86
|
91 |
mMenuView.reset(new HsMenuView(
|
|
92 |
menuViewBuilder, stateContext, mMainWindow));
|
63
|
93 |
mMenuView->view()->setNavigationAction(mBackKeyAction);
|
71
|
94 |
mMenuView->view()->setMenu(mViewOptions);
|
62
|
95 |
|
63
|
96 |
connect(this, SIGNAL(entered()),SLOT(stateEntered()));
|
|
97 |
connect(this, SIGNAL(exited()),SLOT(stateExited()));
|
62
|
98 |
}
|
|
99 |
|
|
100 |
/*!
|
|
101 |
Creates and open application launch fail message.
|
|
102 |
\param errorCode eroor code to display.
|
63
|
103 |
\param itemId id of the launched item.
|
62
|
104 |
*/
|
63
|
105 |
void HsBaseViewState::createApplicationLaunchFailMessage(int errorCode,
|
|
106 |
int itemId)
|
62
|
107 |
{
|
86
|
108 |
QString message(HbParameterLengthLimiter(
|
|
109 |
"txt_applib_info_launching_the_application_failed").arg(
|
|
110 |
errorCode));
|
62
|
111 |
|
|
112 |
// create and show message box
|
69
|
113 |
mApplicationLaunchFailMessage = HsMenuDialogFactory().create(
|
|
114 |
message, HsMenuDialogFactory::Close);
|
62
|
115 |
|
69
|
116 |
QScopedPointer<HsMenuEntryRemovedHandler> entryObserver(
|
97
|
117 |
new HsMenuEntryRemovedHandler(itemId,
|
86
|
118 |
mApplicationLaunchFailMessage.data(), SLOT(close())));
|
69
|
119 |
|
|
120 |
entryObserver.take()->setParent(mApplicationLaunchFailMessage.data());
|
|
121 |
|
|
122 |
mApplicationLaunchFailMessage->open();
|
62
|
123 |
}
|
|
124 |
|
|
125 |
/*!
|
63
|
126 |
Slot invoked when a state is entered.
|
|
127 |
*/
|
|
128 |
void HsBaseViewState::stateEntered()
|
|
129 |
{
|
|
130 |
qDebug("HsBaseViewState::stateEntered()");
|
|
131 |
HSMENUTEST_FUNC_ENTRY("HsBaseViewState::stateEntered");
|
|
132 |
mMenuView->activate();
|
69
|
133 |
connect(mMenuView.data(), SIGNAL(listViewChange()),
|
|
134 |
this, SLOT(closeContextMenu()));
|
63
|
135 |
HSMENUTEST_FUNC_EXIT("HsBaseViewState::stateEntered");
|
|
136 |
}
|
|
137 |
|
62
|
138 |
/*!
|
|
139 |
Slot invoked when a state is exited.
|
|
140 |
*/
|
|
141 |
void HsBaseViewState::stateExited()
|
|
142 |
{
|
|
143 |
HSMENUTEST_FUNC_ENTRY("HsBaseViewState::stateExited");
|
69
|
144 |
|
|
145 |
mMenuView->hideSearchPanel();
|
63
|
146 |
mMenuView->disconnect(this);
|
71
|
147 |
|
63
|
148 |
mMenuView->inactivate();
|
69
|
149 |
if (!mApplicationLaunchFailMessage.isNull()) {
|
|
150 |
mApplicationLaunchFailMessage->close();
|
63
|
151 |
}
|
69
|
152 |
closeContextMenu();
|
62
|
153 |
HSMENUTEST_FUNC_EXIT("HsBaseViewState::stateExited");
|
|
154 |
}
|
|
155 |
|
|
156 |
/*!
|
63
|
157 |
Add mode entered.
|
|
158 |
*/
|
|
159 |
void HsBaseViewState::addModeEntered()
|
|
160 |
{
|
71
|
161 |
mViewOptions = mMenuView->view()->takeMenu();
|
97
|
162 |
mMenuView->disableOviStore(true);
|
63
|
163 |
connect(mMenuView.data(),
|
|
164 |
SIGNAL(activated(QModelIndex)),
|
|
165 |
SLOT(addActivated(QModelIndex)));
|
|
166 |
connect(mMenuView.data(),
|
|
167 |
SIGNAL(longPressed(HbAbstractViewItem *, QPointF)),
|
86
|
168 |
SLOT(addModeShowContextMenu(HbAbstractViewItem *, QPointF)));
|
63
|
169 |
}
|
|
170 |
|
|
171 |
/*!
|
71
|
172 |
Add mode exited.
|
|
173 |
*/
|
|
174 |
void HsBaseViewState::addModeExited()
|
|
175 |
{
|
|
176 |
mMenuView->view()->setMenu(mViewOptions);
|
|
177 |
}
|
|
178 |
|
|
179 |
/*!
|
|
180 |
Slot invoked when normal mode entered.
|
63
|
181 |
*/
|
|
182 |
void HsBaseViewState::normalModeEntered()
|
|
183 |
{
|
|
184 |
setMenuOptions();
|
97
|
185 |
mMenuView->disableOviStore(false);
|
63
|
186 |
connect(mMenuView.data(),
|
|
187 |
SIGNAL(longPressed(HbAbstractViewItem *, QPointF)),
|
|
188 |
SLOT(showContextMenu(HbAbstractViewItem *, QPointF)));
|
|
189 |
}
|
|
190 |
|
|
191 |
/*!
|
62
|
192 |
Destructor.
|
|
193 |
*/
|
|
194 |
HsBaseViewState::~HsBaseViewState()
|
|
195 |
{
|
63
|
196 |
delete mModel;
|
81
|
197 |
mViewOptions = mMenuView->view()->takeMenu();
|
|
198 |
delete mViewOptions;
|
62
|
199 |
}
|
63
|
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);
|
71
|
210 |
if (!entry.isNull() && !(entry->flags() & UninstallEntryFlag)) {
|
81
|
211 |
if (entry->entryTypeName() == Hs::widgetTypeName) {
|
71
|
212 |
machine()->postEvent(HsMenuEventFactory::createPreviewHSWidgetEvent(entry->id(),
|
81
|
213 |
entry->entryTypeName(), entry->attribute(Hs::widgetUriAttributeName),
|
|
214 |
entry->attribute(Hs::widgetLibraryAttributeName)));
|
97
|
215 |
HsMenuService::touch(*entry);
|
|
216 |
} else {
|
|
217 |
int errCode = HsMenuService::executeAction(*entry);
|
69
|
218 |
if (errCode != 0) {
|
|
219 |
createApplicationLaunchFailMessage(errCode, entry->id());
|
|
220 |
}
|
63
|
221 |
}
|
|
222 |
}
|
|
223 |
HSMENUTEST_FUNC_EXIT("HsBaseViewState::launchItem");
|
|
224 |
}
|
|
225 |
|
|
226 |
/*!
|
|
227 |
Slot connected to List widget in normal mode.
|
|
228 |
\param index Model index of the activated item.
|
|
229 |
*/
|
|
230 |
void HsBaseViewState::openCollection(const QModelIndex &index)
|
|
231 |
{
|
|
232 |
HSMENUTEST_FUNC_ENTRY("HsBaseViewState::openCollection");
|
|
233 |
QVariant data = mModel->data(index, CaItemModel::IdRole);
|
|
234 |
int id = data.toInt();
|
69
|
235 |
QString collectionType = mModel->data(
|
|
236 |
index, CaItemModel::TypeRole).toString();
|
97
|
237 |
qDebug("HsBaseViewState::openCollection - ID: %d", data.toInt());
|
63
|
238 |
|
69
|
239 |
machine()->postEvent(
|
|
240 |
HsMenuEventFactory::createOpenCollectionFromAppLibraryEvent(
|
|
241 |
id, collectionType));
|
63
|
242 |
HSMENUTEST_FUNC_EXIT("HsBaseViewState::openCollection");
|
|
243 |
}
|
|
244 |
|
|
245 |
/*!
|
|
246 |
Slot connected to List widget in normal mode.
|
|
247 |
\param index Model index of the activated item.
|
|
248 |
*/
|
86
|
249 |
void HsBaseViewState::showContextMenu(
|
|
250 |
HbAbstractViewItem *item, const QPointF &coords)
|
63
|
251 |
{
|
|
252 |
HSMENUTEST_FUNC_ENTRY("HsBaseViewState::showContextMenu");
|
|
253 |
|
|
254 |
EntryFlags flags = item->modelIndex().data(
|
69
|
255 |
CaItemModel::FlagsRole).value<EntryFlags> ();
|
63
|
256 |
|
97
|
257 |
if ((!(flags & UninstallEntryFlag)) && (flags & VisibleEntryFlag)) {
|
63
|
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*)));
|
|
264 |
}
|
|
265 |
HSMENUTEST_FUNC_EXIT("HsBaseViewState::showContextMenu");
|
|
266 |
|
|
267 |
}
|
|
268 |
|
|
269 |
/*!
|
|
270 |
Open task switcher.
|
|
271 |
\retval true if operation is successful.
|
|
272 |
*/
|
|
273 |
bool HsBaseViewState::openTaskSwitcher()
|
|
274 |
{
|
|
275 |
return HsMenuService::launchTaskSwitcher();
|
|
276 |
}
|
|
277 |
|
|
278 |
/*!
|
|
279 |
Menu softkey back action slot
|
|
280 |
*/
|
|
281 |
void HsBaseViewState::openAppLibrary()
|
|
282 |
{
|
|
283 |
machine()->postEvent(HsMenuEventFactory::createOpenAppLibraryEvent());
|
|
284 |
}
|
|
285 |
|
|
286 |
/*!
|
81
|
287 |
Triggers event so that a state adding to Home Screen is reached
|
|
288 |
\param entryId of an item to be added to homescreen.
|
|
289 |
\retval void
|
|
290 |
*/
|
|
291 |
void HsBaseViewState::addToHomeScreen(const int entryId)
|
|
292 |
{
|
|
293 |
HSMENUTEST_FUNC_ENTRY("HsBaseViewState::addToHomeScreen");
|
|
294 |
machine()->postEvent(
|
|
295 |
HsMenuEventFactory::createAddToHomeScreenEvent(
|
|
296 |
entryId, mMenuMode->getHsMenuMode(), mMenuMode->getHsToken()));
|
|
297 |
HSMENUTEST_FUNC_EXIT("HsBaseViewState::addToHomeScreen");
|
|
298 |
}
|
|
299 |
|
|
300 |
/*!
|
63
|
301 |
Check software updates.
|
|
302 |
\retval 0 if operation is successful.
|
|
303 |
*/
|
|
304 |
int HsBaseViewState::checkSoftwareUpdates()
|
|
305 |
{
|
|
306 |
int errCode = HsMenuService::launchSoftwareUpdate();
|
|
307 |
if (errCode != 0){
|
|
308 |
createApplicationLaunchFailMessage(errCode,0);
|
|
309 |
}
|
|
310 |
return errCode;
|
|
311 |
}
|
69
|
312 |
|
|
313 |
/*!
|
|
314 |
close context menu
|
|
315 |
*/
|
|
316 |
void HsBaseViewState::closeContextMenu()
|
|
317 |
{
|
|
318 |
if (mContextMenu) {
|
|
319 |
mContextMenu->close();
|
97
|
320 |
}
|
69
|
321 |
}
|
81
|
322 |
|
|
323 |
/*!
|
|
324 |
Handles context menu actions
|
|
325 |
\param action action taken in context menu
|
|
326 |
*/
|
|
327 |
void HsBaseViewState::contextMenuAction(HbAction *action)
|
|
328 |
{
|
|
329 |
Hs::HsContextAction command =
|
|
330 |
static_cast<Hs::HsContextAction>(action->data().toInt());
|
|
331 |
|
|
332 |
const int itemId = mContextModelIndex.data(CaItemModel::IdRole).toInt();
|
97
|
333 |
|
90
|
334 |
if (itemId > 0) {
|
|
335 |
switch (command) {
|
|
336 |
case Hs::AddToHomeScreenContextAction:
|
|
337 |
addToHomeScreen(itemId);
|
|
338 |
break;
|
|
339 |
case Hs::AddToCollectionFromApplicationsViewContextAction:
|
|
340 |
// Addding a specific application to
|
|
341 |
// an existing collection via item specific menu.
|
|
342 |
machine()->postEvent(
|
|
343 |
HsMenuEventFactory::createAddAppsFromApplicationsViewEvent(
|
|
344 |
Hs::NoHsSortAttribute, itemId));
|
|
345 |
break;
|
|
346 |
case Hs::AddToCollectionFromCollectionViewContextAction:
|
|
347 |
machine()->postEvent(
|
|
348 |
HsMenuEventFactory::createAddAppsFromCollectionViewEvent(
|
|
349 |
-1, itemId));
|
|
350 |
break;
|
|
351 |
case Hs::UninstallContextAction:
|
|
352 |
machine()->postEvent(
|
|
353 |
HsMenuEventFactory::createUninstallApplicationEvent(
|
|
354 |
itemId));
|
|
355 |
break;
|
|
356 |
case Hs::AppSettingContextAction:
|
|
357 |
machine()->postEvent(
|
|
358 |
HsMenuEventFactory::createAppSettingsViewEvent(itemId));
|
|
359 |
break;
|
|
360 |
case Hs::AppDetailsContextAction:
|
|
361 |
machine()->postEvent(
|
|
362 |
HsMenuEventFactory::createAppDetailsViewEvent(itemId));
|
|
363 |
break;
|
|
364 |
case Hs::OpenAppContextAction:
|
|
365 |
launchItem(mContextModelIndex);
|
|
366 |
break;
|
|
367 |
case Hs::RenameCollectionContextAction:
|
|
368 |
machine()->postEvent(
|
|
369 |
HsMenuEventFactory::createRenameCollectionEvent(itemId));
|
|
370 |
break;
|
|
371 |
case Hs::DeleteCollectionContextAction:
|
|
372 |
machine()->postEvent(
|
|
373 |
HsMenuEventFactory::createDeleteCollectionEvent(itemId));
|
|
374 |
break;
|
|
375 |
case Hs::OpenCollectionContextAction:
|
|
376 |
openCollection(mContextModelIndex);
|
|
377 |
break;
|
|
378 |
default:
|
|
379 |
break;
|
|
380 |
}
|
|
381 |
HsMenuService::touch(itemId);
|
|
382 |
} else {
|
|
383 |
closeContextMenu();
|
81
|
384 |
}
|
|
385 |
}
|
|
386 |
|
|
387 |
/*!
|
|
388 |
Slot connected to List widget in add mode.
|
|
389 |
\param index Model index of the activated item.
|
|
390 |
*/
|
|
391 |
void HsBaseViewState::addActivated(const QModelIndex &index)
|
|
392 |
{
|
|
393 |
HSMENUTEST_FUNC_ENTRY("HsAllAppsState::addActivated");
|
|
394 |
mMenuView->disconnect(this);
|
|
395 |
const int itemId = index.data(CaItemModel::IdRole).toInt();
|
|
396 |
addToHomeScreen(itemId);
|
|
397 |
HsMenuService::touch(itemId);
|
|
398 |
HSMENUTEST_FUNC_EXIT("HsAllAppsState::addActivated");
|
|
399 |
}
|
|
400 |
|
|
401 |
/*!
|
|
402 |
Slot connected to List widget in add mode.
|
|
403 |
Called when item long pressed.
|
|
404 |
\param item View item.
|
|
405 |
\param coords Press point coordinates.
|
|
406 |
*/
|
86
|
407 |
void HsBaseViewState::addModeShowContextMenu(HbAbstractViewItem *item,
|
81
|
408 |
const QPointF &coords)
|
|
409 |
{
|
|
410 |
Q_UNUSED(coords);
|
|
411 |
HSMENUTEST_FUNC_ENTRY("HsAllAppsState::addLongPressed");
|
86
|
412 |
EntryFlags flags = item->modelIndex().data(
|
|
413 |
CaItemModel::FlagsRole).value<EntryFlags> ();
|
|
414 |
|
|
415 |
if (!(flags & UninstallEntryFlag)) {
|
|
416 |
mContextMenu = new HbMenu;
|
|
417 |
|
|
418 |
HbAction *addToHomeScreenAction = mContextMenu->addAction(
|
|
419 |
hbTrId("txt_applib_menu_add_to_home_screen"));
|
|
420 |
addToHomeScreenAction->setData(Hs::AddToHomeScreenContextAction);
|
|
421 |
|
|
422 |
mContextModelIndex = item->modelIndex();
|
|
423 |
mContextMenu->setPreferredPos(coords);
|
|
424 |
mContextMenu->setAttribute(Qt::WA_DeleteOnClose);
|
|
425 |
mContextMenu->open(this, SLOT(contextMenuAction(HbAction*)));
|
|
426 |
}
|
81
|
427 |
HSMENUTEST_FUNC_EXIT("HsAllAppsState::addLongPressed");
|
|
428 |
}
|
|
429 |
|
63
|
430 |
/*!
|
|
431 |
Scrolls view to first item at top
|
|
432 |
*/
|
|
433 |
void HsBaseViewState::scrollToBeginning()
|
|
434 |
{
|
|
435 |
mMenuView->listView()->scrollTo(
|
69
|
436 |
mModel->index(0), HbAbstractItemView::PositionAtTop);
|
63
|
437 |
}
|
|
438 |
|
|
439 |
/*!
|
|
440 |
Normal mode exited dummy implementation.
|
|
441 |
*/
|
|
442 |
void HsBaseViewState::normalModeExited()
|
|
443 |
{
|
|
444 |
}
|
|
445 |
|
|
446 |
/*!
|
|
447 |
Defines transitions
|
|
448 |
*/
|
|
449 |
void HsBaseViewState::defineTransitions()
|
|
450 |
{
|
|
451 |
QState *initialState = new QState(this);
|
|
452 |
setInitialState(initialState);
|
|
453 |
|
|
454 |
QState *addModeState = new QState(this);
|
|
455 |
connect(addModeState, SIGNAL(entered()),SLOT(addModeEntered()));
|
71
|
456 |
connect(addModeState, SIGNAL(exited()),SLOT(addModeExited()));
|
63
|
457 |
|
|
458 |
QState *normalModeState = new QState(this);
|
|
459 |
connect(normalModeState, SIGNAL(entered()),SLOT(normalModeEntered()));
|
|
460 |
connect(normalModeState, SIGNAL(exited()),SLOT(normalModeExited()));
|
|
461 |
|
|
462 |
initialState->addTransition(new HsMenuModeTransition(
|
81
|
463 |
*mMenuMode, Hs::NormalHsMenuMode, normalModeState));
|
63
|
464 |
initialState->addTransition(new HsMenuModeTransition(
|
81
|
465 |
*mMenuMode, Hs::AddHsMenuMode, addModeState));
|
63
|
466 |
}
|
81
|
467 |
|
90
|
468 |
/*!
|
|
469 |
Triggers event so that an installed applications state is entered.
|
|
470 |
*/
|
|
471 |
#ifdef COVERAGE_MEASUREMENT
|
|
472 |
#pragma CTC SKIP
|
|
473 |
#endif //COVERAGE_MEASUREMENT
|
|
474 |
void HsBaseViewState::openInstalledView()
|
|
475 |
{
|
|
476 |
machine()->postEvent(HsMenuEventFactory::createOpenInstalledViewEvent());
|
|
477 |
}
|
|
478 |
#ifdef COVERAGE_MEASUREMENT
|
|
479 |
#pragma CTC ENDSKIP
|
|
480 |
#endif //COVERAGE_MEASUREMENT
|