homescreenapp/hsdomainmodel/src/hsshortcutservice.cpp
changeset 35 f9ce957a272c
child 36 cdae8c6c3876
equal deleted inserted replaced
5:c743ef5928ba 35:f9ce957a272c
       
     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:  Entry point for shortcut widget 
       
    15 *
       
    16 */
       
    17 
       
    18 #include <QStateMachine>    
       
    19 #include "hsshortcutservice.h"
       
    20 #include "hsshortcutservice_p.h"
       
    21 #include "hsdatabase.h"
       
    22 #include "hswidgetdata.h"
       
    23 #include "hsmenueventfactory.h"
       
    24 
       
    25 namespace
       
    26 {
       
    27     const char SHORTCUT_ID[] = "mcsId";
       
    28     const char SHORTCUT_WIDGET_URI[] = "hsshortcutwidgetplugin";
       
    29 }
       
    30 
       
    31 HsShortcutServicePrivate::HsShortcutServicePrivate(QStateMachine *stateMachine, QObject *parent)
       
    32     : QObject(parent),
       
    33 	  mStateMachine(stateMachine)
       
    34 {
       
    35 }
       
    36 
       
    37 HsShortcutServicePrivate::~HsShortcutServicePrivate()
       
    38 {
       
    39 
       
    40 }
       
    41 
       
    42 void HsShortcutServicePrivate::executeCollectionAction(
       
    43         int shortcutId, const QString& collectionType)
       
    44 {
       
    45 	QEvent *menuEvent = HsMenuEventFactory::
       
    46         createOpenCollectionEvent(shortcutId, collectionType);
       
    47 	mStateMachine->postEvent(menuEvent);
       
    48 }
       
    49 
       
    50 bool HsShortcutServicePrivate::isItemShortcutWidget(int itemId)
       
    51 {
       
    52     HsDatabase *db = HsDatabase::instance();
       
    53     Q_ASSERT(db);
       
    54 
       
    55 	QList<int> ids;
       
    56 	if (db->widgetIds(SHORTCUT_WIDGET_URI, ids)) {
       
    57 		for (int i = 0; i < ids.count(); ++i) {
       
    58             QString id;
       
    59             if (db->widgetPreferenceForKey(ids.at(i), SHORTCUT_ID, id) 
       
    60 				&& id.toInt() == itemId) {
       
    61                 return true;
       
    62             }
       
    63         }
       
    64     }
       
    65 	return false;
       
    66 }
       
    67 
       
    68 HsShortcutService *HsShortcutService::instance(QStateMachine *stateMachine)
       
    69 {
       
    70     if (!mInstance && stateMachine) {
       
    71         mInstance.reset(new HsShortcutService(stateMachine));
       
    72     }
       
    73     return mInstance.data();
       
    74 }
       
    75 
       
    76 HsShortcutService::~HsShortcutService()
       
    77 {
       
    78 }
       
    79 
       
    80 void HsShortcutService::executeCollectionAction(
       
    81         int shortcutId, const QString& collectionType)
       
    82 {
       
    83     mD->executeCollectionAction(shortcutId, collectionType);
       
    84 }
       
    85 
       
    86 bool HsShortcutService::isItemShortcutWidget(int itemId)
       
    87 {
       
    88     return mD->isItemShortcutWidget(itemId);
       
    89 }
       
    90 
       
    91 HsShortcutService::HsShortcutService(QStateMachine *stateMachine, QObject *parent)
       
    92     : QObject(parent)
       
    93 {
       
    94     mD.reset(new HsShortcutServicePrivate(stateMachine));
       
    95 }
       
    96 
       
    97 QScopedPointer<HsShortcutService> HsShortcutService::mInstance(0);