|
1 /**************************************************************************** |
|
2 ** |
|
3 ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). |
|
4 ** All rights reserved. |
|
5 ** Contact: Nokia Corporation (qt-info@nokia.com) |
|
6 ** |
|
7 ** This file is part of the tools applications of the Qt Toolkit. |
|
8 ** |
|
9 ** $QT_BEGIN_LICENSE:LGPL$ |
|
10 ** No Commercial Usage |
|
11 ** This file contains pre-release code and may not be distributed. |
|
12 ** You may use this file in accordance with the terms and conditions |
|
13 ** contained in the Technology Preview License Agreement accompanying |
|
14 ** this package. |
|
15 ** |
|
16 ** GNU Lesser General Public License Usage |
|
17 ** Alternatively, this file may be used under the terms of the GNU Lesser |
|
18 ** General Public License version 2.1 as published by the Free Software |
|
19 ** Foundation and appearing in the file LICENSE.LGPL included in the |
|
20 ** packaging of this file. Please review the following information to |
|
21 ** ensure the GNU Lesser General Public License version 2.1 requirements |
|
22 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. |
|
23 ** |
|
24 ** In addition, as a special exception, Nokia gives you certain additional |
|
25 ** rights. These rights are described in the Nokia Qt LGPL Exception |
|
26 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. |
|
27 ** |
|
28 ** If you have questions regarding the use of this file, please contact |
|
29 ** Nokia at qt-info@nokia.com. |
|
30 ** |
|
31 ** |
|
32 ** |
|
33 ** |
|
34 ** |
|
35 ** |
|
36 ** |
|
37 ** |
|
38 ** $QT_END_LICENSE$ |
|
39 ** |
|
40 ****************************************************************************/ |
|
41 |
|
42 #include "uic.h" |
|
43 #include "option.h" |
|
44 #include "driver.h" |
|
45 #include "../../corelib/global/qconfig.cpp" |
|
46 #include <QtCore/QFile> |
|
47 #include <QtCore/QDir> |
|
48 #include <QtCore/QTextStream> |
|
49 #include <QtCore/QTextCodec> |
|
50 |
|
51 QT_BEGIN_NAMESPACE |
|
52 |
|
53 static const char *error = 0; |
|
54 |
|
55 void showHelp(const char *appName) |
|
56 { |
|
57 fprintf(stderr, "Qt User Interface Compiler version %s\n", QT_VERSION_STR); |
|
58 if (error) |
|
59 fprintf(stderr, "%s: %s\n", appName, error); |
|
60 |
|
61 fprintf(stderr, "Usage: %s [options] <uifile>\n\n" |
|
62 " -h, -help display this help and exit\n" |
|
63 " -v, -version display version\n" |
|
64 " -d, -dependencies display the dependencies\n" |
|
65 " -o <file> place the output into <file>\n" |
|
66 " -tr <func> use func() for i18n\n" |
|
67 " -p, -no-protection disable header protection\n" |
|
68 " -n, -no-implicit-includes disable generation of #include-directives\n" |
|
69 " for forms generated by uic3\n" |
|
70 " -g <name> change generator\n" |
|
71 "\n", appName); |
|
72 } |
|
73 |
|
74 int runUic(int argc, char *argv[]) |
|
75 { |
|
76 Driver driver; |
|
77 |
|
78 const char *fileName = 0; |
|
79 |
|
80 int arg = 1; |
|
81 while (arg < argc) { |
|
82 QString opt = QString::fromLocal8Bit(argv[arg]); |
|
83 if (opt == QLatin1String("-h") || opt == QLatin1String("-help")) { |
|
84 showHelp(argv[0]); |
|
85 return 0; |
|
86 } else if (opt == QLatin1String("-d") || opt == QLatin1String("-dependencies")) { |
|
87 driver.option().dependencies = true; |
|
88 } else if (opt == QLatin1String("-v") || opt == QLatin1String("-version")) { |
|
89 fprintf(stderr, "Qt User Interface Compiler version %s\n", QT_VERSION_STR); |
|
90 return 0; |
|
91 } else if (opt == QLatin1String("-o") || opt == QLatin1String("-output")) { |
|
92 ++arg; |
|
93 if (!argv[arg]) { |
|
94 showHelp(argv[0]); |
|
95 return 1; |
|
96 } |
|
97 driver.option().outputFile = QFile::decodeName(argv[arg]); |
|
98 } else if (opt == QLatin1String("-p") || opt == QLatin1String("-no-protection")) { |
|
99 driver.option().headerProtection = false; |
|
100 } else if (opt == QLatin1String("-n") || opt == QLatin1String("-no-implicit-includes")) { |
|
101 driver.option().implicitIncludes = false; |
|
102 } else if (opt == QLatin1String("-postfix")) { |
|
103 ++arg; |
|
104 if (!argv[arg]) { |
|
105 showHelp(argv[0]); |
|
106 return 1; |
|
107 } |
|
108 driver.option().postfix = QLatin1String(argv[arg]); |
|
109 } else if (opt == QLatin1String("-3")) { |
|
110 ++arg; |
|
111 if (!argv[arg]) { |
|
112 showHelp(argv[0]); |
|
113 return 1; |
|
114 } |
|
115 driver.option().uic3 = QFile::decodeName(argv[arg]); |
|
116 } else if (opt == QLatin1String("-tr") || opt == QLatin1String("-translate")) { |
|
117 ++arg; |
|
118 if (!argv[arg]) { |
|
119 showHelp(argv[0]); |
|
120 return 1; |
|
121 } |
|
122 driver.option().translateFunction = QLatin1String(argv[arg]); |
|
123 } else if (opt == QLatin1String("-g") || opt == QLatin1String("-generator")) { |
|
124 ++arg; |
|
125 if (!argv[arg]) { |
|
126 showHelp(argv[0]); |
|
127 return 1; |
|
128 } |
|
129 QString name = QString::fromLocal8Bit(argv[arg]).toLower (); |
|
130 driver.option().generator = (name == QLatin1String ("java")) ? Option::JavaGenerator : Option::CppGenerator; |
|
131 } else if (!fileName) { |
|
132 fileName = argv[arg]; |
|
133 } else { |
|
134 showHelp(argv[0]); |
|
135 return 1; |
|
136 } |
|
137 |
|
138 ++arg; |
|
139 } |
|
140 |
|
141 QString inputFile; |
|
142 if (fileName) |
|
143 inputFile = QString::fromLocal8Bit(fileName); |
|
144 else |
|
145 driver.option().headerProtection = false; |
|
146 |
|
147 if (driver.option().dependencies) { |
|
148 return !driver.printDependencies(inputFile); |
|
149 } |
|
150 |
|
151 QTextStream *out = 0; |
|
152 QFile f; |
|
153 if (driver.option().outputFile.size()) { |
|
154 f.setFileName(driver.option().outputFile); |
|
155 if (!f.open(QIODevice::WriteOnly | QFile::Text)) { |
|
156 fprintf(stderr, "Could not create output file\n"); |
|
157 return 1; |
|
158 } |
|
159 out = new QTextStream(&f); |
|
160 out->setCodec(QTextCodec::codecForName("UTF-8")); |
|
161 } |
|
162 |
|
163 bool rtn = driver.uic(inputFile, out); |
|
164 delete out; |
|
165 |
|
166 if (!rtn) { |
|
167 if (driver.option().outputFile.size()) { |
|
168 f.close(); |
|
169 f.remove(); |
|
170 } |
|
171 fprintf(stderr, "File '%s' is not valid\n", inputFile.isEmpty() ? "<stdin>" : inputFile.toLocal8Bit().constData()); |
|
172 } |
|
173 |
|
174 return !rtn; |
|
175 } |
|
176 |
|
177 QT_END_NAMESPACE |
|
178 |
|
179 int main(int argc, char *argv[]) |
|
180 { |
|
181 return QT_PREPEND_NAMESPACE(runUic)(argc, argv); |
|
182 } |