2010-01-13 20:05:20 +00:00
|
|
|
/* -*- mode: js2; js2-basic-offset: 4; indent-tabs-mode: nil -*- */
|
|
|
|
|
|
|
|
const Clutter = imports.gi.Clutter;
|
|
|
|
const Lang = imports.lang;
|
|
|
|
const Mainloop = imports.mainloop;
|
2010-02-01 17:10:38 +00:00
|
|
|
const Pango = imports.gi.Pango;
|
2010-01-28 17:04:26 +00:00
|
|
|
const Shell = imports.gi.Shell;
|
2010-01-13 20:05:20 +00:00
|
|
|
const Signals = imports.signals;
|
2010-01-28 17:04:26 +00:00
|
|
|
const St = imports.gi.St;
|
2010-01-13 20:05:20 +00:00
|
|
|
const Tweener = imports.ui.tweener;
|
|
|
|
|
|
|
|
const Main = imports.ui.main;
|
|
|
|
|
|
|
|
const ANIMATION_TIME = 0.2;
|
|
|
|
const NOTIFICATION_TIMEOUT = 4;
|
2010-01-28 18:39:00 +00:00
|
|
|
const SUMMARY_TIMEOUT = 1;
|
2010-01-13 20:05:20 +00:00
|
|
|
|
|
|
|
const MESSAGE_TRAY_TIMEOUT = 0.2;
|
|
|
|
|
|
|
|
const ICON_SIZE = 24;
|
|
|
|
|
2010-01-28 18:39:00 +00:00
|
|
|
const MessageTrayState = {
|
|
|
|
HIDDEN: 0, // entire message tray is hidden
|
|
|
|
NOTIFICATION: 1, // notifications are visible
|
|
|
|
SUMMARY: 2, // summary is visible
|
|
|
|
TRAY_ONLY: 3 // neither notifiations nor summary are visible, only tray
|
|
|
|
};
|
|
|
|
|
2010-02-01 20:23:49 +00:00
|
|
|
function _cleanMarkup(text) {
|
|
|
|
// Support <b>, <i>, and <u>, escape anything else
|
|
|
|
// so it displays as raw markup.
|
|
|
|
return text.replace(/<(\/?[^biu]>|[^>\/][^>])/g, "<$1");
|
|
|
|
}
|
|
|
|
|
2010-02-01 17:10:38 +00:00
|
|
|
// Notification:
|
|
|
|
// @source: the notification's Source
|
|
|
|
// @title: the title
|
|
|
|
// @banner: the banner text
|
|
|
|
// @body: the body text, or %null
|
|
|
|
//
|
|
|
|
// Creates a notification. In banner mode, it will show
|
2010-02-01 20:23:49 +00:00
|
|
|
// @source's icon, @title (in bold) and @banner, all on a single line
|
2010-02-01 17:10:38 +00:00
|
|
|
// (with @banner ellipsized if necessary). If @body is not %null, then
|
|
|
|
// the notification will be expandable. In expanded mode, it will show
|
2010-02-01 20:23:49 +00:00
|
|
|
// just the icon and @title (in bold) on the first line, and @body on
|
2010-02-01 17:10:38 +00:00
|
|
|
// multiple lines underneath.
|
2010-02-01 20:23:49 +00:00
|
|
|
function Notification(source, title, banner, body) {
|
|
|
|
this._init(source, title, banner, body);
|
2010-01-13 20:05:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Notification.prototype = {
|
2010-02-01 20:23:49 +00:00
|
|
|
_init: function(source, title, banner, body) {
|
2010-01-28 18:39:00 +00:00
|
|
|
this.source = source;
|
2010-01-13 20:05:20 +00:00
|
|
|
|
2010-02-01 17:10:38 +00:00
|
|
|
this.actor = new St.Table({ name: 'notification' });
|
2010-01-13 20:05:20 +00:00
|
|
|
|
2010-02-01 20:23:49 +00:00
|
|
|
let icon = source.createIcon(ICON_SIZE);
|
|
|
|
this.actor.add(icon, { row: 0,
|
|
|
|
col: 0,
|
|
|
|
x_expand: false,
|
|
|
|
y_expand: false,
|
|
|
|
y_fill: false });
|
2010-02-01 17:10:38 +00:00
|
|
|
|
|
|
|
// The first line should have the title, followed by the
|
|
|
|
// banner text, but ellipsized if they won't both fit. We can't
|
|
|
|
// make St.Table or St.BoxLayout do this the way we want (don't
|
|
|
|
// show banner at all if title needs to be ellipsized), so we
|
|
|
|
// use Shell.GenericContainer.
|
|
|
|
this._bannerBox = new Shell.GenericContainer();
|
|
|
|
this._bannerBox.connect('get-preferred-width', Lang.bind(this, this._bannerBoxGetPreferredWidth));
|
|
|
|
this._bannerBox.connect('get-preferred-height', Lang.bind(this, this._bannerBoxGetPreferredHeight));
|
|
|
|
this._bannerBox.connect('allocate', Lang.bind(this, this._bannerBoxAllocate));
|
|
|
|
this.actor.add(this._bannerBox, { row: 0,
|
|
|
|
col: 1,
|
|
|
|
y_expand: false,
|
|
|
|
y_fill: false });
|
|
|
|
|
|
|
|
this._titleText = new St.Label();
|
2010-02-01 20:23:49 +00:00
|
|
|
title = title ? _cleanMarkup(title.replace('\n', ' ')) : '';
|
|
|
|
this._titleText.clutter_text.set_markup('<b>' + title + '</b>');
|
2010-02-01 17:10:38 +00:00
|
|
|
this._bannerBox.add_actor(this._titleText);
|
|
|
|
|
|
|
|
this._bannerText = new St.Label();
|
2010-02-01 20:23:49 +00:00
|
|
|
banner = banner ? _cleanMarkup(banner.replace('\n', ' ')) : '';
|
|
|
|
this._bannerText.clutter_text.set_markup(banner);
|
2010-02-01 17:10:38 +00:00
|
|
|
this._bannerBox.add_actor(this._bannerText);
|
|
|
|
|
|
|
|
this._bodyText = new St.Label();
|
|
|
|
this._bodyText.clutter_text.line_wrap = true;
|
|
|
|
this._bodyText.clutter_text.ellipsize = Pango.EllipsizeMode.NONE;
|
2010-02-01 20:23:49 +00:00
|
|
|
if (body) {
|
|
|
|
body = _cleanMarkup(body);
|
|
|
|
this._bodyText.clutter_text.set_markup(body);
|
2010-02-01 17:10:38 +00:00
|
|
|
this._canPopOut = true;
|
|
|
|
} else {
|
2010-02-01 20:23:49 +00:00
|
|
|
// If there's no body, then normally we wouldn't do
|
|
|
|
// pop-out. But if title+banner is too wide for the
|
|
|
|
// notification, then we'd need to pop out to show the
|
|
|
|
// full banner. So we set up bodyText with that now.
|
|
|
|
this._bodyText.clutter_text.set_markup(banner);
|
2010-02-01 17:10:38 +00:00
|
|
|
this._canPopOut = false;
|
|
|
|
}
|
2010-02-01 20:23:49 +00:00
|
|
|
this.actor.add(this._bodyText, { row: 1,
|
|
|
|
col: 1 });
|
|
|
|
|
2010-02-01 20:41:22 +00:00
|
|
|
this.actions = {};
|
|
|
|
this._buttonBox = null;
|
|
|
|
},
|
|
|
|
|
|
|
|
addAction: function(id, label) {
|
|
|
|
if (!this._buttonBox) {
|
|
|
|
this._buttonBox = new St.BoxLayout({ name: 'notification-actions' });
|
|
|
|
this.actor.add(this._buttonBox, { row: 2,
|
|
|
|
col: 1,
|
|
|
|
x_expand: false,
|
|
|
|
x_fill: false,
|
|
|
|
x_align: 1.0 });
|
|
|
|
this._canPopOut = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
let button = new St.Button({ style_class: 'notification-button',
|
|
|
|
label: label });
|
|
|
|
this._buttonBox.add(button);
|
|
|
|
button.connect('clicked', Lang.bind(this, function() { this.emit('action-invoked', id); }));
|
2010-02-01 17:10:38 +00:00
|
|
|
},
|
2010-01-13 20:05:20 +00:00
|
|
|
|
2010-02-01 17:10:38 +00:00
|
|
|
_bannerBoxGetPreferredWidth: function(actor, forHeight, alloc) {
|
|
|
|
let [titleMin, titleNat] = this._titleText.get_preferred_width(forHeight);
|
|
|
|
let [bannerMin, bannerNat] = this._bannerText.get_preferred_width(forHeight);
|
|
|
|
let [has_spacing, spacing] = this.actor.get_theme_node().get_length('spacing-columns', false);
|
2010-01-28 18:39:00 +00:00
|
|
|
|
2010-02-01 17:10:38 +00:00
|
|
|
alloc.min_size = titleMin;
|
|
|
|
alloc.natural_size = titleNat + (has_spacing ? spacing : 0) + bannerNat;
|
|
|
|
},
|
|
|
|
|
|
|
|
_bannerBoxGetPreferredHeight: function(actor, forWidth, alloc) {
|
|
|
|
[alloc.min_size, alloc.natural_size] =
|
|
|
|
this._titleText.get_preferred_height(forWidth);
|
|
|
|
},
|
|
|
|
|
|
|
|
_bannerBoxAllocate: function(actor, box, flags) {
|
|
|
|
let [titleMinW, titleNatW] = this._titleText.get_preferred_width(-1);
|
|
|
|
let [titleMinH, titleNatH] = this._titleText.get_preferred_height(-1);
|
|
|
|
let [bannerMinW, bannerNatW] = this._bannerText.get_preferred_width(-1);
|
|
|
|
let [has_spacing, spacing] = this.actor.get_theme_node().get_length('spacing-columns', false);
|
|
|
|
if (!has_spacing)
|
|
|
|
spacing = 0;
|
|
|
|
let availWidth = box.x2 - box.x1;
|
|
|
|
|
|
|
|
let titleBox = new Clutter.ActorBox();
|
|
|
|
titleBox.x1 = titleBox.y1 = 0;
|
|
|
|
titleBox.x2 = Math.min(titleNatW, availWidth);
|
|
|
|
titleBox.y2 = titleNatH;
|
|
|
|
this._titleText.allocate(titleBox, flags);
|
|
|
|
|
2010-02-03 20:15:12 +00:00
|
|
|
if (titleBox.x2 + spacing > availWidth) {
|
|
|
|
this._bannerText.hide();
|
2010-02-01 17:10:38 +00:00
|
|
|
this._canPopOut = true;
|
2010-02-03 20:15:12 +00:00
|
|
|
} else {
|
|
|
|
let bannerBox = new Clutter.ActorBox();
|
|
|
|
bannerBox.x1 = titleBox.x2 + spacing;
|
|
|
|
bannerBox.y1 = 0;
|
|
|
|
bannerBox.x2 = Math.min(bannerBox.x1 + bannerNatW, availWidth);
|
|
|
|
bannerBox.y2 = titleNatH;
|
|
|
|
this._bannerText.show();
|
|
|
|
this._bannerText.allocate(bannerBox, flags);
|
|
|
|
|
|
|
|
if (bannerBox.x2 < bannerBox.x1 + bannerNatW)
|
|
|
|
this._canPopOut = true;
|
|
|
|
}
|
2010-02-01 17:10:38 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
popOut: function() {
|
|
|
|
if (!this._canPopOut)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
Tweener.addTween(this._bannerText,
|
|
|
|
{ opacity: 0,
|
|
|
|
time: ANIMATION_TIME,
|
|
|
|
transition: "easeOutQuad" });
|
|
|
|
return true;
|
|
|
|
},
|
|
|
|
|
|
|
|
popIn: function() {
|
|
|
|
if (!this._canPopOut)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
Tweener.addTween(this._bannerText,
|
|
|
|
{ opacity: 255,
|
|
|
|
time: ANIMATION_TIME,
|
|
|
|
transition: "easeOutQuad" });
|
|
|
|
return true;
|
2010-01-13 20:05:20 +00:00
|
|
|
}
|
|
|
|
};
|
2010-02-01 20:41:22 +00:00
|
|
|
Signals.addSignalMethods(Notification.prototype);
|
2010-01-13 20:05:20 +00:00
|
|
|
|
|
|
|
function Source(id, createIcon) {
|
|
|
|
this._init(id, createIcon);
|
|
|
|
}
|
|
|
|
|
|
|
|
Source.prototype = {
|
|
|
|
_init: function(id, createIcon) {
|
|
|
|
this.id = id;
|
2010-01-28 18:12:03 +00:00
|
|
|
this.text = null;
|
2010-01-13 20:05:20 +00:00
|
|
|
if (createIcon)
|
|
|
|
this.createIcon = createIcon;
|
|
|
|
},
|
|
|
|
|
|
|
|
// This can be overridden by a subclass, or by the createIcon
|
|
|
|
// parameter to _init()
|
|
|
|
createIcon: function(size) {
|
|
|
|
throw new Error('no implementation of createIcon in ' + this);
|
|
|
|
},
|
|
|
|
|
2010-02-01 20:23:49 +00:00
|
|
|
notify: function(notification) {
|
|
|
|
this.emit('notify', notification);
|
2010-01-13 20:05:20 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
clicked: function() {
|
|
|
|
this.emit('clicked');
|
|
|
|
},
|
|
|
|
|
|
|
|
destroy: function() {
|
|
|
|
this.emit('destroy');
|
|
|
|
}
|
|
|
|
};
|
|
|
|
Signals.addSignalMethods(Source.prototype);
|
|
|
|
|
|
|
|
function MessageTray() {
|
|
|
|
this._init();
|
|
|
|
}
|
|
|
|
|
|
|
|
MessageTray.prototype = {
|
|
|
|
_init: function() {
|
|
|
|
this.actor = new St.BoxLayout({ name: 'message-tray',
|
|
|
|
reactive: true });
|
|
|
|
|
2010-02-01 17:10:38 +00:00
|
|
|
this._notificationBin = new St.Bin({ reactive: true });
|
2010-01-28 17:04:26 +00:00
|
|
|
this.actor.add(this._notificationBin);
|
|
|
|
this._notificationBin.hide();
|
2010-01-13 20:05:20 +00:00
|
|
|
this._notificationQueue = [];
|
2010-02-01 20:23:49 +00:00
|
|
|
this._notification = null;
|
2010-01-13 20:05:20 +00:00
|
|
|
|
2010-01-28 17:04:26 +00:00
|
|
|
this._summaryBin = new St.BoxLayout();
|
|
|
|
this.actor.add(this._summaryBin);
|
2010-02-09 18:31:39 +00:00
|
|
|
this._summary = new St.BoxLayout({ name: 'summary-mode',
|
|
|
|
reactive: true });
|
2010-01-28 17:04:26 +00:00
|
|
|
this._summaryBin.add(this._summary, { x_align: St.Align.END,
|
|
|
|
x_fill: false,
|
|
|
|
expand: true });
|
2010-01-13 20:05:20 +00:00
|
|
|
|
2010-02-09 18:31:39 +00:00
|
|
|
|
|
|
|
this._summary.connect('enter-event',
|
|
|
|
Lang.bind(this, this._showMessageTray));
|
|
|
|
|
2010-01-13 20:05:20 +00:00
|
|
|
this.actor.connect('enter-event',
|
2010-02-09 18:31:39 +00:00
|
|
|
Lang.bind(this, function() {
|
|
|
|
if (this._state == MessageTrayState.NOTIFICATION || this._state == MessageTrayState.SUMMARY)
|
|
|
|
this._showMessageTray();
|
|
|
|
}));
|
|
|
|
|
2010-01-13 20:05:20 +00:00
|
|
|
this.actor.connect('leave-event',
|
2010-02-09 18:31:39 +00:00
|
|
|
Lang.bind(this, this._hideMessageTray));
|
2010-01-28 18:39:00 +00:00
|
|
|
this._state = MessageTrayState.HIDDEN;
|
2010-01-13 20:05:20 +00:00
|
|
|
this.actor.show();
|
2010-01-28 17:04:26 +00:00
|
|
|
Main.chrome.addActor(this.actor, { affectsStruts: false });
|
2010-02-01 17:10:38 +00:00
|
|
|
Main.chrome.trackActor(this._notificationBin, { affectsStruts: false });
|
2010-01-13 20:05:20 +00:00
|
|
|
|
2010-01-28 17:04:26 +00:00
|
|
|
global.connect('screen-size-changed',
|
|
|
|
Lang.bind(this, this._setSizePosition));
|
|
|
|
this._setSizePosition();
|
2010-01-13 20:05:20 +00:00
|
|
|
|
|
|
|
this._sources = {};
|
|
|
|
this._icons = {};
|
|
|
|
},
|
|
|
|
|
2010-01-25 18:28:35 +00:00
|
|
|
_setSizePosition: function() {
|
|
|
|
let primary = global.get_primary_monitor();
|
2010-02-02 13:02:32 +00:00
|
|
|
this.actor.x = primary.x;
|
|
|
|
this.actor.y = primary.y + primary.height - 1;
|
2010-01-25 18:28:35 +00:00
|
|
|
this.actor.width = primary.width;
|
2010-01-28 17:04:26 +00:00
|
|
|
|
|
|
|
let third = Math.floor(this.actor.width / 3);
|
|
|
|
this._notificationBin.x = third;
|
|
|
|
this._notificationBin.width = third;
|
|
|
|
this._summaryBin.x = this.actor.width - third;
|
|
|
|
this._summaryBin.width = third;
|
2010-01-25 18:28:35 +00:00
|
|
|
},
|
|
|
|
|
2010-01-13 20:05:20 +00:00
|
|
|
contains: function(source) {
|
|
|
|
return this._sources.hasOwnProperty(source.id);
|
|
|
|
},
|
|
|
|
|
|
|
|
add: function(source) {
|
|
|
|
if (this.contains(source)) {
|
|
|
|
log('Trying to re-add source ' + source.id);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
let iconBox = new St.Bin({ reactive: true });
|
|
|
|
iconBox.child = source.createIcon(ICON_SIZE);
|
|
|
|
this._summary.insert_actor(iconBox, 0);
|
|
|
|
this._icons[source.id] = iconBox;
|
|
|
|
this._sources[source.id] = source;
|
|
|
|
|
2010-01-28 18:12:03 +00:00
|
|
|
source.connect('notify', Lang.bind(this, this._onNotify));
|
|
|
|
|
2010-01-13 20:05:20 +00:00
|
|
|
iconBox.connect('button-release-event', Lang.bind(this,
|
|
|
|
function () {
|
|
|
|
source.clicked();
|
|
|
|
}));
|
|
|
|
|
|
|
|
source.connect('destroy', Lang.bind(this,
|
|
|
|
function () {
|
|
|
|
this.remove(source);
|
|
|
|
}));
|
|
|
|
},
|
|
|
|
|
|
|
|
remove: function(source) {
|
|
|
|
if (!this.contains(source))
|
|
|
|
return;
|
|
|
|
|
2010-01-28 18:39:00 +00:00
|
|
|
// remove all notifications with this source from the queue
|
|
|
|
let newNotificationQueue = [];
|
|
|
|
for (let i = 0; i < this._notificationQueue.length; i++) {
|
|
|
|
if (this._notificationQueue[i].source != source)
|
|
|
|
newNotificationQueue.push(this._notificationQueue[i]);
|
|
|
|
}
|
|
|
|
this._notificationQueue = newNotificationQueue;
|
|
|
|
|
|
|
|
// Update state if we are showing a notification from the removed source
|
|
|
|
if (this._state == MessageTrayState.NOTIFICATION &&
|
2010-02-01 20:23:49 +00:00
|
|
|
this._notification.source == source)
|
2010-01-28 18:39:00 +00:00
|
|
|
this._updateState();
|
|
|
|
|
2010-01-13 20:05:20 +00:00
|
|
|
this._summary.remove_actor(this._icons[source.id]);
|
|
|
|
delete this._icons[source.id];
|
|
|
|
delete this._sources[source.id];
|
|
|
|
},
|
|
|
|
|
|
|
|
getSource: function(id) {
|
|
|
|
return this._sources[id];
|
|
|
|
},
|
|
|
|
|
2010-02-01 20:23:49 +00:00
|
|
|
_onNotify: function(source, notification) {
|
|
|
|
this._notificationQueue.push(notification);
|
2010-01-28 18:39:00 +00:00
|
|
|
|
|
|
|
if (this._state == MessageTrayState.HIDDEN)
|
2010-02-02 15:31:38 +00:00
|
|
|
this._updateState();
|
2010-01-28 18:12:03 +00:00
|
|
|
},
|
|
|
|
|
2010-02-09 18:31:39 +00:00
|
|
|
_showMessageTray: function() {
|
2010-01-28 18:39:00 +00:00
|
|
|
// Don't hide the message tray after a timeout if the user has moved
|
|
|
|
// the mouse over it.
|
|
|
|
// We might have a timeout in place if the user moved the mouse away
|
|
|
|
// from the message tray for a very short period of time or if we are
|
|
|
|
// showing a notification.
|
|
|
|
if (this._updateTimeoutId > 0)
|
|
|
|
Mainloop.source_remove(this._updateTimeoutId);
|
|
|
|
|
|
|
|
if (this._state == MessageTrayState.HIDDEN)
|
|
|
|
this._updateState();
|
2010-02-01 17:10:38 +00:00
|
|
|
else if (this._state == MessageTrayState.NOTIFICATION) {
|
2010-02-01 20:23:49 +00:00
|
|
|
if (this._notification.popOut()) {
|
2010-02-01 17:10:38 +00:00
|
|
|
Tweener.addTween(this._notificationBin,
|
|
|
|
{ y: this.actor.height - this._notificationBin.height,
|
|
|
|
time: ANIMATION_TIME,
|
|
|
|
transition: "easeOutQuad"
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
2010-01-28 18:39:00 +00:00
|
|
|
},
|
2010-01-13 20:05:20 +00:00
|
|
|
|
2010-02-09 18:31:39 +00:00
|
|
|
_hideMessageTray: function() {
|
2010-01-28 18:39:00 +00:00
|
|
|
if (this._state == MessageTrayState.HIDDEN)
|
2010-01-13 20:05:20 +00:00
|
|
|
return;
|
|
|
|
|
2010-01-28 18:39:00 +00:00
|
|
|
// We wait just a little before hiding the message tray in case the
|
|
|
|
// user will quickly move the mouse back over it.
|
|
|
|
let timeout = MESSAGE_TRAY_TIMEOUT * 1000;
|
|
|
|
this._updateTimeoutId = Mainloop.timeout_add(timeout, Lang.bind(this, this._updateState));
|
2010-01-13 20:05:20 +00:00
|
|
|
},
|
|
|
|
|
2010-01-28 18:39:00 +00:00
|
|
|
// As tray, notification box and summary view are all animated separately,
|
|
|
|
// but dependant on each other's states, it appears less confusing
|
|
|
|
// handling all transitions in a state machine rather than spread out
|
|
|
|
// over different event handlers.
|
|
|
|
//
|
|
|
|
// State changes are triggered when
|
|
|
|
// - a notification arrives (see _onNotify())
|
2010-02-09 18:31:39 +00:00
|
|
|
// - the mouse enters the tray (see _showMessageTray())
|
|
|
|
// - the mouse leaves the tray (see _hideMessageTray())
|
2010-01-28 18:39:00 +00:00
|
|
|
// - a timeout expires (usually set up in a previous invocation of this function)
|
|
|
|
_updateState: function() {
|
|
|
|
if (this._updateTimeoutId > 0)
|
|
|
|
Mainloop.source_remove(this._updateTimeoutId);
|
|
|
|
|
|
|
|
this._updateTimeoutId = 0;
|
|
|
|
let timeout = -1;
|
|
|
|
|
|
|
|
switch (this._state) {
|
|
|
|
case MessageTrayState.HIDDEN:
|
|
|
|
if (this._notificationQueue.length > 0) {
|
|
|
|
this._showNotification();
|
|
|
|
this._showTray();
|
|
|
|
this._state = MessageTrayState.NOTIFICATION;
|
|
|
|
// Because we set up the timeout before we do the animation,
|
|
|
|
// we add ANIMATION_TIME to NOTIFICATION_TIMEOUT, so that
|
|
|
|
// NOTIFICATION_TIMEOUT represents the time the notifiation
|
|
|
|
// is fully shown.
|
|
|
|
timeout = (ANIMATION_TIME + NOTIFICATION_TIMEOUT) * 1000;
|
2010-02-02 15:31:38 +00:00
|
|
|
} else {
|
2010-01-28 18:39:00 +00:00
|
|
|
this._showSummary();
|
|
|
|
this._showTray();
|
|
|
|
this._state = MessageTrayState.SUMMARY;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case MessageTrayState.NOTIFICATION:
|
|
|
|
if (this._notificationQueue.length > 0) {
|
|
|
|
this._hideNotification();
|
|
|
|
this._state = MessageTrayState.TRAY_ONLY;
|
|
|
|
timeout = ANIMATION_TIME * 1000;
|
|
|
|
} else {
|
|
|
|
this._hideNotification();
|
|
|
|
this._showSummary();
|
|
|
|
this._state = MessageTrayState.SUMMARY;
|
|
|
|
timeout = (ANIMATION_TIME + SUMMARY_TIMEOUT) * 1000;
|
|
|
|
}
|
2010-02-02 15:31:38 +00:00
|
|
|
break;
|
2010-01-28 18:39:00 +00:00
|
|
|
case MessageTrayState.SUMMARY:
|
|
|
|
if (this._notificationQueue.length > 0) {
|
|
|
|
this._hideSummary();
|
|
|
|
this._showNotification();
|
|
|
|
this._state = MessageTrayState.NOTIFICATION;
|
|
|
|
timeout = (ANIMATION_TIME + NOTIFICATION_TIMEOUT) * 1000;
|
|
|
|
} else {
|
|
|
|
this._hideSummary();
|
|
|
|
this._hideTray();
|
|
|
|
this._state = MessageTrayState.HIDDEN;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case MessageTrayState.TRAY_ONLY:
|
|
|
|
this._showNotification();
|
|
|
|
this._state = MessageTrayState.NOTIFICATION;
|
|
|
|
timeout = (ANIMATION_TIME + NOTIFICATION_TIMEOUT) * 1000;
|
|
|
|
break;
|
|
|
|
}
|
2010-01-13 20:05:20 +00:00
|
|
|
|
2010-01-28 18:39:00 +00:00
|
|
|
if (timeout > -1)
|
|
|
|
this._updateTimeoutId = Mainloop.timeout_add(timeout, Lang.bind(this, this._updateState));
|
2010-01-13 20:05:20 +00:00
|
|
|
},
|
|
|
|
|
2010-01-28 18:39:00 +00:00
|
|
|
_showTray: function() {
|
2010-01-13 20:05:20 +00:00
|
|
|
let primary = global.get_primary_monitor();
|
|
|
|
Tweener.addTween(this.actor,
|
2010-02-02 13:02:32 +00:00
|
|
|
{ y: primary.y + primary.height - this.actor.height,
|
2010-01-13 20:05:20 +00:00
|
|
|
time: ANIMATION_TIME,
|
|
|
|
transition: "easeOutQuad"
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
2010-01-28 18:39:00 +00:00
|
|
|
_hideTray: function() {
|
2010-01-13 20:05:20 +00:00
|
|
|
let primary = global.get_primary_monitor();
|
|
|
|
|
|
|
|
Tweener.addTween(this.actor,
|
2010-02-02 13:02:32 +00:00
|
|
|
{ y: primary.y + primary.height - 1,
|
2010-01-13 20:05:20 +00:00
|
|
|
time: ANIMATION_TIME,
|
2010-01-28 18:39:00 +00:00
|
|
|
transition: "easeOutQuad"
|
2010-01-13 20:05:20 +00:00
|
|
|
});
|
|
|
|
return false;
|
|
|
|
},
|
|
|
|
|
2010-01-28 18:39:00 +00:00
|
|
|
_showNotification: function() {
|
2010-02-01 20:23:49 +00:00
|
|
|
this._notification = this._notificationQueue.shift();
|
|
|
|
this._notificationBin.child = this._notification.actor;
|
2010-01-13 20:05:20 +00:00
|
|
|
|
2010-01-28 17:04:26 +00:00
|
|
|
this._notificationBin.opacity = 0;
|
|
|
|
this._notificationBin.y = this.actor.height;
|
|
|
|
this._notificationBin.show();
|
2010-01-13 20:05:20 +00:00
|
|
|
|
2010-01-28 17:04:26 +00:00
|
|
|
Tweener.addTween(this._notificationBin,
|
|
|
|
{ y: 0,
|
2010-01-28 18:39:00 +00:00
|
|
|
opacity: 255,
|
|
|
|
time: ANIMATION_TIME,
|
|
|
|
transition: "easeOutQuad" });
|
|
|
|
},
|
2010-01-13 20:05:20 +00:00
|
|
|
|
2010-01-28 18:39:00 +00:00
|
|
|
_hideNotification: function() {
|
2010-02-01 20:23:49 +00:00
|
|
|
this._notification.popIn();
|
2010-02-01 17:10:38 +00:00
|
|
|
|
2010-01-28 17:04:26 +00:00
|
|
|
Tweener.addTween(this._notificationBin,
|
|
|
|
{ y: this.actor.height,
|
2010-01-28 18:39:00 +00:00
|
|
|
opacity: 0,
|
|
|
|
time: ANIMATION_TIME,
|
|
|
|
transition: "easeOutQuad",
|
|
|
|
onComplete: Lang.bind(this, function() {
|
2010-01-28 17:04:26 +00:00
|
|
|
this._notificationBin.hide();
|
2010-02-01 20:23:49 +00:00
|
|
|
this._notificationBin.child = null;
|
|
|
|
this._notification = null;
|
2010-01-28 18:39:00 +00:00
|
|
|
})});
|
|
|
|
},
|
2010-01-13 20:05:20 +00:00
|
|
|
|
2010-01-28 18:39:00 +00:00
|
|
|
_showSummary: function() {
|
2010-02-02 13:02:32 +00:00
|
|
|
let primary = global.get_primary_monitor();
|
2010-01-28 18:39:00 +00:00
|
|
|
this._summaryBin.opacity = 0;
|
|
|
|
this._summaryBin.y = this.actor.height;
|
|
|
|
Tweener.addTween(this._summaryBin,
|
2010-02-09 18:31:39 +00:00
|
|
|
{ y: 0,
|
2010-01-28 18:39:00 +00:00
|
|
|
opacity: 255,
|
|
|
|
time: ANIMATION_TIME,
|
|
|
|
transition: "easeOutQuad" });
|
|
|
|
},
|
|
|
|
|
|
|
|
_hideSummary: function() {
|
|
|
|
Tweener.addTween(this._summaryBin,
|
2010-02-09 18:31:39 +00:00
|
|
|
{ opacity: 0,
|
2010-01-28 18:39:00 +00:00
|
|
|
time: ANIMATION_TIME,
|
2010-02-09 18:31:39 +00:00
|
|
|
transition: "easeOutQuad"
|
|
|
|
});
|
2010-01-28 18:39:00 +00:00
|
|
|
}
|
2010-01-13 20:05:20 +00:00
|
|
|
};
|