author | Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com> |
Fri, 19 Feb 2010 23:40:16 +0200 | |
branch | RCL_3 |
changeset 4 | 3b1da2848fc7 |
parent 3 | 41300fa6a67c |
permissions | -rw-r--r-- |
0 | 1 |
/**************************************************************************** |
2 |
** |
|
4
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
3 |
** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). |
0 | 4 |
** All rights reserved. |
5 |
** Contact: Nokia Corporation (qt-info@nokia.com) |
|
6 |
** |
|
7 |
** This file is part of the Qt Linguist 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 |
#ifndef TRANSLATORMESSAGE_H |
|
43 |
#define TRANSLATORMESSAGE_H |
|
44 |
||
45 |
#ifndef QT_NO_TRANSLATION |
|
46 |
||
47 |
#include <QString> |
|
48 |
#include <QStringList> |
|
49 |
#include <QHash> |
|
50 |
||
51 |
||
52 |
QT_BEGIN_NAMESPACE |
|
53 |
||
54 |
enum TranslatorSaveMode { SaveEverything, SaveStripped }; |
|
55 |
||
56 |
class TranslatorMessage |
|
57 |
{ |
|
58 |
public: |
|
59 |
enum Type { Unfinished, Finished, Obsolete }; |
|
60 |
typedef QHash<QString, QString> ExtraData; |
|
61 |
class Reference |
|
62 |
{ |
|
63 |
QString m_fileName; |
|
64 |
int m_lineNumber; |
|
65 |
public: |
|
66 |
Reference(const QString &n, int l) : m_fileName(n), m_lineNumber(l) {} |
|
67 |
bool operator==(const Reference &other) const |
|
68 |
{ return fileName() == other.fileName() && lineNumber() == other.lineNumber(); } |
|
69 |
QString fileName() const { return m_fileName; } |
|
70 |
int lineNumber() const { return m_lineNumber; } |
|
71 |
}; |
|
72 |
typedef QList<Reference> References; |
|
73 |
||
74 |
TranslatorMessage(); |
|
75 |
TranslatorMessage(const QString &context, const QString &sourceText, |
|
76 |
const QString &comment, const QString &userData, |
|
77 |
const QString &fileName, int lineNumber, |
|
78 |
const QStringList &translations = QStringList(), |
|
79 |
Type type = Unfinished, bool plural = false); |
|
80 |
||
81 |
uint hash() const; |
|
82 |
||
83 |
QString id() const { return m_id; } |
|
84 |
void setId(const QString &id) { m_id = id; } |
|
85 |
||
86 |
QString context() const { return m_context; } |
|
87 |
void setContext(const QString &context) { m_context = context; } |
|
88 |
||
89 |
QString sourceText() const { return m_sourcetext; } |
|
90 |
void setSourceText(const QString &sourcetext) { m_sourcetext = sourcetext; } |
|
91 |
QString oldSourceText() const { return m_oldsourcetext; } |
|
92 |
void setOldSourceText(const QString &oldsourcetext) { m_oldsourcetext = oldsourcetext; } |
|
93 |
||
94 |
QString comment() const { return m_comment; } |
|
95 |
void setComment(const QString &comment) { m_comment = comment; } |
|
96 |
QString oldComment() const { return m_oldcomment; } |
|
97 |
void setOldComment(const QString &oldcomment) { m_oldcomment = oldcomment; } |
|
98 |
||
99 |
QStringList translations() const { return m_translations; } |
|
100 |
void setTranslations(const QStringList &translations) { m_translations = translations; } |
|
101 |
QString translation() const { return m_translations.value(0); } |
|
102 |
void setTranslation(const QString &translation) { m_translations = QStringList(translation); } |
|
103 |
void appendTranslation(const QString &translation) { m_translations.append(translation); } |
|
104 |
bool isTranslated() const |
|
105 |
{ |
|
106 |
foreach (const QString &trans, m_translations) |
|
107 |
if (!trans.isEmpty()) |
|
108 |
return true; |
|
109 |
return false; |
|
110 |
} |
|
111 |
||
112 |
QString fileName() const { return m_fileName; } |
|
113 |
void setFileName(const QString &fileName) { m_fileName = fileName; } |
|
114 |
int lineNumber() const { return m_lineNumber; } |
|
115 |
void setLineNumber(int lineNumber) { m_lineNumber = lineNumber; } |
|
116 |
void clearReferences(); |
|
117 |
void setReferences(const References &refs); |
|
118 |
void addReference(const QString &fileName, int lineNumber); |
|
119 |
void addReference(const Reference &ref) { addReference(ref.fileName(), ref.lineNumber()); } |
|
120 |
void addReferenceUniq(const QString &fileName, int lineNumber); |
|
121 |
References extraReferences() const { return m_extraRefs; } |
|
122 |
References allReferences() const; |
|
123 |
QString userData() const { return m_userData; } |
|
124 |
void setUserData(const QString &userData) { m_userData = userData; } |
|
125 |
QString extraComment() const { return m_extraComment; } |
|
126 |
void setExtraComment(const QString &extraComment) { m_extraComment = extraComment; } |
|
127 |
QString translatorComment() const { return m_translatorComment; } |
|
128 |
void setTranslatorComment(const QString &translatorComment) { m_translatorComment = translatorComment; } |
|
129 |
||
130 |
bool isNull() const { return m_sourcetext.isNull() && m_lineNumber == -1 && m_translations.isEmpty(); } |
|
131 |
||
132 |
Type type() const { return m_type; } |
|
133 |
void setType(Type t) { m_type = t; } |
|
134 |
bool isUtf8() const { return m_utf8; } // codecForTr override |
|
135 |
void setUtf8(bool on) { m_utf8 = on; } |
|
136 |
bool isNonUtf8() const { return m_nonUtf8; } // codecForTr override |
|
137 |
void setNonUtf8(bool on) { m_nonUtf8 = on; } |
|
138 |
bool isPlural() const { return m_plural; } |
|
139 |
void setPlural(bool isplural) { m_plural = isplural; } |
|
140 |
||
141 |
// note: use '<fileformat>:' as prefix for file format specific members, |
|
142 |
// e.g. "po-msgid_plural" |
|
143 |
QString extra(const QString &ba) const; |
|
144 |
void setExtra(const QString &ba, const QString &var); |
|
145 |
bool hasExtra(const QString &ba) const; |
|
146 |
const ExtraData &extras() const { return m_extra; } |
|
147 |
void setExtras(const ExtraData &extras) { m_extra = extras; } |
|
148 |
void unsetExtra(const QString &key); |
|
149 |
||
150 |
bool needs8Bit() const; |
|
151 |
void dump() const; |
|
152 |
||
153 |
private: |
|
154 |
QString m_id; |
|
155 |
QString m_context; |
|
156 |
QString m_sourcetext; |
|
157 |
QString m_oldsourcetext; |
|
158 |
QString m_comment; |
|
159 |
QString m_oldcomment; |
|
160 |
QString m_userData; |
|
161 |
ExtraData m_extra; // PO flags, PO plurals |
|
162 |
QString m_extraComment; |
|
163 |
QString m_translatorComment; |
|
164 |
QStringList m_translations; |
|
165 |
QString m_fileName; |
|
166 |
int m_lineNumber; |
|
167 |
References m_extraRefs; |
|
168 |
||
169 |
Type m_type; |
|
170 |
bool m_utf8; |
|
171 |
bool m_nonUtf8; |
|
172 |
bool m_plural; |
|
173 |
}; |
|
174 |
||
175 |
Q_DECLARE_TYPEINFO(TranslatorMessage, Q_MOVABLE_TYPE); |
|
176 |
||
177 |
QT_END_NAMESPACE |
|
178 |
||
179 |
#endif // QT_NO_TRANSLATION |
|
180 |
||
181 |
#endif // TRANSLATORMESSAGE_H |