diff -r f00a6757af32 -r 5f0182e07bfb homescreenapp/stateplugins/hsmenuworkerstateplugin/src/hsdeletecollectionitemstate.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/homescreenapp/stateplugins/hsmenuworkerstateplugin/src/hsdeletecollectionitemstate.cpp Tue Aug 31 15:06:34 2010 +0300 @@ -0,0 +1,127 @@ +/* + * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). + * All rights reserved. + * This component and the accompanying materials are made available + * under the terms of "Eclipse Public License v1.0" + * which accompanies this distribution, and is available + * at the URL "http://www.eclipse.org/legal/epl-v10.html". + * + * Initial Contributors: + * Nokia Corporation - initial contribution. + * + * Contributors: + * + * Description: Menu delete collection item state + * + */ + +#include +#include +#include +#include +#include + +#include "hsmenudialogfactory.h" +#include "hsdeletecollectionitemstate.h" +#include "hsmenuevent.h" + +/*! + \class HsDeleteCollectionItemState + \ingroup group_hsworkerstateplugin + \brief Delete Collection Item State. + Deletes app from collection. + */ + +/*! + Constructor. + \param parent Parent state. + */ +HsDeleteCollectionItemState::HsDeleteCollectionItemState(QState *parent) : + QState(parent), + mItemId(0), + mCollectionId(0), + mDeleteMessage(NULL), + mConfirmAction(NULL) +{ + construct(); +} + +/*! + Destructor. + */ +HsDeleteCollectionItemState::~HsDeleteCollectionItemState() +{ + cleanUp(); // in case of throw +} + +/*! + Constructs contained objects. + */ +void HsDeleteCollectionItemState::construct() +{ + setObjectName("/DeleteCollectionItemState"); + if (this->parent()) { + setObjectName(this->parent()->objectName() + objectName()); + } + connect(this, SIGNAL(exited()), SLOT(cleanUp())); +} + +/*! + Sets entry event. + \param event entry event. + */ +void HsDeleteCollectionItemState::onEntry(QEvent *event) +{ + HSMENUTEST_FUNC_ENTRY("HsDeleteCollectionItemState::onEntry"); + QState::onEntry(event); + qDebug("CollectionState::onEntry()"); + HsMenuEvent *menuEvent = static_cast(event); + QVariantMap data = menuEvent->data(); + + mItemId = data.value(Hs::itemIdKey).toInt(); + mCollectionId = data.value(Hs::collectionIdKey).toInt(); + + QString message; + message.append( + HbParameterLengthLimiter("txt_applib_dialog_remove_1_from_collection").arg( + HsMenuService::getName(mItemId))); + + // create and show message box + mDeleteMessage = HsMenuDialogFactory().create(message); + mConfirmAction = mDeleteMessage->actions().value(0); + mDeleteMessage->open(this, SLOT(deleteMessageFinished(HbAction*))); + + HSMENUTEST_FUNC_EXIT("HsDeleteCollectionItemState::onEntry"); +} + +/*! + Action after closed confirmation dialog. + \param finishedAction chosen action. + \retval void + */ +void HsDeleteCollectionItemState::deleteMessageFinished(HbAction* finishedAction) +{ + if (static_cast(finishedAction) == mConfirmAction) { + HsMenuService::removeApplicationFromCollection(mItemId, mCollectionId); + } + emit exit(); + mConfirmAction = NULL; +} + +/*! + Slot launched after state has exited and in destructor. + \retval void + */ +void HsDeleteCollectionItemState::cleanUp() +{ + // Close messagebox if App key was pressed + if (mDeleteMessage) { + disconnect(mDeleteMessage, SIGNAL(finished(HbAction*)), this, SLOT(deleteMessageFinished(HbAction*))); + mDeleteMessage->close(); + mDeleteMessage = NULL; + } + + mConfirmAction = NULL; + mItemId = 0; + mCollectionId = 0; +}