27 #include "hbthemeserverutils_p.h" |
27 #include "hbthemeserverutils_p.h" |
28 #include "hbmemorymanager_p.h" |
28 #include "hbmemorymanager_p.h" |
29 #include "hbiconsource_p.h" |
29 #include "hbiconsource_p.h" |
30 #include "hbthemeindex_p.h" |
30 #include "hbthemeindex_p.h" |
31 #include "hbthemeutils_p.h" |
31 #include "hbthemeutils_p.h" |
|
32 #include "hbsharedmemorymanager_p.h" |
32 |
33 |
33 #include <QHash> |
34 #include <QHash> |
34 #include <QImage> |
35 #include <QImage> |
35 #include <QSettings> |
|
36 #include <QSharedMemory> |
36 #include <QSharedMemory> |
37 #include <QDebug> |
37 #include <QDebug> |
38 #include <QProcess> |
38 #include <QProcess> |
39 #include <QFile> |
39 #include <QFile> |
40 #include <QPainter> |
40 #include <QPainter> |
|
41 #include <QSettings> |
41 #include <QSizeF> |
42 #include <QSizeF> |
42 #include <e32property.h> |
43 #include <e32property.h> |
43 #include <e32base.h> |
44 #include <e32base.h> |
44 #include <e32svr.h> |
45 #include <e32svr.h> |
45 #include "hbpixmapiconprocessor_p.h" |
46 #include "hbpixmapiconprocessor_p.h" |
46 #include "hbpixmapiconimpl_p.h" |
47 #include "hbpixmapiconimpl_p.h" |
47 #include "hblayeredstyleloader_p.h" |
48 #include "hblayeredstyleloader_p.h" |
48 #include "hbmemoryutils_p.h" |
49 #include "hbmemoryutils_p.h" |
49 #include "hbdeviceprofiledatabase_p.h" |
50 #include "hbdeviceprofiledatabase_p.h" |
|
51 #include "hbthemesystemeffect_p.h" |
50 #ifdef HB_SGIMAGE_ICON |
52 #ifdef HB_SGIMAGE_ICON |
51 #include "hbsgimagerenderer_p.h" |
53 #include "hbsgimagerenderer_p.h" |
52 #endif |
54 #endif |
53 // 5 MB GPU cache size |
55 // 5 MB GPU cache size |
54 #define GPU_CACHE_SIZE 0x500000 |
56 #define GPU_CACHE_SIZE 0x500000 |
55 |
57 |
56 // 5 MB CPU cache size |
58 // 5 MB CPU cache size |
57 #define CPU_CACHE_SIZE 0x500000 |
59 #define CPU_CACHE_SIZE 0x500000 |
58 |
60 |
59 const TInt KThemeName = 0; |
61 static const TInt KThemeName = 0; |
60 |
62 |
|
63 // Publish/Subscribe themeRequestProp specific |
|
64 static _LIT_SECURITY_POLICY_PASS(KAllowAllPolicy); |
|
65 static _LIT_SECURITY_POLICY_C1(KThemeChangerPolicy,ECapabilityWriteDeviceData); |
61 |
66 |
62 |
67 |
63 static HbThemeServerPrivate *TheServer = 0; |
68 static HbThemeServerPrivate *TheServer = 0; |
64 bool HbThemeServerPrivate::gpuGoodMemoryState = true; |
69 bool HbThemeServerPrivate::gpuGoodMemoryState = true; |
65 // This is used as parent theme always regardless of the active theme |
70 // This is used as parent theme always regardless of the active theme |
66 static const char *baseThemeName = "hbdefault"; |
|
67 const int themeIndexFailed = -2; // error code to indicate failure in processing theme index |
71 const int themeIndexFailed = -2; // error code to indicate failure in processing theme index |
68 |
72 |
69 //********************************** |
73 //********************************** |
70 //HbThemeServerPrivate |
74 //HbThemeServerPrivate |
71 //********************************** |
75 //********************************** |
98 User::LeaveIfError( err ); |
102 User::LeaveIfError( err ); |
99 } |
103 } |
100 TInt error = iThemeProperty.Attach(KServerUid3, KThemeName ); |
104 TInt error = iThemeProperty.Attach(KServerUid3, KThemeName ); |
101 User::LeaveIfError(error); |
105 User::LeaveIfError(error); |
102 |
106 |
103 QSettings settings(QLatin1String(ORGANIZATION), QLatin1String(THEME_COMPONENT)); |
|
104 // Store the active theme name in a member string |
107 // Store the active theme name in a member string |
105 iCurrentThemeName = settings.value("currenttheme").toString(); |
108 iCurrentThemeName = HbThemeUtils::getThemeSetting(HbThemeUtils::CurrentThemeSetting); |
106 |
109 |
107 // HACK |
|
108 if (iCurrentThemeName.isEmpty()) { |
110 if (iCurrentThemeName.isEmpty()) { |
109 iCurrentThemeName = "sfblacktheme"; |
111 iCurrentThemeName = HbThemeUtils::defaultTheme().name; |
110 } |
112 HbThemeUtils::setThemeSetting(HbThemeUtils::CurrentThemeSetting, iCurrentThemeName); |
|
113 } |
|
114 // Register theme system effects in construction |
|
115 HbThemeSystemEffect::handleThemeChange(iCurrentThemeName); |
111 |
116 |
112 // TODO: Get default theme name if current theme setting does not return theme name |
117 |
113 |
118 // Set the current theme also in the pubsub key that is used to notify clients. |
114 /* |
119 TPtrC currentThemePtr(reinterpret_cast<const TUint16 *>(iCurrentThemeName.constData())); |
115 if (iCurrentThemeName.isEmpty()) { |
120 iThemeProperty.Set(currentThemePtr); |
116 iCurrentThemeName = HbThemeUtils::defaultTheme(); |
121 |
117 settings.setValue("currenttheme", iCurrentThemeName); |
122 // Resolve the drive letter of the current theme |
118 settings.sync(); |
123 resolveCurrentThemeDrive(); |
119 TPtrC name(reinterpret_cast<const TUint16 *>(iCurrentThemeName.constData())); |
124 // Open index file to prevent uninstallation of the active theme |
120 iThemeProperty.Set(name); |
125 openCurrentIndexFile(); |
121 } |
|
122 */ |
|
123 |
|
124 cache = 0; |
126 cache = 0; |
125 cssCache = 0; |
127 cssCache = 0; |
126 |
128 |
127 QT_TRY { |
129 QT_TRY { |
128 //Create the Icon cache |
130 //Create the Icon cache |
135 qt_symbian_exception2LeaveL(badalloc); |
137 qt_symbian_exception2LeaveL(badalloc); |
136 } |
138 } |
137 setMaxGpuCacheSize(GPU_CACHE_SIZE); |
139 setMaxGpuCacheSize(GPU_CACHE_SIZE); |
138 setMaxCpuCacheSize(CPU_CACHE_SIZE); |
140 setMaxCpuCacheSize(CPU_CACHE_SIZE); |
139 |
141 |
|
142 const QString &baseThemeName = HbThemeUtils::baseTheme().name; |
140 // Process base theme index, it is used as parent index also when the current theme is something else |
143 // Process base theme index, it is used as parent index also when the current theme is something else |
141 processThemeIndex(baseThemeName, QChar('Z')); |
144 processThemeIndex(baseThemeName, QChar('Z')); |
142 baseThemeIndexKey = themeIndexKey(baseThemeName, QChar('Z')); |
145 baseThemeIndexKey = themeIndexKey(baseThemeName, QChar('Z')); |
143 |
146 |
144 // Temporary hack for pre-loading app. background graphics in server startup to give more realistic |
147 // Temporary hack for pre-loading app. background graphics in server startup to give more realistic |
145 // results in performance tests. (Normally these graphics get loaded anyway when the first hb app is started.) |
148 // results in performance tests. (Normally these graphics get loaded anyway when the first hb app is started.) |
146 #ifndef HB_NVG_CS_ICON |
149 #ifndef HB_NVG_CS_ICON |
147 QProcess::startDetached("hbiconpreloader.exe"); |
150 QProcess::startDetached("hbiconpreloader.exe"); |
148 #endif |
151 #endif |
149 |
152 |
|
153 // Cache ROM theme(name)s |
|
154 QString romPath = "Z:\\resource\\hb\\themes\\icons\\"; |
|
155 QDir dir(romPath); |
|
156 romThemeNames = dir.entryList(QDir::Dirs); |
|
157 |
150 // Start the splash screen generator app. |
158 // Start the splash screen generator app. |
151 //QProcess::startDetached("hbsplashgenerator.exe"); |
159 //QProcess::startDetached("hbsplashgenerator.exe"); |
152 } |
160 } |
153 |
161 |
154 /** |
162 /** |
165 : CServer2( aActiveObjectPriority ), |
173 : CServer2( aActiveObjectPriority ), |
166 currentThemeDrive('Z') // Assume default theme is in ROM |
174 currentThemeDrive('Z') // Assume default theme is in ROM |
167 { |
175 { |
168 // Set server pointer in static variable |
176 // Set server pointer in static variable |
169 TheServer = this; |
177 TheServer = this; |
|
178 |
|
179 // Set up the listener to listen for Publish events |
|
180 TRAPD(err, iListener = CHbThemeChangeNotificationListener::NewL(*this)); |
|
181 if (err) { |
|
182 qWarning( "HbThemeServerPrivate::HbThemeServerPrivate: CHbThemeChangeNotificationListener::NewL failed = %d", err ); |
|
183 } else { |
|
184 TRAPD( err, iListener->startListening()); |
|
185 if (err) { |
|
186 qWarning( "HbThemeServerPrivate::HbThemeServerPrivate: iListener->startListening failed = %d", err ); |
|
187 } |
|
188 } |
170 } |
189 } |
171 |
190 |
172 /** |
191 /** |
173 Destructor |
192 Destructor |
174 */ |
193 */ |
205 void HbThemeServerPrivate::resolveCurrentThemeDrive() |
230 void HbThemeServerPrivate::resolveCurrentThemeDrive() |
206 { |
231 { |
207 if (!iCurrentThemeName.isEmpty()) { |
232 if (!iCurrentThemeName.isEmpty()) { |
208 // Check for the theme's icon directory in different drives. |
233 // Check for the theme's icon directory in different drives. |
209 // ROM is checked first and then phone memory and memory card drives. |
234 // ROM is checked first and then phone memory and memory card drives. |
210 |
235 |
211 QString filename = "Z:\\resource\\hb\\themes\\icons\\"; |
236 // ROM theme names can't change after they have been cached in server |
212 filename.append(iCurrentThemeName); |
237 // construction time, so first check from there |
213 |
238 if (romThemeNames.contains(iCurrentThemeName)) { |
214 if (QFile::exists(filename)) { |
|
215 currentThemeDrive = 'Z'; |
239 currentThemeDrive = 'Z'; |
216 return; |
240 return; |
217 } |
241 } |
218 |
242 |
219 filename[0] = 'C'; |
243 QString filename = "C:\\resource\\hb\\themes\\icons\\"; |
220 if (QFile::exists(filename)) { |
244 filename.append(iCurrentThemeName); |
|
245 filename.append("\\index.theme"); |
|
246 QFile file; |
|
247 |
|
248 file.setFileName(filename); |
|
249 if (file.open(QIODevice::ReadOnly)) { |
221 currentThemeDrive = 'C'; |
250 currentThemeDrive = 'C'; |
|
251 file.close(); |
222 return; |
252 return; |
223 } |
253 } |
224 |
254 |
225 filename[0] = 'E'; |
255 filename[0] = 'E'; |
226 if (QFile::exists(filename)) { |
256 file.setFileName(filename); |
|
257 if (file.open(QIODevice::ReadOnly)) { |
227 currentThemeDrive = 'E'; |
258 currentThemeDrive = 'E'; |
|
259 file.close(); |
|
260 return; |
|
261 } |
|
262 |
|
263 filename[0] = 'F'; |
|
264 file.setFileName(filename); |
|
265 if (file.open(QIODevice::ReadOnly)) { |
|
266 currentThemeDrive = 'F'; |
|
267 file.close(); |
228 return; |
268 return; |
229 } |
269 } |
230 |
270 |
231 // Default to 'Z' if not found in any drive |
271 // Default to 'Z' if not found in any drive |
232 currentThemeDrive = 'Z'; |
272 currentThemeDrive = 'Z'; |
233 } |
273 } |
|
274 } |
|
275 |
|
276 /** |
|
277 Handles theme selection |
|
278 */ |
|
279 void HbThemeServerPrivate::HandleThemeSelection( const QString& themeName) |
|
280 { |
|
281 //Make a copy for ourselves |
|
282 |
|
283 |
|
284 QString cleanThemeName = themeName.trimmed(); |
|
285 |
|
286 if (cleanThemeName == iCurrentThemeName) { |
|
287 // Theme did not change, return. |
|
288 return; |
|
289 } |
|
290 // ToDo: Validate the theme name somehow |
|
291 |
|
292 #ifdef THEME_INDEX_TRACES |
|
293 qDebug() << "ThemeIndex: theme change request, new theme =" << cleanThemeName.toUtf8(); |
|
294 #endif |
|
295 |
|
296 iCurrentThemeName = cleanThemeName; |
|
297 |
|
298 // Resolve the drive letter of the current theme |
|
299 resolveCurrentThemeDrive(); |
|
300 |
|
301 currentIndexfile.close(); |
|
302 // Open index file to prevent uninstallation of the active theme |
|
303 openCurrentIndexFile(); |
|
304 |
|
305 // Clear cached icons and session data |
|
306 clearIconCache(); |
|
307 iSessionIter.SetToFirst(); |
|
308 while(iSessionIter != NULL) { |
|
309 HbThemeServerSession &session = reinterpret_cast<HbThemeServerSession &>(*iSessionIter); |
|
310 session.ClearSessionData(); |
|
311 iSessionIter++; |
|
312 } |
|
313 |
|
314 HbThemeSystemEffect::handleThemeChange(cleanThemeName); |
|
315 |
|
316 QSettings settings(QLatin1String(ORGANIZATION), QLatin1String(THEME_COMPONENT)); |
|
317 settings.setValue(CURRENT_THEME_KEY, cleanThemeName); |
|
318 settings.sync(); |
|
319 TPtrC name(reinterpret_cast<const TUint16 *>(cleanThemeName.constData())); |
|
320 TInt err = iThemeProperty.Set(name); |
|
321 User::LeaveIfError(err); |
234 } |
322 } |
235 |
323 |
236 /** |
324 /** |
237 Creates a new session with the server. |
325 Creates a new session with the server. |
238 */ |
326 */ |
338 { |
426 { |
339 /* |
427 /* |
340 Don't call any HbIconDataCache functions if HbThemeServerPrivate has already deleted it, |
428 Don't call any HbIconDataCache functions if HbThemeServerPrivate has already deleted it, |
341 which happens when ThemeServer is closed before the client(s). |
429 which happens when ThemeServer is closed before the client(s). |
342 */ |
430 */ |
343 if (cache) |
431 if (cache) { |
344 cache->remove(key); |
432 cache->remove(key); |
|
433 } |
|
434 } |
|
435 |
|
436 /** |
|
437 * HbThemeServerPrivate::IconTypeInCache |
|
438 * |
|
439 * Returns the Icon Format Type i.e SGIMAGE,NVG,SVG etc...if it is present in cache |
|
440 * else returns INVALID_FORMAT |
|
441 */ |
|
442 HbIconFormatType HbThemeServerPrivate::IconTypeInCache( const HbIconKey &key ) const |
|
443 { |
|
444 if ( key.filename.isEmpty() || !cache->contains(key) ) { |
|
445 return INVALID_FORMAT; |
|
446 } |
|
447 HbIconCacheItem* item = cache->value(key); |
|
448 if ( item->rasterIconData.type != INVALID_FORMAT ) { |
|
449 return item->rasterIconData.type; |
|
450 } else { |
|
451 return item->vectorIconData.type; |
|
452 } |
345 } |
453 } |
346 |
454 |
347 /** |
455 /** |
348 * HbThemeServerPrivate::CleanupSessionCssItem |
456 * HbThemeServerPrivate::CleanupSessionCssItem |
349 * |
457 * |
390 bool HbThemeServerPrivate::gpuMemoryState() |
499 bool HbThemeServerPrivate::gpuMemoryState() |
391 { |
500 { |
392 return gpuGoodMemoryState; |
501 return gpuGoodMemoryState; |
393 } |
502 } |
394 |
503 |
|
504 int HbThemeServerPrivate::freeSharedMemory() |
|
505 { |
|
506 GET_MEMORY_MANAGER(HbMemoryManager::SharedMemory); |
|
507 return static_cast<HbSharedMemoryManager *>(manager)->freeSharedMemory(); |
|
508 } |
|
509 |
|
510 int HbThemeServerPrivate::allocatedSharedMemory() |
|
511 { |
|
512 GET_MEMORY_MANAGER(HbMemoryManager::SharedMemory); |
|
513 return static_cast<HbSharedMemoryManager *>(manager)->allocatedSharedMemory(); |
|
514 } |
|
515 |
|
516 int HbThemeServerPrivate::allocatedHeapMemory() |
|
517 { |
|
518 TInt heapSize = 0; |
|
519 User::AllocSize(heapSize); |
|
520 return heapSize; |
|
521 } |
395 |
522 |
396 //Debug Code for Test Purpose |
523 //Debug Code for Test Purpose |
397 #ifdef HB_ICON_CACHE_DEBUG |
524 #ifdef HB_ICON_CACHE_DEBUG |
398 int HbThemeServerPrivate ::cacheIconCount() const |
525 int HbThemeServerPrivate ::cacheIconCount() const |
399 { |
526 { |
402 |
529 |
403 unsigned long HbThemeServerPrivate::totalGPUMemory() |
530 unsigned long HbThemeServerPrivate::totalGPUMemory() |
404 { |
531 { |
405 #ifdef HB_SGIMAGE_ICON |
532 #ifdef HB_SGIMAGE_ICON |
406 qDebug() << "Inside HbThemeServerSymbian::totalGPUMemory() " ; |
533 qDebug() << "Inside HbThemeServerSymbian::totalGPUMemory() " ; |
407 return HbSgImageRenderer::instance()->totalGPUMemory(); |
534 return HbSgImageRenderer::global()->totalGPUMemory(); |
408 #else |
535 #else |
409 return 0; |
536 return 0; |
410 #endif |
537 #endif |
411 } |
538 } |
412 |
539 |
413 unsigned long HbThemeServerPrivate::freeGPUMemory() |
540 unsigned long HbThemeServerPrivate::freeGPUMemory() |
414 { |
541 { |
415 #ifdef HB_SGIMAGE_ICON |
542 #ifdef HB_SGIMAGE_ICON |
416 qDebug() << "Inside HbThemeServerSymbian::freeGPUMemory() " ; |
543 qDebug() << "Inside HbThemeServerSymbian::freeGPUMemory() " ; |
417 return HbSgImageRenderer::instance()->freeGPUMemory(); |
544 return HbSgImageRenderer::global()->freeGPUMemory(); |
418 #else |
545 #else |
419 return 0; |
546 return 0; |
420 #endif |
547 #endif |
421 } |
548 } |
422 int HbThemeServerPrivate::freeVectorMemory() |
549 int HbThemeServerPrivate::freeVectorMemory() |
654 processThemeIndex(iCurrentThemeName, currentThemeDrive); |
781 processThemeIndex(iCurrentThemeName, currentThemeDrive); |
655 } |
782 } |
656 |
783 |
657 tables.tables[0] = themeIndexes.value(key, -1); |
784 tables.tables[0] = themeIndexes.value(key, -1); |
658 tables.drives[0] = currentThemeDrive; |
785 tables.drives[0] = currentThemeDrive; |
659 |
786 |
|
787 const QString &baseThemeName = HbThemeUtils::baseTheme().name; |
660 // Set base theme table as parent table if the current theme is not the base theme |
788 // Set base theme table as parent table if the current theme is not the base theme |
661 if (tables.tables[0] >= 0 && iCurrentThemeName != baseThemeName) { |
789 if (tables.tables[0] >= 0 && iCurrentThemeName != baseThemeName) { |
662 QString base(baseThemeName); |
790 QString base(baseThemeName); |
663 tables.tables[1] = themeIndexes.value(themeIndexKey(base, 'Z'), -1); |
791 tables.tables[1] = themeIndexes.value(themeIndexKey(base, 'Z'), -1); |
664 tables.drives[1] = 'Z'; |
792 tables.drives[1] = 'Z'; |
792 break; |
920 break; |
793 |
921 |
794 case EUnloadMultiIcon: |
922 case EUnloadMultiIcon: |
795 unloadMultiIcon(aMessage); |
923 unloadMultiIcon(aMessage); |
796 break; |
924 break; |
797 |
925 case ENotifyForegroundLost: |
|
926 #if defined(HB_SGIMAGE_ICON) || defined(HB_NVG_CS_ICON) |
|
927 freeClientGpuResources(); |
|
928 #endif |
|
929 break; |
798 //Debug Code for Test Purpose |
930 //Debug Code for Test Purpose |
799 #ifdef HB_ICON_CACHE_DEBUG |
931 #ifdef HB_ICON_CACHE_DEBUG |
800 case ECacheIconCount: { |
932 case ECacheIconCount: { |
801 TInt count = iServer->cacheIconCount(); |
933 TInt count = iServer->cacheIconCount(); |
802 TPckg<TInt> out(count); |
934 TPckg<TInt> out(count); |
960 |
1091 |
961 iServer->FreeGpuRam(params); |
1092 iServer->FreeGpuRam(params); |
962 break; |
1093 break; |
963 } |
1094 } |
964 |
1095 |
965 case EThemeIndex: { |
1096 case EThemeIndex: { |
966 // Using leave here because this function does not return a value |
1097 // Using leave here because this function does not return a value |
967 ThemeIndexTables tables; |
1098 ThemeIndexTables tables; |
968 iServer->getThemeIndexTables(tables); |
1099 iServer->getThemeIndexTables(tables); |
969 TPckg<ThemeIndexTables> out(tables); |
1100 TPckg<ThemeIndexTables> out(tables); |
970 aMessage.WriteL(0, out); |
1101 aMessage.WriteL(0, out); |
971 break; |
1102 break; |
972 } |
1103 } |
|
1104 |
|
1105 case EFreeSharedMem: { |
|
1106 int freeSharedMem = iServer->freeSharedMemory(); |
|
1107 TPckg<int> out(freeSharedMem); |
|
1108 aMessage.WriteL(1, out); |
|
1109 break; |
|
1110 } |
|
1111 case EAllocatedSharedMem: { |
|
1112 int allocatedSharedMem = iServer->allocatedSharedMemory(); |
|
1113 TPckg<int> out(allocatedSharedMem); |
|
1114 aMessage.WriteL(1, out); |
|
1115 break; |
|
1116 } |
|
1117 case EAllocatedHeapMem: { |
|
1118 int allocatedHeapMem = iServer->allocatedHeapMemory(); |
|
1119 TPckg<int> out(allocatedHeapMem); |
|
1120 aMessage.WriteL(1, out); |
|
1121 break; |
|
1122 } |
|
1123 |
973 |
1124 |
974 // This is an example of a request that we know about, but don't support. |
1125 // This is an example of a request that we know about, but don't support. |
975 // We cause KErrNotSupported to be returned to the client. |
1126 // We cause KErrNotSupported to be returned to the client. |
976 default: |
1127 default: |
977 PanicClient(aMessage, EBadRequest); |
1128 PanicClient(aMessage, EBadRequest); |
1036 } while (tryAgain); |
1187 } while (tryAgain); |
1037 } |
1188 } |
1038 if (insertKeyIntoSessionList) { |
1189 if (insertKeyIntoSessionList) { |
1039 //The session will only keep track of cssFiles that were either successfully found or were |
1190 //The session will only keep track of cssFiles that were either successfully found or were |
1040 //successfully inserted in the cache. |
1191 //successfully inserted in the cache. |
1041 sessionCssData.append(cssFileName); |
1192 if (!sessionCssData.contains(cssFileName)) { |
|
1193 sessionCssData.append(cssFileName); |
|
1194 } |
1042 } |
1195 } |
1043 TPckg<HbSharedStyleSheetInfo> data(offsetInfo); |
1196 TPckg<HbSharedStyleSheetInfo> data(offsetInfo); |
1044 aMessage.WriteL(2, data); |
1197 aMessage.WriteL(2, data); |
1045 } |
1198 } |
1046 |
1199 |
1221 if (tempIconCacheItem.data()) { |
1374 if (tempIconCacheItem.data()) { |
1222 tempIconCacheItem.take(); |
1375 tempIconCacheItem.take(); |
1223 } |
1376 } |
1224 } QT_CATCH(const std::bad_alloc &) { |
1377 } QT_CATCH(const std::bad_alloc &) { |
1225 data.type = INVALID_FORMAT; |
1378 data.type = INVALID_FORMAT; |
1226 FreeDataFromCacheItem(cacheItem); |
1379 if (cacheItem) { |
|
1380 FreeDataFromCacheItem(cacheItem); |
|
1381 } |
1227 } |
1382 } |
1228 } |
1383 } |
1229 if (insertKeyIntoSessionList) { |
1384 if (insertKeyIntoSessionList) { |
1230 //The session will only keep track of icons that were either successfully found or were |
1385 //The session will only keep track of icons that were either successfully found or were |
1231 //successfully inserted in the cache. |
1386 //successfully inserted in the cache. |
1254 User::Leave(ENonNumericString); |
1409 User::Leave(ENonNumericString); |
1255 } |
1410 } |
1256 QString newTheme((QChar*)buffer.Ptr(), buffer.Length()); |
1411 QString newTheme((QChar*)buffer.Ptr(), buffer.Length()); |
1257 CleanupStack::PopAndDestroy(); // close the buffer |
1412 CleanupStack::PopAndDestroy(); // close the buffer |
1258 |
1413 |
1259 QString cleanThemeName = newTheme.trimmed(); |
1414 QString cleanThemeName = newTheme.trimmed(); |
1260 |
1415 |
1261 if (cleanThemeName == iServer->iCurrentThemeName) { |
1416 if (cleanThemeName != iServer->iCurrentThemeName) { |
1262 // Theme did not change, return. |
1417 iServer->HandleThemeSelection(cleanThemeName); |
1263 return; |
1418 sessionData.clear(); |
1264 } |
1419 } |
1265 // ToDo: Validate the theme name somehow |
|
1266 |
|
1267 #ifdef THEME_INDEX_TRACES |
|
1268 qDebug() << "ThemeIndex: theme change request, new theme =" << cleanThemeName.toUtf8(); |
|
1269 #endif |
|
1270 |
|
1271 iServer->iCurrentThemeName = cleanThemeName; |
|
1272 |
|
1273 // Resolve the drive letter of the current theme |
|
1274 iServer->resolveCurrentThemeDrive(); |
|
1275 |
|
1276 iServer->currentIndexfile.close(); |
|
1277 // Open index file to prevent uninstallation of the active theme |
|
1278 iServer->openCurrentIndexFile(); |
|
1279 |
|
1280 QSettings settings(QLatin1String(ORGANIZATION), QLatin1String(THEME_COMPONENT)); |
|
1281 settings.setValue("currenttheme", cleanThemeName); |
|
1282 settings.sync(); |
|
1283 TPtrC name(reinterpret_cast<const TUint16 *>(cleanThemeName.constData())); |
|
1284 TInt err = iServer->iThemeProperty.Set(name); |
|
1285 User::LeaveIfError(err); |
|
1286 } |
1420 } |
1287 |
1421 |
1288 /** |
1422 /** |
1289 * Panics the client |
1423 * Panics the client |
1290 */ |
1424 */ |
1477 bool failedToCreateParts = false; |
1613 bool failedToCreateParts = false; |
1478 QString format; |
1614 QString format; |
1479 |
1615 |
1480 int nvgPiecesCount = 0; |
1616 int nvgPiecesCount = 0; |
1481 |
1617 |
1482 for (int i = 0; i < noOfPieces; i++) { |
1618 try { |
1483 HbSharedIconInfo data; |
1619 for (int i = 0; i < noOfPieces; i++) { |
1484 bool iconPieceMirrored = false; |
1620 HbSharedIconInfo data; |
1485 HbIconKey key(frameItemParams.multiPartIconList.at(i), frameItemParams.multiPartIconData.pixmapSizes[i], (Qt::AspectRatioMode)stichedKey.aspectRatioMode, (QIcon::Mode)stichedKey.mode, iconPieceMirrored, stichedKey.color); |
1621 bool iconPieceMirrored = false; |
1486 insertKeyIntoSessionList = IconInfoFromSingleIcon(key, data); |
1622 HbIconKey key(frameItemParams.multiPartIconList.at(i), frameItemParams.multiPartIconData.pixmapSizes[i], (Qt::AspectRatioMode)stichedKey.aspectRatioMode, (QIcon::Mode)stichedKey.mode, iconPieceMirrored, stichedKey.color); |
1487 if (!insertKeyIntoSessionList) { |
1623 insertKeyIntoSessionList = IconInfoFromSingleIcon(key, data); |
1488 insertKeyIntoSessionList = CreateCacheItemData(key, frameItemParams.options, data, true); |
1624 if (!insertKeyIntoSessionList) { |
1489 } |
1625 insertKeyIntoSessionList = CreateCacheItemData(key, frameItemParams.options, data, true); |
1490 if ((data.type == INVALID_FORMAT) || (!insertKeyIntoSessionList)) { |
|
1491 failedToCreateParts = true; |
|
1492 break; |
|
1493 } else { |
|
1494 if (data.type == NVG) { |
|
1495 ++nvgPiecesCount; |
|
1496 } |
1626 } |
1497 |
1627 if ((data.type == INVALID_FORMAT) || (!insertKeyIntoSessionList)) { |
1498 //The session will only keep track of icons that were either successfully found or were |
1628 failedToCreateParts = true; |
1499 //successfully inserted in the cache. |
1629 break; |
1500 keysInserted.append(key); |
1630 } else { |
1501 dataForParts.append(data); |
1631 if (data.type == NVG) { |
1502 } |
1632 ++nvgPiecesCount; |
1503 }//end of for |
1633 } |
|
1634 |
|
1635 //The session will only keep track of icons that were either successfully found or were |
|
1636 //successfully inserted in the cache. |
|
1637 keysInserted.append(key); |
|
1638 dataForParts.append(data); |
|
1639 } |
|
1640 }//end of for |
|
1641 } catch (std::exception &) { |
|
1642 failedToCreateParts = true; |
|
1643 } |
1504 bool allNvg = false; |
1644 bool allNvg = false; |
1505 |
1645 |
1506 if (nvgPiecesCount == noOfPieces) { |
1646 if (nvgPiecesCount == noOfPieces) { |
1507 #ifdef HB_SGIMAGE_ICON |
1647 #ifdef HB_SGIMAGE_ICON |
1508 // all individual icons are NVGs, can create sgImage |
1648 // all individual icons are NVGs, can create sgImage |
1532 } |
1672 } |
1533 stitchedData.type = INVALID_FORMAT; |
1673 stitchedData.type = INVALID_FORMAT; |
1534 return; |
1674 return; |
1535 } |
1675 } |
1536 // Create a stitched icon of the available piece shared iconinfos |
1676 // Create a stitched icon of the available piece shared iconinfos |
1537 if ((dataPartCount == noOfPieces) && (!failedToCreateParts) && |
1677 if ((dataPartCount == noOfPieces) && (!failedToCreateParts)) { |
1538 (CreateStichedIconInfoOfParts(dataForParts, frameItemParams, stichedKey, stitchedData, allNvg))) { |
1678 try { |
1539 sessionData.append(stichedKey); |
1679 if (CreateStichedIconInfoOfParts(dataForParts, frameItemParams, stichedKey, stitchedData, allNvg)) { |
|
1680 sessionData.append(stichedKey); |
|
1681 } |
|
1682 } catch(std::exception &) { |
|
1683 |
|
1684 } |
1540 } |
1685 } |
1541 |
1686 |
1542 QVector<HbIconKey>::const_iterator itEnd(keysInserted.constEnd()); |
1687 QVector<HbIconKey>::const_iterator itEnd(keysInserted.constEnd()); |
1543 for (QVector<HbIconKey>::const_iterator iter = keysInserted.constBegin(); |
1688 for (QVector<HbIconKey>::const_iterator iter = keysInserted.constBegin(); |
1544 iter != itEnd; |
1689 iter != itEnd; |
1660 QVector<HbIconKey> keysInserted; |
1805 QVector<HbIconKey> keysInserted; |
1661 |
1806 |
1662 bool insertKeyIntoSessionList = false; |
1807 bool insertKeyIntoSessionList = false; |
1663 QString format; |
1808 QString format; |
1664 QColor color = GetColorFromRgba(frameItemParams.rgba, frameItemParams.colorflag); |
1809 QColor color = GetColorFromRgba(frameItemParams.rgba, frameItemParams.colorflag); |
1665 for (int i = 0; i < noOfPieces; i++) { |
1810 try { |
1666 HbSharedIconInfo data; |
1811 for (int i = 0; i < noOfPieces; i++) { |
1667 QString pieceName((QChar*)frameItemParams.iconList[i].Ptr(), frameItemParams.iconList[i].Length()); |
1812 HbSharedIconInfo data; |
1668 HbIconKey key(pieceName, frameItemParams.sizeList[i], |
1813 QString pieceName((QChar*)frameItemParams.iconList[i].Ptr(), frameItemParams.iconList[i].Length()); |
1669 (Qt::AspectRatioMode)frameItemParams.aspectRatioMode, (QIcon::Mode)frameItemParams.mode, |
1814 HbIconKey key(pieceName, frameItemParams.sizeList[i], |
1670 (bool)frameItemParams.mirrored, color); |
1815 (Qt::AspectRatioMode)frameItemParams.aspectRatioMode, (QIcon::Mode)frameItemParams.mode, |
1671 insertKeyIntoSessionList = IconInfoFromSingleIcon(key, data); |
1816 (bool)frameItemParams.mirrored, color); |
1672 if (!insertKeyIntoSessionList) { |
1817 insertKeyIntoSessionList = IconInfoFromSingleIcon(key, data); |
1673 insertKeyIntoSessionList = CreateCacheItemData(key, 0, data, false); |
1818 if (!insertKeyIntoSessionList) { |
1674 } |
1819 insertKeyIntoSessionList = CreateCacheItemData(key, 0, data, false); |
1675 if ((data.type != INVALID_FORMAT) || (insertKeyIntoSessionList)) { |
1820 } |
1676 //The session will only keep track of icons that were either successfully found or were |
1821 if ((data.type != INVALID_FORMAT) || (insertKeyIntoSessionList)) { |
1677 //successfully inserted in the cache. |
1822 //The session will only keep track of icons that were either successfully found or were |
1678 keysInserted.append(key); |
1823 //successfully inserted in the cache. |
1679 iconInfoList.icon[i] = data; |
1824 keysInserted.append(key); |
1680 } |
1825 iconInfoList.icon[i] = data; |
1681 }//end of for |
1826 } |
|
1827 }//end of for |
|
1828 } catch (std::exception &) { |
|
1829 for (int i = 0; i < noOfPieces; i++) { |
|
1830 iconInfoList.icon[i].type = INVALID_FORMAT; |
|
1831 } |
|
1832 QVector<HbIconKey>::const_iterator itEnd(keysInserted.constEnd()); |
|
1833 for (QVector<HbIconKey>::const_iterator iter = keysInserted.constBegin();iter != itEnd;++iter) { |
|
1834 iServer->CleanupSessionIconItem(*iter); |
|
1835 } |
|
1836 } |
1682 } |
1837 } |
1683 |
1838 |
1684 void HbThemeServerSession::unLoadIcon(const RMessage2& aMessage) |
1839 void HbThemeServerSession::unLoadIcon(const RMessage2& aMessage) |
1685 { |
1840 { |
1686 TIconParams params = ReadMessageAndRetrieveParams(aMessage); |
1841 TIconParams params = ReadMessageAndRetrieveParams(aMessage); |
1714 iServer->CleanupSessionIconItem(key); |
1869 iServer->CleanupSessionIconItem(key); |
1715 sessionData.removeOne(key); |
1870 sessionData.removeOne(key); |
1716 } |
1871 } |
1717 } |
1872 } |
1718 |
1873 |
|
1874 /** |
|
1875 freeClientGpuResources - unloads all the GPU resources in the session |
|
1876 |
|
1877 Iterates all the keys in sessionData and if the Icon Format Type is SGIMage |
|
1878 or NVG then CleanUpSessionIConItem is called on that item, which will do the |
|
1879 cleanup based on the reference count. |
|
1880 */ |
|
1881 void HbThemeServerSession::freeClientGpuResources() |
|
1882 { |
|
1883 #if defined(HB_SGIMAGE_ICON) || defined(HB_NVG_CS_ICON) |
|
1884 QList<HbIconKey> tempSessionData(sessionData); |
|
1885 QList<HbIconKey>::const_iterator itEnd( tempSessionData.constEnd() ); |
|
1886 for ( QList<HbIconKey>::const_iterator iter = tempSessionData.constBegin(); |
|
1887 iter != itEnd; |
|
1888 ++iter ) { |
|
1889 if ( iServer->IconTypeInCache(*iter) == SGIMAGE |
|
1890 || iServer->IconTypeInCache(*iter) == NVG ) { |
|
1891 iServer->CleanupSessionIconItem(*iter); |
|
1892 // remove the item in the session data. |
|
1893 sessionData.removeOne(*iter); |
|
1894 } |
|
1895 } |
|
1896 #endif |
|
1897 } |
|
1898 |
|
1899 /** |
|
1900 * HbThemeServerSession::ClearSessionData |
|
1901 * |
|
1902 * Clears the session data list. Items in the server should be deleted before clearing. |
|
1903 */ |
|
1904 void HbThemeServerSession::ClearSessionData() |
|
1905 { |
|
1906 sessionData.clear(); |
|
1907 } |
|
1908 |
1719 #ifdef HB_ICON_CACHE_DEBUG |
1909 #ifdef HB_ICON_CACHE_DEBUG |
1720 /** |
1910 /** |
1721 * iconRefCount |
1911 * iconRefCount |
1722 */ |
1912 */ |
1723 #if defined (Q_OS_SYMBIAN) |
1913 #if defined (Q_OS_SYMBIAN) |
1748 return refCount; |
1938 return refCount; |
1749 } |
1939 } |
1750 #endif |
1940 #endif |
1751 |
1941 |
1752 #endif |
1942 #endif |
|
1943 |
|
1944 CHbThemeChangeNotificationListener* CHbThemeChangeNotificationListener::NewL(HbThemeServerPrivate& aObserver) |
|
1945 { |
|
1946 CHbThemeChangeNotificationListener* self = new (ELeave) CHbThemeChangeNotificationListener(aObserver); |
|
1947 CleanupStack::PushL(self); |
|
1948 self->ConstructL(); |
|
1949 CleanupStack::Pop(); |
|
1950 return self; |
|
1951 } |
|
1952 |
|
1953 CHbThemeChangeNotificationListener::CHbThemeChangeNotificationListener(HbThemeServerPrivate& aObserver) |
|
1954 :CActive(EPriorityStandard),iObserver(aObserver) |
|
1955 { |
|
1956 |
|
1957 } |
|
1958 |
|
1959 void CHbThemeChangeNotificationListener::ConstructL() |
|
1960 { |
|
1961 TInt err = RProperty::Define( KServerUid3, KNewThemeForThemeChanger, RProperty::ELargeText, KAllowAllPolicy, KThemeChangerPolicy ); |
|
1962 if ( err != KErrAlreadyExists ) { |
|
1963 User::LeaveIfError( err ); |
|
1964 } |
|
1965 err = themeRequestProp.Attach(KServerUid3, KNewThemeForThemeChanger ); |
|
1966 User::LeaveIfError(err); |
|
1967 |
|
1968 CActiveScheduler::Add(this); |
|
1969 } |
|
1970 |
|
1971 CHbThemeChangeNotificationListener::~CHbThemeChangeNotificationListener() |
|
1972 { |
|
1973 // Close the handle since it is not needed anymore |
|
1974 themeRequestProp.Close(); |
|
1975 Cancel(); |
|
1976 } |
|
1977 |
|
1978 void CHbThemeChangeNotificationListener::startListening() |
|
1979 { |
|
1980 if (IsActive()) { |
|
1981 return; //do nothing if allready listening |
|
1982 } |
|
1983 |
|
1984 User::LeaveIfError(themeRequestProp.Attach(KServerUid3,KNewThemeForThemeChanger)); |
|
1985 //Subscribe for updates |
|
1986 themeRequestProp.Subscribe(iStatus); |
|
1987 |
|
1988 SetActive(); |
|
1989 |
|
1990 } |
|
1991 |
|
1992 void CHbThemeChangeNotificationListener::stopListening() |
|
1993 { |
|
1994 Cancel(); // cancel |
|
1995 if(IsActive()) { // only if already listening |
|
1996 themeRequestProp.Close(); // Close the handle since it is not needed anymore |
|
1997 } |
|
1998 } |
|
1999 |
|
2000 /* |
|
2001 * Returns TRUE if parsing succeeded, FALSE otherwise |
|
2002 */ |
|
2003 bool CHbThemeChangeNotificationListener::parseData( TDesC& requestData, HbThemeServerRequest& etype, TDes& data) |
|
2004 { |
|
2005 TInt result = 0; |
|
2006 const TChar delimiter = ':'; |
|
2007 // initialize return value as failed |
|
2008 bool bSuccess = false; |
|
2009 |
|
2010 result = requestData.Locate( delimiter ); |
|
2011 if( KErrNotFound != result ) { |
|
2012 TInt len = requestData.Length(); |
|
2013 const TDesC& typestr = requestData.Mid( 0, result); |
|
2014 TLex atype ( typestr ); |
|
2015 TInt iType; |
|
2016 atype.Val( iType ); |
|
2017 etype = static_cast<HbThemeServerRequest>(iType); |
|
2018 data.Copy( requestData.Mid( result + 1, len - result - 1 ) ); |
|
2019 bSuccess = true; |
|
2020 } else { |
|
2021 bSuccess = false; |
|
2022 } |
|
2023 |
|
2024 return bSuccess; |
|
2025 } |
|
2026 |
|
2027 void CHbThemeChangeNotificationListener::RunL() |
|
2028 { |
|
2029 // Subscribe first to make sure we don't miss any |
|
2030 // when handling this one. |
|
2031 themeRequestProp.Subscribe(iStatus); |
|
2032 |
|
2033 SetActive(); |
|
2034 |
|
2035 TBuf<256> requestData; |
|
2036 TInt ret = themeRequestProp.Get(requestData); |
|
2037 switch (ret) { |
|
2038 case KErrNone: |
|
2039 { |
|
2040 QString qrequestData((QChar*)requestData.Ptr(),requestData.Length()); |
|
2041 HbThemeServerRequest etype = EInvalidServerRequest; |
|
2042 TBuf<256> data; |
|
2043 ///Parse the data from the Publisher |
|
2044 bool bSuccess = parseData( requestData, etype, data); |
|
2045 if( bSuccess && EThemeSelection == etype) { |
|
2046 QString str((QChar*)data.Ptr(),data.Length()); |
|
2047 str = str.trimmed(); |
|
2048 iObserver.HandleThemeSelection( str ); |
|
2049 } |
|
2050 } |
|
2051 break; |
|
2052 case KErrPermissionDenied: |
|
2053 qDebug() << "KErrPermissionDenied"; |
|
2054 break; |
|
2055 case KErrNotFound: |
|
2056 qDebug() << "KErrNotFound"; |
|
2057 break; |
|
2058 case KErrArgument: |
|
2059 qDebug() << "KErrArgument"; |
|
2060 break; |
|
2061 case KErrOverflow: |
|
2062 qDebug() << "KErrOverflow"; |
|
2063 break; |
|
2064 } |
|
2065 } |
|
2066 |
|
2067 void CHbThemeChangeNotificationListener::DoCancel() |
|
2068 { |
|
2069 themeRequestProp.Cancel(); |
|
2070 } |
|
2071 |
|
2072 |