src/hbcore/theme/hbthemeutils_p.cpp
changeset 5 627c4a0fd0e7
parent 3 11d3954df52a
child 6 c3690ec91ef8
equal deleted inserted replaced
3:11d3954df52a 5:627c4a0fd0e7
    50 
    50 
    51 const char *HbThemeUtils::iconsResourceFolder = "icons";
    51 const char *HbThemeUtils::iconsResourceFolder = "icons";
    52 const char *HbThemeUtils::effectsResourceFolder = "effects";
    52 const char *HbThemeUtils::effectsResourceFolder = "effects";
    53 const char *HbThemeUtils::styleResourceFolder = "style";
    53 const char *HbThemeUtils::styleResourceFolder = "style";
    54 const char *HbThemeUtils::themeResourceFolder = "theme";
    54 const char *HbThemeUtils::themeResourceFolder = "theme";
    55 const char *HbThemeUtils::operatorHierarchy = "operatortheme";
    55 const char *HbThemeUtils::operatorHierarchy = "prioritytheme";
    56 const char *HbThemeUtils::appHierarchy = "apptheme";
    56 const char *HbThemeUtils::appHierarchy = "apptheme";
    57 const char *HbThemeUtils::platformHierarchy = "themes";
    57 const char *HbThemeUtils::platformHierarchy = "themes";
    58 
    58 
    59 const char *operatorNameKey = "OperatorName";
    59 const char *operatorNameKey = "OperatorName";
    60 static const char *themeSettingFile = "theme.theme";
    60 static const char *themeSettingFile = "theme.theme";
   288  * @param resType type of Resource whether "style" or "icons"
   288  * @param resType type of Resource whether "style" or "icons"
   289  *
   289  *
   290  * @ret list of hierarchy of themes in priority.Also appends the default path with least priority.
   290  * @ret list of hierarchy of themes in priority.Also appends the default path with least priority.
   291  */
   291  */
   292 QMap<int, QString> HbThemeUtils::constructHierarchyListWithPathInfo(const QString &fileName,
   292 QMap<int, QString> HbThemeUtils::constructHierarchyListWithPathInfo(const QString &fileName,
   293                                                                    const QString &currentTheme,
   293                                                                     const QString &currentTheme,
   294                                                                    const Hb::ResourceType resType)
   294                                                                     const Hb::ResourceType resType)
   295 {
   295 {
   296     QMap<int,QString> hierarchyListWithPathInfo;
   296     QMap<int,QString> hierarchyListWithPathInfo;
   297 
   297 
   298     // Map the resource enum to string here
   298     // Map the resource enum to string here
   299     const QString &resourcePath = getResourceFolderName(resType);
   299     const QString &resourcePath = getResourceFolderName(resType);
   300 
   300 #ifdef Q_OS_SYMBIAN
   301     foreach (const HbHierarchy &hierarchy, d.hierarchies) {
   301     foreach (const HbHierarchy &hierarchy, d.hierarchies) {
   302         switch(hierarchy.layerPriority) {
   302         switch(hierarchy.layerPriority) {
   303         case HbLayeredStyleLoader::Priority_Operator:
   303         case HbLayeredStyleLoader::Priority_Operator: {
   304             if (!d.operatorPath.isEmpty()) {
   304                 // Operator C drive path
   305                 hierarchyListWithPathInfo.insert(HbLayeredStyleLoader::Priority_Operator,
   305                 HbThemeIndexInfo info = HbThemeUtils::getThemeIndexInfo(OperatorC);
   306                                                  d.constructOperatorPath(operatorBasePath(), fileName));
   306                 if (info.themeIndexOffset > 0) {
   307             }
   307 
   308             break;
   308                     hierarchyListWithPathInfo.insert(HbLayeredStyleLoader::Priority_Operator,
   309         case HbLayeredStyleLoader::Priority_Application:
   309                             (info.path + '/' + resourcePath + '/' + info.name + '/' + fileName));
   310             hierarchyListWithPathInfo.insert(HbLayeredStyleLoader::Priority_Application, 
   310                 }
       
   311                 // Operator ROM path
       
   312                 info = HbThemeUtils::getThemeIndexInfo(OperatorROM);
       
   313                 if (info.themeIndexOffset > 0) {
       
   314                     hierarchyListWithPathInfo.insert(HbLayeredStyleLoader::Priority_Operator,
       
   315                             (info.path + '/' + resourcePath + '/' + info.name + '/' + fileName));
       
   316                 }
       
   317                 break;
       
   318             }
       
   319         case HbLayeredStyleLoader::Priority_Theme: {
       
   320                 HbThemeIndexInfo info = HbThemeUtils::getThemeIndexInfo(ActiveTheme);
       
   321                 if (info.themeIndexOffset > 0) {
       
   322                     hierarchyListWithPathInfo.insert(HbLayeredStyleLoader::Priority_Theme,
       
   323                             (info.path + '/' + resourcePath + '/' + info.name + '/' + fileName));
       
   324                 }
       
   325                 break;
       
   326             }
       
   327         default: {
       
   328                 // this is for a new hierarchy level and for the time being HbLayeredStyleLoader::Priority_Theme prirority
       
   329                 // is used,since there is no enum defined in hblayeredstyleloader_p.h
       
   330                 // priority should be replaced with respective enum.
       
   331                 hierarchyListWithPathInfo.insert(HbLayeredStyleLoader::Priority_Theme,
       
   332                         (hierarchy.name + '/' + resourcePath + '/' + currentTheme + '/' + fileName));
       
   333             }
       
   334         }
       
   335     }
       
   336     // lets add base CSS path too in this list for now
       
   337     // This comes last in base hierarchy
       
   338     HbThemeIndexInfo info = HbThemeUtils::getThemeIndexInfo(BaseTheme);
       
   339     if (info.themeIndexOffset > 0) {
       
   340     hierarchyListWithPathInfo.insert(HbLayeredStyleLoader::Priority_Core,
       
   341             (info.path + '/' + resourcePath + '/' + info.name + '/' + fileName));
       
   342     }
       
   343     
       
   344 #else
       
   345     foreach (const HbHierarchy &hierarchy, d.hierarchies) {
       
   346         switch(hierarchy.layerPriority) {
       
   347         case HbLayeredStyleLoader::Priority_Operator: {
       
   348                 if (!d.operatorPath.isEmpty()) {
       
   349                     hierarchyListWithPathInfo.insert(HbLayeredStyleLoader::Priority_Operator,
       
   350                                                      d.constructOperatorPath(operatorBasePath(), fileName));
       
   351                 }
       
   352                 break;
       
   353             }
       
   354         case HbLayeredStyleLoader::Priority_Application: {
       
   355                 hierarchyListWithPathInfo.insert(HbLayeredStyleLoader::Priority_Application,
   311                     (hierarchy.name + '/' + HbMemoryUtils::getCleanAppName() + '/' +
   356                     (hierarchy.name + '/' + HbMemoryUtils::getCleanAppName() + '/' +
   312                      resourcePath + '/' + currentTheme + '/' + fileName));
   357                      resourcePath + '/' + currentTheme + '/' + fileName));
   313             break;
   358                 break;
   314         case HbLayeredStyleLoader::Priority_Theme:
   359             }
   315             // Add platform theme folder only if it is different from base theme
   360         case HbLayeredStyleLoader::Priority_Theme: {
   316             // Base theme is anyway added at the core priority
   361                 if (currentTheme != baseTheme().name) {
   317             if (currentTheme != baseTheme().name) {
   362                     // Add platform theme folder only if it is different from base theme
   318                 hierarchyListWithPathInfo.insert(HbLayeredStyleLoader::Priority_Theme, 
   363                     // Base theme is anyway added at the core priority
       
   364                     hierarchyListWithPathInfo.insert(HbLayeredStyleLoader::Priority_Theme,
       
   365                             (hierarchy.name + '/' + resourcePath + '/' + currentTheme + '/' + fileName));
       
   366                 }
       
   367                 break;
       
   368             }
       
   369         default: {
       
   370                 // this is for a new hierarchy level and for the time being
       
   371                 // HbLayeredStyleLoader::Priority_Theme prirority is used,
       
   372                 // since there is no enum defined in hblayeredstyleloader_p.h
       
   373                 // priority should be replaced with respective enum.
       
   374                 hierarchyListWithPathInfo.insert(HbLayeredStyleLoader::Priority_Theme,
   319                         (hierarchy.name + '/' + resourcePath + '/' + currentTheme + '/' + fileName));
   375                         (hierarchy.name + '/' + resourcePath + '/' + currentTheme + '/' + fileName));
   320             }
   376             }
   321             break;
       
   322         default:
       
   323             // this is for a new hierarchy level and for the time being
       
   324             // HbLayeredStyleLoader::Priority_Theme priority is used,
       
   325             // since there is no enum defined in hblayeredstyleloader_p.h
       
   326             // priority should be replaced with respective enum.
       
   327             hierarchyListWithPathInfo.insert(HbLayeredStyleLoader::Priority_Theme, 
       
   328                     (hierarchy.name + '/' + resourcePath + '/' + currentTheme + '/' + fileName));
       
   329         }
   377         }
   330     }
   378     }
   331     
   379     
   332     if (resType == Hb::StyleSheetResource || resType == Hb::EffectResource) {
   380     if (resType == Hb::StyleSheetResource || resType == Hb::EffectResource) {
   333         // lets add base CSS path too in this list for now
   381         // lets add base CSS path too in this list for now
   334         // This comes last in base hierarchy
   382         // This comes last in base hierarchy
   335         hierarchyListWithPathInfo.insert(HbLayeredStyleLoader::Priority_Core, 
   383         hierarchyListWithPathInfo.insert(HbLayeredStyleLoader::Priority_Core, 
   336                 (QLatin1String("themes/") + resourcePath + '/' + baseTheme().name + '/' + fileName));
   384                 (QLatin1String("themes/") + resourcePath + '/' + baseTheme().name + '/' + fileName));
   337     }
   385     }
   338 
   386 #endif // Q_OS_SYMBIAN
   339     return hierarchyListWithPathInfo;
   387     return hierarchyListWithPathInfo;
   340 }
   388 }
   341 
   389 
   342 /* returns information of base theme
   390 /* returns information of base theme
   343  */
   391  */
   359                 baseThemeInfo = getBaseThemeFromFile(CoreResourcesRootDir);
   407                 baseThemeInfo = getBaseThemeFromFile(CoreResourcesRootDir);
   360             }
   408             }
   361         } else {
   409         } else {
   362             // So settings are initialized, it will have other value as well
   410             // So settings are initialized, it will have other value as well
   363             baseThemeInfo.rootDir = getThemeSetting(DefaultThemeRootDirSetting).trimmed();
   411             baseThemeInfo.rootDir = getThemeSetting(DefaultThemeRootDirSetting).trimmed();
       
   412             // On desktop platforms try the HB_THEMES_DIR environment variable instead of
       
   413             // blindly sticking to the previous stored setting, the theme directory may have been
       
   414             // moved meanwhile and that usually results in a changed HB_THEMES_DIR but nobody will
       
   415             // update the our settings stored via QSettings.
       
   416 #ifndef Q_OS_SYMBIAN            
       
   417             QString themesDirFromEnv = HbStandardDirs::themesDir();
       
   418             if (!themesDirFromEnv.isEmpty()) {
       
   419                 baseThemeInfo.rootDir = themesDirFromEnv;
       
   420             }
       
   421 #endif
   364         }
   422         }
   365     }
   423     }
   366     
   424     
   367     return baseThemeInfo;
   425     return baseThemeInfo;
   368 }
   426 }
   506 
   564 
   507 HbThemeIndexInfo HbThemeUtils::getThemeIndexInfo(const HbThemeType &type)
   565 HbThemeIndexInfo HbThemeUtils::getThemeIndexInfo(const HbThemeType &type)
   508 {
   566 {
   509     HbThemeIndexInfo info;
   567     HbThemeIndexInfo info;
   510     GET_MEMORY_MANAGER(HbMemoryManager::SharedMemory);
   568     GET_MEMORY_MANAGER(HbMemoryManager::SharedMemory);
   511     HbSharedChunkHeader *chunkHeader = (HbSharedChunkHeader*)(manager->base());
   569     if (manager) { 
   512     
   570         HbSharedChunkHeader *chunkHeader = (HbSharedChunkHeader*)(manager->base());
   513     switch(type) {
   571         
   514     case BaseTheme:
   572         switch(type) {
   515         info.name = QString(HbMemoryUtils::getAddress<char>(HbMemoryManager::SharedMemory, 
   573         case BaseTheme:
   516                                                        chunkHeader->baseThemeNameOffset));
   574             if (chunkHeader->baseThemeIndexOffset > 0) {
   517         info.path = QString(HbMemoryUtils::getAddress<char>(HbMemoryManager::SharedMemory, 
   575                 info.name = QString(HbMemoryUtils::getAddress<char>(HbMemoryManager::SharedMemory, 
   518                                                         chunkHeader->baseThemePathOffset));
   576                                                                chunkHeader->baseThemeNameOffset));
   519         info.themeIndexOffset = chunkHeader->baseThemeIndexOffset;
   577                 info.path = QString(HbMemoryUtils::getAddress<char>(HbMemoryManager::SharedMemory, 
   520         break;
   578                                                                 chunkHeader->baseThemePathOffset));
   521     case OperatorC:
   579                 info.themeIndexOffset = chunkHeader->baseThemeIndexOffset;
   522         info.name = QString(HbMemoryUtils::getAddress<char>(HbMemoryManager::SharedMemory, 
   580             }
   523                                                        chunkHeader->operatorThemeDriveCNameOffset));
   581             break;
   524         info.path = QString(HbMemoryUtils::getAddress<char>(HbMemoryManager::SharedMemory, 
   582         case OperatorC:
   525                                                         chunkHeader->operatorThemeDriveCPathOffset));
   583             if (chunkHeader->operatorThemeDriveCIndexOffset > 0) {
   526         info.themeIndexOffset = chunkHeader->operatorThemeDriveCIndexOffset;
   584                 info.name = QString(HbMemoryUtils::getAddress<char>(HbMemoryManager::SharedMemory, 
   527         break;
   585                                                                chunkHeader->operatorThemeDriveCNameOffset));
   528     case OperatorROM:
   586                 info.path = QString(HbMemoryUtils::getAddress<char>(HbMemoryManager::SharedMemory, 
   529         info.name = QString(HbMemoryUtils::getAddress<char>(HbMemoryManager::SharedMemory, 
   587                                                                 chunkHeader->operatorThemeDriveCPathOffset));
   530                                                        chunkHeader->operatorThemeRomPathOffset));
   588                 info.themeIndexOffset = chunkHeader->operatorThemeDriveCIndexOffset;
   531         info.path = QString(HbMemoryUtils::getAddress<char>(HbMemoryManager::SharedMemory, 
   589             }
   532                                                         chunkHeader->operatorThemeRomPathOffset));
   590             break;
   533         info.themeIndexOffset = chunkHeader->operatorThemeRomIndexOffset;
   591         case OperatorROM:
   534         break;
   592             if (chunkHeader->operatorThemeRomIndexOffset > 0) {
   535     case ActiveTheme:
   593                 info.name = QString(HbMemoryUtils::getAddress<char>(HbMemoryManager::SharedMemory, 
   536         info.name = QString(HbMemoryUtils::getAddress<char>(HbMemoryManager::SharedMemory, 
   594                                                                chunkHeader->operatorThemeRomNameOffset));
   537                                                        chunkHeader->activeThemeNameOffset));
   595                 info.path = QString(HbMemoryUtils::getAddress<char>(HbMemoryManager::SharedMemory, 
   538         info.path = QString(HbMemoryUtils::getAddress<char>(HbMemoryManager::SharedMemory, 
   596                                                                 chunkHeader->operatorThemeRomPathOffset));
   539                                                         chunkHeader->activeThemePathOffset));
   597                 info.themeIndexOffset = chunkHeader->operatorThemeRomIndexOffset;
   540         info.themeIndexOffset = chunkHeader->activeThemeIndexOffset;
   598             }
   541         break;
   599             break;
   542     default:
   600         case ActiveTheme:
   543         break;
   601             if (chunkHeader->activeThemeIndexOffset > 0) {
   544     }
   602                 info.name = QString(HbMemoryUtils::getAddress<char>(HbMemoryManager::SharedMemory, 
   545     
   603                                                                chunkHeader->activeThemeNameOffset));
       
   604                 info.path = QString(HbMemoryUtils::getAddress<char>(HbMemoryManager::SharedMemory, 
       
   605                                                                 chunkHeader->activeThemePathOffset));
       
   606                 info.themeIndexOffset = chunkHeader->activeThemeIndexOffset;
       
   607             }
       
   608             break;
       
   609         default:
       
   610             break;
       
   611         }
       
   612     }
   546     return info;
   613     return info;
   547 }
   614 }
       
   615 
       
   616 bool HbThemeUtils::isLogicalName(const QString &fileName)
       
   617 {
       
   618     return !(fileName.contains(QChar('/'), Qt::CaseSensitive) || fileName.contains(QChar('\\'), Qt::CaseSensitive));
       
   619 }