src/hbcore/core/hbthemeindex.cpp
changeset 28 b7da29130b0e
parent 21 4633027730f5
equal deleted inserted replaced
23:e6ad4ef83b23 28:b7da29130b0e
    22 ** Nokia at developer.feedback@nokia.com.
    22 ** Nokia at developer.feedback@nokia.com.
    23 **
    23 **
    24 ****************************************************************************/
    24 ****************************************************************************/
    25 
    25 
    26 #include "hbthemeindex_p.h"
    26 #include "hbthemeindex_p.h"
       
    27 #include "hbhash_p.h"
    27 #include <QDebug>
    28 #include <QDebug>
    28 #ifndef HB_BOOTSTRAPPED
    29 #ifndef HB_BOOTSTRAPPED
    29 #include "hbthemeclient_p.h"
    30 #include "hbthemeclient_p.h"
    30 #include "hbinstance.h"
    31 #include "hbinstance.h"
    31 #endif // HB_BOOTSTRAPPED
    32 #endif // HB_BOOTSTRAPPED
    32 
    33 
    33 
    34 
    34 HbThemeIndexResource::HbThemeIndexResource(const QString &resourceName) :
    35 HbThemeIndexResource::HbThemeIndexResource(const QString &resourceName) :
    35     resourceName(resourceName),
    36     resourceName(&resourceName),
       
    37     hashValue(0),
    36     data(0)
    38     data(0)
    37 {
    39 {
    38 #ifndef HB_BOOTSTRAPPED
    40 #ifndef HB_BOOTSTRAPPED
    39     getResourceData();
    41     getResourceData();
    40 #endif // HB_BOOTSTRAPPED
    42 #endif // HB_BOOTSTRAPPED
    41 }
    43 }
    42 
    44 
       
    45 HbThemeIndexResource::HbThemeIndexResource(quint32 hashValue) :
       
    46     resourceName(0),
       
    47     hashValue(hashValue),
       
    48     data(0)
       
    49 {
       
    50 #ifndef HB_BOOTSTRAPPED
       
    51     getResourceData();
       
    52 #endif // HB_BOOTSTRAPPED
       
    53 }
       
    54 
    43 void HbThemeIndexResource::getResourceData()
    55 void HbThemeIndexResource::getResourceData()
    44 {
    56 {
    45 #ifndef HB_BOOTSTRAPPED
    57 #ifndef HB_BOOTSTRAPPED
    46 #ifdef THEME_INDEX_TRACES
    58 #ifdef THEME_INDEX_TRACES
    47     qDebug() << "HbThemeIndexResource::getResourceData(), resourceName: " << resourceName;
    59     if ( resourceName ) {
       
    60         qDebug() << "HbThemeIndexResource::getResourceData(), resourceName: " << *resourceName;
       
    61     } else {
       
    62         qDebug() << "HbThemeIndexResource::getResourceData(), hashValue: " << hashValue;
       
    63     }
    48 #endif
    64 #endif
    49     // Theme index tables are always valid in shared memory
    65     // Theme index tables are always valid in shared memory
    50 
    66 
    51     // Try to find themable item with following logic:
    67     // Try to find themable item with following logic:
    52     // If item is locked in base theme
    68     // If item is locked in base theme
    63     type = BaseTheme; // This is the default, even we couldn't find themable resource
    79     type = BaseTheme; // This is the default, even we couldn't find themable resource
    64 
    80 
    65     // First check base theme, which should be always valid
    81     // First check base theme, which should be always valid
    66     HbThemeIndexInfo info = HbThemeUtils::getThemeIndexInfo(BaseTheme);
    82     HbThemeIndexInfo info = HbThemeUtils::getThemeIndexInfo(BaseTheme);
    67     if (!info.address) { // This shouldn't happen, as there must be valid base theme
    83     if (!info.address) { // This shouldn't happen, as there must be valid base theme
    68 #ifdef THEME_INDEX_TRACES
    84         THEME_INDEX_DEBUG() << "HbThemeUtils::getThemeIndexInfo(BaseTheme) returned null address";
    69         qDebug("HbThemeUtils::getThemeIndexInfo(BaseTheme) returned null address");
       
    70 #endif
       
    71         return; // Data will be 0
    85         return; // Data will be 0
    72     }
    86     }
    73     
    87     
    74     HbThemeIndex baseIndex(info.address);
    88     HbThemeIndex baseIndex(info.address);
    75     const HbThemeIndexItemData *baseItemData = baseIndex.getItemData(resourceName);
    89     const HbThemeIndexItemData *baseItemData = resourceName
       
    90         ? baseIndex.getItemData(*resourceName)
       
    91         : baseIndex.getItemData(hashValue);
    76 
    92 
    77     if (!baseItemData) { // If the item is not found from base theme, it can't be found elsewhere
    93     if (!baseItemData) { // If the item is not found from base theme, it can't be found elsewhere
    78 #ifdef THEME_INDEX_TRACES
    94 #ifdef THEME_INDEX_TRACES
    79         qDebug("HbThemeIndex::getItemData(%s) returned null data", qPrintable(resourceName));
    95         if ( resourceName ) {
       
    96             qDebug("HbThemeIndex::getItemData(%s) returned null data", qPrintable(*resourceName));
       
    97         } else {
       
    98             qDebug("HbThemeIndex::getItemData(%u) returned null data", hashValue);
       
    99         }
    80 #endif
   100 #endif
    81         return; // Data will be 0
   101         return; // Data will be 0
    82     }
   102     }
    83 
   103 
    84     if (baseItemData->flags & HbThemeIndexItemData::Locked) {
   104     if (baseItemData->flags & HbThemeIndexItemData::Locked) {
    90 
   110 
    91     // Base wasn't locked, next check operator theme in C-drive
   111     // Base wasn't locked, next check operator theme in C-drive
    92     info = HbThemeUtils::getThemeIndexInfo(OperatorC);
   112     info = HbThemeUtils::getThemeIndexInfo(OperatorC);
    93     if (info.address) {
   113     if (info.address) {
    94         HbThemeIndex operatorCIndex(info.address);
   114         HbThemeIndex operatorCIndex(info.address);
    95         const HbThemeIndexItemData *operatorCItemData = operatorCIndex.getItemData(resourceName);
   115         const HbThemeIndexItemData *operatorCItemData = resourceName
       
   116             ? operatorCIndex.getItemData(*resourceName)
       
   117             : operatorCIndex.getItemData(hashValue);
    96 
   118 
    97         if (operatorCItemData) { // Found, use it
   119         if (operatorCItemData) { // Found, use it
    98             type = OperatorC;
   120             type = OperatorC;
    99             basePath = info.path;
   121             basePath = info.path;
   100             themeName = info.name;
   122             themeName = info.name;
   105 
   127 
   106     // Not found from operator theme in C-drive, next check operator theme in ROM
   128     // Not found from operator theme in C-drive, next check operator theme in ROM
   107     info = HbThemeUtils::getThemeIndexInfo(OperatorROM);
   129     info = HbThemeUtils::getThemeIndexInfo(OperatorROM);
   108     if (info.address) {
   130     if (info.address) {
   109         HbThemeIndex operatorZIndex(info.address);
   131         HbThemeIndex operatorZIndex(info.address);
   110         const HbThemeIndexItemData *operatorZItemData = operatorZIndex.getItemData(resourceName);
   132         const HbThemeIndexItemData *operatorZItemData = resourceName
       
   133             ? operatorZIndex.getItemData(*resourceName)
       
   134             : operatorZIndex.getItemData(hashValue);
   111 
   135 
   112         if (operatorZItemData) { // Found, use it
   136         if (operatorZItemData) { // Found, use it
   113             type = OperatorROM;
   137             type = OperatorROM;
   114             basePath = info.path;
   138             basePath = info.path;
   115             themeName = info.name;
   139             themeName = info.name;
   120 
   144 
   121     // Not found from operator themes, try active theme
   145     // Not found from operator themes, try active theme
   122     info = HbThemeUtils::getThemeIndexInfo(ActiveTheme);
   146     info = HbThemeUtils::getThemeIndexInfo(ActiveTheme);
   123     if (info.address) {
   147     if (info.address) {
   124         HbThemeIndex activeThemeIndex(info.address);
   148         HbThemeIndex activeThemeIndex(info.address);
   125         const HbThemeIndexItemData *activeThemeItemData =
   149         const HbThemeIndexItemData *activeThemeItemData = resourceName
   126                 activeThemeIndex.getItemData(resourceName);
   150             ? activeThemeIndex.getItemData(*resourceName)
       
   151             : activeThemeIndex.getItemData(hashValue);
   127 
   152 
   128         if (activeThemeItemData) { // Found, use it
   153         if (activeThemeItemData) { // Found, use it
   129             type = ActiveTheme;
   154             type = ActiveTheme;
   130             basePath = info.path;
   155             basePath = info.path;
   131             themeName = info.name;
   156             themeName = info.name;
   194     return false;
   219     return false;
   195 }
   220 }
   196 
   221 
   197 QString HbThemeIndexResource::fullFileName()
   222 QString HbThemeIndexResource::fullFileName()
   198 {
   223 {
   199     if (!data) {
   224     if (!data || !resourceName) {
   200         return QString();
   225         return QString();
   201     }
   226     }
   202 
   227 
   203     QString fullName = basePath;
   228     QString fullName = basePath;
   204     switch (data->itemType) {
   229     switch (data->itemType) {
   205         case HbThemeIndexItemData::SvgItem:
   230         case HbThemeIndexItemData::SvgItem:
   206             {
   231             {
   207             fullName = fullName + "/icons/" + themeName + "/scalable/" + resourceName + ".svg";
   232             fullName = fullName + "/icons/" + themeName + "/scalable/" + *resourceName + ".svg";
   208             break;
   233             break;
   209             }
   234             }
   210         case HbThemeIndexItemData::PngItem:
   235         case HbThemeIndexItemData::PngItem:
   211             {
   236             {
   212             fullName = fullName + "/icons/" + themeName + "/pixmap/" + resourceName + ".png";
   237             fullName = fullName + "/icons/" + themeName + "/pixmap/" + *resourceName + ".png";
   213             break;
   238             break;
   214             }
   239             }
   215         case HbThemeIndexItemData::MngItem:
   240         case HbThemeIndexItemData::MngItem:
   216             {
   241             {
   217             fullName = fullName + "/icons/" + themeName + "/pixmap/" + resourceName + ".mng";
   242             fullName = fullName + "/icons/" + themeName + "/pixmap/" + *resourceName + ".mng";
   218             break;
   243             break;
   219             }
   244             }
   220         case HbThemeIndexItemData::GifItem:
   245         case HbThemeIndexItemData::GifItem:
   221             {
   246             {
   222             fullName = fullName + "/icons/" + themeName + "/pixmap/" + resourceName + ".gif";
   247             fullName = fullName + "/icons/" + themeName + "/pixmap/" + *resourceName + ".gif";
   223             break;
   248             break;
   224             }
   249             }
   225         case HbThemeIndexItemData::XpmItem:
   250         case HbThemeIndexItemData::XpmItem:
   226             {
   251             {
   227             fullName = fullName + "/icons/" + themeName + "/pixmap/" + resourceName + ".xpm";
   252             fullName = fullName + "/icons/" + themeName + "/pixmap/" + *resourceName + ".xpm";
   228             break;
   253             break;
   229             }
   254             }
   230         case HbThemeIndexItemData::JpgItem:
   255         case HbThemeIndexItemData::JpgItem:
   231             {
   256             {
   232             fullName = fullName + "/icons/" + themeName + "/pixmap/" + resourceName + ".jpg";
   257             fullName = fullName + "/icons/" + themeName + "/pixmap/" + *resourceName + ".jpg";
   233             break;
   258             break;
   234             }
   259             }
   235         case HbThemeIndexItemData::NvgItem:
   260         case HbThemeIndexItemData::NvgItem:
   236             {
   261             {
   237             fullName = fullName + "/icons/" + themeName + "/scalable/" + resourceName + ".nvg";
   262             fullName = fullName + "/icons/" + themeName + "/scalable/" + *resourceName + ".nvg";
   238             break;
   263             break;
   239             }
   264             }
   240         case HbThemeIndexItemData::SvgzItem:
   265         case HbThemeIndexItemData::SvgzItem:
   241             {
   266             {
   242             fullName = fullName + "/icons/" + themeName + "/scalable/" + resourceName + ".svgz";
   267             fullName = fullName + "/icons/" + themeName + "/scalable/" + *resourceName + ".svgz";
   243             break;
   268             break;
   244             }
   269             }
   245         case HbThemeIndexItemData::QpicItem:
   270         case HbThemeIndexItemData::QpicItem:
   246             {
   271             {
   247             fullName = fullName + "/icons/" + themeName + "/pixmap/" + resourceName + ".qpic";
   272             fullName = fullName + "/icons/" + themeName + "/pixmap/" + *resourceName + ".qpic";
   248             break;
   273             break;
   249             }
   274             }
   250         case HbThemeIndexItemData::AxmlItem:
   275         case HbThemeIndexItemData::AxmlItem:
   251             {
   276             {
   252             fullName = fullName + "/animations/" + themeName + '/' + resourceName;
   277             fullName = fullName + "/animations/" + themeName + '/' + *resourceName;
   253             break;
   278             break;
   254             }
   279             }
   255         case HbThemeIndexItemData::FxmlItem:
   280         case HbThemeIndexItemData::FxmlItem:
   256             {
   281             {
   257             fullName = fullName + "/effects/" + themeName + '/' + resourceName;
   282             fullName = fullName + "/effects/" + themeName + '/' + *resourceName;
   258             break;
   283             break;
   259             }
   284             }
   260         default:
   285         default:
   261             {
   286             {
   262             break;
   287             break;
   266     return fullName;
   291     return fullName;
   267 }
   292 }
   268 
   293 
   269 QString HbThemeIndexResource::fullMirroredFileName()
   294 QString HbThemeIndexResource::fullMirroredFileName()
   270 {
   295 {
   271     if (!data) {
   296     if (!data || !resourceName) {
   272         return QString();
   297         return QString();
   273     }
   298     }
   274 
   299 
   275     QString fullName = basePath;
   300     QString fullName = basePath;
   276     switch (data->mirroredItemType) {
   301     switch (data->mirroredItemType) {
   277         case HbThemeIndexItemData::SvgItem:
   302         case HbThemeIndexItemData::SvgItem:
   278             {
   303             {
   279             fullName = fullName + "/icons/" + themeName + "/scalable/mirrored/"
   304             fullName = fullName + "/icons/" + themeName + "/scalable/mirrored/"
   280                        + resourceName + ".svg";
   305                        + *resourceName + ".svg";
   281             break;
   306             break;
   282             }
   307             }
   283         case HbThemeIndexItemData::PngItem:
   308         case HbThemeIndexItemData::PngItem:
   284             {
   309             {
   285             fullName = fullName + "/icons/" + themeName + "/pixmap/mirrored/"
   310             fullName = fullName + "/icons/" + themeName + "/pixmap/mirrored/"
   286                        + resourceName + ".png";
   311                        + *resourceName + ".png";
   287             break;
   312             break;
   288             }
   313             }
   289         case HbThemeIndexItemData::MngItem:
   314         case HbThemeIndexItemData::MngItem:
   290             {
   315             {
   291             fullName = fullName + "/icons/" + themeName + "/pixmap/mirrored/"
   316             fullName = fullName + "/icons/" + themeName + "/pixmap/mirrored/"
   292                        + resourceName + ".mng";
   317                        + *resourceName + ".mng";
   293             break;
   318             break;
   294             }
   319             }
   295         case HbThemeIndexItemData::GifItem:
   320         case HbThemeIndexItemData::GifItem:
   296             {
   321             {
   297             fullName = fullName + "/icons/" + themeName + "/pixmap/mirrored/"
   322             fullName = fullName + "/icons/" + themeName + "/pixmap/mirrored/"
   298                        + resourceName + ".gif";
   323                        + *resourceName + ".gif";
   299             break;
   324             break;
   300             }
   325             }
   301         case HbThemeIndexItemData::XpmItem:
   326         case HbThemeIndexItemData::XpmItem:
   302             {
   327             {
   303             fullName = fullName + "/icons/" + themeName + "/pixmap/mirrored/"
   328             fullName = fullName + "/icons/" + themeName + "/pixmap/mirrored/"
   304                        + resourceName + ".xpm";
   329                        + *resourceName + ".xpm";
   305             break;
   330             break;
   306             }
   331             }
   307         case HbThemeIndexItemData::JpgItem:
   332         case HbThemeIndexItemData::JpgItem:
   308             {
   333             {
   309             fullName = fullName + "/icons/" + themeName + "/pixmap/mirrored/"
   334             fullName = fullName + "/icons/" + themeName + "/pixmap/mirrored/"
   310                        + resourceName + ".jpg";
   335                        + *resourceName + ".jpg";
   311             break;
   336             break;
   312             }
   337             }
   313         case HbThemeIndexItemData::NvgItem:
   338         case HbThemeIndexItemData::NvgItem:
   314             {
   339             {
   315             fullName = fullName + "/icons/" + themeName + "/scalable/mirrored/"
   340             fullName = fullName + "/icons/" + themeName + "/scalable/mirrored/"
   316                        + resourceName + ".nvg";
   341                        + *resourceName + ".nvg";
   317             break;
   342             break;
   318             }
   343             }
   319         case HbThemeIndexItemData::SvgzItem:
   344         case HbThemeIndexItemData::SvgzItem:
   320             {
   345             {
   321             fullName = fullName + "/icons/" + themeName + "/scalable/mirrored/"
   346             fullName = fullName + "/icons/" + themeName + "/scalable/mirrored/"
   322                        + resourceName + ".svgz";
   347                        + *resourceName + ".svgz";
   323             break;
   348             break;
   324             }
   349             }
   325         case HbThemeIndexItemData::QpicItem:
   350         case HbThemeIndexItemData::QpicItem:
   326             {
   351             {
   327             fullName = fullName + "/icons/" + themeName + "/pixmap/mirrored/"
   352             fullName = fullName + "/icons/" + themeName + "/pixmap/mirrored/"
   328                        + resourceName + ".qpic";
   353                        + *resourceName + ".qpic";
   329             break;
   354             break;
   330             }
   355             }
   331         default:
   356         default:
   332             {
   357             {
   333             return fullFileName(); // There was no mirrored icon, return normal icon
   358             return fullFileName(); // There was no mirrored icon, return normal icon
   338 }
   363 }
   339 
   364 
   340 QColor HbThemeIndexResource::colorValue()
   365 QColor HbThemeIndexResource::colorValue()
   341 {
   366 {
   342     if (!data || data->itemType != HbThemeIndexItemData::ColorItem) {
   367     if (!data || data->itemType != HbThemeIndexItemData::ColorItem) {
   343         qWarning("HbThemeIndexResource::colorValue(): cannot fetch color for 0x%p::%i",
   368         THEME_INDEX_DEBUG("HbThemeIndexResource::colorValue(): cannot fetch color for 0x%p::%i",
   344                  data, data ? data->itemType : (uint) -1);
   369                  data, data ? data->itemType : (uint) -1);
   345         return QColor();
   370         return QColor();
   346     }
   371     }
   347 #ifdef THEME_INDEX_TRACES
   372     THEME_INDEX_DEBUG() << "HbThemeIndexResource::colorValue(): constructing QColor with value:" << data->colorValue;
   348     qDebug("HbThemeIndexResource::colorValue(): constructing QColor(%x)", data->colorValue);
       
   349 #endif // THEME_INDEX_TRACES
       
   350     return QColor(data->colorValue);
   373     return QColor(data->colorValue);
   351 }
   374 }
   352 
   375 
   353 
   376 
   354 // Class HbThemeIndex has the logic of handling different versions of
   377 // Class HbThemeIndex has the logic of handling different versions of
   377                             (mBaseAddress + sizeof(HbThemeIndexHeaderV1));
   400                             (mBaseAddress + sizeof(HbThemeIndexHeaderV1));
   378 
   401 
   379     initialized = true;
   402     initialized = true;
   380 }
   403 }
   381 
   404 
   382 quint32 HbThemeIndex::hash(const QString &string)
       
   383 {
       
   384     quint32 hashValue = 0;
       
   385     quint32 c;
       
   386     QByteArray array = string.toLatin1();
       
   387     char *data = array.data();
       
   388     c = *data++;
       
   389 
       
   390     while (c) {
       
   391         hashValue = c + (hashValue << 6) + (hashValue << 16) - hashValue;
       
   392         c = *data++;
       
   393     }
       
   394 
       
   395     return hashValue;
       
   396 }
       
   397 
       
   398 const HbThemeIndexItemData *HbThemeIndex::getItemData(const QString &itemName)
   405 const HbThemeIndexItemData *HbThemeIndex::getItemData(const QString &itemName)
       
   406 {
       
   407     return getItemData(hbHash(itemName));
       
   408 }
       
   409 
       
   410 const HbThemeIndexItemData *HbThemeIndex::getItemData(quint32 hashValue)
   399 {
   411 {
   400     if (!initialized) {
   412     if (!initialized) {
   401         init();
   413         init();
   402     }
   414     }
   403 
   415 
   404     quint32 hashValue = hash(itemName);
       
   405     int begin = 0;
   416     int begin = 0;
   406     int end = mItemCount - 1;
   417     int end = mItemCount - 1;
   407 
   418 
   408     const HbThemeIndexItemData *retItem = 0;
   419     const HbThemeIndexItemData *retItem = 0;
   409 
   420 
   447 
   458 
   448     if (indexCalculatedSize == byteSize) {
   459     if (indexCalculatedSize == byteSize) {
   449         indexOK = true;
   460         indexOK = true;
   450     }
   461     }
   451 
   462 
   452     #ifdef THEME_INDEX_TRACES
       
   453     if (!indexOK) {
   463     if (!indexOK) {
   454         qDebug() <<  "ThemeIndex: Index file corrupted (index size is wrong)!";
   464         THEME_INDEX_DEBUG() <<  "ThemeIndex: Index file corrupted (index size is wrong)!";
   455     }
   465     }
   456     #endif    
       
   457 
   466 
   458     return indexOK;
   467     return indexOK;
   459 }
   468 }