Skip to content

Commit

Permalink
Configurable date formats
Browse files Browse the repository at this point in the history
  • Loading branch information
clefebvre committed Jan 10, 2012
1 parent 95830ab commit 17d7a78
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 97 deletions.
35 changes: 16 additions & 19 deletions data/org.cinnamon.gschema.xml
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,8 @@
<default>0</default>
<summary/>
</key>
<child schema="org.cinnamon.clock" name="clock"/>
<child schema="org.cinnamon.theme" name="theme"/>
<child schema="org.cinnamon.calendar" name="calendar"/>
<child schema="org.cinnamon.theme" name="theme"/>
<child schema="org.cinnamon.recorder" name="recorder"/>
<child schema="org.cinnamon.keyboard" name="keyboard"/>
</schema>
Expand All @@ -86,14 +85,6 @@
</key>
</schema>

<schema path="/org/cinnamon/calendar/" id="org.cinnamon.calendar" gettext-domain="@GETTEXT_PACKAGE@">
<key type="b" name="show-weekdate">
<default>false</default>
<summary>Show the week date in the calendar</summary>
<description>If true, display the ISO week date in the calendar.</description>
</key>
</schema>

<schema path="/org/cinnamon/keyboard/" id="org.cinnamon.keyboard" gettext-domain="@GETTEXT_PACKAGE@">
<key type="s" name="keyboard-type">
<default>'touch'</default>
Expand All @@ -102,16 +93,22 @@
</key>
</schema>

<schema path="/org/cinnamon/clock/" id="org.cinnamon.clock" gettext-domain="@GETTEXT_PACKAGE@">
<key type="b" name="show-seconds">
<default>false</default>
<summary>Show time with seconds</summary>
<description>If true, display seconds in time.</description>
<schema path="/org/cinnamon/calendar/" id="org.cinnamon.calendar" gettext-domain="@GETTEXT_PACKAGE@">

<key name="date-format" type="s">
<default>'%a %b %e, %H:%M'</default>
<summary>Format for the date in the panel</summary>
<description>Format used to show the date in the panel.</description>
</key>
<key type="b" name="show-date">
<default>true</default>
<summary>Show date in clock</summary>
<description>If true, display date in the clock, in addition to time.</description>
<key name="date-format-full" type="s">
<default>'%A %B %e, %Y'</default>
<summary>Format for the date in the applet menu</summary>
<description>Format used to show the date in the applet menu.</description>
</key>
<key name="show-weekdate" type="b">
<default>false</default>
<summary>Show the week date in the calendar</summary>
<description>If true, display the ISO week date in the calendar.</description>
</key>
</schema>

Expand Down
51 changes: 29 additions & 22 deletions data/org.cinnamon.gschema.xml.in
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,14 @@
</_description>
</key>

<key name="date-format" type="s">
<default>"YYYY-MM-DD"</default>
<_summary>Auto-hide panel</_summary>
<_description>
Whether the panel autohides or not.
</_description>
</key>

<key type="s" name="menu-text">
<default>"Menu"</default>
<_summary>Text for the menu</_summary>
Expand Down Expand Up @@ -99,9 +107,8 @@
<default>0</default>
<_summary></_summary>
</key>
<child name="clock" schema="org.cinnamon.clock"/>
<child name="theme" schema="org.cinnamon.theme"/>
<child name="calendar" schema="org.cinnamon.calendar"/>
<child name="theme" schema="org.cinnamon.theme"/>
<child name="recorder" schema="org.cinnamon.recorder"/>
<child name="keyboard" schema="org.cinnamon.keyboard"/>
</schema>
Expand All @@ -116,18 +123,7 @@
</_description>
</key>
</schema>

<schema id="org.cinnamon.calendar" path="/org/cinnamon/calendar/"
gettext-domain="@GETTEXT_PACKAGE@">
<key name="show-weekdate" type="b">
<default>false</default>
<_summary>Show the week date in the calendar</_summary>
<_description>
If true, display the ISO week date in the calendar.
</_description>
</key>
</schema>


<schema id="org.cinnamon.keyboard" path="/org/cinnamon/keyboard/"
gettext-domain="@GETTEXT_PACKAGE@">
<key name="keyboard-type" type="s">
Expand All @@ -139,22 +135,33 @@
</key>
</schema>

<schema id="org.cinnamon.clock" path="/org/cinnamon/clock/"
<schema id="org.cinnamon.calendar" path="/org/cinnamon/calendar/"
gettext-domain="@GETTEXT_PACKAGE@">
<key name="show-seconds" type="b">

<key name="show-weekdate" type="b">
<default>false</default>
<_summary>Show time with seconds</_summary>
<_summary>Show the week date in the calendar</_summary>
<_description>
If true, display seconds in time.
If true, display the ISO week date in the calendar.
</_description>
</key>
<key name="show-date" type="b">
<default>true</default>
<_summary>Show date in clock</_summary>

<key name="date-format" type="s">
<default>'%a %b %e, %H:%M'</default>
<_summary>Format for the date in the panel</_summary>
<_description>
If true, display date in the clock, in addition to time.
Format used to show the date in the panel.
</_description>
</key>

<key name="date-format-full" type="s">
<default>'%A %B %e, %Y'</default>
<_summary>Format for the date in the applet menu</_summary>
<_description>
Format used to show the date in the applet menu.
</_description>
</key>

</schema>

<schema id="org.cinnamon.recorder" path="/org/cinnamon/recorder/"
Expand Down
62 changes: 7 additions & 55 deletions js/ui/dateMenu.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,6 @@ const PopupMenu = imports.ui.popupMenu;
const Calendar = imports.ui.calendar;
const UPowerGlib = imports.gi.UPowerGlib;

// in org.gnome.desktop.interface
const CLOCK_FORMAT_KEY = 'clock-format';

// in org.cinnamon.clock
const CLOCK_SHOW_DATE_KEY = 'show-date';
const CLOCK_SHOW_SECONDS_KEY = 'show-seconds';

function _onVertSepRepaint (area)
{
let cr = area.get_context();
Expand Down Expand Up @@ -117,11 +110,9 @@ DateMenuButton.prototype = {

// 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.cinnamon.clock' });
this._desktopSettings.connect('changed', Lang.bind(this, this._updateClockAndDate));
this._clockSettings.connect('changed', Lang.bind(this, this._updateClockAndDate));
// Track changes to clock settings
this._calendarSettings = new Gio.Settings({ schema: 'org.cinnamon.calendar' });
this._calendarSettings.connect('changed', Lang.bind(this, this._updateClockAndDate));

// https://bugzilla.gnome.org/show_bug.cgi?id=655129
this._upClient = new UPowerGlib.Client();
Expand All @@ -132,50 +123,11 @@ DateMenuButton.prototype = {
},

_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 dateFormat = this._calendarSettings.get_string('date-format');
let dateFormatFull = this._calendarSettings.get_string('date-format-full');
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 Cinnamon (e.g. "Tue 9:29 AM").
*/
dateFormat = _("%A %B %e, %Y");
this._date.set_text(displayDate.toLocaleFormat(dateFormat));
this._clock.set_text(displayDate.toLocaleFormat(dateFormat));
this._date.set_text(displayDate.toLocaleFormat(dateFormatFull));

Mainloop.timeout_add_seconds(1, Lang.bind(this, this._updateClockAndDate));
return false;
Expand Down
2 changes: 1 addition & 1 deletion js/ui/panel.js
Original file line number Diff line number Diff line change
Expand Up @@ -550,7 +550,7 @@ Panel.prototype = {
if (button==1) {
if (this._context_menu.isOpen) this._context_menu.toggle();
}else if (button==3) {
this._context_menu.toggle();
this._context_menu.toggle();
}
},

Expand Down

0 comments on commit 17d7a78

Please sign in to comment.