homescreenapp/hsdomainmodel/src/hsshortcutservice.cpp
author Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
Fri, 19 Mar 2010 09:27:44 +0200
changeset 35 f9ce957a272c
child 36 cdae8c6c3876
permissions -rw-r--r--
Revision: 201007 Kit: 201011

/*
* 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);