homescreenapp/stateplugins/hsapplibrarystateplugin/src/hsbaseviewstate.cpp
changeset 85 35368b604b28
parent 77 4b195f3bea29
child 92 6727c5d0afc7
equal deleted inserted replaced
77:4b195f3bea29 85:35368b604b28
    32 #include "hsmenudialogfactory.h"
    32 #include "hsmenudialogfactory.h"
    33 #include "hsmenuitemmodel.h"
    33 #include "hsmenuitemmodel.h"
    34 #include "hsmenumodetransition.h"
    34 #include "hsmenumodetransition.h"
    35 #include "hsmenuentryremovedhandler.h"
    35 #include "hsmenuentryremovedhandler.h"
    36 #include "hsmainwindow.h"
    36 #include "hsmainwindow.h"
       
    37 #include "hsmenumodewrapper.h"
    37 
    38 
    38 
    39 
    39 /*!
    40 /*!
    40  Constructor.
    41  Constructor.
    41  \param mainWindow main window wrapper object.
    42  \param mainWindow main window wrapper object.
   178  */
   179  */
   179 void HsBaseViewState::normalModeEntered()
   180 void HsBaseViewState::normalModeEntered()
   180 {
   181 {
   181     setMenuOptions();
   182     setMenuOptions();
   182     connect(mMenuView.data(),
   183     connect(mMenuView.data(),
   183             SIGNAL(activated(QModelIndex)),
       
   184             mMenuView.data(),
       
   185             SLOT(hideSearchPanel()));
       
   186     connect(mMenuView.data(),
       
   187             SIGNAL(longPressed(HbAbstractViewItem *, QPointF)),
   184             SIGNAL(longPressed(HbAbstractViewItem *, QPointF)),
   188             SLOT(showContextMenu(HbAbstractViewItem *, QPointF)));
   185             SLOT(showContextMenu(HbAbstractViewItem *, QPointF)));
   189 }
   186 }
   190 
   187 
   191 /*!
   188 /*!
   192  Destructor.
   189  Destructor.
   193  */
   190  */
   194 HsBaseViewState::~HsBaseViewState()
   191 HsBaseViewState::~HsBaseViewState()
   195 {
   192 {
   196     delete mModel;
   193     delete mModel;
   197 	mViewOptions = mMenuView->view()->takeMenu();
   194     mViewOptions = mMenuView->view()->takeMenu();
   198 	delete mViewOptions;
   195     delete mViewOptions;
   199 }
   196 }
   200 
   197 
   201 /*!
   198 /*!
   202  Slot connected to List widget in normal mode.
   199  Slot connected to List widget in normal mode.
   203  \param index Model index of the activated item.
   200  \param index Model index of the activated item.
   206 {
   203 {
   207     HSMENUTEST_FUNC_ENTRY("HsBaseViewState::launchItem");
   204     HSMENUTEST_FUNC_ENTRY("HsBaseViewState::launchItem");
   208 
   205 
   209     QSharedPointer<const CaEntry> entry = mModel->entry(index);
   206     QSharedPointer<const CaEntry> entry = mModel->entry(index);
   210     if (!entry.isNull() && !(entry->flags() & UninstallEntryFlag)) {
   207     if (!entry.isNull() && !(entry->flags() & UninstallEntryFlag)) {
   211         if (entry->entryTypeName() == widgetTypeName()) {
   208         if (entry->entryTypeName() == Hs::widgetTypeName) {
   212             machine()->postEvent(HsMenuEventFactory::createPreviewHSWidgetEvent(entry->id(),
   209             machine()->postEvent(HsMenuEventFactory::createPreviewHSWidgetEvent(entry->id(),
   213                 entry->entryTypeName(), entry->attribute(widgetUriAttributeName()),
   210                 entry->entryTypeName(), entry->attribute(Hs::widgetUriAttributeName),
   214                 entry->attribute(widgetLibraryAttributeName())));
   211                 entry->attribute(Hs::widgetLibraryAttributeName)));
   215             HsMenuService::touch(entry->id());
   212             HsMenuService::touch(entry->id());
   216         }
   213         }
   217         else {
   214         else {
   218             int errCode = HsMenuService::executeAction(entry->id());
   215             int errCode = HsMenuService::executeAction(entry->id());
   219             if (errCode != 0) {
   216             if (errCode != 0) {
   282 {
   279 {
   283     machine()->postEvent(HsMenuEventFactory::createOpenAppLibraryEvent());
   280     machine()->postEvent(HsMenuEventFactory::createOpenAppLibraryEvent());
   284 }
   281 }
   285 
   282 
   286 /*!
   283 /*!
       
   284  Triggers event so that a state adding to Home Screen is reached
       
   285  \param entryId of an item to be added to homescreen.
       
   286  \retval void
       
   287  */
       
   288 void HsBaseViewState::addToHomeScreen(const int entryId)
       
   289 {
       
   290     HSMENUTEST_FUNC_ENTRY("HsBaseViewState::addToHomeScreen");
       
   291     machine()->postEvent(
       
   292         HsMenuEventFactory::createAddToHomeScreenEvent(
       
   293             entryId, mMenuMode->getHsMenuMode(), mMenuMode->getHsToken()));
       
   294     HSMENUTEST_FUNC_EXIT("HsBaseViewState::addToHomeScreen");
       
   295 }
       
   296 
       
   297 /*!
   287  Check software updates.
   298  Check software updates.
   288  \retval 0 if operation is successful.
   299  \retval 0 if operation is successful.
   289  */
   300  */
   290 int HsBaseViewState::checkSoftwareUpdates()
   301 int HsBaseViewState::checkSoftwareUpdates()
   291 {
   302 {
   303 {
   314 {
   304     if (mContextMenu) {
   315     if (mContextMenu) {
   305         mContextMenu->close();
   316         mContextMenu->close();
   306     }    
   317     }    
   307 }
   318 }
       
   319 
       
   320 /*!
       
   321  Handles context menu actions
       
   322  \param action action taken in context menu
       
   323  */
       
   324 void HsBaseViewState::contextMenuAction(HbAction *action)
       
   325 {
       
   326     Hs::HsContextAction command =
       
   327         static_cast<Hs::HsContextAction>(action->data().toInt());
       
   328 
       
   329     const int itemId = mContextModelIndex.data(CaItemModel::IdRole).toInt();
       
   330 
       
   331     switch (command) {
       
   332         case Hs::AddToHomeScreenContextAction:
       
   333             addToHomeScreen(itemId);
       
   334             break;
       
   335         case Hs::AddToCollectionFromApplicationsViewContextAction:
       
   336             // Addding a specific application to
       
   337             // an existing collection via item specific menu.
       
   338             machine()->postEvent(
       
   339                 HsMenuEventFactory::createAddAppsFromApplicationsViewEvent(
       
   340                     Hs::NoHsSortAttribute, itemId));
       
   341             break;
       
   342         case Hs::AddToCollectionFromCollectionViewContextAction:
       
   343             machine()->postEvent(
       
   344                 HsMenuEventFactory::createAddAppsFromCollectionViewEvent(
       
   345                     -1, itemId));
       
   346             break;
       
   347         case Hs::UninstallContextAction:
       
   348             machine()->postEvent(
       
   349                 HsMenuEventFactory::createUninstallApplicationEvent(
       
   350                     itemId));
       
   351             break;
       
   352         case Hs::AppSettingContextAction:
       
   353             machine()->postEvent(
       
   354                 HsMenuEventFactory::createAppSettingsViewEvent(itemId));
       
   355             break;
       
   356         case Hs::AppDetailsContextAction:
       
   357             machine()->postEvent(
       
   358                 HsMenuEventFactory::createAppDetailsViewEvent(itemId));
       
   359             break;
       
   360         case Hs::OpenAppContextAction:
       
   361             launchItem(mContextModelIndex);
       
   362             break;
       
   363         case Hs::RenameCollectionContextAction:
       
   364             machine()->postEvent(
       
   365                 HsMenuEventFactory::createRenameCollectionEvent(itemId));
       
   366             break;
       
   367         case Hs::DeleteCollectionContextAction:
       
   368              machine()->postEvent(
       
   369                 HsMenuEventFactory::createDeleteCollectionEvent(itemId));
       
   370             break;
       
   371         case Hs::OpenCollectionContextAction:
       
   372             openCollection(mContextModelIndex);
       
   373             break;
       
   374         default:
       
   375             break;
       
   376     }
       
   377     
       
   378     HsMenuService::touch(itemId);
       
   379 }
       
   380 
       
   381 /*!
       
   382  Slot connected to List widget in add mode.
       
   383  \param index Model index of the activated item.
       
   384  */
       
   385 void HsBaseViewState::addActivated(const QModelIndex &index)
       
   386 {
       
   387     HSMENUTEST_FUNC_ENTRY("HsAllAppsState::addActivated");
       
   388     mMenuView->disconnect(this);
       
   389     const int itemId = index.data(CaItemModel::IdRole).toInt();
       
   390     addToHomeScreen(itemId);
       
   391     HsMenuService::touch(itemId);
       
   392     HSMENUTEST_FUNC_EXIT("HsAllAppsState::addActivated");
       
   393 }
       
   394 
       
   395 /*!
       
   396  Slot connected to List widget in add mode.
       
   397  Called when item long pressed.
       
   398  \param item View item.
       
   399  \param coords Press point coordinates.
       
   400  */
       
   401 void HsBaseViewState::addLongPressed(HbAbstractViewItem *item,
       
   402                                     const QPointF &coords)
       
   403 {
       
   404     Q_UNUSED(coords);
       
   405     HSMENUTEST_FUNC_ENTRY("HsAllAppsState::addLongPressed");
       
   406     addActivated(item->modelIndex());
       
   407     HSMENUTEST_FUNC_EXIT("HsAllAppsState::addLongPressed");
       
   408 }
       
   409 
   308 /*!
   410 /*!
   309  Scrolls view to first item at top
   411  Scrolls view to first item at top
   310  */
   412  */
   311 void HsBaseViewState::scrollToBeginning()
   413 void HsBaseViewState::scrollToBeginning()
   312 {
   414 {
   336     QState *normalModeState = new QState(this);
   438     QState *normalModeState = new QState(this);
   337     connect(normalModeState, SIGNAL(entered()),SLOT(normalModeEntered()));
   439     connect(normalModeState, SIGNAL(entered()),SLOT(normalModeEntered()));
   338     connect(normalModeState, SIGNAL(exited()),SLOT(normalModeExited()));
   440     connect(normalModeState, SIGNAL(exited()),SLOT(normalModeExited()));
   339 
   441 
   340     initialState->addTransition(new HsMenuModeTransition(
   442     initialState->addTransition(new HsMenuModeTransition(
   341             *mMenuMode, NormalHsMenuMode, normalModeState));
   443             *mMenuMode, Hs::NormalHsMenuMode, normalModeState));
   342     initialState->addTransition(new HsMenuModeTransition(
   444     initialState->addTransition(new HsMenuModeTransition(
   343             *mMenuMode, AddHsMenuMode, addModeState));
   445             *mMenuMode, Hs::AddHsMenuMode, addModeState));
   344 }
   446 }
       
   447