|
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: HsWidget factory. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include <QStringList> |
|
20 #include <QDir> |
|
21 #include <QPluginLoader> |
|
22 |
|
23 #include "hswidgetfactory.h" |
|
24 #include "hswidgetfactory_p.h" |
|
25 #include "hswidget.h" |
|
26 #include "hswidgetprovidermanifest.h" |
|
27 #include "hstest_global.h" |
|
28 |
|
29 |
|
30 |
|
31 /*DEPRECATED |
|
32 \class HsPluginUnloader |
|
33 \ingroup group_hswidgetmodel |
|
34 \brief Unloads plugin and deletes plugin loader. |
|
35 |
|
36 Holds plugin loader instance and unloads and destroys plugin |
|
37 on it's destructor. |
|
38 |
|
39 */ |
|
40 |
|
41 |
|
42 /*! |
|
43 \fn HsPluginUnloader::HsPluginUnloader(QPluginLoader *pluginLoader,QObject *parent) |
|
44 |
|
45 Constructs plugin unloader object. When this object is destroyed it |
|
46 unloads it's pointed \a pluginLoader instance. |
|
47 */ |
|
48 HsPluginUnloader::HsPluginUnloader(QPluginLoader *pluginLoader,QObject *parent) |
|
49 :QObject(parent),mPluginLoader(pluginLoader) |
|
50 { |
|
51 } |
|
52 |
|
53 /*! |
|
54 \fn HsPluginUnloader::~HsPluginUnloader() |
|
55 |
|
56 Unloads it's plugin loader instance. |
|
57 */ |
|
58 HsPluginUnloader::~HsPluginUnloader() |
|
59 { |
|
60 if(mPluginLoader) { |
|
61 mPluginLoader->unload(); |
|
62 delete mPluginLoader; |
|
63 } |
|
64 } |
|
65 |
|
66 /*DEPRECATED |
|
67 \class HsWidgetFactory |
|
68 \ingroup group_hswidgetmodel |
|
69 \brief Finds and creates home screen widgets. |
|
70 |
|
71 HsWidget factory creates an instance of |
|
72 a widget base on a widget token that is given to it. |
|
73 |
|
74 */ |
|
75 |
|
76 |
|
77 HsWidgetFactoryPrivate::HsWidgetFactoryPrivate(HsWidgetFactory *factory): |
|
78 mPublic(factory) |
|
79 { |
|
80 |
|
81 } |
|
82 |
|
83 |
|
84 HsWidgetFactoryPrivate::~HsWidgetFactoryPrivate() |
|
85 { |
|
86 |
|
87 } |
|
88 |
|
89 |
|
90 |
|
91 HsWidget* HsWidgetFactoryPrivate::createWidget(const HsWidgetToken &token) |
|
92 { |
|
93 QPluginLoader* loader = new QPluginLoader(token.mLibrary); |
|
94 QObject* plugin = loader->instance(); |
|
95 IHsWidgetProvider* provider = qobject_cast<IHsWidgetProvider*>(plugin); |
|
96 HsWidget* widget(0); |
|
97 |
|
98 if (provider) { |
|
99 widget = provider->createWidget(token); |
|
100 |
|
101 if (!widget) { |
|
102 HSDEBUG("Widget creation failed.") |
|
103 loader->unload(); |
|
104 delete loader; |
|
105 } |
|
106 else { |
|
107 HsPluginUnloader* p = new HsPluginUnloader(loader); |
|
108 p->connect(widget,SIGNAL(destroyed()),SLOT(deleteLater())); |
|
109 } |
|
110 } |
|
111 |
|
112 else { |
|
113 HSDEBUG("Widget creation failed - No provider.") |
|
114 loader->unload(); |
|
115 delete loader; |
|
116 } |
|
117 |
|
118 |
|
119 return widget; |
|
120 } |
|
121 |
|
122 /*! |
|
123 Constructor |
|
124 */ |
|
125 HsWidgetFactory::HsWidgetFactory(QObject *parent) |
|
126 : QObject(parent),mD(new HsWidgetFactoryPrivate(this)) |
|
127 { |
|
128 } |
|
129 /*! |
|
130 Destructor |
|
131 */ |
|
132 HsWidgetFactory::~HsWidgetFactory() |
|
133 { |
|
134 delete mD; |
|
135 } |
|
136 |
|
137 |
|
138 /*! |
|
139 Creates and returns a widget based on given \a token |
|
140 */ |
|
141 HsWidget* HsWidgetFactory::createWidget(const HsWidgetToken &token) |
|
142 { |
|
143 return mD->createWidget(token); |
|
144 } |
|
145 |
|
146 |