homescreenapp/stateplugins/hsmenuworkerstateplugin/src/hsmenubasestate.cpp
author Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
Fri, 16 Apr 2010 14:54:01 +0300
changeset 36 cdae8c6c3876
parent 35 f9ce957a272c
child 46 23b5d6a29cce
permissions -rw-r--r--
Revision: 201011 Kit: 201015

/*
 * 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:
 *
 */

#include <QDebug>
#include <QVariantList>

#include <hsmenuservice.h>
#include <hsshortcutservice.h>
#include <hscontentservice.h>

#include "hsmenubasestate.h"

// ---------------------------------------------------------------------------
// ---------------------------------------------------------------------------
//
HsMenuBaseState::HsMenuBaseState(const QString &objectName, QState *parent) :
    QState(parent)
{
    construct(objectName);
}

// ---------------------------------------------------------------------------
// ---------------------------------------------------------------------------
//

HsMenuBaseState::~HsMenuBaseState()
{
}

// ---------------------------------------------------------------------------
// ---------------------------------------------------------------------------
//
void HsMenuBaseState::construct(const QString &objectName)
{
    if (this->parent()) {
        setObjectName(this->parent()->objectName() + "/" + objectName);
    } else {
        setObjectName(objectName);
    }
}

// ---------------------------------------------------------------------------
// ---------------------------------------------------------------------------
//
void HsMenuBaseState::requestService(const QVariant &service)
{
    requestServices(QList<QVariant> () << service);
}

// ---------------------------------------------------------------------------
// ---------------------------------------------------------------------------
//
void HsMenuBaseState::requestServices(const QVariantList &services)
{
    // if value is not list, it returns empty list
    QVariantList value = property(HS_SERVICES_REGISTRATION_KEY).toList();
    // apppend to list
    value.append(services);
    setProperty(HS_SERVICES_REGISTRATION_KEY, value);
}

// ---------------------------------------------------------------------------
// ---------------------------------------------------------------------------
//
HsShortcutService *HsMenuBaseState::shortcutService() const
{
    return propertyWithChecking(SHORTCUT_SERVICE_KEY).value<
           HsShortcutService *> ();
}

// ---------------------------------------------------------------------------
// ---------------------------------------------------------------------------
//
HsContentService *HsMenuBaseState::contentService() const
{
    return propertyWithChecking(CONTENT_SERVICE_KEY).value<
           HsContentService *> ();
}

// ---------------------------------------------------------------------------
// ---------------------------------------------------------------------------
//
QVariant HsMenuBaseState::propertyWithChecking(const char *propertyName) const
{
    QVariant val = property(propertyName);
    if (!val.isValid()) {
        qWarning() << "Missing value for property: " << propertyName;
    }
    return val;
}