2011-09-28 09:16:26 -04:00
|
|
|
// -*- mode: js; js-indent-level: 4; indent-tabs-mode: nil -*-
|
2011-01-28 16:35:46 -05:00
|
|
|
|
|
|
|
const GLib = imports.gi.GLib;
|
|
|
|
const Gio = imports.gi.Gio;
|
|
|
|
const Lang = imports.lang;
|
|
|
|
const Mainloop = imports.mainloop;
|
|
|
|
const Cairo = imports.cairo;
|
|
|
|
const Clutter = imports.gi.Clutter;
|
|
|
|
const Shell = imports.gi.Shell;
|
|
|
|
const St = imports.gi.St;
|
|
|
|
|
2011-08-22 14:21:51 -04:00
|
|
|
const Params = imports.misc.params;
|
2011-01-28 16:35:46 -05: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;
|
2011-08-12 10:06:19 -04:00
|
|
|
const UPowerGlib = imports.gi.UPowerGlib;
|
2011-01-28 16:35:46 -05:00
|
|
|
|
|
|
|
// in org.gnome.desktop.interface
|
|
|
|
const CLOCK_FORMAT_KEY = 'clock-format';
|
|
|
|
|
|
|
|
// in org.gnome.shell.clock
|
|
|
|
const CLOCK_SHOW_DATE_KEY = 'show-date';
|
|
|
|
const CLOCK_SHOW_SECONDS_KEY = 'show-seconds';
|
|
|
|
|
|
|
|
function _onVertSepRepaint (area)
|
|
|
|
{
|
|
|
|
let cr = area.get_context();
|
|
|
|
let themeNode = area.get_theme_node();
|
|
|
|
let [width, height] = area.get_surface_size();
|
2011-02-14 09:20:22 -05:00
|
|
|
let stippleColor = themeNode.get_color('-stipple-color');
|
2011-01-28 16:35:46 -05:00
|
|
|
let stippleWidth = themeNode.get_length('-stipple-width');
|
|
|
|
let x = Math.floor(width/2) + 0.5;
|
|
|
|
cr.moveTo(x, 0);
|
|
|
|
cr.lineTo(x, height);
|
|
|
|
Clutter.cairo_set_source_color(cr, stippleColor);
|
|
|
|
cr.setDash([1, 3], 1); // Hard-code for now
|
|
|
|
cr.setLineWidth(stippleWidth);
|
|
|
|
cr.stroke();
|
|
|
|
};
|
|
|
|
|
2011-11-20 09:38:48 -05:00
|
|
|
const DateMenuButton = new Lang.Class({
|
|
|
|
Name: 'DateMenuButton',
|
|
|
|
Extends: PanelMenu.Button,
|
2011-01-28 16:35:46 -05:00
|
|
|
|
2011-08-22 14:21:51 -04:00
|
|
|
_init: function(params) {
|
|
|
|
params = Params.parse(params, { showEvents: true });
|
|
|
|
|
2011-01-28 16:35:46 -05:00
|
|
|
let item;
|
|
|
|
let hbox;
|
|
|
|
let vbox;
|
|
|
|
|
2011-02-18 18:09:01 -05:00
|
|
|
let menuAlignment = 0.25;
|
2012-02-13 20:37:28 -05:00
|
|
|
if (Clutter.get_default_text_direction() == Clutter.TextDirection.RTL)
|
2011-02-18 18:09:01 -05:00
|
|
|
menuAlignment = 1.0 - menuAlignment;
|
2011-11-20 09:38:48 -05:00
|
|
|
this.parent(menuAlignment);
|
2011-01-28 16:35:46 -05:00
|
|
|
|
|
|
|
this._clock = new St.Label();
|
2011-06-09 11:50:24 -04:00
|
|
|
this.actor.add_actor(this._clock);
|
2011-01-28 16:35:46 -05:00
|
|
|
|
2011-06-28 08:57:19 -04:00
|
|
|
hbox = new St.BoxLayout({name: 'calendarArea' });
|
2011-01-28 16:35:46 -05:00
|
|
|
this.menu.addActor(hbox);
|
|
|
|
|
|
|
|
// Fill up the first column
|
|
|
|
|
|
|
|
vbox = new St.BoxLayout({vertical: true});
|
|
|
|
hbox.add(vbox);
|
|
|
|
|
|
|
|
// Date
|
|
|
|
this._date = new St.Label();
|
2012-01-05 13:00:06 -05:00
|
|
|
this.actor.label_actor = this._date;
|
2011-01-28 16:35:46 -05:00
|
|
|
this._date.style_class = 'datemenu-date-label';
|
|
|
|
vbox.add(this._date);
|
|
|
|
|
2011-08-22 14:21:51 -04:00
|
|
|
if (params.showEvents) {
|
|
|
|
this._eventSource = new Calendar.DBusEventSource();
|
|
|
|
this._eventList = new Calendar.EventsList(this._eventSource);
|
|
|
|
} else {
|
|
|
|
this._eventSource = null;
|
|
|
|
this._eventList = null;
|
|
|
|
}
|
2011-01-28 16:35:46 -05:00
|
|
|
|
|
|
|
// Calendar
|
|
|
|
this._calendar = new Calendar.Calendar(this._eventSource);
|
2011-08-22 14:21:51 -04:00
|
|
|
|
2011-01-28 16:35:46 -05:00
|
|
|
this._calendar.connect('selected-date-changed',
|
|
|
|
Lang.bind(this, function(calendar, date) {
|
2011-08-22 14:21:51 -04:00
|
|
|
// we know this._eventList is defined here, because selected-data-changed
|
|
|
|
// only gets emitted when the user clicks a date in the calendar,
|
|
|
|
// and the calender makes those dates unclickable when instantiated with
|
|
|
|
// a null event source
|
2011-01-28 16:35:46 -05:00
|
|
|
this._eventList.setDate(date);
|
|
|
|
}));
|
|
|
|
vbox.add(this._calendar.actor);
|
|
|
|
|
2011-08-23 10:14:55 -04:00
|
|
|
item = this.menu.addSettingsAction(_("Date and Time Settings"), 'gnome-datetime-panel.desktop');
|
2011-08-28 22:15:53 -04:00
|
|
|
if (item) {
|
|
|
|
let separator = new PopupMenu.PopupSeparatorMenuItem();
|
|
|
|
separator.setColumnWidths(1);
|
|
|
|
vbox.add(separator.actor, {y_align: St.Align.END, expand: true, y_fill: false});
|
2011-08-23 10:14:55 -04:00
|
|
|
|
2011-08-28 22:15:53 -04:00
|
|
|
item.actor.can_focus = false;
|
|
|
|
item.actor.reparent(vbox);
|
|
|
|
}
|
2011-01-28 16:35:46 -05:00
|
|
|
|
2011-08-22 14:21:51 -04:00
|
|
|
if (params.showEvents) {
|
|
|
|
// Add vertical separator
|
2011-01-28 16:35:46 -05:00
|
|
|
|
2011-08-22 14:21:51 -04:00
|
|
|
item = new St.DrawingArea({ style_class: 'calendar-vertical-separator',
|
|
|
|
pseudo_class: 'highlighted' });
|
|
|
|
item.connect('repaint', Lang.bind(this, _onVertSepRepaint));
|
|
|
|
hbox.add(item);
|
2011-01-28 16:35:46 -05:00
|
|
|
|
2011-08-22 14:21:51 -04:00
|
|
|
// Fill up the second column
|
|
|
|
vbox = new St.BoxLayout({name: 'calendarEventsArea',
|
|
|
|
vertical: true});
|
|
|
|
hbox.add(vbox, { expand: true });
|
2011-01-28 16:35:46 -05:00
|
|
|
|
2011-08-22 14:21:51 -04:00
|
|
|
// Event list
|
|
|
|
vbox.add(this._eventList.actor, { expand: true });
|
2011-01-28 16:35:46 -05:00
|
|
|
|
2011-08-22 14:21:51 -04:00
|
|
|
item = new PopupMenu.PopupMenuItem(_("Open Calendar"));
|
|
|
|
item.connect('activate', Lang.bind(this, this._onOpenCalendarActivate));
|
|
|
|
item.actor.can_focus = false;
|
|
|
|
vbox.add(item.actor, {y_align: St.Align.END, expand: true, y_fill: false});
|
|
|
|
}
|
2011-01-28 16:35:46 -05:00
|
|
|
|
|
|
|
// Whenever the menu is opened, select today
|
|
|
|
this.menu.connect('open-state-changed', Lang.bind(this, function(menu, isOpen) {
|
|
|
|
if (isOpen) {
|
|
|
|
let now = new Date();
|
2011-02-25 17:42:25 -05:00
|
|
|
/* Passing true to setDate() forces events to be reloaded. We
|
|
|
|
* want this behavior, because
|
|
|
|
*
|
|
|
|
* o It will cause activation of the calendar server which is
|
|
|
|
* useful if it has crashed
|
|
|
|
*
|
|
|
|
* o It will cause the calendar server to reload events which
|
|
|
|
* is useful if dynamic updates are not supported or not
|
|
|
|
* properly working
|
|
|
|
*
|
|
|
|
* Since this only happens when the menu is opened, the cost
|
|
|
|
* isn't very big.
|
|
|
|
*/
|
|
|
|
this._calendar.setDate(now, true);
|
2011-01-28 16:35:46 -05:00
|
|
|
// No need to update this._eventList as ::selected-date-changed
|
|
|
|
// signal will fire
|
|
|
|
}
|
|
|
|
}));
|
|
|
|
|
|
|
|
// Done with hbox for calendar and event list
|
|
|
|
|
|
|
|
// Track changes to clock settings
|
|
|
|
this._desktopSettings = new Gio.Settings({ schema: 'org.gnome.desktop.interface' });
|
|
|
|
this._clockSettings = new Gio.Settings({ schema: 'org.gnome.shell.clock' });
|
|
|
|
this._desktopSettings.connect('changed', Lang.bind(this, this._updateClockAndDate));
|
|
|
|
this._clockSettings.connect('changed', Lang.bind(this, this._updateClockAndDate));
|
|
|
|
|
2011-08-12 10:06:19 -04:00
|
|
|
// https://bugzilla.gnome.org/show_bug.cgi?id=655129
|
|
|
|
this._upClient = new UPowerGlib.Client();
|
|
|
|
this._upClient.connect('notify-resume', Lang.bind(this, this._updateClockAndDate));
|
|
|
|
|
2011-01-28 16:35:46 -05:00
|
|
|
// Start the clock
|
|
|
|
this._updateClockAndDate();
|
|
|
|
},
|
|
|
|
|
|
|
|
_updateClockAndDate: function() {
|
|
|
|
let format = this._desktopSettings.get_string(CLOCK_FORMAT_KEY);
|
|
|
|
let showDate = this._clockSettings.get_boolean(CLOCK_SHOW_DATE_KEY);
|
|
|
|
let showSeconds = this._clockSettings.get_boolean(CLOCK_SHOW_SECONDS_KEY);
|
|
|
|
|
|
|
|
let clockFormat;
|
|
|
|
let dateFormat;
|
|
|
|
|
|
|
|
switch (format) {
|
|
|
|
case '24h':
|
|
|
|
if (showDate)
|
2011-08-12 12:48:32 -04:00
|
|
|
/* Translators: This is the time format with date used
|
2011-01-28 16:35:46 -05:00
|
|
|
in 24-hour mode. */
|
|
|
|
clockFormat = showSeconds ? _("%a %b %e, %R:%S")
|
|
|
|
: _("%a %b %e, %R");
|
|
|
|
else
|
2011-08-12 12:48:32 -04:00
|
|
|
/* Translators: This is the time format without date used
|
2011-01-28 16:35:46 -05:00
|
|
|
in 24-hour mode. */
|
|
|
|
clockFormat = showSeconds ? _("%a %R:%S")
|
|
|
|
: _("%a %R");
|
|
|
|
break;
|
|
|
|
case '12h':
|
|
|
|
default:
|
|
|
|
if (showDate)
|
2011-08-12 12:48:32 -04:00
|
|
|
/* Translators: This is a time format with date used
|
2011-01-28 16:35:46 -05:00
|
|
|
for AM/PM. */
|
|
|
|
clockFormat = showSeconds ? _("%a %b %e, %l:%M:%S %p")
|
|
|
|
: _("%a %b %e, %l:%M %p");
|
|
|
|
else
|
2011-08-12 12:48:32 -04:00
|
|
|
/* Translators: This is a time format without date used
|
2011-01-28 16:35:46 -05:00
|
|
|
for AM/PM. */
|
|
|
|
clockFormat = showSeconds ? _("%a %l:%M:%S %p")
|
|
|
|
: _("%a %l:%M %p");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
let displayDate = new Date();
|
|
|
|
|
|
|
|
this._clock.set_text(displayDate.toLocaleFormat(clockFormat));
|
|
|
|
|
|
|
|
/* Translators: This is the date format to use when the calendar popup is
|
|
|
|
* shown - it is shown just below the time in the shell (e.g. "Tue 9:29 AM").
|
|
|
|
*/
|
|
|
|
dateFormat = _("%A %B %e, %Y");
|
|
|
|
this._date.set_text(displayDate.toLocaleFormat(dateFormat));
|
|
|
|
|
2011-03-14 10:32:15 -04:00
|
|
|
Mainloop.timeout_add_seconds(1, Lang.bind(this, this._updateClockAndDate));
|
2011-01-28 16:35:46 -05:00
|
|
|
return false;
|
|
|
|
},
|
|
|
|
|
|
|
|
_onOpenCalendarActivate: function() {
|
|
|
|
this.menu.close();
|
2011-08-11 05:30:47 -04:00
|
|
|
let calendarSettings = new Gio.Settings({ schema: 'org.gnome.desktop.default-applications.office.calendar' });
|
|
|
|
let tool = calendarSettings.get_string('exec');
|
|
|
|
if (tool.length == 0 || tool == 'evolution') {
|
|
|
|
// TODO: pass the selected day
|
|
|
|
Util.spawn(['evolution', '-c', 'calendar']);
|
|
|
|
} else {
|
|
|
|
let needTerm = calendarSettings.get_boolean('needs-term');
|
|
|
|
if (needTerm) {
|
|
|
|
let terminalSettings = new Gio.Settings({ schema: 'org.gnome.desktop.default-applications.terminal' });
|
|
|
|
let term = terminalSettings.get_string('exec');
|
|
|
|
let arg = terminalSettings.get_string('exec-arg');
|
|
|
|
if (arg != '')
|
|
|
|
Util.spawn([term, arg, tool]);
|
|
|
|
else
|
|
|
|
Util.spawn([term, tool]);
|
|
|
|
} else {
|
|
|
|
Util.spawnCommandLine(tool)
|
|
|
|
}
|
|
|
|
}
|
2011-03-14 09:05:59 -04:00
|
|
|
}
|
2011-11-20 09:38:48 -05:00
|
|
|
});
|