1
|
1 /****************************************************************************
|
|
2 **
|
|
3 ** Copyright (C) 2008 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 ** Commercial Usage
|
|
9 ** Licensees holding valid Qt Commercial licenses may use this file in
|
|
10 ** accordance with the Qt Commercial License Agreement provided with the
|
|
11 ** Software or, alternatively, in accordance with the terms contained in
|
|
12 ** a written agreement between you and Nokia.
|
|
13 **
|
|
14 **
|
|
15 ** GNU General Public License Usage
|
|
16 ** Alternatively, this file may be used under the terms of the GNU
|
|
17 ** General Public License versions 2.0 or 3.0 as published by the Free
|
|
18 ** Software Foundation and appearing in the file LICENSE.GPL included in
|
|
19 ** the packaging of this file. Please review the following information
|
|
20 ** to ensure GNU General Public Licensing requirements will be met:
|
|
21 ** http://www.fsf.org/licensing/licenses/info/GPLv2.html and
|
|
22 ** http://www.gnu.org/copyleft/gpl.html. In addition, as a special
|
|
23 ** exception, Nokia gives you certain additional rights. These rights
|
|
24 ** are described in the Nokia Qt GPL Exception version 1.3, included in
|
|
25 ** the file GPL_EXCEPTION.txt in this package.
|
|
26 **
|
|
27 ** Qt for Windows(R) Licensees
|
|
28 ** As a special exception, Nokia, as the sole copyright holder for Qt
|
|
29 ** Designer, grants users of the Qt/Eclipse Integration plug-in the
|
|
30 ** right for the Qt/Eclipse Integration to link to functionality
|
|
31 ** provided by Qt Designer and its related libraries.
|
|
32 **
|
|
33 ** If you are unsure which license is appropriate for your use, please
|
|
34 ** contact the sales department at qt-sales@nokia.com.
|
|
35 **
|
|
36 ****************************************************************************/
|
|
37
|
|
38 #include "uic.h"
|
|
39 #include "option.h"
|
|
40 #include "driver.h"
|
|
41 #include <QtCore/QFile>
|
|
42 #include <QtCore/QDir>
|
|
43 #include <QtCore/QTextStream>
|
|
44 #include <QtCore/QTextCodec>
|
|
45 #include <QtCore/QObject>
|
|
46
|
|
47 QT_BEGIN_NAMESPACE
|
|
48
|
|
49 static const char *error = 0;
|
|
50
|
|
51 void showHelp(const char *appName)
|
|
52 {
|
|
53 fprintf(stderr, "QtD User Interface Compiler version %s\n", QT_VERSION_STR);
|
|
54 if (error)
|
|
55 fprintf(stderr, "%s: %s\n", appName, error);
|
|
56
|
|
57 fprintf(stderr, "Usage: %s [options] <uifile>\n\n"
|
|
58 " -h, -help display this help and exit\n"
|
|
59 " -v, -version display version\n"
|
|
60 " -d, -dependencies display the dependencies\n"
|
|
61 " -o <file> place the output into <file>\n"
|
|
62 " -tr <func> use func() for i18n\n"
|
|
63 " -p, -no-protection disable header protection\n"
|
|
64 " -n, -no-implicit-includes disable generation of #include-directives\n"
|
|
65 " for forms generated by uic3\n"
|
|
66 " -g <name> change generator\n"
|
|
67 "\n", appName);
|
|
68 }
|
|
69
|
|
70 int runUic(int argc, char *argv[])
|
|
71 {
|
|
72 Driver driver;
|
|
73
|
|
74 const char *fileName = 0;
|
|
75
|
|
76 int arg = 1;
|
|
77 while (arg < argc) {
|
|
78 QString opt = QString::fromLocal8Bit(argv[arg]);
|
|
79 if (opt == QLatin1String("-h") || opt == QLatin1String("-help")) {
|
|
80 showHelp(argv[0]);
|
|
81 return 0;
|
|
82 } else if (opt == QLatin1String("-d") || opt == QLatin1String("-dependencies")) {
|
|
83 driver.option().dependencies = true;
|
|
84 } else if (opt == QLatin1String("-v") || opt == QLatin1String("-version")) {
|
|
85 fprintf(stderr, "Qt User Interface Compiler version %s\n", QT_VERSION_STR);
|
|
86 return 0;
|
|
87 } else if (opt == QLatin1String("-o") || opt == QLatin1String("-output")) {
|
|
88 ++arg;
|
|
89 if (!argv[arg]) {
|
|
90 showHelp(argv[0]);
|
|
91 return 1;
|
|
92 }
|
|
93 driver.option().outputFile = QFile::decodeName(argv[arg]);
|
|
94 } else if (opt == QLatin1String("-p") || opt == QLatin1String("-no-protection")) {
|
|
95 driver.option().headerProtection = false;
|
|
96 } else if (opt == QLatin1String("-n") || opt == QLatin1String("-no-implicit-includes")) {
|
|
97 driver.option().implicitIncludes = false;
|
|
98 } else if (opt == QLatin1String("-postfix")) {
|
|
99 ++arg;
|
|
100 if (!argv[arg]) {
|
|
101 showHelp(argv[0]);
|
|
102 return 1;
|
|
103 }
|
|
104 driver.option().postfix = QLatin1String(argv[arg]);
|
|
105 } else if (opt == QLatin1String("-3")) {
|
|
106 ++arg;
|
|
107 if (!argv[arg]) {
|
|
108 showHelp(argv[0]);
|
|
109 return 1;
|
|
110 }
|
|
111 driver.option().uic3 = QFile::decodeName(argv[arg]);
|
|
112 } else if (opt == QLatin1String("-tr") || opt == QLatin1String("-translate")) {
|
|
113 ++arg;
|
|
114 if (!argv[arg]) {
|
|
115 showHelp(argv[0]);
|
|
116 return 1;
|
|
117 }
|
|
118 driver.option().translateFunction = QLatin1String(argv[arg]);
|
|
119 } else if (opt == QLatin1String("-g") || opt == QLatin1String("-generator")) {
|
|
120 ++arg;
|
|
121 if (!argv[arg]) {
|
|
122 showHelp(argv[0]);
|
|
123 return 1;
|
|
124 }
|
|
125 QString name = QString::fromLocal8Bit(argv[arg]).toLower ();
|
|
126 driver.option().generator = (name == QLatin1String ("java")) ? Option::JavaGenerator : Option::DGenerator;
|
|
127 } else if (!fileName) {
|
|
128 fileName = argv[arg];
|
|
129 } else {
|
|
130 showHelp(argv[0]);
|
|
131 return 1;
|
|
132 }
|
|
133
|
|
134 ++arg;
|
|
135 }
|
|
136
|
|
137 // report Qt usage for commercial customers with a "metered license" (currently experimental)
|
|
138 #if QT_EDITION != QT_EDITION_OPENSOURCE
|
|
139 #ifdef QT_CONFIGURE_BINARIES_PATH
|
|
140 const char *binariesPath = QT_CONFIGURE_BINARIES_PATH;
|
|
141 QString reporterPath = QString::fromLocal8Bit(binariesPath);
|
|
142 reporterPath += QDir::separator();
|
|
143 reporterPath += QLatin1String("qtusagereporter");
|
|
144 #if defined(Q_OS_WIN)
|
|
145 reporterPath += QLatin1String(".exe");
|
|
146 #endif
|
|
147 if (QFile::exists(reporterPath))
|
|
148 system(qPrintable(reporterPath + QLatin1String(" uic")));
|
|
149 #endif
|
|
150 #endif
|
|
151
|
|
152 QString inputFile;
|
|
153 if (fileName)
|
|
154 inputFile = QString::fromLocal8Bit(fileName);
|
|
155 else
|
|
156 driver.option().headerProtection = false;
|
|
157
|
|
158 if (driver.option().dependencies) {
|
|
159 return !driver.printDependencies(inputFile);
|
|
160 }
|
|
161
|
|
162 QTextStream *out = 0;
|
|
163 QFile f;
|
|
164 if (driver.option().outputFile.size()) {
|
|
165 f.setFileName(driver.option().outputFile);
|
|
166 if (!f.open(QIODevice::WriteOnly | QFile::Text)) {
|
|
167 fprintf(stderr, "Could not create output file\n");
|
|
168 return 1;
|
|
169 }
|
|
170 out = new QTextStream(&f);
|
|
171 out->setCodec(QTextCodec::codecForName("UTF-8"));
|
|
172 }
|
|
173
|
|
174 bool rtn = driver.uic(inputFile, out);
|
|
175 delete out;
|
|
176
|
|
177 if (!rtn) {
|
|
178 if (driver.option().outputFile.size()) {
|
|
179 f.close();
|
|
180 f.remove();
|
|
181 }
|
|
182 fprintf(stderr, "File '%s' is not valid\n", inputFile.isEmpty() ? "<stdin>" : inputFile.toLocal8Bit().constData());
|
|
183 }
|
|
184
|
|
185 return !rtn;
|
|
186 }
|
|
187
|
|
188 QT_END_NAMESPACE
|
|
189
|
|
190 int main(int argc, char *argv[])
|
|
191 {
|
|
192 return QT_PREPEND_NAMESPACE(runUic)(argc, argv);
|
|
193 }
|