libqutim
0.3.1.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 STATUS_H 00027 #define STATUS_H 00028 00029 #include "localizedstring.h" 00030 #include <QSharedData> 00031 #include <QVariant> 00032 #include <QIcon> 00033 #include <QEvent> 00034 00035 namespace qutim_sdk_0_3 00036 { 00037 class StatusPrivate; 00038 class ExtendedStatusesEventPrivate; 00039 00040 class LIBQUTIM_EXPORT Status 00041 { 00042 public: 00043 enum Type 00044 { 00045 Connecting = -1, 00046 Online = 0, 00047 FreeChat, 00048 Away, 00049 NA, 00050 DND, 00051 Invisible, 00052 Offline 00053 }; 00054 00055 enum ChangeReason 00056 { 00057 ByUser, 00058 ByIdle, 00059 ByAuthorizationFailed, 00060 ByNetworkError, 00061 ByFatalError 00062 }; 00063 00064 // TODO: Remove defines, and optimize code, currently I just want plugins to compile 00065 #if 0 00066 explicit 00067 #endif 00068 Status(Type type = Offline); 00069 Status(const Status &other); 00070 Status &operator =(const Status &other); 00071 Status &operator =(Type type); 00072 virtual ~Status(); 00073 00074 bool operator ==(Type type) const; 00075 inline bool operator !=(Type type) const { return !operator ==(type); } 00076 00077 QString text() const; 00078 void setText(const QString &text); 00079 LocalizedString name() const; 00080 void setName(const LocalizedString &name); 00081 QIcon icon() const; 00082 void setIcon(const QIcon &icon); 00083 Type type() const; 00084 void setType(Type type); 00085 int subtype() const; 00086 void setSubtype(int stype); 00087 template <typename T> T subtype() const { return static_cast<T>(subtype()); } 00088 template <typename T> void setSubtype(T stype) { setSubtype(static_cast<int>(stype)); } 00089 ChangeReason changeReason() const; 00090 void setChangeReason(ChangeReason reason); 00091 00092 QVariant property(const char *name, const QVariant &def) const; 00093 template<typename T> 00094 T property(const char *name, const T &def) const 00095 { return qVariantValue<T>(property(name, qVariantFromValue<T>(def))); } 00096 void setProperty(const char *name, const QVariant &value); 00097 00098 void initIcon(const QString &protocol = QString()); 00099 static QIcon createIcon(Type type, const QString &protocol = QString()); 00100 static QString iconName(Type type, const QString &protocol = QString()); 00101 static Status instance(Type type, const char *proto, int subtype = 0); 00102 static bool remember(const Status &status, const char *proto); 00103 static Status createConnecting(const Status &status, const char *proto); 00104 static Status connectingGoal(const Status &status); 00105 Status connectingGoal() const; 00106 void setExtendedInfo(const QString &name, const QVariantHash &status); 00107 void removeExtendedInfo(const QString &name); 00108 QVariantHash extendedInfo(const QString &name) const; 00109 QHash<QString, QVariantHash> extendedInfos() const; 00110 void setExtendedInfos(const QHash<QString, QVariantHash> &extInfos); 00111 private: 00112 QSharedDataPointer<StatusPrivate> d; 00113 }; 00114 00119 class LIBQUTIM_EXPORT ExtendedInfosEvent : public QEvent 00120 { 00121 public: 00122 ExtendedInfosEvent(); 00123 ~ExtendedInfosEvent(); 00124 void addInfo(const QString &name, const QVariantHash &info); 00125 QHash<QString, QVariantHash> infos(); 00126 static QEvent::Type eventType(); 00127 private: 00128 QScopedPointer<ExtendedStatusesEventPrivate> d; 00129 }; 00130 00131 } 00132 00133 class QDebug; 00134 LIBQUTIM_EXPORT QDebug operator<<(QDebug debug, qutim_sdk_0_3::Status::Type status); 00135 LIBQUTIM_EXPORT QDebug operator<<(QDebug debug, const qutim_sdk_0_3::Status &status); 00136 LIBQUTIM_EXPORT QDataStream &operator<<(QDataStream &out, const qutim_sdk_0_3::Status &status); 00137 LIBQUTIM_EXPORT QDataStream &operator>>(QDataStream &in, qutim_sdk_0_3::Status &status); 00138 00139 Q_ENUMS(qutim_sdk_0_3::Status::Type) 00140 Q_ENUMS(qutim_sdk_0_3::Status::ChangeReason) 00141 Q_DECLARE_METATYPE(qutim_sdk_0_3::Status) 00142 Q_DECLARE_METATYPE(qutim_sdk_0_3::Status::ChangeReason) 00143 00144 #endif // STATUS_H 00145