|
1 /**************************************************************************** |
|
2 ** |
|
3 ** Copyright (C) 2008-2010 Nokia Corporation and/or its subsidiary(-ies). |
|
4 ** All rights reserved. |
|
5 ** Contact: Nokia Corporation (developer.feedback@nokia.com) |
|
6 ** |
|
7 ** This file is part of the HbCore module of the UI Extensions for Mobile. |
|
8 ** |
|
9 ** GNU Lesser General Public License Usage |
|
10 ** This file may be used under the terms of the GNU Lesser General Public |
|
11 ** License version 2.1 as published by the Free Software Foundation and |
|
12 ** appearing in the file LICENSE.LGPL included in the packaging of this file. |
|
13 ** Please review the following information to ensure the GNU Lesser General |
|
14 ** Public License version 2.1 requirements will be met: |
|
15 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. |
|
16 ** |
|
17 ** In addition, as a special exception, Nokia gives you certain additional |
|
18 ** rights. These rights are described in the Nokia Qt LGPL Exception |
|
19 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. |
|
20 ** |
|
21 ** If you have questions regarding the use of this file, please contact |
|
22 ** Nokia at developer.feedback@nokia.com. |
|
23 ** |
|
24 ****************************************************************************/ |
|
25 |
|
26 #include "hbthemeclient_p.h" |
|
27 #include "hbthemeclient_p_p.h" |
|
28 #include "hbsharedmemorymanager_p.h" |
|
29 #include "hbmemoryutils_p.h" |
|
30 |
|
31 static HbThemeClient *clientInst=0; |
|
32 static int sharedCacheOffset = -1; |
|
33 |
|
34 /** |
|
35 * Constructor |
|
36 */ |
|
37 HbThemeClient::HbThemeClient():d_ptr(new HbThemeClientPrivate) |
|
38 { |
|
39 |
|
40 } |
|
41 |
|
42 /** |
|
43 * HbThemeClient::connectToServer() |
|
44 */ |
|
45 bool HbThemeClient::connectToServer() |
|
46 { |
|
47 Q_D(HbThemeClient); |
|
48 return d->connectToServer(); |
|
49 } |
|
50 |
|
51 QSizeF HbThemeClient::getSharedIconDefaultSize(const QString &iconPath) |
|
52 { |
|
53 Q_D(HbThemeClient); |
|
54 return d->getSharedIconDefaultSize(iconPath); |
|
55 } |
|
56 |
|
57 /** |
|
58 * HbThemeClient::getSharedIconInfo() |
|
59 * |
|
60 * Returns HbIconInfo structure to the clients. This basically contains information about the shared |
|
61 * icon resources on server's shared memory |
|
62 * |
|
63 * \a iconPath |
|
64 * \a size |
|
65 * \a aspectRatioMode |
|
66 * \a mode |
|
67 * \a mirrored |
|
68 * \a options |
|
69 * \a color |
|
70 * |
|
71 |
|
72 */ |
|
73 HbSharedIconInfo HbThemeClient::getSharedIconInfo(const QString& iconPath , |
|
74 const QSizeF &size, |
|
75 Qt::AspectRatioMode aspectRatioMode, |
|
76 QIcon::Mode mode, |
|
77 bool mirrored, |
|
78 HbIconLoader::IconLoaderOptions options, |
|
79 const QColor &color) |
|
80 { |
|
81 Q_D(HbThemeClient); |
|
82 return d->getSharedIconInfo(iconPath, |
|
83 size, |
|
84 aspectRatioMode, |
|
85 mode, |
|
86 mirrored, |
|
87 options, |
|
88 color); |
|
89 } |
|
90 |
|
91 /** |
|
92 * HbThemeClient::getSharedBlob() |
|
93 * |
|
94 * \a name |
|
95 */ |
|
96 QByteArray HbThemeClient::getSharedBlob(const QString &name) |
|
97 { |
|
98 HbSharedIconInfo info = getSharedIconInfo( |
|
99 name, |
|
100 QSizeF(), |
|
101 Qt::KeepAspectRatio, |
|
102 QIcon::Normal, |
|
103 false, |
|
104 HbIconLoader::NoOptions, |
|
105 QColor()); |
|
106 return info.type == BLOB |
|
107 ? QByteArray::fromRawData(HbMemoryUtils::getAddress<char>( |
|
108 HbMemoryManager::SharedMemory, |
|
109 info.blobData.offset), |
|
110 info.blobData.dataSize) |
|
111 : QByteArray(); |
|
112 } |
|
113 |
|
114 |
|
115 HbSharedIconInfo HbThemeClient::getMultiPartIconInfo(const QStringList &multiPartIconList, |
|
116 const HbMultiPartSizeData &multiPartIconData , |
|
117 const QSizeF &size, |
|
118 Qt::AspectRatioMode aspectRatioMode, |
|
119 QIcon::Mode mode, |
|
120 bool mirrored, |
|
121 HbIconLoader::IconLoaderOptions options, |
|
122 const QColor &color) |
|
123 { |
|
124 Q_D(HbThemeClient); |
|
125 return d->getMultiPartIconInfo(multiPartIconList, multiPartIconData, size, aspectRatioMode, mode, mirrored, options, color); |
|
126 } |
|
127 |
|
128 void HbThemeClient::getThemeIndexTables(ThemeIndexTables &tables) |
|
129 { |
|
130 Q_D(HbThemeClient); |
|
131 d->getThemeIndexTables(tables); |
|
132 } |
|
133 |
|
134 /** |
|
135 * HbThemeClient::getSharedStyleSheet() |
|
136 * |
|
137 * \a fielName css filename |
|
138 * \a priority layer priority |
|
139 */ |
|
140 HbCss::StyleSheet *HbThemeClient::getSharedStyleSheet(const QString &fileName, HbLayeredStyleLoader::LayerPriority priority) |
|
141 { |
|
142 int offset = -1; |
|
143 if( HbLayeredStyleLoader::Priority_Core == priority ) { |
|
144 offset = sharedCacheItemOffset(fileName); |
|
145 } |
|
146 if ( -1 != offset ) { |
|
147 HbCss::StyleSheet *styleSheet = HbMemoryUtils::getAddress<HbCss::StyleSheet>(HbMemoryManager::SharedMemory,offset); |
|
148 return styleSheet; |
|
149 } |
|
150 Q_D(HbThemeClient); |
|
151 return d->getSharedStyleSheet(fileName,priority); |
|
152 } |
|
153 |
|
154 /** |
|
155 * HbThemeClient::getSharedLayoutDefs() |
|
156 * |
|
157 * \a fileName |
|
158 * \a layout |
|
159 * \a section |
|
160 */ |
|
161 LayoutDefinition *HbThemeClient::getSharedLayoutDefs(const QString &fileName,const QString &layout,const QString §ion) |
|
162 { |
|
163 int offset = sharedCacheItemOffset(fileName + layout + section); |
|
164 if ( -1 != offset ) { |
|
165 LayoutDefinition *layoutDefs = HbMemoryUtils::getAddress<LayoutDefinition>(HbMemoryManager::SharedMemory,offset); |
|
166 return layoutDefs; |
|
167 } |
|
168 Q_D(HbThemeClient); |
|
169 return d->getSharedLayoutDefs(fileName,layout,section); |
|
170 } |
|
171 /** |
|
172 * HbThemeClient::deviceProfiles() |
|
173 */ |
|
174 HbDeviceProfileList *HbThemeClient::deviceProfiles() |
|
175 { |
|
176 Q_D(HbThemeClient); |
|
177 return d->deviceProfiles(); |
|
178 } |
|
179 |
|
180 /** |
|
181 * HbThemeClient::globalCacheOffset() |
|
182 * |
|
183 */ |
|
184 int HbThemeClient::globalCacheOffset() |
|
185 { |
|
186 if ( -1 == sharedCacheOffset ) { |
|
187 Q_D(HbThemeClient); |
|
188 sharedCacheOffset = d->globalCacheOffset(); |
|
189 } |
|
190 return sharedCacheOffset; |
|
191 } |
|
192 |
|
193 /** |
|
194 * HbThemeClient::getSharedEffect() |
|
195 * |
|
196 * \a filePath |
|
197 */ |
|
198 HbEffectFxmlData *HbThemeClient::getSharedEffect(const QString &filePath) |
|
199 { |
|
200 int offset = sharedCacheItemOffset(filePath); |
|
201 if ( -1 != offset ) { |
|
202 HbEffectFxmlData *effectFxmlData = HbMemoryUtils::getAddress<HbEffectFxmlData>(HbMemoryManager::SharedMemory,offset); |
|
203 return effectFxmlData; |
|
204 } |
|
205 Q_D(HbThemeClient); |
|
206 return d->getSharedEffect(filePath); |
|
207 } |
|
208 |
|
209 /** |
|
210 * HbThemeClient::addSharedEffect() |
|
211 * |
|
212 * \a filePath |
|
213 */ |
|
214 bool HbThemeClient::addSharedEffect(const QString& filePath) |
|
215 { |
|
216 int offset = sharedCacheItemOffset(filePath); |
|
217 if ( -1 != offset ) { |
|
218 // effect already added. |
|
219 return true; |
|
220 } |
|
221 Q_D(HbThemeClient); |
|
222 return d->addSharedEffect(filePath); |
|
223 } |
|
224 |
|
225 /** |
|
226 * HbThemeClient::unloadIcon() |
|
227 * |
|
228 * \a iconPath |
|
229 * \a size |
|
230 * \a aspectRatioMode |
|
231 * \a mode |
|
232 * \a mirrored |
|
233 * \a options |
|
234 * \a color |
|
235 |
|
236 */ |
|
237 void HbThemeClient::unloadIcon(const QString& iconPath , |
|
238 const QSizeF &size, |
|
239 Qt::AspectRatioMode aspectRatioMode, |
|
240 QIcon::Mode mode, |
|
241 bool mirrored, |
|
242 const QColor &color) |
|
243 { |
|
244 Q_D(HbThemeClient); |
|
245 return d->unloadIcon(iconPath, |
|
246 size, |
|
247 aspectRatioMode, |
|
248 mode, |
|
249 mirrored, |
|
250 color); |
|
251 } |
|
252 |
|
253 /** |
|
254 * HbThemeClient::unLoadMultiIcon() |
|
255 * |
|
256 * \a iconPathList |
|
257 * \a sizeList |
|
258 * \a aspectRatioMode |
|
259 * \a mode |
|
260 * \a mirrored |
|
261 * \a color |
|
262 */ |
|
263 void HbThemeClient::unLoadMultiIcon(const QStringList& iconPathList, |
|
264 const QVector<QSizeF> &sizeList, |
|
265 Qt::AspectRatioMode aspectRatioMode, |
|
266 QIcon::Mode mode, |
|
267 bool mirrored, |
|
268 const QColor &color) |
|
269 { |
|
270 Q_D(HbThemeClient); |
|
271 return d->unLoadMultiIcon(iconPathList, |
|
272 sizeList, |
|
273 aspectRatioMode, |
|
274 mode, |
|
275 mirrored, |
|
276 color); |
|
277 } |
|
278 |
|
279 /** |
|
280 * HbThemeClient::~HbThemeClient() |
|
281 */ |
|
282 HbThemeClient::~HbThemeClient() |
|
283 { |
|
284 Q_D(HbThemeClient); |
|
285 delete d; |
|
286 } |
|
287 |
|
288 /** |
|
289 * HbThemeClient::clientConnected() |
|
290 */ |
|
291 bool HbThemeClient::clientConnected() const |
|
292 { |
|
293 Q_D(const HbThemeClient); |
|
294 return d->clientConnected; |
|
295 } |
|
296 |
|
297 /** |
|
298 * HbThemeClient::global() |
|
299 */ |
|
300 HbThemeClient *HbThemeClient::global() |
|
301 { |
|
302 if ( !clientInst ) { |
|
303 clientInst = new HbThemeClient; |
|
304 } |
|
305 return clientInst; |
|
306 } |
|
307 |
|
308 /** |
|
309 * HbThemeClient::releaseInstance() |
|
310 */ |
|
311 void HbThemeClient::releaseInstance() |
|
312 { |
|
313 delete clientInst; |
|
314 clientInst = 0; |
|
315 } |
|
316 |
|
317 /** |
|
318 * sharedCacheItemOffset function returns the offset of the cache item |
|
319 * for the given key |
|
320 * \param key |
|
321 * |
|
322 */ |
|
323 int HbThemeClient::sharedCacheItemOffset(const QString & key) |
|
324 { |
|
325 if ( -1 == sharedCacheOffset ) { |
|
326 // No IPC call happened so far for the globalCacheOffset |
|
327 globalCacheOffset(); |
|
328 } |
|
329 if ( -1 != sharedCacheOffset ) { |
|
330 HbSharedCache *sharedCache = HbMemoryUtils::getAddress<HbSharedCache>(HbMemoryManager::SharedMemory,sharedCacheOffset); |
|
331 int count = sharedCache->count(); |
|
332 for(int i = 0; i < count ; i++ ) { |
|
333 if (sharedCache->at(i).key == key) { |
|
334 return sharedCache->at(i).offset; |
|
335 } |
|
336 } |
|
337 } |
|
338 // item not found in the secondary cache. |
|
339 return -1; |
|
340 } |
|
341 |
|
342 #ifdef HB_THEME_SERVER_MEMORY_REPORT |
|
343 /** |
|
344 * createMemoryReport creates memory report from current shared memory |
|
345 * |
|
346 */ |
|
347 void HbThemeClient::createMemoryReport() const |
|
348 { |
|
349 Q_D(const HbThemeClient); |
|
350 d->createMemoryReport(); |
|
351 } |
|
352 #endif |
|
353 |
|
354 /** |
|
355 * getMultiIconInfo function returns a list of HbSharedIconInfo |
|
356 * for the given list of frameitems. |
|
357 */ |
|
358 HbSharedIconInfoList HbThemeClient::getMultiIconInfo(const QStringList &multiPartIconList, |
|
359 const QVector<QSizeF> &sizeList , |
|
360 Qt::AspectRatioMode aspectRatioMode, |
|
361 QIcon::Mode mode, |
|
362 bool mirrored, |
|
363 HbIconLoader::IconLoaderOptions options, |
|
364 const QColor &color) |
|
365 { |
|
366 Q_D(HbThemeClient); |
|
367 return d->getMultiIconInfo(multiPartIconList, sizeList,aspectRatioMode, mode, mirrored, options, color); |
|
368 } |
|
369 |
|
370 |