source: branches/vendor/trolltech/qt/current/tools/linguist/shared/translatormessage.h @ 2

Last change on this file since 2 was 2, checked in by Dmitry A. Kuminov, 13 years ago

Initially imported qt-all-opensource-src-4.5.1 from Trolltech.

File size: 7.7 KB
Line 
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 Qt Linguist 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#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
52QT_BEGIN_NAMESPACE
53
54enum TranslatorSaveMode { SaveEverything, SaveStripped };
55
56class TranslatorMessage
57{
58public:
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    bool operator==(const TranslatorMessage& m) const;
113    bool operator<(const TranslatorMessage& m) const;
114
115    QString fileName() const { return m_fileName; }
116    void setFileName(const QString &fileName) { m_fileName = fileName; }
117    int lineNumber() const { return m_lineNumber; }
118    void setLineNumber(int lineNumber) { m_lineNumber = lineNumber; }
119    void clearReferences();
120    void setReferences(const References &refs);
121    void addReference(const QString &fileName, int lineNumber);
122    void addReference(const Reference &ref) { addReference(ref.fileName(), ref.lineNumber()); }
123    void addReferenceUniq(const QString &fileName, int lineNumber);
124    References extraReferences() const { return m_extraRefs; }
125    References allReferences() const;
126    QString userData() const { return m_userData; }
127    void setUserData(const QString &userData) { m_userData = userData; }
128    QString extraComment() const { return m_extraComment; }
129    void setExtraComment(const QString &extraComment) { m_extraComment = extraComment; }
130    QString translatorComment() const { return m_translatorComment; }
131    void setTranslatorComment(const QString &translatorComment) { m_translatorComment = translatorComment; }
132
133    bool isNull() const { return m_sourcetext.isNull() && m_lineNumber == -1 && m_translations.isEmpty(); }
134
135    Type type() const { return m_type; }
136    void setType(Type t) { m_type = t; }
137    bool isUtf8() const { return m_utf8; } // codecForTr override
138    void setUtf8(bool on) { m_utf8 = on; }
139    bool isNonUtf8() const { return m_nonUtf8; } // codecForTr override
140    void setNonUtf8(bool on) { m_nonUtf8 = on; }
141    bool isPlural() const { return m_plural; }
142    void setPlural(bool isplural) { m_plural = isplural; }
143
144    // note: use '<fileformat>:' as prefix for file format specific members,
145    // e.g. "po-msgid_plural"
146    QString extra(const QString &ba) const;
147    void setExtra(const QString &ba, const QString &var);
148    bool hasExtra(const QString &ba) const;
149    const ExtraData &extras() const { return m_extra; }
150    void setExtras(const ExtraData &extras) { m_extra = extras; }
151    void unsetExtra(const QString &key);
152
153    bool needs8Bit() const;
154    void dump() const;
155
156private:
157    QString     m_id;
158    QString     m_context;
159    QString     m_sourcetext;
160    QString     m_oldsourcetext;
161    QString     m_comment;
162    QString     m_oldcomment;
163    QString     m_userData;
164    ExtraData   m_extra; // PO flags, PO plurals
165    QString     m_extraComment;
166    QString     m_translatorComment;
167    QStringList m_translations;
168    QString     m_fileName;
169    int         m_lineNumber;
170    References  m_extraRefs;
171
172    Type m_type;
173    bool m_utf8;
174    bool m_nonUtf8;
175    bool m_plural;
176};
177
178Q_DECLARE_TYPEINFO(TranslatorMessage, Q_MOVABLE_TYPE);
179
180int qHash(const TranslatorMessage &msg);
181
182struct TranslatorMessagePtr {
183    TranslatorMessagePtr(const TranslatorMessage &tm)
184    {
185        ptr = &tm;
186    }
187
188    inline const TranslatorMessage *operator->() const
189    {
190        return ptr;
191    }
192
193    const TranslatorMessage *ptr;
194};
195
196Q_DECLARE_TYPEINFO(TranslatorMessagePtr, Q_MOVABLE_TYPE);
197
198inline int qHash(TranslatorMessagePtr tmp)
199{
200    return qHash(*tmp.ptr);
201}
202
203inline bool operator==(TranslatorMessagePtr tmp1, TranslatorMessagePtr tmp2)
204{
205    return *tmp1.ptr == *tmp2.ptr;
206}
207
208QT_END_NAMESPACE
209
210#endif // QT_NO_TRANSLATION
211
212#endif // TRANSLATORMESSAGE_H
Note: See TracBrowser for help on using the repository browser.