2011-01-28 16:35:46 -05:00
|
|
|
/* -*- mode: js2; js2-basic-offset: 4; indent-tabs-mode: nil -*- */
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
// 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();
|
|
|
|
};
|
|
|
|
|
|
|
|
function DateMenuButton() {
|
|
|
|
this._init();
|
|
|
|
}
|
|
|
|
|
|
|
|
DateMenuButton.prototype = {
|
|
|
|
__proto__: PanelMenu.Button.prototype,
|
|
|
|
|
|
|
|
_init: function() {
|
|
|
|
let item;
|
|
|
|
let hbox;
|
|
|
|
let vbox;
|
|
|
|
|
2011-02-25 17:42:25 -05:00
|
|
|
this._eventSource = new Calendar.DBusEventSource();
|
2011-01-28 16:35:46 -05:00
|
|
|
|
2011-02-18 18:09:01 -05:00
|
|
|
let menuAlignment = 0.25;
|
|
|
|
if (St.Widget.get_default_direction() == St.TextDirection.RTL)
|
|
|
|
menuAlignment = 1.0 - menuAlignment;
|
|
|
|
PanelMenu.Button.prototype._init.call(this, menuAlignment);
|
2011-01-28 16:35:46 -05:00
|
|
|
|
|
|
|
this._clock = new St.Label();
|
|
|
|
this.actor.set_child(this._clock);
|
|
|
|
|
|
|
|
hbox = new St.BoxLayout({name: 'calendarArea'});
|
|
|
|
this.menu.addActor(hbox);
|
|
|
|
|
|
|
|
// Fill up the first column
|
|
|
|
|
|
|
|
vbox = new St.BoxLayout({vertical: true});
|
|
|
|
hbox.add(vbox);
|
|
|
|
|
|
|
|
// Date
|
|
|
|
this._date = new St.Label();
|
|
|
|
this._date.style_class = 'datemenu-date-label';
|
|
|
|
vbox.add(this._date);
|
|
|
|
|
|
|
|
this._eventList = new Calendar.EventsList(this._eventSource);
|
|
|
|
|
|
|
|
// Calendar
|
|
|
|
this._calendar = new Calendar.Calendar(this._eventSource);
|
|
|
|
this._calendar.connect('selected-date-changed',
|
|
|
|
Lang.bind(this, function(calendar, date) {
|
|
|
|
this._eventList.setDate(date);
|
|
|
|
}));
|
|
|
|
vbox.add(this._calendar.actor);
|
|
|
|
|
|
|
|
item = new PopupMenu.PopupSeparatorMenuItem();
|
|
|
|
item.setColumnWidths(1);
|
|
|
|
vbox.add(item.actor, {y_align: St.Align.END, expand: true, y_fill: false});
|
|
|
|
item = new PopupMenu.PopupMenuItem(_("Date and Time Settings"));
|
|
|
|
item.connect('activate', Lang.bind(this, this._onPreferencesActivate));
|
2011-02-15 17:10:35 -05:00
|
|
|
item.actor.can_focus = false;
|
2011-01-28 16:35:46 -05:00
|
|
|
vbox.add(item.actor);
|
|
|
|
|
|
|
|
// Add vertical separator
|
|
|
|
|
|
|
|
item = new St.DrawingArea({ style_class: 'calendar-vertical-separator',
|
|
|
|
pseudo_class: 'highlighted' });
|
|
|
|
item.connect('repaint', Lang.bind(this, _onVertSepRepaint));
|
|
|
|
hbox.add(item);
|
|
|
|
|
|
|
|
// Fill up the second column
|
|
|
|
|
|
|
|
vbox = new St.BoxLayout({vertical: true});
|
2011-02-23 08:34:37 -05:00
|
|
|
hbox.add(vbox, { expand: true });
|
2011-01-28 16:35:46 -05:00
|
|
|
|
|
|
|
// Event list
|
2011-02-23 08:34:37 -05:00
|
|
|
vbox.add(this._eventList.actor, { expand: true });
|
2011-01-28 16:35:46 -05:00
|
|
|
|
|
|
|
item = new PopupMenu.PopupMenuItem(_("Open Calendar"));
|
|
|
|
item.connect('activate', Lang.bind(this, this._onOpenCalendarActivate));
|
2011-02-15 17:10:35 -05:00
|
|
|
item.actor.can_focus = false;
|
2011-01-28 16:35:46 -05:00
|
|
|
vbox.add(item.actor, {y_align: St.Align.END, expand: true, y_fill: false});
|
|
|
|
|
|
|
|
// 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));
|
|
|
|
|
|
|
|
// 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)
|
|
|
|
/* Translators: This is the time format with date used
|
|
|
|
in 24-hour mode. */
|
|
|
|
clockFormat = showSeconds ? _("%a %b %e, %R:%S")
|
|
|
|
: _("%a %b %e, %R");
|
|
|
|
else
|
|
|
|
/* Translators: This is the time format without date used
|
|
|
|
in 24-hour mode. */
|
|
|
|
clockFormat = showSeconds ? _("%a %R:%S")
|
|
|
|
: _("%a %R");
|
|
|
|
break;
|
|
|
|
case '12h':
|
|
|
|
default:
|
|
|
|
if (showDate)
|
|
|
|
/* Translators: This is a time format with date used
|
|
|
|
for AM/PM. */
|
|
|
|
clockFormat = showSeconds ? _("%a %b %e, %l:%M:%S %p")
|
|
|
|
: _("%a %b %e, %l:%M %p");
|
|
|
|
else
|
|
|
|
/* Translators: This is a time format without date used
|
|
|
|
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;
|
|
|
|
},
|
|
|
|
|
|
|
|
_onPreferencesActivate: function() {
|
|
|
|
this.menu.close();
|
2011-06-21 18:26:57 -04:00
|
|
|
Main.overview.hide();
|
Kill off ShellAppInfo, move into ShellApp
This dramatically thins down and sanitizes the application code.
The ShellAppSystem changes in a number of ways:
* Preferences are special cased more explicitly; they aren't apps,
they're shortcuts for an app), and we don't have many of them, so
don't need e.g. the optimizations in ShellAppSystem for searching.
* get_app() changes to lookup_app() and returns null if an app isn't
found. The semantics where it tried to find the .desktop file
if we didn't know about it were just broken; I am pretty sure no
caller needs this, and if they do we'll fix them.
* ShellAppSystem maintains two indexes on apps (by desktop file id
and by GMenuTreeEntry), but is no longer in the business of
dealing with GMenuTree as far as hierarchy and categories go. That
is moved up into js/ui/appDisplay.js. Actually, it flattens both
apps and settings.
Also, ShellWindowTracker is now the sole reference-owner for
window-backed apps. We still do the weird "window:0x1234beef" id
for these apps, but a reference is not stored in ShellAppSystem.
The js/ui/appDisplay.js code is rewritten, and sucks a lot less.
Variable names are clearer:
_apps -> _appIcons
_filterApp -> _visibleApps
_filters -> _categoryBox
Similarly for function names. We no longer call (for every app) a
recursive lookup in GMenuTree to see if it's in a particular section
on every category switch; it's all cached.
NOTE - this intentionally reverts the incremental loading code from
commit 7813c5b93f6bcde8c4beae286e82bfc472b2b656. It's fast enough
here without that.
https://bugzilla.gnome.org/show_bug.cgi?id=648149
2011-04-21 13:35:01 -04:00
|
|
|
let app = Shell.AppSystem.get_default().lookup_setting('gnome-datetime-panel.desktop');
|
2011-08-11 05:35:23 -04:00
|
|
|
app.activate();
|
2011-01-28 16:35:46 -05:00
|
|
|
},
|
|
|
|
|
|
|
|
_onOpenCalendarActivate: function() {
|
|
|
|
this.menu.close();
|
|
|
|
// TODO: pass the selected day
|
2011-03-14 09:05:59 -04:00
|
|
|
Util.spawn(['evolution', '-c', 'calendar']);
|
|
|
|
}
|
2011-01-28 16:35:46 -05:00
|
|
|
};
|