123 } |
123 } |
124 } else if (inSharedCache) { |
124 } else if (inSharedCache) { |
125 *inSharedCache = false; |
125 *inSharedCache = false; |
126 } |
126 } |
127 |
127 |
128 #ifdef THEME_SERVER_TRACES |
|
129 qDebug() << "In " << Q_FUNC_INFO; |
|
130 #endif // THEME_SERVER_TRACES |
|
131 if (cssOffset < 0) { |
128 if (cssOffset < 0) { |
|
129 THEME_GENERIC_DEBUG() << Q_FUNC_INFO << "Stylesheet: " << fileName << " not found in shared cache."; |
132 HbCss::Parser parser; |
130 HbCss::Parser parser; |
133 if (!parseCssFile(parser, fileName, cssOffset, fileExists)) { |
131 if (!parseCssFile(parser, fileName, cssOffset, fileExists)) { |
134 if (parser.errorCode == HbCss::Parser::OutOfMemoryError) { |
132 if (parser.errorCode == HbCss::Parser::OutOfMemoryError) { |
135 return OUT_OF_MEMORY_ERROR; |
133 return OUT_OF_MEMORY_ERROR; |
136 } |
134 } |
262 HbWidgetLoader loader; |
260 HbWidgetLoader loader; |
263 |
261 |
264 QFile file(fileName); |
262 QFile file(fileName); |
265 fileExists = file.open(QFile::ReadOnly | QFile::Text); |
263 fileExists = file.open(QFile::ReadOnly | QFile::Text); |
266 if (!fileExists) { |
264 if (!fileExists) { |
267 #ifdef THEME_SERVER_TRACES |
265 THEME_GENERIC_DEBUG() << Q_FUNC_INFO << "Unable to open the file: " << fileName; |
268 qWarning("Unable to open file"); |
|
269 #endif |
|
270 return -1; |
266 return -1; |
271 } |
267 } |
272 #ifdef THEME_SERVER_TRACES |
268 THEME_GENERIC_DEBUG() << Q_FUNC_INFO << "Trying to load: " << fileName << "::" << layout << "::" << section; |
273 qDebug() << "Trying to load: " << fileName << "::" << layout << "::" << section; |
|
274 #endif // THEME_SERVER_TRACES |
|
275 |
269 |
276 HbWidgetLoader::LayoutDefinition *layoutDef(0); |
270 HbWidgetLoader::LayoutDefinition *layoutDef(0); |
277 GET_MEMORY_MANAGER(HbMemoryManager::SharedMemory); |
271 GET_MEMORY_MANAGER(HbMemoryManager::SharedMemory); |
278 try { |
272 try { |
279 layoutDefOffset = manager->alloc(sizeof(HbWidgetLoader::LayoutDefinition)); |
273 layoutDefOffset = manager->alloc(sizeof(HbWidgetLoader::LayoutDefinition)); |
352 * \return offset of the parsed effect data in the shared memory, -1 if error |
346 * \return offset of the parsed effect data in the shared memory, -1 if error |
353 * |
347 * |
354 */ |
348 */ |
355 int HbThemeServerUtils::getSharedEffect(const QString &fileName) |
349 int HbThemeServerUtils::getSharedEffect(const QString &fileName) |
356 { |
350 { |
357 #ifdef THEME_SERVER_TRACES |
351 THEME_GENERIC_DEBUG() << Q_FUNC_INFO << "called with fileName: " << fileName; |
358 qDebug() << "In " << Q_FUNC_INFO << fileName; |
|
359 #endif // THEME_SERVER_TRACES |
|
360 |
352 |
361 qptrdiff effOffset = -1; |
353 qptrdiff effOffset = -1; |
362 if (effCache()->contains(fileName)) { |
354 if (effCache()->contains(fileName)) { |
363 effOffset = effCache()->value(fileName); |
355 effOffset = effCache()->value(fileName); |
364 |
356 THEME_GENERIC_DEBUG() << "in cache: " << fileName << "offset=" << effOffset; |
365 #ifdef THEME_SERVER_TRACES |
|
366 qDebug() << "Got effect in cache: " << fileName << "offset=" << effOffset; |
|
367 #endif //THEME_SERVER_TRACES |
|
368 |
|
369 } else { |
357 } else { |
370 |
358 THEME_GENERIC_DEBUG() << "Not in cache, parsing: " << fileName; |
371 #ifdef THEME_SERVER_TRACES |
359 |
372 qDebug() << "Not in cache, parsing: " << fileName; |
|
373 #endif //THEME_SERVER_TRACES |
|
374 |
|
375 // 1. Create an effect in shared memory |
360 // 1. Create an effect in shared memory |
376 GET_MEMORY_MANAGER(HbMemoryManager::SharedMemory); |
361 GET_MEMORY_MANAGER(HbMemoryManager::SharedMemory); |
377 HbEffectFxmlData *data = 0; |
362 HbEffectFxmlData *data = 0; |
378 try { |
363 try { |
379 effOffset = manager->alloc(sizeof(HbEffectFxmlData)); |
364 effOffset = manager->alloc(sizeof(HbEffectFxmlData)); |
403 } catch (std::exception &) { |
389 } catch (std::exception &) { |
404 f.close(); |
390 f.close(); |
405 fail = true; |
391 fail = true; |
406 } |
392 } |
407 } else { |
393 } else { |
408 #ifdef THEME_SERVER_TRACES |
394 THEME_GENERIC_DEBUG() << "Cannot open:" << fileName; |
409 qWarning() << "Cannot open" << fileName; |
|
410 #endif // THEME_SERVER_TRACES |
|
411 fail = true; |
395 fail = true; |
412 } |
396 } |
413 if (fail) { |
397 if (fail) { |
414 data->~HbEffectFxmlData(); |
398 data->~HbEffectFxmlData(); |
415 manager->free(effOffset); |
399 manager->free(effOffset); |
|
400 THEME_GENERIC_DEBUG() << "Failed to parese effect."; |
416 return -1; |
401 return -1; |
417 } |
402 } |
418 |
403 |
419 // add the filename and css offset to the secondary cache. |
404 // add the filename and css offset to the secondary cache. |
420 // no need to check if this item is already present in the |
405 // no need to check if this item is already present in the |
421 // cache as the parsing of the file happens only once |
406 // cache as the parsing of the file happens only once |
422 // in the server side. |
407 // in the server side. |
423 HbSharedCache::instance()->add(HbSharedCache::Effect, fileName, effOffset); |
408 HbSharedCache::instance()->add(HbSharedCache::Effect, fileName, effOffset); |
424 } |
409 } |
425 |
410 |
426 #ifdef THEME_SERVER_TRACES |
411 THEME_GENERIC_DEBUG() << "returning offset: " << effOffset; |
427 qDebug() << "returning offset: " << effOffset; |
|
428 #endif // THEME_SERVER_TRACES |
|
429 |
|
430 return effOffset; |
412 return effOffset; |
431 } |
413 } |
432 |
414 |
433 void HbThemeServerUtils::createThemeIndex(const QString &themePath, const HbThemeType &themetype) |
415 void HbThemeServerUtils::createThemeIndex(const QString &themePath, const HbThemeType &themetype) |
434 { |
416 { |
435 #ifdef THEME_INDEX_TRACES |
417 THEME_INDEX_DEBUG() << "ThemeIndex: createThemeIndex" << themePath.toUtf8(); |
436 qDebug() << "ThemeIndex: createThemeIndex" << themePath.toUtf8(); |
|
437 #endif |
|
438 QDir themeBasePath(themePath); |
418 QDir themeBasePath(themePath); |
439 // Path is like "C:/resource/hb/themes/icons/sfwhitetheme" |
419 // Path is like "C:/resource/hb/themes/icons/sfwhitetheme" |
440 QString themeName = themeBasePath.dirName(); |
420 QString themeName = themeBasePath.dirName(); |
441 |
421 |
442 QString filename(themeBasePath.absolutePath()); |
422 QString filename(themeBasePath.absolutePath()); |
443 int cutindex = filename.lastIndexOf("/",filename.lastIndexOf("/")-1)+1; |
423 int cutindex = filename.lastIndexOf('/',filename.lastIndexOf('/')-1)+1; |
444 filename = filename.left(cutindex); |
424 filename = filename.left(cutindex); |
445 themeBasePath.setPath(filename); |
425 themeBasePath.setPath(filename); |
446 filename.append(themeName); |
426 filename.append(themeName); |
447 filename.append(".themeindex"); |
427 filename.append(".themeindex"); |
448 |
428 |
455 QFile indexFile(filename); |
435 QFile indexFile(filename); |
456 |
436 |
457 bool indexOK = false; |
437 bool indexOK = false; |
458 |
438 |
459 if (indexFile.open(QIODevice::ReadOnly)) { |
439 if (indexFile.open(QIODevice::ReadOnly)) { |
460 |
|
461 indexOK = true; |
440 indexOK = true; |
462 |
|
463 GET_MEMORY_MANAGER(HbMemoryManager::SharedMemory); |
441 GET_MEMORY_MANAGER(HbMemoryManager::SharedMemory); |
464 |
442 |
465 HbSharedChunkHeader *chunkHeader = (HbSharedChunkHeader*) manager->base(); |
443 HbSharedChunkHeader *chunkHeader = (HbSharedChunkHeader*) manager->base(); |
466 |
|
467 qint64 byteSize = indexFile.size(); |
444 qint64 byteSize = indexFile.size(); |
468 |
445 THEME_INDEX_DEBUG() << "ThemeIndex: " << themeName.toUtf8() << " index file size:" << byteSize; |
469 #ifdef THEME_INDEX_TRACES |
|
470 qDebug() << "ThemeIndex: " << themeName.toUtf8() << " index file size:" << byteSize; |
|
471 #endif |
|
472 |
446 |
473 int offset = manager->alloc(byteSize); |
447 int offset = manager->alloc(byteSize); |
474 if (offset >= 0) { |
448 if (offset >= 0) { |
475 #ifdef THEME_INDEX_TRACES |
449 THEME_INDEX_DEBUG() << "ThemeIndex: memory allocated for theme: " << themeName.toUtf8(); |
476 qDebug() << "ThemeIndex: memory allocated for theme: " << themeName.toUtf8(); |
|
477 #endif |
|
478 |
450 |
479 // Read the theme index in the shared chunk |
451 // Read the theme index in the shared chunk |
480 char *address = HbMemoryUtils::getAddress<char>(HbMemoryManager::SharedMemory, offset); |
452 char *address = HbMemoryUtils::getAddress<char>(HbMemoryManager::SharedMemory, offset); |
481 |
453 |
482 indexFile.read(address, byteSize); |
454 indexFile.read(address, byteSize); |
483 indexFile.close(); |
455 indexFile.close(); |
484 |
456 THEME_INDEX_DEBUG() << "ThemeIndex: Reading themeindex for theme" << themeName.toUtf8() << "... Done!"; |
485 #ifdef THEME_INDEX_TRACES |
|
486 qDebug() << "ThemeIndex: Reading themeindex for theme" << themeName.toUtf8() << "... Done!"; |
|
487 #endif |
|
488 |
457 |
489 // Verify theme index contents if it is not located in ROM, |
458 // Verify theme index contents if it is not located in ROM, |
490 // so that it does not have over-indexing offsets which might |
459 // so that it does not have over-indexing offsets which might |
491 // crash all the clients trying to read from it. |
460 // crash all the clients trying to read from it. |
492 |
461 |
493 if (themePath[0] != 'z' && themePath[0] != 'Z') { |
462 if (themePath[0] != 'z' && themePath[0] != 'Z') { |
494 #ifdef THEME_INDEX_TRACES |
463 THEME_INDEX_DEBUG() << "ThemeIndex: Validating themeindex for theme" << themeName.toUtf8(); |
495 qDebug() << "ThemeIndex: Validating themeindex for theme" << themeName.toUtf8(); |
|
496 #endif |
|
497 |
|
498 HbThemeIndex index(address); |
464 HbThemeIndex index(address); |
499 indexOK = index.validateItems(byteSize); |
465 indexOK = index.validateItems(byteSize); |
500 |
466 THEME_INDEX_DEBUG() << "ThemeIndex: Validating themeindex for theme" << themeName.toUtf8() << " done! Result: " << indexOK; |
501 #ifdef THEME_INDEX_TRACES |
|
502 qDebug() << "ThemeIndex: Validating themeindex for theme" << themeName.toUtf8() << " done! Result: " << indexOK; |
|
503 #endif |
|
504 } |
467 } |
505 |
468 |
506 if (indexOK) { |
469 if (indexOK) { |
507 // Allocate theme path string from shared memory |
470 // Allocate theme path string from shared memory |
508 QByteArray themePathArray = themeBasePath.absolutePath().toLatin1(); |
471 QByteArray themePathArray = themeBasePath.absolutePath().toLatin1(); |