Commit b75a7b06 authored by Florian Müllner's avatar Florian Müllner

Use new GNotification API

Bump the GIO requirement and replace our own org.freedesktop.Notifications
implementation with the new GNotification API.
parent ea4c7f61
...@@ -21,7 +21,7 @@ LT_INIT([disable-static]) ...@@ -21,7 +21,7 @@ LT_INIT([disable-static])
GLIB_GSETTINGS GLIB_GSETTINGS
PKG_CHECK_MODULES(POLARI, PKG_CHECK_MODULES(POLARI,
gio-2.0 gio-2.0 >= 2.39.0
gobject-introspection-1.0 gobject-introspection-1.0
gtk+-3.0 >= 3.9.12 gtk+-3.0 >= 3.9.12
telepathy-glib); telepathy-glib);
......
...@@ -39,7 +39,6 @@ dist_js_DATA = \ ...@@ -39,7 +39,6 @@ dist_js_DATA = \
main.js \ main.js \
mainWindow.js \ mainWindow.js \
messageDialog.js \ messageDialog.js \
notify.js \
pasteManager.js \ pasteManager.js \
roomList.js \ roomList.js \
roomStack.js \ roomStack.js \
......
...@@ -8,7 +8,6 @@ const Tpl = imports.gi.TelepathyLogger; ...@@ -8,7 +8,6 @@ const Tpl = imports.gi.TelepathyLogger;
const Lang = imports.lang; const Lang = imports.lang;
const Mainloop = imports.mainloop; const Mainloop = imports.mainloop;
const Notify = imports.notify;
const Utils = imports.utils; const Utils = imports.utils;
const MAX_NICK_CHARS = 8; const MAX_NICK_CHARS = 8;
...@@ -110,8 +109,8 @@ const ChatView = new Lang.Class({ ...@@ -110,8 +109,8 @@ const ChatView = new Lang.Class({
let adj = this.widget.vadjustment; let adj = this.widget.vadjustment;
this._scrollBottom = adj.upper - adj.page_size; this._scrollBottom = adj.upper - adj.page_size;
let app = Gio.Application.get_default(); this._app = Gio.Application.get_default();
app.pasteManager.addWidget(this._view); this._app.pasteManager.addWidget(this._view);
this._linkCursor = Gdk.Cursor.new(Gdk.CursorType.HAND1); this._linkCursor = Gdk.Cursor.new(Gdk.CursorType.HAND1);
...@@ -640,20 +639,17 @@ const ChatView = new Lang.Class({ ...@@ -640,20 +639,17 @@ const ChatView = new Lang.Class({
if (message.shouldHighlight && !this._toplevelFocus) { if (message.shouldHighlight && !this._toplevelFocus) {
let summary = '%s %s'.format(this._room.display_name, message.nick); let summary = '%s %s'.format(this._room.display_name, message.nick);
let notification = new Notify.Notification(summary, message.text); let notification = new Gio.Notification();
notification.set_title(summary);
notification.set_body(message.text);
let account = this._room.account; let account = this._room.account;
let param = GLib.Variant.new('(ssu)', let param = GLib.Variant.new('(ssu)',
[ account.get_object_path(), [ account.get_object_path(),
this._room.channel_name, this._room.channel_name,
TP_CURRENT_TIME ]); TP_CURRENT_TIME ]);
notification.addAction('default', 'default'); notification.set_default_action_and_target('app.join-room', param);
notification.connect('action-invoked', function() { this._app.send_notification(null, notification);
let app = Gio.Application.get_default();
let action = app.lookup_action('join-room');
action.activate(param);
});
notification.show();
} }
let buffer = this._view.get_buffer(); let buffer = this._view.get_buffer();
......
const Gio = imports.gi.Gio;
const Lang = imports.lang;
const Signals = imports.signals;
const NotificationDaemonIface = '<node> \
<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> \
</node>';
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('ActionInvoked',
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) {
if (error)
logError(error, 'Failed to send notification');
else
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);
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment