[gnome-initial-setup/shell/4765: 105/362] Set time format based on personality
- From: Jasper St. Pierre <jstpierre src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-initial-setup/shell/4765: 105/362] Set time format based on personality
- Date: Thu, 19 Mar 2015 01:29:53 +0000 (UTC)
commit 15d529af8b727c2666e5b1e9c18a55a2eba59836
Author: Juan A. Suarez Romero <jasuarez igalia com>
Date: Mon Jul 21 11:52:16 2014 +0200
Set time format based on personality
Read personality file to find out if the time format should be 24h
(default) or 12h (aka AM/PM).
[endlessm/eos-shell#3133]
gnome-initial-setup/gis-driver.c | 14 +++
gnome-initial-setup/gis-driver.h | 2 +
.../pages/location/gis-location-page.c | 21 +++-
.../pages/location/gis-location-page.ui | 114 ++++++++++++--------
4 files changed, 103 insertions(+), 48 deletions(-)
---
diff --git a/gnome-initial-setup/gis-driver.c b/gnome-initial-setup/gis-driver.c
index 9aed9b2..6af03f7 100644
--- a/gnome-initial-setup/gis-driver.c
+++ b/gnome-initial-setup/gis-driver.c
@@ -36,6 +36,7 @@
#define INITIAL_CONFIG_GROUP "Setup"
#define LANGUAGE_KEY "DefaultLanguage"
#define TIMEZONE_KEY "DefaultTimezone"
+#define TIMEFORMAT_KEY "DefaultTimeFormat"
/* Statically include this for now. Maybe later
* we'll generate this from glib-mkenums. */
@@ -80,6 +81,7 @@ struct _GisDriverPrivate {
gchar *lang_id;
gchar *lang_override;
gchar *default_timezone;
+ gchar *default_time_format;
GisDriverMode mode;
};
@@ -96,6 +98,7 @@ gis_driver_finalize (GObject *object)
g_free (priv->lang_id);
g_free (priv->lang_override);
g_free (priv->default_timezone);
+ g_free (priv->default_time_format);
G_OBJECT_CLASS (gis_driver_parent_class)->finalize (object);
}
@@ -211,6 +214,13 @@ gis_driver_get_default_timezone (GisDriver *driver)
return priv->default_timezone;
}
+const gchar *
+gis_driver_get_default_time_format (GisDriver *driver)
+{
+ GisDriverPrivate *priv = gis_driver_get_instance_private (driver);
+ return priv->default_time_format;
+}
+
static void
gis_driver_get_property (GObject *object,
guint prop_id,
@@ -278,6 +288,7 @@ gis_driver_read_personality_file (GisDriver *driver)
GKeyFile *keyfile = g_key_file_new ();
gchar *language = NULL;
gchar *timezone = NULL;
+ gchar *time_format = NULL;
if (g_key_file_load_from_file (keyfile, PERSONALITY_FILE_PATH,
G_KEY_FILE_NONE, NULL)) {
@@ -285,6 +296,8 @@ gis_driver_read_personality_file (GisDriver *driver)
LANGUAGE_KEY, NULL);
timezone = g_key_file_get_string (keyfile, INITIAL_CONFIG_GROUP,
TIMEZONE_KEY, NULL);
+ time_format = g_key_file_get_string (keyfile, INITIAL_CONFIG_GROUP,
+ TIMEFORMAT_KEY, NULL);
}
g_free (priv->lang_override);
@@ -295,6 +308,7 @@ gis_driver_read_personality_file (GisDriver *driver)
g_free (priv->default_timezone);
priv->default_timezone = timezone;
+ priv->default_time_format = time_format;
g_key_file_free (keyfile);
}
diff --git a/gnome-initial-setup/gis-driver.h b/gnome-initial-setup/gis-driver.h
index d8c092f..309bf3d 100644
--- a/gnome-initial-setup/gis-driver.h
+++ b/gnome-initial-setup/gis-driver.h
@@ -80,6 +80,8 @@ const gchar *gis_driver_get_language_override (GisDriver *driver);
const gchar *gis_driver_get_default_timezone (GisDriver *driver);
+const gchar *gis_driver_get_default_time_format (GisDriver *driver);
+
GisDriverMode gis_driver_get_mode (GisDriver *driver);
void gis_driver_add_page (GisDriver *driver,
diff --git a/gnome-initial-setup/pages/location/gis-location-page.c
b/gnome-initial-setup/pages/location/gis-location-page.c
index 7c0567f..6acd0d6 100644
--- a/gnome-initial-setup/pages/location/gis-location-page.c
+++ b/gnome-initial-setup/pages/location/gis-location-page.c
@@ -293,11 +293,26 @@ 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;
- /* Update the hours label */
- label = g_date_time_format (priv->date, "%H");
- gtk_label_set_text (GTK_LABEL (WID ("hours_label")), label);
+ time_format = gis_driver_get_default_time_format (driver);
+
+ if (!time_format || time_format[0] == '2') {
+ /* Update the hours label in 24h format */
+ label = g_date_time_format (priv->date, "%H");
+ gtk_label_set_text (GTK_LABEL (WID ("hours_label")), label);
+ gtk_widget_set_visible (WID ("ampm_label"), FALSE);
+ } else {
+ /* Update the hours label in AM/PM format */
+ label = g_date_time_format (priv->date, "%I");
+ gtk_label_set_text (GTK_LABEL (WID ("hours_label")), label);
+ g_free (label);
+ label = g_date_time_format (priv->date, "%p");
+ gtk_label_set_text (GTK_LABEL (WID ("ampm_label")), label);
+ gtk_widget_set_visible (WID ("ampm_label"), TRUE);
+ }
g_free (label);
/* Update the minutes label */
diff --git a/gnome-initial-setup/pages/location/gis-location-page.ui
b/gnome-initial-setup/pages/location/gis-location-page.ui
index cdb8a34..044c332 100644
--- a/gnome-initial-setup/pages/location/gis-location-page.ui
+++ b/gnome-initial-setup/pages/location/gis-location-page.ui
@@ -1,6 +1,51 @@
<?xml version="1.0" encoding="UTF-8"?>
+<!-- Generated with glade 3.16.1 -->
<interface>
- <!-- interface-requires gtk+ 3.0 -->
+ <requires lib="gtk+" version="3.0"/>
+ <object class="GtkListStore" id="month-liststore">
+ <columns>
+ <!-- column-name month -->
+ <column type="gchararray"/>
+ </columns>
+ <data>
+ <row>
+ <col id="0" translatable="yes">January</col>
+ </row>
+ <row>
+ <col id="0" translatable="yes">February</col>
+ </row>
+ <row>
+ <col id="0" translatable="yes">March</col>
+ </row>
+ <row>
+ <col id="0" translatable="yes">April</col>
+ </row>
+ <row>
+ <col id="0" translatable="yes">May</col>
+ </row>
+ <row>
+ <col id="0" translatable="yes">June</col>
+ </row>
+ <row>
+ <col id="0" translatable="yes">July</col>
+ </row>
+ <row>
+ <col id="0" translatable="yes">August</col>
+ </row>
+ <row>
+ <col id="0" translatable="yes">September</col>
+ </row>
+ <row>
+ <col id="0" translatable="yes">October</col>
+ </row>
+ <row>
+ <col id="0" translatable="yes">November</col>
+ </row>
+ <row>
+ <col id="0" translatable="yes">December</col>
+ </row>
+ </data>
+ </object>
<object class="GtkGrid" id="location-page">
<property name="visible">True</property>
<property name="can_focus">False</property>
@@ -335,6 +380,29 @@
</packing>
</child>
<child>
+ <object class="GtkLabel" id="ampm_label">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="label">PM</property>
+ <attributes>
+ <attribute name="weight" value="bold"/>
+ <attribute name="scale" value="2.5"/>
+ </attributes>
+ </object>
+ <packing>
+ <property name="left_attach">3</property>
+ <property name="top_attach">1</property>
+ <property name="width">1</property>
+ <property name="height">1</property>
+ </packing>
+ </child>
+ <child>
+ <placeholder/>
+ </child>
+ <child>
+ <placeholder/>
+ </child>
+ <child>
<placeholder/>
</child>
<child>
@@ -434,48 +502,4 @@
<placeholder/>
</child>
</object>
- <object class="GtkListStore" id="month-liststore">
- <columns>
- <!-- column-name month -->
- <column type="gchararray"/>
- </columns>
- <data>
- <row>
- <col id="0" translatable="yes">January</col>
- </row>
- <row>
- <col id="0" translatable="yes">February</col>
- </row>
- <row>
- <col id="0" translatable="yes">March</col>
- </row>
- <row>
- <col id="0" translatable="yes">April</col>
- </row>
- <row>
- <col id="0" translatable="yes">May</col>
- </row>
- <row>
- <col id="0" translatable="yes">June</col>
- </row>
- <row>
- <col id="0" translatable="yes">July</col>
- </row>
- <row>
- <col id="0" translatable="yes">August</col>
- </row>
- <row>
- <col id="0" translatable="yes">September</col>
- </row>
- <row>
- <col id="0" translatable="yes">October</col>
- </row>
- <row>
- <col id="0" translatable="yes">November</col>
- </row>
- <row>
- <col id="0" translatable="yes">December</col>
- </row>
- </data>
- </object>
</interface>
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]