homescreenapp/stateplugins/hsapplibrarystateplugin/src/hsbaseviewstate.cpp
changeset 69 87476091b3f5
parent 63 52b0f64eeb51
child 71 1db7cc813a4e
equal deleted inserted replaced
67:474929a40a0f 69:87476091b3f5
    13  *
    13  *
    14  * Description: Base for menu view states.
    14  * Description: Base for menu view states.
    15  *
    15  *
    16  */
    16  */
    17 
    17 
       
    18 #include <QScopedPointer>
    18 #include <QStateMachine>
    19 #include <QStateMachine>
    19 #include <HbMessageBox>
    20 #include <HbMessageBox>
    20 #include <HbParameterLengthLimiter>
    21 #include <HbParameterLengthLimiter>
    21 #include <HbAction>
    22 #include <HbAction>
    22 #include <HbMenu>
    23 #include <HbMenu>
    29 #include "hsbaseviewstate.h"
    30 #include "hsbaseviewstate.h"
    30 #include "hsmenueventfactory.h"
    31 #include "hsmenueventfactory.h"
    31 #include "hsmenudialogfactory.h"
    32 #include "hsmenudialogfactory.h"
    32 #include "hsmenuitemmodel.h"
    33 #include "hsmenuitemmodel.h"
    33 #include "hsmenumodetransition.h"
    34 #include "hsmenumodetransition.h"
       
    35 #include "hsmenuentryremovedhandler.h"
    34 #include "hsmainwindow.h"
    36 #include "hsmainwindow.h"
    35 
    37 
    36 
    38 
    37 /*!
    39 /*!
    38  Constructor.
    40  Constructor.
    39  \param mainWindow main window wrapper object.
    41  \param mainWindow main window wrapper object.
    40  \param parent Owner.
    42  \param parent Owner.
    41  */
    43  */
    42 HsBaseViewState::HsBaseViewState(HsMainWindow &mainWindow, QState *parent):
    44 HsBaseViewState::HsBaseViewState(HsMainWindow &mainWindow, QState *parent):
    43     QState(parent),
    45     QState(parent),
    44     mNotifier(0),
       
    45     mMessageRelatedItemId(0),
       
    46     mApplicationLaunchFailMessage(0),
    46     mApplicationLaunchFailMessage(0),
    47     mModel(0),
    47     mModel(0),
    48     mContextMenu(0),
    48     mContextMenu(0),
    49     mContextModelIndex(),
    49     mContextModelIndex(),
    50     mBackKeyAction(0),
    50     mBackKeyAction(0),
    59  Constructor.
    59  Constructor.
    60  \param mainWindow main window wrapper object.
    60  \param mainWindow main window wrapper object.
    61  \param menuMode menu mode object.
    61  \param menuMode menu mode object.
    62  \param parent Owner.
    62  \param parent Owner.
    63  */
    63  */
    64 HsBaseViewState::HsBaseViewState(HsMainWindow &mainWindow, 
    64 HsBaseViewState::HsBaseViewState(HsMainWindow &mainWindow,
    65     HsMenuModeWrapper& menuMode, 
    65     HsMenuModeWrapper& menuMode,
    66     QState *parent):
    66     QState *parent):
    67     QState(parent),
    67     QState(parent),
    68     mNotifier(0),
       
    69     mMessageRelatedItemId(0),
       
    70     mApplicationLaunchFailMessage(0),
    68     mApplicationLaunchFailMessage(0),
    71     mModel(0),
    69     mModel(0),
    72     mContextMenu(0),
    70     mContextMenu(0),
    73     mContextModelIndex(),
    71     mContextModelIndex(),
    74     mBackKeyAction(0),
    72     mBackKeyAction(0),
    79     mBackKeyAction = new HbAction(Hb::BackNaviAction, this);
    77     mBackKeyAction = new HbAction(Hb::BackNaviAction, this);
    80 }
    78 }
    81 /*!
    79 /*!
    82  Initialize contained objects.
    80  Initialize contained objects.
    83  \param menuViewBuilder object providing widgets for menu view.
    81  \param menuViewBuilder object providing widgets for menu view.
    84  \param viewContext state context of the view the builder is to provide widgets for.
    82  \param stateContext state context of the view the builder
    85  */
    83      is to provide widgets for.
    86 void HsBaseViewState::initialize(HsMenuViewBuilder &menuViewBuilder, 
    84  */
    87     HsViewContext viewContext)
    85 void HsBaseViewState::initialize(HsMenuViewBuilder &menuViewBuilder,
    88 {
    86     HsStateContext stateContext)
    89     mMenuView.reset(new HsMenuView(menuViewBuilder, viewContext));
    87 {
       
    88     mMenuView.reset(new HsMenuView(menuViewBuilder, stateContext, mMainWindow));
    90     mMenuView->view()->setNavigationAction(mBackKeyAction);
    89     mMenuView->view()->setNavigationAction(mBackKeyAction);
    91 
    90 
    92     connect(this, SIGNAL(entered()),SLOT(stateEntered()));
    91     connect(this, SIGNAL(entered()),SLOT(stateEntered()));
    93     connect(this, SIGNAL(exited()),SLOT(stateExited()));
    92     connect(this, SIGNAL(exited()),SLOT(stateExited()));
    94 }
    93 }
   103 {
   102 {
   104     QString message;
   103     QString message;
   105     message.append(
   104     message.append(
   106         HbParameterLengthLimiter("txt_applib_info_launching_the_application_failed").arg(
   105         HbParameterLengthLimiter("txt_applib_info_launching_the_application_failed").arg(
   107             errorCode));
   106             errorCode));
   108     
       
   109     mMessageRelatedItemId = itemId;
       
   110 
   107 
   111     // create and show message box
   108     // create and show message box
   112     mApplicationLaunchFailMessage = HsMenuDialogFactory().create(message, HsMenuDialogFactory::Close);
   109     mApplicationLaunchFailMessage = HsMenuDialogFactory().create(
   113 
   110             message, HsMenuDialogFactory::Close);
   114     mApplicationLaunchFailMessage->open(this, SLOT(applicationLaunchFailMessageFinished(HbAction*)));
   111 
   115     
   112     QScopedPointer<HsMenuEntryRemovedHandler> entryObserver(
   116     subscribeForMemoryCardRemove();
   113         new HsMenuEntryRemovedHandler(itemId, mApplicationLaunchFailMessage.data(), SLOT(close())));
   117 }
   114 
   118 
   115     entryObserver.take()->setParent(mApplicationLaunchFailMessage.data());
   119 /*!
   116 
   120  Subscribe for memory card remove.
   117     mApplicationLaunchFailMessage->open();
   121  */
   118 }
   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 
       
   163 
   119 
   164 /*!
   120 /*!
   165  Slot invoked when a state is entered.
   121  Slot invoked when a state is entered.
   166  */
   122  */
   167 void HsBaseViewState::stateEntered()
   123 void HsBaseViewState::stateEntered()
   168 {
   124 {
   169     qDebug("HsBaseViewState::stateEntered()");
   125     qDebug("HsBaseViewState::stateEntered()");
   170     HSMENUTEST_FUNC_ENTRY("HsBaseViewState::stateEntered");
   126     HSMENUTEST_FUNC_ENTRY("HsBaseViewState::stateEntered");
   171 
       
   172     mMainWindow.setCurrentView(*mMenuView);
       
   173     mMenuView->activate();
   127     mMenuView->activate();
   174 
   128     connect(mMenuView.data(), SIGNAL(listViewChange()),
       
   129             this, SLOT(closeContextMenu()));
   175     HSMENUTEST_FUNC_EXIT("HsBaseViewState::stateEntered");
   130     HSMENUTEST_FUNC_EXIT("HsBaseViewState::stateEntered");
   176 }
   131 }
   177 
   132 
   178 /*!
   133 /*!
   179  Slot invoked when a state is exited.
   134  Slot invoked when a state is exited.
   180  */
   135  */
   181 void HsBaseViewState::stateExited()
   136 void HsBaseViewState::stateExited()
   182 {
   137 {
   183     HSMENUTEST_FUNC_ENTRY("HsBaseViewState::stateExited");
   138     HSMENUTEST_FUNC_ENTRY("HsBaseViewState::stateExited");
   184     mMenuView->setSearchPanelVisible(false);
   139 
       
   140     mMenuView->hideSearchPanel();
   185     mMenuView->disconnect(this);
   141     mMenuView->disconnect(this);
   186     mMenuView->view()->setMenu(NULL);
   142     mMenuView->view()->setMenu(NULL);
   187     mMenuView->inactivate();
   143     mMenuView->inactivate();
   188     cleanUpApplicationLaunchFailMessage();
   144     if (!mApplicationLaunchFailMessage.isNull()) {
   189     if (mContextMenu){
   145         mApplicationLaunchFailMessage->close();
   190         mContextMenu->close();
       
   191     }
   146     }
       
   147     closeContextMenu();
   192     HSMENUTEST_FUNC_EXIT("HsBaseViewState::stateExited");
   148     HSMENUTEST_FUNC_EXIT("HsBaseViewState::stateExited");
   193 }
   149 }
   194 
   150 
   195 /*!
   151 /*!
   196  Add mode entered.
   152  Add mode entered.
   223 /*!
   179 /*!
   224  Destructor.
   180  Destructor.
   225  */
   181  */
   226 HsBaseViewState::~HsBaseViewState()
   182 HsBaseViewState::~HsBaseViewState()
   227 {
   183 {
   228     mMenuView->setModel(NULL);
       
   229     delete mModel;
   184     delete mModel;
   230 }
   185 }
   231 
   186 
   232 /*!
   187 /*!
   233  Slot connected to List widget in normal mode.
   188  Slot connected to List widget in normal mode.
   236 void HsBaseViewState::launchItem(const QModelIndex &index)
   191 void HsBaseViewState::launchItem(const QModelIndex &index)
   237 {
   192 {
   238     HSMENUTEST_FUNC_ENTRY("HsBaseViewState::launchItem");
   193     HSMENUTEST_FUNC_ENTRY("HsBaseViewState::launchItem");
   239 
   194 
   240     QSharedPointer<const CaEntry> entry = mModel->entry(index);
   195     QSharedPointer<const CaEntry> entry = mModel->entry(index);
   241 
   196     if (!entry.isNull()) {
   242     if (entry->entryTypeName() == widgetTypeName()) {
   197         if (entry->entryTypeName() == widgetTypeName()) {
   243         EntryFlags flags = index.data(CaItemModel::FlagsRole).value<
   198             EntryFlags flags = entry->flags();
   244                                EntryFlags> ();
   199             if (!(flags & UninstallEntryFlag)) {
   245         if (!(flags & UninstallEntryFlag)) {
   200                 machine()->postEvent(HsMenuEventFactory::createPreviewHSWidgetEvent(entry->id(),
   246             machine()->postEvent(
   201                     entry->entryTypeName(), entry->attribute(widgetUriAttributeName()),
   247                 HsMenuEventFactory::createPreviewHSWidgetEvent(
   202                     entry->attribute(widgetLibraryAttributeName())));
   248                     entry->id(), entry->entryTypeName(), entry->attribute(
   203                 HsMenuService::touch(entry->id());
   249                         widgetUriAttributeName()), entry->attribute(
   204             }
   250                         widgetLibraryAttributeName())));
       
   251 
       
   252             const int itemId = index.data(CaItemModel::IdRole).toInt();
       
   253             HsMenuService::touch(itemId);
       
   254         }
   205         }
   255     } else {
   206         else {
   256         QVariant data = mModel->data(index, CaItemModel::IdRole);
   207             int errCode = HsMenuService::executeAction(entry->id());
   257         int errCode = HsMenuService::executeAction(data.toInt());
   208             if (errCode != 0) {
   258         if (errCode != 0) {
   209                 createApplicationLaunchFailMessage(errCode, entry->id());
   259             createApplicationLaunchFailMessage(errCode,index.data(CaItemModel::IdRole).toInt());
   210             }
   260         }
   211         }
   261     }
   212     }
   262 
       
   263     HSMENUTEST_FUNC_EXIT("HsBaseViewState::launchItem");
   213     HSMENUTEST_FUNC_EXIT("HsBaseViewState::launchItem");
   264 }
   214 }
   265 
   215 
   266 /*!
   216 /*!
   267  Slot connected to List widget in normal mode.
   217  Slot connected to List widget in normal mode.
   270 void HsBaseViewState::openCollection(const QModelIndex &index)
   220 void HsBaseViewState::openCollection(const QModelIndex &index)
   271 {
   221 {
   272     HSMENUTEST_FUNC_ENTRY("HsBaseViewState::openCollection");
   222     HSMENUTEST_FUNC_ENTRY("HsBaseViewState::openCollection");
   273     QVariant data = mModel->data(index, CaItemModel::IdRole);
   223     QVariant data = mModel->data(index, CaItemModel::IdRole);
   274     int id = data.toInt();
   224     int id = data.toInt();
   275     QString collectionType =
   225     QString collectionType = mModel->data(
   276         mModel->data(index, CaItemModel::TypeRole).toString();
   226             index, CaItemModel::TypeRole).toString();
   277     qDebug("HsBaseViewState::openCollection - MCS ID: %d",
   227     qDebug("HsBaseViewState::openCollection - MCS ID: %d", data.toInt());
   278            data.toInt());
   228 
   279 
   229     machine()->postEvent(
   280     machine()->postEvent(HsMenuEventFactory::createOpenCollectionFromAppLibraryEvent(id,
   230             HsMenuEventFactory::createOpenCollectionFromAppLibraryEvent(
   281                          collectionType));
   231                     id, collectionType));
   282     HSMENUTEST_FUNC_EXIT("HsBaseViewState::openCollection");
   232     HSMENUTEST_FUNC_EXIT("HsBaseViewState::openCollection");
   283 }
   233 }
   284 
   234 
   285 /*!
   235 /*!
   286  Slot connected to List widget in normal mode.
   236  Slot connected to List widget in normal mode.
   287  \param index Model index of the activated item.
   237  \param index Model index of the activated item.
   288  */
   238  */
   289 void HsBaseViewState::showContextMenu(HbAbstractViewItem *item, const QPointF &coords)
   239 void HsBaseViewState::showContextMenu(HbAbstractViewItem *item, const QPointF &coords)
   290 {
   240 {
   291 
       
   292     HSMENUTEST_FUNC_ENTRY("HsBaseViewState::showContextMenu");
   241     HSMENUTEST_FUNC_ENTRY("HsBaseViewState::showContextMenu");
   293 
   242 
   294     EntryFlags flags = item->modelIndex().data(
   243     EntryFlags flags = item->modelIndex().data(
   295                            CaItemModel::FlagsRole).value<EntryFlags> ();
   244             CaItemModel::FlagsRole).value<EntryFlags> ();
   296 
   245 
   297     if (!(flags & UninstallEntryFlag)) {
   246     if (!(flags & UninstallEntryFlag)) {
   298         mContextMenu = new HbMenu;
   247         mContextMenu = new HbMenu;
   299         setContextMenuOptions(item,flags);
   248         setContextMenuOptions(item,flags);
   300         mContextModelIndex = item->modelIndex();
   249         mContextModelIndex = item->modelIndex();
   333     if (errCode != 0){
   282     if (errCode != 0){
   334         createApplicationLaunchFailMessage(errCode,0);
   283         createApplicationLaunchFailMessage(errCode,0);
   335     }
   284     }
   336     return errCode;
   285     return errCode;
   337 }
   286 }
       
   287 
       
   288 /*!
       
   289  close context menu
       
   290  */
       
   291 void HsBaseViewState::closeContextMenu()
       
   292 {
       
   293     if (mContextMenu) {
       
   294         mContextMenu->close();
       
   295     }    
       
   296 }
   338 /*!
   297 /*!
   339  Scrolls view to first item at top
   298  Scrolls view to first item at top
   340  */
   299  */
   341 void HsBaseViewState::scrollToBeginning()
   300 void HsBaseViewState::scrollToBeginning()
   342 {
   301 {
   343     mMenuView->listView()->scrollTo(
   302     mMenuView->listView()->scrollTo(
   344         mModel->index(0), HbAbstractItemView::PositionAtTop);
   303             mModel->index(0), HbAbstractItemView::PositionAtTop);
   345 }
   304 }
   346 
   305 
   347 /*!
   306 /*!
   348  Normal mode exited dummy implementation.
   307  Normal mode exited dummy implementation.
   349  */
   308  */
   365     QState *normalModeState = new QState(this);
   324     QState *normalModeState = new QState(this);
   366     connect(normalModeState, SIGNAL(entered()),SLOT(normalModeEntered()));
   325     connect(normalModeState, SIGNAL(entered()),SLOT(normalModeEntered()));
   367     connect(normalModeState, SIGNAL(exited()),SLOT(normalModeExited()));
   326     connect(normalModeState, SIGNAL(exited()),SLOT(normalModeExited()));
   368 
   327 
   369     initialState->addTransition(new HsMenuModeTransition(
   328     initialState->addTransition(new HsMenuModeTransition(
   370                                     *mMenuMode, NormalHsMenuMode, normalModeState));
   329             *mMenuMode, NormalHsMenuMode, normalModeState));
   371     initialState->addTransition(new HsMenuModeTransition(
   330     initialState->addTransition(new HsMenuModeTransition(
   372                                     *mMenuMode, AddHsMenuMode, addModeState));
   331             *mMenuMode, AddHsMenuMode, addModeState));
   373 }
   332 }