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;
|
2011-01-28 21:35:46 +00:00
|
|
|
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;
|
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;
|
|
|
|
|
|
|
|
function _onVertSepRepaint (area)
|
|
|
|
{
|
|
|
|
let cr = area.get_context();
|
|
|
|
let themeNode = area.get_theme_node();
|
|
|
|
let [width, height] = area.get_surface_size();
|
2011-02-14 14:20:22 +00:00
|
|
|
let stippleColor = themeNode.get_color('-stipple-color');
|
2011-01-28 21:35:46 +00: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();
|
2013-01-07 20:07:40 +00:00
|
|
|
cr.$dispose();
|
2011-01-28 21:35:46 +00:00
|
|
|
};
|
|
|
|
|
2011-11-20 14:38:48 +00:00
|
|
|
const DateMenuButton = new Lang.Class({
|
|
|
|
Name: 'DateMenuButton',
|
|
|
|
Extends: PanelMenu.Button,
|
2011-01-28 21:35:46 +00:00
|
|
|
|
2012-05-17 22:32:04 +00:00
|
|
|
_init: function() {
|
2011-01-28 21:35:46 +00:00
|
|
|
let item;
|
|
|
|
let hbox;
|
|
|
|
let vbox;
|
|
|
|
|
2011-02-18 23:09:01 +00:00
|
|
|
let menuAlignment = 0.25;
|
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;
|
2011-11-20 14:38:48 +00:00
|
|
|
this.parent(menuAlignment);
|
2011-01-28 21:35:46 +00:00
|
|
|
|
2011-08-21 07:31:16 +00:00
|
|
|
this._clockDisplay = new St.Label();
|
|
|
|
this.actor.add_actor(this._clockDisplay);
|
2011-01-28 21:35:46 +00:00
|
|
|
|
2011-06-28 12:57:19 +00:00
|
|
|
hbox = new St.BoxLayout({name: 'calendarArea' });
|
2011-01-28 21:35:46 +00: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();
|
2011-08-21 07:31:16 +00:00
|
|
|
this.actor.label_actor = this._clockDisplay;
|
2011-01-28 21:35:46 +00:00
|
|
|
this._date.style_class = 'datemenu-date-label';
|
|
|
|
vbox.add(this._date);
|
|
|
|
|
2012-09-01 12:42:53 +00:00
|
|
|
this._eventList = new Calendar.EventsList();
|
|
|
|
this._calendar = new Calendar.Calendar();
|
2011-08-22 18:21:51 +00:00
|
|
|
|
2011-01-28 21:35:46 +00:00
|
|
|
this._calendar.connect('selected-date-changed',
|
|
|
|
Lang.bind(this, function(calendar, date) {
|
2011-08-22 18:21:51 +00: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 21:35:46 +00:00
|
|
|
this._eventList.setDate(date);
|
|
|
|
}));
|
|
|
|
vbox.add(this._calendar.actor);
|
|
|
|
|
2012-12-21 21:54:20 +00:00
|
|
|
let separator = new PopupMenu.PopupSeparatorMenuItem();
|
2013-06-08 16:31:30 +00:00
|
|
|
vbox.add(separator.actor, { y_align: St.Align.END, expand: true, y_fill: false });
|
2012-12-21 21:54:20 +00:00
|
|
|
|
|
|
|
this._openCalendarItem = new PopupMenu.PopupMenuItem(_("Open Calendar"));
|
|
|
|
this._openCalendarItem.connect('activate', Lang.bind(this, this._onOpenCalendarActivate));
|
|
|
|
vbox.add(this._openCalendarItem.actor, {y_align: St.Align.END, expand: true, y_fill: false});
|
|
|
|
|
2012-12-15 10:30:03 +00:00
|
|
|
this._openClocksItem = new PopupMenu.PopupMenuItem(_("Open Clocks"));
|
|
|
|
this._openClocksItem.connect('activate', Lang.bind(this, this._onOpenClocksActivate));
|
|
|
|
vbox.add(this._openClocksItem.actor, {y_align: St.Align.END, expand: true, y_fill: false});
|
|
|
|
|
|
|
|
Shell.AppSystem.get_default().connect('installed-changed',
|
|
|
|
Lang.bind(this, this._appInstalledChanged));
|
|
|
|
|
2013-02-05 13:54:16 +00:00
|
|
|
item = this.menu.addSettingsAction(_("Date & Time Settings"), 'gnome-datetime-panel.desktop');
|
2011-08-29 02:15:53 +00:00
|
|
|
if (item) {
|
2012-10-02 17:32:55 +00:00
|
|
|
item.actor.show_on_set_parent = false;
|
2011-08-29 02:15:53 +00:00
|
|
|
item.actor.reparent(vbox);
|
2012-10-02 17:32:55 +00:00
|
|
|
this._dateAndTimeSeparator = separator;
|
2011-08-29 02:15:53 +00:00
|
|
|
}
|
2011-01-28 21:35:46 +00:00
|
|
|
|
2012-09-01 12:42:53 +00:00
|
|
|
this._separator = new St.DrawingArea({ style_class: 'calendar-vertical-separator',
|
|
|
|
pseudo_class: 'highlighted' });
|
|
|
|
this._separator.connect('repaint', Lang.bind(this, _onVertSepRepaint));
|
|
|
|
hbox.add(this._separator);
|
2011-01-28 21:35:46 +00:00
|
|
|
|
2012-09-01 12:42:53 +00:00
|
|
|
// Fill up the second column
|
2013-06-08 16:31:30 +00:00
|
|
|
hbox.add(this._eventList.actor, { expand: true, y_fill: false, y_align: St.Align.START });
|
2011-01-28 21:35:46 +00: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 22:42:25 +00: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 21:35:46 +00:00
|
|
|
// No need to update this._eventList as ::selected-date-changed
|
|
|
|
// signal will fire
|
|
|
|
}
|
|
|
|
}));
|
|
|
|
|
|
|
|
// Done with hbox for calendar and event list
|
|
|
|
|
2011-08-21 07:31:16 +00:00
|
|
|
this._clock = new GnomeDesktop.WallClock();
|
|
|
|
this._clock.connect('notify::clock', Lang.bind(this, this._updateClockAndDate));
|
2011-01-28 21:35:46 +00:00
|
|
|
this._updateClockAndDate();
|
2012-09-01 12:42:53 +00:00
|
|
|
|
|
|
|
Main.sessionMode.connect('updated', Lang.bind(this, this._sessionUpdated));
|
|
|
|
this._sessionUpdated();
|
|
|
|
},
|
|
|
|
|
2012-12-15 10:30:03 +00:00
|
|
|
_appInstalledChanged: function() {
|
2013-04-10 14:29:01 +00:00
|
|
|
this._calendarApp = undefined;
|
|
|
|
this._updateEventsVisibility();
|
2012-12-15 10:30:03 +00:00
|
|
|
},
|
|
|
|
|
2012-10-29 15:37:07 +00:00
|
|
|
_updateEventsVisibility: function() {
|
|
|
|
let visible = this._eventSource.hasCalendars;
|
2013-04-10 14:29:01 +00:00
|
|
|
this._openCalendarItem.actor.visible = visible &&
|
|
|
|
(this._getCalendarApp() != null);
|
|
|
|
this._openClocksItem.actor.visible = visible &&
|
|
|
|
(this._getClockApp() != null);
|
2012-09-01 12:42:53 +00:00
|
|
|
this._separator.visible = visible;
|
2012-10-02 17:32:55 +00:00
|
|
|
if (visible) {
|
|
|
|
let alignment = 0.25;
|
|
|
|
if (Clutter.get_default_text_direction() == Clutter.TextDirection.RTL)
|
|
|
|
alignment = 1.0 - alignment;
|
|
|
|
this.menu._arrowAlignment = alignment;
|
|
|
|
this._eventList.actor.get_parent().show();
|
|
|
|
} else {
|
|
|
|
this.menu._arrowAlignment = 0.5;
|
|
|
|
this._eventList.actor.get_parent().hide();
|
|
|
|
}
|
2012-09-01 12:42:53 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
_setEventSource: function(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);
|
|
|
|
this._eventList.setEventSource(eventSource);
|
2013-03-04 16:04:28 +00:00
|
|
|
|
|
|
|
this._eventSource = eventSource;
|
2012-10-29 15:37:07 +00:00
|
|
|
this._eventSource.connect('notify::has-calendars', Lang.bind(this, function() {
|
|
|
|
this._updateEventsVisibility();
|
|
|
|
}));
|
2012-09-01 12:42:53 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
_sessionUpdated: function() {
|
|
|
|
let eventSource;
|
|
|
|
let showEvents = Main.sessionMode.showCalendarEvents;
|
|
|
|
if (showEvents) {
|
|
|
|
eventSource = new Calendar.DBusEventSource();
|
|
|
|
} else {
|
2013-03-04 16:04:28 +00:00
|
|
|
eventSource = new Calendar.EmptyEventSource();
|
2012-09-01 12:42:53 +00:00
|
|
|
}
|
|
|
|
this._setEventSource(eventSource);
|
2012-10-29 15:37:07 +00:00
|
|
|
this._updateEventsVisibility();
|
2012-10-02 17:32:55 +00:00
|
|
|
|
|
|
|
// This needs to be handled manually, as the code to
|
|
|
|
// autohide separators doesn't work across the vbox
|
|
|
|
this._dateAndTimeSeparator.actor.visible = Main.sessionMode.allowSettings;
|
2011-01-28 21:35:46 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
_updateClockAndDate: function() {
|
2011-08-21 07:31:16 +00:00
|
|
|
this._clockDisplay.set_text(this._clock.clock);
|
2012-06-26 18:00:35 +00:00
|
|
|
/* 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").
|
|
|
|
*/
|
|
|
|
let dateFormat = _("%A %B %e, %Y");
|
|
|
|
let displayDate = new Date();
|
|
|
|
this._date.set_text(displayDate.toLocaleFormat(dateFormat));
|
2011-01-28 21:35:46 +00:00
|
|
|
},
|
|
|
|
|
2013-04-10 14:29:01 +00:00
|
|
|
_getCalendarApp: function() {
|
|
|
|
if (this._calendarApp !== undefined)
|
|
|
|
return this._calendarApp;
|
|
|
|
|
|
|
|
let apps = Gio.AppInfo.get_recommended_for_type('text/calendar');
|
|
|
|
if (apps && (apps.length > 0))
|
|
|
|
this._calendarApp = apps[0];
|
|
|
|
else
|
|
|
|
this._calendarApp = null;
|
|
|
|
return this._calendarApp;
|
|
|
|
},
|
|
|
|
|
|
|
|
_getClockApp: function() {
|
|
|
|
return Shell.AppSystem.get_default().lookup_app('gnome-clocks.desktop');
|
|
|
|
},
|
|
|
|
|
2011-01-28 21:35:46 +00:00
|
|
|
_onOpenCalendarActivate: function() {
|
|
|
|
this.menu.close();
|
2012-12-25 00:29:18 +00:00
|
|
|
|
2013-04-10 14:29:01 +00:00
|
|
|
let app = this._getCalendarApp();
|
2013-04-26 06:35:22 +00:00
|
|
|
if (app.get_id() == 'evolution.desktop')
|
|
|
|
app = Gio.DesktopAppInfo.new('evolution-calendar.desktop');
|
2012-12-25 00:29:18 +00:00
|
|
|
app.launch([], global.create_app_launch_context());
|
2012-12-15 10:30:03 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
_onOpenClocksActivate: function() {
|
|
|
|
this.menu.close();
|
2013-04-10 14:29:01 +00:00
|
|
|
let app = this._getClockApp();
|
2012-12-15 10:30:03 +00:00
|
|
|
app.activate();
|
2011-03-14 13:05:59 +00:00
|
|
|
}
|
2011-11-20 14:38:48 +00:00
|
|
|
});
|