homescreenapp/stateplugins/hsmenuworkerstateplugin/src/hsaddtohomescreenstate.cpp
changeset 90 3ac3aaebaee5
parent 81 7dd137878ff8
equal deleted inserted replaced
86:e4f038c420f7 90:3ac3aaebaee5
    21 #include <hscontentservice.h>
    21 #include <hscontentservice.h>
    22 #include <hbmessagebox.h>
    22 #include <hbmessagebox.h>
    23 #include <hbaction.h>
    23 #include <hbaction.h>
    24 #include <hbnotificationdialog.h>
    24 #include <hbnotificationdialog.h>
    25 #include <hsmenueventfactory.h>
    25 #include <hsmenueventfactory.h>
    26 #include "hsmenudialogfactory.h"
    26 #include "hsdialogcontroller.h"
    27 #include "hsmenuentryremovedhandler.h"
       
    28 
    27 
    29 #include "hsaddtohomescreenstate.h"
    28 #include "hsaddtohomescreenstate.h"
    30 #include "hsmenuevent.h"
    29 #include "hsmenuevent.h"
    31 #include "canotifier.h"
    30 #include "canotifier.h"
    32 #include "canotifierfilter.h"
    31 #include "canotifierfilter.h"
    53  Constructor
    52  Constructor
    54  \param parent Parent state.
    53  \param parent Parent state.
    55  \retval void
    54  \retval void
    56  */
    55  */
    57 HsAddToHomeScreenState::HsAddToHomeScreenState(QState *parent) :
    56 HsAddToHomeScreenState::HsAddToHomeScreenState(QState *parent) :
    58     QState(parent), 
    57     QState(parent),
    59     mCorruptedMessage(NULL), mConfirmAction(NULL),
       
    60     mMenuMode(Hs::NormalHsMenuMode)
    58     mMenuMode(Hs::NormalHsMenuMode)
    61 {
    59 {
    62     setObjectName("/AddToHomeScreenState");
    60     setObjectName("/AddToHomeScreenState");
    63     
    61     
    64     if (this->parent()) {
    62     if (this->parent()) {
    67     
    65     
    68     connect(this, SIGNAL(exited()), SLOT(cleanUp()));
    66     connect(this, SIGNAL(exited()), SLOT(cleanUp()));
    69 }
    67 }
    70 
    68 
    71 /*!
    69 /*!
    72  Destructor. Empty one.
    70  Destructor.
    73  */
    71  */
    74 HsAddToHomeScreenState::~HsAddToHomeScreenState()
    72 HsAddToHomeScreenState::~HsAddToHomeScreenState()
    75 {
    73 {
    76     cleanUp();
    74     QT_TRY {
       
    75         emit exit();
       
    76     } QT_CATCH (...) {
       
    77     }
    77 }
    78 }
    78 
    79 
    79 /*!
    80 /*!
    80  onEntry method invoked on entering the state
    81  onEntry method invoked on entering the state
    81  Adds a widget or shortcut to the active page of home screen.
    82  Adds a widget or shortcut to the active page of home screen.
   122 }
   123 }
   123 
   124 
   124 /*!
   125 /*!
   125  Adds a widget to active page of home screen
   126  Adds a widget to active page of home screen
   126  \param contentService: service for adding widgets
   127  \param contentService: service for adding widgets
   127  \param library: widget library path and file name
       
   128  \param uri: widget uri
   128  \param uri: widget uri
   129  \param entryId: widget entry id (ignored)
       
   130  \param activePage: active page of home screen
       
   131  \retval true if successful
   129  \retval true if successful
   132  */
   130  */
   133 bool HsAddToHomeScreenState::addWidget(HsContentService &contentService, 
   131 bool HsAddToHomeScreenState::addWidget(HsContentService &contentService, 
   134         const QString &uri)
   132         const QString &uri)
   135 {
   133 {
   139     params[Hs::homescreenData] = mToken;
   137     params[Hs::homescreenData] = mToken;
   140     bool success = contentService.createWidget(params);
   138     bool success = contentService.createWidget(params);
   141     if (!success) {
   139     if (!success) {
   142         showMessageWidgetCorrupted();
   140         showMessageWidgetCorrupted();
   143     } else {
   141     } else {
   144         emit exit();
   142         openHomeScreen();
   145         if (mMenuMode == Hs::AddHsMenuMode) {
       
   146             machine()->postEvent(
       
   147                 HsMenuEventFactory::createOpenHomeScreenEvent());
       
   148         }
       
   149     }
   143     }
   150     logActionResult("Adding widget", mEntryId, success);
   144     logActionResult("Adding widget", mEntryId, success);
   151     HSMENUTEST_FUNC_EXIT("HsAddToHomeScreenState::addWidget");
   145     HSMENUTEST_FUNC_EXIT("HsAddToHomeScreenState::addWidget");
   152     return success;
   146     return success;
   153 }
   147 }
   154 
   148 
   155 /*!
   149 /*!
   156  Shows message about corrupted widget library. Deletes widget eventually
   150  Shows message about corrupted widget library. Deletes widget eventually.
   157  \param itemId entryId of widget (needed to delete it)
   151  \param itemId entryId of widget (needed to delete it)
   158  \retval void
   152  \retval void
   159  */
   153  */
   160 void HsAddToHomeScreenState::showMessageWidgetCorrupted()
   154 void HsAddToHomeScreenState::showMessageWidgetCorrupted()
   161 {
   155 {
   162     HSMENUTEST_FUNC_ENTRY("HsCollectionState::showMessageWidgetCorrupted");
   156     HSMENUTEST_FUNC_ENTRY("HsCollectionState::showMessageWidgetCorrupted");
   163 
   157 
   164     mCorruptedMessage = HsMenuDialogFactory().create(
   158     QScopedPointer<HsDialogController> dialogController(
   165             hbTrId("txt_applib_dialog_file_corrupted_unable_to_use_wi"));
   159             new HsDialogController(
   166     mConfirmAction = mCorruptedMessage->actions().value(0);
   160                 hbTrId(
   167     
   161                     "txt_applib_dialog_file_corrupted_unable_to_use_wi")));
   168     QScopedPointer<HsMenuEntryRemovedHandler> entryObserver(
   162 
   169         new HsMenuEntryRemovedHandler(mEntryId, 
   163     connect(dialogController.data(),
   170             mCorruptedMessage, SLOT(close())));
   164             SIGNAL(acceptActionTriggered(QAction*)),
   171     
   165             this,
   172     entryObserver.take()->setParent(mCorruptedMessage); 
   166             SLOT(removeWidget()));
   173     
   167 
   174     mCorruptedMessage->open(this, SLOT(messageWidgetCorruptedFinished(HbAction*)));
   168     connect(dialogController.data(),
   175 
   169             SIGNAL(dialogCompleted()),
       
   170             this,
       
   171             SLOT(openHomeScreen()));
       
   172 
       
   173     // ensure dialog is dismissed on app key pressed
       
   174     connect(this, SIGNAL(exited()),
       
   175             dialogController.data(),
       
   176             SLOT(dismissDialog()));
       
   177 
       
   178     dialogController.take()->openDialog(
       
   179             mEntryId
       
   180             );
       
   181     
   176     HSMENUTEST_FUNC_EXIT("HsCollectionState::showMessageWidgetCorrupted");
   182     HSMENUTEST_FUNC_EXIT("HsCollectionState::showMessageWidgetCorrupted");
   177 }
   183 }
   178 
   184 
   179 /*!
   185 /*!
   180  Slot launched on dismissing the corrupted widget error note
   186  Exits the state. When in Add Mode sends event requesting back step to
   181  \retval void
   187  Home Screen.
   182  */
   188  \retval void
   183 void HsAddToHomeScreenState::messageWidgetCorruptedFinished
   189  */
   184         (HbAction* finishedAction)
   190 void HsAddToHomeScreenState::openHomeScreen()
   185 {
   191 {
   186     if (static_cast<QAction*>(finishedAction) == mConfirmAction) {
       
   187         HsMenuService::executeAction(mEntryId, Hs::removeActionIdentifier);
       
   188     }
       
   189     emit exit();
   192     emit exit();
   190     if (mMenuMode == Hs::AddHsMenuMode) {
   193     if (mMenuMode == Hs::AddHsMenuMode) {
   191         machine()->postEvent(
   194         machine()->postEvent(
   192             HsMenuEventFactory::createOpenHomeScreenEvent());
   195             HsMenuEventFactory::createOpenHomeScreenEvent());
   193     }
   196     }
   194     mConfirmAction = NULL;
   197 }
   195 }
   198 
   196 
   199 
       
   200 /*!
       
   201  Slot. Removes entry requested that was subject of
       
   202  current 'add to homescreen' action.
       
   203  \retval void
       
   204  */
       
   205 #ifdef COVERAGE_MEASUREMENT
       
   206 #pragma CTC SKIP
       
   207 #endif //COVERAGE_MEASUREMENT
       
   208 void HsAddToHomeScreenState::removeWidget()
       
   209 {
       
   210     HsMenuService::executeAction(mEntryId, Hs::removeActionIdentifier);
       
   211 }
       
   212 #ifdef COVERAGE_MEASUREMENT
       
   213 #pragma CTC ENDSKIP
       
   214 #endif //COVERAGE_MEASUREMENT
   197 
   215 
   198 /*!
   216 /*!
   199  Slot launched after state has exited and in destructor.
   217  Slot launched after state has exited and in destructor.
   200  \retval void
   218  \retval void
   201  */
   219  */
   202 void HsAddToHomeScreenState::cleanUp()
   220 void HsAddToHomeScreenState::cleanUp()
   203 {
   221 {
   204     // Close popups if App key was pressed
       
   205     if (mCorruptedMessage != NULL) {
       
   206         mCorruptedMessage->close();
       
   207         mCorruptedMessage = NULL;
       
   208     }
       
   209     
       
   210     mToken = NULL;
   222     mToken = NULL;
   211 }
   223 }
   212 
   224 
   213 
   225 
   214 /*!
   226 /*!
   215  Adds a shortcut to active page of home screen
   227  Adds a shortcut to active page of home screen
   216  \param shortcutService: service for adding shortcuts
   228  \param contentService service for adding shortcuts.
   217  \param entryId: menu entry id
   229  \retval true if successful.
   218  \param activePage: active page of home screen
       
   219  \retval true if successful
       
   220  */
   230  */
   221 bool HsAddToHomeScreenState::addShortcut(HsContentService &contentService)
   231 bool HsAddToHomeScreenState::addShortcut(HsContentService &contentService)
   222 {
   232 {
   223     HSMENUTEST_FUNC_ENTRY("HsAddToHomeScreenState::addShortcut");
   233     HSMENUTEST_FUNC_ENTRY("HsAddToHomeScreenState::addShortcut");
   224     QVariantHash params;
   234     QVariantHash params;
   232     HSMENUTEST_FUNC_EXIT("HsAddToHomeScreenState::addShortcut");
   242     HSMENUTEST_FUNC_EXIT("HsAddToHomeScreenState::addShortcut");
   233     return result;
   243     return result;
   234 }
   244 }
   235 
   245 
   236 /*!
   246 /*!
   237  Adds a tapplication to active page of home screen
   247  Adds a tapplication to active page of Home Screen.
   238  \param shortcutService: service for adding shortcuts
   248  \param contentService Service for adding shortcuts.
   239  \param entryId: menu entry id
   249  \param entry Entry being added to Home Screen.
   240  \param data: data from event
       
   241  \retval true if successful
   250  \retval true if successful
   242  */
   251  */
   243 bool HsAddToHomeScreenState::addApplication(HsContentService &contentService,
   252 bool HsAddToHomeScreenState::addApplication(HsContentService &contentService,
   244                                              CaEntry& entry)
   253                                              CaEntry& entry)
   245 {
   254 {
   268             success = addShortcut(contentService);
   277             success = addShortcut(contentService);
   269         }
   278         }
   270     } else {
   279     } else {
   271             success = addShortcut(contentService);
   280             success = addShortcut(contentService);
   272     }
   281     }
   273     emit exit();
   282     openHomeScreen();
   274     if (mMenuMode == Hs::AddHsMenuMode) {
   283 
   275         machine()->postEvent(
       
   276             HsMenuEventFactory::createOpenHomeScreenEvent());
       
   277     }
       
   278     return success;
   284     return success;
   279 }
   285 }
   280 
   286 
   281 /*!
   287 /*!
   282  Provides debug logging of add widget/shortcut action
   288  Provides debug logging of add widget/shortcut action