libqutim 0.3.1.0
|
00001 /**************************************************************************** 00002 ** 00003 ** qutIM - instant messenger 00004 ** 00005 ** Copyright © 2011 Alexey Prokhin <alexey.prokhin@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 INFOREQUEST_H 00027 #define INFOREQUEST_H 00028 00029 #include "dataforms.h" 00030 #include "config.h" 00031 #include <QEvent> 00032 #include <QSet> 00033 #include <QHash> 00034 00035 namespace qutim_sdk_0_3 00036 { 00037 class InfoRequest; 00038 class InfoRequestPrivate; 00039 class InfoRequestFactoryPrivate; 00040 class InfoObserverPrivate; 00041 class Account; 00042 class Buddy; 00043 00044 class LIBQUTIM_EXPORT InfoRequestFactory 00045 { 00046 public: 00047 enum SupportLevel { 00048 NotSupported, 00049 Unavailable, 00050 ReadOnly, 00051 ReadWrite 00052 }; 00053 00054 virtual ~InfoRequestFactory(); 00055 virtual SupportLevel supportLevel(QObject *object) = 0; 00056 virtual InfoRequest *createrDataFormRequest(QObject *object) = 0; 00057 static InfoRequest *dataFormRequest(QObject *object); 00058 static InfoRequestFactory *factory(QObject *object); 00059 00060 protected: 00061 friend class InfoObserver; 00062 InfoRequestFactory(); 00063 void setSupportLevel(QObject *object, SupportLevel level); 00064 virtual bool startObserve(QObject *object) = 0; 00065 virtual bool stopObserve(QObject *object) = 0; 00066 virtual void virtual_hook(int id, void *data); 00067 }; 00068 00069 class LIBQUTIM_EXPORT InfoRequest : public QObject 00070 { 00071 Q_OBJECT 00072 Q_DECLARE_PRIVATE(InfoRequest) 00073 public: 00074 enum State { 00075 Initialized, 00076 Requesting, 00077 RequestDone, 00078 Updating, 00079 Updated, 00080 Canceled, 00081 LoadedFromCache, 00082 Error 00083 }; 00084 00085 virtual ~InfoRequest(); 00086 QObject *object() const; 00087 State state() const; 00088 DataItem dataItem() const; 00089 LocalizedString errorString() const; 00090 void requestData(const QSet<QString> &hints = QSet<QString>()); 00091 void updateData(const DataItem &dataItem); 00092 void cancel(); 00093 QVariant value(const QString &name, const QVariant &def = QVariant()) const; 00094 template <typename T> 00095 T value(const QString &name, const T &def = T()) const; 00096 signals: 00097 void stateChanged(qutim_sdk_0_3::InfoRequest::State state); 00098 void errorStringChanged(const qutim_sdk_0_3::LocalizedString &error); 00099 protected: 00100 InfoRequest(QObject *object); 00101 void setState(State state); 00102 void setErrorString(const LocalizedString &errorString); 00103 virtual DataItem createDataItem() const = 0; 00104 virtual QVariant getValue(const QString &name) const; 00105 virtual void doRequest(const QSet<QString> &hints) = 0; 00106 virtual void doUpdate(const DataItem &dataItem) = 0; 00107 virtual void doCancel() = 0; 00108 virtual void virtual_hook(int id, void *data); 00109 private: 00110 QScopedPointer<InfoRequestPrivate> d_ptr; 00111 }; 00112 00113 template <typename T> 00114 T InfoRequest::value(const QString &name, const T &def) const 00115 { 00116 QVariant val = value(name); 00117 return val.isNull() ? def : qVariantValue<T>(val); 00118 } 00119 00120 class LIBQUTIM_EXPORT InfoObserver : public QObject 00121 { 00122 Q_OBJECT 00123 Q_DECLARE_PRIVATE(InfoObserver) 00124 public: 00125 InfoObserver(QObject *object); 00126 virtual ~InfoObserver(); 00127 QObject *object() const; 00128 InfoRequestFactory::SupportLevel supportLevel() const; 00129 00130 signals: 00131 void supportLevelChanged(qutim_sdk_0_3::InfoRequestFactory::SupportLevel level); 00132 00133 private slots: 00134 void onObjectDestroyed(QObject *object); 00135 00136 private: 00137 friend class InfoRequestFactory; 00138 QScopedPointer<InfoObserverPrivate> d_ptr; 00139 }; 00140 00141 } 00142 00143 Q_DECLARE_INTERFACE(qutim_sdk_0_3::InfoRequestFactory, "org.qutim.InfoRequestFactory") 00144 00145 #endif // INFOREQUEST_H 00146