homescreenapp/stateplugins/hsmenuworkerstateplugin/src/hsdeletecollectionstate.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 delete collection state
       
    15  *
       
    16  */
       
    17 
       
    18 #include <QStateMachine>
       
    19 #include <HbMessageBox>
       
    20 #include <hbaction.h>
       
    21 #include <hsmenuservice.h>
       
    22 #include <HbParameterLengthLimiter>
       
    23 #include <hsshortcutservice.h>
       
    24 #include <hsmenueventfactory.h>
       
    25 
       
    26 #include "hsdeletecollectionstate.h"
       
    27 #include "hsmenudialogfactory.h"
       
    28 #include "hsmenuevent.h"
       
    29 
       
    30 /*!
       
    31  \class HsDeleteCollectionState
       
    32  \ingroup group_hsworkerstateplugin
       
    33  \brief Delete Collection State.
       
    34  Deletes collections.
       
    35  */
       
    36 
       
    37 /*!
       
    38  Constructor.
       
    39  \param parent Parent state.
       
    40  */
       
    41 HsDeleteCollectionState::HsDeleteCollectionState(QState *parent) :
       
    42     QState(parent),
       
    43     mItemId(0),
       
    44     mDeleteMessage(NULL),
       
    45     mConfirmAction(NULL)
       
    46 {
       
    47     construct();
       
    48 }
       
    49 
       
    50 /*!
       
    51  Destructor.
       
    52  */
       
    53 HsDeleteCollectionState::~HsDeleteCollectionState()
       
    54 {
       
    55     cleanUp(); // in case of throw
       
    56 }
       
    57 
       
    58 /*!
       
    59  Constructs contained objects.
       
    60  */
       
    61 void HsDeleteCollectionState::construct()
       
    62 {
       
    63     setObjectName("/DeleteCollectionState");
       
    64     if (this->parent()) {
       
    65         setObjectName(this->parent()->objectName() + objectName());
       
    66     }
       
    67     connect(this, SIGNAL(exited()), SLOT(cleanUp()));
       
    68 }
       
    69 
       
    70 /*!
       
    71  Sets entry event.
       
    72  \param event entry event.
       
    73  */
       
    74 void HsDeleteCollectionState::onEntry(QEvent *event)
       
    75 {
       
    76     HSMENUTEST_FUNC_ENTRY("HsDeleteCollectionState::onEntry");
       
    77     QState::onEntry(event);
       
    78     qDebug("CollectionState::onEntry()");
       
    79 
       
    80     HsMenuEvent *menuEvent = static_cast<HsMenuEvent *>(event);
       
    81     QVariantMap data = menuEvent->data();
       
    82     mItemId = data.value(Hs::itemIdKey).toInt();
       
    83 
       
    84     QString message;
       
    85     if (HsShortcutService::instance()->isItemShortcutWidget(mItemId)) {
       
    86         message.append(HbParameterLengthLimiter(
       
    87                            "txt_applib_dialog_deletes_1_also_from_home_screen"). arg(
       
    88                            HsMenuService::getName(mItemId)));
       
    89     } else {
       
    90         message.append(HbParameterLengthLimiter("txt_applib_dialog_delete_1").arg(
       
    91                            HsMenuService::getName(mItemId)));
       
    92     }
       
    93 
       
    94     // create and show message box
       
    95     mDeleteMessage = HsMenuDialogFactory().create(message);
       
    96     mConfirmAction = mDeleteMessage->actions().value(0);
       
    97     mDeleteMessage->open(this, SLOT(deleteMessageFinished(HbAction*)));
       
    98 
       
    99     HSMENUTEST_FUNC_EXIT("HsDeleteCollectionState::onEntry");
       
   100 }
       
   101 
       
   102 
       
   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 
       
   117 /*!
       
   118  Slot launched after state has exited and in destructor.
       
   119  \retval void
       
   120  */
       
   121 void HsDeleteCollectionState::cleanUp()
       
   122 {
       
   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;
       
   131 }