homescreenapp/hsdomainmodel/src/hsshortcutservice.cpp
changeset 35 f9ce957a272c
child 36 cdae8c6c3876
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/homescreenapp/hsdomainmodel/src/hsshortcutservice.cpp	Fri Mar 19 09:27:44 2010 +0200
@@ -0,0 +1,97 @@
+/*
+* 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:  Entry point for shortcut widget 
+*
+*/
+
+#include <QStateMachine>    
+#include "hsshortcutservice.h"
+#include "hsshortcutservice_p.h"
+#include "hsdatabase.h"
+#include "hswidgetdata.h"
+#include "hsmenueventfactory.h"
+
+namespace
+{
+    const char SHORTCUT_ID[] = "mcsId";
+    const char SHORTCUT_WIDGET_URI[] = "hsshortcutwidgetplugin";
+}
+
+HsShortcutServicePrivate::HsShortcutServicePrivate(QStateMachine *stateMachine, QObject *parent)
+    : QObject(parent),
+	  mStateMachine(stateMachine)
+{
+}
+
+HsShortcutServicePrivate::~HsShortcutServicePrivate()
+{
+
+}
+
+void HsShortcutServicePrivate::executeCollectionAction(
+        int shortcutId, const QString& collectionType)
+{
+	QEvent *menuEvent = HsMenuEventFactory::
+        createOpenCollectionEvent(shortcutId, collectionType);
+	mStateMachine->postEvent(menuEvent);
+}
+
+bool HsShortcutServicePrivate::isItemShortcutWidget(int itemId)
+{
+    HsDatabase *db = HsDatabase::instance();
+    Q_ASSERT(db);
+
+	QList<int> ids;
+	if (db->widgetIds(SHORTCUT_WIDGET_URI, ids)) {
+		for (int i = 0; i < ids.count(); ++i) {
+            QString id;
+            if (db->widgetPreferenceForKey(ids.at(i), SHORTCUT_ID, id) 
+				&& id.toInt() == itemId) {
+                return true;
+            }
+        }
+    }
+	return false;
+}
+
+HsShortcutService *HsShortcutService::instance(QStateMachine *stateMachine)
+{
+    if (!mInstance && stateMachine) {
+        mInstance.reset(new HsShortcutService(stateMachine));
+    }
+    return mInstance.data();
+}
+
+HsShortcutService::~HsShortcutService()
+{
+}
+
+void HsShortcutService::executeCollectionAction(
+        int shortcutId, const QString& collectionType)
+{
+    mD->executeCollectionAction(shortcutId, collectionType);
+}
+
+bool HsShortcutService::isItemShortcutWidget(int itemId)
+{
+    return mD->isItemShortcutWidget(itemId);
+}
+
+HsShortcutService::HsShortcutService(QStateMachine *stateMachine, QObject *parent)
+    : QObject(parent)
+{
+    mD.reset(new HsShortcutServicePrivate(stateMachine));
+}
+
+QScopedPointer<HsShortcutService> HsShortcutService::mInstance(0);