2011-09-28 13:16:26 +00:00
|
|
|
// -*- mode: js; js-indent-level: 4; indent-tabs-mode: nil -*-
|
2011-01-28 21:35:46 +00:00
|
|
|
|
|
|
|
const GLib = imports.gi.GLib;
|
|
|
|
const Gio = imports.gi.Gio;
|
2011-08-21 07:31:16 +00:00
|
|
|
const GnomeDesktop = imports.gi.GnomeDesktop;
|
2014-10-01 21:28:14 +00:00
|
|
|
const GObject = imports.gi.GObject;
|
2015-02-06 23:47:27 +00:00
|
|
|
const GWeather = imports.gi.GWeather;
|
2011-01-28 21:35:46 +00:00
|
|
|
const Mainloop = imports.mainloop;
|
2017-02-24 12:15:39 +00:00
|
|
|
const Pango = imports.gi.Pango;
|
2011-01-28 21:35:46 +00:00
|
|
|
const Cairo = imports.cairo;
|
|
|
|
const Clutter = imports.gi.Clutter;
|
|
|
|
const Shell = imports.gi.Shell;
|
|
|
|
const St = imports.gi.St;
|
2012-02-27 16:31:10 +00:00
|
|
|
const Atk = imports.gi.Atk;
|
2011-01-28 21:35:46 +00:00
|
|
|
|
2011-08-22 18:21:51 +00:00
|
|
|
const Params = imports.misc.params;
|
2011-01-28 21:35:46 +00:00
|
|
|
const Util = imports.misc.util;
|
|
|
|
const Main = imports.ui.main;
|
|
|
|
const PanelMenu = imports.ui.panelMenu;
|
|
|
|
const PopupMenu = imports.ui.popupMenu;
|
|
|
|
const Calendar = imports.ui.calendar;
|
2017-02-24 12:15:39 +00:00
|
|
|
const Weather = imports.misc.weather;
|
2015-08-13 22:57:49 +00:00
|
|
|
const System = imports.system;
|
2011-01-28 21:35:46 +00:00
|
|
|
|
2015-02-13 15:25:21 +00:00
|
|
|
function _isToday(date) {
|
|
|
|
let now = new Date();
|
|
|
|
return now.getYear() == date.getYear() &&
|
|
|
|
now.getMonth() == date.getMonth() &&
|
|
|
|
now.getDate() == date.getDate();
|
|
|
|
}
|
|
|
|
|
2017-10-31 01:19:44 +00:00
|
|
|
var TodayButton = class TodayButton {
|
|
|
|
constructor(calendar) {
|
2014-12-05 15:03:59 +00:00
|
|
|
// Having the ability to go to the current date if the user is already
|
|
|
|
// on the current date can be confusing. So don't make the button reactive
|
|
|
|
// until the selected date changes.
|
|
|
|
this.actor = new St.Button({ style_class: 'datemenu-today-button',
|
2017-02-24 13:56:47 +00:00
|
|
|
x_expand: true, x_align: St.Align.START,
|
2015-02-21 19:09:56 +00:00
|
|
|
can_focus: true,
|
2014-12-05 15:03:59 +00:00
|
|
|
reactive: false
|
|
|
|
});
|
2017-10-31 00:38:18 +00:00
|
|
|
this.actor.connect('clicked', () => {
|
|
|
|
this._calendar.setDate(new Date(), false);
|
|
|
|
});
|
2014-12-05 15:03:59 +00:00
|
|
|
|
|
|
|
let hbox = new St.BoxLayout({ vertical: true });
|
|
|
|
this.actor.add_actor(hbox);
|
|
|
|
|
|
|
|
this._dayLabel = new St.Label({ style_class: 'day-label',
|
|
|
|
x_align: Clutter.ActorAlign.START });
|
|
|
|
hbox.add_actor(this._dayLabel);
|
|
|
|
|
|
|
|
this._dateLabel = new St.Label({ style_class: 'date-label' });
|
|
|
|
hbox.add_actor(this._dateLabel);
|
|
|
|
|
|
|
|
this._calendar = calendar;
|
2017-10-31 00:38:18 +00:00
|
|
|
this._calendar.connect('selected-date-changed', (calendar, date) => {
|
|
|
|
// Make the button reactive only if the selected date is not the
|
|
|
|
// current date.
|
|
|
|
this.actor.reactive = !_isToday(date)
|
|
|
|
});
|
2017-10-31 01:19:44 +00:00
|
|
|
}
|
2014-12-05 15:03:59 +00:00
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
setDate(date) {
|
2014-12-05 15:03:59 +00:00
|
|
|
this._dayLabel.set_text(date.toLocaleFormat('%A'));
|
|
|
|
|
|
|
|
/* Translators: This is the date format to use when the calendar popup is
|
2018-10-15 14:43:36 +00:00
|
|
|
* shown - it is shown just below the time in the top bar (e.g.,
|
|
|
|
* "Tue 9:29 AM"). The string itself should become a full date, e.g.,
|
|
|
|
* "February 17 2015".
|
2014-12-05 15:03:59 +00:00
|
|
|
*/
|
2018-10-15 14:50:02 +00:00
|
|
|
let dateFormat = Shell.util_translate_time_string (N_("%B %-d %Y"));
|
2014-12-05 15:03:59 +00:00
|
|
|
this._dateLabel.set_text(date.toLocaleFormat(dateFormat));
|
|
|
|
|
|
|
|
/* Translators: This is the accessible name of the date button shown
|
|
|
|
* below the time in the shell; it should combine the weekday and the
|
|
|
|
* date, e.g. "Tuesday February 17 2015".
|
|
|
|
*/
|
2017-02-10 02:12:59 +00:00
|
|
|
dateFormat = Shell.util_translate_time_string (N_("%A %B %e %Y"));
|
2014-12-05 15:03:59 +00:00
|
|
|
this.actor.accessible_name = date.toLocaleFormat(dateFormat);
|
|
|
|
}
|
2017-10-31 01:19:44 +00:00
|
|
|
};
|
2015-02-06 23:47:27 +00:00
|
|
|
|
2017-10-31 01:19:44 +00:00
|
|
|
var WorldClocksSection = class WorldClocksSection {
|
|
|
|
constructor() {
|
2015-02-06 23:47:27 +00:00
|
|
|
this._clock = new GnomeDesktop.WallClock();
|
|
|
|
this._clockNotifyId = 0;
|
|
|
|
|
|
|
|
this._locations = [];
|
|
|
|
|
|
|
|
this.actor = new St.Button({ style_class: 'world-clocks-button',
|
|
|
|
x_fill: true,
|
|
|
|
can_focus: true });
|
2017-10-31 00:38:18 +00:00
|
|
|
this.actor.connect('clicked', () => {
|
|
|
|
this._clockAppMon.activateApp();
|
2015-02-06 23:47:27 +00:00
|
|
|
|
2017-10-31 00:38:18 +00:00
|
|
|
Main.overview.hide();
|
|
|
|
Main.panel.closeCalendar();
|
|
|
|
});
|
2015-02-06 23:47:27 +00:00
|
|
|
|
|
|
|
let layout = new Clutter.GridLayout({ orientation: Clutter.Orientation.VERTICAL });
|
|
|
|
this._grid = new St.Widget({ style_class: 'world-clocks-grid',
|
|
|
|
layout_manager: layout });
|
|
|
|
layout.hookup_style(this._grid);
|
|
|
|
|
|
|
|
this.actor.child = this._grid;
|
|
|
|
|
2017-02-23 21:54:32 +00:00
|
|
|
this._clockAppMon = new Util.AppSettingsMonitor('org.gnome.clocks.desktop',
|
|
|
|
'org.gnome.clocks');
|
|
|
|
this._clockAppMon.connect('available-changed',
|
2017-12-02 00:27:35 +00:00
|
|
|
this._sync.bind(this));
|
2017-02-23 21:54:32 +00:00
|
|
|
this._clockAppMon.watchSetting('world-clocks',
|
2017-12-02 00:27:35 +00:00
|
|
|
this._clocksChanged.bind(this));
|
2015-02-06 23:47:27 +00:00
|
|
|
this._sync();
|
2017-10-31 01:19:44 +00:00
|
|
|
}
|
2015-02-06 23:47:27 +00:00
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
_sync() {
|
2017-02-23 21:54:32 +00:00
|
|
|
this.actor.visible = this._clockAppMon.available;
|
2017-10-31 01:19:44 +00:00
|
|
|
}
|
2015-02-06 23:47:27 +00:00
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
_clocksChanged(settings) {
|
2015-02-06 23:47:27 +00:00
|
|
|
this._grid.destroy_all_children();
|
|
|
|
this._locations = [];
|
|
|
|
|
|
|
|
let world = GWeather.Location.get_world();
|
2017-02-23 21:54:32 +00:00
|
|
|
let clocks = settings.get_value('world-clocks').deep_unpack();
|
2015-02-06 23:47:27 +00:00
|
|
|
for (let i = 0; i < clocks.length; i++) {
|
2017-12-04 13:30:01 +00:00
|
|
|
if (!clocks[i].location)
|
|
|
|
continue;
|
2015-02-06 23:47:27 +00:00
|
|
|
let l = world.deserialize(clocks[i].location);
|
2017-12-04 13:30:01 +00:00
|
|
|
if (l)
|
|
|
|
this._locations.push({ location: l });
|
2015-02-06 23:47:27 +00:00
|
|
|
}
|
|
|
|
|
2017-10-31 00:38:18 +00:00
|
|
|
this._locations.sort((a, b) => {
|
2015-02-06 23:47:27 +00:00
|
|
|
return a.location.get_timezone().get_offset() -
|
|
|
|
b.location.get_timezone().get_offset();
|
|
|
|
});
|
|
|
|
|
|
|
|
let layout = this._grid.layout_manager;
|
|
|
|
let title = (this._locations.length == 0) ? _("Add world clocks…")
|
|
|
|
: _("World Clocks");
|
|
|
|
let header = new St.Label({ style_class: 'world-clocks-header',
|
|
|
|
x_align: Clutter.ActorAlign.START,
|
|
|
|
text: title });
|
|
|
|
layout.attach(header, 0, 0, 2, 1);
|
2015-03-03 22:22:02 +00:00
|
|
|
this.actor.label_actor = header;
|
2015-02-06 23:47:27 +00:00
|
|
|
|
|
|
|
for (let i = 0; i < this._locations.length; i++) {
|
|
|
|
let l = this._locations[i].location;
|
|
|
|
|
2018-03-25 16:39:37 +00:00
|
|
|
let name = l.get_level() == GWeather.LocationLevel.NAMED_TIMEZONE ? l.get_name()
|
|
|
|
: l.get_city_name();
|
2015-02-06 23:47:27 +00:00
|
|
|
let label = new St.Label({ style_class: 'world-clocks-city',
|
2018-03-25 16:39:37 +00:00
|
|
|
text: name,
|
2015-02-06 23:47:27 +00:00
|
|
|
x_align: Clutter.ActorAlign.START,
|
|
|
|
x_expand: true });
|
|
|
|
|
|
|
|
let time = new St.Label({ style_class: 'world-clocks-time',
|
|
|
|
x_align: Clutter.ActorAlign.END,
|
|
|
|
x_expand: true });
|
|
|
|
|
|
|
|
if (this._grid.text_direction == Clutter.TextDirection.RTL) {
|
|
|
|
layout.attach(time, 0, i + 1, 1, 1);
|
|
|
|
layout.attach(label, 1, i + 1, 1, 1);
|
|
|
|
} else {
|
|
|
|
layout.attach(label, 0, i + 1, 1, 1);
|
|
|
|
layout.attach(time, 1, i + 1, 1, 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
this._locations[i].actor = time;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (this._grid.get_n_children() > 1) {
|
|
|
|
if (!this._clockNotifyId)
|
|
|
|
this._clockNotifyId =
|
2017-12-02 00:27:35 +00:00
|
|
|
this._clock.connect('notify::clock', this._updateLabels.bind(this));
|
2015-02-06 23:47:27 +00:00
|
|
|
this._updateLabels();
|
|
|
|
} else {
|
|
|
|
if (this._clockNotifyId)
|
|
|
|
this._clock.disconnect(this._clockNotifyId);
|
|
|
|
this._clockNotifyId = 0;
|
|
|
|
}
|
2017-10-31 01:19:44 +00:00
|
|
|
}
|
2015-02-06 23:47:27 +00:00
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
_updateLabels() {
|
2015-02-06 23:47:27 +00:00
|
|
|
for (let i = 0; i < this._locations.length; i++) {
|
|
|
|
let l = this._locations[i];
|
|
|
|
let tz = GLib.TimeZone.new(l.location.get_timezone().get_tzid());
|
|
|
|
let now = GLib.DateTime.new_now(tz);
|
2015-02-25 19:26:08 +00:00
|
|
|
l.actor.text = Util.formatTime(now, { timeOnly: true });
|
2015-02-06 23:47:27 +00:00
|
|
|
}
|
|
|
|
}
|
2017-10-31 01:19:44 +00:00
|
|
|
};
|
2015-02-06 23:47:27 +00:00
|
|
|
|
2017-10-31 01:19:44 +00:00
|
|
|
var WeatherSection = class WeatherSection {
|
|
|
|
constructor() {
|
2017-02-24 12:15:39 +00:00
|
|
|
this._weatherClient = new Weather.WeatherClient();
|
|
|
|
|
|
|
|
this.actor = new St.Button({ style_class: 'weather-button',
|
|
|
|
x_fill: true,
|
|
|
|
can_focus: true });
|
|
|
|
this.actor.connect('clicked', () => {
|
|
|
|
this._weatherClient.activateApp();
|
|
|
|
|
|
|
|
Main.overview.hide();
|
|
|
|
Main.panel.closeCalendar();
|
|
|
|
});
|
|
|
|
this.actor.connect('notify::mapped', () => {
|
|
|
|
if (this.actor.mapped)
|
|
|
|
this._weatherClient.update();
|
|
|
|
});
|
|
|
|
|
|
|
|
let box = new St.BoxLayout({ style_class: 'weather-box',
|
|
|
|
vertical: true });
|
|
|
|
|
|
|
|
this.actor.child = box;
|
|
|
|
|
|
|
|
box.add_child(new St.Label({ style_class: 'weather-header',
|
|
|
|
x_align: Clutter.ActorAlign.START,
|
|
|
|
text: _("Weather") }));
|
|
|
|
|
|
|
|
this._conditionsLabel = new St.Label({ style_class: 'weather-conditions',
|
|
|
|
x_align: Clutter.ActorAlign.START });
|
|
|
|
this._conditionsLabel.clutter_text.ellipsize = Pango.EllipsizeMode.NONE;
|
|
|
|
this._conditionsLabel.clutter_text.line_wrap = true;
|
|
|
|
box.add_child(this._conditionsLabel);
|
|
|
|
|
2017-12-02 00:27:35 +00:00
|
|
|
this._weatherClient.connect('changed', this._sync.bind(this));
|
2017-02-24 12:15:39 +00:00
|
|
|
this._sync();
|
2017-10-31 01:19:44 +00:00
|
|
|
}
|
2017-02-24 12:15:39 +00:00
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
_getSummary(info, capitalize=false) {
|
2017-02-25 17:25:07 +00:00
|
|
|
let options = capitalize ? GWeather.FormatOptions.SENTENCE_CAPITALIZATION
|
|
|
|
: GWeather.FormatOptions.NO_CAPITALIZATION;
|
|
|
|
|
2017-09-08 10:13:48 +00:00
|
|
|
let [ok, phenomenon, qualifier] = info.get_value_conditions();
|
2017-02-25 17:25:07 +00:00
|
|
|
if (ok)
|
2017-10-04 15:02:36 +00:00
|
|
|
return new GWeather.Conditions({ significant: true,
|
|
|
|
phenomenon,
|
|
|
|
qualifier }).to_string_full(options);
|
2017-02-25 17:25:07 +00:00
|
|
|
|
|
|
|
let [, sky] = info.get_value_sky();
|
2017-09-08 10:13:48 +00:00
|
|
|
return GWeather.Sky.to_string_full(sky, options);
|
2017-10-31 01:19:44 +00:00
|
|
|
}
|
2017-02-24 12:15:39 +00:00
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
_sameSummary(info1, info2) {
|
2017-02-24 12:15:39 +00:00
|
|
|
let [ok1, phenom1, qualifier1] = info1.get_value_conditions();
|
|
|
|
let [ok2, phenom2, qualifier2] = info2.get_value_conditions();
|
|
|
|
if (ok1 || ok2)
|
|
|
|
return ok1 == ok2 && phenom1 == phenom2 && qualifier1 == qualifier2;
|
|
|
|
|
|
|
|
let [, sky1] = info1.get_value_sky();
|
|
|
|
let [, sky2] = info2.get_value_sky();
|
|
|
|
return sky1 == sky2;
|
2017-10-31 01:19:44 +00:00
|
|
|
}
|
2017-02-24 12:15:39 +00:00
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
_getSummaryText() {
|
2017-02-24 12:15:39 +00:00
|
|
|
let info = this._weatherClient.info;
|
|
|
|
let forecasts = info.get_forecast_list();
|
|
|
|
if (forecasts.length == 0) // No forecasts, just current conditions
|
2017-02-25 17:25:07 +00:00
|
|
|
return '%s.'.format(this._getSummary(info, true));
|
2017-02-24 12:15:39 +00:00
|
|
|
|
|
|
|
let current = info;
|
2017-02-25 17:25:07 +00:00
|
|
|
let infos = [info];
|
2017-02-24 12:15:39 +00:00
|
|
|
for (let i = 0; i < forecasts.length; i++) {
|
|
|
|
let [ok, timestamp] = forecasts[i].get_value_update();
|
|
|
|
if (!_isToday(new Date(timestamp * 1000)))
|
|
|
|
continue; // Ignore forecasts from other days
|
|
|
|
|
|
|
|
if (this._sameSummary(current, forecasts[i]))
|
|
|
|
continue; // Ignore consecutive runs of equal summaries
|
|
|
|
|
|
|
|
current = forecasts[i];
|
2017-02-25 17:25:07 +00:00
|
|
|
if (infos.push(current) == 3)
|
2017-02-24 12:15:39 +00:00
|
|
|
break; // Use a maximum of three summaries
|
|
|
|
}
|
|
|
|
|
|
|
|
let fmt;
|
2017-02-25 17:25:07 +00:00
|
|
|
switch(infos.length) {
|
2017-02-24 12:15:39 +00:00
|
|
|
/* Translators: %s is a weather condition like "Clear sky"; see
|
|
|
|
libgweather for the possible condition strings. If at all
|
|
|
|
possible, the sentence should match the grammatical case etc. of
|
|
|
|
the inserted conditions. */
|
|
|
|
case 1: fmt = _("%s all day."); break;
|
|
|
|
|
|
|
|
/* Translators: %s is a weather condition like "Clear sky"; see
|
|
|
|
libgweather for the possible condition strings. If at all
|
|
|
|
possible, the sentence should match the grammatical case etc. of
|
|
|
|
the inserted conditions. */
|
|
|
|
case 2: fmt = _("%s, then %s later."); break;
|
|
|
|
|
|
|
|
/* Translators: %s is a weather condition like "Clear sky"; see
|
|
|
|
libgweather for the possible condition strings. If at all
|
|
|
|
possible, the sentence should match the grammatical case etc. of
|
|
|
|
the inserted conditions. */
|
|
|
|
case 3: fmt = _("%s, then %s, followed by %s later."); break;
|
|
|
|
}
|
2017-02-25 17:25:07 +00:00
|
|
|
let summaries = infos.map((info, i) => {
|
|
|
|
let capitalize = i == 0 && fmt.startsWith('%s');
|
|
|
|
return this._getSummary(info, capitalize);
|
|
|
|
});
|
2017-02-24 12:15:39 +00:00
|
|
|
return String.prototype.format.apply(fmt, summaries);
|
2017-10-31 01:19:44 +00:00
|
|
|
}
|
2017-02-24 12:15:39 +00:00
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
_getLabelText() {
|
2017-03-19 13:42:35 +00:00
|
|
|
if (!this._weatherClient.hasLocation)
|
|
|
|
return _("Select a location…");
|
|
|
|
|
2017-02-24 12:15:39 +00:00
|
|
|
if (this._weatherClient.loading)
|
|
|
|
return _("Loading…");
|
|
|
|
|
|
|
|
let info = this._weatherClient.info;
|
|
|
|
if (info.is_valid())
|
|
|
|
return this._getSummaryText() + ' ' +
|
|
|
|
/* Translators: %s is a temperature with unit, e.g. "23℃" */
|
|
|
|
_("Feels like %s.").format(info.get_apparent());
|
|
|
|
|
|
|
|
if (info.network_error())
|
|
|
|
return _("Go online for weather information");
|
|
|
|
|
|
|
|
return _("Weather information is currently unavailable");
|
2017-10-31 01:19:44 +00:00
|
|
|
}
|
2017-02-24 12:15:39 +00:00
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
_sync() {
|
2017-02-24 12:15:39 +00:00
|
|
|
this.actor.visible = this._weatherClient.available;
|
|
|
|
|
|
|
|
if (!this.actor.visible)
|
|
|
|
return;
|
|
|
|
|
|
|
|
this._conditionsLabel.text = this._getLabelText();
|
|
|
|
}
|
2017-10-31 01:19:44 +00:00
|
|
|
};
|
2017-02-24 12:15:39 +00:00
|
|
|
|
2017-10-31 01:19:44 +00:00
|
|
|
var MessagesIndicator = class MessagesIndicator {
|
|
|
|
constructor() {
|
2017-09-12 10:33:37 +00:00
|
|
|
this.actor = new St.Icon({ icon_name: 'message-indicator-symbolic',
|
|
|
|
icon_size: 16,
|
|
|
|
visible: false, y_expand: true,
|
|
|
|
y_align: Clutter.ActorAlign.CENTER });
|
2015-02-14 02:17:16 +00:00
|
|
|
|
|
|
|
this._sources = [];
|
|
|
|
|
2017-12-02 00:27:35 +00:00
|
|
|
Main.messageTray.connect('source-added', this._onSourceAdded.bind(this));
|
|
|
|
Main.messageTray.connect('source-removed', this._onSourceRemoved.bind(this));
|
|
|
|
Main.messageTray.connect('queue-changed', this._updateCount.bind(this));
|
2015-02-14 02:17:16 +00:00
|
|
|
|
|
|
|
let sources = Main.messageTray.getSources();
|
2017-10-31 00:38:18 +00:00
|
|
|
sources.forEach(source => { this._onSourceAdded(null, source); });
|
2017-10-31 01:19:44 +00:00
|
|
|
}
|
2015-02-14 02:17:16 +00:00
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
_onSourceAdded(tray, source) {
|
2017-12-02 00:27:35 +00:00
|
|
|
source.connect('count-updated', this._updateCount.bind(this));
|
2015-02-14 02:17:16 +00:00
|
|
|
this._sources.push(source);
|
|
|
|
this._updateCount();
|
2017-10-31 01:19:44 +00:00
|
|
|
}
|
2015-02-14 02:17:16 +00:00
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
_onSourceRemoved(tray, source) {
|
2015-02-14 02:17:16 +00:00
|
|
|
this._sources.splice(this._sources.indexOf(source), 1);
|
|
|
|
this._updateCount();
|
2017-10-31 01:19:44 +00:00
|
|
|
}
|
2015-02-14 02:17:16 +00:00
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
_updateCount() {
|
2015-02-14 02:17:16 +00:00
|
|
|
let count = 0;
|
2017-10-31 00:38:18 +00:00
|
|
|
this._sources.forEach(source => { count += source.unseenCount; });
|
2015-02-14 02:17:16 +00:00
|
|
|
count -= Main.messageTray.queueCount;
|
|
|
|
|
|
|
|
this.actor.visible = (count > 0);
|
|
|
|
}
|
2017-10-31 01:19:44 +00:00
|
|
|
};
|
2015-02-14 02:17:16 +00:00
|
|
|
|
2017-10-31 01:23:39 +00:00
|
|
|
var IndicatorPad = GObject.registerClass(
|
|
|
|
class IndicatorPad extends St.Widget {
|
2017-10-31 00:03:21 +00:00
|
|
|
_init(actor) {
|
2015-02-14 02:17:16 +00:00
|
|
|
this._source = actor;
|
2017-04-28 14:54:28 +00:00
|
|
|
this._source.connect('notify::visible', () => { this.queue_relayout(); });
|
2017-10-31 01:23:39 +00:00
|
|
|
super._init();
|
|
|
|
}
|
2015-02-14 02:17:16 +00:00
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
vfunc_get_preferred_width(container, forHeight) {
|
2015-02-14 02:17:16 +00:00
|
|
|
if (this._source.visible)
|
|
|
|
return this._source.get_preferred_width(forHeight);
|
|
|
|
return [0, 0];
|
2017-10-31 01:23:39 +00:00
|
|
|
}
|
2015-02-14 02:17:16 +00:00
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
vfunc_get_preferred_height(container, forWidth) {
|
2015-02-14 02:17:16 +00:00
|
|
|
if (this._source.visible)
|
|
|
|
return this._source.get_preferred_height(forWidth);
|
|
|
|
return [0, 0];
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2017-10-31 01:23:39 +00:00
|
|
|
var FreezableBinLayout = GObject.registerClass(
|
|
|
|
class FreezableBinLayout extends Clutter.BinLayout {
|
2017-10-31 00:03:21 +00:00
|
|
|
_init() {
|
2017-10-31 01:23:39 +00:00
|
|
|
super._init();
|
2015-02-13 15:25:21 +00:00
|
|
|
|
|
|
|
this._frozen = false;
|
|
|
|
this._savedWidth = [NaN, NaN];
|
|
|
|
this._savedHeight = [NaN, NaN];
|
2017-10-31 01:23:39 +00:00
|
|
|
}
|
2015-02-13 15:25:21 +00:00
|
|
|
|
|
|
|
set frozen(v) {
|
|
|
|
if (this._frozen == v)
|
|
|
|
return;
|
|
|
|
|
|
|
|
this._frozen = v;
|
|
|
|
if (!this._frozen)
|
|
|
|
this.layout_changed();
|
2017-10-31 01:23:39 +00:00
|
|
|
}
|
2015-02-13 15:25:21 +00:00
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
vfunc_get_preferred_width(container, forHeight) {
|
2015-02-13 15:25:21 +00:00
|
|
|
if (!this._frozen || this._savedWidth.some(isNaN))
|
2017-10-31 01:23:39 +00:00
|
|
|
return super.vfunc_get_preferred_width(container, forHeight);
|
2015-02-13 15:25:21 +00:00
|
|
|
return this._savedWidth;
|
2017-10-31 01:23:39 +00:00
|
|
|
}
|
2015-02-13 15:25:21 +00:00
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
vfunc_get_preferred_height(container, forWidth) {
|
2015-02-13 15:25:21 +00:00
|
|
|
if (!this._frozen || this._savedHeight.some(isNaN))
|
2017-10-31 01:23:39 +00:00
|
|
|
return super.vfunc_get_preferred_height(container, forWidth);
|
2015-02-13 15:25:21 +00:00
|
|
|
return this._savedHeight;
|
2017-10-31 01:23:39 +00:00
|
|
|
}
|
2017-02-26 13:37:51 +00:00
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
vfunc_allocate(container, allocation, flags) {
|
2017-10-31 01:23:39 +00:00
|
|
|
super.vfunc_allocate(container, allocation, flags);
|
2017-02-26 13:37:51 +00:00
|
|
|
|
|
|
|
let [width, height] = allocation.get_size();
|
|
|
|
this._savedWidth = [width, width];
|
|
|
|
this._savedHeight = [height, height];
|
2015-02-13 15:25:21 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2017-10-31 01:23:39 +00:00
|
|
|
var CalendarColumnLayout = GObject.registerClass(
|
|
|
|
class CalendarColumnLayout extends Clutter.BoxLayout {
|
2017-10-31 00:03:21 +00:00
|
|
|
_init(actor) {
|
2017-10-31 01:23:39 +00:00
|
|
|
super._init({ orientation: Clutter.Orientation.VERTICAL });
|
2017-02-24 13:56:47 +00:00
|
|
|
this._calActor = actor;
|
2017-10-31 01:23:39 +00:00
|
|
|
}
|
2017-02-24 13:56:47 +00:00
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
vfunc_get_preferred_width(container, forHeight) {
|
2017-02-24 13:56:47 +00:00
|
|
|
if (!this._calActor || this._calActor.get_parent() != container)
|
2017-10-31 01:23:39 +00:00
|
|
|
return super.vfunc_get_preferred_width(container, forHeight);
|
2017-02-24 13:56:47 +00:00
|
|
|
return this._calActor.get_preferred_width(forHeight);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2017-10-31 01:23:39 +00:00
|
|
|
var DateMenuButton = GObject.registerClass(
|
|
|
|
class DateMenuButton extends PanelMenu.Button {
|
2017-10-31 00:03:21 +00:00
|
|
|
_init() {
|
2011-01-28 21:35:46 +00:00
|
|
|
let item;
|
|
|
|
let hbox;
|
|
|
|
let vbox;
|
|
|
|
|
2015-01-30 04:56:28 +00:00
|
|
|
let menuAlignment = 0.5;
|
2012-02-14 01:37:28 +00:00
|
|
|
if (Clutter.get_default_text_direction() == Clutter.TextDirection.RTL)
|
2011-02-18 23:09:01 +00:00
|
|
|
menuAlignment = 1.0 - menuAlignment;
|
2017-10-31 01:23:39 +00:00
|
|
|
super._init(menuAlignment);
|
2011-01-28 21:35:46 +00:00
|
|
|
|
2013-08-03 12:30:46 +00:00
|
|
|
this._clockDisplay = new St.Label({ y_align: Clutter.ActorAlign.CENTER });
|
2015-02-14 02:17:16 +00:00
|
|
|
this._indicator = new MessagesIndicator();
|
|
|
|
|
|
|
|
let box = new St.BoxLayout();
|
|
|
|
box.add_actor(new IndicatorPad(this._indicator.actor));
|
|
|
|
box.add_actor(this._clockDisplay);
|
|
|
|
box.add_actor(this._indicator.actor);
|
|
|
|
|
2013-08-27 13:44:46 +00:00
|
|
|
this.actor.label_actor = this._clockDisplay;
|
2015-02-14 02:17:16 +00:00
|
|
|
this.actor.add_actor(box);
|
2013-08-07 18:35:56 +00:00
|
|
|
this.actor.add_style_class_name ('clock-display');
|
2011-01-28 21:35:46 +00:00
|
|
|
|
2015-02-14 02:17:16 +00:00
|
|
|
|
2015-02-13 15:25:21 +00:00
|
|
|
let layout = new FreezableBinLayout();
|
|
|
|
let bin = new St.Widget({ layout_manager: layout });
|
2017-06-17 16:14:20 +00:00
|
|
|
// For some minimal compatibility with PopupMenuItem
|
|
|
|
bin._delegate = this;
|
2015-02-13 15:25:21 +00:00
|
|
|
this.menu.box.add_child(bin);
|
|
|
|
|
2013-07-16 00:00:41 +00:00
|
|
|
hbox = new St.BoxLayout({ name: 'calendarArea' });
|
2015-02-13 15:25:21 +00:00
|
|
|
bin.add_actor(hbox);
|
2011-01-28 21:35:46 +00:00
|
|
|
|
2015-01-30 04:56:28 +00:00
|
|
|
this._calendar = new Calendar.Calendar();
|
|
|
|
this._calendar.connect('selected-date-changed',
|
2017-10-31 00:38:18 +00:00
|
|
|
(calendar, date) => {
|
2015-02-13 15:25:21 +00:00
|
|
|
layout.frozen = !_isToday(date);
|
2014-12-11 17:29:17 +00:00
|
|
|
this._messageList.setDate(date);
|
2017-10-31 00:38:18 +00:00
|
|
|
});
|
2015-01-30 04:56:28 +00:00
|
|
|
|
2017-10-31 00:38:18 +00:00
|
|
|
this.menu.connect('open-state-changed', (menu, isOpen) => {
|
2015-02-13 22:53:18 +00:00
|
|
|
// Whenever the menu is opened, select today
|
2015-01-30 04:56:28 +00:00
|
|
|
if (isOpen) {
|
|
|
|
let now = new Date();
|
|
|
|
this._calendar.setDate(now);
|
2014-12-05 15:03:59 +00:00
|
|
|
this._date.setDate(now);
|
2015-03-02 08:30:20 +00:00
|
|
|
this._messageList.setDate(now);
|
2015-01-30 04:56:28 +00:00
|
|
|
}
|
2017-10-31 00:38:18 +00:00
|
|
|
});
|
2015-01-30 04:56:28 +00:00
|
|
|
|
2011-01-28 21:35:46 +00:00
|
|
|
// Fill up the first column
|
2016-02-15 11:02:31 +00:00
|
|
|
this._messageList = new Calendar.CalendarMessageList();
|
2014-12-11 17:29:17 +00:00
|
|
|
hbox.add(this._messageList.actor, { expand: true, y_fill: false, y_align: St.Align.START });
|
2011-01-28 21:35:46 +00:00
|
|
|
|
2015-01-30 04:56:28 +00:00
|
|
|
// Fill up the second column
|
2017-02-24 13:56:47 +00:00
|
|
|
let boxLayout = new CalendarColumnLayout(this._calendar.actor);
|
|
|
|
vbox = new St.Widget({ style_class: 'datemenu-calendar-column',
|
|
|
|
layout_manager: boxLayout });
|
|
|
|
boxLayout.hookup_style(vbox);
|
2011-01-28 21:35:46 +00:00
|
|
|
hbox.add(vbox);
|
|
|
|
|
2014-12-05 15:03:59 +00:00
|
|
|
this._date = new TodayButton(this._calendar);
|
|
|
|
vbox.add_actor(this._date.actor);
|
2011-01-28 21:35:46 +00:00
|
|
|
|
2017-02-24 13:56:47 +00:00
|
|
|
vbox.add_actor(this._calendar.actor);
|
2011-01-28 21:35:46 +00:00
|
|
|
|
2015-03-03 00:27:43 +00:00
|
|
|
this._displaysSection = new St.ScrollView({ style_class: 'datemenu-displays-section vfade',
|
|
|
|
x_expand: true, x_fill: true,
|
|
|
|
overlay_scrollbars: true });
|
2018-11-27 12:45:36 +00:00
|
|
|
this._displaysSection.set_policy(St.PolicyType.NEVER, St.PolicyType.AUTOMATIC);
|
2015-03-03 00:27:43 +00:00
|
|
|
vbox.add_actor(this._displaysSection);
|
2012-12-21 21:54:20 +00:00
|
|
|
|
2015-02-06 23:47:27 +00:00
|
|
|
let displaysBox = new St.BoxLayout({ vertical: true,
|
|
|
|
style_class: 'datemenu-displays-box' });
|
2015-03-03 00:27:43 +00:00
|
|
|
this._displaysSection.add_actor(displaysBox);
|
2012-12-15 10:30:03 +00:00
|
|
|
|
2015-02-06 23:47:27 +00:00
|
|
|
this._clocksItem = new WorldClocksSection();
|
|
|
|
displaysBox.add(this._clocksItem.actor, { x_fill: true });
|
2012-12-15 10:30:03 +00:00
|
|
|
|
2017-02-24 12:15:39 +00:00
|
|
|
this._weatherItem = new WeatherSection();
|
|
|
|
displaysBox.add(this._weatherItem.actor, { x_fill: true });
|
2011-01-28 21:35:46 +00:00
|
|
|
|
|
|
|
// Done with hbox for calendar and event list
|
|
|
|
|
2011-08-21 07:31:16 +00:00
|
|
|
this._clock = new GnomeDesktop.WallClock();
|
2014-10-01 21:28:14 +00:00
|
|
|
this._clock.bind_property('clock', this._clockDisplay, 'text', GObject.BindingFlags.SYNC_CREATE);
|
2017-12-02 00:27:35 +00:00
|
|
|
this._clock.connect('notify::timezone', this._updateTimeZone.bind(this));
|
2012-09-01 12:42:53 +00:00
|
|
|
|
2017-12-02 00:27:35 +00:00
|
|
|
Main.sessionMode.connect('updated', this._sessionUpdated.bind(this));
|
2012-09-01 12:42:53 +00:00
|
|
|
this._sessionUpdated();
|
2017-10-31 01:23:39 +00:00
|
|
|
}
|
2012-09-01 12:42:53 +00:00
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
_getEventSource() {
|
2012-03-21 07:59:39 +00:00
|
|
|
return new Calendar.DBusEventSource();
|
2017-10-31 01:23:39 +00:00
|
|
|
}
|
2012-03-21 07:59:39 +00:00
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
_setEventSource(eventSource) {
|
2013-03-04 16:04:28 +00:00
|
|
|
if (this._eventSource)
|
|
|
|
this._eventSource.destroy();
|
|
|
|
|
2012-09-01 12:42:53 +00:00
|
|
|
this._calendar.setEventSource(eventSource);
|
2014-12-11 17:29:17 +00:00
|
|
|
this._messageList.setEventSource(eventSource);
|
2013-03-04 16:04:28 +00:00
|
|
|
|
|
|
|
this._eventSource = eventSource;
|
2017-10-31 01:23:39 +00:00
|
|
|
}
|
2012-09-01 12:42:53 +00:00
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
_updateTimeZone() {
|
2015-08-13 22:57:49 +00:00
|
|
|
// SpiderMonkey caches the time zone so we must explicitly clear it
|
|
|
|
// before we can update the calendar, see
|
|
|
|
// https://bugzilla.gnome.org/show_bug.cgi?id=678507
|
|
|
|
System.clearDateCaches();
|
|
|
|
|
|
|
|
this._calendar.updateTimeZone();
|
2017-10-31 01:23:39 +00:00
|
|
|
}
|
2015-08-13 22:57:49 +00:00
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
_sessionUpdated() {
|
2012-09-01 12:42:53 +00:00
|
|
|
let eventSource;
|
|
|
|
let showEvents = Main.sessionMode.showCalendarEvents;
|
|
|
|
if (showEvents) {
|
2012-03-21 07:59:39 +00:00
|
|
|
eventSource = this._getEventSource();
|
2012-09-01 12:42:53 +00:00
|
|
|
} else {
|
2013-03-04 16:04:28 +00:00
|
|
|
eventSource = new Calendar.EmptyEventSource();
|
2012-09-01 12:42:53 +00:00
|
|
|
}
|
|
|
|
this._setEventSource(eventSource);
|
2015-03-03 00:27:43 +00:00
|
|
|
|
|
|
|
// Displays are not actually expected to launch Settings when activated
|
|
|
|
// but the corresponding app (clocks, weather); however we can consider
|
|
|
|
// that display-specific settings, so re-use "allowSettings" here ...
|
|
|
|
this._displaysSection.visible = Main.sessionMode.allowSettings;
|
2017-10-31 01:23:39 +00:00
|
|
|
}
|
2011-11-20 14:38:48 +00:00
|
|
|
});
|