2011-09-28 09:16:26 -04:00
|
|
|
// -*- mode: js; js-indent-level: 4; indent-tabs-mode: nil -*-
|
2009-09-30 10:02:08 -04:00
|
|
|
|
2014-12-05 10:24:35 -05:00
|
|
|
const Atk = imports.gi.Atk;
|
2009-10-01 15:18:20 -04:00
|
|
|
const Clutter = imports.gi.Clutter;
|
2010-05-05 17:05:42 -04:00
|
|
|
const Gio = imports.gi.Gio;
|
2013-02-17 09:52:53 -05:00
|
|
|
const GLib = imports.gi.GLib;
|
2015-02-16 19:12:44 -05:00
|
|
|
const GObject = imports.gi.GObject;
|
2014-12-05 10:24:35 -05:00
|
|
|
const Gtk = imports.gi.Gtk;
|
2009-09-30 10:02:08 -04:00
|
|
|
const Lang = imports.lang;
|
|
|
|
const St = imports.gi.St;
|
2011-01-28 16:35:46 -05:00
|
|
|
const Signals = imports.signals;
|
2010-05-27 03:31:46 -04:00
|
|
|
const Pango = imports.gi.Pango;
|
2010-11-29 16:41:05 -05:00
|
|
|
const Gettext_gtk30 = imports.gettext.domain('gtk30');
|
2011-01-28 16:35:46 -05:00
|
|
|
const Mainloop = imports.mainloop;
|
2015-02-16 13:40:00 -05:00
|
|
|
const Meta = imports.gi.Meta;
|
2011-01-28 16:35:46 -05:00
|
|
|
const Shell = imports.gi.Shell;
|
2009-09-30 10:02:08 -04:00
|
|
|
|
2014-12-05 10:24:35 -05:00
|
|
|
const Main = imports.ui.main;
|
2015-02-11 14:41:56 -05:00
|
|
|
const MessageTray = imports.ui.messageTray;
|
2014-12-05 10:24:35 -05:00
|
|
|
const Tweener = imports.ui.tweener;
|
2015-02-16 13:40:00 -05:00
|
|
|
const Util = imports.misc.util;
|
|
|
|
|
2009-09-30 10:02:08 -04:00
|
|
|
const MSECS_IN_DAY = 24 * 60 * 60 * 1000;
|
2010-05-05 17:05:42 -04:00
|
|
|
const SHOW_WEEKDATE_KEY = 'show-weekdate';
|
2014-09-17 21:32:13 -04:00
|
|
|
const ELLIPSIS_CHAR = '\u2026';
|
2009-09-30 10:02:08 -04:00
|
|
|
|
2015-06-02 10:57:06 -04:00
|
|
|
const MESSAGE_ICON_SIZE = 32;
|
2015-06-02 09:46:37 -04:00
|
|
|
|
2014-12-05 10:24:35 -05:00
|
|
|
const MESSAGE_ANIMATION_TIME = 0.1;
|
|
|
|
|
2015-02-16 19:12:44 -05:00
|
|
|
const DEFAULT_EXPAND_LINES = 6;
|
|
|
|
|
2014-04-26 19:06:13 -04:00
|
|
|
// alias to prevent xgettext from picking up strings translated in GTK+
|
|
|
|
const gtk30_ = Gettext_gtk30.gettext;
|
2015-03-02 22:36:37 -05:00
|
|
|
const NC_ = function(context, str) { return context + '\u0004' + str; };
|
2014-04-26 19:06:13 -04:00
|
|
|
|
2011-01-28 16:35:46 -05:00
|
|
|
function _sameYear(dateA, dateB) {
|
|
|
|
return (dateA.getYear() == dateB.getYear());
|
|
|
|
}
|
|
|
|
|
2013-12-11 20:05:21 -05:00
|
|
|
function _sameMonth(dateA, dateB) {
|
|
|
|
return _sameYear(dateA, dateB) && (dateA.getMonth() == dateB.getMonth());
|
|
|
|
}
|
|
|
|
|
|
|
|
function _sameDay(dateA, dateB) {
|
|
|
|
return _sameMonth(dateA, dateB) && (dateA.getDate() == dateB.getDate());
|
|
|
|
}
|
|
|
|
|
2015-03-11 17:36:00 -04:00
|
|
|
function _isToday(date) {
|
|
|
|
return _sameDay(new Date(), date);
|
|
|
|
}
|
|
|
|
|
2011-01-28 16:35:46 -05:00
|
|
|
function _isWorkDay(date) {
|
2011-11-23 11:48:00 -05:00
|
|
|
/* Translators: Enter 0-6 (Sunday-Saturday) for non-work days. Examples: "0" (Sunday) "6" (Saturday) "06" (Sunday and Saturday). */
|
|
|
|
let days = C_('calendar-no-work', "06");
|
|
|
|
return days.indexOf(date.getDay().toString()) == -1;
|
2011-01-28 16:35:46 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
function _getBeginningOfDay(date) {
|
|
|
|
let ret = new Date(date.getTime());
|
|
|
|
ret.setHours(0);
|
|
|
|
ret.setMinutes(0);
|
|
|
|
ret.setSeconds(0);
|
|
|
|
ret.setMilliseconds(0);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
function _getEndOfDay(date) {
|
|
|
|
let ret = new Date(date.getTime());
|
|
|
|
ret.setHours(23);
|
|
|
|
ret.setMinutes(59);
|
|
|
|
ret.setSeconds(59);
|
|
|
|
ret.setMilliseconds(999);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
function _getCalendarDayAbbreviation(dayNumber) {
|
|
|
|
let abbreviations = [
|
|
|
|
/* Translators: Calendar grid abbreviation for Sunday.
|
|
|
|
*
|
2011-02-03 06:12:57 -05:00
|
|
|
* NOTE: These grid abbreviations are always shown together
|
|
|
|
* and in order, e.g. "S M T W T F S".
|
2011-01-28 16:35:46 -05:00
|
|
|
*/
|
2015-03-02 22:36:37 -05:00
|
|
|
NC_("grid sunday", "S"),
|
2011-01-28 16:35:46 -05:00
|
|
|
/* Translators: Calendar grid abbreviation for Monday */
|
2015-03-02 22:36:37 -05:00
|
|
|
NC_("grid monday", "M"),
|
2011-01-28 16:35:46 -05:00
|
|
|
/* Translators: Calendar grid abbreviation for Tuesday */
|
2015-03-02 22:36:37 -05:00
|
|
|
NC_("grid tuesday", "T"),
|
2011-01-28 16:35:46 -05:00
|
|
|
/* Translators: Calendar grid abbreviation for Wednesday */
|
2015-03-02 22:36:37 -05:00
|
|
|
NC_("grid wednesday", "W"),
|
2011-01-28 16:35:46 -05:00
|
|
|
/* Translators: Calendar grid abbreviation for Thursday */
|
2015-03-02 22:36:37 -05:00
|
|
|
NC_("grid thursday", "T"),
|
2011-01-28 16:35:46 -05:00
|
|
|
/* Translators: Calendar grid abbreviation for Friday */
|
2015-03-02 22:36:37 -05:00
|
|
|
NC_("grid friday", "F"),
|
2011-01-28 16:35:46 -05:00
|
|
|
/* Translators: Calendar grid abbreviation for Saturday */
|
2015-03-02 22:36:37 -05:00
|
|
|
NC_("grid saturday", "S")
|
2011-01-28 16:35:46 -05:00
|
|
|
];
|
2015-03-02 22:36:37 -05:00
|
|
|
return Shell.util_translate_time_string(abbreviations[dayNumber]);
|
2011-01-28 16:35:46 -05:00
|
|
|
}
|
|
|
|
|
2015-02-16 13:40:00 -05:00
|
|
|
function _fixMarkup(text, allowMarkup) {
|
|
|
|
if (allowMarkup) {
|
|
|
|
// Support &, ", ', < and >, escape all other
|
|
|
|
// occurrences of '&'.
|
|
|
|
let _text = text.replace(/&(?!amp;|quot;|apos;|lt;|gt;)/g, '&');
|
|
|
|
|
|
|
|
// Support <b>, <i>, and <u>, escape anything else
|
|
|
|
// so it displays as raw markup.
|
|
|
|
_text = _text.replace(/<(?!\/?[biu]>)/g, '<');
|
|
|
|
|
|
|
|
try {
|
|
|
|
Pango.parse_markup(_text, -1, '');
|
|
|
|
return _text;
|
|
|
|
} catch (e) {}
|
|
|
|
}
|
|
|
|
|
|
|
|
// !allowMarkup, or invalid markup
|
|
|
|
return GLib.markup_escape_text(text, -1);
|
|
|
|
}
|
|
|
|
|
|
|
|
const URLHighlighter = new Lang.Class({
|
|
|
|
Name: 'URLHighlighter',
|
|
|
|
|
|
|
|
_init: function(text, lineWrap, allowMarkup) {
|
|
|
|
if (!text)
|
|
|
|
text = '';
|
2015-03-17 11:46:08 -04:00
|
|
|
this.actor = new St.Label({ reactive: true, style_class: 'url-highlighter',
|
|
|
|
x_expand: true, x_align: Clutter.ActorAlign.START });
|
2015-02-16 13:40:00 -05:00
|
|
|
this._linkColor = '#ccccff';
|
|
|
|
this.actor.connect('style-changed', Lang.bind(this, function() {
|
|
|
|
let [hasColor, color] = this.actor.get_theme_node().lookup_color('link-color', false);
|
|
|
|
if (hasColor) {
|
|
|
|
let linkColor = color.to_string().substr(0, 7);
|
|
|
|
if (linkColor != this._linkColor) {
|
|
|
|
this._linkColor = linkColor;
|
|
|
|
this._highlightUrls();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}));
|
|
|
|
this.actor.clutter_text.line_wrap = lineWrap;
|
|
|
|
this.actor.clutter_text.line_wrap_mode = Pango.WrapMode.WORD_CHAR;
|
|
|
|
|
|
|
|
this.setMarkup(text, allowMarkup);
|
|
|
|
this.actor.connect('button-press-event', Lang.bind(this, function(actor, event) {
|
|
|
|
// Don't try to URL highlight when invisible.
|
|
|
|
// The MessageTray doesn't actually hide us, so
|
|
|
|
// we need to check for paint opacities as well.
|
|
|
|
if (!actor.visible || actor.get_paint_opacity() == 0)
|
|
|
|
return Clutter.EVENT_PROPAGATE;
|
|
|
|
|
|
|
|
// Keep Notification.actor from seeing this and taking
|
|
|
|
// a pointer grab, which would block our button-release-event
|
|
|
|
// handler, if an URL is clicked
|
|
|
|
return this._findUrlAtPos(event) != -1;
|
|
|
|
}));
|
|
|
|
this.actor.connect('button-release-event', Lang.bind(this, function (actor, event) {
|
|
|
|
if (!actor.visible || actor.get_paint_opacity() == 0)
|
|
|
|
return Clutter.EVENT_PROPAGATE;
|
|
|
|
|
|
|
|
let urlId = this._findUrlAtPos(event);
|
|
|
|
if (urlId != -1) {
|
|
|
|
let url = this._urls[urlId].url;
|
|
|
|
if (url.indexOf(':') == -1)
|
|
|
|
url = 'http://' + url;
|
|
|
|
|
|
|
|
Gio.app_info_launch_default_for_uri(url, global.create_app_launch_context(0, -1));
|
|
|
|
return Clutter.EVENT_STOP;
|
|
|
|
}
|
|
|
|
return Clutter.EVENT_PROPAGATE;
|
|
|
|
}));
|
|
|
|
this.actor.connect('motion-event', Lang.bind(this, function(actor, event) {
|
|
|
|
if (!actor.visible || actor.get_paint_opacity() == 0)
|
|
|
|
return Clutter.EVENT_PROPAGATE;
|
|
|
|
|
|
|
|
let urlId = this._findUrlAtPos(event);
|
|
|
|
if (urlId != -1 && !this._cursorChanged) {
|
|
|
|
global.screen.set_cursor(Meta.Cursor.POINTING_HAND);
|
|
|
|
this._cursorChanged = true;
|
|
|
|
} else if (urlId == -1) {
|
|
|
|
global.screen.set_cursor(Meta.Cursor.DEFAULT);
|
|
|
|
this._cursorChanged = false;
|
|
|
|
}
|
|
|
|
return Clutter.EVENT_PROPAGATE;
|
|
|
|
}));
|
|
|
|
this.actor.connect('leave-event', Lang.bind(this, function() {
|
|
|
|
if (!this.actor.visible || this.actor.get_paint_opacity() == 0)
|
|
|
|
return Clutter.EVENT_PROPAGATE;
|
|
|
|
|
|
|
|
if (this._cursorChanged) {
|
|
|
|
this._cursorChanged = false;
|
|
|
|
global.screen.set_cursor(Meta.Cursor.DEFAULT);
|
|
|
|
}
|
|
|
|
return Clutter.EVENT_PROPAGATE;
|
|
|
|
}));
|
|
|
|
},
|
|
|
|
|
|
|
|
setMarkup: function(text, allowMarkup) {
|
|
|
|
text = text ? _fixMarkup(text, allowMarkup) : '';
|
|
|
|
this._text = text;
|
|
|
|
|
|
|
|
this.actor.clutter_text.set_markup(text);
|
|
|
|
/* clutter_text.text contain text without markup */
|
|
|
|
this._urls = Util.findUrls(this.actor.clutter_text.text);
|
|
|
|
this._highlightUrls();
|
|
|
|
},
|
|
|
|
|
|
|
|
_highlightUrls: function() {
|
|
|
|
// text here contain markup
|
|
|
|
let urls = Util.findUrls(this._text);
|
|
|
|
let markup = '';
|
|
|
|
let pos = 0;
|
|
|
|
for (let i = 0; i < urls.length; i++) {
|
|
|
|
let url = urls[i];
|
|
|
|
let str = this._text.substr(pos, url.pos - pos);
|
|
|
|
markup += str + '<span foreground="' + this._linkColor + '"><u>' + url.url + '</u></span>';
|
|
|
|
pos = url.pos + url.url.length;
|
|
|
|
}
|
|
|
|
markup += this._text.substr(pos);
|
|
|
|
this.actor.clutter_text.set_markup(markup);
|
|
|
|
},
|
|
|
|
|
|
|
|
_findUrlAtPos: function(event) {
|
|
|
|
let success;
|
|
|
|
let [x, y] = event.get_coords();
|
|
|
|
[success, x, y] = this.actor.transform_stage_point(x, y);
|
|
|
|
let find_pos = -1;
|
|
|
|
for (let i = 0; i < this.actor.clutter_text.text.length; i++) {
|
|
|
|
let [success, px, py, line_height] = this.actor.clutter_text.position_to_coords(i);
|
|
|
|
if (py > y || py + line_height < y || x < px)
|
|
|
|
continue;
|
|
|
|
find_pos = i;
|
|
|
|
}
|
|
|
|
if (find_pos != -1) {
|
|
|
|
for (let i = 0; i < this._urls.length; i++)
|
|
|
|
if (find_pos >= this._urls[i].pos &&
|
|
|
|
this._urls[i].pos + this._urls[i].url.length > find_pos)
|
|
|
|
return i;
|
|
|
|
}
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2011-01-28 16:35:46 -05:00
|
|
|
// Abstraction for an appointment/event in a calendar
|
|
|
|
|
2011-11-20 12:56:27 -05:00
|
|
|
const CalendarEvent = new Lang.Class({
|
|
|
|
Name: 'CalendarEvent',
|
2011-01-28 16:35:46 -05:00
|
|
|
|
2015-03-06 17:58:33 -05:00
|
|
|
_init: function(id, date, end, summary, allDay) {
|
|
|
|
this.id = id;
|
2011-01-28 16:35:46 -05:00
|
|
|
this.date = date;
|
2011-02-25 17:42:25 -05:00
|
|
|
this.end = end;
|
2011-01-28 16:35:46 -05:00
|
|
|
this.summary = summary;
|
|
|
|
this.allDay = allDay;
|
|
|
|
}
|
2011-11-20 12:56:27 -05:00
|
|
|
});
|
2011-01-28 16:35:46 -05:00
|
|
|
|
|
|
|
// Interface for appointments/events - e.g. the contents of a calendar
|
|
|
|
//
|
|
|
|
|
|
|
|
// First, an implementation with no events
|
2011-11-20 12:56:27 -05:00
|
|
|
const EmptyEventSource = new Lang.Class({
|
|
|
|
Name: 'EmptyEventSource',
|
2009-09-30 10:02:08 -04:00
|
|
|
|
2011-01-28 16:35:46 -05:00
|
|
|
_init: function() {
|
2012-10-23 12:41:24 -04:00
|
|
|
this.isLoading = false;
|
2013-03-04 11:04:28 -05:00
|
|
|
this.isDummy = true;
|
2012-10-29 11:37:07 -04:00
|
|
|
this.hasCalendars = false;
|
2013-03-04 11:04:28 -05:00
|
|
|
},
|
|
|
|
|
|
|
|
destroy: function() {
|
2011-01-28 16:35:46 -05:00
|
|
|
},
|
|
|
|
|
|
|
|
requestRange: function(begin, end) {
|
|
|
|
},
|
|
|
|
|
|
|
|
getEvents: function(begin, end) {
|
|
|
|
let result = [];
|
|
|
|
return result;
|
|
|
|
},
|
|
|
|
|
|
|
|
hasEvents: function(day) {
|
|
|
|
return false;
|
|
|
|
}
|
2011-11-20 12:56:27 -05:00
|
|
|
});
|
2011-01-28 16:35:46 -05:00
|
|
|
Signals.addSignalMethods(EmptyEventSource.prototype);
|
|
|
|
|
2013-10-24 17:51:58 -04:00
|
|
|
const CalendarServerIface = '<node> \
|
|
|
|
<interface name="org.gnome.Shell.CalendarServer"> \
|
|
|
|
<method name="GetEvents"> \
|
|
|
|
<arg type="x" direction="in" /> \
|
|
|
|
<arg type="x" direction="in" /> \
|
|
|
|
<arg type="b" direction="in" /> \
|
|
|
|
<arg type="a(sssbxxa{sv})" direction="out" /> \
|
|
|
|
</method> \
|
|
|
|
<property name="HasCalendars" type="b" access="read" /> \
|
|
|
|
<signal name="Changed" /> \
|
|
|
|
</interface> \
|
|
|
|
</node>';
|
2011-08-16 08:28:53 -04:00
|
|
|
|
|
|
|
const CalendarServerInfo = Gio.DBusInterfaceInfo.new_for_xml(CalendarServerIface);
|
|
|
|
|
|
|
|
function CalendarServer() {
|
2013-02-17 09:52:53 -05:00
|
|
|
return new Gio.DBusProxy({ g_connection: Gio.DBus.session,
|
|
|
|
g_interface_name: CalendarServerInfo.name,
|
|
|
|
g_interface_info: CalendarServerInfo,
|
|
|
|
g_name: 'org.gnome.Shell.CalendarServer',
|
2012-10-29 11:37:07 -04:00
|
|
|
g_object_path: '/org/gnome/Shell/CalendarServer' });
|
2011-08-16 08:28:53 -04:00
|
|
|
}
|
2011-01-28 16:35:46 -05:00
|
|
|
|
2011-02-25 17:42:25 -05:00
|
|
|
function _datesEqual(a, b) {
|
|
|
|
if (a < b)
|
|
|
|
return false;
|
|
|
|
else if (a > b)
|
|
|
|
return false;
|
|
|
|
return true;
|
|
|
|
}
|
2011-01-28 16:35:46 -05:00
|
|
|
|
2011-02-25 17:42:25 -05:00
|
|
|
function _dateIntervalsOverlap(a0, a1, b0, b1)
|
|
|
|
{
|
|
|
|
if (a1 <= b0)
|
|
|
|
return false;
|
|
|
|
else if (b1 <= a0)
|
|
|
|
return false;
|
|
|
|
else
|
|
|
|
return true;
|
|
|
|
}
|
2011-01-28 16:35:46 -05:00
|
|
|
|
2011-11-20 12:56:27 -05:00
|
|
|
// an implementation that reads data from a session bus service
|
|
|
|
const DBusEventSource = new Lang.Class({
|
|
|
|
Name: 'DBusEventSource',
|
2011-01-28 16:35:46 -05:00
|
|
|
|
2011-08-16 08:28:53 -04:00
|
|
|
_init: function() {
|
2011-02-25 17:42:25 -05:00
|
|
|
this._resetCache();
|
2012-10-23 12:41:24 -04:00
|
|
|
this.isLoading = false;
|
2013-03-04 11:04:28 -05:00
|
|
|
this.isDummy = false;
|
2011-01-28 16:35:46 -05:00
|
|
|
|
2013-02-17 09:52:53 -05:00
|
|
|
this._initialized = false;
|
2011-08-16 08:28:53 -04:00
|
|
|
this._dbusProxy = new CalendarServer();
|
2013-02-17 09:52:53 -05:00
|
|
|
this._dbusProxy.init_async(GLib.PRIORITY_DEFAULT, null, Lang.bind(this, function(object, result) {
|
2014-12-10 19:41:48 -05:00
|
|
|
let loaded = false;
|
|
|
|
|
2013-02-17 09:52:53 -05:00
|
|
|
try {
|
|
|
|
this._dbusProxy.init_finish(result);
|
2014-12-10 19:41:48 -05:00
|
|
|
loaded = true;
|
2013-02-17 09:52:53 -05:00
|
|
|
} catch(e) {
|
2014-12-10 19:41:48 -05:00
|
|
|
if (e.matches(Gio.DBusError, Gio.DBusError.TIMED_OUT)) {
|
|
|
|
// Ignore timeouts and install signals as normal, because with high
|
|
|
|
// probability the service will appear later on, and we will get a
|
|
|
|
// NameOwnerChanged which will finish loading
|
|
|
|
//
|
|
|
|
// (But still _initialized to false, because the proxy does not know
|
|
|
|
// about the HasCalendars property and would cause an exception trying
|
|
|
|
// to read it)
|
|
|
|
} else {
|
|
|
|
log('Error loading calendars: ' + e.message);
|
|
|
|
return;
|
|
|
|
}
|
2013-02-17 09:52:53 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
this._dbusProxy.connectSignal('Changed', Lang.bind(this, this._onChanged));
|
2011-01-28 16:35:46 -05:00
|
|
|
|
2013-02-17 09:52:53 -05:00
|
|
|
this._dbusProxy.connect('notify::g-name-owner', Lang.bind(this, function() {
|
|
|
|
if (this._dbusProxy.g_name_owner)
|
|
|
|
this._onNameAppeared();
|
|
|
|
else
|
|
|
|
this._onNameVanished();
|
|
|
|
}));
|
|
|
|
|
2012-10-29 11:37:07 -04:00
|
|
|
this._dbusProxy.connect('g-properties-changed', Lang.bind(this, function() {
|
|
|
|
this.emit('notify::has-calendars');
|
|
|
|
}));
|
|
|
|
|
2014-12-10 19:41:48 -05:00
|
|
|
this._initialized = loaded;
|
|
|
|
if (loaded) {
|
|
|
|
this.emit('notify::has-calendars');
|
|
|
|
this._onNameAppeared();
|
|
|
|
}
|
2011-08-16 08:28:53 -04:00
|
|
|
}));
|
2011-02-25 17:42:25 -05:00
|
|
|
},
|
2011-01-28 16:35:46 -05:00
|
|
|
|
2013-03-04 11:04:28 -05:00
|
|
|
destroy: function() {
|
|
|
|
this._dbusProxy.run_dispose();
|
|
|
|
},
|
|
|
|
|
2012-10-29 11:37:07 -04:00
|
|
|
get hasCalendars() {
|
|
|
|
if (this._initialized)
|
|
|
|
return this._dbusProxy.HasCalendars;
|
|
|
|
else
|
|
|
|
return false;
|
|
|
|
},
|
|
|
|
|
2011-02-25 17:42:25 -05:00
|
|
|
_resetCache: function() {
|
|
|
|
this._events = [];
|
|
|
|
this._lastRequestBegin = null;
|
|
|
|
this._lastRequestEnd = null;
|
|
|
|
},
|
2011-01-28 16:35:46 -05:00
|
|
|
|
2011-02-25 17:42:25 -05:00
|
|
|
_onNameAppeared: function(owner) {
|
2014-12-10 19:41:48 -05:00
|
|
|
this._initialized = true;
|
2011-02-25 17:42:25 -05:00
|
|
|
this._resetCache();
|
|
|
|
this._loadEvents(true);
|
|
|
|
},
|
2011-01-28 16:35:46 -05:00
|
|
|
|
2011-02-25 17:42:25 -05:00
|
|
|
_onNameVanished: function(oldOwner) {
|
|
|
|
this._resetCache();
|
|
|
|
this.emit('changed');
|
|
|
|
},
|
2011-01-28 16:35:46 -05:00
|
|
|
|
2011-02-25 17:42:25 -05:00
|
|
|
_onChanged: function() {
|
|
|
|
this._loadEvents(false);
|
|
|
|
},
|
2011-01-28 16:35:46 -05:00
|
|
|
|
2012-10-23 08:32:27 -04:00
|
|
|
_onEventsReceived: function(results, error) {
|
2011-02-25 17:42:25 -05:00
|
|
|
let newEvents = [];
|
2012-10-23 08:32:27 -04:00
|
|
|
let appointments = results ? results[0] : null;
|
2011-02-25 17:42:25 -05:00
|
|
|
if (appointments != null) {
|
|
|
|
for (let n = 0; n < appointments.length; n++) {
|
|
|
|
let a = appointments[n];
|
|
|
|
let date = new Date(a[4] * 1000);
|
|
|
|
let end = new Date(a[5] * 1000);
|
2015-03-06 17:58:33 -05:00
|
|
|
let id = a[0];
|
2011-02-25 17:42:25 -05:00
|
|
|
let summary = a[1];
|
|
|
|
let allDay = a[3];
|
2015-03-06 17:58:33 -05:00
|
|
|
let event = new CalendarEvent(id, date, end, summary, allDay);
|
2011-02-25 17:42:25 -05:00
|
|
|
newEvents.push(event);
|
|
|
|
}
|
|
|
|
newEvents.sort(function(event1, event2) {
|
|
|
|
return event1.date.getTime() - event2.date.getTime();
|
|
|
|
});
|
2011-01-28 16:35:46 -05:00
|
|
|
}
|
|
|
|
|
2011-02-25 17:42:25 -05:00
|
|
|
this._events = newEvents;
|
2012-10-23 12:41:24 -04:00
|
|
|
this.isLoading = false;
|
2011-02-25 17:42:25 -05:00
|
|
|
this.emit('changed');
|
2011-01-28 16:35:46 -05:00
|
|
|
},
|
|
|
|
|
2011-02-25 17:42:25 -05:00
|
|
|
_loadEvents: function(forceReload) {
|
2013-02-17 09:52:53 -05:00
|
|
|
// Ignore while loading
|
|
|
|
if (!this._initialized)
|
|
|
|
return;
|
|
|
|
|
2011-02-25 17:42:25 -05:00
|
|
|
if (this._curRequestBegin && this._curRequestEnd){
|
|
|
|
this._dbusProxy.GetEventsRemote(this._curRequestBegin.getTime() / 1000,
|
|
|
|
this._curRequestEnd.getTime() / 1000,
|
|
|
|
forceReload,
|
|
|
|
Lang.bind(this, this._onEventsReceived),
|
2013-12-11 19:58:42 -05:00
|
|
|
Gio.DBusCallFlags.NONE);
|
2011-02-25 17:42:25 -05:00
|
|
|
}
|
2011-01-28 16:35:46 -05:00
|
|
|
},
|
|
|
|
|
2013-12-11 19:58:42 -05:00
|
|
|
requestRange: function(begin, end) {
|
|
|
|
if (!(_datesEqual(begin, this._lastRequestBegin) && _datesEqual(end, this._lastRequestEnd))) {
|
2012-10-23 12:41:24 -04:00
|
|
|
this.isLoading = true;
|
2011-02-25 17:42:25 -05:00
|
|
|
this._lastRequestBegin = begin;
|
|
|
|
this._lastRequestEnd = end;
|
|
|
|
this._curRequestBegin = begin;
|
|
|
|
this._curRequestEnd = end;
|
2013-12-11 19:58:42 -05:00
|
|
|
this._loadEvents(false);
|
2011-02-25 17:42:25 -05:00
|
|
|
}
|
2011-01-28 16:35:46 -05:00
|
|
|
},
|
|
|
|
|
|
|
|
getEvents: function(begin, end) {
|
|
|
|
let result = [];
|
2011-02-25 17:42:25 -05:00
|
|
|
for(let n = 0; n < this._events.length; n++) {
|
|
|
|
let event = this._events[n];
|
|
|
|
if (_dateIntervalsOverlap (event.date, event.end, begin, end)) {
|
2011-01-28 16:35:46 -05:00
|
|
|
result.push(event);
|
|
|
|
}
|
|
|
|
}
|
2014-09-17 21:34:40 -04:00
|
|
|
result.sort(function(event1, event2) {
|
|
|
|
// sort events by end time on ending day
|
|
|
|
let d1 = event1.date < begin && event1.end <= end ? event1.end : event1.date;
|
|
|
|
let d2 = event2.date < begin && event2.end <= end ? event2.end : event2.date;
|
|
|
|
return d1.getTime() - d2.getTime();
|
|
|
|
});
|
2011-01-28 16:35:46 -05:00
|
|
|
return result;
|
|
|
|
},
|
|
|
|
|
|
|
|
hasEvents: function(day) {
|
|
|
|
let dayBegin = _getBeginningOfDay(day);
|
|
|
|
let dayEnd = _getEndOfDay(day);
|
|
|
|
|
|
|
|
let events = this.getEvents(dayBegin, dayEnd);
|
|
|
|
|
|
|
|
if (events.length == 0)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
2011-11-20 12:56:27 -05:00
|
|
|
});
|
2011-02-25 17:42:25 -05:00
|
|
|
Signals.addSignalMethods(DBusEventSource.prototype);
|
2011-01-28 16:35:46 -05:00
|
|
|
|
2011-11-20 12:56:27 -05:00
|
|
|
const Calendar = new Lang.Class({
|
|
|
|
Name: 'Calendar',
|
2011-01-28 16:35:46 -05:00
|
|
|
|
2012-09-01 08:42:53 -04:00
|
|
|
_init: function() {
|
2011-06-23 20:40:36 -04:00
|
|
|
this._weekStart = Shell.util_get_week_start();
|
2014-06-24 15:17:09 -04:00
|
|
|
this._settings = new Gio.Settings({ schema_id: 'org.gnome.shell.calendar' });
|
2010-05-27 03:31:46 -04:00
|
|
|
|
2010-05-05 17:05:42 -04:00
|
|
|
this._settings.connect('changed::' + SHOW_WEEKDATE_KEY, Lang.bind(this, this._onSettingsChange));
|
|
|
|
this._useWeekdate = this._settings.get_boolean(SHOW_WEEKDATE_KEY);
|
2010-05-27 03:31:46 -04:00
|
|
|
|
2009-09-30 10:02:08 -04:00
|
|
|
// Find the ordering for month/year in the calendar heading
|
2011-01-28 16:35:46 -05:00
|
|
|
this._headerFormatWithoutYear = '%B';
|
2014-04-26 19:06:13 -04:00
|
|
|
switch (gtk30_('calendar:MY')) {
|
2010-05-13 15:46:04 -04:00
|
|
|
case 'calendar:MY':
|
|
|
|
this._headerFormat = '%B %Y';
|
2009-09-30 10:02:08 -04:00
|
|
|
break;
|
2010-05-13 15:46:04 -04:00
|
|
|
case 'calendar:YM':
|
|
|
|
this._headerFormat = '%Y %B';
|
2009-09-30 10:02:08 -04:00
|
|
|
break;
|
|
|
|
default:
|
2010-05-13 15:46:04 -04:00
|
|
|
log('Translation of "calendar:MY" in GTK+ is not correct');
|
|
|
|
this._headerFormat = '%B %Y';
|
2009-09-30 10:02:08 -04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Start off with the current date
|
2011-01-28 16:35:46 -05:00
|
|
|
this._selectedDate = new Date();
|
2009-09-30 10:02:08 -04:00
|
|
|
|
2014-03-03 12:14:51 -05:00
|
|
|
this._shouldDateGrabFocus = false;
|
|
|
|
|
2013-07-06 08:37:22 -04:00
|
|
|
this.actor = new St.Widget({ style_class: 'calendar',
|
2015-02-15 13:45:18 -05:00
|
|
|
layout_manager: new Clutter.TableLayout(),
|
2013-07-06 08:37:22 -04:00
|
|
|
reactive: true });
|
2009-10-01 15:18:20 -04:00
|
|
|
|
|
|
|
this.actor.connect('scroll-event',
|
|
|
|
Lang.bind(this, this._onScroll));
|
2009-09-30 10:02:08 -04:00
|
|
|
|
2010-05-27 03:31:46 -04:00
|
|
|
this._buildHeader ();
|
|
|
|
},
|
|
|
|
|
2012-09-01 08:42:53 -04:00
|
|
|
// @eventSource: is an object implementing the EventSource API, e.g. the
|
|
|
|
// requestRange(), getEvents(), hasEvents() methods and the ::changed signal.
|
|
|
|
setEventSource: function(eventSource) {
|
|
|
|
this._eventSource = eventSource;
|
2013-03-04 11:04:28 -05:00
|
|
|
this._eventSource.connect('changed', Lang.bind(this, function() {
|
2014-03-12 13:50:37 -04:00
|
|
|
this._rebuildCalendar();
|
2013-12-11 19:58:42 -05:00
|
|
|
this._update();
|
2013-03-04 11:04:28 -05:00
|
|
|
}));
|
2014-03-12 13:50:37 -04:00
|
|
|
this._rebuildCalendar();
|
2013-12-11 19:58:42 -05:00
|
|
|
this._update();
|
2012-09-01 08:42:53 -04:00
|
|
|
},
|
|
|
|
|
2010-05-27 03:31:46 -04:00
|
|
|
// Sets the calendar to show a specific date
|
2013-12-11 19:58:42 -05:00
|
|
|
setDate: function(date) {
|
|
|
|
if (_sameDay(date, this._selectedDate))
|
|
|
|
return;
|
|
|
|
|
|
|
|
this._selectedDate = date;
|
|
|
|
this._update();
|
|
|
|
this.emit('selected-date-changed', new Date(this._selectedDate));
|
2010-05-27 03:31:46 -04:00
|
|
|
},
|
|
|
|
|
|
|
|
_buildHeader: function() {
|
2013-07-06 08:37:22 -04:00
|
|
|
let layout = this.actor.layout_manager;
|
2010-05-27 03:31:46 -04:00
|
|
|
let offsetCols = this._useWeekdate ? 1 : 0;
|
2012-02-16 13:27:09 -05:00
|
|
|
this.actor.destroy_all_children();
|
2010-05-27 03:31:46 -04:00
|
|
|
|
2009-09-30 10:02:08 -04:00
|
|
|
// Top line of the calendar '<| September 2009 |>'
|
|
|
|
this._topBox = new St.BoxLayout();
|
2015-02-15 13:45:18 -05:00
|
|
|
layout.pack(this._topBox, 0, 0);
|
|
|
|
layout.set_span(this._topBox, offsetCols + 7, 1);
|
2009-09-30 10:02:08 -04:00
|
|
|
|
2015-01-14 09:08:44 -05:00
|
|
|
this._backButton = new St.Button({ style_class: 'calendar-change-month-back pager-button',
|
2013-08-27 07:50:25 -04:00
|
|
|
accessible_name: _("Previous month"),
|
2013-04-30 18:32:43 -04:00
|
|
|
can_focus: true });
|
|
|
|
this._topBox.add(this._backButton);
|
|
|
|
this._backButton.connect('clicked', Lang.bind(this, this._onPrevMonthButtonClicked));
|
2009-09-30 10:02:08 -04:00
|
|
|
|
2013-08-27 09:17:17 -04:00
|
|
|
this._monthLabel = new St.Label({style_class: 'calendar-month-label',
|
|
|
|
can_focus: true });
|
2011-01-28 16:35:46 -05:00
|
|
|
this._topBox.add(this._monthLabel, { expand: true, x_fill: false, x_align: St.Align.MIDDLE });
|
2009-09-30 10:02:08 -04:00
|
|
|
|
2015-01-14 09:08:44 -05:00
|
|
|
this._forwardButton = new St.Button({ style_class: 'calendar-change-month-forward pager-button',
|
2013-08-27 07:50:25 -04:00
|
|
|
accessible_name: _("Next month"),
|
2013-04-30 18:32:43 -04:00
|
|
|
can_focus: true });
|
|
|
|
this._topBox.add(this._forwardButton);
|
|
|
|
this._forwardButton.connect('clicked', Lang.bind(this, this._onNextMonthButtonClicked));
|
2009-09-30 10:02:08 -04:00
|
|
|
|
2011-01-28 16:35:46 -05:00
|
|
|
// Add weekday labels...
|
|
|
|
//
|
2009-09-30 10:02:08 -04:00
|
|
|
// We need to figure out the abbreviated localized names for the days of the week;
|
|
|
|
// we do this by just getting the next 7 days starting from right now and then putting
|
|
|
|
// them in the right cell in the table. It doesn't matter if we add them in order
|
2011-01-28 16:35:46 -05:00
|
|
|
let iter = new Date(this._selectedDate);
|
2009-09-30 10:02:08 -04:00
|
|
|
iter.setSeconds(0); // Leap second protection. Hah!
|
2009-10-01 16:14:50 -04:00
|
|
|
iter.setHours(12);
|
2009-09-30 10:02:08 -04:00
|
|
|
for (let i = 0; i < 7; i++) {
|
2011-01-28 16:35:46 -05:00
|
|
|
// Could use iter.toLocaleFormat('%a') but that normally gives three characters
|
|
|
|
// and we want, ideally, a single character for e.g. S M T W T F S
|
|
|
|
let customDayAbbrev = _getCalendarDayAbbreviation(iter.getDay());
|
|
|
|
let label = new St.Label({ style_class: 'calendar-day-base calendar-day-heading',
|
2015-03-02 22:37:49 -05:00
|
|
|
text: customDayAbbrev,
|
|
|
|
can_focus: true });
|
|
|
|
label.accessible_name = iter.toLocaleFormat('%A');
|
2014-06-20 10:10:08 -04:00
|
|
|
let col;
|
|
|
|
if (this.actor.get_text_direction() == Clutter.TextDirection.RTL)
|
|
|
|
col = 6 - (7 + iter.getDay() - this._weekStart) % 7;
|
|
|
|
else
|
|
|
|
col = offsetCols + (7 + iter.getDay() - this._weekStart) % 7;
|
2015-02-15 13:45:18 -05:00
|
|
|
layout.pack(label, col, 1);
|
2009-09-30 10:02:08 -04:00
|
|
|
iter.setTime(iter.getTime() + MSECS_IN_DAY);
|
|
|
|
}
|
|
|
|
|
2009-10-01 16:14:50 -04:00
|
|
|
// All the children after this are days, and get removed when we update the calendar
|
2012-05-29 20:36:45 -04:00
|
|
|
this._firstDayIndex = this.actor.get_n_children();
|
2010-05-27 03:31:46 -04:00
|
|
|
},
|
2009-10-01 16:14:50 -04:00
|
|
|
|
2009-10-01 15:18:20 -04:00
|
|
|
_onScroll : function(actor, event) {
|
|
|
|
switch (event.get_scroll_direction()) {
|
|
|
|
case Clutter.ScrollDirection.UP:
|
|
|
|
case Clutter.ScrollDirection.LEFT:
|
2011-01-28 16:35:46 -05:00
|
|
|
this._onPrevMonthButtonClicked();
|
2009-10-01 15:18:20 -04:00
|
|
|
break;
|
|
|
|
case Clutter.ScrollDirection.DOWN:
|
|
|
|
case Clutter.ScrollDirection.RIGHT:
|
2011-01-28 16:35:46 -05:00
|
|
|
this._onNextMonthButtonClicked();
|
2009-10-01 15:18:20 -04:00
|
|
|
break;
|
|
|
|
}
|
2013-11-29 13:17:34 -05:00
|
|
|
return Clutter.EVENT_PROPAGATE;
|
2009-10-01 15:18:20 -04:00
|
|
|
},
|
|
|
|
|
2011-01-28 16:35:46 -05:00
|
|
|
_onPrevMonthButtonClicked: function() {
|
|
|
|
let newDate = new Date(this._selectedDate);
|
2011-01-31 15:00:16 -05:00
|
|
|
let oldMonth = newDate.getMonth();
|
|
|
|
if (oldMonth == 0) {
|
2011-01-28 16:35:46 -05:00
|
|
|
newDate.setMonth(11);
|
|
|
|
newDate.setFullYear(newDate.getFullYear() - 1);
|
2011-01-31 15:00:16 -05:00
|
|
|
if (newDate.getMonth() != 11) {
|
|
|
|
let day = 32 - new Date(newDate.getFullYear() - 1, 11, 32).getDate();
|
|
|
|
newDate = new Date(newDate.getFullYear() - 1, 11, day);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
newDate.setMonth(oldMonth - 1);
|
|
|
|
if (newDate.getMonth() != oldMonth - 1) {
|
|
|
|
let day = 32 - new Date(newDate.getFullYear(), oldMonth - 1, 32).getDate();
|
|
|
|
newDate = new Date(newDate.getFullYear(), oldMonth - 1, day);
|
|
|
|
}
|
2009-09-30 10:02:08 -04:00
|
|
|
}
|
2011-01-31 15:00:16 -05:00
|
|
|
|
2013-04-30 18:32:43 -04:00
|
|
|
this._backButton.grab_key_focus();
|
|
|
|
|
2013-12-11 19:58:42 -05:00
|
|
|
this.setDate(newDate);
|
2013-04-30 18:32:43 -04:00
|
|
|
},
|
2009-09-30 10:02:08 -04:00
|
|
|
|
2013-04-30 18:32:43 -04:00
|
|
|
_onNextMonthButtonClicked: function() {
|
2011-01-28 16:35:46 -05:00
|
|
|
let newDate = new Date(this._selectedDate);
|
2011-01-31 15:00:16 -05:00
|
|
|
let oldMonth = newDate.getMonth();
|
|
|
|
if (oldMonth == 11) {
|
2011-01-28 16:35:46 -05:00
|
|
|
newDate.setMonth(0);
|
|
|
|
newDate.setFullYear(newDate.getFullYear() + 1);
|
2011-01-31 15:00:16 -05:00
|
|
|
if (newDate.getMonth() != 0) {
|
|
|
|
let day = 32 - new Date(newDate.getFullYear() + 1, 0, 32).getDate();
|
|
|
|
newDate = new Date(newDate.getFullYear() + 1, 0, day);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
newDate.setMonth(oldMonth + 1);
|
|
|
|
if (newDate.getMonth() != oldMonth + 1) {
|
|
|
|
let day = 32 - new Date(newDate.getFullYear(), oldMonth + 1, 32).getDate();
|
|
|
|
newDate = new Date(newDate.getFullYear(), oldMonth + 1, day);
|
|
|
|
}
|
2009-09-30 10:02:08 -04:00
|
|
|
}
|
2011-01-31 15:00:16 -05:00
|
|
|
|
2013-04-30 18:32:43 -04:00
|
|
|
this._forwardButton.grab_key_focus();
|
|
|
|
|
2013-12-11 19:58:42 -05:00
|
|
|
this.setDate(newDate);
|
2009-09-30 10:02:08 -04:00
|
|
|
},
|
|
|
|
|
2010-05-27 03:31:46 -04:00
|
|
|
_onSettingsChange: function() {
|
2010-05-05 17:05:42 -04:00
|
|
|
this._useWeekdate = this._settings.get_boolean(SHOW_WEEKDATE_KEY);
|
2010-05-27 03:31:46 -04:00
|
|
|
this._buildHeader();
|
2014-03-02 20:48:25 -05:00
|
|
|
this._rebuildCalendar();
|
2013-12-11 19:58:42 -05:00
|
|
|
this._update();
|
2010-05-27 03:31:46 -04:00
|
|
|
},
|
|
|
|
|
2013-12-11 20:05:21 -05:00
|
|
|
_rebuildCalendar: function() {
|
2011-01-28 16:35:46 -05:00
|
|
|
let now = new Date();
|
|
|
|
|
2009-09-30 10:02:08 -04:00
|
|
|
// Remove everything but the topBox and the weekday labels
|
|
|
|
let children = this.actor.get_children();
|
2009-10-01 16:14:50 -04:00
|
|
|
for (let i = this._firstDayIndex; i < children.length; i++)
|
2009-09-30 10:02:08 -04:00
|
|
|
children[i].destroy();
|
|
|
|
|
2013-12-11 20:05:21 -05:00
|
|
|
this._buttons = [];
|
|
|
|
|
2009-09-30 10:02:08 -04:00
|
|
|
// Start at the beginning of the week before the start of the month
|
2012-10-23 12:21:20 -04:00
|
|
|
//
|
|
|
|
// We want to show always 6 weeks (to keep the calendar menu at the same
|
|
|
|
// height if there are no events), so we pad it according to the following
|
|
|
|
// policy:
|
|
|
|
//
|
|
|
|
// 1 - If a month has 6 weeks, we place no padding (example: Dec 2012)
|
|
|
|
// 2 - If a month has 5 weeks and it starts on week start, we pad one week
|
|
|
|
// before it (example: Apr 2012)
|
|
|
|
// 3 - If a month has 5 weeks and it starts on any other day, we pad one week
|
|
|
|
// after it (example: Nov 2012)
|
|
|
|
// 4 - If a month has 4 weeks, we pad one week before and one after it
|
|
|
|
// (example: Feb 2010)
|
|
|
|
//
|
|
|
|
// Actually computing the number of weeks is complex, but we know that the
|
|
|
|
// problematic categories (2 and 4) always start on week start, and that
|
|
|
|
// all months at the end have 6 weeks.
|
2011-01-28 16:35:46 -05:00
|
|
|
let beginDate = new Date(this._selectedDate);
|
|
|
|
beginDate.setDate(1);
|
|
|
|
beginDate.setSeconds(0);
|
|
|
|
beginDate.setHours(12);
|
2013-12-11 20:05:21 -05:00
|
|
|
|
|
|
|
this._calendarBegin = new Date(beginDate);
|
2015-01-06 18:35:13 -05:00
|
|
|
this._markedAsToday = now;
|
2013-12-11 20:05:21 -05:00
|
|
|
|
2012-10-23 12:21:20 -04:00
|
|
|
let year = beginDate.getYear();
|
|
|
|
|
2011-01-28 16:35:46 -05:00
|
|
|
let daysToWeekStart = (7 + beginDate.getDay() - this._weekStart) % 7;
|
2012-10-23 12:21:20 -04:00
|
|
|
let startsOnWeekStart = daysToWeekStart == 0;
|
|
|
|
let weekPadding = startsOnWeekStart ? 7 : 0;
|
|
|
|
|
|
|
|
beginDate.setTime(beginDate.getTime() - (weekPadding + daysToWeekStart) * MSECS_IN_DAY);
|
2011-01-28 16:35:46 -05:00
|
|
|
|
2013-07-06 08:37:22 -04:00
|
|
|
let layout = this.actor.layout_manager;
|
2011-01-28 16:35:46 -05:00
|
|
|
let iter = new Date(beginDate);
|
2009-09-30 10:02:08 -04:00
|
|
|
let row = 2;
|
2012-10-23 12:21:20 -04:00
|
|
|
// nRows here means 6 weeks + one header + one navbar
|
|
|
|
let nRows = 8;
|
|
|
|
while (row < 8) {
|
2015-08-25 06:11:20 -04:00
|
|
|
let button = new St.Button({ label: iter.toLocaleFormat(C_("date day number format", "%d")),
|
2013-03-14 11:30:38 -04:00
|
|
|
can_focus: true });
|
2012-07-13 13:00:56 -04:00
|
|
|
let rtl = button.get_text_direction() == Clutter.TextDirection.RTL;
|
2011-01-28 16:35:46 -05:00
|
|
|
|
2013-03-04 11:04:28 -05:00
|
|
|
if (this._eventSource.isDummy)
|
2011-08-22 14:21:51 -04:00
|
|
|
button.reactive = false;
|
|
|
|
|
2013-12-11 20:05:21 -05:00
|
|
|
button._date = new Date(iter);
|
2011-01-28 16:35:46 -05:00
|
|
|
button.connect('clicked', Lang.bind(this, function() {
|
2014-03-03 12:14:51 -05:00
|
|
|
this._shouldDateGrabFocus = true;
|
2013-12-11 20:05:21 -05:00
|
|
|
this.setDate(button._date);
|
2014-03-03 12:14:51 -05:00
|
|
|
this._shouldDateGrabFocus = false;
|
2011-01-28 16:35:46 -05:00
|
|
|
}));
|
|
|
|
|
2013-03-04 11:04:28 -05:00
|
|
|
let hasEvents = this._eventSource.hasEvents(iter);
|
2011-01-28 16:35:46 -05:00
|
|
|
let styleClass = 'calendar-day-base calendar-day';
|
2012-10-23 12:21:20 -04:00
|
|
|
|
2011-01-28 16:35:46 -05:00
|
|
|
if (_isWorkDay(iter))
|
2013-12-11 19:59:10 -05:00
|
|
|
styleClass += ' calendar-work-day';
|
2009-09-30 10:02:08 -04:00
|
|
|
else
|
2013-12-11 19:59:10 -05:00
|
|
|
styleClass += ' calendar-nonwork-day';
|
2011-01-28 16:35:46 -05:00
|
|
|
|
|
|
|
// Hack used in lieu of border-collapse - see gnome-shell.css
|
|
|
|
if (row == 2)
|
|
|
|
styleClass = 'calendar-day-top ' + styleClass;
|
2012-07-13 13:00:56 -04:00
|
|
|
|
|
|
|
let leftMost = rtl ? iter.getDay() == (this._weekStart + 6) % 7
|
|
|
|
: iter.getDay() == this._weekStart;
|
|
|
|
if (leftMost)
|
2011-01-28 16:35:46 -05:00
|
|
|
styleClass = 'calendar-day-left ' + styleClass;
|
|
|
|
|
|
|
|
if (_sameDay(now, iter))
|
|
|
|
styleClass += ' calendar-today';
|
|
|
|
else if (iter.getMonth() != this._selectedDate.getMonth())
|
|
|
|
styleClass += ' calendar-other-month-day';
|
|
|
|
|
|
|
|
if (hasEvents)
|
2013-12-11 19:59:10 -05:00
|
|
|
styleClass += ' calendar-day-with-events';
|
2011-01-28 16:35:46 -05:00
|
|
|
|
|
|
|
button.style_class = styleClass;
|
2010-05-27 03:31:46 -04:00
|
|
|
|
|
|
|
let offsetCols = this._useWeekdate ? 1 : 0;
|
2014-06-20 10:10:08 -04:00
|
|
|
let col;
|
|
|
|
if (rtl)
|
|
|
|
col = 6 - (7 + iter.getDay() - this._weekStart) % 7;
|
|
|
|
else
|
|
|
|
col = offsetCols + (7 + iter.getDay() - this._weekStart) % 7;
|
2015-02-15 13:45:18 -05:00
|
|
|
layout.pack(button, col, row);
|
2009-09-30 10:02:08 -04:00
|
|
|
|
2013-12-11 20:05:21 -05:00
|
|
|
this._buttons.push(button);
|
2013-04-30 18:32:43 -04:00
|
|
|
|
2010-05-27 03:31:46 -04:00
|
|
|
if (this._useWeekdate && iter.getDay() == 4) {
|
2014-11-13 10:14:56 -05:00
|
|
|
let label = new St.Label({ text: iter.toLocaleFormat('%V'),
|
2015-03-02 22:37:49 -05:00
|
|
|
style_class: 'calendar-day-base calendar-week-number',
|
|
|
|
can_focus: true });
|
|
|
|
let weekFormat = Shell.util_translate_time_string(N_("Week %V"));
|
|
|
|
label.accessible_name = iter.toLocaleFormat(weekFormat);
|
2015-02-15 13:45:18 -05:00
|
|
|
layout.pack(label, rtl ? 7 : 0, row);
|
2010-05-27 03:31:46 -04:00
|
|
|
}
|
|
|
|
|
2009-09-30 10:02:08 -04:00
|
|
|
iter.setTime(iter.getTime() + MSECS_IN_DAY);
|
2012-10-23 12:21:20 -04:00
|
|
|
|
|
|
|
if (iter.getDay() == this._weekStart)
|
2009-09-30 10:02:08 -04:00
|
|
|
row++;
|
|
|
|
}
|
2013-12-11 20:05:21 -05:00
|
|
|
|
2011-01-28 16:35:46 -05:00
|
|
|
// Signal to the event source that we are interested in events
|
|
|
|
// only from this date range
|
2013-12-11 19:58:42 -05:00
|
|
|
this._eventSource.requestRange(beginDate, iter);
|
2013-12-11 20:05:21 -05:00
|
|
|
},
|
|
|
|
|
|
|
|
_update: function() {
|
|
|
|
let now = new Date();
|
|
|
|
|
|
|
|
if (_sameYear(this._selectedDate, now))
|
|
|
|
this._monthLabel.text = this._selectedDate.toLocaleFormat(this._headerFormatWithoutYear);
|
|
|
|
else
|
|
|
|
this._monthLabel.text = this._selectedDate.toLocaleFormat(this._headerFormat);
|
|
|
|
|
2015-01-06 18:35:13 -05:00
|
|
|
if (!this._calendarBegin || !_sameMonth(this._selectedDate, this._calendarBegin) || !_sameDay(now, this._markedAsToday))
|
2013-12-11 20:05:21 -05:00
|
|
|
this._rebuildCalendar();
|
|
|
|
|
|
|
|
this._buttons.forEach(Lang.bind(this, function(button) {
|
2014-03-03 12:14:51 -05:00
|
|
|
if (_sameDay(button._date, this._selectedDate)) {
|
2013-12-11 20:05:21 -05:00
|
|
|
button.add_style_pseudo_class('active');
|
2014-03-03 12:14:51 -05:00
|
|
|
if (this._shouldDateGrabFocus)
|
|
|
|
button.grab_key_focus();
|
|
|
|
}
|
2013-12-11 20:05:21 -05:00
|
|
|
else
|
|
|
|
button.remove_style_pseudo_class('active');
|
|
|
|
}));
|
2011-01-28 16:35:46 -05:00
|
|
|
}
|
2011-11-20 12:56:27 -05:00
|
|
|
});
|
2011-01-28 16:35:46 -05:00
|
|
|
Signals.addSignalMethods(Calendar.prototype);
|
|
|
|
|
2014-12-05 10:24:35 -05:00
|
|
|
const ScaleLayout = new Lang.Class({
|
|
|
|
Name: 'ScaleLayout',
|
|
|
|
Extends: Clutter.BinLayout,
|
|
|
|
|
|
|
|
_connectContainer: function(container) {
|
|
|
|
if (this._container == container)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (this._container)
|
|
|
|
for (let id of this._signals)
|
|
|
|
this._container.disconnect(id);
|
|
|
|
|
|
|
|
this._container = container;
|
|
|
|
this._signals = [];
|
|
|
|
|
|
|
|
if (this._container)
|
|
|
|
for (let signal of ['notify::scale-x', 'notify::scale-y']) {
|
|
|
|
let id = this._container.connect(signal, Lang.bind(this,
|
|
|
|
function() {
|
|
|
|
this.layout_changed();
|
|
|
|
}));
|
|
|
|
this._signals.push(id);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
vfunc_get_preferred_width: function(container, forHeight) {
|
|
|
|
this._connectContainer(container);
|
|
|
|
|
|
|
|
let [min, nat] = this.parent(container, forHeight);
|
|
|
|
return [Math.floor(min * container.scale_x),
|
|
|
|
Math.floor(nat * container.scale_x)];
|
|
|
|
},
|
|
|
|
|
|
|
|
vfunc_get_preferred_height: function(container, forWidth) {
|
|
|
|
this._connectContainer(container);
|
|
|
|
|
|
|
|
let [min, nat] = this.parent(container, forWidth);
|
|
|
|
return [Math.floor(min * container.scale_y),
|
|
|
|
Math.floor(nat * container.scale_y)];
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2015-02-16 19:12:44 -05:00
|
|
|
const LabelExpanderLayout = new Lang.Class({
|
|
|
|
Name: 'LabelExpanderLayout',
|
|
|
|
Extends: Clutter.LayoutManager,
|
|
|
|
Properties: { 'expansion': GObject.ParamSpec.double('expansion',
|
|
|
|
'Expansion',
|
|
|
|
'Expansion of the layout, between 0 (collapsed) ' +
|
|
|
|
'and 1 (fully expanded',
|
|
|
|
GObject.ParamFlags.READABLE | GObject.ParamFlags.WRITABLE,
|
|
|
|
0, 1, 0)},
|
|
|
|
|
|
|
|
_init: function(params) {
|
|
|
|
this._expansion = 0;
|
|
|
|
this._expandLines = DEFAULT_EXPAND_LINES;
|
|
|
|
|
|
|
|
this.parent(params);
|
|
|
|
},
|
|
|
|
|
|
|
|
get expansion() {
|
|
|
|
return this._expansion;
|
|
|
|
},
|
|
|
|
|
|
|
|
set expansion(v) {
|
|
|
|
if (v == this._expansion)
|
|
|
|
return;
|
|
|
|
this._expansion = v;
|
|
|
|
this.notify('expansion');
|
|
|
|
|
|
|
|
let visibleIndex = this._expansion > 0 ? 1 : 0;
|
|
|
|
for (let i = 0; this._container && i < this._container.get_n_children(); i++)
|
|
|
|
this._container.get_child_at_index(i).visible = (i == visibleIndex);
|
|
|
|
|
|
|
|
this.layout_changed();
|
|
|
|
},
|
|
|
|
|
|
|
|
set expandLines(v) {
|
|
|
|
if (v == this._expandLines)
|
|
|
|
return;
|
|
|
|
this._expandLines = v;
|
|
|
|
if (this._expansion > 0)
|
|
|
|
this.layout_changed();
|
|
|
|
},
|
|
|
|
|
|
|
|
vfunc_set_container: function(container) {
|
|
|
|
this._container = container;
|
|
|
|
},
|
|
|
|
|
|
|
|
vfunc_get_preferred_width: function(container, forHeight) {
|
|
|
|
let [min, nat] = [0, 0];
|
|
|
|
|
|
|
|
for (let i = 0; i < container.get_n_children(); i++) {
|
|
|
|
if (i > 1)
|
|
|
|
break; // we support one unexpanded + one expanded child
|
|
|
|
|
|
|
|
let child = container.get_child_at_index(i);
|
|
|
|
let [childMin, childNat] = child.get_preferred_width(forHeight);
|
|
|
|
[min, nat] = [Math.max(min, childMin), Math.max(nat, childNat)];
|
|
|
|
}
|
|
|
|
|
|
|
|
return [min, nat];
|
|
|
|
},
|
|
|
|
|
|
|
|
vfunc_get_preferred_height: function(container, forWidth) {
|
|
|
|
let [min, nat] = [0, 0];
|
|
|
|
|
|
|
|
let children = container.get_children();
|
|
|
|
if (children[0])
|
|
|
|
[min, nat] = children[0].get_preferred_height(forWidth);
|
|
|
|
|
|
|
|
if (children[1]) {
|
|
|
|
let [min2, nat2] = children[1].get_preferred_height(forWidth);
|
|
|
|
let [expMin, expNat] = [Math.min(min2, min * this._expandLines),
|
|
|
|
Math.min(nat2, nat * this._expandLines)];
|
|
|
|
[min, nat] = [min + this._expansion * (expMin - min),
|
|
|
|
nat + this._expansion * (expNat - nat)];
|
|
|
|
}
|
|
|
|
|
|
|
|
return [min, nat];
|
|
|
|
},
|
|
|
|
|
|
|
|
vfunc_allocate: function(container, box, flags) {
|
|
|
|
for (let i = 0; i < container.get_n_children(); i++) {
|
|
|
|
let child = container.get_child_at_index(i);
|
|
|
|
|
|
|
|
if (child.visible)
|
|
|
|
child.allocate(box, flags);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2014-12-05 10:24:35 -05:00
|
|
|
const Message = new Lang.Class({
|
|
|
|
Name: 'Message',
|
|
|
|
|
|
|
|
_init: function(title, body) {
|
2015-02-16 19:12:44 -05:00
|
|
|
this.expanded = false;
|
|
|
|
|
2014-12-05 10:24:35 -05:00
|
|
|
this.actor = new St.Button({ style_class: 'message',
|
|
|
|
accessible_role: Atk.Role.NOTIFICATION,
|
|
|
|
can_focus: true,
|
|
|
|
x_expand: true, x_fill: true });
|
2015-02-27 09:10:11 -05:00
|
|
|
this.actor.connect('key-press-event',
|
|
|
|
Lang.bind(this, this._onKeyPressed));
|
2014-12-05 10:24:35 -05:00
|
|
|
|
2015-02-16 19:12:44 -05:00
|
|
|
let vbox = new St.BoxLayout({ vertical: true });
|
|
|
|
this.actor.set_child(vbox);
|
|
|
|
|
2014-12-05 10:24:35 -05:00
|
|
|
let hbox = new St.BoxLayout();
|
2015-02-16 19:12:44 -05:00
|
|
|
vbox.add_actor(hbox);
|
|
|
|
|
|
|
|
this._actionBin = new St.Widget({ layout_manager: new ScaleLayout(),
|
|
|
|
visible: false });
|
|
|
|
vbox.add_actor(this._actionBin);
|
2014-12-05 10:24:35 -05:00
|
|
|
|
|
|
|
this._iconBin = new St.Bin({ style_class: 'message-icon-bin',
|
|
|
|
y_expand: true,
|
|
|
|
visible: false });
|
|
|
|
hbox.add_actor(this._iconBin);
|
|
|
|
|
|
|
|
let contentBox = new St.BoxLayout({ style_class: 'message-content',
|
|
|
|
vertical: true, x_expand: true });
|
|
|
|
hbox.add_actor(contentBox);
|
|
|
|
|
|
|
|
let titleBox = new St.BoxLayout();
|
|
|
|
contentBox.add_actor(titleBox);
|
|
|
|
|
|
|
|
this.titleLabel = new St.Label({ style_class: 'message-title',
|
|
|
|
x_expand: true,
|
|
|
|
x_align: Clutter.ActorAlign.START });
|
|
|
|
this.setTitle(title);
|
|
|
|
titleBox.add_actor(this.titleLabel);
|
|
|
|
|
|
|
|
this._secondaryBin = new St.Bin({ style_class: 'message-secondary-bin' });
|
|
|
|
titleBox.add_actor(this._secondaryBin);
|
|
|
|
|
|
|
|
let closeIcon = new St.Icon({ icon_name: 'window-close-symbolic',
|
|
|
|
icon_size: 16 });
|
|
|
|
this._closeButton = new St.Button({ child: closeIcon, visible: false });
|
|
|
|
titleBox.add_actor(this._closeButton);
|
|
|
|
|
2015-03-10 17:30:35 -04:00
|
|
|
this._bodyStack = new St.Widget({ x_expand: true });
|
2015-02-16 19:12:44 -05:00
|
|
|
this._bodyStack.layout_manager = new LabelExpanderLayout();
|
|
|
|
contentBox.add_actor(this._bodyStack);
|
|
|
|
|
2015-02-21 14:10:41 -05:00
|
|
|
this.bodyLabel = new URLHighlighter('', false, this._useBodyMarkup);
|
2014-12-05 10:24:35 -05:00
|
|
|
this.bodyLabel.actor.add_style_class_name('message-body');
|
2015-02-16 19:12:44 -05:00
|
|
|
this._bodyStack.add_actor(this.bodyLabel.actor);
|
2015-02-21 14:10:41 -05:00
|
|
|
this.setBody(body);
|
2014-12-05 10:24:35 -05:00
|
|
|
|
2015-03-11 17:11:25 -04:00
|
|
|
this._closeButton.connect('clicked', Lang.bind(this, this.close));
|
2014-12-05 10:24:35 -05:00
|
|
|
this.actor.connect('notify::hover', Lang.bind(this, this._sync));
|
|
|
|
this.actor.connect('clicked', Lang.bind(this, this._onClicked));
|
|
|
|
this.actor.connect('destroy', Lang.bind(this, this._onDestroy));
|
|
|
|
this._sync();
|
|
|
|
},
|
|
|
|
|
2015-03-11 17:11:25 -04:00
|
|
|
close: function() {
|
|
|
|
this.emit('close');
|
|
|
|
},
|
|
|
|
|
2014-12-05 10:24:35 -05:00
|
|
|
setIcon: function(actor) {
|
|
|
|
this._iconBin.child = actor;
|
|
|
|
this._iconBin.visible = (actor != null);
|
|
|
|
},
|
|
|
|
|
|
|
|
setSecondaryActor: function(actor) {
|
|
|
|
this._secondaryBin.child = actor;
|
|
|
|
},
|
|
|
|
|
|
|
|
setTitle: function(text) {
|
|
|
|
let title = text ? _fixMarkup(text.replace(/\n/g, ' '), false) : '';
|
2015-02-21 13:08:27 -05:00
|
|
|
this.titleLabel.clutter_text.set_markup(title);
|
2014-12-05 10:24:35 -05:00
|
|
|
},
|
|
|
|
|
|
|
|
setBody: function(text) {
|
2015-02-21 14:10:41 -05:00
|
|
|
this._bodyText = text;
|
2015-03-10 18:55:30 -04:00
|
|
|
this.bodyLabel.setMarkup(text ? text.replace(/\n/g, ' ') : '',
|
|
|
|
this._useBodyMarkup);
|
2015-03-10 20:42:05 -04:00
|
|
|
if (this._expandedLabel)
|
|
|
|
this._expandedLabel.setMarkup(text, this._useBodyMarkup);
|
2014-12-05 10:24:35 -05:00
|
|
|
},
|
|
|
|
|
|
|
|
setUseBodyMarkup: function(enable) {
|
|
|
|
if (this._useBodyMarkup === enable)
|
|
|
|
return;
|
|
|
|
this._useBodyMarkup = enable;
|
|
|
|
if (this.bodyLabel)
|
2015-02-21 14:10:41 -05:00
|
|
|
this.setBody(this._bodyText);
|
2014-12-05 10:24:35 -05:00
|
|
|
},
|
|
|
|
|
2015-02-16 19:12:44 -05:00
|
|
|
setActionArea: function(actor) {
|
|
|
|
if (actor == null) {
|
|
|
|
if (this._actionBin.get_n_children() > 0)
|
|
|
|
this._actionBin.get_child_at_index(0).destroy();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (this._actionBin.get_n_children() > 0)
|
|
|
|
throw new Error('Message already has an action area');
|
|
|
|
|
|
|
|
this._actionBin.add_actor(actor);
|
|
|
|
this._actionBin.visible = this.expanded;
|
|
|
|
},
|
|
|
|
|
|
|
|
setExpandedBody: function(actor) {
|
|
|
|
if (actor == null) {
|
|
|
|
if (this._bodyStack.get_n_children() > 1)
|
|
|
|
this._bodyStack.get_child_at_index(1).destroy();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (this._bodyStack.get_n_children() > 1)
|
|
|
|
throw new Error('Message already has an expanded body actor');
|
|
|
|
|
|
|
|
this._bodyStack.insert_child_at_index(actor, 1);
|
|
|
|
},
|
|
|
|
|
|
|
|
setExpandedLines: function(nLines) {
|
|
|
|
this._bodyStack.layout_manager.expandLines = nLines;
|
|
|
|
},
|
|
|
|
|
|
|
|
expand: function(animate) {
|
|
|
|
this.expanded = true;
|
|
|
|
|
|
|
|
this._actionBin.visible = (this._actionBin.get_n_children() > 0);
|
|
|
|
|
|
|
|
if (this._bodyStack.get_n_children() < 2) {
|
2015-03-10 20:42:05 -04:00
|
|
|
this._expandedLabel = new URLHighlighter(this._bodyText,
|
|
|
|
true, this._useBodyMarkup);
|
|
|
|
this.setExpandedBody(this._expandedLabel.actor);
|
2015-02-16 19:12:44 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
if (animate) {
|
|
|
|
Tweener.addTween(this._bodyStack.layout_manager,
|
|
|
|
{ expansion: 1,
|
|
|
|
time: MessageTray.ANIMATION_TIME,
|
|
|
|
transition: 'easeOutQuad' });
|
|
|
|
this._actionBin.scale_y = 0;
|
|
|
|
Tweener.addTween(this._actionBin,
|
|
|
|
{ scale_y: 1,
|
|
|
|
time: MessageTray.ANIMATION_TIME,
|
|
|
|
transition: 'easeOutQuad' });
|
|
|
|
} else {
|
|
|
|
this._bodyStack.layout_manager.expansion = 1;
|
|
|
|
this._actionBin.scale_y = 1;
|
|
|
|
}
|
2015-03-17 16:06:51 -04:00
|
|
|
|
|
|
|
this.emit('expanded');
|
2015-02-16 19:12:44 -05:00
|
|
|
},
|
|
|
|
|
|
|
|
unexpand: function(animate) {
|
|
|
|
if (animate) {
|
|
|
|
Tweener.addTween(this._bodyStack.layout_manager,
|
|
|
|
{ expansion: 0,
|
|
|
|
time: MessageTray.ANIMATION_TIME,
|
|
|
|
transition: 'easeOutQuad' });
|
|
|
|
Tweener.addTween(this._actionBin,
|
|
|
|
{ scale_y: 0,
|
|
|
|
time: MessageTray.ANIMATION_TIME,
|
|
|
|
transition: 'easeOutQuad',
|
|
|
|
onCompleteScope: this,
|
|
|
|
onComplete: function() {
|
|
|
|
this._actionBin.hide();
|
|
|
|
this.expanded = false;
|
|
|
|
}});
|
|
|
|
} else {
|
|
|
|
this._bodyStack.layout_manager.expansion = 0;
|
|
|
|
this._actionBin.scale_y = 0;
|
|
|
|
this.expanded = false;
|
|
|
|
}
|
2015-03-17 16:06:51 -04:00
|
|
|
|
|
|
|
this.emit('unexpanded');
|
2015-02-16 19:12:44 -05:00
|
|
|
},
|
|
|
|
|
2015-03-11 17:33:20 -04:00
|
|
|
canClose: function() {
|
2014-12-05 10:24:35 -05:00
|
|
|
return true;
|
|
|
|
},
|
|
|
|
|
|
|
|
_sync: function() {
|
|
|
|
let hovered = this.actor.hover;
|
2015-03-11 17:33:20 -04:00
|
|
|
this._closeButton.visible = hovered && this.canClose();
|
2014-12-05 10:24:35 -05:00
|
|
|
this._secondaryBin.visible = !hovered;
|
|
|
|
},
|
|
|
|
|
|
|
|
_onClicked: function() {
|
|
|
|
},
|
|
|
|
|
|
|
|
_onDestroy: function() {
|
2015-02-27 09:10:11 -05:00
|
|
|
},
|
|
|
|
|
|
|
|
_onKeyPressed: function(a, event) {
|
|
|
|
let keysym = event.get_key_symbol();
|
|
|
|
|
|
|
|
if (keysym == Clutter.KEY_Delete ||
|
|
|
|
keysym == Clutter.KEY_KP_Delete) {
|
2015-03-11 17:11:25 -04:00
|
|
|
this.close();
|
2015-02-27 09:10:11 -05:00
|
|
|
return Clutter.EVENT_STOP;
|
|
|
|
}
|
|
|
|
return Clutter.EVENT_PROPAGATE;
|
2014-12-05 10:24:35 -05:00
|
|
|
}
|
|
|
|
});
|
|
|
|
Signals.addSignalMethods(Message.prototype);
|
|
|
|
|
2015-03-11 18:04:55 -04:00
|
|
|
const EventMessage = new Lang.Class({
|
|
|
|
Name: 'EventMessage',
|
|
|
|
Extends: Message,
|
|
|
|
|
|
|
|
_init: function(event, date) {
|
|
|
|
this._event = event;
|
|
|
|
this._date = date;
|
|
|
|
|
|
|
|
this.parent(this._formatEventTime(), event.summary);
|
|
|
|
},
|
|
|
|
|
|
|
|
_formatEventTime: function() {
|
|
|
|
let periodBegin = _getBeginningOfDay(this._date);
|
|
|
|
let periodEnd = _getEndOfDay(this._date);
|
|
|
|
let allDay = (this._event.allDay || (this._event.date <= periodBegin &&
|
|
|
|
this._event.end >= periodEnd));
|
|
|
|
let title;
|
|
|
|
if (allDay) {
|
|
|
|
/* Translators: Shown in calendar event list for all day events
|
|
|
|
* Keep it short, best if you can use less then 10 characters
|
|
|
|
*/
|
|
|
|
title = C_("event list time", "All Day");
|
|
|
|
} else {
|
|
|
|
let date = this._event.date >= periodBegin ? this._event.date
|
|
|
|
: this._event.end;
|
|
|
|
title = Util.formatTime(date, { timeOnly: true });
|
|
|
|
}
|
|
|
|
|
|
|
|
let rtl = Clutter.get_default_text_direction() == Clutter.TextDirection.RTL;
|
|
|
|
if (this._event.date < periodBegin && !this._event.allDay) {
|
|
|
|
if (rtl)
|
|
|
|
title = title + ELLIPSIS_CHAR;
|
|
|
|
else
|
|
|
|
title = ELLIPSIS_CHAR + title;
|
|
|
|
}
|
|
|
|
if (this._event.end > periodEnd && !this._event.allDay) {
|
|
|
|
if (rtl)
|
|
|
|
title = ELLIPSIS_CHAR + title;
|
|
|
|
else
|
|
|
|
title = title + ELLIPSIS_CHAR;
|
|
|
|
}
|
|
|
|
return title;
|
2015-03-11 18:06:50 -04:00
|
|
|
},
|
|
|
|
|
|
|
|
canClose: function() {
|
|
|
|
return _isToday(this._date);
|
2015-03-11 18:04:55 -04:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2015-02-11 14:41:56 -05:00
|
|
|
const NotificationMessage = new Lang.Class({
|
|
|
|
Name: 'NotificationMessage',
|
|
|
|
Extends: Message,
|
|
|
|
|
|
|
|
_init: function(notification) {
|
|
|
|
this.notification = notification;
|
|
|
|
|
|
|
|
this.setUseBodyMarkup(notification.bannerBodyMarkup);
|
|
|
|
this.parent(notification.title, notification.bannerBodyText);
|
|
|
|
|
|
|
|
this.setIcon(this._getIcon());
|
|
|
|
|
|
|
|
this.connect('close', Lang.bind(this,
|
|
|
|
function() {
|
|
|
|
this._closed = true;
|
|
|
|
this.notification.destroy(MessageTray.NotificationDestroyedReason.DISMISSED);
|
|
|
|
}));
|
2015-09-22 11:27:56 -04:00
|
|
|
this._destroyId = notification.connect('destroy', Lang.bind(this,
|
2015-02-11 14:41:56 -05:00
|
|
|
function() {
|
|
|
|
if (!this._closed)
|
2015-03-17 00:32:04 -04:00
|
|
|
this.close();
|
2015-02-11 14:41:56 -05:00
|
|
|
}));
|
|
|
|
this._updatedId = notification.connect('updated',
|
|
|
|
Lang.bind(this, this._onUpdated));
|
|
|
|
},
|
|
|
|
|
|
|
|
_getIcon: function() {
|
|
|
|
if (this.notification.gicon)
|
2015-06-02 09:46:37 -04:00
|
|
|
return new St.Icon({ gicon: this.notification.gicon,
|
|
|
|
icon_size: MESSAGE_ICON_SIZE });
|
2015-02-11 14:41:56 -05:00
|
|
|
else
|
2015-06-02 09:46:37 -04:00
|
|
|
return this.notification.source.createIcon(MESSAGE_ICON_SIZE);
|
2015-02-11 14:41:56 -05:00
|
|
|
},
|
|
|
|
|
|
|
|
_onUpdated: function(n, clear) {
|
|
|
|
this.setIcon(this._getIcon());
|
|
|
|
this.setTitle(n.title);
|
|
|
|
this.setBody(n.bannerBodyText);
|
|
|
|
this.setUseBodyMarkup(n.bannerBodyMarkup);
|
|
|
|
},
|
|
|
|
|
|
|
|
_onClicked: function() {
|
|
|
|
this.notification.activate();
|
|
|
|
},
|
|
|
|
|
|
|
|
_onDestroy: function() {
|
|
|
|
if (this._updatedId)
|
|
|
|
this.notification.disconnect(this._updatedId);
|
|
|
|
this._updatedId = 0;
|
2015-09-22 11:27:56 -04:00
|
|
|
|
|
|
|
if (this._destroyId)
|
|
|
|
this.notification.disconnect(this._destroyId);
|
|
|
|
this._destroyId = 0;
|
2015-02-11 14:41:56 -05:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2014-12-05 10:24:35 -05:00
|
|
|
const MessageListSection = new Lang.Class({
|
|
|
|
Name: 'MessageListSection',
|
|
|
|
|
|
|
|
_init: function(title) {
|
|
|
|
this.actor = new St.BoxLayout({ style_class: 'message-list-section',
|
|
|
|
clip_to_allocation: true,
|
|
|
|
x_expand: true, vertical: true });
|
|
|
|
let titleBox = new St.BoxLayout({ style_class: 'message-list-section-title-box' });
|
|
|
|
this.actor.add_actor(titleBox);
|
|
|
|
|
|
|
|
this._title = new St.Button({ style_class: 'message-list-section-title',
|
|
|
|
label: title,
|
|
|
|
can_focus: true,
|
|
|
|
x_expand: true,
|
|
|
|
x_align: St.Align.START });
|
|
|
|
titleBox.add_actor(this._title);
|
|
|
|
|
|
|
|
this._title.connect('clicked', Lang.bind(this, this._onTitleClicked));
|
|
|
|
this._title.connect('key-focus-in', Lang.bind(this, this._onKeyFocusIn));
|
|
|
|
|
|
|
|
let closeIcon = new St.Icon({ icon_name: 'window-close-symbolic' });
|
|
|
|
this._closeButton = new St.Button({ style_class: 'message-list-section-close',
|
|
|
|
child: closeIcon,
|
|
|
|
accessible_name: _("Clear section"),
|
|
|
|
can_focus: true });
|
|
|
|
this._closeButton.set_x_align(Clutter.ActorAlign.END);
|
|
|
|
titleBox.add_actor(this._closeButton);
|
|
|
|
|
|
|
|
this._closeButton.connect('clicked', Lang.bind(this, this.clear));
|
|
|
|
|
|
|
|
this._list = new St.BoxLayout({ style_class: 'message-list-section-list',
|
|
|
|
vertical: true });
|
|
|
|
this.actor.add_actor(this._list);
|
|
|
|
|
|
|
|
this._list.connect('actor-added', Lang.bind(this, this._sync));
|
|
|
|
this._list.connect('actor-removed', Lang.bind(this, this._sync));
|
|
|
|
|
2015-03-02 20:04:37 -05:00
|
|
|
let id = Main.sessionMode.connect('updated',
|
|
|
|
Lang.bind(this, this._sync));
|
|
|
|
this.actor.connect('destroy', function() {
|
|
|
|
Main.sessionMode.disconnect(id);
|
|
|
|
});
|
|
|
|
|
2014-12-05 10:24:35 -05:00
|
|
|
this._messages = new Map();
|
|
|
|
this._date = new Date();
|
|
|
|
this.empty = true;
|
|
|
|
this._sync();
|
|
|
|
},
|
|
|
|
|
|
|
|
_onTitleClicked: function() {
|
|
|
|
Main.overview.hide();
|
|
|
|
Main.panel.closeCalendar();
|
|
|
|
},
|
|
|
|
|
|
|
|
_onKeyFocusIn: function(actor) {
|
|
|
|
this.emit('key-focus-in', actor);
|
|
|
|
},
|
|
|
|
|
2015-03-02 20:04:37 -05:00
|
|
|
get allowed() {
|
|
|
|
return true;
|
|
|
|
},
|
|
|
|
|
2014-12-05 10:24:35 -05:00
|
|
|
setDate: function(date) {
|
|
|
|
if (_sameDay(date, this._date))
|
|
|
|
return;
|
|
|
|
this._date = date;
|
|
|
|
this._sync();
|
|
|
|
},
|
|
|
|
|
|
|
|
addMessage: function(message, animate) {
|
2015-03-10 16:06:53 -04:00
|
|
|
this.addMessageAtIndex(message, -1, animate);
|
2014-12-05 10:24:35 -05:00
|
|
|
},
|
|
|
|
|
|
|
|
addMessageAtIndex: function(message, index, animate) {
|
|
|
|
let obj = {
|
|
|
|
container: null,
|
|
|
|
destroyId: 0,
|
|
|
|
keyFocusId: 0,
|
|
|
|
closeId: 0
|
|
|
|
};
|
|
|
|
let pivot = new Clutter.Point({ x: .5, y: .5 });
|
|
|
|
let scale = animate ? 0 : 1;
|
|
|
|
obj.container = new St.Widget({ layout_manager: new ScaleLayout(),
|
|
|
|
pivot_point: pivot,
|
|
|
|
scale_x: scale, scale_y: scale });
|
|
|
|
obj.keyFocusId = message.actor.connect('key-focus-in',
|
|
|
|
Lang.bind(this, this._onKeyFocusIn));
|
|
|
|
obj.destroyId = message.actor.connect('destroy',
|
|
|
|
Lang.bind(this, function() {
|
|
|
|
this.removeMessage(message, false);
|
|
|
|
}));
|
|
|
|
obj.closeId = message.connect('close',
|
|
|
|
Lang.bind(this, function() {
|
|
|
|
this.removeMessage(message, true);
|
|
|
|
}));
|
|
|
|
|
|
|
|
this._messages.set(message, obj);
|
|
|
|
obj.container.add_actor(message.actor);
|
|
|
|
|
|
|
|
this._list.insert_child_at_index(obj.container, index);
|
|
|
|
|
|
|
|
if (animate)
|
|
|
|
Tweener.addTween(obj.container, { scale_x: 1,
|
|
|
|
scale_y: 1,
|
|
|
|
time: MESSAGE_ANIMATION_TIME,
|
|
|
|
transition: 'easeOutQuad' });
|
|
|
|
},
|
|
|
|
|
2015-02-25 18:26:13 -05:00
|
|
|
moveMessage: function(message, index, animate) {
|
|
|
|
let obj = this._messages.get(message);
|
|
|
|
|
|
|
|
if (!animate) {
|
|
|
|
this._list.set_child_at_index(obj.container, index);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
let onComplete = Lang.bind(this, function() {
|
|
|
|
this._list.set_child_at_index(obj.container, index);
|
|
|
|
Tweener.addTween(obj.container, { scale_x: 1,
|
|
|
|
scale_y: 1,
|
|
|
|
time: MESSAGE_ANIMATION_TIME,
|
|
|
|
transition: 'easeOutQuad' });
|
|
|
|
});
|
|
|
|
Tweener.addTween(obj.container, { scale_x: 0,
|
|
|
|
scale_y: 0,
|
|
|
|
time: MESSAGE_ANIMATION_TIME,
|
|
|
|
transition: 'easeOutQuad',
|
|
|
|
onComplete: onComplete });
|
|
|
|
},
|
|
|
|
|
2014-12-05 10:24:35 -05:00
|
|
|
removeMessage: function(message, animate) {
|
|
|
|
let obj = this._messages.get(message);
|
|
|
|
|
|
|
|
message.actor.disconnect(obj.destroyId);
|
|
|
|
message.actor.disconnect(obj.keyFocusId);
|
|
|
|
message.disconnect(obj.closeId);
|
|
|
|
|
|
|
|
this._messages.delete(message);
|
|
|
|
|
2015-03-11 13:26:55 -04:00
|
|
|
if (animate) {
|
2014-12-05 10:24:35 -05:00
|
|
|
Tweener.addTween(obj.container, { scale_x: 0, scale_y: 0,
|
|
|
|
time: MESSAGE_ANIMATION_TIME,
|
|
|
|
transition: 'easeOutQuad',
|
|
|
|
onComplete: function() {
|
|
|
|
obj.container.destroy();
|
2015-03-11 13:26:55 -04:00
|
|
|
global.sync_pointer();
|
2014-12-05 10:24:35 -05:00
|
|
|
}});
|
2015-03-11 13:26:55 -04:00
|
|
|
} else {
|
2014-12-05 10:24:35 -05:00
|
|
|
obj.container.destroy();
|
2015-03-11 13:26:55 -04:00
|
|
|
global.sync_pointer();
|
|
|
|
}
|
2014-12-05 10:24:35 -05:00
|
|
|
},
|
|
|
|
|
|
|
|
clear: function() {
|
|
|
|
let messages = [...this._messages.keys()].filter(function(message) {
|
2015-03-11 17:33:20 -04:00
|
|
|
return message.canClose();
|
2014-12-05 10:24:35 -05:00
|
|
|
});
|
|
|
|
|
|
|
|
// If there are few messages, letting them all zoom out looks OK
|
|
|
|
if (messages.length < 2) {
|
2015-03-11 17:20:21 -04:00
|
|
|
messages.forEach(function(message) {
|
|
|
|
message.close();
|
|
|
|
});
|
2014-12-05 10:24:35 -05:00
|
|
|
} else {
|
|
|
|
// Otherwise we slide them out one by one, and then zoom them
|
|
|
|
// out "off-screen" in the end to smoothly shrink the parent
|
|
|
|
let delay = MESSAGE_ANIMATION_TIME / Math.max(messages.length, 5);
|
|
|
|
for (let i = 0; i < messages.length; i++) {
|
|
|
|
let message = messages[i];
|
|
|
|
let obj = this._messages.get(message);
|
|
|
|
Tweener.addTween(obj.container,
|
|
|
|
{ anchor_x: this._list.width,
|
|
|
|
opacity: 0,
|
|
|
|
time: MESSAGE_ANIMATION_TIME,
|
|
|
|
delay: i * delay,
|
|
|
|
transition: 'easeOutQuad',
|
2015-03-11 17:20:21 -04:00
|
|
|
onComplete: function() {
|
|
|
|
message.close();
|
|
|
|
}});
|
2014-12-05 10:24:35 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
_canClear: function() {
|
|
|
|
for (let message of this._messages.keys())
|
2015-03-11 17:33:20 -04:00
|
|
|
if (message.canClose())
|
2014-12-05 10:24:35 -05:00
|
|
|
return true;
|
|
|
|
return false;
|
|
|
|
},
|
|
|
|
|
2015-03-02 20:04:37 -05:00
|
|
|
_shouldShow: function() {
|
|
|
|
return !this.empty;
|
2014-12-05 10:24:35 -05:00
|
|
|
},
|
|
|
|
|
|
|
|
_sync: function() {
|
|
|
|
let empty = this._list.get_n_children() == 0;
|
|
|
|
let changed = this.empty !== empty;
|
|
|
|
this.empty = empty;
|
|
|
|
|
|
|
|
if (changed)
|
|
|
|
this.emit('empty-changed');
|
|
|
|
|
|
|
|
this._closeButton.visible = this._canClear();
|
2015-03-02 20:04:37 -05:00
|
|
|
this.actor.visible = this.allowed && this._shouldShow();
|
2014-12-05 10:24:35 -05:00
|
|
|
}
|
|
|
|
});
|
|
|
|
Signals.addSignalMethods(MessageListSection.prototype);
|
|
|
|
|
2014-12-11 12:29:17 -05:00
|
|
|
const EventsSection = new Lang.Class({
|
|
|
|
Name: 'EventsSection',
|
|
|
|
Extends: MessageListSection,
|
2011-01-28 16:35:46 -05:00
|
|
|
|
2012-09-01 08:42:53 -04:00
|
|
|
_init: function() {
|
2014-06-24 15:17:09 -04:00
|
|
|
this._desktopSettings = new Gio.Settings({ schema_id: 'org.gnome.desktop.interface' });
|
2014-12-11 12:29:17 -05:00
|
|
|
this._desktopSettings.connect('changed', Lang.bind(this, this._reloadEvents));
|
|
|
|
this._eventSource = new EmptyEventSource();
|
|
|
|
|
2015-03-06 17:58:33 -05:00
|
|
|
this._ignoredEvents = new Map();
|
|
|
|
|
|
|
|
let savedState = global.get_persistent_state('as', 'ignored_events');
|
|
|
|
if (savedState)
|
|
|
|
savedState.deep_unpack().forEach(Lang.bind(this,
|
|
|
|
function(eventId) {
|
|
|
|
this._ignoredEvents.set(eventId, true);
|
|
|
|
}));
|
|
|
|
|
2014-12-11 12:29:17 -05:00
|
|
|
this.parent('');
|
|
|
|
|
|
|
|
Shell.AppSystem.get_default().connect('installed-changed',
|
|
|
|
Lang.bind(this, this._appInstalledChanged));
|
|
|
|
this._appInstalledChanged();
|
2012-09-01 08:42:53 -04:00
|
|
|
},
|
2011-01-28 21:09:47 -05:00
|
|
|
|
2015-03-06 17:58:33 -05:00
|
|
|
_ignoreEvent: function(event) {
|
|
|
|
this._ignoredEvents.set(event.id, true);
|
|
|
|
let savedState = new GLib.Variant('as', [...this._ignoredEvents.keys()]);
|
|
|
|
global.set_persistent_state('ignored_events', savedState);
|
|
|
|
},
|
|
|
|
|
2012-09-01 08:42:53 -04:00
|
|
|
setEventSource: function(eventSource) {
|
|
|
|
this._eventSource = eventSource;
|
2014-12-11 12:29:17 -05:00
|
|
|
this._eventSource.connect('changed', Lang.bind(this, this._reloadEvents));
|
2011-01-28 16:35:46 -05:00
|
|
|
},
|
|
|
|
|
2015-03-02 20:04:37 -05:00
|
|
|
get allowed() {
|
|
|
|
return Main.sessionMode.showCalendarEvents;
|
|
|
|
},
|
|
|
|
|
2014-12-11 12:29:17 -05:00
|
|
|
_updateTitle: function() {
|
2015-03-11 17:36:00 -04:00
|
|
|
if (_isToday(this._date)) {
|
2014-12-11 12:29:17 -05:00
|
|
|
this._title.label = _("Events");
|
|
|
|
return;
|
2014-09-17 21:32:13 -04:00
|
|
|
}
|
2013-06-08 12:31:30 -04:00
|
|
|
|
2014-12-11 12:29:17 -05:00
|
|
|
let dayFormat;
|
2015-03-11 17:36:00 -04:00
|
|
|
let now = new Date();
|
2014-12-11 12:29:17 -05:00
|
|
|
if (_sameYear(this._date, now))
|
|
|
|
/* Translators: Shown on calendar heading when selected day occurs on current year */
|
|
|
|
dayFormat = Shell.util_translate_time_string(NC_("calendar heading",
|
|
|
|
"%A, %B %d"));
|
|
|
|
else
|
|
|
|
/* Translators: Shown on calendar heading when selected day occurs on different year */
|
|
|
|
dayFormat = Shell.util_translate_time_string(NC_("calendar heading",
|
|
|
|
"%A, %B %d, %Y"));
|
|
|
|
this._title.label = this._date.toLocaleFormat(dayFormat);
|
2011-01-28 16:35:46 -05:00
|
|
|
},
|
|
|
|
|
2014-12-11 12:29:17 -05:00
|
|
|
_reloadEvents: function() {
|
|
|
|
if (this._eventSource.isLoading)
|
|
|
|
return;
|
2011-01-28 16:35:46 -05:00
|
|
|
|
2014-12-11 12:29:17 -05:00
|
|
|
this._reloading = true;
|
2011-01-28 16:35:46 -05:00
|
|
|
|
2014-12-11 12:29:17 -05:00
|
|
|
this._list.destroy_all_children();
|
2011-01-28 16:35:46 -05:00
|
|
|
|
2014-12-11 12:29:17 -05:00
|
|
|
let periodBegin = _getBeginningOfDay(this._date);
|
|
|
|
let periodEnd = _getEndOfDay(this._date);
|
|
|
|
let events = this._eventSource.getEvents(periodBegin, periodEnd);
|
2011-01-28 16:35:46 -05:00
|
|
|
|
2014-12-11 12:29:17 -05:00
|
|
|
for (let i = 0; i < events.length; i++) {
|
|
|
|
let event = events[i];
|
2015-03-06 17:58:33 -05:00
|
|
|
|
|
|
|
if (this._ignoredEvents.has(event.id))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
let message = new EventMessage(event, this._date);
|
|
|
|
message.connect('close', Lang.bind(this, function() {
|
|
|
|
this._ignoreEvent(event);
|
|
|
|
}));
|
|
|
|
this.addMessage(message, false);
|
2011-01-28 16:35:46 -05:00
|
|
|
}
|
2013-06-08 12:31:30 -04:00
|
|
|
|
2014-12-11 12:29:17 -05:00
|
|
|
this._reloading = false;
|
|
|
|
this._sync();
|
2011-01-28 16:35:46 -05:00
|
|
|
},
|
|
|
|
|
2014-12-11 12:29:17 -05:00
|
|
|
_appInstalledChanged: function() {
|
|
|
|
this._calendarApp = undefined;
|
|
|
|
this._title.reactive = (this._getCalendarApp() != null);
|
2011-01-28 16:35:46 -05:00
|
|
|
},
|
|
|
|
|
2014-12-11 12:29:17 -05:00
|
|
|
_getCalendarApp: function() {
|
|
|
|
if (this._calendarApp !== undefined)
|
|
|
|
return this._calendarApp;
|
2011-01-28 16:35:46 -05:00
|
|
|
|
2014-12-11 12:29:17 -05:00
|
|
|
let apps = Gio.AppInfo.get_recommended_for_type('text/calendar');
|
|
|
|
if (apps && (apps.length > 0)) {
|
|
|
|
let app = Gio.AppInfo.get_default_for_type('text/calendar', false);
|
|
|
|
let defaultInRecommended = apps.some(function(a) { return a.equal(app); });
|
|
|
|
this._calendarApp = defaultInRecommended ? app : apps[0];
|
2011-01-28 16:35:46 -05:00
|
|
|
} else {
|
2014-12-11 12:29:17 -05:00
|
|
|
this._calendarApp = null;
|
2011-01-28 16:35:46 -05:00
|
|
|
}
|
2014-12-11 12:29:17 -05:00
|
|
|
return this._calendarApp;
|
|
|
|
},
|
|
|
|
|
|
|
|
_onTitleClicked: function() {
|
|
|
|
this.parent();
|
|
|
|
|
|
|
|
let app = this._getCalendarApp();
|
|
|
|
if (app.get_id() == 'evolution.desktop')
|
|
|
|
app = Gio.DesktopAppInfo.new('evolution-calendar.desktop');
|
|
|
|
app.launch([], global.create_app_launch_context(0, -1));
|
2011-01-28 16:35:46 -05:00
|
|
|
},
|
|
|
|
|
|
|
|
setDate: function(date) {
|
2014-12-11 12:29:17 -05:00
|
|
|
this.parent(date);
|
|
|
|
this._updateTitle();
|
|
|
|
this._reloadEvents();
|
2011-01-28 16:35:46 -05:00
|
|
|
},
|
|
|
|
|
2015-03-02 20:04:37 -05:00
|
|
|
_shouldShow: function() {
|
2015-03-11 17:36:00 -04:00
|
|
|
return !this.empty || !_isToday(this._date);
|
2014-12-11 12:29:17 -05:00
|
|
|
},
|
|
|
|
|
|
|
|
_sync: function() {
|
|
|
|
if (this._reloading)
|
2012-10-23 12:41:24 -04:00
|
|
|
return;
|
|
|
|
|
2014-12-11 12:29:17 -05:00
|
|
|
this.parent();
|
2009-09-30 10:02:08 -04:00
|
|
|
}
|
2011-11-20 12:56:27 -05:00
|
|
|
});
|
2014-12-05 10:24:35 -05:00
|
|
|
|
2015-02-11 14:41:56 -05:00
|
|
|
const NotificationSection = new Lang.Class({
|
|
|
|
Name: 'NotificationSection',
|
|
|
|
Extends: MessageListSection,
|
|
|
|
|
|
|
|
_init: function() {
|
2015-02-24 13:06:53 -05:00
|
|
|
this.parent(_("Notifications"));
|
2015-02-11 14:41:56 -05:00
|
|
|
|
|
|
|
this._sources = new Map();
|
|
|
|
this._nUrgent = 0;
|
|
|
|
|
|
|
|
Main.messageTray.connect('source-added', Lang.bind(this, this._sourceAdded));
|
|
|
|
Main.messageTray.getSources().forEach(Lang.bind(this, function(source) {
|
|
|
|
this._sourceAdded(Main.messageTray, source);
|
|
|
|
}));
|
|
|
|
|
|
|
|
this.actor.connect('notify::mapped', Lang.bind(this, this._onMapped));
|
2015-03-02 20:04:37 -05:00
|
|
|
},
|
2015-02-11 14:41:56 -05:00
|
|
|
|
2015-03-02 20:04:37 -05:00
|
|
|
get allowed() {
|
|
|
|
return Main.sessionMode.hasNotifications &&
|
|
|
|
!Main.sessionMode.isGreeter;
|
2015-02-11 14:41:56 -05:00
|
|
|
},
|
|
|
|
|
2015-02-25 18:26:13 -05:00
|
|
|
_createTimeLabel: function() {
|
|
|
|
let label = Util.createTimeLabel(new Date());
|
|
|
|
label.style_class = 'event-time',
|
|
|
|
label.x_align = Clutter.ActorAlign.END;
|
|
|
|
return label;
|
|
|
|
},
|
|
|
|
|
2015-02-11 14:41:56 -05:00
|
|
|
_sourceAdded: function(tray, source) {
|
|
|
|
let obj = {
|
|
|
|
destroyId: 0,
|
|
|
|
notificationAddedId: 0,
|
|
|
|
};
|
|
|
|
|
|
|
|
obj.destroyId = source.connect('destroy', Lang.bind(this, function(source) {
|
|
|
|
this._onSourceDestroy(source, obj);
|
|
|
|
}));
|
|
|
|
obj.notificationAddedId = source.connect('notification-added',
|
|
|
|
Lang.bind(this, this._onNotificationAdded));
|
|
|
|
|
|
|
|
this._sources.set(source, obj);
|
|
|
|
},
|
|
|
|
|
|
|
|
_onNotificationAdded: function(source, notification) {
|
|
|
|
let message = new NotificationMessage(notification);
|
2015-02-25 18:26:13 -05:00
|
|
|
message.setSecondaryActor(this._createTimeLabel());
|
2015-02-11 14:41:56 -05:00
|
|
|
|
|
|
|
let isUrgent = notification.urgency == MessageTray.Urgency.CRITICAL;
|
2015-02-25 18:26:13 -05:00
|
|
|
|
|
|
|
let updatedId = notification.connect('updated', Lang.bind(this,
|
|
|
|
function() {
|
|
|
|
message.setSecondaryActor(this._createTimeLabel());
|
|
|
|
this.moveMessage(message, isUrgent ? 0 : this._nUrgent, this.actor.mapped);
|
|
|
|
}));
|
|
|
|
let destroyId = notification.connect('destroy', Lang.bind(this,
|
|
|
|
function() {
|
|
|
|
notification.disconnect(destroyId);
|
|
|
|
notification.disconnect(updatedId);
|
|
|
|
if (isUrgent)
|
|
|
|
this._nUrgent--;
|
|
|
|
}));
|
|
|
|
|
2015-02-11 14:41:56 -05:00
|
|
|
if (isUrgent) {
|
|
|
|
// Keep track of urgent notifications to keep them on top
|
|
|
|
this._nUrgent++;
|
|
|
|
} else if (this.mapped) {
|
|
|
|
// Only acknowledge non-urgent notifications in case it
|
|
|
|
// has important actions that are inaccessible when not
|
|
|
|
// shown as banner
|
|
|
|
notification.acknowledged = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
let index = isUrgent ? 0 : this._nUrgent;
|
|
|
|
this.addMessageAtIndex(message, index, this.actor.mapped);
|
|
|
|
},
|
|
|
|
|
|
|
|
_onSourceDestroy: function(source, obj) {
|
|
|
|
source.disconnect(obj.destroyId);
|
|
|
|
source.disconnect(obj.notificationAddedId);
|
|
|
|
|
|
|
|
this._sources.delete(source);
|
|
|
|
},
|
|
|
|
|
|
|
|
_onMapped: function() {
|
|
|
|
if (!this.actor.mapped)
|
|
|
|
return;
|
|
|
|
|
|
|
|
for (let message of this._messages.keys())
|
|
|
|
if (message.notification.urgency != MessageTray.Urgency.CRITICAL)
|
|
|
|
message.notification.acknowledged = true;
|
|
|
|
},
|
|
|
|
|
|
|
|
_onTitleClicked: function() {
|
|
|
|
this.parent();
|
|
|
|
|
|
|
|
let app = Shell.AppSystem.get_default().lookup_app('gnome-notifications-panel.desktop');
|
|
|
|
|
|
|
|
if (!app) {
|
|
|
|
log('Settings panel for desktop file ' + desktopFile + ' could not be loaded!');
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
app.activate();
|
|
|
|
},
|
|
|
|
|
2015-03-02 20:04:37 -05:00
|
|
|
_shouldShow: function() {
|
2015-03-11 17:36:00 -04:00
|
|
|
return !this.empty && _isToday(this._date);
|
2015-02-11 14:41:56 -05:00
|
|
|
},
|
|
|
|
|
2015-03-02 20:04:37 -05:00
|
|
|
_sync: function() {
|
|
|
|
this.parent();
|
2015-02-11 14:41:56 -05:00
|
|
|
this._title.reactive = Main.sessionMode.allowSettings;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2014-12-05 10:24:35 -05:00
|
|
|
const Placeholder = new Lang.Class({
|
|
|
|
Name: 'Placeholder',
|
|
|
|
|
|
|
|
_init: function() {
|
|
|
|
this.actor = new St.BoxLayout({ style_class: 'message-list-placeholder',
|
|
|
|
vertical: true });
|
|
|
|
|
|
|
|
this._date = new Date();
|
|
|
|
|
2015-02-11 14:41:56 -05:00
|
|
|
let todayFile = Gio.File.new_for_uri('resource:///org/gnome/shell/theme/no-notifications.svg');
|
|
|
|
let otherFile = Gio.File.new_for_uri('resource:///org/gnome/shell/theme/no-events.svg');
|
|
|
|
this._todayIcon = new Gio.FileIcon({ file: todayFile });
|
|
|
|
this._otherIcon = new Gio.FileIcon({ file: otherFile });
|
2014-12-05 10:24:35 -05:00
|
|
|
|
2015-02-11 14:41:56 -05:00
|
|
|
this._icon = new St.Icon();
|
2014-12-05 10:24:35 -05:00
|
|
|
this.actor.add_actor(this._icon);
|
|
|
|
|
2015-02-11 14:41:56 -05:00
|
|
|
this._label = new St.Label();
|
2014-12-05 10:24:35 -05:00
|
|
|
this.actor.add_actor(this._label);
|
2015-02-11 14:41:56 -05:00
|
|
|
|
|
|
|
this._sync();
|
|
|
|
},
|
|
|
|
|
|
|
|
setDate: function(date) {
|
|
|
|
if (_sameDay(this._date, date))
|
|
|
|
return;
|
|
|
|
this._date = date;
|
|
|
|
this._sync();
|
|
|
|
},
|
|
|
|
|
|
|
|
_sync: function() {
|
2015-03-11 17:36:00 -04:00
|
|
|
let isToday = _isToday(this._date);
|
2015-02-11 14:41:56 -05:00
|
|
|
if (isToday && this._icon.gicon == this._todayIcon)
|
|
|
|
return;
|
|
|
|
if (!isToday && this._icon.gicon == this._otherIcon)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (isToday) {
|
|
|
|
this._icon.gicon = this._todayIcon;
|
|
|
|
this._label.text = _("No Notifications");
|
|
|
|
} else {
|
|
|
|
this._icon.gicon = this._otherIcon;
|
|
|
|
this._label.text = _("No Events");
|
|
|
|
}
|
2014-12-05 10:24:35 -05:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
const MessageList = new Lang.Class({
|
|
|
|
Name: 'MessageList',
|
|
|
|
|
|
|
|
_init: function() {
|
|
|
|
this.actor = new St.Widget({ style_class: 'message-list',
|
|
|
|
layout_manager: new Clutter.BinLayout(),
|
|
|
|
x_expand: true, y_expand: true });
|
|
|
|
|
|
|
|
this._placeholder = new Placeholder();
|
|
|
|
this.actor.add_actor(this._placeholder.actor);
|
|
|
|
|
|
|
|
this._scrollView = new St.ScrollView({ style_class: 'vfade',
|
|
|
|
overlay_scrollbars: true,
|
|
|
|
x_expand: true, y_expand: true,
|
|
|
|
x_fill: true, y_fill: true });
|
|
|
|
this._scrollView.set_policy(Gtk.PolicyType.NEVER, Gtk.PolicyType.AUTOMATIC);
|
|
|
|
this.actor.add_actor(this._scrollView);
|
|
|
|
|
|
|
|
this._sectionList = new St.BoxLayout({ style_class: 'message-list-sections',
|
|
|
|
vertical: true,
|
|
|
|
y_expand: true,
|
|
|
|
y_align: Clutter.ActorAlign.START });
|
|
|
|
this._scrollView.add_actor(this._sectionList);
|
|
|
|
this._sections = new Map();
|
2014-12-11 12:29:17 -05:00
|
|
|
|
2015-02-11 14:41:56 -05:00
|
|
|
this._notificationSection = new NotificationSection();
|
|
|
|
this._addSection(this._notificationSection);
|
|
|
|
|
2014-12-11 12:29:17 -05:00
|
|
|
this._eventsSection = new EventsSection();
|
|
|
|
this._addSection(this._eventsSection);
|
2015-03-02 20:04:37 -05:00
|
|
|
|
|
|
|
Main.sessionMode.connect('updated', Lang.bind(this, this._sync));
|
2014-12-05 10:24:35 -05:00
|
|
|
},
|
|
|
|
|
|
|
|
_addSection: function(section) {
|
|
|
|
let obj = {
|
|
|
|
destroyId: 0,
|
|
|
|
visibleId: 0,
|
|
|
|
emptyChangedId: 0,
|
|
|
|
keyFocusId: 0
|
|
|
|
};
|
|
|
|
obj.destroyId = section.actor.connect('destroy', Lang.bind(this,
|
|
|
|
function() {
|
|
|
|
this._removeSection(section);
|
|
|
|
}));
|
|
|
|
obj.visibleId = section.actor.connect('notify::visible',
|
|
|
|
Lang.bind(this, this._sync));
|
|
|
|
obj.emptyChangedId = section.connect('empty-changed',
|
|
|
|
Lang.bind(this, this._sync));
|
|
|
|
obj.keyFocusId = section.connect('key-focus-in',
|
|
|
|
Lang.bind(this, this._onKeyFocusIn));
|
|
|
|
|
|
|
|
this._sections.set(section, obj);
|
|
|
|
this._sectionList.add_actor(section.actor);
|
|
|
|
this._sync();
|
|
|
|
},
|
|
|
|
|
|
|
|
_removeSection: function(section) {
|
|
|
|
let obj = this._sections.get(section);
|
|
|
|
section.actor.disconnect(obj.destroyId);
|
|
|
|
section.actor.disconnect(obj.visibleId);
|
|
|
|
section.disconnect(obj.emptyChangedId);
|
|
|
|
section.disconnect(obj.keyFocusId);
|
|
|
|
|
|
|
|
this._sections.delete(section);
|
|
|
|
this._sectionList.remove_actor(section.actor);
|
|
|
|
this._sync();
|
|
|
|
},
|
|
|
|
|
|
|
|
_onKeyFocusIn: function(section, actor) {
|
|
|
|
Util.ensureActorVisibleInScrollView(this._scrollView, actor);
|
|
|
|
},
|
|
|
|
|
|
|
|
_sync: function() {
|
2015-03-02 20:04:37 -05:00
|
|
|
let sections = [...this._sections.keys()];
|
|
|
|
let visible = sections.some(function(s) {
|
|
|
|
return s.allowed;
|
|
|
|
});
|
|
|
|
this.actor.visible = visible;
|
|
|
|
if (!visible)
|
|
|
|
return;
|
|
|
|
|
|
|
|
let showPlaceholder = sections.every(function(s) {
|
2014-12-05 10:24:35 -05:00
|
|
|
return s.empty || !s.actor.visible;
|
|
|
|
});
|
|
|
|
this._placeholder.actor.visible = showPlaceholder;
|
|
|
|
},
|
|
|
|
|
2014-12-11 12:29:17 -05:00
|
|
|
setEventSource: function(eventSource) {
|
|
|
|
this._eventsSection.setEventSource(eventSource);
|
|
|
|
},
|
|
|
|
|
2014-12-05 10:24:35 -05:00
|
|
|
setDate: function(date) {
|
|
|
|
for (let section of this._sections.keys())
|
|
|
|
section.setDate(date);
|
2015-02-11 14:41:56 -05:00
|
|
|
this._placeholder.setDate(date);
|
2014-12-05 10:24:35 -05:00
|
|
|
}
|
|
|
|
});
|