libqutim  0.3.2.0
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     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     void setProperty(const char *name, const QVariant &value);
00096 
00097     void initIcon(const QString &protocol = QString());
00098     static QIcon createIcon(Type type, const QString &protocol = QString());
00099     static QString iconName(Type type, const QString &protocol = QString());
00100     static Status instance(Type type, const char *proto, int subtype = 0);
00101     static bool remember(const Status &status, const char *proto);
00102     static Status createConnecting(const Status &status, const char *proto);
00103     static Status connectingGoal(const Status &status);
00104     Status connectingGoal() const;
00105     void setExtendedInfo(const QString &name, const QVariantHash &status);
00106     void removeExtendedInfo(const QString &name);
00107     QVariantHash extendedInfo(const QString &name) const;
00108     QHash<QString, QVariantHash> extendedInfos() const;
00109     void setExtendedInfos(const QHash<QString, QVariantHash> &extInfos);
00110 private:
00111     QSharedDataPointer<StatusPrivate> d;
00112 };
00113 
00114 template<typename T>
00115 T Status::property(const char *name, const T &def) const
00116 {
00117     QVariant var = property(name, QVariant::fromValue<T>(def));
00118     return var.value<T>();
00119 }
00120 
00125 class LIBQUTIM_EXPORT ExtendedInfosEvent : public QEvent
00126 {
00127 public:
00128     ExtendedInfosEvent();
00129     ~ExtendedInfosEvent();
00130     void addInfo(const QString &name, const QVariantHash &info);
00131     QHash<QString, QVariantHash> infos();
00132     static QEvent::Type eventType();
00133 private:
00134     QScopedPointer<ExtendedStatusesEventPrivate> d;
00135 };
00136 
00137 }
00138 
00139 class QDebug;
00140 LIBQUTIM_EXPORT QDebug operator<<(QDebug debug, qutim_sdk_0_3::Status::Type status);
00141 LIBQUTIM_EXPORT QDebug operator<<(QDebug debug, const qutim_sdk_0_3::Status &status);
00142 LIBQUTIM_EXPORT QDataStream &operator<<(QDataStream &out, const qutim_sdk_0_3::Status &status);
00143 LIBQUTIM_EXPORT QDataStream &operator>>(QDataStream &in, qutim_sdk_0_3::Status &status);
00144 
00145 Q_ENUMS(qutim_sdk_0_3::Status::Type)
00146 Q_ENUMS(qutim_sdk_0_3::Status::ChangeReason)
00147 Q_DECLARE_METATYPE(qutim_sdk_0_3::Status)
00148 Q_DECLARE_METATYPE(qutim_sdk_0_3::Status::ChangeReason)
00149 
00150 #endif // STATUS_H
00151