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