[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
This commit is contained in:
parent
62afd2ffa3
commit
e6b91414de
@ -57,6 +57,90 @@
|
||||
</locale>
|
||||
</schema>
|
||||
|
||||
<schema>
|
||||
<key>/schemas/desktop/gnome/shell/clock/format</key>
|
||||
<applyto>/desktop/gnome/shell/clock/format</applyto>
|
||||
<owner>gnome-shell</owner>
|
||||
<type>string</type>
|
||||
<default>
|
||||
<!-- Translators:
|
||||
This controls whether the GNOME panel clock should display time
|
||||
in 24 hour mode or 12 hour mode by default. The only valid values
|
||||
for this are "24-hour" and "12-hour".
|
||||
If your locale uses 24 hour time notation, translate this to
|
||||
"24-hour".
|
||||
If your locale uses 12 hour time notation with am/pm, translate
|
||||
this to "12-hour".
|
||||
|
||||
Do NOT translate this into anything else than "24-hour" or
|
||||
"12-hour". For example, if you translate this to "24 sata" or
|
||||
anything else that isn't "24-hour" or "12-hour", things will
|
||||
not work.
|
||||
-->
|
||||
24-hour
|
||||
</default>
|
||||
<locale name="C">
|
||||
<short>Hour format</short>
|
||||
<long>
|
||||
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.
|
||||
</long>
|
||||
</locale>
|
||||
</schema>
|
||||
|
||||
<schema>
|
||||
<key>/schemas/desktop/gnome/shell/clock/custom_format</key>
|
||||
<applyto>/desktop/gnome/shell/clock/custom_format</applyto>
|
||||
<owner>gnome-shell</owner>
|
||||
<type>string</type>
|
||||
<default></default>
|
||||
<locale name="C">
|
||||
<short>Custom format of the clock</short>
|
||||
<long>
|
||||
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.
|
||||
</long>
|
||||
</locale>
|
||||
</schema>
|
||||
|
||||
<schema>
|
||||
<key>/schemas/desktop/gnome/shell/clock/show_seconds</key>
|
||||
<applyto>/desktop/gnome/shell/clock/show_seconds</applyto>
|
||||
<owner>gnome-shell</owner>
|
||||
<type>bool</type>
|
||||
<default>false</default>
|
||||
<locale name="C">
|
||||
<short>Show time with seconds</short>
|
||||
<long>
|
||||
If true and format is either "12-hour" or "24-hour",
|
||||
display seconds in time.
|
||||
</long>
|
||||
</locale>
|
||||
</schema>
|
||||
|
||||
<schema>
|
||||
<key>/schemas/desktop/gnome/shell/clock/show_date</key>
|
||||
<applyto>/desktop/gnome/shell/clock/show_date</applyto>
|
||||
<owner>gnome-shell</owner>
|
||||
<type>bool</type>
|
||||
<default>false</default>
|
||||
<locale name="C">
|
||||
<short>Show date in clock</short>
|
||||
<long>
|
||||
If true and format is either "12-hour" or "24-hour",
|
||||
display date in the clock, in addition to time.
|
||||
</long>
|
||||
</locale>
|
||||
</schema>
|
||||
|
||||
<schema>
|
||||
<key>/schemas/desktop/gnome/shell/disabled_extensions</key>
|
||||
<applyto>/desktop/gnome/shell/disabled_extensions</applyto>
|
||||
|
@ -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;
|
||||
},
|
||||
|
Loading…
Reference in New Issue
Block a user