|
1 /**************************************************************************** |
|
2 ** |
|
3 ** Copyright (C) 2008-2010 Nokia Corporation and/or its subsidiary(-ies). |
|
4 ** All rights reserved. |
|
5 ** Contact: Nokia Corporation (developer.feedback@nokia.com) |
|
6 ** |
|
7 ** This file is part of the HbTools module of the UI Extensions for Mobile. |
|
8 ** |
|
9 ** GNU Lesser General Public License Usage |
|
10 ** This file may be used under the terms of the GNU Lesser General Public |
|
11 ** License version 2.1 as published by the Free Software Foundation and |
|
12 ** appearing in the file LICENSE.LGPL included in the packaging of this file. |
|
13 ** Please review the following information to ensure the GNU Lesser General |
|
14 ** Public License version 2.1 requirements will be met: |
|
15 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. |
|
16 ** |
|
17 ** In addition, as a special exception, Nokia gives you certain additional |
|
18 ** rights. These rights are described in the Nokia Qt LGPL Exception |
|
19 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. |
|
20 ** |
|
21 ** If you have questions regarding the use of this file, please contact |
|
22 ** Nokia at developer.feedback@nokia.com. |
|
23 ** |
|
24 ****************************************************************************/ |
|
25 |
|
26 #include "hboffsetmapbuilder_p.h" |
|
27 |
|
28 #include <QFileInfo> |
|
29 |
|
30 extern QTextStream err; |
|
31 |
|
32 /*! |
|
33 Adds \a offsets for a \a className. \a fileInfo points to the layout css file. |
|
34 \a offsets are indexed using CSSFileType - enum value. |
|
35 */ |
|
36 bool HbOffsetMapBuilder::addWidgetOffsets(const QString &className, |
|
37 const QFileInfo *fileInfo, |
|
38 int offsets[]) |
|
39 { |
|
40 bool retValue = true; |
|
41 quint32 nameHash = HbSharedCache::hash(QStringRef(&className)); |
|
42 HbBinMakerOffsetItem mapItem = _mapItems.value(nameHash, HbBinMakerOffsetItem()); |
|
43 if (mapItem.isNull()) { |
|
44 if (fileInfo) { |
|
45 mapItem.name = fileInfo->absoluteFilePath(); |
|
46 } |
|
47 mapItem.widgetHash = nameHash; |
|
48 mapItem.offsetCSS = offsets[CSSFile]; |
|
49 mapItem.offsetColorCSS = offsets[ColorCSSFile]; |
|
50 _mapItems.insert(nameHash, mapItem); |
|
51 } else { |
|
52 err << "duplicate hash value found!" << endl; |
|
53 retValue = false; |
|
54 } |
|
55 return retValue; |
|
56 } |
|
57 |
|
58 /*! |
|
59 Adds \a widgetML layout offsets for a class, which hash is \a classNameHash. |
|
60 Widget offsets for a class must already be added, before calling this method, |
|
61 see \sa addWidgetOffsets. |
|
62 Offsets for each layout is in \a layoutInfoList. \a filePath contains the path to the |
|
63 widgetml file for the class. |
|
64 */ |
|
65 bool HbOffsetMapBuilder::addWidgetMLOffsets(const QString &filePath, |
|
66 quint32 classNameHash, |
|
67 const QList<LayoutItem> &layoutInfoList) |
|
68 { |
|
69 bool retValue = true; |
|
70 QMap<quint32, HbBinMakerOffsetItem>::iterator offsetItem = _mapItems.find(classNameHash); |
|
71 if (offsetItem != _mapItems.end()) { |
|
72 QSet<quint64> hashCheck; |
|
73 QList<HbLayoutIndexItem> &layoutIndexTable = offsetItem.value().layoutIndexItemList; |
|
74 Q_FOREACH(const LayoutItem &layoutInfo, layoutInfoList) { |
|
75 HbLayoutIndexItem item; |
|
76 item.layoutNameHash = HbSharedCache::hash(QStringRef(&layoutInfo.layout->layoutname)); |
|
77 item.sectionNameHash = HbSharedCache::hash(QStringRef(&layoutInfo.layout->section)); |
|
78 quint64 hash = (quint64(item.layoutNameHash) << 32) | item.sectionNameHash; |
|
79 if (!hashCheck.contains(hash)) { |
|
80 hashCheck.insert(hash); |
|
81 } else { |
|
82 err << "duplicate layout name hash found for: " << filePath << endl; |
|
83 retValue = false; |
|
84 break; |
|
85 } |
|
86 item.offset = layoutInfo.offset; |
|
87 layoutIndexTable.append(item); |
|
88 } |
|
89 } |
|
90 return retValue; |
|
91 } |
|
92 |
|
93 /*! |
|
94 dumps the contents of the offset map to bytearray. |
|
95 |
|
96 */ |
|
97 QByteArray HbOffsetMapBuilder::result() |
|
98 { |
|
99 QByteArray dataArray; |
|
100 |
|
101 //first layoutindextable is locates after the offsetitem-array. |
|
102 int currentLayoutIndexTableOffset = _mapItems.size() * sizeof(HbOffsetItem); |
|
103 |
|
104 //store offsetitems, update layout index table offset |
|
105 foreach(const HbBinMakerOffsetItem &mapItem, _mapItems) { |
|
106 HbOffsetItem tmp(mapItem); |
|
107 if (!mapItem.layoutIndexItemList.isEmpty()) { |
|
108 tmp.offsetLayoutIndexTable = currentLayoutIndexTableOffset; |
|
109 currentLayoutIndexTableOffset += sizeof(quint32) // space for the size of the layoutindex table |
|
110 + mapItem.layoutIndexItemList.size() |
|
111 * sizeof(HbLayoutIndexItem); |
|
112 } |
|
113 dataArray.append(reinterpret_cast<const char*>(&tmp), sizeof(HbOffsetItem)); |
|
114 } |
|
115 |
|
116 //store layout index tables |
|
117 QMap<quint32, HbBinMakerOffsetItem>::iterator end = _mapItems.end(); |
|
118 for(QMap<quint32, HbBinMakerOffsetItem>::iterator i = _mapItems.begin(); i != end; ++i) { |
|
119 HbBinMakerOffsetItem &mapItem = i.value(); |
|
120 if (!mapItem.layoutIndexItemList.isEmpty()) { |
|
121 qSort(mapItem.layoutIndexItemList); //sort for binary search. |
|
122 //store the table size first. |
|
123 quint32 size = mapItem.layoutIndexItemList.size(); |
|
124 dataArray.append(reinterpret_cast<const char*>(&size), sizeof(quint32)); |
|
125 //store the layout-index items. |
|
126 foreach(const HbLayoutIndexItem &layoutIndexItem, mapItem.layoutIndexItemList) { |
|
127 dataArray.append(reinterpret_cast<const char*>(&layoutIndexItem), |
|
128 sizeof(HbLayoutIndexItem)); |
|
129 } |
|
130 } |
|
131 } |
|
132 return dataArray; |
|
133 } |