homescreenapp/hsapplication/src/hshomescreenclientserviceprovider.cpp
author Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
Wed, 23 Jun 2010 18:03:36 +0300
changeset 60 30f14686fb04
parent 51 4785f57bf3d4
child 61 2b1b11a301d2
permissions -rw-r--r--
Revision: 201023 Kit: 2010125

/*
* Copyright (c) 2010 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 "hshomescreenclientserviceprovider.h"
#include "hswidgetcomponentdescriptor.h"
#include "hscontentservice.h"
#include "hsscene.h"
#include "hspage.h"
#include "hswallpaper.h"
#include "hswidgetcomponentregistry.h"
#include "hsconfiguration.h"
#include "hsspinnerdialog.h"

namespace
{
    const char gInterfaceName[] = "com.nokia.symbian.IHomeScreenClient";
}


/*!
    \class HsHomeScreenClientServiceProvider
    \ingroup group_hsapplication
    \brief TODO
*/

/*!
    Constructor.
*/
HsHomeScreenClientServiceProvider::HsHomeScreenClientServiceProvider(QObject *parent)
  : XQServiceProvider(gInterfaceName, parent),
    mWaitDialog(0),
    mShowAnimation(false),
    mAsyncRequestIndex(0),    
    mReturnValue(false),
    mWallpaper(0)
{
    publishAll();
}

/*!
    Destructor.
*/
HsHomeScreenClientServiceProvider::~HsHomeScreenClientServiceProvider()
{
}

#ifdef COVERAGE_MEASUREMENT
#pragma CTC SKIP
#endif //COVERAGE_MEASUREMENT

/*!
    Adds new widget, with the give \a uri and \a preferences,
    to the active home screen page.
*/
bool HsHomeScreenClientServiceProvider::addWidget(const QString &uri, const QVariantHash &preferences)
{
    return HsContentService::instance()->addWidget(uri, preferences);
}

/*!
    Changes \a fileName image to the active home screen page's wallpaper.
*/
void HsHomeScreenClientServiceProvider::setWallpaper(const QString &fileName)
{
#ifndef HOMESCREEN_TEST //We can't use QtHighway at unit tests due to missing service client connection
    mAsyncRequestIndex = setCurrentRequestAsync();
#endif
    if ( !mWaitDialog ) {
        mWaitDialog = new HsSpinnerDialog();
        }
    mWaitDialog->start();
    mShowAnimation = true;
    if (HSCONFIGURATION_GET(sceneType) == HsConfiguration::PageWallpapers) {
        mWallpaper = HsScene::instance()->activePage()->wallpaper();
    } else {
        mWallpaper = HsScene::instance()->wallpaper();
    }
    connect(mWallpaper, SIGNAL(imageSet()), SLOT(onImageSet()));
    connect(mWallpaper, SIGNAL(imageSetFailed()),
            SLOT(onImageSetFailed()));
    mWallpaper->setImage(fileName);
}

/*!
    \internal
    Called when wallpaper image has been set successfully  
*/
void HsHomeScreenClientServiceProvider::onImageSet()
{
    mWallpaper->disconnect(this);
    stopAnimation();
#ifndef HOMESCREEN_TEST //We can't use QtHighway at unit tests due to missing service client connection
    completeRequest(mAsyncRequestIndex, QVariant(true));
#endif
}

/*!
    \internal
    Called when error has happened in wallpaper image setting
*/
void HsHomeScreenClientServiceProvider::onImageSetFailed()
{
    mWallpaper->disconnect(this);
    stopAnimation();
#ifndef HOMESCREEN_TEST //We can't use QtHighway at unit tests due to missing service client connection
    completeRequest(mAsyncRequestIndex, QVariant(false));
#endif
}

/*!
    Stops progress animation
*/
void HsHomeScreenClientServiceProvider::stopAnimation()
{
    if (mShowAnimation) {
        mWaitDialog->stop();
        mWaitDialog=0;
    }
}

/*!

*/
bool HsHomeScreenClientServiceProvider::widgetUninstalled(const QVariantHash &widgetDescriptor)
{
    HsWidgetComponentDescriptor widgetComponent = widgetComponentDescriptor(widgetDescriptor);
    HsWidgetComponentRegistry* widgetRegistry = HsWidgetComponentRegistry::instance();
    widgetRegistry->uninstallComponent(widgetComponent);
    return true;
}


#ifdef COVERAGE_MEASUREMENT
#pragma CTC ENDSKIP
#endif //COVERAGE_MEASUREMENT

/*!

*/
HsWidgetComponentDescriptor HsHomeScreenClientServiceProvider::widgetComponentDescriptor(const QVariantHash& widgetDescriptor)
{
    HsWidgetComponentDescriptor widget;
    widget.installationPath = widgetDescriptor["installationPath"].toString();
    widget.uri = widgetDescriptor["uri"].toString();
    widget.title = widgetDescriptor["title"].toString();
    widget.description = widgetDescriptor["description"].toString();
    widget.iconUri = widgetDescriptor["iconUri"].toString();
    widget.hidden = widgetDescriptor["hidden"].toString();
    widget.serviceXml = widgetDescriptor["serviceXml"].toString();
    widget.version = widgetDescriptor["version"].toString();
    return widget;
}