|
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 |
|
19 |
|
20 #include <qservicemanager.h> |
|
21 #include <qservicefilter.h> |
|
22 #include <qserviceinterfacedescriptor.h> |
|
23 #include <QGraphicsWidget> |
|
24 #include "hshostedwidgetfactory.h" |
|
25 |
|
26 QTM_USE_NAMESPACE |
|
27 |
|
28 /*! |
|
29 \class HsWidgetFactory |
|
30 \ingroup group_hsdomainmodel |
|
31 \brief Each widget is controlled by the home screen framework through a widget host. |
|
32 */ |
|
33 |
|
34 |
|
35 struct HsHostedWidgetFactoryImpl{ |
|
36 QServiceManager mServiceManager; |
|
37 QServiceFilter mFilter; |
|
38 }; |
|
39 |
|
40 |
|
41 |
|
42 HsHostedWidgetFactory *HsHostedWidgetFactory::mInstance = 0; |
|
43 |
|
44 HsHostedWidgetFactory *HsHostedWidgetFactory::instance() |
|
45 { |
|
46 if (!mInstance) { |
|
47 mInstance = new HsHostedWidgetFactory; |
|
48 } |
|
49 return mInstance; |
|
50 } |
|
51 |
|
52 HsHostedWidgetFactory *HsHostedWidgetFactory::takeInstance() |
|
53 { |
|
54 HsHostedWidgetFactory *instance = mInstance; |
|
55 mInstance = 0; |
|
56 return instance; |
|
57 } |
|
58 |
|
59 HsHostedWidgetFactory *HsHostedWidgetFactory::setInstance |
|
60 (HsHostedWidgetFactory *instance) |
|
61 { |
|
62 HsHostedWidgetFactory *old = mInstance; |
|
63 if (mInstance != instance) { |
|
64 mInstance = instance; |
|
65 } |
|
66 return old; |
|
67 } |
|
68 |
|
69 QObject *HsHostedWidgetFactory::createWidget(const QString &uri) |
|
70 { |
|
71 mImpl->mFilter.setServiceName(uri); |
|
72 QList<QServiceInterfaceDescriptor> interfaces = |
|
73 mImpl->mServiceManager.findInterfaces(mImpl->mFilter); |
|
74 |
|
75 if (interfaces.isEmpty()) { |
|
76 return 0; |
|
77 } |
|
78 // In theory we support QGraphicsWidget derived widgets |
|
79 QObject *widgetObject = mImpl->mServiceManager.loadInterface(interfaces.first()); |
|
80 |
|
81 if (!qobject_cast<QGraphicsWidget *>(widgetObject)) { |
|
82 delete widgetObject; |
|
83 widgetObject = 0; |
|
84 } |
|
85 return widgetObject; |
|
86 } |
|
87 |
|
88 /*! |
|
89 Constructs a new widget host with given \a databaseId and |
|
90 \a parent item. |
|
91 */ |
|
92 HsHostedWidgetFactory::HsHostedWidgetFactory(QObject *parent) |
|
93 : QObject(parent), |
|
94 mImpl(new HsHostedWidgetFactoryImpl) |
|
95 { |
|
96 mImpl->mFilter.setInterface("com.nokia.symbian.IHomeScreenWidget"); |
|
97 } |
|
98 |
|
99 /*! |
|
100 Destructor. |
|
101 */ |
|
102 HsHostedWidgetFactory::~HsHostedWidgetFactory() |
|
103 { |
|
104 delete mImpl; |
|
105 } |
|
106 |