messageTray: Use a GIcon for a notification's icon/secondary icon

Using a GIcon instead of an actor means that we can always create
a new icon with the right size from an old icon.

https://bugzilla.gnome.org/show_bug.cgi?id=680426
This commit is contained in:
Jasper St. Pierre 2012-09-14 11:33:52 -03:00
parent b7acb1d488
commit 928ea3bb01
4 changed files with 39 additions and 35 deletions

View File

@ -527,33 +527,32 @@ const ChatSource = new Lang.Class({
}, },
createSecondaryIcon: function() { createSecondaryIcon: function() {
let iconBox = new St.Bin(); let iconName;
iconBox.child = new St.Icon({ style_class: 'secondary-icon' });
let presenceType = this._contact.get_presence_type(); let presenceType = this._contact.get_presence_type();
switch (presenceType) { switch (presenceType) {
case Tp.ConnectionPresenceType.AVAILABLE: case Tp.ConnectionPresenceType.AVAILABLE:
iconBox.child.icon_name = 'user-available'; iconName = 'user-available';
break; break;
case Tp.ConnectionPresenceType.BUSY: case Tp.ConnectionPresenceType.BUSY:
iconBox.child.icon_name = 'user-busy'; iconName = 'user-busy';
break; break;
case Tp.ConnectionPresenceType.OFFLINE: case Tp.ConnectionPresenceType.OFFLINE:
iconBox.child.icon_name = 'user-offline'; iconName = 'user-offline';
break; break;
case Tp.ConnectionPresenceType.HIDDEN: case Tp.ConnectionPresenceType.HIDDEN:
iconBox.child.icon_name = 'user-invisible'; iconName = 'user-invisible';
break; break;
case Tp.ConnectionPresenceType.AWAY: case Tp.ConnectionPresenceType.AWAY:
iconBox.child.icon_name = 'user-away'; iconName = 'user-away';
break; break;
case Tp.ConnectionPresenceType.EXTENDED_AWAY: case Tp.ConnectionPresenceType.EXTENDED_AWAY:
iconBox.child.icon_name = 'user-idle'; iconName = 'user-idle';
break; break;
default: default:
iconBox.child.icon_name = 'user-offline'; iconName = 'user-offline';
} }
return iconBox; return new Gio.ThemedIcon({ name: iconName });
}, },
_updateAvatarIcon: function() { _updateAvatarIcon: function() {
@ -733,7 +732,7 @@ const ChatSource = new Lang.Class({
title = GLib.markup_escape_text(this.title, -1); title = GLib.markup_escape_text(this.title, -1);
this._notification.update(this._notification.title, null, { customContent: true, secondaryIcon: this.createSecondaryIcon() }); this._notification.update(this._notification.title, null, { customContent: true, secondaryGIcon: this.createSecondaryIcon() });
if (message) if (message)
msg += ' <i>(' + GLib.markup_escape_text(message, -1) + ')</i>'; msg += ' <i>(' + GLib.markup_escape_text(message, -1) + ')</i>';
@ -761,7 +760,7 @@ const ChatNotification = new Lang.Class({
Extends: MessageTray.Notification, Extends: MessageTray.Notification,
_init: function(source) { _init: function(source) {
this.parent(source, source.title, null, { customContent: true, secondaryIcon: source.createSecondaryIcon() }); this.parent(source, source.title, null, { customContent: true, secondaryGIcon: source.createSecondaryIcon() });
this.setResident(true); this.setResident(true);
this._responseEntry = new St.Entry({ style_class: 'chat-response', this._responseEntry = new St.Entry({ style_class: 'chat-response',

View File

@ -35,8 +35,6 @@ const LONGER_SUMMARY_TIMEOUT = 4;
const HIDE_TIMEOUT = 0.2; const HIDE_TIMEOUT = 0.2;
const LONGER_HIDE_TIMEOUT = 0.6; const LONGER_HIDE_TIMEOUT = 0.6;
const NOTIFICATION_ICON_SIZE = 24;
// We delay hiding of the tray if the mouse is within MOUSE_LEFT_ACTOR_THRESHOLD // We delay hiding of the tray if the mouse is within MOUSE_LEFT_ACTOR_THRESHOLD
// range from the point where it left the tray. // range from the point where it left the tray.
const MOUSE_LEFT_ACTOR_THRESHOLD = 20; const MOUSE_LEFT_ACTOR_THRESHOLD = 20;
@ -291,9 +289,12 @@ function makeCloseButton() {
// If @params contains a 'body' parameter, then that text will be added to // If @params contains a 'body' parameter, then that text will be added to
// the content area (as with addBody()). // the content area (as with addBody()).
// //
// By default, the icon shown is created by calling // By default, the icon shown is the same as the source's.
// source.createIcon(). However, if @params contains an 'icon' // However, if @params contains a 'gicon' parameter, the passed in gicon
// parameter, the passed in icon will be used. // will be used.
//
// You can add a secondary icon to the banner with 'secondaryGIcon'. There
// is no fallback for this icon.
// //
// If @params contains a 'titleMarkup', 'bannerMarkup', or // If @params contains a 'titleMarkup', 'bannerMarkup', or
// 'bodyMarkup' parameter with the value %true, then the corresponding // 'bodyMarkup' parameter with the value %true, then the corresponding
@ -308,6 +309,8 @@ function makeCloseButton() {
const Notification = new Lang.Class({ const Notification = new Lang.Class({
Name: 'Notification', Name: 'Notification',
ICON_SIZE: 24,
IMAGE_SIZE: 125, IMAGE_SIZE: 125,
_init: function(source, title, banner, params) { _init: function(source, title, banner, params) {
@ -391,8 +394,8 @@ const Notification = new Lang.Class({
update: function(title, banner, params) { update: function(title, banner, params) {
params = Params.parse(params, { customContent: false, params = Params.parse(params, { customContent: false,
body: null, body: null,
icon: null, gicon: null,
secondaryIcon: null, secondaryGIcon: null,
titleMarkup: false, titleMarkup: false,
bannerMarkup: false, bannerMarkup: false,
bodyMarkup: false, bodyMarkup: false,
@ -402,12 +405,12 @@ const Notification = new Lang.Class({
let oldFocus = global.stage.key_focus; let oldFocus = global.stage.key_focus;
if (this._icon && (params.icon || params.clear)) { if (this._icon && (params.gicon || params.clear)) {
this._icon.destroy(); this._icon.destroy();
this._icon = null; this._icon = null;
} }
if (this._secondaryIcon && (params.secondaryIcon || params.clear)) { if (this._secondaryIcon && (params.secondaryGIcon || params.clear)) {
this._secondaryIcon.destroy(); this._secondaryIcon.destroy();
this._secondaryIcon = null; this._secondaryIcon = null;
} }
@ -437,8 +440,14 @@ const Notification = new Lang.Class({
if (!this._scrollArea && !this._actionArea && !this._imageBin) if (!this._scrollArea && !this._actionArea && !this._imageBin)
this._table.remove_style_class_name('multi-line-notification'); this._table.remove_style_class_name('multi-line-notification');
if (!this._icon) { if (params.gicon) {
this._icon = params.icon || this.source.createIcon(NOTIFICATION_ICON_SIZE); this._icon = new St.Icon({ gicon: params.gicon,
icon_size: this.ICON_SIZE });
} else {
this._icon = this.source.createIcon(this.ICON_SIZE);
}
if (this._icon) {
this._table.add(this._icon, { row: 0, this._table.add(this._icon, { row: 0,
col: 0, col: 0,
x_expand: false, x_expand: false,
@ -447,11 +456,10 @@ const Notification = new Lang.Class({
y_align: St.Align.START }); y_align: St.Align.START });
} }
if (!this._secondaryIcon) { if (params.secondaryGIcon) {
this._secondaryIcon = params.secondaryIcon; this._secondaryIcon = new St.Icon({ gicon: params.secondaryGIcon,
style_class: 'secondary-icon' });
if (this._secondaryIcon) this._bannerBox.add_actor(this._secondaryIcon);
this._bannerBox.add_actor(this._secondaryIcon);
} }
this.title = title; this.title = title;

View File

@ -356,12 +356,10 @@ const NotificationDaemon = new Lang.Class({
ndata.actions, ndata.hints, ndata.notification]; ndata.actions, ndata.hints, ndata.notification];
let gicon = this._iconForNotificationData(icon, hints); let gicon = this._iconForNotificationData(icon, hints);
let iconActor = new St.Icon({ gicon: gicon,
icon_size: MessageTray.NOTIFICATION_ICON_SIZE });
if (notification == null) { if (notification == null) {
notification = new MessageTray.Notification(source, summary, body, notification = new MessageTray.Notification(source, summary, body,
{ icon: iconActor, { gicon: gicon,
bannerMarkup: true }); bannerMarkup: true });
ndata.notification = notification; ndata.notification = notification;
notification.connect('destroy', Lang.bind(this, notification.connect('destroy', Lang.bind(this,
@ -386,7 +384,7 @@ const NotificationDaemon = new Lang.Class({
this._emitActionInvoked(ndata.id, actionId); this._emitActionInvoked(ndata.id, actionId);
})); }));
} else { } else {
notification.update(summary, body, { icon: iconActor, notification.update(summary, body, { gicon: gicon,
bannerMarkup: true, bannerMarkup: true,
clear: true }); clear: true });
} }

View File

@ -1747,10 +1747,9 @@ const NMApplet = new Lang.Class({
or this._source will be cleared */ or this._source will be cleared */
this._ensureSource(); this._ensureSource();
let icon = new St.Icon({ icon_name: iconName, let gicon = new Gio.ThemedIcon({ name: iconName });
icon_size: MessageTray.NOTIFICATION_ICON_SIZE });
device._notification = new MessageTray.Notification(this._source, title, text, device._notification = new MessageTray.Notification(this._source, title, text,
{ icon: icon }); { gicon: gicon });
device._notification.setUrgency(urgency); device._notification.setUrgency(urgency);
device._notification.setTransient(true); device._notification.setTransient(true);
device._notification.connect('destroy', function() { device._notification.connect('destroy', function() {