homescreenapp/stateplugins/hsmenuworkerstateplugin/src/hsdeletecollectionstate.cpp
changeset 96 458d8c8d9580
parent 85 35368b604b28
child 97 66b5fe3c07fd
equal deleted inserted replaced
92:6727c5d0afc7 96:458d8c8d9580
    22 #include <HbParameterLengthLimiter>
    22 #include <HbParameterLengthLimiter>
    23 #include <hsshortcutservice.h>
    23 #include <hsshortcutservice.h>
    24 #include <hsmenueventfactory.h>
    24 #include <hsmenueventfactory.h>
    25 
    25 
    26 #include "hsdeletecollectionstate.h"
    26 #include "hsdeletecollectionstate.h"
    27 #include "hsmenudialogfactory.h"
    27 #include "hsdialogcontroller.h"
    28 #include "hsmenuevent.h"
    28 #include "hsmenuevent.h"
    29 
    29 
    30 /*!
    30 /*!
    31  \class HsDeleteCollectionState
    31  \class HsDeleteCollectionState
    32  \ingroup group_hsworkerstateplugin
    32  \ingroup group_hsworkerstateplugin
    38  Constructor.
    38  Constructor.
    39  \param parent Parent state.
    39  \param parent Parent state.
    40  */
    40  */
    41 HsDeleteCollectionState::HsDeleteCollectionState(QState *parent) :
    41 HsDeleteCollectionState::HsDeleteCollectionState(QState *parent) :
    42     QState(parent),
    42     QState(parent),
    43     mItemId(0),
    43     mItemId(0)
    44     mDeleteMessage(NULL),
       
    45     mConfirmAction(NULL)
       
    46 {
    44 {
    47     construct();
    45     construct();
    48 }
    46 }
    49 
    47 
    50 /*!
    48 /*!
    51  Destructor.
    49  Destructor.
    52  */
    50  */
    53 HsDeleteCollectionState::~HsDeleteCollectionState()
    51 HsDeleteCollectionState::~HsDeleteCollectionState()
    54 {
    52 {
    55     cleanUp(); // in case of throw
    53     QT_TRY {
       
    54         emit exit();
       
    55     } QT_CATCH (...) {
       
    56     }
    56 }
    57 }
    57 
    58 
    58 /*!
    59 /*!
    59  Constructs contained objects.
    60  Constructs contained objects.
    60  */
    61  */
    89     } else {
    90     } else {
    90         message.append(HbParameterLengthLimiter("txt_applib_dialog_delete_1").arg(
    91         message.append(HbParameterLengthLimiter("txt_applib_dialog_delete_1").arg(
    91                            HsMenuService::getName(mItemId)));
    92                            HsMenuService::getName(mItemId)));
    92     }
    93     }
    93 
    94 
    94     // create and show message box
    95     QScopedPointer<HsDialogController> dialogController(
    95     mDeleteMessage = HsMenuDialogFactory().create(message);
    96             new HsDialogController(message));
    96     mConfirmAction = mDeleteMessage->actions().value(0);
    97 
    97     mDeleteMessage->open(this, SLOT(deleteMessageFinished(HbAction*)));
    98     connect(dialogController.data(),
       
    99             SIGNAL(acceptActionTriggered(QAction*)),
       
   100             this,
       
   101             SLOT(deleteCollection()));
       
   102 
       
   103     connect(dialogController.data(),
       
   104             SIGNAL(dialogCompleted()),
       
   105             this,
       
   106             SIGNAL(exit()));
       
   107 
       
   108     // ensure dialog is dismissed on app key pressed
       
   109     connect(this, SIGNAL(exited()),
       
   110             dialogController.data(),
       
   111             SLOT(dismissDialog()));
       
   112 
       
   113     dialogController.take()->openDialog();
    98 
   114 
    99     HSMENUTEST_FUNC_EXIT("HsDeleteCollectionState::onEntry");
   115     HSMENUTEST_FUNC_EXIT("HsDeleteCollectionState::onEntry");
   100 }
   116 }
   101 
   117 
       
   118 /*!
       
   119  Slot. Removes collection specified by event passed on entry to the state.
       
   120  \retval void
       
   121  */
       
   122 void HsDeleteCollectionState::deleteCollection()
       
   123 {
       
   124     HsMenuService::removeCollection(mItemId);
       
   125     machine()->postEvent(
       
   126         HsMenuEventFactory::createCollectionDeletedEvent());
       
   127 }
   102 
   128 
   103 // ---------------------------------------------------------------------------
       
   104 // ---------------------------------------------------------------------------
       
   105 //
       
   106 void HsDeleteCollectionState::deleteMessageFinished(HbAction* finishedAction)
       
   107 {
       
   108     if (static_cast<QAction*>(finishedAction) == mConfirmAction) {
       
   109         HsMenuService::removeCollection(mItemId);
       
   110         machine()->postEvent(
       
   111         HsMenuEventFactory::createCollectionDeletedEvent());
       
   112     }
       
   113     emit exit();
       
   114     mConfirmAction = NULL;
       
   115 }
       
   116 
   129 
   117 /*!
   130 /*!
   118  Slot launched after state has exited and in destructor.
   131  Slot launched after state has exited and in destructor.
   119  \retval void
   132  \retval void
   120  */
   133  */
   121 void HsDeleteCollectionState::cleanUp()
   134 void HsDeleteCollectionState::cleanUp()
   122 {
   135 {
   123     // Close messagebox if App key was pressed
       
   124     if (mDeleteMessage) {
       
   125         mDeleteMessage->close();
       
   126         mDeleteMessage = NULL;
       
   127     }
       
   128 
       
   129     mConfirmAction = NULL;
       
   130     mItemId = 0;
   136     mItemId = 0;
   131 }
   137 }