diff options
author | toma <toma@283d02a7-25f6-0310-bc7c-ecb5cbfe19da> | 2009-11-25 17:56:58 +0000 |
---|---|---|
committer | toma <toma@283d02a7-25f6-0310-bc7c-ecb5cbfe19da> | 2009-11-25 17:56:58 +0000 |
commit | 90825e2392b2d70e43c7a25b8a3752299a933894 (patch) | |
tree | e33aa27f02b74604afbfd0ea4f1cfca8833d882a /python/pyqt/pylupdate3/main.cpp | |
download | tdebindings-90825e2392b2d70e43c7a25b8a3752299a933894.tar.gz tdebindings-90825e2392b2d70e43c7a25b8a3752299a933894.zip |
Copy the KDE 3.5 branch to branches/trinity for new KDE 3.5 features.
BUG:215923
git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/kdebindings@1054174 283d02a7-25f6-0310-bc7c-ecb5cbfe19da
Diffstat (limited to 'python/pyqt/pylupdate3/main.cpp')
-rw-r--r-- | python/pyqt/pylupdate3/main.cpp | 155 |
1 files changed, 155 insertions, 0 deletions
diff --git a/python/pyqt/pylupdate3/main.cpp b/python/pyqt/pylupdate3/main.cpp new file mode 100644 index 00000000..427fed51 --- /dev/null +++ b/python/pyqt/pylupdate3/main.cpp @@ -0,0 +1,155 @@ +/********************************************************************** +** Copyright (C) 2002 Detlev Offenbach <detlev@die-offenbachs.de> +** +** This is a modified version of lupdate. The original is part of Qt-Linguist. +** The copyright of the original file can be found below. +** +** This version is modified to handle python sources. +** +** The file is provided AS IS with NO WARRANTY OF ANY KIND, +** INCLUDING THE WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE. +** +**********************************************************************/ + + +/********************************************************************** +** Copyright (C) 2000 Trolltech AS. All rights reserved. +** +** main.cpp +** +** This file is part of Qt Linguist. +** +** See the file LICENSE included in the distribution for the usage +** and distribution terms. +** +** The file is provided AS IS with NO WARRANTY OF ANY KIND, +** INCLUDING THE WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE. +** +**********************************************************************/ + +#include <qfile.h> +#include <qstring.h> +#include <qstringlist.h> +#include <qtextstream.h> + +#include <errno.h> +#include <metatranslator.h> +#include <proparser.h> +#include <string.h> + +// defined in fetchtr.cpp +extern void fetchtr_py( const char *fileName, MetaTranslator *tor, + const char *defaultContext, bool mustExist ); + +// defined in merge.cpp +extern void merge( MetaTranslator *tor, const MetaTranslator *virginTor, + bool verbose ); + +typedef QValueList<MetaTranslatorMessage> TML; + +static void printUsage() +{ + qWarning( "Usage: pylupdate [options] file.pro...\n" + "Options:\n" + " -help Display this information and exits\n" + " -noobsolete\n" + " Drop all obsolete strings\n" + " -verbose\n" + " Explain what is being done\n" + " -version\n" + " Display the version of pylupdate and exits" ); +} + +int main( int argc, char **argv ) +{ + bool verbose = FALSE; + bool noObsolete = FALSE; + bool metSomething = FALSE; + int numProFiles = 0; + + for ( int i = 1; i < argc; i++ ) { + if ( qstrcmp(argv[i], "-help") == 0 ) { + printUsage(); + return 0; + } else if ( qstrcmp(argv[i], "-noobsolete") == 0 ) { + noObsolete = TRUE; + continue; + } else if ( qstrcmp(argv[i], "-verbose") == 0 ) { + verbose = TRUE; + continue; + } else if ( qstrcmp(argv[i], "-version") == 0 ) { + qWarning( "pylupdate version %s", QT_VERSION_STR ); + return 0; + } + + numProFiles++; + QFile f( argv[i] ); + if ( !f.open(IO_ReadOnly) ) { + qWarning( "pylupdate error: Cannot open project file '%s': %s", + argv[i], strerror(errno) ); + return 1; + } + + QTextStream t( &f ); + QString fullText = t.read(); + f.close(); + + MetaTranslator fetchedTor; + QString defaultContext = "@default"; + QCString codec; + QStringList translatorFiles; + QStringList::Iterator tf; + + QMap<QString, QString> tagMap = proFileTagMap( fullText ); + QMap<QString, QString>::Iterator it; + + for ( it = tagMap.begin(); it != tagMap.end(); ++it ) { + QStringList toks = QStringList::split( QChar(' '), it.data() ); + QStringList::Iterator t; + + for ( t = toks.begin(); t != toks.end(); ++t ) { + if ( it.key() == QString("SOURCES") ) { + fetchtr_py( *t, &fetchedTor, + defaultContext, TRUE ); + metSomething = TRUE; + } else if ( it.key() == QString("TRANSLATIONS") ) { + translatorFiles.append( *t ); + metSomething = TRUE; + } else if ( it.key() == QString("CODEC") ) { + codec = (*t).latin1(); + } + } + } + + for ( tf = translatorFiles.begin(); tf != translatorFiles.end(); ++tf ) { + MetaTranslator tor; + tor.load( *tf ); + if ( !codec.isEmpty() ) + tor.setCodec( codec ); + if ( verbose ) + qWarning( "Updating '%s'...", (*tf).latin1() ); + merge( &tor, &fetchedTor, verbose ); + if ( noObsolete ) + tor.stripObsoleteMessages(); + tor.stripEmptyContexts(); + if ( !tor.save(*tf) ) + qWarning( "pylupdate error: Cannot save '%s': %s", (*tf).latin1(), + strerror(errno) ); + } + if ( !metSomething ) { + qWarning( "pylupdate warning: File '%s' does not look like a project" + " file", argv[i] ); + } else if ( translatorFiles.isEmpty() ) { + qWarning( "pylupdate warning: Met no 'TRANSLATIONS' entry in project" + " file '%s'", argv[i] ); + } + } + + if ( numProFiles == 0 ) { + printUsage(); + return 1; + } + return 0; +} |