[gnome-control-center] datetime: Add UI code to reorder date widgets
- From: Bastien Nocera <hadess src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-control-center] datetime: Add UI code to reorder date widgets
- Date: Tue, 8 Mar 2011 07:59:45 +0000 (UTC)
commit c93e7add24047ed51d693d1f835f235e5c9e3592
Author: Bastien Nocera <hadess hadess net>
Date: Tue Mar 8 06:47:19 2011 +0000
datetime: Add UI code to reorder date widgets
Based on the locale's date format, rather than only support
the US-centric version.
https://bugzilla.gnome.org/show_bug.cgi?id=636896
panels/datetime/Makefile.am | 2 +
panels/datetime/cc-datetime-panel.c | 38 +++++++++++++++++++++++++
panels/datetime/date-endian.c | 53 +++++++++++++++++++++++++++++++++++
panels/datetime/date-endian.h | 30 +++++++++++++++++++
4 files changed, 123 insertions(+), 0 deletions(-)
---
diff --git a/panels/datetime/Makefile.am b/panels/datetime/Makefile.am
index f29d8e9..1d48bae 100644
--- a/panels/datetime/Makefile.am
+++ b/panels/datetime/Makefile.am
@@ -95,6 +95,8 @@ libdate_time_la_SOURCES = \
cc-timezone-map.h \
set-timezone.c \
set-timezone.h \
+ date-endian.c \
+ date-endian.h \
tz.c tz.h
libdate_time_la_LIBADD = $(PANEL_LIBS) $(DATETIME_PANEL_LIBS)
diff --git a/panels/datetime/cc-datetime-panel.c b/panels/datetime/cc-datetime-panel.c
index 89810a7..369ea1e 100644
--- a/panels/datetime/cc-datetime-panel.c
+++ b/panels/datetime/cc-datetime-panel.c
@@ -25,6 +25,7 @@
#include "cc-timezone-map.h"
#include "set-timezone.h"
#include "cc-lockbutton.h"
+#include "date-endian.h"
#include <gsettings-desktop-schemas/gdesktop-enums.h>
#include <string.h>
@@ -743,6 +744,40 @@ on_permission_changed (GPermission *permission,
}
static void
+reorder_date_widget (DateEndianess endianess,
+ CcDateTimePanelPrivate *priv)
+{
+ GtkWidget *month, *day, *year;
+ GtkBox *box;
+
+ if (endianess == DATE_ENDIANESS_MIDDLE)
+ return;
+
+ month = W ("month-combobox");
+ day = W ("day-spinbutton");
+ year = W("year-spinbutton");
+
+ box = GTK_BOX (W("table1"));
+
+ switch (endianess) {
+ case DATE_ENDIANESS_LITTLE:
+ gtk_box_reorder_child (box, month, 0);
+ gtk_box_reorder_child (box, day, 0);
+ gtk_box_reorder_child (box, year, -1);
+ break;
+ case DATE_ENDIANESS_BIG:
+ gtk_box_reorder_child (box, month, 0);
+ gtk_box_reorder_child (box, year, 0);
+ gtk_box_reorder_child (box, day, -1);
+ break;
+ case DATE_ENDIANESS_MIDDLE:
+ /* Let's please GCC */
+ g_assert_not_reached ();
+ break;
+ }
+}
+
+static void
cc_date_time_panel_init (CcDateTimePanel *self)
{
CcDateTimePanelPrivate *priv;
@@ -760,6 +795,7 @@ cc_date_time_panel_init (CcDateTimePanel *self)
int ret;
GtkWidget *lockbutton;
GPermission *permission;
+ DateEndianess endianess;
priv = self->priv = DATE_TIME_PANEL_PRIVATE (self);
@@ -792,6 +828,8 @@ cc_date_time_panel_init (CcDateTimePanel *self)
/* set up date editing widgets */
priv->date = g_date_time_new_now_local ();
+ endianess = date_endian_get_default ();
+ reorder_date_widget (endianess, priv);
gtk_combo_box_set_active (GTK_COMBO_BOX (W ("month-combobox")),
g_date_time_get_month (priv->date) - 1);
diff --git a/panels/datetime/date-endian.c b/panels/datetime/date-endian.c
new file mode 100644
index 0000000..a45f849
--- /dev/null
+++ b/panels/datetime/date-endian.c
@@ -0,0 +1,53 @@
+/*
+ * Copyright (C) 2011 Red Hat, Inc.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ *
+ * Author: Bastien Nocera <hadess hadess net>
+ *
+ */
+
+#include <langinfo.h>
+#include <locale.h>
+#include <glib.h>
+
+#include "date-endian.h"
+
+DateEndianess
+date_endian_get_default (void)
+{
+ const char *fmt;
+
+ fmt = nl_langinfo (D_FMT);
+ g_return_val_if_fail (fmt != NULL, DATE_ENDIANESS_MIDDLE);
+
+ /* FIXME, implement */
+
+ return DATE_ENDIANESS_MIDDLE;
+}
+
+DateEndianess
+date_endian_get_for_lang (const char *lang)
+{
+ const char *old_lang;
+ DateEndianess endian;
+
+ old_lang = setlocale (LC_TIME, lang);
+ endian = date_endian_get_default ();
+ setlocale (LC_TIME, old_lang);
+
+ return endian;
+}
+
diff --git a/panels/datetime/date-endian.h b/panels/datetime/date-endian.h
new file mode 100644
index 0000000..3c10a6b
--- /dev/null
+++ b/panels/datetime/date-endian.h
@@ -0,0 +1,30 @@
+/*
+ * Copyright (C) 2011 Red Hat, Inc.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ *
+ * Author: Bastien Nocera <hadess hadess net>
+ *
+ */
+
+/* From http://en.wikipedia.org/wiki/Date_notation_by_country */
+typedef enum {
+ DATE_ENDIANESS_BIG, /* Big-endian (year, month, day), e.g. 03-04-05 */
+ DATE_ENDIANESS_LITTLE, /* Little-endian (day, month, year), e.g. 05/04/03 */
+ DATE_ENDIANESS_MIDDLE /* Middle-endian (month, day, year), e.g. 04/05/03 */
+} DateEndianess;
+
+DateEndianess date_endian_get_default (void);
+DateEndianess date_endian_get_for_lang (const char *lang);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]