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
|
|
|
|
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;
|
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;
|
|
|
|
const Shell = imports.gi.Shell;
|
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
|
|
|
|
2014-04-26 19:06:13 -04:00
|
|
|
// alias to prevent xgettext from picking up strings translated in GTK+
|
|
|
|
const gtk30_ = Gettext_gtk30.gettext;
|
2014-10-16 08:38:13 -04:00
|
|
|
const NC_ = function(context, str) { return str; };
|
2014-04-26 19:06:13 -04:00
|
|
|
|
2011-01-28 16:35:46 -05:00
|
|
|
// in org.gnome.desktop.interface
|
|
|
|
const CLOCK_FORMAT_KEY = 'clock-format';
|
|
|
|
|
|
|
|
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());
|
|
|
|
}
|
|
|
|
|
2011-01-28 16:35:46 -05:00
|
|
|
/* TODO: maybe needs config - right now we assume that Saturday and
|
|
|
|
* Sunday are non-work days (not true in e.g. Israel, it's Sunday and
|
|
|
|
* Monday there)
|
|
|
|
*/
|
|
|
|
function _isWorkDay(date) {
|
|
|
|
return date.getDay() != 0 && date.getDay() != 6;
|
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2014-09-17 21:32:13 -04:00
|
|
|
function _formatEventTime(event, clockFormat, periodBegin, periodEnd) {
|
2011-01-28 16:35:46 -05:00
|
|
|
let ret;
|
2014-09-17 21:32:13 -04:00
|
|
|
let allDay = (event.allDay || (event.date <= periodBegin && event.end >= periodEnd));
|
|
|
|
if (allDay) {
|
2011-02-03 06:12:57 -05:00
|
|
|
/* Translators: Shown in calendar event list for all day events
|
|
|
|
* Keep it short, best if you can use less then 10 characters
|
|
|
|
*/
|
|
|
|
ret = C_("event list time", "All Day");
|
2011-01-28 16:35:46 -05:00
|
|
|
} else {
|
2014-09-17 21:32:13 -04:00
|
|
|
let date = event.date >= periodBegin ? event.date : event.end;
|
2011-01-28 16:35:46 -05:00
|
|
|
switch (clockFormat) {
|
|
|
|
case '24h':
|
2012-11-28 22:59:24 -05:00
|
|
|
/* Translators: Shown in calendar event list, if 24h format,
|
|
|
|
\u2236 is a ratio character, similar to : */
|
2014-09-17 21:32:13 -04:00
|
|
|
ret = date.toLocaleFormat(C_("event list time", "%H\u2236%M"));
|
2011-01-28 16:35:46 -05:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
/* explicit fall-through */
|
|
|
|
case '12h':
|
2013-03-23 00:15:20 -04:00
|
|
|
/* Translators: Shown in calendar event list, if 12h format,
|
2012-11-28 22:59:24 -05:00
|
|
|
\u2236 is a ratio character, similar to : and \u2009 is
|
|
|
|
a thin space */
|
2014-09-17 21:32:13 -04:00
|
|
|
ret = date.toLocaleFormat(C_("event list time", "%l\u2236%M\u2009%p"));
|
2011-01-28 16:35:46 -05:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2010-05-27 03:31:46 -04:00
|
|
|
function _getCalendarWeekForDate(date) {
|
2010-05-30 17:17:40 -04:00
|
|
|
// Based on the algorithms found here:
|
|
|
|
// http://en.wikipedia.org/wiki/Talk:ISO_week_date
|
|
|
|
let midnightDate = new Date(date.getFullYear(), date.getMonth(), date.getDate());
|
|
|
|
// Need to get Monday to be 1 ... Sunday to be 7
|
|
|
|
let dayOfWeek = 1 + ((midnightDate.getDay() + 6) % 7);
|
|
|
|
let nearestThursday = new Date(midnightDate.getFullYear(), midnightDate.getMonth(),
|
|
|
|
midnightDate.getDate() + (4 - dayOfWeek));
|
|
|
|
|
|
|
|
let jan1st = new Date(nearestThursday.getFullYear(), 0, 1);
|
|
|
|
let diffDate = nearestThursday - jan1st;
|
|
|
|
let dayNumber = Math.floor(Math.abs(diffDate) / MSECS_IN_DAY);
|
|
|
|
let weekNumber = Math.floor(dayNumber / 7) + 1;
|
|
|
|
|
|
|
|
return weekNumber;
|
2010-05-27 03:31:46 -04:00
|
|
|
}
|
|
|
|
|
2011-01-28 16:35:46 -05:00
|
|
|
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
|
|
|
*/
|
2011-02-03 06:12:57 -05:00
|
|
|
C_("grid sunday", "S"),
|
2011-01-28 16:35:46 -05:00
|
|
|
/* Translators: Calendar grid abbreviation for Monday */
|
2011-02-03 06:12:57 -05:00
|
|
|
C_("grid monday", "M"),
|
2011-01-28 16:35:46 -05:00
|
|
|
/* Translators: Calendar grid abbreviation for Tuesday */
|
2011-02-03 06:12:57 -05:00
|
|
|
C_("grid tuesday", "T"),
|
2011-01-28 16:35:46 -05:00
|
|
|
/* Translators: Calendar grid abbreviation for Wednesday */
|
2011-02-03 06:12:57 -05:00
|
|
|
C_("grid wednesday", "W"),
|
2011-01-28 16:35:46 -05:00
|
|
|
/* Translators: Calendar grid abbreviation for Thursday */
|
2011-02-03 06:12:57 -05:00
|
|
|
C_("grid thursday", "T"),
|
2011-01-28 16:35:46 -05:00
|
|
|
/* Translators: Calendar grid abbreviation for Friday */
|
2011-02-03 06:12:57 -05:00
|
|
|
C_("grid friday", "F"),
|
2011-01-28 16:35:46 -05:00
|
|
|
/* Translators: Calendar grid abbreviation for Saturday */
|
2011-02-03 06:12:57 -05:00
|
|
|
C_("grid saturday", "S")
|
2011-01-28 16:35:46 -05:00
|
|
|
];
|
|
|
|
return abbreviations[dayNumber];
|
|
|
|
}
|
|
|
|
|
|
|
|
function _getEventDayAbbreviation(dayNumber) {
|
|
|
|
let abbreviations = [
|
|
|
|
/* Translators: Event list abbreviation for Sunday.
|
|
|
|
*
|
2011-02-03 06:12:57 -05:00
|
|
|
* NOTE: These list abbreviations are normally not shown together
|
2011-01-28 16:35:46 -05:00
|
|
|
* so they need to be unique (e.g. Tuesday and Thursday cannot
|
|
|
|
* both be 'T').
|
|
|
|
*/
|
2011-02-03 06:12:57 -05:00
|
|
|
C_("list sunday", "Su"),
|
2011-01-28 16:35:46 -05:00
|
|
|
/* Translators: Event list abbreviation for Monday */
|
2011-02-03 06:12:57 -05:00
|
|
|
C_("list monday", "M"),
|
2011-01-28 16:35:46 -05:00
|
|
|
/* Translators: Event list abbreviation for Tuesday */
|
2011-02-03 06:12:57 -05:00
|
|
|
C_("list tuesday", "T"),
|
2011-01-28 16:35:46 -05:00
|
|
|
/* Translators: Event list abbreviation for Wednesday */
|
2011-02-03 06:12:57 -05:00
|
|
|
C_("list wednesday", "W"),
|
2011-01-28 16:35:46 -05:00
|
|
|
/* Translators: Event list abbreviation for Thursday */
|
2011-02-03 06:12:57 -05:00
|
|
|
C_("list thursday", "Th"),
|
2011-01-28 16:35:46 -05:00
|
|
|
/* Translators: Event list abbreviation for Friday */
|
2011-02-03 06:12:57 -05:00
|
|
|
C_("list friday", "F"),
|
2011-01-28 16:35:46 -05:00
|
|
|
/* Translators: Event list abbreviation for Saturday */
|
2011-02-03 06:12:57 -05:00
|
|
|
C_("list saturday", "S")
|
2011-01-28 16:35:46 -05:00
|
|
|
];
|
|
|
|
return abbreviations[dayNumber];
|
|
|
|
}
|
|
|
|
|
|
|
|
// 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
|
|
|
|
2011-02-25 17:42:25 -05:00
|
|
|
_init: function(date, end, summary, allDay) {
|
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) {
|
|
|
|
try {
|
|
|
|
this._dbusProxy.init_finish(result);
|
|
|
|
} catch(e) {
|
|
|
|
log('Error loading calendars: ' + e.message);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
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');
|
|
|
|
}));
|
|
|
|
|
2013-02-17 09:52:53 -05:00
|
|
|
this._initialized = true;
|
2012-10-29 11:37:07 -04:00
|
|
|
this.emit('notify::has-calendars');
|
2013-02-17 09:52:53 -05:00
|
|
|
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) {
|
|
|
|
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);
|
|
|
|
let summary = a[1];
|
|
|
|
let allDay = a[3];
|
|
|
|
let event = new CalendarEvent(date, end, summary, allDay);
|
|
|
|
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',
|
2014-06-20 10:23:32 -04:00
|
|
|
layout_manager: new Clutter.GridLayout(),
|
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();
|
2014-06-20 10:23:32 -04:00
|
|
|
layout.attach(this._topBox, 0, 0, offsetCols + 7, 1);
|
2009-09-30 10:02:08 -04:00
|
|
|
|
2013-04-30 18:32:43 -04:00
|
|
|
this._backButton = new St.Button({ style_class: 'calendar-change-month-back',
|
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
|
|
|
|
2013-04-30 18:32:43 -04:00
|
|
|
this._forwardButton = new St.Button({ style_class: 'calendar-change-month-forward',
|
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',
|
|
|
|
text: customDayAbbrev });
|
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;
|
2014-06-20 10:23:32 -04:00
|
|
|
layout.attach(label, col, 1, 1, 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);
|
|
|
|
|
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) {
|
2013-03-14 11:30:38 -04:00
|
|
|
let button = new St.Button({ label: iter.getDate().toString(),
|
|
|
|
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;
|
2014-06-20 10:23:32 -04:00
|
|
|
layout.attach(button, col, row, 1, 1);
|
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) {
|
|
|
|
let label = new St.Label({ text: _getCalendarWeekForDate(iter).toString(),
|
2011-01-28 16:35:46 -05:00
|
|
|
style_class: 'calendar-day-base calendar-week-number'});
|
2014-06-20 10:23:32 -04:00
|
|
|
layout.attach(label, rtl ? 7 : 0, row, 1, 1);
|
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);
|
|
|
|
|
|
|
|
if (!this._calendarBegin || !_sameMonth(this._selectedDate, this._calendarBegin))
|
|
|
|
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);
|
|
|
|
|
2011-11-20 12:56:27 -05:00
|
|
|
const EventsList = new Lang.Class({
|
|
|
|
Name: 'EventsList',
|
2011-01-28 16:35:46 -05:00
|
|
|
|
2012-09-01 08:42:53 -04:00
|
|
|
_init: function() {
|
2014-08-05 17:59:28 -04:00
|
|
|
let layout = new Clutter.GridLayout({ orientation: Clutter.Orientation.VERTICAL });
|
2013-07-08 20:39:42 -04:00
|
|
|
this.actor = new St.Widget({ style_class: 'events-table',
|
|
|
|
layout_manager: layout });
|
|
|
|
layout.hookup_style(this.actor);
|
2011-01-28 16:35:46 -05:00
|
|
|
this._date = new Date();
|
2014-06-24 15:17:09 -04:00
|
|
|
this._desktopSettings = new Gio.Settings({ schema_id: 'org.gnome.desktop.interface' });
|
2011-01-28 16:35:46 -05:00
|
|
|
this._desktopSettings.connect('changed', Lang.bind(this, this._update));
|
2011-06-23 20:40:36 -04:00
|
|
|
this._weekStart = Shell.util_get_week_start();
|
2012-09-01 08:42:53 -04:00
|
|
|
},
|
2011-01-28 21:09:47 -05:00
|
|
|
|
2012-09-01 08:42:53 -04:00
|
|
|
setEventSource: function(eventSource) {
|
|
|
|
this._eventSource = eventSource;
|
2013-03-04 11:04:28 -05:00
|
|
|
this._eventSource.connect('changed', Lang.bind(this, this._update));
|
2011-01-28 16:35:46 -05:00
|
|
|
},
|
|
|
|
|
2014-09-17 21:32:13 -04:00
|
|
|
_addEvent: function(event, index, includeDayName, periodBegin, periodEnd) {
|
2013-06-08 12:31:30 -04:00
|
|
|
let dayString;
|
2014-09-17 21:32:13 -04:00
|
|
|
if (includeDayName) {
|
|
|
|
if (event.date >= periodBegin)
|
|
|
|
dayString = _getEventDayAbbreviation(event.date.getDay());
|
|
|
|
else /* show event end day if it began earlier */
|
|
|
|
dayString = _getEventDayAbbreviation(event.end.getDay());
|
|
|
|
} else {
|
2013-06-08 12:31:30 -04:00
|
|
|
dayString = '';
|
2014-09-17 21:32:13 -04:00
|
|
|
}
|
2013-06-08 12:31:30 -04:00
|
|
|
|
|
|
|
let dayLabel = new St.Label({ style_class: 'events-day-dayname',
|
2014-08-05 17:59:28 -04:00
|
|
|
text: dayString,
|
|
|
|
x_align: Clutter.ActorAlign.END,
|
|
|
|
y_align: Clutter.ActorAlign.START });
|
2013-06-08 12:31:30 -04:00
|
|
|
dayLabel.clutter_text.line_wrap = false;
|
|
|
|
dayLabel.clutter_text.ellipsize = false;
|
|
|
|
|
2014-06-20 10:30:46 -04:00
|
|
|
let rtl = this.actor.get_text_direction() == Clutter.TextDirection.RTL;
|
|
|
|
|
2013-07-08 20:39:42 -04:00
|
|
|
let layout = this.actor.layout_manager;
|
2014-08-05 17:59:28 -04:00
|
|
|
layout.attach(dayLabel, rtl ? 2 : 0, index, 1, 1);
|
2013-06-08 12:31:30 -04:00
|
|
|
let clockFormat = this._desktopSettings.get_string(CLOCK_FORMAT_KEY);
|
2014-09-17 21:32:13 -04:00
|
|
|
let timeString = _formatEventTime(event, clockFormat, periodBegin, periodEnd);
|
2013-06-08 12:31:30 -04:00
|
|
|
let timeLabel = new St.Label({ style_class: 'events-day-time',
|
2014-08-05 17:59:28 -04:00
|
|
|
text: timeString,
|
|
|
|
y_align: Clutter.ActorAlign.START });
|
2013-06-08 12:31:30 -04:00
|
|
|
timeLabel.clutter_text.line_wrap = false;
|
|
|
|
timeLabel.clutter_text.ellipsize = false;
|
|
|
|
|
2014-09-17 21:32:13 -04:00
|
|
|
let preEllipsisLabel = new St.Label({ style_class: 'events-day-time-ellipses',
|
|
|
|
text: ELLIPSIS_CHAR,
|
|
|
|
y_align: Clutter.ActorAlign.START });
|
|
|
|
let postEllipsisLabel = new St.Label({ style_class: 'events-day-time-ellipses',
|
|
|
|
text: ELLIPSIS_CHAR,
|
|
|
|
y_align: Clutter.ActorAlign.START });
|
2014-10-27 18:35:35 -04:00
|
|
|
if (event.allDay || event.date >= periodBegin)
|
2014-09-17 21:32:13 -04:00
|
|
|
preEllipsisLabel.opacity = 0;
|
2014-10-27 18:35:35 -04:00
|
|
|
if (event.allDay || event.end <= periodEnd)
|
2014-09-17 21:32:13 -04:00
|
|
|
postEllipsisLabel.opacity = 0;
|
|
|
|
|
|
|
|
let timeLabelBoxLayout = new St.BoxLayout();
|
|
|
|
timeLabelBoxLayout.add(preEllipsisLabel);
|
|
|
|
timeLabelBoxLayout.add(timeLabel);
|
|
|
|
timeLabelBoxLayout.add(postEllipsisLabel);
|
|
|
|
layout.attach(timeLabelBoxLayout, 1, index, 1, 1);
|
2013-06-08 12:31:30 -04:00
|
|
|
|
|
|
|
let titleLabel = new St.Label({ style_class: 'events-day-task',
|
2014-08-05 17:59:28 -04:00
|
|
|
text: event.summary,
|
|
|
|
x_expand: true });
|
2013-06-08 12:31:30 -04:00
|
|
|
titleLabel.clutter_text.line_wrap = true;
|
|
|
|
titleLabel.clutter_text.ellipsize = false;
|
|
|
|
|
2014-08-05 17:59:28 -04:00
|
|
|
layout.attach(titleLabel, rtl ? 0 : 2, index, 1, 1);
|
2011-01-28 16:35:46 -05:00
|
|
|
},
|
|
|
|
|
2014-09-17 21:32:13 -04:00
|
|
|
_addPeriod: function(header, index, periodBegin, periodEnd, includeDayName, showNothingScheduled) {
|
|
|
|
let events = this._eventSource.getEvents(periodBegin, periodEnd);
|
2011-01-28 16:35:46 -05:00
|
|
|
|
|
|
|
if (events.length == 0 && !showNothingScheduled)
|
2013-06-08 12:31:30 -04:00
|
|
|
return index;
|
2011-01-28 16:35:46 -05:00
|
|
|
|
2013-07-08 20:39:42 -04:00
|
|
|
let label = new St.Label({ style_class: 'events-day-header', text: header });
|
|
|
|
let layout = this.actor.layout_manager;
|
2014-08-05 17:59:28 -04:00
|
|
|
layout.attach(label, 0, index, 3, 1);
|
2013-06-08 12:31:30 -04:00
|
|
|
index++;
|
2011-01-28 16:35:46 -05:00
|
|
|
|
|
|
|
for (let n = 0; n < events.length; n++) {
|
2014-09-17 21:32:13 -04:00
|
|
|
this._addEvent(events[n], index, includeDayName, periodBegin, periodEnd);
|
2013-06-08 12:31:30 -04:00
|
|
|
index++;
|
2011-01-28 16:35:46 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
if (events.length == 0 && showNothingScheduled) {
|
|
|
|
/* Translators: Text to show if there are no events */
|
2014-09-17 21:32:13 -04:00
|
|
|
let nothingEvent = new CalendarEvent(periodBegin, periodBegin, _("Nothing Scheduled"), true);
|
|
|
|
this._addEvent(nothingEvent, index, false, periodBegin, periodEnd);
|
2013-06-08 12:31:30 -04:00
|
|
|
index++;
|
2011-01-28 16:35:46 -05:00
|
|
|
}
|
2013-06-08 12:31:30 -04:00
|
|
|
|
|
|
|
return index;
|
2011-01-28 16:35:46 -05:00
|
|
|
},
|
|
|
|
|
|
|
|
_showOtherDay: function(day) {
|
2012-02-16 13:27:09 -05:00
|
|
|
this.actor.destroy_all_children();
|
2011-01-28 16:35:46 -05:00
|
|
|
|
|
|
|
let dayBegin = _getBeginningOfDay(day);
|
|
|
|
let dayEnd = _getEndOfDay(day);
|
|
|
|
|
2014-10-16 08:38:13 -04:00
|
|
|
let dayFormat;
|
2011-01-28 16:35:46 -05:00
|
|
|
let now = new Date();
|
|
|
|
if (_sameYear(day, now))
|
2011-02-03 06:12:57 -05:00
|
|
|
/* Translators: Shown on calendar heading when selected day occurs on current year */
|
2014-10-16 08:38:13 -04:00
|
|
|
dayFormat = Shell.util_translate_time_string(NC_("calendar heading",
|
|
|
|
"%A, %B %d"));
|
2011-01-28 16:35:46 -05:00
|
|
|
else
|
2011-02-03 06:12:57 -05:00
|
|
|
/* Translators: Shown on calendar heading when selected day occurs on different year */
|
2014-10-16 08:38:13 -04:00
|
|
|
dayFormat = Shell.util_translate_time_string(NC_("calendar heading",
|
|
|
|
"%A, %B %d, %Y"));
|
|
|
|
let dayString = day.toLocaleFormat(dayFormat);
|
2013-06-08 12:31:30 -04:00
|
|
|
this._addPeriod(dayString, 0, dayBegin, dayEnd, false, true);
|
2011-01-28 16:35:46 -05:00
|
|
|
},
|
|
|
|
|
|
|
|
_showToday: function() {
|
2012-02-16 13:27:09 -05:00
|
|
|
this.actor.destroy_all_children();
|
2013-06-08 12:31:30 -04:00
|
|
|
let index = 0;
|
2011-01-28 16:35:46 -05:00
|
|
|
|
|
|
|
let now = new Date();
|
|
|
|
let dayBegin = _getBeginningOfDay(now);
|
|
|
|
let dayEnd = _getEndOfDay(now);
|
2013-06-08 12:31:30 -04:00
|
|
|
index = this._addPeriod(_("Today"), index, dayBegin, dayEnd, false, true);
|
2011-01-28 16:35:46 -05:00
|
|
|
|
|
|
|
let tomorrowBegin = new Date(dayBegin.getTime() + 86400 * 1000);
|
|
|
|
let tomorrowEnd = new Date(dayEnd.getTime() + 86400 * 1000);
|
2013-06-08 12:31:30 -04:00
|
|
|
index = this._addPeriod(_("Tomorrow"), index, tomorrowBegin, tomorrowEnd, false, true);
|
2011-01-28 16:35:46 -05:00
|
|
|
|
2012-08-19 11:26:09 -04:00
|
|
|
let dayInWeek = (dayEnd.getDay() - this._weekStart + 7) % 7;
|
|
|
|
|
|
|
|
if (dayInWeek < 5) {
|
2011-01-28 21:09:47 -05:00
|
|
|
/* If now is within the first 5 days we show "This week" and
|
|
|
|
* include events up until and including Saturday/Sunday
|
|
|
|
* (depending on whether a week starts on Sunday/Monday).
|
2011-01-28 16:35:46 -05:00
|
|
|
*/
|
|
|
|
let thisWeekBegin = new Date(dayBegin.getTime() + 2 * 86400 * 1000);
|
2012-08-19 11:26:09 -04:00
|
|
|
let thisWeekEnd = new Date(dayEnd.getTime() + (6 - dayInWeek) * 86400 * 1000);
|
2013-06-08 12:31:30 -04:00
|
|
|
index = this._addPeriod(_("This week"), index, thisWeekBegin, thisWeekEnd, true, false);
|
2011-01-28 16:35:46 -05:00
|
|
|
} else {
|
2011-01-28 21:09:47 -05:00
|
|
|
/* otherwise it's one of the two last days of the week ... show
|
|
|
|
* "Next week" and include events up until and including *next*
|
|
|
|
* Saturday/Sunday
|
2011-01-28 16:35:46 -05:00
|
|
|
*/
|
|
|
|
let nextWeekBegin = new Date(dayBegin.getTime() + 2 * 86400 * 1000);
|
2012-08-19 11:26:09 -04:00
|
|
|
let nextWeekEnd = new Date(dayEnd.getTime() + (13 - dayInWeek) * 86400 * 1000);
|
2013-06-08 12:31:30 -04:00
|
|
|
index = this._addPeriod(_("Next week"), index, nextWeekBegin, nextWeekEnd, true, false);
|
2011-01-28 16:35:46 -05:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
// Sets the event list to show events from a specific date
|
|
|
|
setDate: function(date) {
|
|
|
|
if (!_sameDay(date, this._date)) {
|
|
|
|
this._date = date;
|
|
|
|
this._update();
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
_update: function() {
|
2012-10-23 12:41:24 -04:00
|
|
|
if (this._eventSource.isLoading)
|
|
|
|
return;
|
|
|
|
|
2011-01-28 16:35:46 -05:00
|
|
|
let today = new Date();
|
|
|
|
if (_sameDay (this._date, today)) {
|
|
|
|
this._showToday();
|
|
|
|
} else {
|
|
|
|
this._showOtherDay(this._date);
|
|
|
|
}
|
2009-09-30 10:02:08 -04:00
|
|
|
}
|
2011-11-20 12:56:27 -05:00
|
|
|
});
|