libqutim
0.3.2.0
|
00001 /**************************************************************************** 00002 ** 00003 ** qutIM - instant messenger 00004 ** 00005 ** Copyright © 2011 Aleksey Sidorov <gorthauer87@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 NOTIFICATION_H 00027 #define NOTIFICATION_H 00028 00029 #include "libqutim_global.h" 00030 #include "actiongenerator.h" 00031 #include <QIcon> 00032 00033 namespace qutim_sdk_0_3 00034 { 00035 00036 class NotificationBackend; 00037 class NotificationPrivate; 00038 class NotificationRequest; 00039 class NotificationRequestPrivate; 00040 class NotificationActionPrivate; 00041 class NotificationBackendPrivate; 00042 class Message; 00043 class Status; 00044 class Buddy; 00045 00046 class LIBQUTIM_EXPORT Notification : public QObject 00047 { 00048 Q_OBJECT 00049 Q_DECLARE_PRIVATE(Notification) 00050 Q_ENUMS(Type) 00051 public: 00052 typedef QSharedPointer<Notification> Ptr; //FIXME find usable pointer! 00053 enum Type 00054 { 00055 IncomingMessage, 00056 OutgoingMessage, 00057 AppStartup, 00058 BlockedMessage, 00059 ChatUserJoined, 00060 ChatUserLeft, 00061 ChatIncomingMessage, 00062 ChatOutgoingMessage, 00063 FileTransferCompleted, 00064 UserOnline, 00065 UserOffline, 00066 UserChangedStatus, 00067 UserHasBirthday, 00068 UserTyping, 00069 System, 00070 Attention, 00071 LastType = Attention 00072 }; 00073 enum State 00074 { 00075 Active, 00076 Accepted, 00077 Ignored, 00078 Rejected 00079 }; 00080 static Notification *send(const Message &msg); 00081 static Notification *send(const QString &text); 00082 ~Notification(); 00083 NotificationRequest request() const; 00084 State state(); 00085 static LocalizedString typeString(Type type); 00086 static LocalizedStringList typeStrings(); 00087 static LocalizedString descriptionString(Type type); 00088 static LocalizedStringList descriptionStrings(); 00089 Q_INVOKABLE static QString typeText(Type type); 00090 Q_INVOKABLE static QString descriptionText(Type type); 00091 public slots: 00092 void accept(); 00093 void ignore(); 00094 void reject(); 00095 signals: 00096 void accepted(); 00097 void ignored(); 00098 void rejected(); 00099 void finished(qutim_sdk_0_3::Notification::State state); 00100 protected: 00101 Notification(const NotificationRequest &request); 00102 QScopedPointer<NotificationPrivate> d_ptr; 00103 friend class NotificationRequest; 00104 friend class NotificationBackend; 00105 }; 00106 typedef QList<Notification*> NotificationList; 00107 00108 class LIBQUTIM_EXPORT NotificationAction 00109 { 00110 public: 00111 enum Type 00112 { 00113 AcceptButton, 00114 IgnoreButton, 00115 AdditionalButton 00116 }; 00117 00118 NotificationAction(); 00119 NotificationAction(const QIcon &icon, const LocalizedString &title, 00120 QObject *receiver, const char *method); 00121 NotificationAction(const LocalizedString &title, 00122 QObject *receiver, const char *method); 00123 NotificationAction(const NotificationAction &action); 00124 ~NotificationAction(); 00125 const NotificationAction &operator=(const NotificationAction &rhs); 00126 QIcon icon() const; 00127 LocalizedString title() const; 00128 Type type() const; 00129 void setType(Type type); 00130 QObject *receiver() const; 00131 const char *method() const; 00132 void trigger() const; 00133 private: 00134 friend class Notification; 00135 QSharedDataPointer<NotificationActionPrivate> d; 00136 }; 00137 00138 class LIBQUTIM_EXPORT NotificationRequest 00139 { 00140 public: 00141 NotificationRequest(); 00142 NotificationRequest(const Message &msg); 00143 NotificationRequest(Notification::Type type); 00144 NotificationRequest(Buddy *buddy, const Status &status, const Status &previous); 00145 NotificationRequest(const NotificationRequest &other); 00146 ~NotificationRequest(); 00147 NotificationRequest &operator =(const NotificationRequest &other); 00150 Notification *send(); 00151 void setObject(QObject *obj); 00152 QObject *object() const; 00153 void setImage(const QPixmap &pixmap); 00154 QPixmap image() const; 00155 void setTitle(const QString &title); 00156 QString title() const; 00157 void setText(const QString &text); 00158 QString text() const; 00159 void setType(Notification::Type type); 00160 Notification::Type type() const; 00161 void reject(const QByteArray &reason); 00162 QSet<QByteArray> rejectionReasons() const; 00163 void setBackends(const QSet<QByteArray> &backendTypes); 00164 void blockBackend(const QByteArray &backendType); 00165 void unblockBackend(const QByteArray &backendType); 00166 bool isBackendBlocked(const QByteArray &backendType); 00167 QVariant property(const char *name, const QVariant &def) const; 00168 template<typename T> 00169 T property(const char *name, const T &def) const; 00170 void setProperty(const char *name, const QVariant &value); 00171 void addAction(const NotificationAction &action); 00172 static void addAction(Notification::Type type, const NotificationAction &action); 00173 QList<NotificationAction> actions() const; 00174 private: 00175 friend class Notification; 00176 QSharedDataPointer<NotificationRequestPrivate> d_ptr; 00177 }; 00178 00179 template<typename T> 00180 T NotificationRequest::property(const char *name, const T &def) const 00181 { 00182 QVariant var = property(name, QVariant::fromValue<T>(def)); 00183 return var.value<T>(); 00184 } 00185 00186 class LIBQUTIM_EXPORT NotificationFilter 00187 { 00188 public: 00189 enum Priority 00190 { 00191 LowPriority = 0x00000100, 00192 NormalPriortity = 0x00010000, 00193 HighPriority = 0x01000000 00194 }; 00195 virtual ~NotificationFilter(); 00196 00197 static void registerFilter(NotificationFilter *handler, 00198 int priority = NormalPriortity); 00199 static void unregisterFilter(NotificationFilter *handler); 00200 protected: 00201 friend class NotificationRequest; 00202 virtual void filter(NotificationRequest &request) = 0; 00203 virtual void notificationCreated(Notification *notification); 00204 virtual void virtual_hook(int id, void *data); 00205 }; 00206 00207 class LIBQUTIM_EXPORT NotificationBackend 00208 { 00209 Q_DECLARE_PRIVATE(NotificationBackend) 00210 public: 00211 NotificationBackend(const QByteArray &type); 00212 virtual ~NotificationBackend(); 00213 //TODO rewrite on Notification::Ptr 00214 virtual void handleNotification(Notification *notification) = 0; 00215 QByteArray backendType() const; 00216 LocalizedString description() const; 00217 static QList<QByteArray> allTypes(); 00218 static NotificationBackend* get(const QByteArray &type); 00219 static QList<NotificationBackend*> all(); 00220 protected: 00221 void ref(Notification *notification); 00222 void deref(Notification *notification); 00223 void setDescription(const LocalizedString &description); 00224 void allowRejectedNotifications(const QByteArray &reason); 00225 virtual void virtual_hook(int id, void *data); 00226 private: 00227 friend class NotificationRequest; 00228 QScopedPointer<NotificationBackendPrivate> d_ptr; 00229 }; 00230 00231 class LIBQUTIM_EXPORT NotificationManager : public QObject 00232 { 00233 Q_OBJECT 00234 public: 00235 static NotificationManager *instance(); 00236 static void setBackendState(const QByteArray &type, bool enabled); 00237 static void enableBackend(const QByteArray &type); 00238 static void disableBackend(const QByteArray &type); 00239 static bool isBackendEnabled(const QByteArray &type); 00240 signals: 00241 void backendCreated(const QByteArray &type, qutim_sdk_0_3::NotificationBackend *backend); 00242 void backendDestroyed(const QByteArray &type, qutim_sdk_0_3::NotificationBackend *backend); 00243 void backendStateChanged(const QByteArray &type, bool enabled); 00244 private: 00245 friend class NotificationBackend; 00246 NotificationManager(); 00247 }; 00248 00249 } // namespace qutim_sdk_0_3 00250 00251 Q_DECLARE_METATYPE(qutim_sdk_0_3::Notification*) 00252 Q_DECLARE_METATYPE(qutim_sdk_0_3::NotificationRequest) 00253 Q_DECLARE_METATYPE(qutim_sdk_0_3::NotificationAction) 00254 Q_DECLARE_METATYPE(qutim_sdk_0_3::NotificationBackend*) 00255 Q_DECLARE_INTERFACE(qutim_sdk_0_3::NotificationFilter, "org.qutim.core.NotificationFilter") 00256 00257 #endif // NOTIFICATION_H 00258