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  void setProperty(const char *name, const QVariant &value);
96 
97  void initIcon(const QString &protocol = QString());
98  static QIcon createIcon(Type type, const QString &protocol = QString());
99  static QString iconName(Type type, const QString &protocol = QString());
100  static Status instance(Type type, const char *proto, int subtype = 0);
101  static bool remember(const Status &status, const char *proto);
102  static Status createConnecting(const Status &status, const char *proto);
103  static Status connectingGoal(const Status &status);
104  Status connectingGoal() const;
105  void setExtendedInfo(const QString &name, const QVariantHash &status);
106  void removeExtendedInfo(const QString &name);
107  QVariantHash extendedInfo(const QString &name) const;
108  QHash<QString, QVariantHash> extendedInfos() const;
109  void setExtendedInfos(const QHash<QString, QVariantHash> &extInfos);
110 private:
111  QSharedDataPointer<StatusPrivate> d;
112 };
113 
114 template<typename T>
115 T Status::property(const char *name, const T &def) const
116 {
117  QVariant var = property(name, QVariant::fromValue<T>(def));
118  return var.value<T>();
119 }
120 
125 class LIBQUTIM_EXPORT ExtendedInfosEvent : public QEvent
126 {
127 public:
130  void addInfo(const QString &name, const QVariantHash &info);
131  QHash<QString, QVariantHash> infos();
132  static QEvent::Type eventType();
133 private:
134  QScopedPointer<ExtendedStatusesEventPrivate> d;
135 };
136 
137 }
138 
139 class QDebug;
141 LIBQUTIM_EXPORT QDebug operator<<(QDebug debug, const qutim_sdk_0_3::Status &status);
142 LIBQUTIM_EXPORT QDataStream &operator<<(QDataStream &out, const qutim_sdk_0_3::Status &status);
143 LIBQUTIM_EXPORT QDataStream &operator>>(QDataStream &in, qutim_sdk_0_3::Status &status);
144 
146 Q_ENUMS(qutim_sdk_0_3::Status::ChangeReason)
147 Q_DECLARE_METATYPE(qutim_sdk_0_3::Status)
148 Q_DECLARE_METATYPE(qutim_sdk_0_3::Status::ChangeReason)
149 
150 #endif // STATUS_H
151 

Generated by Doxygen