1 /**************************************************************************** 2 ** $Id: qt/qtranslator.h 3.3.8 edited Jan 11 14:46 $ 3 ** 4 ** Definition of the translator class 5 ** 6 ** Created : 980906 7 ** 8 ** Copyright (C) 1998-2007 Trolltech ASA. All rights reserved. 9 ** 10 ** This file is part of the kernel module of the Qt GUI Toolkit. 11 ** 12 ** This file may be distributed under the terms of the Q Public License 13 ** as defined by Trolltech ASA of Norway and appearing in the file 14 ** LICENSE.QPL included in the packaging of this file. 15 ** 16 ** This file may be distributed and/or modified under the terms of the 17 ** GNU General Public License version 2 as published by the Free Software 18 ** Foundation and appearing in the file LICENSE.GPL included in the 19 ** packaging of this file. 20 ** 21 ** Licensees holding valid Qt Enterprise Edition or Qt Professional Edition 22 ** licenses may use this file in accordance with the Qt Commercial License 23 ** Agreement provided with the Software. 24 ** 25 ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE 26 ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 27 ** 28 ** See http://www.trolltech.com/pricing.html or email sales@trolltech.com for 29 ** information about Qt Commercial License Agreements. 30 ** See http://www.trolltech.com/qpl/ for QPL licensing information. 31 ** See http://www.trolltech.com/gpl/ for GPL licensing information. 32 ** 33 ** Contact info@trolltech.com if any conditions of this licensing are 34 ** not clear to you. 35 ** 36 **********************************************************************/ 37 38 39 #ifndef QTRANSLATOR_H 40 #define QTRANSLATOR_H 41 42 #ifndef QT_H 43 #include "qobject.h" 44 #include "qvaluelist.h" 45 #endif // QT_H 46 47 #ifndef QT_NO_TRANSLATION 48 49 class QTranslatorPrivate; 50 51 class Q_EXPORT QTranslatorMessage 52 { 53 public: 54 QTranslatorMessage(); 55 QTranslatorMessage( const char * context, 56 const char * sourceText, 57 const char * comment, 58 const QString& translation = QString::null ); 59 QTranslatorMessage( QDataStream & ); 60 QTranslatorMessage( const QTranslatorMessage & m ); 61 62 QTranslatorMessage & operator=( const QTranslatorMessage & m ); 63 hash()64 uint hash() const { return h; } context()65 const char *context() const { return cx; } sourceText()66 const char *sourceText() const { return st; } comment()67 const char *comment() const { return cm; } 68 setTranslation(const QString & translation)69 void setTranslation( const QString & translation ) { tn = translation; } translation()70 QString translation() const { return tn; } 71 72 enum Prefix { NoPrefix, Hash, HashContext, HashContextSourceText, 73 HashContextSourceTextComment }; 74 void write( QDataStream & s, bool strip = FALSE, 75 Prefix prefix = HashContextSourceTextComment ) const; 76 Prefix commonPrefix( const QTranslatorMessage& ) const; 77 78 bool operator==( const QTranslatorMessage& m ) const; 79 bool operator!=( const QTranslatorMessage& m ) const 80 { return !operator==( m ); } 81 bool operator<( const QTranslatorMessage& m ) const; 82 bool operator<=( const QTranslatorMessage& m ) const 83 { return !m.operator<( *this ); } 84 bool operator>( const QTranslatorMessage& m ) const 85 { return m.operator<( *this ); } 86 bool operator>=( const QTranslatorMessage& m ) const 87 { return !operator<( m ); } 88 89 private: 90 uint h; 91 QCString cx; 92 QCString st; 93 QCString cm; 94 QString tn; 95 96 enum Tag { Tag_End = 1, Tag_SourceText16, Tag_Translation, Tag_Context16, 97 Tag_Hash, Tag_SourceText, Tag_Context, Tag_Comment, 98 Tag_Obsolete1 }; 99 }; 100 101 102 class Q_EXPORT QTranslator: public QObject 103 { 104 Q_OBJECT 105 public: 106 QTranslator( QObject * parent = 0, const char * name = 0 ); 107 ~QTranslator(); 108 109 #ifndef QT_NO_COMPAT 110 QString find( const char *context, const char *sourceText, const char * comment = 0 ) const { 111 return findMessage( context, sourceText, comment ).translation(); 112 } 113 #endif 114 virtual QTranslatorMessage findMessage( const char *, const char *, 115 const char * = 0 ) const; 116 117 bool load( const QString & filename, 118 const QString & directory = QString::null, 119 const QString & search_delimiters = QString::null, 120 const QString & suffix = QString::null ); load(const uchar * data,int len)121 bool load( const uchar *data, int len ) { 122 clear(); 123 return do_load( data, len ); 124 } 125 126 void clear(); 127 128 #ifndef QT_NO_TRANSLATION_BUILDER 129 enum SaveMode { Everything, Stripped }; 130 131 bool save( const QString & filename, SaveMode mode = Everything ); 132 133 void insert( const QTranslatorMessage& ); insert(const char * context,const char * sourceText,const QString & translation)134 void insert( const char *context, const char *sourceText, const QString &translation ) { 135 insert( QTranslatorMessage(context, sourceText, "", translation) ); 136 } 137 void remove( const QTranslatorMessage& ); remove(const char * context,const char * sourceText)138 void remove( const char *context, const char *sourceText ) { 139 remove( QTranslatorMessage(context, sourceText, "") ); 140 } 141 bool contains( const char *, const char *, const char * comment = 0 ) const; 142 143 void squeeze( SaveMode = Everything ); 144 void unsqueeze(); 145 146 QValueList<QTranslatorMessage> messages() const; 147 #endif 148 149 bool isEmpty() const; 150 151 private: 152 #if defined(Q_DISABLE_COPY) 153 QTranslator( const QTranslator & ); 154 QTranslator &operator=( const QTranslator & ); 155 #endif 156 157 bool do_load( const uchar *data, int len ); 158 159 QTranslatorPrivate * d; 160 }; 161 162 #endif // QT_NO_TRANSLATION 163 164 #endif 165