[gnome-initial-setup/shell/4765: 332/362] location: Get time format from nl_langinfo
- From: Jasper St. Pierre <jstpierre src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-initial-setup/shell/4765: 332/362] location: Get time format from nl_langinfo
- Date: Thu, 19 Mar 2015 01:48:59 +0000 (UTC)
commit a07e4d628b790a88cbf07ac30799c0ca29e60a8f
Author: Dan Nicholson <nicholson endlessm com>
Date: Thu Feb 5 12:20:22 2015 -0800
location: Get time format from nl_langinfo
Instead of taking this from a hardcoded default in the personality file,
query the current locale's T_FMT from nl_langinfo and parse out the
formats that use 12 hour format.
[endlessm/eos-shell#4558]
.../pages/location/gis-location-page.c | 25 +++++++++++++++++--
1 files changed, 22 insertions(+), 3 deletions(-)
---
diff --git a/gnome-initial-setup/pages/location/gis-location-page.c
b/gnome-initial-setup/pages/location/gis-location-page.c
index 7f85b72..616f452 100644
--- a/gnome-initial-setup/pages/location/gis-location-page.c
+++ b/gnome-initial-setup/pages/location/gis-location-page.c
@@ -36,6 +36,7 @@
#include <stdlib.h>
#include <string.h>
+#include <langinfo.h>
#define GWEATHER_I_KNOW_THIS_IS_UNSTABLE
#include <libgweather/location-entry.h>
@@ -289,15 +290,33 @@ update_ntp_switch_from_system (GisLocationPage *page)
g_signal_handlers_unblock_by_func (switch_widget, change_ntp, page);
}
+static const char *
+get_time_format (void)
+{
+ gchar *nl_fmt;
+
+ /* Default to 24 hour if we can't get the format from the locale */
+ nl_fmt = nl_langinfo (T_FMT);
+ if (nl_fmt == NULL || *nl_fmt == '\0')
+ return "24h";
+
+ /* Parse out any formats that use 12h format. See stftime(3). */
+ if (g_str_has_prefix (nl_fmt, "%I") ||
+ g_str_has_prefix (nl_fmt, "%l") ||
+ g_str_has_prefix (nl_fmt, "%r"))
+ return "12h";
+ else
+ return "24h";
+}
+
static void
update_time (GisLocationPage *page)
{
GisLocationPagePrivate *priv = gis_location_page_get_instance_private (page);
- GisDriver *driver = GIS_PAGE (page)->driver;
const gchar *time_format;
char *label;
- time_format = gis_driver_get_default_time_format (driver);
+ time_format = get_time_format ();
if (!time_format || time_format[0] == '2') {
/* Update the hours label in 24h format */
@@ -745,7 +764,7 @@ gis_location_page_constructed (GObject *object)
update_time (page);
clock_settings = g_settings_new ("org.gnome.desktop.interface");
- clock_format = gis_driver_get_default_time_format (GIS_PAGE (page)->driver);
+ clock_format = get_time_format ();
g_settings_set_string (clock_settings, "clock-format", clock_format? clock_format: "24h");
g_object_unref (clock_settings);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]