1
/****************************************************************************
3
** Copyright (C) 1992-2005 Trolltech AS. All rights reserved.
5
** This file is part of the tools applications of the Qt Toolkit.
7
** This file may be distributed under the terms of the Q Public License
8
** as defined by Trolltech AS of Norway and appearing in the file
9
** LICENSE.QPL included in the packaging of this file.
11
** This file may be distributed and/or modified under the terms of the
12
** GNU General Public License version 2 as published by the Free Software
13
** Foundation and appearing in the file LICENSE.GPL included in the
14
** packaging of this file.
16
** See http://www.trolltech.com/pricing.html or email sales@trolltech.com for
17
** information about Qt Commercial License Agreements.
18
** See http://www.trolltech.com/qpl/ for QPL licensing information.
19
** See http://www.trolltech.com/gpl/ for GPL licensing information.
21
** Contact info@trolltech.com if any conditions of this licensing are
24
** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
25
** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
27
****************************************************************************/
29
#include "ui3reader.h"
32
#include <qapplication.h>
34
#include <qfileinfo.h>
35
#include <qstringlist.h>
36
#include <qdatetime.h>
37
#include <qsettings.h>
38
#include <globaldefs.h>
43
#include <qt_windows.h>
46
int main(int argc, char * argv[])
50
bool imagecollection = false;
51
bool imagecollection_tmpfile = false;
54
const char *error = 0;
55
const char* fileName = 0;
56
const char* className = 0;
57
const char* headerFile = 0;
58
QByteArray outputFile;
59
QByteArray image_tmpfile;
60
const char* projectName = 0;
61
const char* trmacro = 0;
65
QApplication app(argc, argv, false);
67
for (int n = 1; n < argc && error == 0; n++) {
68
QByteArray arg = argv[n];
69
if (arg[0] == '-') { // option
70
QByteArray opt = arg.data() + 1;
71
if (opt[0] == 'o') { // output redirection
74
error = "Missing output-file name";
77
outputFile = argv[++n];
79
outputFile = opt.data() + 1;
80
} else if (opt[0] == 'i' || opt == "impl") {
82
if (opt == "impl" || opt[1] == '\0') {
84
error = "Missing name of header file";
87
headerFile = argv[++n];
89
headerFile = opt.data() + 1;
90
} else if ( opt[0] == 'e' || opt == "embed" ) {
91
imagecollection = true;
92
if ( opt == "embed" || opt[1] == '\0' ) {
93
if ( !(n < argc-1) ) {
94
error = "Missing name of project";
97
projectName = argv[++n];
99
projectName = opt.data() + 1;
101
if ( argc > n+1 && qstrcmp( argv[n+1], "-f" ) == 0 ) {
102
imagecollection_tmpfile = true;
103
image_tmpfile = argv[n+2];
106
} else if (opt == "nofwd") {
108
} else if (opt == "nounload") {
110
} else if (opt == "convert") {
112
} else if (opt == "subdecl") {
115
error = "Missing arguments";
118
className = argv[++n];
119
headerFile = argv[++n];
120
} else if (opt == "subimpl") {
124
error = "Missing arguments";
127
className = argv[++n];
128
headerFile = argv[++n];
129
} else if (opt == "tr") {
130
if (opt == "tr" || opt[1] == '\0') {
132
error = "Missing tr macro.";
137
trmacro = opt.data() + 1;
139
} else if (opt == "L") {
141
error = "Missing plugin path.";
144
++n; // ignore the next argument
145
} else if (opt == "version") {
147
"User Interface Compiler for Qt version %s\n",
150
} else if (opt == "help") {
152
} else if (opt == "fix") {
154
} else if (opt == "pch") {
156
error = "Missing name of PCH file";
161
error = "Unrecognized option";
164
if (imagecollection && !imagecollection_tmpfile)
165
images << QLatin1String(argv[n]);
166
else if (fileName) // can handle only one file
167
error = "Too many input files specified";
173
if (argc < 2 || error || (!fileName && !imagecollection)) {
174
fprintf(stderr, "Qt user interface compiler\n");
176
fprintf(stderr, "uic: %s\n", error);
178
fprintf(stderr, "Usage: %s [options] [mode] <uifile>\n\n"
179
"Convert a UI file to version 4:\n"
180
" %s [options] -convert <uifile>\n"
181
"Generate declaration:\n"
182
" %s [options] <uifile>\n"
183
"\t<uiheaderfile> name of the data file\n"
184
" %s [options] -decl <uiheaderfile> <uifile>\n"
185
"\t<uiheaderfile> name of the data file\n"
186
"Generate implementation:\n"
187
" %s [options] -impl <headerfile> <uifile>\n"
188
"\t<headerfile> name of the declaration file\n"
189
"Generate image collection:\n"
190
" %s [options] -embed <project> <image1> <image2> <image3> ...\n"
192
" %s [options] -embed <project> -f <temporary file containing image names>\n"
193
"\t<project> project name\n"
194
"\t<image[1-N]> image files\n"
195
"Generate subclass declaration:\n"
196
" %s [options] -subdecl <subclassname> <baseclassheaderfile> <uifile>\n"
197
"\t<subclassname> name of the subclass to generate\n"
198
"\t<baseclassheaderfile> declaration file of the baseclass\n"
199
"Generate subclass implementation:\n"
200
" %s [options] -subimpl <subclassname> <subclassheaderfile> <uifile>\n"
201
"\t<subclassname> name of the subclass to generate\n"
202
"\t<subclassheaderfile> declaration file of the subclass\n"
204
"\t-o file Write output to file rather than stdout\n"
205
"\t-pch file Add #include \"file\" as the first statement in implementation\n"
206
"\t-nofwd Omit forward declarations of custom classes\n"
207
"\t-nounload Don't unload plugins after processing\n"
208
"\t-tr func Use func() instead of tr() for i18n\n"
209
"\t-L path Additional plugin search path\n"
210
"\t-version Display version of uic\n"
211
"\t-help Display this information\n"
212
, argv[0], argv[0], argv[0], argv[0], argv[0], argv[0], argv[0], argv[0], argv[0]
217
if (imagecollection_tmpfile) {
218
QFile ifile(QFile::decodeName(image_tmpfile));
219
if (ifile.open(QIODevice::ReadOnly)) {
220
QTextStream ts(&ifile);
221
QString s = ts.read();
223
images = s.split(QLatin1Char(' '));
224
for (QStringList::Iterator it = images.begin(); it != images.end(); ++it)
225
*it = (*it).simplified();
230
if (!outputFile.isEmpty()) {
231
fileOut.setFileName(QFile::decodeName(outputFile));
232
if (!fileOut.open(QIODevice::WriteOnly)) {
233
fprintf(stderr, "%s: Could not open output file '%s'\n", argv[0], outputFile.data());
237
fileOut.open(QIODevice::WriteOnly, stdout);
240
QTextStream out(&fileOut);
244
if (projectName && imagecollection) {
245
out.setEncoding(QTextStream::Latin1);
246
ui3.embed(projectName, images);
250
out.setEncoding(QTextStream::UnicodeUTF8);
252
QFile file(QFile::decodeName(fileName));
253
if (!file.open(QIODevice::ReadOnly)) {
254
fprintf(stderr, "%s: Could not open file '%s'\n", argv[0], fileName);
261
if (!doc.setContent(&file, &errMsg, &errLine)) {
262
fprintf(stderr, "%s: Failed to parse %s: %s in line %d\n", argv[0], fileName, errMsg.latin1(), errLine);
266
QDomElement e = doc.firstChild().toElement();
267
double version = e.attribute(QLatin1String("version"), QLatin1String("3.0")).toDouble();
270
fprintf(stderr, "%s: File generated with too recent version of Qt Designer (%s vs. %s)\n",
271
argv[0], e.attribute(QLatin1String("version")).latin1(), "3.3");
275
DomTool::fixDocument(doc);
278
out << doc.toString();
282
if (imagecollection) {
283
out.setEncoding(QTextStream::Latin1);
284
ui3.embed(projectName, images);
289
ui3.generateUi4(QFile::decodeName(fileName), QFile::decodeName(outputFile), doc);
294
if (subcl && className && !impl)
295
protector = QString::fromUtf8(className).toUpper() + QLatin1String("_H");
297
if (!protector.isEmpty()) {
298
out << "#ifndef " << protector << endl;
299
out << "#define " << protector << endl;
302
if (!pchFile.isEmpty() && impl) {
303
out << "#include \"" << pchFile << "\" // PCH include" << endl;
307
out << "#include \"" << headerFile << "\"" << endl << endl;
310
ui3.generate(QFile::decodeName(fileName),
311
QFile::decodeName(outputFile),
315
QString::fromUtf8(trmacro),
316
QString::fromUtf8(className),
319
if (!protector.isEmpty()) {
321
out << "#endif // " << protector << endl;
324
if (fileOut.error() != QFile::NoError) {
325
fprintf(stderr, "%s: Error writing to file\n", argv[0]);
326
if (!outputFile.isEmpty())