From e6b91414de749f35a56171538357bf9e9af13849 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Florian=20M=C3=BCllner?= Date: Thu, 25 Feb 2010 20:30:23 +0100 Subject: [PATCH] [panel] Make clock configurable via gconf Add keys for customizing the panel clock to the gconf schema and make the clock use them. The settings are copied from gnome-panel's clock applet, excluding all location/weather/appointment/... keys. In addition, 'internet' is no longer a supported value for the format key. https://bugzilla.gnome.org/show_bug.cgi?id=600276 --- data/gnome-shell.schemas | 84 +++++++++++++++++++++++++++++++++++++++ js/ui/panel.js | 85 +++++++++++++++++++++++++++++++--------- 2 files changed, 150 insertions(+), 19 deletions(-) diff --git a/data/gnome-shell.schemas b/data/gnome-shell.schemas index 0f0132515..b2de7038a 100644 --- a/data/gnome-shell.schemas +++ b/data/gnome-shell.schemas @@ -57,6 +57,90 @@ + + /schemas/desktop/gnome/shell/clock/format + /desktop/gnome/shell/clock/format + gnome-shell + string + + + 24-hour + + + Hour format + + This key specifies the hour format used by the panel clock. + Possible values are "12-hour", "24-hour", "unix" and "custom". + If set to "unix", the clock will display time in seconds since Epoch, + i.e. 1970-01-01. + If set to "custom", the clock will display time according to the format + specified in the custom_format key. + Note that if set to either "unix" or "custom", the show_date and + show_seconds keys are ignored. + + + + + + /schemas/desktop/gnome/shell/clock/custom_format + /desktop/gnome/shell/clock/custom_format + gnome-shell + string + + + Custom format of the clock + + This key specifies the format used by the panel clock when the + format key is set to "custom". You can use conversion specifiers + understood by strftime() to obtain a specific format. See the + strftime() manual for more information. + + + + + + /schemas/desktop/gnome/shell/clock/show_seconds + /desktop/gnome/shell/clock/show_seconds + gnome-shell + bool + false + + Show time with seconds + + If true and format is either "12-hour" or "24-hour", + display seconds in time. + + + + + + /schemas/desktop/gnome/shell/clock/show_date + /desktop/gnome/shell/clock/show_date + gnome-shell + bool + false + + Show date in clock + + If true and format is either "12-hour" or "24-hour", + display date in the clock, in addition to time. + + + + /schemas/desktop/gnome/shell/disabled_extensions /desktop/gnome/shell/disabled_extensions diff --git a/js/ui/panel.js b/js/ui/panel.js index f002139e7..34f5696e4 100644 --- a/js/ui/panel.js +++ b/js/ui/panel.js @@ -33,6 +33,11 @@ const STANDARD_TRAY_ICON_IMPLEMENTATIONS = { 'gnome-power-manager': 'battery' }; +const CLOCK_FORMAT_KEY = 'clock/format'; +const CLOCK_CUSTOM_FORMAT_KEY = 'clock/custom_format'; +const CLOCK_SHOW_DATE_KEY = 'clock/show_date'; +const CLOCK_SHOW_SECONDS_KEY = 'clock/show_seconds'; + function TextShadower() { this._init(); } @@ -478,6 +483,9 @@ Panel.prototype = { Main.chrome.addActor(this.actor, { visibleInOverview: true }); + let gconf = Shell.GConf.get_default(); + gconf.connect('changed', Lang.bind(this, this._updateClock)); + // Start the clock this._updateClock(); }, @@ -544,29 +552,68 @@ Panel.prototype = { }, _updateClock: function() { - let displayDate = new Date(); - let msecRemaining = 60000 - (1000 * displayDate.getSeconds() + - displayDate.getMilliseconds()); - if (msecRemaining < 500) { - displayDate.setMinutes(displayDate.getMinutes() + 1); - msecRemaining += 60000; + let gconf = Shell.GConf.get_default(); + let format = gconf.get_string(CLOCK_FORMAT_KEY); + let showDate = gconf.get_boolean(CLOCK_SHOW_DATE_KEY); + let showSeconds = gconf.get_boolean(CLOCK_SHOW_SECONDS_KEY); + + let clockFormat; + switch (format) { + case 'unix': + // force updates every second + showSeconds = true; + clockFormat = "%s"; + break; + case 'custom': + // force updates every second + showSeconds = true; + clockFormat = gconf.get_string(CLOCK_CUSTOM_FORMAT_KEY); + break; + case '24-hour': + 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 '12-hour': + 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; } - // if the locale representations of 05:00 and 17:00 do not - // start with the same 2 digits, it must be a 24h clock - let fiveAm = new Date(); - fiveAm.setHours(5); - let fivePm = new Date(); - fivePm.setHours(17); - let isTime24h = fiveAm.toLocaleFormat("%X").substr(0,2) != - fivePm.toLocaleFormat("%X").substr(0,2); - if (isTime24h) { - /* Translators: This is the time format used in 24-hour mode. */ - this._clock.set_text(displayDate.toLocaleFormat(_("%a %R"))); + let displayDate = new Date(); + let msecRemaining; + if (showSeconds) { + msecRemaining = 1000 - displayDate.getMilliseconds(); + if (msecRemaining < 50) { + displayDate.setSeconds(displayDate.getSeconds() + 1); + msecRemaining += 1000; + } } else { - /* Translators: This is a time format used for AM/PM. */ - this._clock.set_text(displayDate.toLocaleFormat(_("%a %l:%M %p"))); + msecRemaining = 60000 - (1000 * displayDate.getSeconds() + + displayDate.getMilliseconds()); + if (msecRemaining < 500) { + displayDate.setMinutes(displayDate.getMinutes() + 1); + msecRemaining += 60000; + } } + + this._clock.set_text(displayDate.toLocaleFormat(clockFormat)); Mainloop.timeout_add(msecRemaining, Lang.bind(this, this._updateClock)); return false; },