| 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 | #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 | // report Qt usage for commercial customers with a "metered license" (currently experimental) | 
|---|
| 142 | #if QT_EDITION != QT_EDITION_OPENSOURCE | 
|---|
| 143 | #ifdef QT_CONFIGURE_BINARIES_PATH | 
|---|
| 144 | const char *binariesPath = QT_CONFIGURE_BINARIES_PATH; | 
|---|
| 145 | QString reporterPath = QString::fromLocal8Bit(binariesPath); | 
|---|
| 146 | reporterPath += QDir::separator(); | 
|---|
| 147 | reporterPath += QLatin1String("qtusagereporter"); | 
|---|
| 148 | #if defined(Q_OS_WIN) || defined(Q_OS_OS2) | 
|---|
| 149 | reporterPath += QLatin1String(".exe"); | 
|---|
| 150 | #endif | 
|---|
| 151 | if (QFile::exists(reporterPath)) | 
|---|
| 152 | system(qPrintable(reporterPath + QLatin1String(" uic"))); | 
|---|
| 153 | #endif | 
|---|
| 154 | #endif | 
|---|
| 155 |  | 
|---|
| 156 | QString inputFile; | 
|---|
| 157 | if (fileName) | 
|---|
| 158 | inputFile = QString::fromLocal8Bit(fileName); | 
|---|
| 159 | else | 
|---|
| 160 | driver.option().headerProtection = false; | 
|---|
| 161 |  | 
|---|
| 162 | if (driver.option().dependencies) { | 
|---|
| 163 | return !driver.printDependencies(inputFile); | 
|---|
| 164 | } | 
|---|
| 165 |  | 
|---|
| 166 | QTextStream *out = 0; | 
|---|
| 167 | QFile f; | 
|---|
| 168 | if (driver.option().outputFile.size()) { | 
|---|
| 169 | f.setFileName(driver.option().outputFile); | 
|---|
| 170 | if (!f.open(QIODevice::WriteOnly | QFile::Text)) { | 
|---|
| 171 | fprintf(stderr, "Could not create output file\n"); | 
|---|
| 172 | return 1; | 
|---|
| 173 | } | 
|---|
| 174 | out = new QTextStream(&f); | 
|---|
| 175 | out->setCodec(QTextCodec::codecForName("UTF-8")); | 
|---|
| 176 | } | 
|---|
| 177 |  | 
|---|
| 178 | bool rtn = driver.uic(inputFile, out); | 
|---|
| 179 | delete out; | 
|---|
| 180 |  | 
|---|
| 181 | if (!rtn) { | 
|---|
| 182 | if (driver.option().outputFile.size()) { | 
|---|
| 183 | f.close(); | 
|---|
| 184 | f.remove(); | 
|---|
| 185 | } | 
|---|
| 186 | fprintf(stderr, "File '%s' is not valid\n", inputFile.isEmpty() ? "<stdin>" : inputFile.toLocal8Bit().constData()); | 
|---|
| 187 | } | 
|---|
| 188 |  | 
|---|
| 189 | return !rtn; | 
|---|
| 190 | } | 
|---|
| 191 |  | 
|---|
| 192 | QT_END_NAMESPACE | 
|---|
| 193 |  | 
|---|
| 194 | int main(int argc, char *argv[]) | 
|---|
| 195 | { | 
|---|
| 196 | return QT_PREPEND_NAMESPACE(runUic)(argc, argv); | 
|---|
| 197 | } | 
|---|