homescreenapp/stateplugins/hsmenuworkerstateplugin/src/hsmenubasestate.cpp
branchGCC_SURGE
changeset 68 4c11ecddf6b2
parent 53 f75922b9e380
parent 61 2b1b11a301d2
equal deleted inserted replaced
53:f75922b9e380 68:4c11ecddf6b2
     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:
       
    15  *
       
    16  */
       
    17 
       
    18 #include <QDebug>
       
    19 #include <QVariantList>
       
    20 
       
    21 #include <hsmenuservice.h>
       
    22 #include <hsshortcutservice.h>
       
    23 #include <hscontentservice.h>
       
    24 
       
    25 #include "hsmenubasestate.h"
       
    26 
       
    27 /*!
       
    28  \class HsMenuBaseState
       
    29  \ingroup group_hsworkerstateplugin
       
    30  \brief Menu Base State
       
    31  Menu Base state is the base class for states used in Menu.
       
    32  It provides basic functionality that makes implemenatation state easier.
       
    33  Derived implementation can request specific service and access it using convience function.
       
    34  \lib ?library
       
    35  */
       
    36 
       
    37 /*!
       
    38  Constructor.
       
    39  \param objectName object name, used for debug purpose
       
    40  \param parent Owner.
       
    41  */
       
    42 HsMenuBaseState::HsMenuBaseState(const QString &objectName, QState *parent) :
       
    43     QState(parent)
       
    44 {
       
    45     construct(objectName);
       
    46 }
       
    47 
       
    48 /*!
       
    49  Destructor.
       
    50  */
       
    51 HsMenuBaseState::~HsMenuBaseState()
       
    52 {
       
    53 }
       
    54 
       
    55 /*!
       
    56  Constructs contained objects.
       
    57  \param objectName object name, used for debug purpose
       
    58  */
       
    59 void HsMenuBaseState::construct(const QString &objectName)
       
    60 {
       
    61     if (this->parent()) {
       
    62         setObjectName(this->parent()->objectName() + "/" + objectName);
       
    63     } else {
       
    64         setObjectName(objectName);
       
    65     }
       
    66 }
       
    67 
       
    68 /*!
       
    69  Convenience method that request single service.
       
    70  \param service service to be requested.
       
    71  \see requestServices
       
    72  */
       
    73 void HsMenuBaseState::requestService(const QVariant &service)
       
    74 {
       
    75     requestServices(QList<QVariant> () << service);
       
    76 }
       
    77 
       
    78 /*!
       
    79  Request for services
       
    80  notice that services are appended to the list,
       
    81  so this fuction can be called more than once.
       
    82  \param services list of requested services
       
    83  this method must be called during construction phased of derived class
       
    84  */
       
    85 void HsMenuBaseState::requestServices(const QVariantList &services)
       
    86 {
       
    87     // if value is not list, it returns empty list
       
    88     QVariantList value = property(HS_SERVICES_REGISTRATION_KEY).toList();
       
    89     // apppend to list
       
    90     value.append(services);
       
    91     setProperty(HS_SERVICES_REGISTRATION_KEY, value);
       
    92 }
       
    93 
       
    94 /*!
       
    95  Convenience method that returns the shortcut serviceif was requested
       
    96  \return Shortcut service if exists.
       
    97  */
       
    98 HsShortcutService *HsMenuBaseState::shortcutService() const
       
    99 {
       
   100     return propertyWithChecking(SHORTCUT_SERVICE_KEY).value<
       
   101            HsShortcutService *> ();
       
   102 }
       
   103 
       
   104 /*!
       
   105  Convenient method that returns the content serviceif was requested
       
   106  \return Content service if exists.
       
   107  */
       
   108 HsContentService *HsMenuBaseState::contentService() const
       
   109 {
       
   110     return propertyWithChecking(CONTENT_SERVICE_KEY).value<
       
   111            HsContentService *> ();
       
   112 }
       
   113 
       
   114 /*!
       
   115  Function return value for specified property and
       
   116  if it is not valid add warning message on console.
       
   117  \param propertyName Property name.
       
   118  \return Property after validation.
       
   119  */
       
   120 QVariant HsMenuBaseState::propertyWithChecking(const char *propertyName) const
       
   121 {
       
   122     QVariant val = property(propertyName);
       
   123     if (!val.isValid()) {
       
   124         qWarning() << "Missing value for property: " << propertyName;
       
   125     }
       
   126     return val;
       
   127 }