calendar: Improve week start handling
Add a helper function (mostly copied from gtkcalendar.c) for getting the first week day for the current locale, using nl_langinfo if available and falling back to the GTK+ gettext fallback otherwise. Use that function in the calendar, so that the LC_TIME setting is used if possible. https://bugzilla.gnome.org/show_bug.cgi?id=649078
This commit is contained in:
parent
6c97e2a5ab
commit
7ed3facf8f
11
configure.ac
11
configure.ac
@ -156,6 +156,17 @@ AC_CHECK_FUNCS(fdwalk)
|
|||||||
AC_CHECK_FUNCS(mallinfo)
|
AC_CHECK_FUNCS(mallinfo)
|
||||||
AC_CHECK_HEADERS([sys/resource.h])
|
AC_CHECK_HEADERS([sys/resource.h])
|
||||||
|
|
||||||
|
# _NL_TIME_FIRST_WEEKDAY is an enum and not a define
|
||||||
|
AC_MSG_CHECKING([for _NL_TIME_FIRST_WEEKDAY])
|
||||||
|
AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include <langinfo.h>]],
|
||||||
|
[[nl_langinfo(_NL_TIME_FIRST_WEEKDAY);]])],
|
||||||
|
[langinfo_ok=yes], [langinfo_ok=no])
|
||||||
|
AC_MSG_RESULT($langinfo_ok)
|
||||||
|
if test "$langinfo_ok" = "yes"; then
|
||||||
|
AC_DEFINE([HAVE__NL_TIME_FIRST_WEEKDAY], [1],
|
||||||
|
[Define if _NL_TIME_FIRST_WEEKDAY is available])
|
||||||
|
fi
|
||||||
|
|
||||||
# Sets GLIB_GENMARSHAL and GLIB_MKENUMS
|
# Sets GLIB_GENMARSHAL and GLIB_MKENUMS
|
||||||
AM_PATH_GLIB_2_0()
|
AM_PATH_GLIB_2_0()
|
||||||
G_IR_SCANNER=`$PKG_CONFIG --variable=g_ir_scanner gobject-introspection-1.0`
|
G_IR_SCANNER=`$PKG_CONFIG --variable=g_ir_scanner gobject-introspection-1.0`
|
||||||
|
@ -358,10 +358,7 @@ Calendar.prototype = {
|
|||||||
this._update(false);
|
this._update(false);
|
||||||
}));
|
}));
|
||||||
|
|
||||||
// FIXME: This is actually the fallback method for GTK+ for the week start;
|
this._weekStart = Shell.util_get_week_start();
|
||||||
// GTK+ by preference uses nl_langinfo (NL_TIME_FIRST_WEEKDAY). We probably
|
|
||||||
// should add a C function so we can do the full handling.
|
|
||||||
this._weekStart = NaN;
|
|
||||||
this._weekdate = NaN;
|
this._weekdate = NaN;
|
||||||
this._digitWidth = NaN;
|
this._digitWidth = NaN;
|
||||||
this._settings = new Gio.Settings({ schema: 'org.gnome.shell.calendar' });
|
this._settings = new Gio.Settings({ schema: 'org.gnome.shell.calendar' });
|
||||||
@ -369,16 +366,6 @@ Calendar.prototype = {
|
|||||||
this._settings.connect('changed::' + SHOW_WEEKDATE_KEY, Lang.bind(this, this._onSettingsChange));
|
this._settings.connect('changed::' + SHOW_WEEKDATE_KEY, Lang.bind(this, this._onSettingsChange));
|
||||||
this._useWeekdate = this._settings.get_boolean(SHOW_WEEKDATE_KEY);
|
this._useWeekdate = this._settings.get_boolean(SHOW_WEEKDATE_KEY);
|
||||||
|
|
||||||
let weekStartString = Gettext_gtk30.gettext('calendar:week_start:0');
|
|
||||||
if (weekStartString.indexOf('calendar:week_start:') == 0) {
|
|
||||||
this._weekStart = parseInt(weekStartString.substring(20));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (isNaN(this._weekStart) || this._weekStart < 0 || this._weekStart > 6) {
|
|
||||||
log('Translation of "calendar:week_start:0" in GTK+ is not correct');
|
|
||||||
this._weekStart = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Find the ordering for month/year in the calendar heading
|
// Find the ordering for month/year in the calendar heading
|
||||||
this._headerFormatWithoutYear = '%B';
|
this._headerFormatWithoutYear = '%B';
|
||||||
switch (Gettext_gtk30.gettext('calendar:MY')) {
|
switch (Gettext_gtk30.gettext('calendar:MY')) {
|
||||||
@ -638,17 +625,7 @@ EventsList.prototype = {
|
|||||||
this._eventSource.connect('changed', Lang.bind(this, this._update));
|
this._eventSource.connect('changed', Lang.bind(this, this._update));
|
||||||
this._desktopSettings = new Gio.Settings({ schema: 'org.gnome.desktop.interface' });
|
this._desktopSettings = new Gio.Settings({ schema: 'org.gnome.desktop.interface' });
|
||||||
this._desktopSettings.connect('changed', Lang.bind(this, this._update));
|
this._desktopSettings.connect('changed', Lang.bind(this, this._update));
|
||||||
let weekStartString = Gettext_gtk30.gettext('calendar:week_start:0');
|
this._weekStart = Shell.util_get_week_start();
|
||||||
if (weekStartString.indexOf('calendar:week_start:') == 0) {
|
|
||||||
this._weekStart = parseInt(weekStartString.substring(20));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (isNaN(this._weekStart) ||
|
|
||||||
this._weekStart < 0 ||
|
|
||||||
this._weekStart > 6) {
|
|
||||||
log('Translation of "calendar:week_start:0" in GTK+ is not correct');
|
|
||||||
this._weekStart = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
this._update();
|
this._update();
|
||||||
},
|
},
|
||||||
|
@ -6,6 +6,10 @@
|
|||||||
#include <glib/gi18n-lib.h>
|
#include <glib/gi18n-lib.h>
|
||||||
#include <gtk/gtk.h>
|
#include <gtk/gtk.h>
|
||||||
|
|
||||||
|
#ifdef HAVE__NL_TIME_FIRST_WEEKDAY
|
||||||
|
#include <langinfo.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
#include <libxml/parser.h>
|
#include <libxml/parser.h>
|
||||||
#include <libxml/tree.h>
|
#include <libxml/tree.h>
|
||||||
#include <libxml/xmlmemory.h>
|
#include <libxml/xmlmemory.h>
|
||||||
@ -541,6 +545,62 @@ shell_util_format_date (const char *format,
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* shell_util_get_week_start:
|
||||||
|
*
|
||||||
|
* Gets the first week day for the current locale, expressed as a
|
||||||
|
* number in the range 0..6, representing week days from Sunday to
|
||||||
|
* Saturday.
|
||||||
|
*
|
||||||
|
* Returns: A number representing the first week day for the current
|
||||||
|
* locale
|
||||||
|
*/
|
||||||
|
/* Copied from gtkcalendar.c */
|
||||||
|
int
|
||||||
|
shell_util_get_week_start ()
|
||||||
|
{
|
||||||
|
int week_start;
|
||||||
|
#ifdef HAVE__NL_TIME_FIRST_WEEKDAY
|
||||||
|
union { unsigned int word; char *string; } langinfo;
|
||||||
|
int week_1stday = 0;
|
||||||
|
int first_weekday = 1;
|
||||||
|
guint week_origin;
|
||||||
|
#else
|
||||||
|
char *gtk_week_start;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef HAVE__NL_TIME_FIRST_WEEKDAY
|
||||||
|
langinfo.string = nl_langinfo (_NL_TIME_FIRST_WEEKDAY);
|
||||||
|
first_weekday = langinfo.string[0];
|
||||||
|
langinfo.string = nl_langinfo (_NL_TIME_WEEK_1STDAY);
|
||||||
|
week_origin = langinfo.word;
|
||||||
|
if (week_origin == 19971130) /* Sunday */
|
||||||
|
week_1stday = 0;
|
||||||
|
else if (week_origin == 19971201) /* Monday */
|
||||||
|
week_1stday = 1;
|
||||||
|
else
|
||||||
|
g_warning ("Unknown value of _NL_TIME_WEEK_1STDAY.\n");
|
||||||
|
|
||||||
|
week_start = (week_1stday + first_weekday - 1) % 7;
|
||||||
|
#else
|
||||||
|
gtk_week_start = dgettext ("gtk30", "calendar:week_start:0");
|
||||||
|
|
||||||
|
if (strncmp (gtk_week_start, "calendar:week_start:", 20) == 0)
|
||||||
|
week_start = *(gtk_week_start + 20) - '0';
|
||||||
|
else
|
||||||
|
week_start = -1;
|
||||||
|
|
||||||
|
if (week_start < 0 || week_start > 6)
|
||||||
|
{
|
||||||
|
g_warning ("Whoever translated calendar:week_start:0 for GTK+ "
|
||||||
|
"did so wrongly.\n");
|
||||||
|
week_start = 0;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
return week_start;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* shell_get_event_state:
|
* shell_get_event_state:
|
||||||
* @event: a #ClutterEvent
|
* @event: a #ClutterEvent
|
||||||
|
@ -20,6 +20,7 @@ void shell_util_set_hidden_from_pick (ClutterActor *actor,
|
|||||||
void shell_util_get_transformed_allocation (ClutterActor *actor,
|
void shell_util_get_transformed_allocation (ClutterActor *actor,
|
||||||
ClutterActorBox *box);
|
ClutterActorBox *box);
|
||||||
|
|
||||||
|
int shell_util_get_week_start (void);
|
||||||
char *shell_util_format_date (const char *format,
|
char *shell_util_format_date (const char *format,
|
||||||
gint64 time_ms);
|
gint64 time_ms);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user