--- a/homescreenapp/stateplugins/hsapplibrarystateplugin/src/hsbaseviewstate.cpp Tue Jul 06 14:06:53 2010 +0300
+++ b/homescreenapp/stateplugins/hsapplibrarystateplugin/src/hsbaseviewstate.cpp Wed Aug 18 09:40:07 2010 +0300
@@ -15,104 +15,122 @@
*
*/
-#include <hbmessagebox.h>
+#include <QScopedPointer>
+#include <QStateMachine>
+#include <HbMessageBox>
#include <HbParameterLengthLimiter>
-#include <hbaction.h>
+#include <HbAction>
+#include <HbMenu>
+#include <HbAbstractViewItem>
+#include <HbView>
+#include <HbListView>
+
#include <canotifier.h>
#include "hsbaseviewstate.h"
+#include "hsmenueventfactory.h"
+#include "hsmenudialogfactory.h"
+#include "hsmenuitemmodel.h"
+#include "hsmenumodetransition.h"
+#include "hsmenuentryremovedhandler.h"
+#include "hsmainwindow.h"
+
/*!
Constructor.
+ \param mainWindow main window wrapper object.
+ \param parent Owner.
*/
-HsBaseViewState::HsBaseViewState(
- QState *parent):
+HsBaseViewState::HsBaseViewState(HsMainWindow &mainWindow, QState *parent):
QState(parent),
- mNotifier(0),
- mMessageRelatedItemId(0),
- mApplicationLaunchFailMessage(0)
+ mApplicationLaunchFailMessage(0),
+ mModel(0),
+ mContextMenu(0),
+ mContextModelIndex(),
+ mBackKeyAction(0),
+ mMenuView(0),
+ mMenuMode(0),
+ mMainWindow(mainWindow)
{
- construct();
+ mBackKeyAction = new HbAction(Hb::BackNaviAction, this);
+ mViewOptions = new HbMenu;
}
/*!
- Constructs contained objects.
+ Constructor.
+ \param mainWindow main window wrapper object.
+ \param menuMode menu mode object.
+ \param parent Owner.
*/
-void HsBaseViewState::construct()
+HsBaseViewState::HsBaseViewState(HsMainWindow &mainWindow,
+ HsMenuModeWrapper& menuMode,
+ QState *parent):
+ QState(parent),
+ mApplicationLaunchFailMessage(0),
+ mModel(0),
+ mContextMenu(0),
+ mContextModelIndex(),
+ mBackKeyAction(0),
+ mMenuView(0),
+ mMenuMode(&menuMode),
+ mMainWindow(mainWindow)
{
+ mBackKeyAction = new HbAction(Hb::BackNaviAction, this);
+ mViewOptions = new HbMenu;
+}
+/*!
+ Initialize contained objects.
+ \param menuViewBuilder object providing widgets for menu view.
+ \param stateContext state context of the view the builder
+ is to provide widgets for.
+ */
+void HsBaseViewState::initialize(HsMenuViewBuilder &menuViewBuilder,
+ HsStateContext stateContext)
+{
+ mMenuView.reset(new HsMenuView(menuViewBuilder, stateContext, mMainWindow));
+ mMenuView->view()->setNavigationAction(mBackKeyAction);
+ mMenuView->view()->setMenu(mViewOptions);
+
+ connect(this, SIGNAL(entered()),SLOT(stateEntered()));
+ connect(this, SIGNAL(exited()),SLOT(stateExited()));
}
/*!
Creates and open application launch fail message.
\param errorCode eroor code to display.
+ \param itemId id of the launched item.
*/
-void HsBaseViewState::createApplicationLaunchFailMessage(int errorCode,int itemId)
+void HsBaseViewState::createApplicationLaunchFailMessage(int errorCode,
+ int itemId)
{
QString message;
message.append(
HbParameterLengthLimiter("txt_applib_info_launching_the_application_failed").arg(
errorCode));
-
- mMessageRelatedItemId = itemId;
// create and show message box
- mApplicationLaunchFailMessage = new HbMessageBox(HbMessageBox::MessageTypeInformation);
- mApplicationLaunchFailMessage->setAttribute(Qt::WA_DeleteOnClose);
-
- mApplicationLaunchFailMessage->setText(message);
+ mApplicationLaunchFailMessage = HsMenuDialogFactory().create(
+ message, HsMenuDialogFactory::Close);
- mApplicationLaunchFailMessage->clearActions();
- HbAction *mClosemAction = new HbAction(hbTrId("txt_common_button_close"),
- mApplicationLaunchFailMessage);
- mApplicationLaunchFailMessage->addAction(mClosemAction);
+ QScopedPointer<HsMenuEntryRemovedHandler> entryObserver(
+ new HsMenuEntryRemovedHandler(itemId, mApplicationLaunchFailMessage.data(), SLOT(close())));
- mApplicationLaunchFailMessage->open(this, SLOT(applicationLaunchFailMessageFinished(HbAction*)));
-
- subscribeForMemoryCardRemove();
+ entryObserver.take()->setParent(mApplicationLaunchFailMessage.data());
+
+ mApplicationLaunchFailMessage->open();
}
/*!
- Subscribe for memory card remove.
+ Slot invoked when a state is entered.
*/
-void HsBaseViewState::subscribeForMemoryCardRemove()
-{
- if (mMessageRelatedItemId !=0 ) {
- CaNotifierFilter filter;
- filter.setIds(QList<int>() << mMessageRelatedItemId);
- mNotifier = CaService::instance()->createNotifier(filter);
- mNotifier->setParent(this);
- connect(mNotifier,
- SIGNAL(entryChanged(CaEntry,ChangeType)),
- SLOT(cleanUpApplicationLaunchFailMessage()));
- }
-}
-
-/*!
- Clean up application launch fail message box.
- \retval void
- */
-void HsBaseViewState::cleanUpApplicationLaunchFailMessage()
+void HsBaseViewState::stateEntered()
{
- if (mApplicationLaunchFailMessage) {
- mApplicationLaunchFailMessage->close();
- mApplicationLaunchFailMessage = NULL;
- }
- if (mNotifier) {
- delete mNotifier;
- mNotifier = NULL;
- }
- mMessageRelatedItemId = 0;
-}
-
-/*!
- Action after closed application launch fail dialog.
- \param finishedAction chosen action.
- \retval void
- */
-void HsBaseViewState::applicationLaunchFailMessageFinished(HbAction*)
-{
- mApplicationLaunchFailMessage = NULL;
- cleanUpApplicationLaunchFailMessage();
+ qDebug("HsBaseViewState::stateEntered()");
+ HSMENUTEST_FUNC_ENTRY("HsBaseViewState::stateEntered");
+ mMenuView->activate();
+ connect(mMenuView.data(), SIGNAL(listViewChange()),
+ this, SLOT(closeContextMenu()));
+ HSMENUTEST_FUNC_EXIT("HsBaseViewState::stateEntered");
}
/*!
@@ -121,13 +139,206 @@
void HsBaseViewState::stateExited()
{
HSMENUTEST_FUNC_ENTRY("HsBaseViewState::stateExited");
- cleanUpApplicationLaunchFailMessage();
+
+ mMenuView->hideSearchPanel();
+ mMenuView->disconnect(this);
+
+ mMenuView->inactivate();
+ if (!mApplicationLaunchFailMessage.isNull()) {
+ mApplicationLaunchFailMessage->close();
+ }
+ closeContextMenu();
HSMENUTEST_FUNC_EXIT("HsBaseViewState::stateExited");
}
/*!
+ Add mode entered.
+ */
+void HsBaseViewState::addModeEntered()
+{
+ mViewOptions = mMenuView->view()->takeMenu();
+ connect(mMenuView.data(),
+ SIGNAL(activated(QModelIndex)),
+ SLOT(addActivated(QModelIndex)));
+ connect(mMenuView.data(),
+ SIGNAL(longPressed(HbAbstractViewItem *, QPointF)),
+ SLOT(addLongPressed(HbAbstractViewItem *, QPointF)));
+}
+
+/*!
+ Add mode exited.
+ */
+void HsBaseViewState::addModeExited()
+{
+ mMenuView->view()->setMenu(mViewOptions);
+}
+
+/*!
+ Slot invoked when normal mode entered.
+ */
+void HsBaseViewState::normalModeEntered()
+{
+ setMenuOptions();
+ connect(mMenuView.data(),
+ SIGNAL(activated(QModelIndex)),
+ mMenuView.data(),
+ SLOT(hideSearchPanel()));
+ connect(mMenuView.data(),
+ SIGNAL(longPressed(HbAbstractViewItem *, QPointF)),
+ SLOT(showContextMenu(HbAbstractViewItem *, QPointF)));
+}
+
+/*!
Destructor.
*/
HsBaseViewState::~HsBaseViewState()
{
+ delete mModel;
+ mViewOptions = mMenuView->view()->takeMenu();
+ delete mViewOptions;
}
+
+/*!
+ Slot connected to List widget in normal mode.
+ \param index Model index of the activated item.
+ */
+void HsBaseViewState::launchItem(const QModelIndex &index)
+{
+ HSMENUTEST_FUNC_ENTRY("HsBaseViewState::launchItem");
+
+ QSharedPointer<const CaEntry> entry = mModel->entry(index);
+ if (!entry.isNull() && !(entry->flags() & UninstallEntryFlag)) {
+ if (entry->entryTypeName() == widgetTypeName()) {
+ machine()->postEvent(HsMenuEventFactory::createPreviewHSWidgetEvent(entry->id(),
+ entry->entryTypeName(), entry->attribute(widgetUriAttributeName()),
+ entry->attribute(widgetLibraryAttributeName())));
+ HsMenuService::touch(entry->id());
+ }
+ else {
+ int errCode = HsMenuService::executeAction(entry->id());
+ if (errCode != 0) {
+ createApplicationLaunchFailMessage(errCode, entry->id());
+ }
+ }
+ }
+ HSMENUTEST_FUNC_EXIT("HsBaseViewState::launchItem");
+}
+
+/*!
+ Slot connected to List widget in normal mode.
+ \param index Model index of the activated item.
+ */
+void HsBaseViewState::openCollection(const QModelIndex &index)
+{
+ HSMENUTEST_FUNC_ENTRY("HsBaseViewState::openCollection");
+ QVariant data = mModel->data(index, CaItemModel::IdRole);
+ int id = data.toInt();
+ QString collectionType = mModel->data(
+ index, CaItemModel::TypeRole).toString();
+ qDebug("HsBaseViewState::openCollection - MCS ID: %d", data.toInt());
+
+ machine()->postEvent(
+ HsMenuEventFactory::createOpenCollectionFromAppLibraryEvent(
+ id, collectionType));
+ HSMENUTEST_FUNC_EXIT("HsBaseViewState::openCollection");
+}
+
+/*!
+ Slot connected to List widget in normal mode.
+ \param index Model index of the activated item.
+ */
+void HsBaseViewState::showContextMenu(HbAbstractViewItem *item, const QPointF &coords)
+{
+ HSMENUTEST_FUNC_ENTRY("HsBaseViewState::showContextMenu");
+
+ EntryFlags flags = item->modelIndex().data(
+ CaItemModel::FlagsRole).value<EntryFlags> ();
+
+ if (!(flags & UninstallEntryFlag)) {
+ mContextMenu = new HbMenu;
+ setContextMenuOptions(item,flags);
+ mContextModelIndex = item->modelIndex();
+ mContextMenu->setPreferredPos(coords);
+ mContextMenu->setAttribute(Qt::WA_DeleteOnClose);
+ mContextMenu->open(this, SLOT(contextMenuAction(HbAction*)));
+ }
+ HSMENUTEST_FUNC_EXIT("HsBaseViewState::showContextMenu");
+
+}
+
+/*!
+ Open task switcher.
+ \retval true if operation is successful.
+ */
+bool HsBaseViewState::openTaskSwitcher()
+{
+ return HsMenuService::launchTaskSwitcher();
+}
+
+/*!
+ Menu softkey back action slot
+ */
+void HsBaseViewState::openAppLibrary()
+{
+ machine()->postEvent(HsMenuEventFactory::createOpenAppLibraryEvent());
+}
+
+/*!
+ Check software updates.
+ \retval 0 if operation is successful.
+ */
+int HsBaseViewState::checkSoftwareUpdates()
+{
+ int errCode = HsMenuService::launchSoftwareUpdate();
+ if (errCode != 0){
+ createApplicationLaunchFailMessage(errCode,0);
+ }
+ return errCode;
+}
+
+/*!
+ close context menu
+ */
+void HsBaseViewState::closeContextMenu()
+{
+ if (mContextMenu) {
+ mContextMenu->close();
+ }
+}
+/*!
+ Scrolls view to first item at top
+ */
+void HsBaseViewState::scrollToBeginning()
+{
+ mMenuView->listView()->scrollTo(
+ mModel->index(0), HbAbstractItemView::PositionAtTop);
+}
+
+/*!
+ Normal mode exited dummy implementation.
+ */
+void HsBaseViewState::normalModeExited()
+{
+}
+
+/*!
+ Defines transitions
+ */
+void HsBaseViewState::defineTransitions()
+{
+ QState *initialState = new QState(this);
+ setInitialState(initialState);
+
+ QState *addModeState = new QState(this);
+ connect(addModeState, SIGNAL(entered()),SLOT(addModeEntered()));
+ connect(addModeState, SIGNAL(exited()),SLOT(addModeExited()));
+
+ QState *normalModeState = new QState(this);
+ connect(normalModeState, SIGNAL(entered()),SLOT(normalModeEntered()));
+ connect(normalModeState, SIGNAL(exited()),SLOT(normalModeExited()));
+
+ initialState->addTransition(new HsMenuModeTransition(
+ *mMenuMode, NormalHsMenuMode, normalModeState));
+ initialState->addTransition(new HsMenuModeTransition(
+ *mMenuMode, AddHsMenuMode, addModeState));
+}