1/*
2 Copyright (C) 2005-2009 by Olivier Goffart <ogoffart at kde.org>
3
4
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2, or (at your option)
8 any later version.
9
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18
19 */
20
21#ifndef KNOTIFY_H
22#define KNOTIFY_H
23
24#include <QObject>
25#include <QHash>
26
27
28#include <QtDBus/QtDBus>
29
30
31#include "knotifyconfig.h"
32
33
34typedef QHash<QString,QString> Dict;
35
36
37class KNotifyPlugin;
38
39
40class KNotify : public QObject
41{
42 Q_OBJECT
43 Q_CLASSINFO("D-Bus Interface", "org.kde.KNotify")
44 public:
45 using QObject::event;
46 KNotify(QObject *parent=0l);
47 ~KNotify();
48 void addPlugin( KNotifyPlugin *p );
49
50 public Q_SLOTS:
51 void reconfigure();
52 void closeNotification( int id);
53
54 int event(const QString &event, const QString &fromApp, const ContextList& contexts ,
55 const QString &title, const QString &text, const KNotifyImage& image, const QStringList& actions,
56 int timeout, WId winId = 0);
57
58 void update(int id, const QString &title, const QString &text, const KNotifyImage& image, const QStringList& actions);
59 void reemit(int id, const ContextList& contexts);
60 Q_SIGNALS:
61 void notificationClosed( int id);
62 void notificationActivated(int id,int action);
63
64 private Q_SLOTS:
65 void slotPluginFinished(int id);
66
67 private:
68
69 struct Event
70 {
71 Event(const QString &appname, const ContextList &contexts , const QString &eventid)
72 : config(appname, contexts , eventid) {}
73 int id;
74 int ref;
75 KNotifyConfig config;
76 };
77
78 int m_counter;
79 QHash<QString, KNotifyPlugin *> m_plugins;
80 QHash<int , Event* > m_notifications;
81 void loadConfig();
82 void emitEvent(Event *e);
83};
84
85class KNotifyAdaptor : public QDBusAbstractAdaptor
86{
87 Q_OBJECT
88 Q_CLASSINFO("D-Bus Interface", "org.kde.KNotify")
89 Q_CLASSINFO("D-Bus Introspection", ""
90 "<interface name=\"org.kde.KNotify\">"
91 "<signal name=\"notificationClosed\">"
92 "<arg name=\"id\" type=\"i\" direction=\"out\"/>"
93 "</signal>"
94 "<signal name=\"notificationActivated\">"
95 "<arg name=\"id\" type=\"i\" direction=\"out\"/>"
96 "<arg name=\"action\" type=\"i\" direction=\"out\"/>"
97 "</signal>"
98 "<method name=\"reconfigure\">"
99 "</method>"
100 "<method name=\"closeNotification\">"
101 "<arg name=\"id\" type=\"i\" direction=\"in\"/>"
102 "</method>"
103 "<method name=\"event\">"
104 "<arg type=\"i\" direction=\"out\"/>"
105 "<arg name=\"event\" type=\"s\" direction=\"in\"/>"
106 "<arg name=\"fromApp\" type=\"s\" direction=\"in\"/>"
107 "<arg name=\"contexts\" type=\"av\" direction=\"in\"/>"
108 "<arg name=\"title\" type=\"s\" direction=\"in\"/>"
109 "<arg name=\"text\" type=\"s\" direction=\"in\"/>"
110 "<arg name=\"pixmap\" type=\"ay\" direction=\"in\"/>"
111 "<arg name=\"actions\" type=\"as\" direction=\"in\"/>"
112 "<arg name=\"timeout\" type=\"i\" direction=\"in\"/>"
113 "<arg name=\"winId\" type=\"x\" direction=\"in\"/>"
114 "</method>"
115 "<method name=\"update\">"
116 "<arg name=\"id\" type=\"i\" direction=\"in\"/>"
117 "<arg name=\"title\" type=\"s\" direction=\"in\"/>"
118 "<arg name=\"text\" type=\"s\" direction=\"in\"/>"
119 "<arg name=\"pixmap\" type=\"ay\" direction=\"in\"/>"
120 "<arg name=\"actions\" type=\"as\" direction=\"in\"/>"
121 "</method>"
122 "<method name=\"reemit\">"
123 "<arg name=\"id\" type=\"i\" direction=\"in\"/>"
124 "<arg name=\"contexts\" type=\"av\" direction=\"in\"/>"
125 "</method>"
126
127 "</interface>" )
128
129 public:
130 KNotifyAdaptor(QObject *parent);
131 using QObject::event;
132
133 public Q_SLOTS:
134
135 void reconfigure();
136 void closeNotification( int id);
137
138 int event(const QString &event, const QString &fromApp, const QVariantList& contexts ,
139 const QString &title, const QString &text, const QByteArray& pixmap, const QStringList& actions , int timeout,
140 qlonglong winId );
141
142 void reemit(int id, const QVariantList& contexts);
143 void update(int id, const QString &title, const QString &text, const QByteArray& pixmap, const QStringList& actions );
144
145 Q_SIGNALS:
146 void notificationClosed( int id);
147 void notificationActivated( int id,int action);
148};
149
150#endif
151
152