homescreenapp/hsdomainmodel/src/hswidgetcomponentregistry.cpp
changeset 39 4e8ebe173323
child 46 23b5d6a29cce
equal deleted inserted replaced
36:cdae8c6c3876 39:4e8ebe173323
       
     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 "hswidgetcomponentregistry.h"
       
    19 #include "hswidgetcomponent.h"
       
    20 #include <QSignalMapper>
       
    21 QScopedPointer<HsWidgetComponentRegistry> HsWidgetComponentRegistry::mInstance(0);
       
    22 
       
    23 /*!
       
    24 
       
    25 */
       
    26 HsWidgetComponentRegistry* HsWidgetComponentRegistry::instance()
       
    27 {
       
    28     if (!mInstance) {
       
    29         mInstance.reset(new HsWidgetComponentRegistry);
       
    30     }
       
    31     return mInstance.data();
       
    32 }
       
    33 
       
    34 /*!
       
    35 
       
    36 */
       
    37 HsWidgetComponentRegistry::~HsWidgetComponentRegistry()
       
    38 {
       
    39     qDeleteAll(mRegistry);
       
    40 }
       
    41 
       
    42 /*!
       
    43 
       
    44 */
       
    45 HsWidgetComponent *HsWidgetComponentRegistry::component(const QString &uri)
       
    46 {
       
    47 	if (mRegistry.contains(uri)) {
       
    48         return mRegistry.value(uri);
       
    49 	}
       
    50 
       
    51 	QScopedPointer<HsWidgetComponent> c(new HsWidgetComponent(uri));
       
    52 	mRegistry.insert(uri, c.data());
       
    53  	connect(c.data(), SIGNAL(aboutToUninstall()), mSignalMapper.data(), 
       
    54         SLOT(map()));
       
    55     mSignalMapper->setMapping(c.data(),uri);
       
    56 	return c.take();
       
    57 }
       
    58 
       
    59 /*!
       
    60 
       
    61 */
       
    62 HsWidgetComponentRegistry::HsWidgetComponentRegistry(QObject *parent)
       
    63   : QObject(parent),mSignalMapper(new QSignalMapper())
       
    64 {
       
    65     connect(mSignalMapper.data(),SIGNAL(mapped(QString)),SLOT(onAboutToUninstall(QString)));
       
    66 }
       
    67 
       
    68 /*!
       
    69 
       
    70 */
       
    71 void HsWidgetComponentRegistry::onAboutToUninstall(const QString &uri)
       
    72 {
       
    73     if (mRegistry.contains(uri)) {
       
    74         mRegistry.take(uri)->deleteLater();
       
    75     }
       
    76 }