libqutim  0.3.1.0
localizedstring.h
Go to the documentation of this file.
1 /****************************************************************************
2 **
3 ** qutIM - instant messenger
4 **
5 ** Copyright © 2011 Ruslan Nigmatullin <euroelessar@yandex.ru>
6 **
7 *****************************************************************************
8 **
9 ** $QUTIM_BEGIN_LICENSE$
10 ** This program is free software: you can redistribute it and/or modify
11 ** it under the terms of the GNU General Public License as published by
12 ** the Free Software Foundation, either version 3 of the License, or
13 ** (at your option) any later version.
14 **
15 ** This program is distributed in the hope that it will be useful,
16 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
17 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
18 ** See the GNU General Public License for more details.
19 **
20 ** You should have received a copy of the GNU General Public License
21 ** along with this program. If not, see http://www.gnu.org/licenses/.
22 ** $QUTIM_END_LICENSE$
23 **
24 ****************************************************************************/
25 
26 #ifndef LOCALIZEDSTRING_H
27 #define LOCALIZEDSTRING_H
28 
29 #include "libqutim_global.h"
30 #include <QMetaType>
31 
32 #ifndef NO_AUTOLOCALIZATION
33 # undef QT_TR_NOOP
34 # undef QT_TR_NOOP_UTF8
35 # undef QT_TRANSLATE_NOOP
36 # undef QT_TRANSLATE_NOOP_UTF8
37 # undef QT_TRANSLATE_NOOP3
38 # undef QT_TRANSLATE_NOOP3_UTF8
39 # define QT_TR_NOOP(x) qutim_sdk_0_3::LocalizedString(staticMetaObject.className(), x)
40 # define QT_TR_NOOP_UTF8(x) qutim_sdk_0_3::LocalizedString(staticMetaObject.className(), x)
41 # define QT_TRANSLATE_NOOP(scope, x) qutim_sdk_0_3::LocalizedString(scope, x)
42 # define QT_TRANSLATE_NOOP_UTF8(scope, x) qutim_sdk_0_3::LocalizedString(scope, x)
43 # define QT_TRANSLATE_NOOP3(scope,x,comment) qutim_sdk_0_3::LocalizedString(scope, x)
44 # define QT_TRANSLATE_NOOP3_UTF8(scope,x,comment) qutim_sdk_0_3::LocalizedString(scope, x)
45 #endif // NO_AUTOLOCALIZATION
46 
47 namespace qutim_sdk_0_3
48 {
50  {
51  public:
53  LocalizedString(const char *str) : m_str(str) {}
54  LocalizedString(const QByteArray &str) : m_str(str) {}
55  LocalizedString(const QString &str) : m_str(str.toUtf8()) {}
56  LocalizedString(const char *cxt, const QByteArray &str) : m_ctx(cxt), m_str(str) {}
57  LocalizedString(const char *cxt, const char *str, int len) : m_ctx(cxt), m_str(str, len) {}
58  LocalizedString(const char *cxt, const char *str) : m_ctx(cxt), m_str(str, qstrlen(str)) {}
59  LocalizedString(const LocalizedString &other) : m_ctx(other.m_ctx), m_str(other.m_str) {}
60  LocalizedString &operator =(const char *str) { m_str = str; return *this; }
61  operator QString() const { return toString(); }
62  QString toString() const;
63  void setOriginal(const QByteArray &str) { m_str = str; }
64  QByteArray original() const { return m_str; }
65  void setContext(const QByteArray &ctx) { m_ctx = ctx; }
66  QByteArray context() const { return m_ctx; }
67  bool isNull() const { return m_str.isNull(); }
68 
69  inline bool operator==(const LocalizedString &s) const { return m_str == s.m_str; }
70  inline bool operator <(const LocalizedString &s) const { return m_str < s.m_str; }
71  inline bool operator >(const LocalizedString &s) const { return s < *this; }
72  inline bool operator!=(const LocalizedString &s) const { return !operator==(s); }
73  inline bool operator<=(const LocalizedString &s) const { return !operator>(s); }
74  inline bool operator>=(const LocalizedString &s) const { return !operator<(s); }
75  private:
76  friend QDataStream &operator<<(QDataStream &out, const LocalizedString &str);
77  friend QDataStream &operator>>(QDataStream &in, LocalizedString &str);
78  QByteArray m_ctx;
79  QByteArray m_str;
80  };
81 
82  typedef QList<LocalizedString> LocalizedStringList;
83 }
84 
87 
88 #endif // LOCALIZEDSTRING_H
89 

Generated by Doxygen