libqutim  0.3.1.0
inforequest.h
Go to the documentation of this file.
1 /****************************************************************************
2 **
3 ** qutIM - instant messenger
4 **
5 ** Copyright © 2011 Alexey Prokhin <alexey.prokhin@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 INFOREQUEST_H
27 #define INFOREQUEST_H
28 
29 #include "dataforms.h"
30 #include "config.h"
31 #include <QEvent>
32 #include <QSet>
33 #include <QHash>
34 
35 namespace qutim_sdk_0_3
36 {
37 class InfoRequest;
38 class InfoRequestPrivate;
39 class InfoRequestFactoryPrivate;
40 class InfoObserverPrivate;
41 class Account;
42 class Buddy;
43 
45 {
46 public:
47  enum SupportLevel {
51  ReadWrite
52  };
53 
54  virtual ~InfoRequestFactory();
55  virtual SupportLevel supportLevel(QObject *object) = 0;
56  virtual InfoRequest *createrDataFormRequest(QObject *object) = 0;
57  static InfoRequest *dataFormRequest(QObject *object);
58  static InfoRequestFactory *factory(QObject *object);
59 
60 protected:
61  friend class InfoObserver;
63  void setSupportLevel(QObject *object, SupportLevel level);
64  virtual bool startObserve(QObject *object) = 0;
65  virtual bool stopObserve(QObject *object) = 0;
66  virtual void virtual_hook(int id, void *data);
67 };
68 
69 class LIBQUTIM_EXPORT InfoRequest : public QObject
70 {
71  Q_OBJECT
72  Q_DECLARE_PRIVATE(InfoRequest)
73 public:
74  enum State {
82  Error
83  };
84 
85  virtual ~InfoRequest();
86  QObject *object() const;
87  State state() const;
88  DataItem dataItem() const;
89  LocalizedString errorString() const;
90  void requestData(const QSet<QString> &hints = QSet<QString>());
91  void updateData(const DataItem &dataItem);
92  void cancel();
93  QVariant value(const QString &name, const QVariant &def = QVariant()) const;
94  template <typename T>
95  T value(const QString &name, const T &def = T()) const;
96 signals:
97  void stateChanged(qutim_sdk_0_3::InfoRequest::State state);
98  void errorStringChanged(const qutim_sdk_0_3::LocalizedString &error);
99 protected:
100  InfoRequest(QObject *object);
101  void setState(State state);
102  void setErrorString(const LocalizedString &errorString);
103  virtual DataItem createDataItem() const = 0;
104  virtual QVariant getValue(const QString &name) const;
105  virtual void doRequest(const QSet<QString> &hints) = 0;
106  virtual void doUpdate(const DataItem &dataItem) = 0;
107  virtual void doCancel() = 0;
108  virtual void virtual_hook(int id, void *data);
109 private:
110  QScopedPointer<InfoRequestPrivate> d_ptr;
111 };
112 
113 template <typename T>
114 T InfoRequest::value(const QString &name, const T &def) const
115 {
116  QVariant val = value(name);
117  return val.isNull() ? def : qVariantValue<T>(val);
118 }
119 
120 class LIBQUTIM_EXPORT InfoObserver : public QObject
121 {
122  Q_OBJECT
123  Q_DECLARE_PRIVATE(InfoObserver)
124 public:
125  InfoObserver(QObject *object);
126  virtual ~InfoObserver();
127  QObject *object() const;
128  InfoRequestFactory::SupportLevel supportLevel() const;
129 
130 signals:
131  void supportLevelChanged(qutim_sdk_0_3::InfoRequestFactory::SupportLevel level);
132 
133 private slots:
134  void onObjectDestroyed(QObject *object);
135 
136 private:
137  friend class InfoRequestFactory;
138  QScopedPointer<InfoObserverPrivate> d_ptr;
139 };
140 
141 }
142 
143 Q_DECLARE_INTERFACE(qutim_sdk_0_3::InfoRequestFactory, "org.qutim.InfoRequestFactory")
144 
145 #endif // INFOREQUEST_H
146 

Generated by Doxygen