+
+ /**
+ * HildonDateEditor:min-year:
+ *
+ * Minimum valid year.
+ */
+ g_object_class_install_property( gobject_class, PROP_MIN_YEAR,
+ g_param_spec_uint("min-year",
+ "Minimum valid year",
+ "Minimum valid year",
+ 1, 2100,
+ DEFAULT_MIN_YEAR,
+ G_PARAM_READWRITE) );
+
+ /**
+ * HildonDateEditor:max-year:
+ *
+ * Maximum valid year.
+ */
+ g_object_class_install_property( gobject_class, PROP_MAX_YEAR,
+ g_param_spec_uint("max-year",
+ "Maximum valid year",
+ "Maximum valid year",
+ 1, 2100,
+ DEFAULT_MAX_YEAR,
+ G_PARAM_READWRITE) );
+}
+
+/* Forces setting of the icon to certain state. Used initially
+ and from the actual setter function */
+static void
+real_set_calendar_icon_state(HildonDateEditorPrivate *priv,
+ gboolean pressed)
+{
+ gtk_image_set_from_icon_name(GTK_IMAGE(priv->calendar_icon),
+ pressed ? "qgn_widg_datedit_pr" : "qgn_widg_datedit",
+ HILDON_ICON_SIZE_WIDG);
+
+ priv->calendar_icon_pressed = pressed;
+}
+
+/* Sets the icon to given state (normal/pressed). Returns
+ info if the state actually changed. */
+static gboolean
+hildon_date_editor_set_calendar_icon_state(HildonDateEditor *editor,
+ gboolean pressed)
+{
+ HildonDateEditorPrivate *priv;
+
+ g_assert(HILDON_IS_DATE_EDITOR(editor));
+
+ priv = HILDON_DATE_EDITOR_GET_PRIVATE(editor);
+ if (pressed != priv->calendar_icon_pressed) {
+ real_set_calendar_icon_state(priv, pressed);
+ return TRUE;
+ }
+
+ return FALSE;
+}
+
+/* Packing day, month and year entries depend on locale settings
+ We find out the order and all separators by converting a known
+ date to default format and inspecting the result string */
+static void apply_locale_field_order(HildonDateEditorPrivate *priv)
+{
+ GDate locale_test_date;
+ GtkWidget *delim;
+ gchar buffer[256];
+ gchar *iter, *delim_text;
+
+ g_date_set_dmy(&locale_test_date, 1, 2, 1970);
+ (void) g_date_strftime(buffer, sizeof(buffer), "%x", &locale_test_date);
+ iter = buffer;
+
+ while (*iter)
+ {
+ gchar *endp;
+ unsigned long value;
+
+ /* Try to convert the current location into number. */
+ value = strtoul(iter, &endp, 10);
+
+ /* If the conversion didn't progress or the detected value was
+ unknown (we used a fixed date, you remember), we treat
+ current position as a literal */
+ switch (value)
+ {
+ case 1:
+ gtk_box_pack_start(GTK_BOX(priv->d_box_date),
+ priv->d_entry, FALSE, FALSE, 0);
+ break;
+ case 2:
+ gtk_box_pack_start(GTK_BOX(priv->d_box_date),
+ priv->m_entry, FALSE, FALSE, 0);
+ break;
+ case 70: /* %x format uses only 2 numbers for some locales */
+ case 1970:
+ gtk_box_pack_start(GTK_BOX(priv->d_box_date),
+ priv->y_entry, FALSE, FALSE, 0);
+ break;
+ default:
+ /* All non-number characters starting from current position
+ form the delimeter */
+ for (endp = iter; *endp; endp++)
+ if (g_ascii_isdigit(*endp))
+ break;
+
+ /* Now endp points one place past the delimeter text */
+ delim_text = g_strndup(iter, endp - iter);
+ delim = gtk_label_new(delim_text);
+ gtk_box_pack_start(GTK_BOX(priv->d_box_date),
+ delim, FALSE, FALSE, 0);
+ priv->delims = g_list_append(priv->delims, delim);
+ g_free(delim_text);
+
+ break;
+ };
+
+ iter = endp;
+ }