libqutim 0.2.80.1

status.h

Go to the documentation of this file.
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 
00090     QVariant property(const char *name, const QVariant &def) const;
00091     template<typename T>
00092     T property(const char *name, const T &def) const
00093     { return qVariantValue<T>(property(name, qVariantFromValue<T>(def))); }
00094     void setProperty(const char *name, const QVariant &value);
00095 
00096     void initIcon(const QString &protocol = QString());
00097     static QIcon createIcon(Type type, const QString &protocol = QString());
00098     static QString iconName(Type type, const QString &protocol = QString());
00099     static Status instance(Type type, const char *proto, int subtype = 0);
00100     static bool remember(const Status &status, const char *proto);
00101     void setExtendedInfo(const QString &name, const QVariantHash &status);
00102     void removeExtendedInfo(const QString &name);
00103     QVariantHash extendedInfo(const QString &name) const;
00104     QHash<QString, QVariantHash> extendedInfos() const;
00105     void setExtendedInfos(const QHash<QString, QVariantHash> &extInfos);
00106 private:
00107     QSharedDataPointer<StatusPrivate> d;
00108 };
00109 
00114 class LIBQUTIM_EXPORT ExtendedInfosEvent : public QEvent
00115 {
00116 public:
00117     ExtendedInfosEvent();
00118     ~ExtendedInfosEvent();
00119     void addInfo(const QString &name, const QVariantHash &info);
00120     QHash<QString, QVariantHash> infos();
00121     static QEvent::Type eventType();
00122 private:
00123     QScopedPointer<ExtendedStatusesEventPrivate> d;
00124 };
00125 
00126 }
00127 
00128 class QDebug;
00129 LIBQUTIM_EXPORT QDebug operator<<(QDebug debug, qutim_sdk_0_3::Status::Type status);
00130 LIBQUTIM_EXPORT QDebug operator<<(QDebug debug, const qutim_sdk_0_3::Status &status);
00131 LIBQUTIM_EXPORT QDataStream &operator<<(QDataStream &out, const qutim_sdk_0_3::Status &status);
00132 LIBQUTIM_EXPORT QDataStream &operator>>(QDataStream &in, qutim_sdk_0_3::Status &status);
00133 
00134 Q_ENUMS(qutim_sdk_0_3::Status::Type)
00135 Q_ENUMS(qutim_sdk_0_3::Status::ChangeReason)
00136 Q_DECLARE_METATYPE(qutim_sdk_0_3::Status)
00137 Q_DECLARE_METATYPE(qutim_sdk_0_3::Status::ChangeReason)
00138 
00139 #endif // STATUS_H
00140