comparison tools/drcc/rcc.h @ 57:7be693ea7070

drcc, resource compiler, see interview demo
author eldar
date Tue, 19 May 2009 02:49:08 +0000
parents
children a2871e6b8b15
comparison
equal deleted inserted replaced
56:d5a6b6269f44 57:7be693ea7070
1 /****************************************************************************
2 **
3 ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
4 ** Contact: Qt Software Information (qt-info@nokia.com)
5 **
6 ** This file is part of the tools applications of the Qt Toolkit.
7 **
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** Commercial Usage
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Nokia.
14 **
15 ** GNU Lesser General Public License Usage
16 ** Alternatively, this file may be used under the terms of the GNU Lesser
17 ** General Public License version 2.1 as published by the Free Software
18 ** Foundation and appearing in the file LICENSE.LGPL included in the
19 ** packaging of this file. Please review the following information to
20 ** ensure the GNU Lesser General Public License version 2.1 requirements
21 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
22 **
23 ** In addition, as a special exception, Nokia gives you certain
24 ** additional rights. These rights are described in the Nokia Qt LGPL
25 ** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
26 ** package.
27 **
28 ** GNU General Public License Usage
29 ** Alternatively, this file may be used under the terms of the GNU
30 ** General Public License version 3.0 as published by the Free Software
31 ** Foundation and appearing in the file LICENSE.GPL included in the
32 ** packaging of this file. Please review the following information to
33 ** ensure the GNU General Public License version 3.0 requirements will be
34 ** met: http://www.gnu.org/copyleft/gpl.html.
35 **
36 ** If you are unsure which license is appropriate for your use, please
37 ** contact the sales department at qt-sales@nokia.com.
38 ** $QT_END_LICENSE$
39 **
40 ****************************************************************************/
41
42 #ifndef RCC_H
43 #define RCC_H
44
45 #include <QtCore/QStringList>
46 #include <QtCore/QHash>
47 #include <QtCore/QString>
48
49 QT_BEGIN_NAMESPACE
50
51 class RCCFileInfo;
52 class QIODevice;
53 class QTextStream;
54
55
56 class RCCResourceLibrary
57 {
58 RCCResourceLibrary(const RCCResourceLibrary &);
59 RCCResourceLibrary &operator=(const RCCResourceLibrary &);
60
61 public:
62 RCCResourceLibrary();
63 ~RCCResourceLibrary();
64
65 bool output(QIODevice &out, QIODevice &errorDevice);
66
67 bool readFiles(bool ignoreErrors, QIODevice &errorDevice);
68
69 enum Format { Binary, C_Code };
70 void setFormat(Format f) { m_format = f; }
71 Format format() const { return m_format; }
72
73 void setInputFiles(const QStringList &files) { m_fileNames = files; }
74 QStringList inputFiles() const { return m_fileNames; }
75
76 QStringList dataFiles() const;
77
78 // Return a map of resource identifier (':/newPrefix/images/p1.png') to file.
79 typedef QHash<QString, QString> ResourceDataFileMap;
80 ResourceDataFileMap resourceDataFileMap() const;
81
82 void setVerbose(bool b) { m_verbose = b; }
83 bool verbose() const { return m_verbose; }
84
85 void setInitName(const QString &name) { m_initName = name; }
86 QString initName() const { return m_initName; }
87
88 void setCompressLevel(int c) { m_compressLevel = c; }
89 int compressLevel() const { return m_compressLevel; }
90
91 void setCompressThreshold(int t) { m_compressThreshold = t; }
92 int compressThreshold() const { return m_compressThreshold; }
93
94 void setResourceRoot(const QString &root) { m_resourceRoot = root; }
95 QString resourceRoot() const { return m_resourceRoot; }
96
97 void setUseNameSpace(bool v) { m_useNameSpace = v; }
98 bool useNameSpace() const { return m_useNameSpace; }
99
100 QStringList failedResources() const { return m_failedResources; }
101
102 private:
103 struct Strings {
104 Strings();
105 const QString TAG_RCC;
106 const QString TAG_RESOURCE;
107 const QString TAG_FILE;
108 const QString ATTRIBUTE_LANG;
109 const QString ATTRIBUTE_PREFIX;
110 const QString ATTRIBUTE_ALIAS;
111 const QString ATTRIBUTE_THRESHOLD;
112 const QString ATTRIBUTE_COMPRESS;
113 };
114 friend class RCCFileInfo;
115 void reset();
116 bool addFile(const QString &alias, const RCCFileInfo &file);
117 bool interpretResourceFile(QIODevice *inputDevice, const QString &file,
118 QString currentPath = QString(), bool ignoreErrors = false);
119 bool writeHeader();
120 bool writeDataBlobs();
121 bool writeDataNames();
122 bool writeDataStructure();
123 bool writeInitializer();
124 void writeMangleNamespaceFunction(const QByteArray &name);
125 void writeAddNamespaceFunction(const QByteArray &name);
126 void writeHex(quint8 number);
127 void writeNumber2(quint16 number);
128 void writeNumber4(quint32 number);
129 void writeChar(char c) { m_out.append(c); }
130 void writeByteArray(const QByteArray &);
131 void write(const char *, int len);
132
133 const Strings m_strings;
134 RCCFileInfo *m_root;
135 QStringList m_fileNames;
136 QString m_resourceRoot;
137 QString m_initName;
138 Format m_format;
139 bool m_verbose;
140 int m_compressLevel;
141 int m_compressThreshold;
142 int m_treeOffset;
143 int m_namesOffset;
144 int m_dataOffset;
145 bool m_useNameSpace;
146 QStringList m_failedResources;
147 QIODevice *m_errorDevice;
148 QByteArray m_out;
149 };
150
151 QT_END_NAMESPACE
152
153 #endif // RCC_H