date-selector: load popover with date selector
This commit is contained in:
committed by
Erick Pérez Castellanos
parent
40683e5e10
commit
2be9c125dd
+26
-15
@@ -8,13 +8,32 @@
|
|||||||
<property name="border_width">12</property>
|
<property name="border_width">12</property>
|
||||||
<property name="row_spacing">6</property>
|
<property name="row_spacing">6</property>
|
||||||
<child>
|
<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="visible">True</property>
|
||||||
<property name="can_focus">False</property>
|
<property name="can_focus">False</property>
|
||||||
|
<property name="hexpand">True</property>
|
||||||
|
<property name="homogeneous">True</property>
|
||||||
<child>
|
<child>
|
||||||
<object class="GtkEntry" id="entry1">
|
<object class="GtkEntry" id="entry1">
|
||||||
<property name="visible">True</property>
|
<property name="visible">True</property>
|
||||||
<property name="can_focus">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>
|
</object>
|
||||||
<packing>
|
<packing>
|
||||||
<property name="expand">False</property>
|
<property name="expand">False</property>
|
||||||
@@ -26,6 +45,9 @@
|
|||||||
<object class="GtkEntry" id="entry2">
|
<object class="GtkEntry" id="entry2">
|
||||||
<property name="visible">True</property>
|
<property name="visible">True</property>
|
||||||
<property name="can_focus">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>
|
<style>
|
||||||
<class name="middle-entry"/>
|
<class name="middle-entry"/>
|
||||||
</style>
|
</style>
|
||||||
@@ -40,6 +62,9 @@
|
|||||||
<object class="GtkEntry" id="entry3">
|
<object class="GtkEntry" id="entry3">
|
||||||
<property name="visible">True</property>
|
<property name="visible">True</property>
|
||||||
<property name="can_focus">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>
|
</object>
|
||||||
<packing>
|
<packing>
|
||||||
<property name="expand">False</property>
|
<property name="expand">False</property>
|
||||||
@@ -56,19 +81,5 @@
|
|||||||
<property name="top_attach">0</property>
|
<property name="top_attach">0</property>
|
||||||
</packing>
|
</packing>
|
||||||
</child>
|
</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>
|
</object>
|
||||||
</interface>
|
</interface>
|
||||||
|
|||||||
+56
-10
@@ -23,19 +23,31 @@
|
|||||||
#include <langinfo.h>
|
#include <langinfo.h>
|
||||||
#include <glib/gi18n.h>
|
#include <glib/gi18n.h>
|
||||||
|
|
||||||
|
enum
|
||||||
|
{
|
||||||
|
DAY,
|
||||||
|
MONTH,
|
||||||
|
YEAR,
|
||||||
|
NUM_ENTRIES
|
||||||
|
};
|
||||||
|
|
||||||
struct _GcalDateSelectorPrivate
|
struct _GcalDateSelectorPrivate
|
||||||
{
|
{
|
||||||
gboolean internal_skip;
|
GtkWidget *date_label;
|
||||||
|
GtkWidget *popover;
|
||||||
|
GtkWidget *entries[NUM_ENTRIES];
|
||||||
|
|
||||||
gint day;
|
gint day;
|
||||||
gint month;
|
gint month;
|
||||||
gint year;
|
gint year;
|
||||||
|
|
||||||
gchar *mask;
|
gchar *mask;
|
||||||
guint day_pos;
|
guint day_pos;
|
||||||
guint month_pos;
|
guint month_pos;
|
||||||
guint year_pos;
|
guint year_pos;
|
||||||
gboolean have_long_year;
|
gboolean have_long_year;
|
||||||
|
|
||||||
|
gboolean format_24h;
|
||||||
};
|
};
|
||||||
|
|
||||||
enum
|
enum
|
||||||
@@ -76,13 +88,13 @@ gcal_date_selector_init (GcalDateSelector *self)
|
|||||||
|
|
||||||
priv = gcal_date_selector_get_instance_private (GCAL_DATE_SELECTOR (self));;
|
priv = gcal_date_selector_get_instance_private (GCAL_DATE_SELECTOR (self));;
|
||||||
|
|
||||||
priv->internal_skip = FALSE;
|
|
||||||
priv->day = 1;
|
priv->day = 1;
|
||||||
priv->month = 1;
|
priv->month = 1;
|
||||||
priv->year = 1970;
|
priv->year = 1970;
|
||||||
|
|
||||||
setlocale (LC_ALL,"");
|
setlocale (LC_ALL,"");
|
||||||
priv->mask = nl_langinfo (D_FMT);
|
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->day_pos = - (priv->mask - g_strstr_len (priv->mask, -1, "%d"));
|
||||||
priv->month_pos = - (priv->mask - g_strstr_len (priv->mask, -1, "%m"));
|
priv->month_pos = - (priv->mask - g_strstr_len (priv->mask, -1, "%m"));
|
||||||
@@ -106,11 +118,45 @@ static void
|
|||||||
gcal_date_selector_constructed (GObject *object)
|
gcal_date_selector_constructed (GObject *object)
|
||||||
{
|
{
|
||||||
GcalDateSelectorPrivate *priv;
|
GcalDateSelectorPrivate *priv;
|
||||||
|
GtkWidget *grid;
|
||||||
|
GtkBuilder *builder;
|
||||||
|
|
||||||
|
GSettings *settings;
|
||||||
|
gchar *clock_format;
|
||||||
|
|
||||||
priv = gcal_date_selector_get_instance_private (GCAL_DATE_SELECTOR (object));
|
priv = gcal_date_selector_get_instance_private (GCAL_DATE_SELECTOR (object));
|
||||||
|
|
||||||
/* chaining up */
|
/* chaining up */
|
||||||
G_OBJECT_CLASS (gcal_date_selector_parent_class)->constructed (object);
|
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 */
|
/* Public API */
|
||||||
|
|||||||
Reference in New Issue
Block a user