homescreenapp/hsdomainmodel/src/hsshortcutservice.cpp
branchRCL_3
changeset 82 5f0182e07bfb
equal deleted inserted replaced
79:f00a6757af32 82:5f0182e07bfb
       
     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 "hsdomainmodeldatastructures.h"
       
    23 #include "hsmenueventfactory.h"
       
    24 
       
    25 namespace
       
    26 {
       
    27     const char gShortcutId[]        = "caEntryId";
       
    28     const char gShortcutWidgetUri[] = "hsshortcutwidgetplugin";
       
    29 }
       
    30 
       
    31 
       
    32 /*!
       
    33     \class HsShortcutService
       
    34     \ingroup group_hsdomainmodel
       
    35     \brief 
       
    36 */
       
    37 
       
    38 /*!
       
    39 
       
    40 */
       
    41 HsShortcutServicePrivate::HsShortcutServicePrivate(QStateMachine *stateMachine, QObject *parent)
       
    42     : QObject(parent),
       
    43 	  mStateMachine(stateMachine)
       
    44 {
       
    45 }
       
    46 
       
    47 /*!
       
    48 
       
    49 */
       
    50 HsShortcutServicePrivate::~HsShortcutServicePrivate()
       
    51 {
       
    52 
       
    53 }
       
    54 
       
    55 /*!
       
    56 
       
    57 */
       
    58 void HsShortcutServicePrivate::executeCollectionAction(
       
    59         int shortcutId, const QString& collectionType)
       
    60 {
       
    61 	QEvent *menuEvent = HsMenuEventFactory::
       
    62         createOpenCollectionEvent(shortcutId, collectionType);
       
    63 	mStateMachine->postEvent(menuEvent);
       
    64 }
       
    65 
       
    66 /*!
       
    67 
       
    68 */
       
    69 bool HsShortcutServicePrivate::isItemShortcutWidget(int itemId)
       
    70 {
       
    71     HsDatabase *db = HsDatabase::instance();
       
    72     Q_ASSERT(db);
       
    73 
       
    74 	QList<HsWidgetData> widgetDatas;
       
    75 	if (db->widgets(gShortcutWidgetUri, widgetDatas)) {
       
    76         for (int i = 0; i < widgetDatas.count(); ++i) {
       
    77             QVariant id;
       
    78             if (db->widgetPreference(widgetDatas.at(i).id, gShortcutId, id) && 
       
    79                 id.toInt() == itemId) {
       
    80                 return true;
       
    81             }
       
    82         }
       
    83     }
       
    84 	return false;
       
    85 }
       
    86 
       
    87 /*!
       
    88 
       
    89 */
       
    90 HsShortcutService *HsShortcutService::instance(QStateMachine *stateMachine)
       
    91 {
       
    92     if (!mInstance && stateMachine) {
       
    93         mInstance = new HsShortcutService(stateMachine);
       
    94     }
       
    95     return mInstance;
       
    96 }
       
    97 
       
    98 /*!
       
    99 
       
   100 */
       
   101 HsShortcutService::~HsShortcutService()
       
   102 {
       
   103     
       
   104 }
       
   105 
       
   106 /*!
       
   107 
       
   108 */
       
   109 void HsShortcutService::executeCollectionAction(
       
   110         int shortcutId, const QString& collectionType)
       
   111 {
       
   112     mD->executeCollectionAction(shortcutId, collectionType);
       
   113 }
       
   114 
       
   115 /*!
       
   116 
       
   117 */
       
   118 bool HsShortcutService::isItemShortcutWidget(int itemId)
       
   119 {
       
   120     return mD->isItemShortcutWidget(itemId);
       
   121 }
       
   122 
       
   123 /*!
       
   124 
       
   125 */
       
   126 HsShortcutService::HsShortcutService(QStateMachine *stateMachine, QObject *parent)
       
   127     : QObject(parent)
       
   128 {
       
   129     mD.reset(new HsShortcutServicePrivate(stateMachine));
       
   130 }
       
   131 
       
   132 HsShortcutService *HsShortcutService::mInstance(0);