[gnome-calendar] date-selector: load popover with date selector
- From: Erick Pérez Castellanos <erickpc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-calendar] date-selector: load popover with date selector
- Date: Tue, 23 Dec 2014 17:05:20 +0000 (UTC)
commit 2be9c125dd31471710f018931ab7bd2865f3c07e
Author: Georges Basile Stavracas Neto <georges stavracas gmail com>
Date: Thu Dec 18 15:24:44 2014 -0200
date-selector: load popover with date selector
data/ui/date-selector.ui | 41 ++++++++++++++++++----------
src/gcal-date-selector.c | 66 +++++++++++++++++++++++++++++++++++++++-------
2 files changed, 82 insertions(+), 25 deletions(-)
---
diff --git a/data/ui/date-selector.ui b/data/ui/date-selector.ui
index 997de6e..8b88784 100644
--- a/data/ui/date-selector.ui
+++ b/data/ui/date-selector.ui
@@ -8,13 +8,32 @@
<property name="border_width">12</property>
<property name="row_spacing">6</property>
<child>
- <object class="GtkBox" id="date_box">
+ <object class="GtkCalendar" id="calendar">
+ <property name="visible">True</property>
+ <property name="can_focus">True</property>
+ <property name="year">2014</property>
+ <property name="month">11</property>
+ <property name="day">18</property>
+ <property name="show_week_numbers">True</property>
+ </object>
+ <packing>
+ <property name="left_attach">0</property>
+ <property name="top_attach">1</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkBox" id="box">
<property name="visible">True</property>
<property name="can_focus">False</property>
+ <property name="hexpand">True</property>
+ <property name="homogeneous">True</property>
<child>
<object class="GtkEntry" id="entry1">
<property name="visible">True</property>
<property name="can_focus">True</property>
+ <property name="width_chars">4</property>
+ <property name="xalign">0.5</property>
+ <property name="input_purpose">number</property>
</object>
<packing>
<property name="expand">False</property>
@@ -26,6 +45,9 @@
<object class="GtkEntry" id="entry2">
<property name="visible">True</property>
<property name="can_focus">True</property>
+ <property name="width_chars">4</property>
+ <property name="xalign">0.5</property>
+ <property name="input_purpose">number</property>
<style>
<class name="middle-entry"/>
</style>
@@ -40,6 +62,9 @@
<object class="GtkEntry" id="entry3">
<property name="visible">True</property>
<property name="can_focus">True</property>
+ <property name="width_chars">4</property>
+ <property name="xalign">0.5</property>
+ <property name="input_purpose">number</property>
</object>
<packing>
<property name="expand">False</property>
@@ -56,19 +81,5 @@
<property name="top_attach">0</property>
</packing>
</child>
- <child>
- <object class="GtkCalendar" id="calendar">
- <property name="visible">True</property>
- <property name="can_focus">True</property>
- <property name="year">2014</property>
- <property name="month">11</property>
- <property name="day">18</property>
- <property name="show_week_numbers">True</property>
- </object>
- <packing>
- <property name="left_attach">0</property>
- <property name="top_attach">1</property>
- </packing>
- </child>
</object>
</interface>
diff --git a/src/gcal-date-selector.c b/src/gcal-date-selector.c
index 1fdd459..d034d36 100644
--- a/src/gcal-date-selector.c
+++ b/src/gcal-date-selector.c
@@ -23,19 +23,31 @@
#include <langinfo.h>
#include <glib/gi18n.h>
+enum
+{
+ DAY,
+ MONTH,
+ YEAR,
+ NUM_ENTRIES
+};
+
struct _GcalDateSelectorPrivate
{
- gboolean internal_skip;
+ GtkWidget *date_label;
+ GtkWidget *popover;
+ GtkWidget *entries[NUM_ENTRIES];
- gint day;
- gint month;
- gint year;
+ gint day;
+ gint month;
+ gint year;
- gchar *mask;
- guint day_pos;
- guint month_pos;
- guint year_pos;
- gboolean have_long_year;
+ gchar *mask;
+ guint day_pos;
+ guint month_pos;
+ guint year_pos;
+ gboolean have_long_year;
+
+ gboolean format_24h;
};
enum
@@ -76,13 +88,13 @@ gcal_date_selector_init (GcalDateSelector *self)
priv = gcal_date_selector_get_instance_private (GCAL_DATE_SELECTOR (self));;
- priv->internal_skip = FALSE;
priv->day = 1;
priv->month = 1;
priv->year = 1970;
setlocale (LC_ALL,"");
priv->mask = nl_langinfo (D_FMT);
+ g_debug ("Mask: %s", priv->mask);
priv->day_pos = - (priv->mask - g_strstr_len (priv->mask, -1, "%d"));
priv->month_pos = - (priv->mask - g_strstr_len (priv->mask, -1, "%m"));
@@ -106,11 +118,45 @@ static void
gcal_date_selector_constructed (GObject *object)
{
GcalDateSelectorPrivate *priv;
+ GtkWidget *grid;
+ GtkBuilder *builder;
+
+ GSettings *settings;
+ gchar *clock_format;
priv = gcal_date_selector_get_instance_private (GCAL_DATE_SELECTOR (object));
/* chaining up */
G_OBJECT_CLASS (gcal_date_selector_parent_class)->constructed (object);
+
+ /* 24h setting */
+ settings = g_settings_new ("org.gnome.desktop.interface");
+ clock_format = g_settings_get_string (settings, "clock-format");
+ priv->format_24h = (g_strcmp0 (clock_format, "24h") == 0);
+
+ g_free (clock_format);
+ g_object_unref (settings);
+
+ /* date label */
+ priv->date_label = gtk_label_new (NULL);
+ gtk_widget_show (priv->date_label);
+
+ gtk_container_add (GTK_CONTAINER (object), priv->date_label);
+
+ /* retrieve components from UI definition */
+ builder = gtk_builder_new ();
+ gtk_builder_add_from_resource (builder, "/org/gnome/calendar/date-selector.ui", NULL);
+
+ /* popover */
+ priv->popover = gtk_popover_new (GTK_WIDGET (object));
+ gtk_popover_set_position (GTK_POPOVER (priv->popover), GTK_POS_BOTTOM);
+
+ /* main grid */
+ grid = (GtkWidget*) gtk_builder_get_object (builder, "grid");
+ g_object_ref (grid);
+
+ gtk_container_add (GTK_CONTAINER (priv->popover), grid);
+ g_object_bind_property (priv->popover, "visible", object, "active", G_BINDING_BIDIRECTIONAL);
}
/* Public API */
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]