libqutim  0.3.1.0
notification.h
Go to the documentation of this file.
1 /****************************************************************************
2 **
3 ** qutIM - instant messenger
4 **
5 ** Copyright © 2011 Aleksey Sidorov <gorthauer87@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 NOTIFICATION_H
27 #define NOTIFICATION_H
28 
29 #include "libqutim_global.h"
30 #include "actiongenerator.h"
31 #include <QIcon>
32 
33 namespace qutim_sdk_0_3
34 {
35 
36 class NotificationBackend;
37 class NotificationPrivate;
38 class NotificationRequest;
39 class NotificationRequestPrivate;
40 class NotificationActionPrivate;
41 class NotificationBackendPrivate;
42 class Message;
43 class Status;
44 class Buddy;
45 
46 class LIBQUTIM_EXPORT Notification : public QObject
47 {
48  Q_OBJECT
49  Q_DECLARE_PRIVATE(Notification)
50  Q_ENUMS(Type)
51 public:
52  typedef QSharedPointer<Notification> Ptr; //FIXME find usable pointer!
53  enum Type
54  {
71  LastType = Attention
72  };
73  enum State
74  {
78  Rejected
79  };
80  static Notification *send(const Message &msg);
81  static Notification *send(const QString &text);
82  ~Notification();
83  NotificationRequest request() const;
84  State state();
85  static LocalizedString typeString(Type type);
86  static LocalizedStringList typeStrings();
87  static LocalizedString descriptionString(Type type);
88  static LocalizedStringList descriptionStrings();
89  Q_INVOKABLE static QString typeText(Type type);
90  Q_INVOKABLE static QString descriptionText(Type type);
91 public slots:
92  void accept();
93  void ignore();
94  void reject();
95 signals:
96  void accepted();
97  void ignored();
98  void rejected();
99  void finished(qutim_sdk_0_3::Notification::State state);
100 protected:
101  Notification(const NotificationRequest &request);
102  QScopedPointer<NotificationPrivate> d_ptr;
103  friend class NotificationRequest;
104  friend class NotificationBackend;
105 };
106 typedef QList<Notification*> NotificationList;
107 
109 {
110 public:
111  enum Type
112  {
115  AdditionalButton
116  };
117 
119  NotificationAction(const QIcon &icon, const LocalizedString &title,
120  QObject *receiver, const char *method);
121  NotificationAction(const LocalizedString &title,
122  QObject *receiver, const char *method);
123  NotificationAction(const NotificationAction &action);
125  const NotificationAction &operator=(const NotificationAction &rhs);
126  QIcon icon() const;
127  LocalizedString title() const;
128  Type type() const;
129  void setType(Type type);
130  QObject *receiver() const;
131  const char *method() const;
132  void trigger() const;
133 private:
134  friend class Notification;
135  QSharedDataPointer<NotificationActionPrivate> d;
136 };
137 
139 {
140 public:
142  NotificationRequest(const Message &msg);
144  NotificationRequest(Buddy *buddy, const Status &status, const Status &previous);
147  NotificationRequest &operator =(const NotificationRequest &other);
150  Notification *send();
151  void setObject(QObject *obj);
152  QObject *object() const;
153  void setImage(const QPixmap &pixmap);
154  QPixmap image() const;
155  void setTitle(const QString &title);
156  QString title() const;
157  void setText(const QString &text);
158  QString text() const;
159  void setType(Notification::Type type);
160  Notification::Type type() const;
161  void reject(const QByteArray &reason);
162  QSet<QByteArray> rejectionReasons() const;
163  void setBackends(const QSet<QByteArray> &backendTypes);
164  void blockBackend(const QByteArray &backendType);
165  void unblockBackend(const QByteArray &backendType);
166  bool isBackendBlocked(const QByteArray &backendType);
167  QVariant property(const char *name, const QVariant &def) const;
168  template<typename T>
169  T property(const char *name, const T &def) const;
170  void setProperty(const char *name, const QVariant &value);
171  void addAction(const NotificationAction &action);
172  static void addAction(Notification::Type type, const NotificationAction &action);
173  QList<NotificationAction> actions() const;
174 private:
175  friend class Notification;
176  QSharedDataPointer<NotificationRequestPrivate> d_ptr;
177 };
178 
179 template<typename T>
180 T NotificationRequest::property(const char *name, const T &def) const
181 {
182  QVariant var = property(name, QVariant::fromValue<T>(def));
183  return var.value<T>();
184 }
185 
187 {
188 public:
189  enum Priority
190  {
191  LowPriority = 0x00000100,
192  NormalPriortity = 0x00010000,
193  HighPriority = 0x01000000
194  };
195  virtual ~NotificationFilter();
196 
197  static void registerFilter(NotificationFilter *handler,
198  int priority = NormalPriortity);
199  static void unregisterFilter(NotificationFilter *handler);
200 protected:
201  friend class NotificationRequest;
202  virtual void filter(NotificationRequest &request) = 0;
203  virtual void notificationCreated(Notification *notification);
204  virtual void virtual_hook(int id, void *data);
205 };
206 
208 {
209  Q_DECLARE_PRIVATE(NotificationBackend)
210 public:
211  NotificationBackend(const QByteArray &type);
212  virtual ~NotificationBackend();
213  //TODO rewrite on Notification::Ptr
214  virtual void handleNotification(Notification *notification) = 0;
215  QByteArray backendType() const;
216  LocalizedString description() const;
217  static QList<QByteArray> allTypes();
218  static NotificationBackend* get(const QByteArray &type);
219  static QList<NotificationBackend*> all();
220 protected:
221  void ref(Notification *notification);
222  void deref(Notification *notification);
223  void setDescription(const LocalizedString &description);
224  void allowRejectedNotifications(const QByteArray &reason);
225  virtual void virtual_hook(int id, void *data);
226 private:
227  friend class NotificationRequest;
228  QScopedPointer<NotificationBackendPrivate> d_ptr;
229 };
230 
231 class LIBQUTIM_EXPORT NotificationManager : public QObject
232 {
233  Q_OBJECT
234 public:
235  static NotificationManager *instance();
236  static void setBackendState(const QByteArray &type, bool enabled);
237  static void enableBackend(const QByteArray &type);
238  static void disableBackend(const QByteArray &type);
239  static bool isBackendEnabled(const QByteArray &type);
240 signals:
241  void backendCreated(const QByteArray &type, qutim_sdk_0_3::NotificationBackend *backend);
242  void backendDestroyed(const QByteArray &type, qutim_sdk_0_3::NotificationBackend *backend);
243  void backendStateChanged(const QByteArray &type, bool enabled);
244 private:
245  friend class NotificationBackend;
247 };
248 
249 } // namespace qutim_sdk_0_3
250 
252 Q_DECLARE_METATYPE(qutim_sdk_0_3::NotificationRequest)
253 Q_DECLARE_METATYPE(qutim_sdk_0_3::NotificationAction)
254 Q_DECLARE_METATYPE(qutim_sdk_0_3::NotificationBackend*)
255 Q_DECLARE_INTERFACE(qutim_sdk_0_3::NotificationFilter, "org.qutim.core.NotificationFilter")
256 
257 #endif // NOTIFICATION_H
258 

Generated by Doxygen