Show both summary and body of notifications, and support body-markup

Previously we were only showing the summary for notifications, but most
notifications only make sense if you show both.

https://bugzilla.gnome.org/show_bug.cgi?id=606331
This commit is contained in:
Dan Winship 2010-01-07 12:08:19 -05:00
parent 4ab513ca77
commit a424bbbabf
3 changed files with 33 additions and 5 deletions

View File

@ -17,6 +17,7 @@ dist_jsui_DATA = \
lookingGlass.js \
main.js \
messageTray.js \
notificationDaemon.js \
overview.js \
panel.js \
placeDisplay.js \

View File

@ -44,7 +44,11 @@ NotificationBox.prototype = {
setContent: function(notification) {
this._iconBox.child = notification.icon;
this._text.text = notification.text;
// Support <b>, <i>, and <u>, escape anything else
// so it displays as raw markup.
let markup = notification.text.replace(/<(\/?[^biu]>|[^>\/][^>])/g, "&lt;$1");
this._text.clutter_text.set_markup(markup);
}
};

View File

@ -8,6 +8,7 @@ const Mainloop = imports.mainloop;
const Main = imports.ui.main;
const MessageTray = imports.ui.messageTray;
const Params = imports.misc.params;
let nextNotificationId = 1;
@ -42,6 +43,12 @@ const NotificationClosedReason = {
UNDEFINED: 4
};
const Urgency = {
LOW: 0,
NORMAL: 1,
CRITICAL: 2
};
function NotificationDaemon() {
this._init();
}
@ -92,7 +99,11 @@ NotificationDaemon.prototype = {
}));
}
source.notify(summary);
summary = GLib.markup_escape_text(summary, -1);
if (body)
source.notify('<b>' + summary + '</b>: ' + body);
else
source.notify('<b>' + summary + '</b>');
return id;
},
@ -109,7 +120,7 @@ NotificationDaemon.prototype = {
'body',
// 'body-hyperlinks',
// 'body-images',
// 'body-markup',
'body-markup',
// 'icon-multi',
'icon-static'
// 'sound',
@ -145,8 +156,11 @@ Source.prototype = {
_init: function(sourceId, icon, hints) {
MessageTray.Source.prototype._init.call(this, sourceId);
hints = Params.parse(hints, { urgency: Urgency.NORMAL }, true);
this._icon = icon;
this._iconData = hints.icon_data;
this._urgency = hints.urgency;
},
createIcon: function(size) {
@ -166,8 +180,17 @@ Source.prototype = {
return textureCache.load_from_raw(data, data.length, hasAlpha,
width, height, rowStride, size);
} else {
// FIXME: fallback icon?
return textureCache.load_icon_name('gtk-dialog-info', size);
let stockIcon;
switch (this._urgency) {
case Urgency.LOW:
case Urgency.NORMAL:
stockIcon = 'gtk-dialog-info';
break;
case Urgency.CRITICAL:
stockIcon = 'gtk-dialog-error';
break;
}
return textureCache.load_icon_name(stockIcon, size);
}
}
};