libqutim  0.3.1.0
status.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 STATUS_H
27 #define STATUS_H
28 
29 #include "localizedstring.h"
30 #include <QSharedData>
31 #include <QVariant>
32 #include <QIcon>
33 #include <QEvent>
34 
35 namespace qutim_sdk_0_3
36 {
37 class StatusPrivate;
38 class ExtendedStatusesEventPrivate;
39 
41 {
42 public:
43  enum Type
44  {
45  Connecting = -1,
46  Online = 0,
49  NA,
50  DND,
52  Offline
53  };
54 
56  {
61  ByFatalError
62  };
63 
64  // TODO: Remove defines, and optimize code, currently I just want plugins to compile
65 #if 0
66  explicit
67 #endif
68  Status(Type type = Offline);
69  Status(const Status &other);
70  Status &operator =(const Status &other);
71  Status &operator =(Type type);
72  virtual ~Status();
73 
74  bool operator ==(Type type) const;
75  inline bool operator !=(Type type) const { return !operator ==(type); }
76 
77  QString text() const;
78  void setText(const QString &text);
79  LocalizedString name() const;
80  void setName(const LocalizedString &name);
81  QIcon icon() const;
82  void setIcon(const QIcon &icon);
83  Type type() const;
84  void setType(Type type);
85  int subtype() const;
86  void setSubtype(int stype);
87  template <typename T> T subtype() const { return static_cast<T>(subtype()); }
88  template <typename T> void setSubtype(T stype) { setSubtype(static_cast<int>(stype)); }
89  ChangeReason changeReason() const;
90  void setChangeReason(ChangeReason reason);
91 
92  QVariant property(const char *name, const QVariant &def) const;
93  template<typename T>
94  T property(const char *name, const T &def) const
95  { return qVariantValue<T>(property(name, qVariantFromValue<T>(def))); }
96  void setProperty(const char *name, const QVariant &value);
97 
98  void initIcon(const QString &protocol = QString());
99  static QIcon createIcon(Type type, const QString &protocol = QString());
100  static QString iconName(Type type, const QString &protocol = QString());
101  static Status instance(Type type, const char *proto, int subtype = 0);
102  static bool remember(const Status &status, const char *proto);
103  static Status createConnecting(const Status &status, const char *proto);
104  static Status connectingGoal(const Status &status);
105  Status connectingGoal() const;
106  void setExtendedInfo(const QString &name, const QVariantHash &status);
107  void removeExtendedInfo(const QString &name);
108  QVariantHash extendedInfo(const QString &name) const;
109  QHash<QString, QVariantHash> extendedInfos() const;
110  void setExtendedInfos(const QHash<QString, QVariantHash> &extInfos);
111 private:
112  QSharedDataPointer<StatusPrivate> d;
113 };
114 
119 class LIBQUTIM_EXPORT ExtendedInfosEvent : public QEvent
120 {
121 public:
124  void addInfo(const QString &name, const QVariantHash &info);
125  QHash<QString, QVariantHash> infos();
126  static QEvent::Type eventType();
127 private:
128  QScopedPointer<ExtendedStatusesEventPrivate> d;
129 };
130 
131 }
132 
133 class QDebug;
135 LIBQUTIM_EXPORT QDebug operator<<(QDebug debug, const qutim_sdk_0_3::Status &status);
136 LIBQUTIM_EXPORT QDataStream &operator<<(QDataStream &out, const qutim_sdk_0_3::Status &status);
137 LIBQUTIM_EXPORT QDataStream &operator>>(QDataStream &in, qutim_sdk_0_3::Status &status);
138 
140 Q_ENUMS(qutim_sdk_0_3::Status::ChangeReason)
141 Q_DECLARE_METATYPE(qutim_sdk_0_3::Status)
142 Q_DECLARE_METATYPE(qutim_sdk_0_3::Status::ChangeReason)
143 
144 #endif // STATUS_H
145 

Generated by Doxygen