homescreenapp/stateplugins/hsapplibrarystateplugin/src/hsallcollectionsstate.cpp
branchRCL_3
changeset 82 5f0182e07bfb
equal deleted inserted replaced
79:f00a6757af32 82:5f0182e07bfb
       
     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: Menu All Collections state.
       
    15  *
       
    16  */
       
    17 #include <QPointF>
       
    18 #include <QScopedPointer>
       
    19 #include <QStateMachine>
       
    20 #include <HbView>
       
    21 #include <HbListView>
       
    22 #include <HbMenu>
       
    23 #include <HbAction>
       
    24 #include <HbAbstractViewItem>
       
    25 
       
    26 #include <cadefs.h>
       
    27 
       
    28 #include "hsmenumodewrapper.h"
       
    29 #include "hsmenueventfactory.h"
       
    30 #include "hsmenumodewrapper.h"
       
    31 #include "hsmenuitemmodel.h"
       
    32 #include "hsallcollectionsstate.h"
       
    33 #include "hsaddappstocollectionstate.h"
       
    34 #include "hsmainwindow.h"
       
    35 
       
    36 /*!
       
    37  \class HsAllCollectionsState
       
    38  \ingroup group_hsmenustateplugin
       
    39  \brief All Collections State.
       
    40  Displays all collections present on the device.
       
    41  \lib ?library
       
    42  \see StateMachine
       
    43  */
       
    44 
       
    45 /*!
       
    46  Constructor.
       
    47  \param menuViewBuilder Menu view builder.
       
    48  \param menuMode reference to object representing menu mode (add mode on/add mode off).
       
    49  \param parent Owner.
       
    50  */
       
    51 HsAllCollectionsState::HsAllCollectionsState(
       
    52     HsMenuViewBuilder &menuViewBuilder,
       
    53     HsMenuModeWrapper &menuMode,
       
    54     HsMainWindow &mainWindow,
       
    55     QState *parent):
       
    56     HsBaseViewState(mainWindow, menuMode, parent)
       
    57 {
       
    58     initialize(menuViewBuilder, HsAllCollectionsContext);
       
    59     construct();
       
    60 }
       
    61 
       
    62 /*!
       
    63  Constructs contained objects.
       
    64  */
       
    65 void HsAllCollectionsState::construct()
       
    66 {
       
    67     HSMENUTEST_FUNC_ENTRY("HsAllCollectionsState::construct");
       
    68     defineTransitions();
       
    69     const QString parentName =
       
    70         parent() != 0 ? parent()->objectName() : QString("");
       
    71     setObjectName(parentName + "/allcollectionsstate");
       
    72 
       
    73     connect(mBackKeyAction, SIGNAL(triggered()), SIGNAL(toAppLibraryState()));
       
    74 
       
    75     mModel = HsMenuService::getAllCollectionsModel();
       
    76     mMenuView->setModel(mModel);
       
    77 
       
    78     HSMENUTEST_FUNC_EXIT("HsAllCollectionsState::construct");
       
    79 }
       
    80 
       
    81 /*!
       
    82  Creates and installs menu options for the view.
       
    83  */
       
    84 void HsAllCollectionsState::setMenuOptions()
       
    85 {
       
    86     HSMENUTEST_FUNC_ENTRY("HsAllCollectionsState::setMenuOptions");
       
    87 
       
    88     mViewOptions->clearActions();
       
    89     mViewOptions->addAction(hbTrId("txt_applib_opt_task_switcher"),
       
    90                            static_cast<HsBaseViewState*>(this),
       
    91                            SLOT(openTaskSwitcher()));
       
    92     mViewOptions->addAction(hbTrId("txt_applib_opt_new_collection"),
       
    93                            this, SLOT(createNewCollection()));
       
    94 
       
    95     mViewOptions->addAction(hbTrId("txt_applib_opt_arrange"),
       
    96         this, SLOT(createArrangeCollection()));
       
    97 
       
    98     HSMENUTEST_FUNC_EXIT("HsAllCollectionsState::setMenuOptions");
       
    99 }
       
   100 
       
   101 /*!
       
   102  Method seting context menu options.
       
   103  \param item the context menu is requested for.
       
   104  \param flags related to \a item.
       
   105  */
       
   106 void HsAllCollectionsState::setContextMenuOptions(HbAbstractViewItem *item, EntryFlags flags)
       
   107 {
       
   108     Q_UNUSED(item)
       
   109 
       
   110     HbAction *openAction = mContextMenu->addAction(hbTrId(
       
   111         "txt_common_menu_open"));
       
   112     openAction->setData(Hs::OpenCollectionContextAction);
       
   113 
       
   114     // create context menu
       
   115     HbAction *addShortcutAction = mContextMenu->addAction(hbTrId(
       
   116                                       "txt_applib_menu_add_to_home_screen"));
       
   117     addShortcutAction->setData(Hs::AddToHomeScreenContextAction);
       
   118     HbAction *renameAction = NULL;
       
   119     HbAction *deleteAction = NULL;
       
   120 
       
   121     if ((flags & RemovableEntryFlag)) {
       
   122         renameAction = mContextMenu->addAction(
       
   123                            hbTrId("txt_common_menu_rename_item"));
       
   124         renameAction->setData(Hs::RenameCollectionContextAction);
       
   125         deleteAction = mContextMenu->addAction(hbTrId("txt_common_menu_delete"));
       
   126         deleteAction->setData(Hs::DeleteCollectionContextAction);
       
   127     }
       
   128 }
       
   129 
       
   130 /*!
       
   131  Destructor.
       
   132  */
       
   133 HsAllCollectionsState::~HsAllCollectionsState()
       
   134 {
       
   135 }
       
   136 
       
   137 /*!
       
   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 constructMenu.
       
   173  */
       
   174 void HsAllCollectionsState::createNewCollection()
       
   175 {
       
   176     // Adding a new collection via the Collections view
       
   177     machine()->postEvent(HsMenuEventFactory::createNewCollectionEvent());
       
   178 }
       
   179 
       
   180 /*!
       
   181  Slot connected to constructMenu.
       
   182  */
       
   183 void HsAllCollectionsState::createArrangeCollection()
       
   184 {
       
   185     // Arrange collection via the Arrange view
       
   186     int topItemId(0);
       
   187 
       
   188     const QList<HbAbstractViewItem *> array =
       
   189         mMenuView->listView()->visibleItems();
       
   190 
       
   191     if (array.count() >= 1) {
       
   192         QModelIndex idx = array[0]->modelIndex();
       
   193         topItemId = idx.data(CaItemModel::IdRole).toInt();
       
   194     }
       
   195 
       
   196     machine()->postEvent(
       
   197         HsMenuEventFactory::createArrangeAllCollectionsEvent(topItemId));
       
   198 }