src/hbtools/hbbincssmaker/hboffsetmapbuilder.cpp
changeset 34 ed14f46c0e55
parent 5 627c4a0fd0e7
equal deleted inserted replaced
31:7516d6d86cf5 34:ed14f46c0e55
    22 ** Nokia at developer.feedback@nokia.com.
    22 ** Nokia at developer.feedback@nokia.com.
    23 **
    23 **
    24 ****************************************************************************/
    24 ****************************************************************************/
    25 
    25 
    26 #include "hboffsetmapbuilder_p.h"
    26 #include "hboffsetmapbuilder_p.h"
       
    27 #include "hblayoutparameters_p.h"
       
    28 #include "hbhash_p.h"
    27 
    29 
    28 #include <QFileInfo>
    30 #include <QFileInfo>
    29 
    31 
    30 extern QTextStream err;
    32 extern QTextStream err;
    31 
    33 
    33     Adds \a offsets for a \a className. \a fileInfo points to the layout css file.
    35     Adds \a offsets for a \a className. \a fileInfo points to the layout css file.
    34     \a offsets are indexed using CSSFileType - enum value.
    36     \a offsets are indexed using CSSFileType - enum value.
    35 */
    37 */
    36 bool HbOffsetMapBuilder::addWidgetOffsets(const QString &className,
    38 bool HbOffsetMapBuilder::addWidgetOffsets(const QString &className,
    37                                        const QFileInfo *fileInfo,
    39                                        const QFileInfo *fileInfo,
    38                                        int offsets[])
    40                                        qptrdiff offsets[])
    39 {
    41 {
    40     bool retValue = true;
    42     bool retValue = true;
    41     quint32 nameHash = HbSharedCache::hash(QStringRef(&className));
    43     quint32 nameHash = hbHash(QStringRef(&className));
    42     HbBinMakerOffsetItem mapItem = _mapItems.value(nameHash, HbBinMakerOffsetItem());
    44     HbBinMakerOffsetItem mapItem = mMapItems.value(nameHash, HbBinMakerOffsetItem());
    43     if (mapItem.isNull()) {
    45     if (mapItem.isNull()) {
    44         if (fileInfo) {
    46         if (fileInfo) {
    45             mapItem.name = fileInfo->absoluteFilePath();
    47             mapItem.name = fileInfo->absoluteFilePath();
    46         }
    48         }
    47         mapItem.widgetHash = nameHash;
    49         mapItem.widgetHash = nameHash;
    48         mapItem.offsetCSS = offsets[CSSFile];
    50         mapItem.offsetCSS = offsets[CSSFile];
    49         mapItem.offsetColorCSS = offsets[ColorCSSFile];
    51         mapItem.offsetColorCSS = offsets[ColorCSSFile];
    50         _mapItems.insert(nameHash, mapItem);
    52         mMapItems.insert(nameHash, mapItem);
    51     } else {
    53     } else {
    52         err << "duplicate hash value found!" << endl;
    54         err << "duplicate hash value found!" << endl;
    53         retValue = false;
    55         retValue = false;
    54     }
    56     }
    55     return retValue;
    57     return retValue;
    65 bool HbOffsetMapBuilder::addWidgetMLOffsets(const QString &filePath,
    67 bool HbOffsetMapBuilder::addWidgetMLOffsets(const QString &filePath,
    66                                             quint32 classNameHash,
    68                                             quint32 classNameHash,
    67                                             const QList<LayoutItem> &layoutInfoList)
    69                                             const QList<LayoutItem> &layoutInfoList)
    68 {
    70 {
    69     bool retValue = true;
    71     bool retValue = true;
    70     QMap<quint32, HbBinMakerOffsetItem>::iterator offsetItem = _mapItems.find(classNameHash);
    72     QMap<quint32, HbBinMakerOffsetItem>::iterator offsetItem = mMapItems.find(classNameHash);
    71     if (offsetItem != _mapItems.end()) {
    73     if (offsetItem != mMapItems.end()) {
    72         QSet<quint64> hashCheck;
    74         QSet<quint64> hashCheck;
    73         QList<HbLayoutIndexItem> &layoutIndexTable = offsetItem.value().layoutIndexItemList;
    75         QList<HbLayoutIndexItem> &layoutIndexTable = offsetItem.value().layoutIndexItemList;
    74         Q_FOREACH(const LayoutItem &layoutInfo, layoutInfoList) {
    76         Q_FOREACH(const LayoutItem &layoutInfo, layoutInfoList) {
    75             HbLayoutIndexItem item;
    77             HbLayoutIndexItem item;
    76             item.layoutNameHash = HbSharedCache::hash(QStringRef(&layoutInfo.layout->layoutname));
    78             item.layoutNameHash = hbHash(QStringRef(&layoutInfo.layout->layoutname));
    77             item.sectionNameHash = HbSharedCache::hash(QStringRef(&layoutInfo.layout->section));
    79             item.sectionNameHash = hbHash(QStringRef(&layoutInfo.layout->section));
    78             quint64 hash = (quint64(item.layoutNameHash) << 32) | item.sectionNameHash;
    80             quint64 hash = (quint64(item.layoutNameHash) << 32) | item.sectionNameHash;
    79             if (!hashCheck.contains(hash)) {
    81             if (!hashCheck.contains(hash)) {
    80                 hashCheck.insert(hash);
    82                 hashCheck.insert(hash);
    81             } else {
    83             } else {
    82                 err << "duplicate layout name hash found for: " << filePath << endl;
    84                 err << "duplicate layout name hash found for: " << filePath << endl;
    88         }
    90         }
    89     }
    91     }
    90     return retValue;
    92     return retValue;
    91 }
    93 }
    92 
    94 
       
    95 bool HbOffsetMapBuilder::addGlobalParameters(int zoomLevel,
       
    96                                              const QHash<QString, HbParameterValueItem> &parameters)
       
    97 {
       
    98     Q_UNUSED(zoomLevel)
       
    99     mParameters.clear();
       
   100     bool status = true;
       
   101 
       
   102     QHash<QString, HbParameterValueItem>::const_iterator end = parameters.end();
       
   103     for (QHash<QString, HbParameterValueItem>::const_iterator i = parameters.begin(); i != end; ++i) {
       
   104         quint32 hash = hbHash(QStringRef(&i.key()));
       
   105         if (mParameters.contains(hash)) {
       
   106             err << "duplicate parameter hash found for: " << i.key();
       
   107             status = false;
       
   108             break;
       
   109         }
       
   110         mParameters.insert(hash, qMakePair(i.key(), i.value()));
       
   111     }
       
   112     return status;
       
   113 }
       
   114 
    93 /*!
   115 /*!
    94     dumps the contents of the offset map to bytearray.
   116     dumps the contents of the offset map to bytearray.
    95 
   117 
    96 */
   118 */
    97 QByteArray HbOffsetMapBuilder::result()
   119 QByteArray HbOffsetMapBuilder::result()
    98 {
   120 {
    99     QByteArray dataArray;
   121     QByteArray dataArray;
   100 
   122 
   101     //first layoutindextable is locates after the offsetitem-array.
   123     //first layoutindextable is located after the offsetitem-array.
   102     int currentLayoutIndexTableOffset = _mapItems.size() * sizeof(HbOffsetItem);
   124     qint32 currentLayoutIndexTableOffset = mMapItems.size() * sizeof(HbOffsetItem);
   103 
   125 
   104     //store offsetitems, update layout index table offset
   126     //store offsetitems, update layout index table offset
   105     foreach(const HbBinMakerOffsetItem &mapItem, _mapItems) {
   127     foreach(const HbBinMakerOffsetItem &mapItem, mMapItems) {
   106         HbOffsetItem tmp(mapItem);
   128         HbOffsetItem tmp(mapItem);
   107         if (!mapItem.layoutIndexItemList.isEmpty()) {
   129         if (!mapItem.layoutIndexItemList.isEmpty()) {
   108             tmp.offsetLayoutIndexTable = currentLayoutIndexTableOffset;
   130             tmp.offsetLayoutIndexTable = currentLayoutIndexTableOffset;
   109             currentLayoutIndexTableOffset += sizeof(quint32) // space for the size of the layoutindex table
   131             currentLayoutIndexTableOffset += sizeof(quint32) // space for the size of the layoutindex table
   110                                              + mapItem.layoutIndexItemList.size()
   132                                              + mapItem.layoutIndexItemList.size()
   111                                              * sizeof(HbLayoutIndexItem);
   133                                              * sizeof(HbLayoutIndexItem);
   112         }
   134         }
   113         dataArray.append(reinterpret_cast<const char*>(&tmp), sizeof(HbOffsetItem));
   135         dataArray.append(reinterpret_cast<const char*>(&tmp), sizeof(HbOffsetItem));
   114     }
   136     }
   115 
       
   116     //store layout index tables
   137     //store layout index tables
   117     QMap<quint32, HbBinMakerOffsetItem>::iterator end = _mapItems.end();
   138     QMap<quint32, HbBinMakerOffsetItem>::iterator end = mMapItems.end();
   118     for(QMap<quint32, HbBinMakerOffsetItem>::iterator i = _mapItems.begin(); i != end; ++i) {
   139     for(QMap<quint32, HbBinMakerOffsetItem>::iterator i = mMapItems.begin(); i != end; ++i) {
   119         HbBinMakerOffsetItem &mapItem = i.value();
   140         HbBinMakerOffsetItem &mapItem = i.value();
   120         if (!mapItem.layoutIndexItemList.isEmpty()) {
   141         if (!mapItem.layoutIndexItemList.isEmpty()) {
   121             qSort(mapItem.layoutIndexItemList); //sort for binary search.
   142             qSort(mapItem.layoutIndexItemList); //sort for binary search.
   122             //store the table size first.
   143             //store the table size first.
   123             quint32 size = mapItem.layoutIndexItemList.size();
   144             qint32 size = mapItem.layoutIndexItemList.size();
   124             dataArray.append(reinterpret_cast<const char*>(&size), sizeof(quint32));
   145             dataArray.append(reinterpret_cast<const char*>(&size), sizeof(qint32));
   125             //store the layout-index items.
   146             //store the layout-index items.
   126             foreach(const HbLayoutIndexItem &layoutIndexItem, mapItem.layoutIndexItemList) {
   147             foreach(const HbLayoutIndexItem &layoutIndexItem, mapItem.layoutIndexItemList) {
   127                 dataArray.append(reinterpret_cast<const char*>(&layoutIndexItem),
   148                 dataArray.append(reinterpret_cast<const char*>(&layoutIndexItem),
   128                                  sizeof(HbLayoutIndexItem));
   149                                  sizeof(HbLayoutIndexItem));
   129             }
   150             }
   130         }
   151         }
   131     }
   152     }
       
   153     //store global parameters.
       
   154     mGlobalParameterOffset = dataArray.size()
       
   155                              + sizeof(qint32); //for size
       
   156     qint32 parameterCount = mParameters.count();
       
   157 
       
   158     //parameter item array is followed by the variable name strings.
       
   159     //the start address of the hbparameter-array is the base for the name (added to nameOffset)
       
   160     int nameOffset = parameterCount * sizeof(HbParameterItem);
       
   161 
       
   162     dataArray.append(reinterpret_cast<const char*>(&parameterCount), sizeof(qint32));
       
   163     ParameterMap::const_iterator parametersEnd = mParameters.end();
       
   164     for (ParameterMap::const_iterator i = mParameters.begin(); i != parametersEnd; ++i) {
       
   165         HbParameterItem item(i.key(), i.value().second.offset, nameOffset, i.value().second.special);
       
   166         dataArray.append(reinterpret_cast<const char*>(&item), sizeof(HbParameterItem));
       
   167         nameOffset += i.value().first.length() + 1; // +1 for '\0'.
       
   168     }
       
   169 
       
   170     //store parameter names
       
   171     for (ParameterMap::const_iterator i = mParameters.begin(); i != parametersEnd; ++i) {
       
   172         QByteArray name(i.value().first.toLatin1());
       
   173         dataArray.append(name.constData(), name.length() + 1); //constData will contain the '\0'
       
   174     }
   132     return dataArray;
   175     return dataArray;
   133 }
   176 }