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  { return qVariantValue<T>(property(name, qVariantFromValue<T>(def))); }
171  void setProperty(const char *name, const QVariant &value);
172  void addAction(const NotificationAction &action);
173  static void addAction(Notification::Type type, const NotificationAction &action);
174  QList<NotificationAction> actions() const;
175 private:
176  friend class Notification;
177  QSharedDataPointer<NotificationRequestPrivate> d_ptr;
178 };
179 
181 {
182 public:
183  enum Priority
184  {
185  LowPriority = 0x00000100,
186  NormalPriortity = 0x00010000,
187  HighPriority = 0x01000000
188  };
189  virtual ~NotificationFilter();
190 
191  static void registerFilter(NotificationFilter *handler,
192  int priority = NormalPriortity);
193  static void unregisterFilter(NotificationFilter *handler);
194 protected:
195  friend class NotificationRequest;
196  virtual void filter(NotificationRequest &request) = 0;
197  virtual void notificationCreated(Notification *notification);
198  virtual void virtual_hook(int id, void *data);
199 };
200 
202 {
203  Q_DECLARE_PRIVATE(NotificationBackend)
204 public:
205  NotificationBackend(const QByteArray &type);
206  virtual ~NotificationBackend();
207  //TODO rewrite on Notification::Ptr
208  virtual void handleNotification(Notification *notification) = 0;
209  QByteArray backendType() const;
210  LocalizedString description() const;
211  static QList<QByteArray> allTypes();
212  static NotificationBackend* get(const QByteArray &type);
213  static QList<NotificationBackend*> all();
214 protected:
215  void ref(Notification *notification);
216  void deref(Notification *notification);
217  void setDescription(const LocalizedString &description);
218  void allowRejectedNotifications(const QByteArray &reason);
219  virtual void virtual_hook(int id, void *data);
220 private:
221  friend class NotificationRequest;
222  QScopedPointer<NotificationBackendPrivate> d_ptr;
223 };
224 
225 class LIBQUTIM_EXPORT NotificationManager : public QObject
226 {
227  Q_OBJECT
228 public:
229  static NotificationManager *instance();
230  static void setBackendState(const QByteArray &type, bool enabled);
231  static void enableBackend(const QByteArray &type);
232  static void disableBackend(const QByteArray &type);
233  static bool isBackendEnabled(const QByteArray &type);
234 signals:
235  void backendCreated(const QByteArray &type, qutim_sdk_0_3::NotificationBackend *backend);
236  void backendDestroyed(const QByteArray &type, qutim_sdk_0_3::NotificationBackend *backend);
237  void backendStateChanged(const QByteArray &type, bool enabled);
238 private:
239  friend class NotificationBackend;
241 };
242 
243 } // namespace qutim_sdk_0_3
244 
246 Q_DECLARE_METATYPE(qutim_sdk_0_3::NotificationRequest)
247 Q_DECLARE_METATYPE(qutim_sdk_0_3::NotificationAction)
248 Q_DECLARE_METATYPE(qutim_sdk_0_3::NotificationBackend*)
249 Q_DECLARE_INTERFACE(qutim_sdk_0_3::NotificationFilter, "org.qutim.core.NotificationFilter")
250 
251 #endif // NOTIFICATION_H
252 

Generated by Doxygen