add an explicit message tray Source type
https://bugzilla.gnome.org/show_bug.cgi?id=603546
This commit is contained in:
@ -6,6 +6,9 @@ const Shell = imports.gi.Shell;
|
||||
const Mainloop = imports.mainloop;
|
||||
|
||||
const Main = imports.ui.main;
|
||||
const MessageTray = imports.ui.messageTray;
|
||||
|
||||
let nextNotificationId = 1;
|
||||
|
||||
const NotificationDaemonIface = {
|
||||
name: 'org.freedesktop.Notifications',
|
||||
@ -24,7 +27,18 @@ const NotificationDaemonIface = {
|
||||
{ name: 'GetServerInformation',
|
||||
inSignature: '',
|
||||
outSignature: 'ssss'
|
||||
}]
|
||||
}],
|
||||
signals: [{ name: 'NotificationClosed',
|
||||
inSignature: 'uu' },
|
||||
{ name: 'ActionInvoked',
|
||||
inSignature: 'us' }]
|
||||
};
|
||||
|
||||
const NotificationClosedReason = {
|
||||
EXPIRED: 1,
|
||||
DISMISSED: 2,
|
||||
APP_CLOSED: 3,
|
||||
UNDEFINED: 4
|
||||
};
|
||||
|
||||
function NotificationDaemon() {
|
||||
@ -49,20 +63,52 @@ NotificationDaemon.prototype = {
|
||||
});
|
||||
},
|
||||
|
||||
_sourceId: function(id) {
|
||||
return 'notification-' + id;
|
||||
},
|
||||
|
||||
Notify: function(appName, replacesId, icon, summary, body,
|
||||
actions, hints, timeout) {
|
||||
let iconActor = null;
|
||||
let id, source = null;
|
||||
|
||||
if (icon != '')
|
||||
iconActor = Shell.TextureCache.get_default().load_icon_name(icon, 24);
|
||||
else {
|
||||
// FIXME: load icon data from hints
|
||||
}
|
||||
if (replacesId != 0) {
|
||||
id = replacesId;
|
||||
source = Main.messageTray.getSource(this._sourceId(id));
|
||||
// source may be null if the current source was destroyed
|
||||
// right as the client sent the new notification
|
||||
}
|
||||
|
||||
Main.notificationPopup.show(iconActor, summary);
|
||||
if (source == null) {
|
||||
id = nextNotificationId++;
|
||||
|
||||
source = new MessageTray.Source(this._sourceId(id), Lang.bind(this,
|
||||
function (size) {
|
||||
if (icon != '')
|
||||
return Shell.TextureCache.get_default().load_icon_name(icon, size);
|
||||
else {
|
||||
// FIXME: load icon data from hints
|
||||
// FIXME: better fallback icon
|
||||
return Shell.TextureCache.get_default().load_icon_name('gtk-dialog-info', size);
|
||||
}
|
||||
}));
|
||||
Main.messageTray.add(source);
|
||||
|
||||
source.connect('clicked', Lang.bind(this,
|
||||
function() {
|
||||
source.destroy();
|
||||
this._emitNotificationClosed(id, NotificationClosedReason.DISMISSED);
|
||||
}));
|
||||
}
|
||||
|
||||
source.notify(summary);
|
||||
return id;
|
||||
},
|
||||
|
||||
CloseNotification: function(id) {
|
||||
let source = Main.messageTray.getSource(this._sourceId(id));
|
||||
if (source)
|
||||
source.destroy();
|
||||
this._emitNotificationClosed(id, NotificationClosedReason.APP_CLOSED);
|
||||
},
|
||||
|
||||
GetCapabilities: function() {
|
||||
@ -85,6 +131,13 @@ NotificationDaemon.prototype = {
|
||||
'0.1', // FIXME, get this from somewhere
|
||||
'1.0'
|
||||
];
|
||||
},
|
||||
|
||||
_emitNotificationClosed: function(id, reason) {
|
||||
DBus.session.emit_signal('/org/freedesktop/Notifications',
|
||||
'org.freedesktop.Notifications',
|
||||
'NotificationClosed', 'uu',
|
||||
[id, reason]);
|
||||
}
|
||||
};
|
||||
|
||||
|
Reference in New Issue
Block a user