2011-09-28 09:16:26 -04:00
|
|
|
// -*- mode: js; js-indent-level: 4; indent-tabs-mode: nil -*-
|
2019-05-29 01:52:17 -04:00
|
|
|
/* exported Calendar, CalendarMessageList, DBusEventSource */
|
2009-09-30 10:02:08 -04:00
|
|
|
|
2019-08-31 14:43:05 -04:00
|
|
|
const { Clutter, Gio, GLib, GObject, Shell, St } = imports.gi;
|
2009-09-30 10:02:08 -04:00
|
|
|
|
2014-12-05 10:24:35 -05:00
|
|
|
const Main = imports.ui.main;
|
2016-02-15 06:02:31 -05:00
|
|
|
const MessageList = imports.ui.messageList;
|
2015-02-11 14:41:56 -05:00
|
|
|
const MessageTray = imports.ui.messageTray;
|
2016-02-15 06:13:22 -05:00
|
|
|
const Mpris = imports.ui.mpris;
|
2018-05-04 11:55:29 -04:00
|
|
|
const PopupMenu = imports.ui.popupMenu;
|
2015-02-16 13:40:00 -05:00
|
|
|
const Util = imports.misc.util;
|
|
|
|
|
2019-02-12 13:40:13 -05:00
|
|
|
const { loadInterfaceXML } = imports.misc.fileUtils;
|
|
|
|
|
2017-07-18 13:47:27 -04:00
|
|
|
var MSECS_IN_DAY = 24 * 60 * 60 * 1000;
|
|
|
|
var SHOW_WEEKDATE_KEY = 'show-weekdate';
|
|
|
|
var ELLIPSIS_CHAR = '\u2026';
|
2009-09-30 10:02:08 -04:00
|
|
|
|
2017-09-29 08:56:19 -04:00
|
|
|
var MESSAGE_ICON_SIZE = -1; // pick up from CSS
|
2015-06-02 09:46:37 -04:00
|
|
|
|
2020-02-14 10:10:34 -05:00
|
|
|
var NC_ = (context, str) => '%s\u0004%s'.format(context, str);
|
2014-04-26 19:06:13 -04:00
|
|
|
|
2016-02-15 06:02:31 -05:00
|
|
|
function sameYear(dateA, dateB) {
|
2019-08-19 15:38:51 -04:00
|
|
|
return dateA.getYear() == dateB.getYear();
|
2011-01-28 16:35:46 -05:00
|
|
|
}
|
|
|
|
|
2016-02-15 06:02:31 -05:00
|
|
|
function sameMonth(dateA, dateB) {
|
|
|
|
return sameYear(dateA, dateB) && (dateA.getMonth() == dateB.getMonth());
|
2013-12-11 20:05:21 -05:00
|
|
|
}
|
|
|
|
|
2016-02-15 06:02:31 -05:00
|
|
|
function sameDay(dateA, dateB) {
|
|
|
|
return sameMonth(dateA, dateB) && (dateA.getDate() == dateB.getDate());
|
2013-12-11 20:05:21 -05:00
|
|
|
}
|
|
|
|
|
2016-02-15 06:02:31 -05:00
|
|
|
function isToday(date) {
|
|
|
|
return sameDay(new Date(), date);
|
2015-03-11 17:36:00 -04:00
|
|
|
}
|
|
|
|
|
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");
|
2018-07-14 16:56:22 -04:00
|
|
|
return !days.includes(date.getDay().toString());
|
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 */
|
2019-08-20 17:43:54 -04: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
|
|
|
}
|
|
|
|
|
|
|
|
// Abstraction for an appointment/event in a calendar
|
|
|
|
|
2017-10-30 21:19:44 -04:00
|
|
|
var CalendarEvent = class CalendarEvent {
|
|
|
|
constructor(id, date, end, summary, allDay) {
|
2015-03-06 17:58:33 -05:00
|
|
|
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;
|
|
|
|
}
|
2017-10-30 21:19:44 -04:00
|
|
|
};
|
2011-01-28 16:35:46 -05:00
|
|
|
|
|
|
|
// Interface for appointments/events - e.g. the contents of a calendar
|
|
|
|
//
|
|
|
|
|
2019-05-29 01:52:17 -04:00
|
|
|
var EventSourceBase = GObject.registerClass({
|
|
|
|
GTypeFlags: GObject.TypeFlags.ABSTRACT,
|
|
|
|
Properties: {
|
|
|
|
'has-calendars': GObject.ParamSpec.boolean(
|
|
|
|
'has-calendars', 'has-calendars', 'has-calendars',
|
|
|
|
GObject.ParamFlags.READABLE,
|
|
|
|
false),
|
|
|
|
'is-loading': GObject.ParamSpec.boolean(
|
|
|
|
'is-loading', 'is-loading', 'is-loading',
|
|
|
|
GObject.ParamFlags.READABLE,
|
|
|
|
false),
|
|
|
|
},
|
2019-08-20 17:43:54 -04:00
|
|
|
Signals: { 'changed': {} },
|
2019-05-29 01:52:17 -04:00
|
|
|
}, class EventSourceBase extends GObject.Object {
|
|
|
|
get isLoading() {
|
2020-02-14 10:10:34 -05:00
|
|
|
throw new GObject.NotImplementedError('isLoading in %s'.format(this.constructor.name));
|
2019-05-29 01:52:17 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
get hasCalendars() {
|
2020-02-14 10:10:34 -05:00
|
|
|
throw new GObject.NotImplementedError('hasCalendars in %s'.format(this.constructor.name));
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2013-03-04 11:04:28 -05:00
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
destroy() {
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2011-01-28 16:35:46 -05:00
|
|
|
|
2019-05-29 01:52:17 -04:00
|
|
|
requestRange(_begin, _end) {
|
2020-02-14 10:10:34 -05:00
|
|
|
throw new GObject.NotImplementedError('requestRange in %s'.format(this.constructor.name));
|
2019-05-29 01:52:17 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
getEvents(_begin, _end) {
|
2020-02-14 10:10:34 -05:00
|
|
|
throw new GObject.NotImplementedError('getEvents in %s'.format(this.constructor.name));
|
2019-05-29 01:52:17 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
hasEvents(_day) {
|
2020-02-14 10:10:34 -05:00
|
|
|
throw new GObject.NotImplementedError('hasEvents in %s'.format(this.constructor.name));
|
2019-05-29 01:52:17 -04:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
var EmptyEventSource = GObject.registerClass(
|
|
|
|
class EmptyEventSource extends EventSourceBase {
|
|
|
|
get isLoading() {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
get hasCalendars() {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2019-01-31 09:08:10 -05:00
|
|
|
requestRange(_begin, _end) {
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2011-01-28 16:35:46 -05:00
|
|
|
|
2019-01-31 09:08:10 -05:00
|
|
|
getEvents(_begin, _end) {
|
2011-01-28 16:35:46 -05:00
|
|
|
let result = [];
|
|
|
|
return result;
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2011-01-28 16:35:46 -05:00
|
|
|
|
2019-01-31 09:08:10 -05:00
|
|
|
hasEvents(_day) {
|
2011-01-28 16:35:46 -05:00
|
|
|
return false;
|
|
|
|
}
|
2019-05-29 01:52:17 -04:00
|
|
|
});
|
2011-01-28 16:35:46 -05:00
|
|
|
|
2019-02-12 13:40:13 -05:00
|
|
|
const CalendarServerIface = loadInterfaceXML('org.gnome.Shell.CalendarServer');
|
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
|
|
|
|
2019-01-29 16:02:57 -05:00
|
|
|
function _dateIntervalsOverlap(a0, a1, b0, b1) {
|
2011-02-25 17:42:25 -05:00
|
|
|
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
|
2019-05-29 01:52:17 -04:00
|
|
|
var DBusEventSource = GObject.registerClass(
|
|
|
|
class DBusEventSource extends EventSourceBase {
|
|
|
|
_init() {
|
|
|
|
super._init();
|
2011-02-25 17:42:25 -05:00
|
|
|
this._resetCache();
|
2019-05-29 01:52:17 -04:00
|
|
|
this._isLoading = 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();
|
2019-12-19 14:50:37 -05:00
|
|
|
this._initProxy();
|
|
|
|
}
|
2011-01-28 16:35:46 -05:00
|
|
|
|
2019-12-19 14:50:37 -05:00
|
|
|
async _initProxy() {
|
|
|
|
let loaded = false;
|
|
|
|
|
|
|
|
try {
|
|
|
|
await this._dbusProxy.init_async(GLib.PRIORITY_DEFAULT, null);
|
|
|
|
loaded = true;
|
|
|
|
} catch (e) {
|
|
|
|
// 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)
|
|
|
|
if (!e.matches(Gio.DBusError, Gio.DBusError.TIMED_OUT)) {
|
|
|
|
log('Error loading calendars: %s'.format(e.message));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2013-02-17 09:52:53 -05:00
|
|
|
|
2020-04-02 03:24:28 -04:00
|
|
|
this._dbusProxy.connectSignal('EventsAddedOrUpdated',
|
|
|
|
this._onEventsAddedOrUpdated.bind(this));
|
|
|
|
this._dbusProxy.connectSignal('EventsRemoved',
|
|
|
|
this._onEventsRemoved.bind(this));
|
|
|
|
this._dbusProxy.connectSignal('ClientDisappeared',
|
|
|
|
this._onClientDisappeared.bind(this));
|
2012-10-29 11:37:07 -04:00
|
|
|
|
2019-12-19 14:50:37 -05:00
|
|
|
this._dbusProxy.connect('notify::g-name-owner', () => {
|
|
|
|
if (this._dbusProxy.g_name_owner)
|
2014-12-10 19:41:48 -05:00
|
|
|
this._onNameAppeared();
|
2019-12-19 14:50:37 -05:00
|
|
|
else
|
|
|
|
this._onNameVanished();
|
|
|
|
});
|
|
|
|
|
|
|
|
this._dbusProxy.connect('g-properties-changed', () => {
|
|
|
|
this.notify('has-calendars');
|
2017-10-30 20:38:18 -04:00
|
|
|
});
|
2019-12-19 14:50:37 -05:00
|
|
|
|
|
|
|
this._initialized = loaded;
|
|
|
|
if (loaded) {
|
|
|
|
this.notify('has-calendars');
|
|
|
|
this._onNameAppeared();
|
|
|
|
}
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2011-01-28 16:35:46 -05:00
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
destroy() {
|
2013-03-04 11:04:28 -05:00
|
|
|
this._dbusProxy.run_dispose();
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2013-03-04 11:04:28 -05:00
|
|
|
|
2012-10-29 11:37:07 -04:00
|
|
|
get hasCalendars() {
|
|
|
|
if (this._initialized)
|
|
|
|
return this._dbusProxy.HasCalendars;
|
|
|
|
else
|
|
|
|
return false;
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2012-10-29 11:37:07 -04:00
|
|
|
|
2019-05-29 01:52:17 -04:00
|
|
|
get isLoading() {
|
|
|
|
return this._isLoading;
|
|
|
|
}
|
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
_resetCache() {
|
2020-04-02 03:24:28 -04:00
|
|
|
this._events = new Map();
|
2011-02-25 17:42:25 -05:00
|
|
|
this._lastRequestBegin = null;
|
|
|
|
this._lastRequestEnd = null;
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2011-01-28 16:35:46 -05:00
|
|
|
|
2019-02-04 06:30:53 -05:00
|
|
|
_onNameAppeared() {
|
2014-12-10 19:41:48 -05:00
|
|
|
this._initialized = true;
|
2011-02-25 17:42:25 -05:00
|
|
|
this._resetCache();
|
|
|
|
this._loadEvents(true);
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2011-01-28 16:35:46 -05:00
|
|
|
|
2019-02-04 06:30:53 -05:00
|
|
|
_onNameVanished() {
|
2011-02-25 17:42:25 -05:00
|
|
|
this._resetCache();
|
|
|
|
this.emit('changed');
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2011-01-28 16:35:46 -05:00
|
|
|
|
2020-04-02 03:24:28 -04:00
|
|
|
_onEventsAddedOrUpdated(dbusProxy, nameOwner, argArray) {
|
|
|
|
const [appointments = []] = argArray;
|
|
|
|
let changed = false;
|
2011-01-28 16:35:46 -05:00
|
|
|
|
2019-07-11 23:25:54 -04:00
|
|
|
for (let n = 0; n < appointments.length; n++) {
|
2020-04-02 03:24:28 -04:00
|
|
|
const [id, summary, allDay, startTime, endTime] = appointments[n];
|
|
|
|
const date = new Date(startTime * 1000);
|
|
|
|
const end = new Date(endTime * 1000);
|
2019-07-11 23:25:54 -04:00
|
|
|
let event = new CalendarEvent(id, date, end, summary, allDay);
|
2020-04-02 03:24:28 -04:00
|
|
|
this._events.set(event.id, event);
|
|
|
|
|
|
|
|
changed = true;
|
2011-01-28 16:35:46 -05:00
|
|
|
}
|
|
|
|
|
2020-04-02 03:24:28 -04:00
|
|
|
if (changed)
|
|
|
|
this.emit('changed');
|
|
|
|
}
|
|
|
|
|
|
|
|
_onEventsRemoved(dbusProxy, nameOwner, argArray) {
|
|
|
|
const [ids = []] = argArray;
|
|
|
|
|
|
|
|
let changed = false;
|
|
|
|
for (const id of ids)
|
|
|
|
changed |= this._events.delete(id);
|
|
|
|
|
|
|
|
if (changed)
|
|
|
|
this.emit('changed');
|
|
|
|
}
|
|
|
|
|
|
|
|
_onClientDisappeared(dbusProxy, nameOwner, argArray) {
|
|
|
|
let [sourceUid = ''] = argArray;
|
|
|
|
sourceUid += '\n';
|
|
|
|
|
|
|
|
let changed = false;
|
|
|
|
for (const id of this._events.keys()) {
|
|
|
|
if (id.startsWith(sourceUid))
|
|
|
|
changed |= this._events.delete(id);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (changed)
|
|
|
|
this.emit('changed');
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2011-01-28 16:35:46 -05:00
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
_loadEvents(forceReload) {
|
2013-02-17 09:52:53 -05:00
|
|
|
// Ignore while loading
|
|
|
|
if (!this._initialized)
|
|
|
|
return;
|
|
|
|
|
2019-01-28 20:27:05 -05:00
|
|
|
if (this._curRequestBegin && this._curRequestEnd) {
|
2020-04-02 03:24:28 -04:00
|
|
|
if (forceReload) {
|
|
|
|
this._events.clear();
|
|
|
|
this.emit('changed');
|
|
|
|
}
|
|
|
|
this._dbusProxy.SetTimeRangeRemote(
|
|
|
|
this._curRequestBegin.getTime() / 1000,
|
|
|
|
this._curRequestEnd.getTime() / 1000,
|
|
|
|
forceReload,
|
|
|
|
Gio.DBusCallFlags.NONE);
|
2011-02-25 17:42:25 -05:00
|
|
|
}
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2011-01-28 16:35:46 -05:00
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
requestRange(begin, end) {
|
2013-12-11 19:58:42 -05:00
|
|
|
if (!(_datesEqual(begin, this._lastRequestBegin) && _datesEqual(end, this._lastRequestEnd))) {
|
2011-02-25 17:42:25 -05:00
|
|
|
this._lastRequestBegin = begin;
|
|
|
|
this._lastRequestEnd = end;
|
|
|
|
this._curRequestBegin = begin;
|
|
|
|
this._curRequestEnd = end;
|
2020-04-02 03:24:28 -04:00
|
|
|
this._loadEvents(true);
|
2011-02-25 17:42:25 -05:00
|
|
|
}
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2011-01-28 16:35:46 -05:00
|
|
|
|
2020-04-02 17:46:48 -04:00
|
|
|
*_getFilteredEvents(begin, end) {
|
2020-04-02 03:24:28 -04:00
|
|
|
for (const event of this._events.values()) {
|
2019-08-19 20:51:42 -04:00
|
|
|
if (_dateIntervalsOverlap(event.date, event.end, begin, end))
|
2020-04-02 17:46:48 -04:00
|
|
|
yield event;
|
2011-01-28 16:35:46 -05:00
|
|
|
}
|
2020-04-02 17:46:48 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
getEvents(begin, end) {
|
|
|
|
let result = [...this._getFilteredEvents(begin, end)];
|
|
|
|
|
2017-10-30 20:38:18 -04:00
|
|
|
result.sort((event1, event2) => {
|
2014-09-17 21:34:40 -04:00
|
|
|
// 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;
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2011-01-28 16:35:46 -05:00
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
hasEvents(day) {
|
2011-01-28 16:35:46 -05:00
|
|
|
let dayBegin = _getBeginningOfDay(day);
|
|
|
|
let dayEnd = _getEndOfDay(day);
|
|
|
|
|
2020-04-02 17:46:48 -04:00
|
|
|
const { done } = this._getFilteredEvents(dayBegin, dayEnd).next();
|
|
|
|
return !done;
|
2011-01-28 16:35:46 -05:00
|
|
|
}
|
2019-05-29 01:52:17 -04:00
|
|
|
});
|
2011-01-28 16:35:46 -05:00
|
|
|
|
2019-07-16 05:24:13 -04:00
|
|
|
var Calendar = GObject.registerClass({
|
2019-08-20 17:43:54 -04:00
|
|
|
Signals: { 'selected-date-changed': { param_types: [GLib.DateTime.$gtype] } },
|
2019-07-16 05:24:13 -04:00
|
|
|
}, class Calendar extends St.Widget {
|
|
|
|
_init() {
|
2011-06-23 20:40:36 -04:00
|
|
|
this._weekStart = Shell.util_get_week_start();
|
2016-05-12 06:31:29 -04:00
|
|
|
this._settings = new Gio.Settings({ schema_id: 'org.gnome.desktop.calendar' });
|
2010-05-27 03:31:46 -04:00
|
|
|
|
2020-02-14 10:10:34 -05:00
|
|
|
this._settings.connect('changed::%s'.format(SHOW_WEEKDATE_KEY), this._onSettingsChange.bind(this));
|
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
|
|
|
|
2017-04-14 16:30:12 -04:00
|
|
|
/**
|
|
|
|
* Translators: The header displaying just the month name
|
|
|
|
* standalone, when this is a month of the current year.
|
2018-02-08 06:47:26 -05:00
|
|
|
* "%OB" is the new format specifier introduced in glibc 2.27,
|
|
|
|
* in most cases you should not change it.
|
2017-04-14 16:30:12 -04:00
|
|
|
*/
|
2018-02-08 06:47:26 -05:00
|
|
|
this._headerFormatWithoutYear = _('%OB');
|
2017-04-14 16:30:12 -04:00
|
|
|
/**
|
|
|
|
* Translators: The header displaying the month name and the year
|
|
|
|
* number, when this is a month of a different year. You can
|
|
|
|
* reorder the format specifiers or add other modifications
|
|
|
|
* according to the requirements of your language.
|
2018-02-08 06:47:26 -05:00
|
|
|
* "%OB" is the new format specifier introduced in glibc 2.27,
|
|
|
|
* in most cases you should not use the old "%B" here unless you
|
|
|
|
* absolutely know what you are doing.
|
2017-04-14 16:30:12 -04:00
|
|
|
*/
|
2018-02-08 06:47:26 -05:00
|
|
|
this._headerFormat = _('%OB %Y');
|
2009-09-30 10:02:08 -04:00
|
|
|
|
|
|
|
// 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;
|
|
|
|
|
2019-07-16 05:24:13 -04:00
|
|
|
super._init({
|
|
|
|
style_class: 'calendar',
|
2014-06-20 10:23:32 -04:00
|
|
|
layout_manager: new Clutter.GridLayout(),
|
2019-08-20 17:43:54 -04:00
|
|
|
reactive: true,
|
2019-07-16 05:24:13 -04:00
|
|
|
});
|
2009-10-01 15:18:20 -04:00
|
|
|
|
2019-08-19 13:55:49 -04:00
|
|
|
this._buildHeader();
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2010-05-27 03:31:46 -04:00
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
setEventSource(eventSource) {
|
2019-05-29 01:52:17 -04:00
|
|
|
if (!(eventSource instanceof EventSourceBase))
|
|
|
|
throw new Error('Event source is not valid type');
|
|
|
|
|
2012-09-01 08:42:53 -04:00
|
|
|
this._eventSource = eventSource;
|
2017-10-30 20:38:18 -04:00
|
|
|
this._eventSource.connect('changed', () => {
|
2014-03-12 13:50:37 -04:00
|
|
|
this._rebuildCalendar();
|
2013-12-11 19:58:42 -05:00
|
|
|
this._update();
|
2017-10-30 20:38:18 -04:00
|
|
|
});
|
2014-03-12 13:50:37 -04:00
|
|
|
this._rebuildCalendar();
|
2013-12-11 19:58:42 -05:00
|
|
|
this._update();
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2012-09-01 08:42:53 -04:00
|
|
|
|
2010-05-27 03:31:46 -04:00
|
|
|
// Sets the calendar to show a specific date
|
2017-10-30 20:03:21 -04:00
|
|
|
setDate(date) {
|
2016-02-15 06:02:31 -05:00
|
|
|
if (sameDay(date, this._selectedDate))
|
2013-12-11 19:58:42 -05:00
|
|
|
return;
|
|
|
|
|
|
|
|
this._selectedDate = date;
|
|
|
|
this._update();
|
2019-09-02 15:18:54 -04:00
|
|
|
|
|
|
|
let datetime = GLib.DateTime.new_from_unix_local(
|
|
|
|
this._selectedDate.getTime() / 1000);
|
|
|
|
this.emit('selected-date-changed', datetime);
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2010-05-27 03:31:46 -04:00
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
updateTimeZone() {
|
2015-08-13 18:57:49 -04:00
|
|
|
// The calendar need to be rebuilt after a time zone update because
|
|
|
|
// the date might have changed.
|
|
|
|
this._rebuildCalendar();
|
|
|
|
this._update();
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2015-08-13 18:57:49 -04:00
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
_buildHeader() {
|
2019-07-16 05:24:13 -04:00
|
|
|
let layout = this.layout_manager;
|
2010-05-27 03:31:46 -04:00
|
|
|
let offsetCols = this._useWeekdate ? 1 : 0;
|
2019-07-16 05:24:13 -04:00
|
|
|
this.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
|
|
|
|
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 });
|
2018-11-20 11:55:31 -05:00
|
|
|
this._backButton.add_actor(new St.Icon({ icon_name: 'pan-start-symbolic' }));
|
2013-04-30 18:32:43 -04:00
|
|
|
this._topBox.add(this._backButton);
|
2017-12-01 19:27:35 -05:00
|
|
|
this._backButton.connect('clicked', this._onPrevMonthButtonClicked.bind(this));
|
2009-09-30 10:02:08 -04:00
|
|
|
|
2019-10-21 14:44:00 -04:00
|
|
|
this._monthLabel = new St.Label({
|
|
|
|
style_class: 'calendar-month-label',
|
|
|
|
can_focus: true,
|
|
|
|
x_align: Clutter.ActorAlign.CENTER,
|
|
|
|
x_expand: true,
|
|
|
|
});
|
|
|
|
this._topBox.add_child(this._monthLabel);
|
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 });
|
2018-11-20 11:55:31 -05:00
|
|
|
this._forwardButton.add_actor(new St.Icon({ icon_name: 'pan-end-symbolic' }));
|
2013-04-30 18:32:43 -04:00
|
|
|
this._topBox.add(this._forwardButton);
|
2017-12-01 19:27:35 -05:00
|
|
|
this._forwardButton.connect('clicked', this._onNextMonthButtonClicked.bind(this));
|
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;
|
2019-07-16 05:24:13 -04:00
|
|
|
if (this.get_text_direction() == Clutter.TextDirection.RTL)
|
2014-06-20 10:10:08 -04:00
|
|
|
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
|
2019-07-16 05:24:13 -04:00
|
|
|
this._firstDayIndex = this.get_n_children();
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2009-10-01 16:14:50 -04:00
|
|
|
|
2019-09-10 01:42:48 -04:00
|
|
|
vfunc_scroll_event(scrollEvent) {
|
|
|
|
switch (scrollEvent.direction) {
|
2009-10-01 15:18:20 -04:00
|
|
|
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;
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2009-10-01 15:18:20 -04:00
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
_onPrevMonthButtonClicked() {
|
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 == 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);
|
|
|
|
}
|
2019-01-29 16:02:57 -05:00
|
|
|
} else {
|
2011-01-31 15:00:16 -05:00
|
|
|
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);
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2009-09-30 10:02:08 -04:00
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
_onNextMonthButtonClicked() {
|
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);
|
|
|
|
}
|
2019-01-29 16:02:57 -05:00
|
|
|
} else {
|
2011-01-31 15:00:16 -05:00
|
|
|
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);
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2009-09-30 10:02:08 -04:00
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
_onSettingsChange() {
|
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();
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2010-05-27 03:31:46 -04:00
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
_rebuildCalendar() {
|
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
|
2019-07-16 05:24:13 -04:00
|
|
|
let children = this.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
|
|
|
|
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
|
|
|
|
2019-07-16 05:24:13 -04:00
|
|
|
let layout = this.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;
|
2019-01-31 09:04:56 -05:00
|
|
|
while (row < nRows) {
|
2015-12-25 05:36:26 -05:00
|
|
|
// xgettext:no-javascript-format
|
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
|
|
|
|
2019-05-29 01:52:17 -04:00
|
|
|
if (this._eventSource instanceof EmptyEventSource)
|
2011-08-22 14:21:51 -04:00
|
|
|
button.reactive = false;
|
|
|
|
|
2013-12-11 20:05:21 -05:00
|
|
|
button._date = new Date(iter);
|
2017-10-30 20:38:18 -04:00
|
|
|
button.connect('clicked', () => {
|
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;
|
2017-10-30 20:38:18 -04:00
|
|
|
});
|
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)
|
2020-02-14 10:10:34 -05:00
|
|
|
styleClass = 'calendar-day-top %s'.format(styleClass);
|
2012-07-13 13:00:56 -04:00
|
|
|
|
2019-08-19 15:33:15 -04:00
|
|
|
let leftMost = rtl
|
|
|
|
? iter.getDay() == (this._weekStart + 6) % 7
|
|
|
|
: iter.getDay() == this._weekStart;
|
2012-07-13 13:00:56 -04:00
|
|
|
if (leftMost)
|
2020-02-14 10:10:34 -05:00
|
|
|
styleClass = 'calendar-day-left %s'.format(styleClass);
|
2011-01-28 16:35:46 -05:00
|
|
|
|
2016-02-15 06:02:31 -05:00
|
|
|
if (sameDay(now, iter))
|
2011-01-28 16:35:46 -05:00
|
|
|
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) {
|
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);
|
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);
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2013-12-11 20:05:21 -05:00
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
_update() {
|
2013-12-11 20:05:21 -05:00
|
|
|
let now = new Date();
|
|
|
|
|
2016-02-15 06:02:31 -05:00
|
|
|
if (sameYear(this._selectedDate, now))
|
2013-12-11 20:05:21 -05:00
|
|
|
this._monthLabel.text = this._selectedDate.toLocaleFormat(this._headerFormatWithoutYear);
|
|
|
|
else
|
|
|
|
this._monthLabel.text = this._selectedDate.toLocaleFormat(this._headerFormat);
|
|
|
|
|
2016-02-15 06:02:31 -05:00
|
|
|
if (!this._calendarBegin || !sameMonth(this._selectedDate, this._calendarBegin) || !sameDay(now, this._markedAsToday))
|
2013-12-11 20:05:21 -05:00
|
|
|
this._rebuildCalendar();
|
|
|
|
|
2017-10-30 20:38:18 -04:00
|
|
|
this._buttons.forEach(button => {
|
2016-02-15 06:02:31 -05:00
|
|
|
if (sameDay(button._date, this._selectedDate)) {
|
2016-07-07 20:06:31 -04:00
|
|
|
button.add_style_pseudo_class('selected');
|
2014-03-03 12:14:51 -05:00
|
|
|
if (this._shouldDateGrabFocus)
|
|
|
|
button.grab_key_focus();
|
2019-01-29 16:02:57 -05:00
|
|
|
} else {
|
2016-07-07 20:06:31 -04:00
|
|
|
button.remove_style_pseudo_class('selected');
|
2019-01-29 16:02:57 -05:00
|
|
|
}
|
2017-10-30 20:38:18 -04:00
|
|
|
});
|
2011-01-28 16:35:46 -05:00
|
|
|
}
|
2019-07-16 05:24:13 -04:00
|
|
|
});
|
2011-01-28 16:35:46 -05:00
|
|
|
|
2019-07-16 05:24:13 -04:00
|
|
|
var EventMessage = GObject.registerClass(
|
|
|
|
class EventMessage extends MessageList.Message {
|
|
|
|
_init(event, date) {
|
2020-04-09 06:50:39 -04:00
|
|
|
super._init('', '');
|
2015-03-11 18:04:55 -04:00
|
|
|
|
|
|
|
this._date = date;
|
|
|
|
|
2020-04-09 06:50:39 -04:00
|
|
|
this.update(event);
|
2017-02-25 21:33:26 -05:00
|
|
|
|
|
|
|
this._icon = new St.Icon({ icon_name: 'x-office-calendar-symbolic' });
|
|
|
|
this.setIcon(this._icon);
|
2019-09-10 01:42:48 -04:00
|
|
|
}
|
2017-02-25 21:33:26 -05:00
|
|
|
|
2019-09-10 01:42:48 -04:00
|
|
|
vfunc_style_changed() {
|
|
|
|
let iconVisible = this.get_parent().has_style_pseudo_class('first-child');
|
2019-08-19 15:38:51 -04:00
|
|
|
this._icon.opacity = iconVisible ? 255 : 0;
|
2019-09-10 01:42:48 -04:00
|
|
|
super.vfunc_style_changed();
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2015-03-11 18:04:55 -04:00
|
|
|
|
2020-04-09 06:50:39 -04:00
|
|
|
update(event) {
|
|
|
|
this._event = event;
|
|
|
|
|
|
|
|
this.setTitle(this._formatEventTime());
|
|
|
|
this.setBody(event.summary);
|
|
|
|
}
|
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
_formatEventTime() {
|
2015-03-11 18:04:55 -04:00
|
|
|
let periodBegin = _getBeginningOfDay(this._date);
|
|
|
|
let periodEnd = _getEndOfDay(this._date);
|
2019-08-19 15:38:51 -04:00
|
|
|
let allDay = this._event.allDay || (this._event.date <= periodBegin &&
|
|
|
|
this._event.end >= periodEnd);
|
2015-03-11 18:04:55 -04:00
|
|
|
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 {
|
2019-08-19 15:33:15 -04:00
|
|
|
let date = this._event.date >= periodBegin
|
|
|
|
? this._event.date
|
|
|
|
: this._event.end;
|
2015-03-11 18:04:55 -04:00
|
|
|
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)
|
2020-02-14 10:10:34 -05:00
|
|
|
title = '%s%s'.format(title, ELLIPSIS_CHAR);
|
2015-03-11 18:04:55 -04:00
|
|
|
else
|
2020-02-14 10:10:34 -05:00
|
|
|
title = '%s%s'.format(ELLIPSIS_CHAR, title);
|
2015-03-11 18:04:55 -04:00
|
|
|
}
|
|
|
|
if (this._event.end > periodEnd && !this._event.allDay) {
|
|
|
|
if (rtl)
|
2020-02-14 10:10:34 -05:00
|
|
|
title = '%s%s'.format(ELLIPSIS_CHAR, title);
|
2015-03-11 18:04:55 -04:00
|
|
|
else
|
2020-02-14 10:10:34 -05:00
|
|
|
title = '%s%s'.format(title, ELLIPSIS_CHAR);
|
2015-03-11 18:04:55 -04:00
|
|
|
}
|
|
|
|
return title;
|
|
|
|
}
|
2019-07-16 05:24:13 -04:00
|
|
|
});
|
2015-03-11 18:04:55 -04:00
|
|
|
|
2019-07-16 05:24:13 -04:00
|
|
|
var NotificationMessage = GObject.registerClass(
|
2017-10-30 21:19:44 -04:00
|
|
|
class NotificationMessage extends MessageList.Message {
|
2019-07-16 05:24:13 -04:00
|
|
|
_init(notification) {
|
|
|
|
super._init(notification.title, notification.bannerBodyText);
|
2017-10-30 21:19:44 -04:00
|
|
|
this.setUseBodyMarkup(notification.bannerBodyMarkup);
|
2015-02-11 14:41:56 -05:00
|
|
|
|
|
|
|
this.notification = notification;
|
|
|
|
|
|
|
|
this.setIcon(this._getIcon());
|
|
|
|
|
2017-10-30 20:38:18 -04:00
|
|
|
this.connect('close', () => {
|
|
|
|
this._closed = true;
|
2018-10-10 22:08:38 -04:00
|
|
|
if (this.notification)
|
|
|
|
this.notification.destroy(MessageTray.NotificationDestroyedReason.DISMISSED);
|
2017-10-30 20:38:18 -04:00
|
|
|
});
|
|
|
|
this._destroyId = notification.connect('destroy', () => {
|
2018-11-23 10:22:45 -05:00
|
|
|
this._disconnectNotificationSignals();
|
2018-10-10 22:08:38 -04:00
|
|
|
this.notification = null;
|
2017-10-30 20:38:18 -04:00
|
|
|
if (!this._closed)
|
|
|
|
this.close();
|
|
|
|
});
|
2015-02-11 14:41:56 -05:00
|
|
|
this._updatedId = notification.connect('updated',
|
2017-12-01 19:27:35 -05:00
|
|
|
this._onUpdated.bind(this));
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2015-02-11 14:41:56 -05:00
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
_getIcon() {
|
2019-08-19 20:51:42 -04:00
|
|
|
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 });
|
2019-08-19 20:51:42 -04:00
|
|
|
} else {
|
2015-06-02 09:46:37 -04:00
|
|
|
return this.notification.source.createIcon(MESSAGE_ICON_SIZE);
|
2019-08-19 20:51:42 -04:00
|
|
|
}
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2015-02-11 14:41:56 -05:00
|
|
|
|
2019-01-31 09:08:10 -05:00
|
|
|
_onUpdated(n, _clear) {
|
2015-02-11 14:41:56 -05:00
|
|
|
this.setIcon(this._getIcon());
|
|
|
|
this.setTitle(n.title);
|
|
|
|
this.setBody(n.bannerBodyText);
|
|
|
|
this.setUseBodyMarkup(n.bannerBodyMarkup);
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2015-02-11 14:41:56 -05:00
|
|
|
|
2019-09-10 01:42:48 -04:00
|
|
|
vfunc_clicked() {
|
2015-02-11 14:41:56 -05:00
|
|
|
this.notification.activate();
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2015-02-11 14:41:56 -05:00
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
_onDestroy() {
|
2017-10-30 21:19:44 -04:00
|
|
|
super._onDestroy();
|
2018-11-23 10:22:45 -05:00
|
|
|
this._disconnectNotificationSignals();
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2018-07-09 07:31:26 -04:00
|
|
|
|
2018-11-23 10:22:45 -05:00
|
|
|
_disconnectNotificationSignals() {
|
2015-02-11 14:41:56 -05:00
|
|
|
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;
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2018-12-17 12:36:03 -05:00
|
|
|
|
|
|
|
canClose() {
|
|
|
|
return true;
|
2015-02-11 14:41:56 -05:00
|
|
|
}
|
2019-07-16 05:24:13 -04:00
|
|
|
});
|
2015-02-11 14:41:56 -05:00
|
|
|
|
2019-07-16 05:24:13 -04:00
|
|
|
var EventsSection = GObject.registerClass(
|
|
|
|
class EventsSection extends MessageList.MessageListSection {
|
|
|
|
_init() {
|
|
|
|
super._init();
|
2011-01-28 16:35:46 -05:00
|
|
|
|
2014-06-24 15:17:09 -04:00
|
|
|
this._desktopSettings = new Gio.Settings({ schema_id: 'org.gnome.desktop.interface' });
|
2017-12-01 19:27:35 -05:00
|
|
|
this._desktopSettings.connect('changed', this._reloadEvents.bind(this));
|
2014-12-11 12:29:17 -05:00
|
|
|
this._eventSource = new EmptyEventSource();
|
|
|
|
|
2018-06-09 07:23:35 -04:00
|
|
|
this._messageById = new Map();
|
|
|
|
|
2017-02-25 22:35:43 -05:00
|
|
|
this._title = new St.Button({ style_class: 'events-section-title',
|
|
|
|
label: '',
|
|
|
|
can_focus: true });
|
2019-10-17 17:40:24 -04:00
|
|
|
this._title.child.x_align = Clutter.ActorAlign.START;
|
2019-07-16 05:24:13 -04:00
|
|
|
this.insert_child_below(this._title, null);
|
2017-02-25 22:35:43 -05:00
|
|
|
|
2017-12-01 19:27:35 -05:00
|
|
|
this._title.connect('clicked', this._onTitleClicked.bind(this));
|
|
|
|
this._title.connect('key-focus-in', this._onKeyFocusIn.bind(this));
|
2014-12-11 12:29:17 -05:00
|
|
|
|
2020-03-14 09:45:42 -04:00
|
|
|
this._appSys = Shell.AppSystem.get_default();
|
|
|
|
this._appSys.connect('installed-changed',
|
|
|
|
this._appInstalledChanged.bind(this));
|
2014-12-11 12:29:17 -05:00
|
|
|
this._appInstalledChanged();
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2011-01-28 21:09:47 -05:00
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
setEventSource(eventSource) {
|
2019-05-29 01:52:17 -04:00
|
|
|
if (!(eventSource instanceof EventSourceBase))
|
|
|
|
throw new Error('Event source is not valid type');
|
|
|
|
|
2012-09-01 08:42:53 -04:00
|
|
|
this._eventSource = eventSource;
|
2017-12-01 19:27:35 -05:00
|
|
|
this._eventSource.connect('changed', this._reloadEvents.bind(this));
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2011-01-28 16:35:46 -05:00
|
|
|
|
2015-03-02 20:04:37 -05:00
|
|
|
get allowed() {
|
|
|
|
return Main.sessionMode.showCalendarEvents;
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2015-03-02 20:04:37 -05:00
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
_updateTitle() {
|
2017-02-25 22:35:43 -05:00
|
|
|
this._title.visible = !isToday(this._date);
|
|
|
|
|
|
|
|
if (!this._title.visible)
|
2014-12-11 12:29:17 -05:00
|
|
|
return;
|
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();
|
2019-08-19 20:51:42 -04:00
|
|
|
if (sameYear(this._date, now)) {
|
2014-12-11 12:29:17 -05:00
|
|
|
/* Translators: Shown on calendar heading when selected day occurs on current year */
|
2020-01-18 08:04:16 -05:00
|
|
|
dayFormat = Shell.util_translate_time_string(NC_("calendar heading", "%A, %B %-d"));
|
2019-08-19 20:51:42 -04:00
|
|
|
} else {
|
2014-12-11 12:29:17 -05:00
|
|
|
/* Translators: Shown on calendar heading when selected day occurs on different year */
|
2020-01-18 08:04:16 -05:00
|
|
|
dayFormat = Shell.util_translate_time_string(NC_("calendar heading", "%A, %B %-d, %Y"));
|
2019-08-19 20:51:42 -04:00
|
|
|
}
|
2014-12-11 12:29:17 -05:00
|
|
|
this._title.label = this._date.toLocaleFormat(dayFormat);
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2011-01-28 16:35:46 -05:00
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
_reloadEvents() {
|
2020-04-02 03:24:28 -04:00
|
|
|
if (this._eventSource.isLoading || this._reloading)
|
2014-12-11 12:29:17 -05:00
|
|
|
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
|
|
|
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
|
|
|
|
2018-06-09 07:23:35 -04:00
|
|
|
let ids = events.map(e => e.id);
|
|
|
|
this._messageById.forEach((message, id) => {
|
|
|
|
if (ids.includes(id))
|
|
|
|
return;
|
|
|
|
this._messageById.delete(id);
|
|
|
|
this.removeMessage(message);
|
|
|
|
});
|
|
|
|
|
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
|
|
|
|
2018-06-09 07:23:35 -04:00
|
|
|
let message = this._messageById.get(event.id);
|
|
|
|
if (!message) {
|
|
|
|
message = new EventMessage(event, this._date);
|
|
|
|
this._messageById.set(event.id, message);
|
|
|
|
this.addMessage(message, false);
|
|
|
|
} else {
|
2020-04-09 06:50:39 -04:00
|
|
|
message.update(event);
|
2018-06-09 07:23:35 -04:00
|
|
|
this.moveMessage(message, i, 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();
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2011-01-28 16:35:46 -05:00
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
_appInstalledChanged() {
|
2014-12-11 12:29:17 -05:00
|
|
|
this._calendarApp = undefined;
|
2019-08-19 15:38:51 -04:00
|
|
|
this._title.reactive = this._getCalendarApp() != null;
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2011-01-28 16:35:46 -05:00
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
_getCalendarApp() {
|
2014-12-11 12:29:17 -05:00
|
|
|
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);
|
2017-10-30 20:38:18 -04:00
|
|
|
let defaultInRecommended = apps.some(a => a.equal(app));
|
2014-12-11 12:29:17 -05:00
|
|
|
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;
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2014-12-11 12:29:17 -05:00
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
_onTitleClicked() {
|
2017-02-25 22:35:43 -05:00
|
|
|
Main.overview.hide();
|
|
|
|
Main.panel.closeCalendar();
|
2014-12-11 12:29:17 -05:00
|
|
|
|
2020-03-14 09:45:42 -04:00
|
|
|
let appInfo = this._getCalendarApp();
|
|
|
|
if (appInfo.get_id() === 'org.gnome.Evolution.desktop') {
|
2020-03-14 09:45:42 -04:00
|
|
|
let app = this._appSys.lookup_app('evolution-calendar.desktop');
|
2020-03-14 09:45:42 -04:00
|
|
|
if (app)
|
2020-03-14 09:45:42 -04:00
|
|
|
appInfo = app.app_info;
|
2020-03-14 09:45:42 -04:00
|
|
|
}
|
|
|
|
appInfo.launch([], global.create_app_launch_context(0, -1));
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2011-01-28 16:35:46 -05:00
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
setDate(date) {
|
2017-10-30 21:19:44 -04:00
|
|
|
super.setDate(date);
|
2014-12-11 12:29:17 -05:00
|
|
|
this._updateTitle();
|
|
|
|
this._reloadEvents();
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2011-01-28 16:35:46 -05:00
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
_shouldShow() {
|
2016-02-15 06:02:31 -05:00
|
|
|
return !this.empty || !isToday(this._date);
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2014-12-11 12:29:17 -05:00
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
_sync() {
|
2014-12-11 12:29:17 -05:00
|
|
|
if (this._reloading)
|
2012-10-23 12:41:24 -04:00
|
|
|
return;
|
|
|
|
|
2017-10-30 21:19:44 -04:00
|
|
|
super._sync();
|
2009-09-30 10:02:08 -04:00
|
|
|
}
|
2019-07-16 05:24:13 -04:00
|
|
|
});
|
2015-02-11 14:41:56 -05:00
|
|
|
|
2019-09-10 01:42:48 -04:00
|
|
|
var TimeLabel = GObject.registerClass(
|
|
|
|
class NotificationTimeLabel extends St.Label {
|
|
|
|
_init(datetime) {
|
|
|
|
super._init({
|
|
|
|
style_class: 'event-time',
|
|
|
|
x_align: Clutter.ActorAlign.START,
|
2019-08-20 17:43:54 -04:00
|
|
|
y_align: Clutter.ActorAlign.END,
|
2019-09-10 01:42:48 -04:00
|
|
|
});
|
|
|
|
this._datetime = datetime;
|
|
|
|
}
|
|
|
|
|
|
|
|
vfunc_map() {
|
|
|
|
this.text = Util.formatTimeSpan(this._datetime);
|
|
|
|
super.vfunc_map();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2019-07-16 05:24:13 -04:00
|
|
|
var NotificationSection = GObject.registerClass(
|
2017-10-30 21:19:44 -04:00
|
|
|
class NotificationSection extends MessageList.MessageListSection {
|
2019-07-16 05:24:13 -04:00
|
|
|
_init() {
|
|
|
|
super._init();
|
2015-02-11 14:41:56 -05:00
|
|
|
|
|
|
|
this._sources = new Map();
|
|
|
|
this._nUrgent = 0;
|
|
|
|
|
2017-12-01 19:27:35 -05:00
|
|
|
Main.messageTray.connect('source-added', this._sourceAdded.bind(this));
|
2017-10-30 20:38:18 -04:00
|
|
|
Main.messageTray.getSources().forEach(source => {
|
2015-02-11 14:41:56 -05:00
|
|
|
this._sourceAdded(Main.messageTray, source);
|
2017-10-30 20:38:18 -04:00
|
|
|
});
|
2017-10-30 21:19:44 -04: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;
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2015-02-11 14:41:56 -05:00
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
_sourceAdded(tray, source) {
|
2015-02-11 14:41:56 -05:00
|
|
|
let obj = {
|
|
|
|
destroyId: 0,
|
|
|
|
notificationAddedId: 0,
|
|
|
|
};
|
|
|
|
|
2019-08-19 20:20:08 -04:00
|
|
|
obj.destroyId = source.connect('destroy', () => {
|
2015-02-11 14:41:56 -05:00
|
|
|
this._onSourceDestroy(source, obj);
|
2017-10-30 20:38:18 -04:00
|
|
|
});
|
2015-02-11 14:41:56 -05:00
|
|
|
obj.notificationAddedId = source.connect('notification-added',
|
2017-12-01 19:27:35 -05:00
|
|
|
this._onNotificationAdded.bind(this));
|
2015-02-11 14:41:56 -05:00
|
|
|
|
|
|
|
this._sources.set(source, obj);
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2015-02-11 14:41:56 -05:00
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
_onNotificationAdded(source, notification) {
|
2015-02-11 14:41:56 -05:00
|
|
|
let message = new NotificationMessage(notification);
|
2019-09-10 01:42:48 -04:00
|
|
|
message.setSecondaryActor(new TimeLabel(notification.datetime));
|
2015-02-11 14:41:56 -05:00
|
|
|
|
|
|
|
let isUrgent = notification.urgency == MessageTray.Urgency.CRITICAL;
|
2015-02-25 18:26:13 -05:00
|
|
|
|
2017-10-30 20:38:18 -04:00
|
|
|
let updatedId = notification.connect('updated', () => {
|
2019-09-10 01:42:48 -04:00
|
|
|
message.setSecondaryActor(new TimeLabel(notification.datetime));
|
2019-07-16 05:24:13 -04:00
|
|
|
this.moveMessage(message, isUrgent ? 0 : this._nUrgent, this.mapped);
|
2017-10-30 20:38:18 -04:00
|
|
|
});
|
|
|
|
let destroyId = notification.connect('destroy', () => {
|
|
|
|
notification.disconnect(destroyId);
|
|
|
|
notification.disconnect(updatedId);
|
|
|
|
if (isUrgent)
|
|
|
|
this._nUrgent--;
|
|
|
|
});
|
2015-02-25 18:26:13 -05:00
|
|
|
|
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;
|
2019-07-16 05:24:13 -04:00
|
|
|
this.addMessageAtIndex(message, index, this.mapped);
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2015-02-11 14:41:56 -05:00
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
_onSourceDestroy(source, obj) {
|
2015-02-11 14:41:56 -05:00
|
|
|
source.disconnect(obj.destroyId);
|
|
|
|
source.disconnect(obj.notificationAddedId);
|
|
|
|
|
|
|
|
this._sources.delete(source);
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2015-02-11 14:41:56 -05:00
|
|
|
|
2019-09-10 01:42:48 -04:00
|
|
|
vfunc_map() {
|
2019-05-13 14:02:26 -04:00
|
|
|
this._messages.forEach(message => {
|
2015-02-11 14:41:56 -05:00
|
|
|
if (message.notification.urgency != MessageTray.Urgency.CRITICAL)
|
|
|
|
message.notification.acknowledged = true;
|
2019-05-13 14:02:26 -04:00
|
|
|
});
|
2019-09-10 01:42:48 -04:00
|
|
|
super.vfunc_map();
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2015-02-11 14:41:56 -05:00
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
_shouldShow() {
|
2016-02-15 06:02:31 -05:00
|
|
|
return !this.empty && isToday(this._date);
|
2015-02-11 14:41:56 -05:00
|
|
|
}
|
2019-07-16 05:24:13 -04:00
|
|
|
});
|
2014-12-05 10:24:35 -05:00
|
|
|
|
2019-07-16 05:24:13 -04:00
|
|
|
var Placeholder = GObject.registerClass(
|
|
|
|
class Placeholder extends St.BoxLayout {
|
|
|
|
_init() {
|
|
|
|
super._init({ style_class: 'message-list-placeholder', vertical: true });
|
2014-12-05 10:24:35 -05:00
|
|
|
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();
|
2019-07-16 05:24:13 -04:00
|
|
|
this.add_actor(this._icon);
|
2014-12-05 10:24:35 -05:00
|
|
|
|
2015-02-11 14:41:56 -05:00
|
|
|
this._label = new St.Label();
|
2019-07-16 05:24:13 -04:00
|
|
|
this.add_actor(this._label);
|
2015-02-11 14:41:56 -05:00
|
|
|
|
|
|
|
this._sync();
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2015-02-11 14:41:56 -05:00
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
setDate(date) {
|
2016-02-15 06:02:31 -05:00
|
|
|
if (sameDay(this._date, date))
|
2015-02-11 14:41:56 -05:00
|
|
|
return;
|
|
|
|
this._date = date;
|
|
|
|
this._sync();
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2015-02-11 14:41:56 -05:00
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
_sync() {
|
2016-02-15 06:02:31 -05:00
|
|
|
let today = isToday(this._date);
|
|
|
|
if (today && this._icon.gicon == this._todayIcon)
|
2015-02-11 14:41:56 -05:00
|
|
|
return;
|
2016-02-15 06:02:31 -05:00
|
|
|
if (!today && this._icon.gicon == this._otherIcon)
|
2015-02-11 14:41:56 -05:00
|
|
|
return;
|
|
|
|
|
2016-02-15 06:02:31 -05:00
|
|
|
if (today) {
|
2015-02-11 14:41:56 -05:00
|
|
|
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
|
|
|
}
|
2019-07-16 05:24:13 -04:00
|
|
|
});
|
2014-12-05 10:24:35 -05:00
|
|
|
|
2018-05-04 11:55:29 -04:00
|
|
|
const DoNotDisturbSwitch = GObject.registerClass(
|
|
|
|
class DoNotDisturbSwitch extends PopupMenu.Switch {
|
|
|
|
_init() {
|
|
|
|
this._settings = new Gio.Settings({
|
|
|
|
schema_id: 'org.gnome.desktop.notifications',
|
|
|
|
});
|
|
|
|
|
|
|
|
super._init(this._settings.get_boolean('show-banners'));
|
|
|
|
|
|
|
|
this._settings.bind('show-banners',
|
|
|
|
this, 'state',
|
|
|
|
Gio.SettingsBindFlags.INVERT_BOOLEAN);
|
|
|
|
|
|
|
|
this.connect('destroy', () => {
|
|
|
|
this._settings.run_dispose();
|
|
|
|
this._settings = null;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2019-07-16 05:24:13 -04:00
|
|
|
var CalendarMessageList = GObject.registerClass(
|
|
|
|
class CalendarMessageList extends St.Widget {
|
|
|
|
_init() {
|
|
|
|
super._init({
|
|
|
|
style_class: 'message-list',
|
|
|
|
layout_manager: new Clutter.BinLayout(),
|
|
|
|
x_expand: true,
|
2019-08-20 17:43:54 -04:00
|
|
|
y_expand: true,
|
2019-07-16 05:24:13 -04:00
|
|
|
});
|
2014-12-05 10:24:35 -05:00
|
|
|
|
|
|
|
this._placeholder = new Placeholder();
|
2019-07-16 05:24:13 -04:00
|
|
|
this.add_actor(this._placeholder);
|
2014-12-05 10:24:35 -05:00
|
|
|
|
2017-02-25 21:33:26 -05:00
|
|
|
let box = new St.BoxLayout({ vertical: true,
|
|
|
|
x_expand: true, y_expand: true });
|
2019-07-16 05:24:13 -04:00
|
|
|
this.add_actor(box);
|
2017-02-25 21:33:26 -05:00
|
|
|
|
2019-08-20 17:43:54 -04:00
|
|
|
this._scrollView = new St.ScrollView({
|
|
|
|
style_class: 'vfade',
|
|
|
|
overlay_scrollbars: true,
|
|
|
|
x_expand: true, y_expand: true,
|
|
|
|
});
|
2018-11-27 07:45:36 -05:00
|
|
|
this._scrollView.set_policy(St.PolicyType.NEVER, St.PolicyType.AUTOMATIC);
|
2017-02-25 21:33:26 -05:00
|
|
|
box.add_actor(this._scrollView);
|
|
|
|
|
2018-05-04 11:55:29 -04:00
|
|
|
let hbox = new St.BoxLayout({ style_class: 'message-list-controls' });
|
|
|
|
box.add_child(hbox);
|
|
|
|
|
2020-03-27 23:56:23 -04:00
|
|
|
const dndLabel = new St.Label({
|
2018-05-04 11:55:29 -04:00
|
|
|
text: _('Do Not Disturb'),
|
|
|
|
y_align: Clutter.ActorAlign.CENTER,
|
2020-03-27 23:56:23 -04:00
|
|
|
});
|
|
|
|
hbox.add_child(dndLabel);
|
2018-05-04 11:55:29 -04:00
|
|
|
|
|
|
|
this._dndSwitch = new DoNotDisturbSwitch();
|
|
|
|
this._dndButton = new St.Button({
|
|
|
|
can_focus: true,
|
2020-03-27 23:56:23 -04:00
|
|
|
toggle_mode: true,
|
2018-05-04 11:55:29 -04:00
|
|
|
child: this._dndSwitch,
|
2020-03-27 23:56:23 -04:00
|
|
|
label_actor: dndLabel,
|
2018-05-04 11:55:29 -04:00
|
|
|
});
|
2020-05-18 12:44:57 -04:00
|
|
|
this._dndSwitch.bind_property('state',
|
|
|
|
this._dndButton, 'checked',
|
2020-03-27 23:56:23 -04:00
|
|
|
GObject.BindingFlags.BIDIRECTIONAL | GObject.BindingFlags.SYNC_CREATE);
|
2018-05-04 11:55:29 -04:00
|
|
|
hbox.add_child(this._dndButton);
|
|
|
|
|
2019-10-17 17:27:27 -04:00
|
|
|
this._clearButton = new St.Button({
|
|
|
|
style_class: 'message-list-clear-button button',
|
|
|
|
label: _('Clear'),
|
|
|
|
can_focus: true,
|
2018-05-04 11:55:29 -04:00
|
|
|
x_expand: true,
|
2019-10-17 17:27:27 -04:00
|
|
|
x_align: Clutter.ActorAlign.END,
|
|
|
|
});
|
2017-02-25 21:33:26 -05:00
|
|
|
this._clearButton.connect('clicked', () => {
|
2019-08-31 14:41:16 -04:00
|
|
|
this._sectionList.get_children().forEach(s => s.clear());
|
2017-02-25 21:33:26 -05:00
|
|
|
});
|
2018-05-04 11:55:29 -04:00
|
|
|
hbox.add_actor(this._clearButton);
|
2014-12-05 10:24:35 -05:00
|
|
|
|
2019-07-16 05:24:13 -04:00
|
|
|
this._placeholder.bind_property('visible',
|
2019-08-31 14:43:05 -04:00
|
|
|
this._clearButton, 'visible',
|
|
|
|
GObject.BindingFlags.INVERT_BOOLEAN);
|
|
|
|
|
2014-12-05 10:24:35 -05:00
|
|
|
this._sectionList = new St.BoxLayout({ style_class: 'message-list-sections',
|
|
|
|
vertical: true,
|
2019-10-17 17:40:24 -04:00
|
|
|
x_expand: true,
|
2014-12-05 10:24:35 -05:00
|
|
|
y_expand: true,
|
|
|
|
y_align: Clutter.ActorAlign.START });
|
2019-08-31 14:41:16 -04:00
|
|
|
this._sectionList.connect('actor-added', this._sync.bind(this));
|
|
|
|
this._sectionList.connect('actor-removed', this._sync.bind(this));
|
2014-12-05 10:24:35 -05:00
|
|
|
this._scrollView.add_actor(this._sectionList);
|
2014-12-11 12:29:17 -05:00
|
|
|
|
2016-02-15 06:13:22 -05:00
|
|
|
this._mediaSection = new Mpris.MediaSection();
|
|
|
|
this._addSection(this._mediaSection);
|
|
|
|
|
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
|
|
|
|
2017-12-01 19:27:35 -05:00
|
|
|
Main.sessionMode.connect('updated', this._sync.bind(this));
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2014-12-05 10:24:35 -05:00
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
_addSection(section) {
|
2019-08-31 14:41:16 -04:00
|
|
|
let connectionsIds = [];
|
2014-12-05 10:24:35 -05:00
|
|
|
|
2019-08-31 14:41:16 -04:00
|
|
|
for (let prop of ['visible', 'empty', 'can-clear']) {
|
|
|
|
connectionsIds.push(
|
2020-02-14 10:10:34 -05:00
|
|
|
section.connect('notify::%s'.format(prop), this._sync.bind(this)));
|
2019-08-31 14:41:16 -04:00
|
|
|
}
|
|
|
|
connectionsIds.push(section.connect('message-focused', (_s, messageActor) => {
|
|
|
|
Util.ensureActorVisibleInScrollView(this._scrollView, messageActor);
|
|
|
|
}));
|
2014-12-05 10:24:35 -05:00
|
|
|
|
2019-08-19 20:20:08 -04:00
|
|
|
connectionsIds.push(section.connect('destroy', () => {
|
2019-08-31 14:41:16 -04:00
|
|
|
connectionsIds.forEach(id => section.disconnect(id));
|
|
|
|
this._sectionList.remove_actor(section);
|
|
|
|
}));
|
2014-12-05 10:24:35 -05:00
|
|
|
|
2019-08-31 14:41:16 -04:00
|
|
|
this._sectionList.add_actor(section);
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2014-12-05 10:24:35 -05:00
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
_sync() {
|
2019-08-31 14:41:16 -04:00
|
|
|
let sections = this._sectionList.get_children();
|
2017-10-30 20:38:18 -04:00
|
|
|
let visible = sections.some(s => s.allowed);
|
2019-07-16 05:24:13 -04:00
|
|
|
this.visible = visible;
|
2015-03-02 20:04:37 -05:00
|
|
|
if (!visible)
|
|
|
|
return;
|
|
|
|
|
2019-07-16 05:24:13 -04:00
|
|
|
let empty = sections.every(s => s.empty || !s.visible);
|
|
|
|
this._placeholder.visible = empty;
|
2017-02-25 21:33:26 -05:00
|
|
|
|
2019-07-16 05:24:13 -04:00
|
|
|
let canClear = sections.some(s => s.canClear && s.visible);
|
2017-02-25 21:33:26 -05:00
|
|
|
this._clearButton.reactive = canClear;
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2014-12-05 10:24:35 -05:00
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
setEventSource(eventSource) {
|
2014-12-11 12:29:17 -05:00
|
|
|
this._eventsSection.setEventSource(eventSource);
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2014-12-11 12:29:17 -05:00
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
setDate(date) {
|
2019-08-31 14:41:16 -04:00
|
|
|
this._sectionList.get_children().forEach(s => s.setDate(date));
|
2015-02-11 14:41:56 -05:00
|
|
|
this._placeholder.setDate(date);
|
2014-12-05 10:24:35 -05:00
|
|
|
}
|
2019-07-16 05:24:13 -04:00
|
|
|
});
|