libqutim
0.3.2.0
|
00001 /**************************************************************************** 00002 ** 00003 ** qutIM - instant messenger 00004 ** 00005 ** Copyright © 2011 Ruslan Nigmatullin <euroelessar@yandex.ru> 00006 ** 00007 ***************************************************************************** 00008 ** 00009 ** $QUTIM_BEGIN_LICENSE$ 00010 ** This program is free software: you can redistribute it and/or modify 00011 ** it under the terms of the GNU General Public License as published by 00012 ** the Free Software Foundation, either version 3 of the License, or 00013 ** (at your option) any later version. 00014 ** 00015 ** This program is distributed in the hope that it will be useful, 00016 ** but WITHOUT ANY WARRANTY; without even the implied warranty of 00017 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 00018 ** See the GNU General Public License for more details. 00019 ** 00020 ** You should have received a copy of the GNU General Public License 00021 ** along with this program. If not, see http://www.gnu.org/licenses/. 00022 ** $QUTIM_END_LICENSE$ 00023 ** 00024 ****************************************************************************/ 00025 00026 #ifndef LOCALIZEDSTRING_H 00027 #define LOCALIZEDSTRING_H 00028 00029 #include "libqutim_global.h" 00030 #include <QMetaType> 00031 00032 #ifndef NO_AUTOLOCALIZATION 00033 # undef QT_TR_NOOP 00034 # undef QT_TR_NOOP_UTF8 00035 # undef QT_TRANSLATE_NOOP 00036 # undef QT_TRANSLATE_NOOP_UTF8 00037 # undef QT_TRANSLATE_NOOP3 00038 # undef QT_TRANSLATE_NOOP3_UTF8 00039 # define QT_TR_NOOP(x) qutim_sdk_0_3::LocalizedString(staticMetaObject.className(), x) 00040 # define QT_TR_NOOP_UTF8(x) qutim_sdk_0_3::LocalizedString(staticMetaObject.className(), x) 00041 # define QT_TRANSLATE_NOOP(scope, x) qutim_sdk_0_3::LocalizedString(scope, x) 00042 # define QT_TRANSLATE_NOOP_UTF8(scope, x) qutim_sdk_0_3::LocalizedString(scope, x) 00043 # define QT_TRANSLATE_NOOP3(scope,x,comment) qutim_sdk_0_3::LocalizedString(scope, x) 00044 # define QT_TRANSLATE_NOOP3_UTF8(scope,x,comment) qutim_sdk_0_3::LocalizedString(scope, x) 00045 #endif // NO_AUTOLOCALIZATION 00046 00047 namespace qutim_sdk_0_3 00048 { 00049 class LIBQUTIM_EXPORT LocalizedString 00050 { 00051 public: 00052 LocalizedString() {} 00053 LocalizedString(const char *str) : m_str(str) {} 00054 LocalizedString(const QByteArray &str) : m_str(str) {} 00055 LocalizedString(const QString &str) : m_str(str.toUtf8()) {} 00056 LocalizedString(const char *cxt, const QByteArray &str) : m_ctx(cxt), m_str(str) {} 00057 LocalizedString(const char *cxt, const char *str, int len) : m_ctx(cxt), m_str(str, len) {} 00058 LocalizedString(const char *cxt, const char *str) : m_ctx(cxt), m_str(str, qstrlen(str)) {} 00059 LocalizedString(const LocalizedString &other) : m_ctx(other.m_ctx), m_str(other.m_str) {} 00060 LocalizedString &operator =(const char *str) { m_str = str; return *this; } 00061 operator QString() const { return toString(); } 00062 QString toString() const; 00063 void setOriginal(const QByteArray &str) { m_str = str; } 00064 QByteArray original() const { return m_str; } 00065 void setContext(const QByteArray &ctx) { m_ctx = ctx; } 00066 QByteArray context() const { return m_ctx; } 00067 bool isNull() const { return m_str.isNull(); } 00068 00069 inline bool operator==(const LocalizedString &s) const { return m_str == s.m_str; } 00070 inline bool operator <(const LocalizedString &s) const { return m_str < s.m_str; } 00071 inline bool operator >(const LocalizedString &s) const { return s < *this; } 00072 inline bool operator!=(const LocalizedString &s) const { return !operator==(s); } 00073 inline bool operator<=(const LocalizedString &s) const { return !operator>(s); } 00074 inline bool operator>=(const LocalizedString &s) const { return !operator<(s); } 00075 private: 00076 friend QDataStream &operator<<(QDataStream &out, const LocalizedString &str); 00077 friend QDataStream &operator>>(QDataStream &in, LocalizedString &str); 00078 QByteArray m_ctx; 00079 QByteArray m_str; 00080 }; 00081 00082 typedef QList<LocalizedString> LocalizedStringList; 00083 } 00084 00085 Q_DECLARE_METATYPE(qutim_sdk_0_3::LocalizedStringList); 00086 Q_DECLARE_METATYPE(qutim_sdk_0_3::LocalizedString); 00087 00088 #endif // LOCALIZEDSTRING_H 00089