diff options
author | Timothy Pearson <kb9vqf@pearsoncomputing.net> | 2011-11-29 01:11:08 -0600 |
---|---|---|
committer | Timothy Pearson <kb9vqf@pearsoncomputing.net> | 2011-11-29 01:11:08 -0600 |
commit | 8a055d66f43592c257cece2eb8cc021808062917 (patch) | |
tree | d0922f201bd5d24b62a33160d1d9baf9e89f9a70 /pylupdate3/metatranslator.cpp | |
parent | b388516ca2691303a076a0764fd40bf7116fe43d (diff) | |
download | pytqt-8a055d66f43592c257cece2eb8cc021808062917.tar.gz pytqt-8a055d66f43592c257cece2eb8cc021808062917.zip |
Initial TQt conversion
Diffstat (limited to 'pylupdate3/metatranslator.cpp')
-rw-r--r-- | pylupdate3/metatranslator.cpp | 192 |
1 files changed, 96 insertions, 96 deletions
diff --git a/pylupdate3/metatranslator.cpp b/pylupdate3/metatranslator.cpp index c3d0673..4b67c32 100644 --- a/pylupdate3/metatranslator.cpp +++ b/pylupdate3/metatranslator.cpp @@ -3,7 +3,7 @@ ** ** metatranslator.cpp ** -** This file is part of Qt Linguist. +** This file is part of TQt Linguist. ** ** See the file LICENSE included in the distribution for the usage ** and distribution terms. @@ -25,20 +25,20 @@ #include "metatranslator.h" -static bool encodingIsUtf8( const QXmlAttributes& atts ) +static bool encodingIsUtf8( const TQXmlAttributes& atts ) { for ( int i = 0; i < atts.length(); i++ ) { // utf8="true" is a pre-3.0 syntax - if ( atts.qName(i) == QString("utf8") ) { - return ( atts.value(i) == QString("true") ); - } else if ( atts.qName(i) == QString("encoding") ) { - return ( atts.value(i) == QString("UTF-8") ); + if ( atts.qName(i) == TQString("utf8") ) { + return ( atts.value(i) == TQString("true") ); + } else if ( atts.qName(i) == TQString("encoding") ) { + return ( atts.value(i) == TQString("UTF-8") ); } } return FALSE; } -class TsHandler : public QXmlDefaultHandler +class TsHandler : public TQXmlDefaultHandler { public: TsHandler( MetaTranslator *translator ) @@ -46,38 +46,38 @@ public: inMessage( FALSE ), ferrorCount( 0 ), contextIsUtf8( FALSE ), messageIsUtf8( FALSE ) { } - virtual bool startElement( const QString& namespaceURI, - const QString& localName, const QString& qName, - const QXmlAttributes& atts ); - virtual bool endElement( const QString& namespaceURI, - const QString& localName, const QString& qName ); - virtual bool characters( const QString& ch ); - virtual bool fatalError( const QXmlParseException& exception ); + virtual bool startElement( const TQString& namespaceURI, + const TQString& localName, const TQString& qName, + const TQXmlAttributes& atts ); + virtual bool endElement( const TQString& namespaceURI, + const TQString& localName, const TQString& qName ); + virtual bool characters( const TQString& ch ); + virtual bool fatalError( const TQXmlParseException& exception ); private: MetaTranslator *tor; MetaTranslatorMessage::Type type; bool inMessage; - QString context; - QString source; - QString comment; - QString translation; + TQString context; + TQString source; + TQString comment; + TQString translation; - QString accum; + TQString accum; int ferrorCount; bool contextIsUtf8; bool messageIsUtf8; }; -bool TsHandler::startElement( const QString& /* namespaceURI */, - const QString& /* localName */, - const QString& qName, - const QXmlAttributes& atts ) +bool TsHandler::startElement( const TQString& /* namespaceURI */, + const TQString& /* localName */, + const TQString& qName, + const TQXmlAttributes& atts ) { - if ( qName == QString("byte") ) { + if ( qName == TQString("byte") ) { for ( int i = 0; i < atts.length(); i++ ) { - if ( atts.qName(i) == QString("value") ) { - QString value = atts.value( i ); + if ( atts.qName(i) == TQString("value") ) { + TQString value = atts.value( i ); int base = 10; if ( value.startsWith("x") ) { base = 16; @@ -85,29 +85,29 @@ bool TsHandler::startElement( const QString& /* namespaceURI */, } int n = value.toUInt( 0, base ); if ( n != 0 ) - accum += QChar( n ); + accum += TQChar( n ); } } } else { - if ( qName == QString("context") ) { + if ( qName == TQString("context") ) { context.truncate( 0 ); source.truncate( 0 ); comment.truncate( 0 ); translation.truncate( 0 ); contextIsUtf8 = encodingIsUtf8( atts ); - } else if ( qName == QString("message") ) { + } else if ( qName == TQString("message") ) { inMessage = TRUE; type = MetaTranslatorMessage::Finished; source.truncate( 0 ); comment.truncate( 0 ); translation.truncate( 0 ); messageIsUtf8 = encodingIsUtf8( atts ); - } else if ( qName == QString("translation") ) { + } else if ( qName == TQString("translation") ) { for ( int i = 0; i < atts.length(); i++ ) { - if ( atts.qName(i) == QString("type") ) { - if ( atts.value(i) == QString("unfinished") ) + if ( atts.qName(i) == TQString("type") ) { + if ( atts.value(i) == TQString("unfinished") ) type = MetaTranslatorMessage::Unfinished; - else if ( atts.value(i) == QString("obsolete") ) + else if ( atts.value(i) == TQString("obsolete") ) type = MetaTranslatorMessage::Obsolete; else type = MetaTranslatorMessage::Finished; @@ -119,33 +119,33 @@ bool TsHandler::startElement( const QString& /* namespaceURI */, return TRUE; } -bool TsHandler::endElement( const QString& /* namespaceURI */, - const QString& /* localName */, - const QString& qName ) +bool TsHandler::endElement( const TQString& /* namespaceURI */, + const TQString& /* localName */, + const TQString& qName ) { - if ( qName == QString("codec") || qName == QString("defaultcodec") ) { + if ( qName == TQString("codec") || qName == TQString("defaultcodec") ) { // "codec" is a pre-3.0 syntax tor->setCodec( accum ); - } else if ( qName == QString("name") ) { + } else if ( qName == TQString("name") ) { context = accum; - } else if ( qName == QString("source") ) { + } else if ( qName == TQString("source") ) { source = accum; - } else if ( qName == QString("comment") ) { + } else if ( qName == TQString("comment") ) { if ( inMessage ) { comment = accum; } else { if ( contextIsUtf8 ) tor->insert( MetaTranslatorMessage(context.utf8(), "", - accum.utf8(), QString::null, TRUE, + accum.utf8(), TQString::null, TRUE, MetaTranslatorMessage::Unfinished) ); else tor->insert( MetaTranslatorMessage(context.ascii(), "", - accum.ascii(), QString::null, FALSE, + accum.ascii(), TQString::null, FALSE, MetaTranslatorMessage::Unfinished) ); } - } else if ( qName == QString("translation") ) { + } else if ( qName == TQString("translation") ) { translation = accum; - } else if ( qName == QString("message") ) { + } else if ( qName == TQString("message") ) { if ( messageIsUtf8 ) tor->insert( MetaTranslatorMessage(context.utf8(), source.utf8(), comment.utf8(), translation, @@ -159,56 +159,56 @@ bool TsHandler::endElement( const QString& /* namespaceURI */, return TRUE; } -bool TsHandler::characters( const QString& ch ) +bool TsHandler::characters( const TQString& ch ) { - QString t = ch; - t.replace( QRegExp(QChar('\r')), "" ); + TQString t = ch; + t.replace( TQRegExp(TQChar('\r')), "" ); accum += t; return TRUE; } -bool TsHandler::fatalError( const QXmlParseException& exception ) +bool TsHandler::fatalError( const TQXmlParseException& exception ) { if ( ferrorCount++ == 0 ) { - QString msg; + TQString msg; msg.sprintf( "Parse error at line %d, column %d (%s).", exception.lineNumber(), exception.columnNumber(), exception.message().latin1() ); if ( qApp == 0 ) qWarning( "XML error: %s", msg.latin1() ); else - QMessageBox::information( qApp->mainWidget(), - QObject::tr("Qt Linguist"), msg ); + TQMessageBox::information( qApp->mainWidget(), + TQObject::tr("TQt Linguist"), msg ); } return FALSE; } -static QString numericEntity( int ch ) +static TQString numericEntity( int ch ) { - return QString( ch <= 0x20 ? "<byte value=\"x%1\"/>" : "&#x%1;" ) + return TQString( ch <= 0x20 ? "<byte value=\"x%1\"/>" : "&#x%1;" ) .arg( ch, 0, 16 ); } -static QString protect( const QCString& str ) +static TQString protect( const TQCString& str ) { - QString result; + TQString result; int len = (int) str.length(); for ( int k = 0; k < len; k++ ) { switch( str[k] ) { case '\"': - result += QString( """ ); + result += TQString( """ ); break; case '&': - result += QString( "&" ); + result += TQString( "&" ); break; case '>': - result += QString( ">" ); + result += TQString( ">" ); break; case '<': - result += QString( "<" ); + result += TQString( "<" ); break; case '\'': - result += QString( "'" ); + result += TQString( "'" ); break; default: if ( (uchar) str[k] < 0x20 && str[k] != '\n' ) @@ -220,19 +220,19 @@ static QString protect( const QCString& str ) return result; } -static QString evilBytes( const QCString& str, bool utf8 ) +static TQString evilBytes( const TQCString& str, bool utf8 ) { if ( utf8 ) { return protect( str ); } else { - QString result; - QCString t = protect( str ).latin1(); + TQString result; + TQCString t = protect( str ).latin1(); int len = (int) t.length(); for ( int k = 0; k < len; k++ ) { if ( (uchar) t[k] >= 0x7f ) result += numericEntity( (uchar) t[k] ); else - result += QChar( t[k] ); + result += TQChar( t[k] ); } return result; } @@ -246,9 +246,9 @@ MetaTranslatorMessage::MetaTranslatorMessage() MetaTranslatorMessage::MetaTranslatorMessage( const char *context, const char *sourceText, const char *comment, - const QString& translation, + const TQString& translation, bool utf8, Type type ) - : QTranslatorMessage( context, sourceText, comment, translation ), + : TQTranslatorMessage( context, sourceText, comment, translation ), utfeight( FALSE ), ty( type ) { /* @@ -281,14 +281,14 @@ MetaTranslatorMessage::MetaTranslatorMessage( const char *context, } MetaTranslatorMessage::MetaTranslatorMessage( const MetaTranslatorMessage& m ) - : QTranslatorMessage( m ), utfeight( m.utfeight ), ty( m.ty ) + : TQTranslatorMessage( m ), utfeight( m.utfeight ), ty( m.ty ) { } MetaTranslatorMessage& MetaTranslatorMessage::operator=( const MetaTranslatorMessage& m ) { - QTranslatorMessage::operator=( m ); + TQTranslatorMessage::operator=( m ); utfeight = m.utfeight; ty = m.ty; return *this; @@ -330,23 +330,23 @@ MetaTranslator& MetaTranslator::operator=( const MetaTranslator& tor ) return *this; } -bool MetaTranslator::load( const QString& filename ) +bool MetaTranslator::load( const TQString& filename ) { mm.clear(); - QFile f( filename ); + TQFile f( filename ); if ( !f.open(IO_ReadOnly) ) return FALSE; - QTextStream t( &f ); - QXmlInputSource in( t ); - QXmlSimpleReader reader; + TQTextStream t( &f ); + TQXmlInputSource in( t ); + TQXmlSimpleReader reader; // don't click on these! reader.setFeature( "http://xml.org/sax/features/namespaces", FALSE ); reader.setFeature( "http://xml.org/sax/features/namespace-prefixes", TRUE ); reader.setFeature( "http://trolltech.com/xml/features/report-whitespace" "-only-CharData", FALSE ); - QXmlDefaultHandler *hand = new TsHandler( this ); + TQXmlDefaultHandler *hand = new TsHandler( this ); reader.setContentHandler( hand ); reader.setErrorHandler( hand ); @@ -360,14 +360,14 @@ bool MetaTranslator::load( const QString& filename ) return ok; } -bool MetaTranslator::save( const QString& filename ) const +bool MetaTranslator::save( const TQString& filename ) const { - QFile f( filename ); + TQFile f( filename ); if ( !f.open(IO_WriteOnly) ) return FALSE; - QTextStream t( &f ); - t.setCodec( QTextCodec::codecForName("ISO-8859-1") ); + TQTextStream t( &f ); + t.setCodec( TQTextCodec::codecForName("ISO-8859-1") ); t << "<!DOCTYPE TS><TS>\n"; if ( codecName != "ISO-8859-1" ) @@ -377,19 +377,19 @@ bool MetaTranslator::save( const QString& filename ) const TMMInv inv; TMMInv::Iterator i; bool contextIsUtf8 = m.key().utf8(); - QCString context = m.key().context(); - QCString comment = ""; + TQCString context = m.key().context(); + TQCString comment = ""; do { - if ( QCString(m.key().sourceText()).isEmpty() ) { + if ( TQCString(m.key().sourceText()).isEmpty() ) { if ( m.key().type() != MetaTranslatorMessage::Obsolete ) { contextIsUtf8 = m.key().utf8(); - comment = QCString( m.key().comment() ); + comment = TQCString( m.key().comment() ); } } else { inv.insert( *m, m.key() ); } - } while ( ++m != mm.end() && QCString(m.key().context()) == context ); + } while ( ++m != mm.end() && TQCString(m.key().context()) == context ); t << "<context"; if ( contextIsUtf8 ) @@ -409,7 +409,7 @@ bool MetaTranslator::save( const QString& filename ) const << " <source>" << evilBytes( (*i).sourceText(), (*i).utf8() ) << "</source>\n"; - if ( !QCString((*i).comment()).isEmpty() ) + if ( !TQCString((*i).comment()).isEmpty() ) t << " <comment>" << evilBytes( (*i).comment(), (*i).utf8() ) << "</comment>\n"; @@ -429,9 +429,9 @@ bool MetaTranslator::save( const QString& filename ) const return TRUE; } -bool MetaTranslator::release( const QString& filename, bool verbose ) const +bool MetaTranslator::release( const TQString& filename, bool verbose ) const { - QTranslator tor( 0 ); + TQTranslator tor( 0 ); int finished = 0; int unfinished = 0; int untranslated = 0; @@ -451,7 +451,7 @@ bool MetaTranslator::release( const QString& filename, bool verbose ) const } } - bool saved = tor.save( filename, QTranslator::Stripped ); + bool saved = tor.save( filename, TQTranslator::Stripped ); if ( saved && verbose ) qWarning( " %d finished, %d unfinished and %d untranslated messages", finished, unfinished, untranslated ); @@ -494,7 +494,7 @@ void MetaTranslator::stripEmptyContexts() TMM::Iterator m = mm.begin(); while ( m != mm.end() ) { - if ( QCString(m.key().sourceText()).isEmpty() ) { + if ( TQCString(m.key().sourceText()).isEmpty() ) { TMM::Iterator n = m; ++n; // the context comment is followed by other messages @@ -514,22 +514,22 @@ void MetaTranslator::setCodec( const char *name ) const int latin1 = 4; codecName = name; - codec = QTextCodec::codecForName( name ); + codec = TQTextCodec::codecForName( name ); if ( codec == 0 || codec->mibEnum() == latin1 ) codec = 0; } -QString MetaTranslator::toUnicode( const char *str, bool utf8 ) const +TQString MetaTranslator::toUnicode( const char *str, bool utf8 ) const { if ( utf8 ) - return QString::fromUtf8( str ); + return TQString::fromUtf8( str ); else if ( codec == 0 ) - return QString( str ); + return TQString( str ); else return codec->toUnicode( str ); } -QValueList<MetaTranslatorMessage> MetaTranslator::messages() const +TQValueList<MetaTranslatorMessage> MetaTranslator::messages() const { int n = mm.count(); TMM::ConstIterator *t = new TMM::ConstIterator[n + 1]; @@ -537,7 +537,7 @@ QValueList<MetaTranslatorMessage> MetaTranslator::messages() const for ( m = mm.begin(); m != mm.end(); ++m ) t[*m] = m; - QValueList<MetaTranslatorMessage> val; + TQValueList<MetaTranslatorMessage> val; for ( int i = 0; i < n; i++ ) val.append( t[i].key() ); @@ -545,9 +545,9 @@ QValueList<MetaTranslatorMessage> MetaTranslator::messages() const return val; } -QValueList<MetaTranslatorMessage> MetaTranslator::translatedMessages() const +TQValueList<MetaTranslatorMessage> MetaTranslator::translatedMessages() const { - QValueList<MetaTranslatorMessage> val; + TQValueList<MetaTranslatorMessage> val; TMM::ConstIterator m; for ( m = mm.begin(); m != mm.end(); ++m ) { if ( m.key().type() == MetaTranslatorMessage::Finished ) |