[polari] Add small wrapper for fd.o notifications
- From: Florian Müllner <fmuellner src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [polari] Add small wrapper for fd.o notifications
- Date: Thu, 8 Aug 2013 13:13:54 +0000 (UTC)
commit 9febede33dbe57dba311a1d09d2c7c4fc7a82a07
Author: Florian Müllner <fmuellner gnome org>
Date: Tue Jul 30 17:52:57 2013 +0200
Add small wrapper for fd.o notifications
src/Makefile.am | 1 +
src/notify.js | 86 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 87 insertions(+), 0 deletions(-)
---
diff --git a/src/Makefile.am b/src/Makefile.am
index 6c3adf4..8936486 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -37,6 +37,7 @@ dist_js_DATA = \
joinDialog.js \
main.js \
mainWindow.js \
+ notify.js \
pasteManager.js \
roomList.js \
userList.js \
diff --git a/src/notify.js b/src/notify.js
new file mode 100644
index 0000000..d034587
--- /dev/null
+++ b/src/notify.js
@@ -0,0 +1,86 @@
+const Gio = imports.gi.Gio;
+
+const Lang = imports.lang;
+const Signals = imports.signals;
+
+const NotificationDaemonIface =
+ <interface name="org.freedesktop.Notifications">
+ <method name="Notify">
+ <arg type="s" direction="in"/>
+ <arg type="u" direction="in"/>
+ <arg type="s" direction="in"/>
+ <arg type="s" direction="in"/>
+ <arg type="s" direction="in"/>
+ <arg type="as" direction="in"/>
+ <arg type="a{sv}" direction="in"/>
+ <arg type="i" direction="in"/>
+ <arg type="u" direction="out"/>
+ </method>
+ <signal name="NotificationClosed">
+ <arg type="u"/>
+ <arg type="u"/>
+ </signal>
+ <signal name="ActionInvoked">
+ <arg type="u"/>
+ <arg type="s"/>
+ </signal>
+ </interface>;
+
+const NotificationDaemon = Gio.DBusProxy.makeProxyWrapper(NotificationDaemonIface);
+
+let _proxy = null;
+
+const Notification = new Lang.Class({
+ Name: 'Notification',
+
+ _init: function(summary, body) {
+ this._summary = summary;
+ this._body = body;
+ this._icon = 'polari';
+ this._id = 0;
+
+ this._actions = [];
+ this._hints = {};
+
+ if (_proxy == null)
+ _proxy = new NotificationDaemon(Gio.DBus.session,
+ 'org.freedesktop.Notifications',
+ '/org/freedesktop/Notifications');
+ this._closedId = _proxy.connectSignal('NotificationClosed',
+ Lang.bind(this, this._onClosed));
+ this._actionInvokedId = _proxy.connectSignal('ActionInoked',
+ Lang.bind(this, this._onActionInvoked));
+ },
+
+ show: function() {
+ _proxy.NotifyRemote('polari', this._id, this._icon, this._summary,
+ this._body, this._actions, this._hints, -1,
+ Lang.bind(this, function(result, error) {
+ this._id = result[0];
+ }));
+ },
+
+ addAction: function(action, label) {
+ this._actions.push(action, label);
+ },
+
+ setHint: function(key, value) {
+ this._hints[key] = value;
+ },
+
+ _onClosed: function(proxy, sender, [id, reason]) {
+ if (this._id != id)
+ return;
+ this.emit('closed');
+
+ proxy.disconnectSignal(this._closedId);
+ proxy.disconnectSignal(this._actionInvokedId);
+ },
+
+ _onActionInvoked: function(proxy, sender, [id, action]) {
+ if (this._id != id)
+ return;
+ this.emit('action-invoked', action);
+ }
+});
+Signals.addSignalMethods(Notification.prototype);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]