time-selector: use GDateTime
Pretty much like the previous commit, but porting the GcalTimeSelector class.
This commit is contained in:
@@ -239,8 +239,8 @@
|
|||||||
<object class="GcalTimeSelector" id="start_time_selector">
|
<object class="GcalTimeSelector" id="start_time_selector">
|
||||||
<property name="visible">True</property>
|
<property name="visible">True</property>
|
||||||
<property name="can_focus">True</property>
|
<property name="can_focus">True</property>
|
||||||
<property name="sensitive" bind-source="all_day_check" bind-property="active" bind-flags="invert-boolean|default" />
|
<property name="sensitive" bind-source="GcalEditDialog" bind-property="writable" bind-flags="default" />
|
||||||
<signal name="modified" handler="update_time" object="GcalEditDialog" swapped="no"/>
|
<signal name="notify::time" handler="update_time" object="GcalEditDialog" swapped="yes"/>
|
||||||
</object>
|
</object>
|
||||||
<packing>
|
<packing>
|
||||||
<property name="position">2</property>
|
<property name="position">2</property>
|
||||||
@@ -275,8 +275,8 @@
|
|||||||
<object class="GcalTimeSelector" id="end_time_selector">
|
<object class="GcalTimeSelector" id="end_time_selector">
|
||||||
<property name="visible">True</property>
|
<property name="visible">True</property>
|
||||||
<property name="can_focus">True</property>
|
<property name="can_focus">True</property>
|
||||||
<property name="sensitive" bind-source="all_day_check" bind-property="active" bind-flags="invert-boolean|default" />
|
<property name="sensitive" bind-source="GcalEditDialog" bind-property="writable" bind-flags="default" />
|
||||||
<signal name="modified" handler="update_time" object="GcalEditDialog" swapped="no"/>
|
<signal name="notify::time" handler="update_time" object="GcalEditDialog" swapped="yes"/>
|
||||||
</object>
|
</object>
|
||||||
<packing>
|
<packing>
|
||||||
<property name="position">2</property>
|
<property name="position">2</property>
|
||||||
|
|||||||
@@ -14,13 +14,13 @@
|
|||||||
<property name="upper">23</property>
|
<property name="upper">23</property>
|
||||||
<property name="step_increment">1</property>
|
<property name="step_increment">1</property>
|
||||||
<property name="page_increment">5</property>
|
<property name="page_increment">5</property>
|
||||||
<signal name="value-changed" handler="time_changed" object="GcalTimeSelector" swapped="no"/>
|
<signal name="value-changed" handler="update_time" object="GcalTimeSelector" swapped="yes"/>
|
||||||
</object>
|
</object>
|
||||||
<object class="GtkAdjustment" id="minute_adjustment">
|
<object class="GtkAdjustment" id="minute_adjustment">
|
||||||
<property name="upper">59</property>
|
<property name="upper">59</property>
|
||||||
<property name="step_increment">1</property>
|
<property name="step_increment">1</property>
|
||||||
<property name="page_increment">10</property>
|
<property name="page_increment">10</property>
|
||||||
<signal name="value-changed" handler="time_changed" object="GcalTimeSelector" swapped="no"/>
|
<signal name="value-changed" handler="update_time" object="GcalTimeSelector" swapped="yes"/>
|
||||||
</object>
|
</object>
|
||||||
<object class="GtkPopover" id="time_selector_popover">
|
<object class="GtkPopover" id="time_selector_popover">
|
||||||
<property name="position">bottom</property>
|
<property name="position">bottom</property>
|
||||||
@@ -73,7 +73,7 @@
|
|||||||
<object class="GtkComboBoxText" id="period_combo">
|
<object class="GtkComboBoxText" id="period_combo">
|
||||||
<property name="valign">center</property>
|
<property name="valign">center</property>
|
||||||
<property name="active">0</property>
|
<property name="active">0</property>
|
||||||
<signal name="changed" handler="period_changed" object="GcalTimeSelector" swapped="no"/>
|
<signal name="changed" handler="update_time" object="GcalTimeSelector" swapped="yes"/>
|
||||||
<items>
|
<items>
|
||||||
<item translatable="yes">AM</item>
|
<item translatable="yes">AM</item>
|
||||||
<item translatable="yes">PM</item>
|
<item translatable="yes">PM</item>
|
||||||
|
|||||||
+34
-63
@@ -87,8 +87,7 @@ static void update_summary (GtkEntry *en
|
|||||||
GParamSpec *pspec,
|
GParamSpec *pspec,
|
||||||
gpointer user_data);
|
gpointer user_data);
|
||||||
|
|
||||||
static void update_time (GtkEntry *entry,
|
static void update_time (GcalEditDialog *dialog);
|
||||||
gpointer user_data);
|
|
||||||
|
|
||||||
static void gcal_edit_dialog_constructed (GObject *object);
|
static void gcal_edit_dialog_constructed (GObject *object);
|
||||||
|
|
||||||
@@ -279,15 +278,11 @@ update_summary (GtkEntry *entry,
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
update_time (GtkEntry *entry,
|
update_time (GcalEditDialog *dialog)
|
||||||
gpointer user_data)
|
|
||||||
{
|
{
|
||||||
GcalEditDialog *dialog;
|
|
||||||
GDateTime *start_date;
|
GDateTime *start_date;
|
||||||
GDateTime *end_date;
|
GDateTime *end_date;
|
||||||
|
|
||||||
dialog = GCAL_EDIT_DIALOG (user_data);
|
|
||||||
|
|
||||||
if (dialog->setting_event)
|
if (dialog->setting_event)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
@@ -521,17 +516,6 @@ gcal_edit_dialog_set_writable (GcalEditDialog *dialog,
|
|||||||
gtk_button_set_label (GTK_BUTTON (dialog->done_button), writable ? _("Save") : _("Done"));
|
gtk_button_set_label (GTK_BUTTON (dialog->done_button), writable ? _("Save") : _("Done"));
|
||||||
|
|
||||||
g_object_notify (G_OBJECT (dialog), "writable");
|
g_object_notify (G_OBJECT (dialog), "writable");
|
||||||
|
|
||||||
if (!writable || (writable && gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (dialog->all_day_check))))
|
|
||||||
{
|
|
||||||
gtk_widget_set_sensitive (dialog->start_time_selector, FALSE);
|
|
||||||
gtk_widget_set_sensitive (dialog->end_time_selector, FALSE);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
gtk_widget_set_sensitive (dialog->start_time_selector, TRUE);
|
|
||||||
gtk_widget_set_sensitive (dialog->end_time_selector, TRUE);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -547,10 +531,6 @@ gcal_edit_dialog_clear_data (GcalEditDialog *dialog)
|
|||||||
update_summary,
|
update_summary,
|
||||||
dialog);
|
dialog);
|
||||||
|
|
||||||
/* date and time */
|
|
||||||
gcal_time_selector_set_time (GCAL_TIME_SELECTOR (dialog->start_time_selector), 0, 0);
|
|
||||||
gcal_time_selector_set_time (GCAL_TIME_SELECTOR (dialog->end_time_selector), 0, 0);
|
|
||||||
|
|
||||||
/* location */
|
/* location */
|
||||||
g_signal_handlers_block_by_func (dialog->location_entry,
|
g_signal_handlers_block_by_func (dialog->location_entry,
|
||||||
update_location,
|
update_location,
|
||||||
@@ -601,14 +581,13 @@ gcal_edit_dialog_all_day_changed (GtkWidget *widget,
|
|||||||
gpointer user_data)
|
gpointer user_data)
|
||||||
{
|
{
|
||||||
GcalEditDialog *dialog;
|
GcalEditDialog *dialog;
|
||||||
|
gboolean active;
|
||||||
|
|
||||||
dialog = GCAL_EDIT_DIALOG (user_data);
|
dialog = GCAL_EDIT_DIALOG (user_data);
|
||||||
|
active = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (dialog->all_day_check));
|
||||||
|
|
||||||
if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (dialog->all_day_check)))
|
gtk_widget_set_sensitive (dialog->start_time_selector, active);
|
||||||
{
|
gtk_widget_set_sensitive (dialog->end_time_selector, active);
|
||||||
gcal_time_selector_set_time (GCAL_TIME_SELECTOR (dialog->start_time_selector), 0, 0);
|
|
||||||
gcal_time_selector_set_time (GCAL_TIME_SELECTOR (dialog->end_time_selector), 0, 0);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Public API */
|
/* Public API */
|
||||||
@@ -705,16 +684,8 @@ gcal_edit_dialog_set_event (GcalEditDialog *dialog,
|
|||||||
gcal_date_selector_set_date (GCAL_DATE_SELECTOR (dialog->end_date_selector), date_end);
|
gcal_date_selector_set_date (GCAL_DATE_SELECTOR (dialog->end_date_selector), date_end);
|
||||||
|
|
||||||
/* time */
|
/* time */
|
||||||
if (!gcal_event_get_all_day (event))
|
gcal_time_selector_set_time (GCAL_TIME_SELECTOR (dialog->start_time_selector), date_start);
|
||||||
{
|
gcal_time_selector_set_time (GCAL_TIME_SELECTOR (dialog->end_time_selector), date_end);
|
||||||
gcal_time_selector_set_time (GCAL_TIME_SELECTOR (dialog->start_time_selector),
|
|
||||||
g_date_time_get_hour (date_start),
|
|
||||||
g_date_time_get_minute (date_start));
|
|
||||||
|
|
||||||
gcal_time_selector_set_time (GCAL_TIME_SELECTOR (dialog->end_time_selector),
|
|
||||||
g_date_time_get_hour (date_end),
|
|
||||||
g_date_time_get_minute (date_end));
|
|
||||||
}
|
|
||||||
|
|
||||||
/* all_day */
|
/* all_day */
|
||||||
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (dialog->all_day_check), gcal_event_get_all_day (event));
|
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (dialog->all_day_check), gcal_event_get_all_day (event));
|
||||||
@@ -750,41 +721,41 @@ gcal_edit_dialog_set_manager (GcalEditDialog *dialog,
|
|||||||
GDateTime*
|
GDateTime*
|
||||||
gcal_edit_dialog_get_date_start (GcalEditDialog *dialog)
|
gcal_edit_dialog_get_date_start (GcalEditDialog *dialog)
|
||||||
{
|
{
|
||||||
GDateTime *date, *aux;
|
GDateTime *date;
|
||||||
gint hour, minute;
|
GDateTime *time;
|
||||||
|
GDateTime *retval;
|
||||||
|
|
||||||
gcal_time_selector_get_time (GCAL_TIME_SELECTOR (dialog->start_time_selector),
|
date = gcal_date_selector_get_date (GCAL_DATE_SELECTOR (dialog->start_date_selector));
|
||||||
&hour,
|
time = gcal_time_selector_get_time (GCAL_TIME_SELECTOR (dialog->start_time_selector));
|
||||||
&minute);
|
|
||||||
|
|
||||||
aux = gcal_date_selector_get_date (GCAL_DATE_SELECTOR (dialog->start_date_selector));
|
retval = g_date_time_new (gcal_event_get_timezone (dialog->event),
|
||||||
|
g_date_time_get_year (date),
|
||||||
|
g_date_time_get_month (date),
|
||||||
|
g_date_time_get_day_of_month (date),
|
||||||
|
g_date_time_get_hour (time),
|
||||||
|
g_date_time_get_minute (time),
|
||||||
|
0);
|
||||||
|
|
||||||
date = g_date_time_new (gcal_event_get_timezone (dialog->event),
|
return retval;
|
||||||
g_date_time_get_year (aux),
|
|
||||||
g_date_time_get_month (aux),
|
|
||||||
g_date_time_get_day_of_month (aux),
|
|
||||||
hour, minute, 0);
|
|
||||||
|
|
||||||
return date;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
GDateTime*
|
GDateTime*
|
||||||
gcal_edit_dialog_get_date_end (GcalEditDialog *dialog)
|
gcal_edit_dialog_get_date_end (GcalEditDialog *dialog)
|
||||||
{
|
{
|
||||||
GDateTime *date, *aux;
|
GDateTime *date;
|
||||||
gint hour, minute;
|
GDateTime *time;
|
||||||
|
GDateTime *retval;
|
||||||
|
|
||||||
gcal_time_selector_get_time (GCAL_TIME_SELECTOR (dialog->end_time_selector),
|
date = gcal_date_selector_get_date (GCAL_DATE_SELECTOR (dialog->end_date_selector));
|
||||||
&hour,
|
time = gcal_time_selector_get_time (GCAL_TIME_SELECTOR (dialog->end_time_selector));
|
||||||
&minute);
|
|
||||||
|
|
||||||
aux = gcal_date_selector_get_date (GCAL_DATE_SELECTOR (dialog->end_date_selector));
|
retval = g_date_time_new (gcal_event_get_timezone (dialog->event),
|
||||||
|
g_date_time_get_year (date),
|
||||||
|
g_date_time_get_month (date),
|
||||||
|
g_date_time_get_day_of_month (date),
|
||||||
|
g_date_time_get_hour (time),
|
||||||
|
g_date_time_get_minute (time),
|
||||||
|
0);
|
||||||
|
|
||||||
date = g_date_time_new (gcal_event_get_timezone (dialog->event),
|
return retval;
|
||||||
g_date_time_get_year (aux),
|
|
||||||
g_date_time_get_month (aux),
|
|
||||||
g_date_time_get_day_of_month (aux),
|
|
||||||
hour, minute, 0);
|
|
||||||
|
|
||||||
return date;
|
|
||||||
}
|
}
|
||||||
|
|||||||
+155
-114
@@ -26,19 +26,25 @@ struct _GcalTimeSelector
|
|||||||
{
|
{
|
||||||
GtkMenuButton parent;
|
GtkMenuButton parent;
|
||||||
|
|
||||||
|
GtkAdjustment *hour_adjustment;
|
||||||
|
GtkAdjustment *minute_adjustment;
|
||||||
|
|
||||||
GtkWidget *time_label;
|
GtkWidget *time_label;
|
||||||
GtkWidget *hour_spin;
|
GtkWidget *hour_spin;
|
||||||
GtkWidget *minute_spin;
|
GtkWidget *minute_spin;
|
||||||
GtkWidget *period_combo;
|
GtkWidget *period_combo;
|
||||||
GtkWidget *grid;
|
GtkWidget *grid;
|
||||||
|
|
||||||
|
GDateTime *time;
|
||||||
|
|
||||||
gboolean format_24h;
|
gboolean format_24h;
|
||||||
};
|
};
|
||||||
|
|
||||||
enum
|
enum
|
||||||
{
|
{
|
||||||
MODIFIED,
|
PROP_0,
|
||||||
NUM_SIGNALS
|
PROP_TIME,
|
||||||
|
LAST_PROP
|
||||||
};
|
};
|
||||||
|
|
||||||
enum
|
enum
|
||||||
@@ -47,71 +53,89 @@ enum
|
|||||||
PM
|
PM
|
||||||
};
|
};
|
||||||
|
|
||||||
static guint signals[NUM_SIGNALS] = { 0, };
|
|
||||||
|
|
||||||
static void format_date_label (GcalTimeSelector *selector);
|
|
||||||
|
|
||||||
static gboolean on_output (GtkSpinButton *button,
|
|
||||||
gpointer user_data);
|
|
||||||
|
|
||||||
static void period_changed (GtkComboBox *combo,
|
|
||||||
gpointer user_data);
|
|
||||||
|
|
||||||
static void time_changed (GtkAdjustment *adjustment,
|
|
||||||
gpointer user_data);
|
|
||||||
|
|
||||||
static void gcal_time_selector_constructed (GObject *object);
|
static void gcal_time_selector_constructed (GObject *object);
|
||||||
|
|
||||||
G_DEFINE_TYPE (GcalTimeSelector, gcal_time_selector, GTK_TYPE_MENU_BUTTON);
|
G_DEFINE_TYPE (GcalTimeSelector, gcal_time_selector, GTK_TYPE_MENU_BUTTON);
|
||||||
|
|
||||||
static void
|
static void
|
||||||
format_date_label (GcalTimeSelector *selector)
|
update_label (GcalTimeSelector *selector)
|
||||||
{
|
{
|
||||||
GtkAdjustment *hour_adj;
|
gchar *new_label;
|
||||||
GtkAdjustment *minute_adj;
|
|
||||||
gchar *new_time;
|
|
||||||
gint hour, minute;
|
|
||||||
|
|
||||||
hour_adj = gtk_spin_button_get_adjustment (GTK_SPIN_BUTTON (selector->hour_spin));
|
|
||||||
minute_adj = gtk_spin_button_get_adjustment (GTK_SPIN_BUTTON (selector->minute_spin));
|
|
||||||
|
|
||||||
/* get current time */
|
|
||||||
hour = (gint) gtk_adjustment_get_value (hour_adj);
|
|
||||||
minute = (gint) gtk_adjustment_get_value (minute_adj);
|
|
||||||
|
|
||||||
/* format time according to the system 12h/24h setting */
|
|
||||||
if (selector->format_24h)
|
if (selector->format_24h)
|
||||||
{
|
{
|
||||||
new_time = g_strdup_printf ("%.2d:%.2d", hour, minute);
|
new_label = g_date_time_format (selector->time, "%H:%M");
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
gint period;
|
gchar *time_str;
|
||||||
|
gint hour, minute, period;
|
||||||
|
|
||||||
|
hour = (gint) gtk_adjustment_get_value (selector->hour_adjustment);
|
||||||
|
minute = (gint) gtk_adjustment_get_value (selector->minute_adjustment);
|
||||||
|
|
||||||
|
|
||||||
period = gtk_combo_box_get_active (GTK_COMBO_BOX (selector->period_combo));
|
period = gtk_combo_box_get_active (GTK_COMBO_BOX (selector->period_combo));
|
||||||
|
time_str = g_strdup_printf ("%.2d:%.2d", hour, minute);
|
||||||
|
|
||||||
/* FIXME: we shouldn't expose print formatting code to translators */
|
|
||||||
if (period == AM)
|
if (period == AM)
|
||||||
new_time = g_strdup_printf (_("%.2d:%.2d AM"), hour, minute);
|
new_label = g_strdup_printf (_("%s AM"), time_str);
|
||||||
else
|
else
|
||||||
new_time = g_strdup_printf (_("%.2d:%.2d PM"), hour, minute);
|
new_label = g_strdup_printf (_("%s PM"), time_str);
|
||||||
|
|
||||||
|
g_free (time_str);
|
||||||
}
|
}
|
||||||
|
|
||||||
gtk_label_set_label (GTK_LABEL (selector->time_label), new_time);
|
gtk_label_set_label (GTK_LABEL (selector->time_label), new_label);
|
||||||
|
|
||||||
g_free (new_time);
|
g_clear_pointer (&new_label, g_free);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
update_time (GcalTimeSelector *selector)
|
||||||
|
{
|
||||||
|
GDateTime *now, *new_time;
|
||||||
|
gint hour, minute;
|
||||||
|
|
||||||
|
/* Retrieve current time */
|
||||||
|
hour = (gint) gtk_adjustment_get_value (selector->hour_adjustment);
|
||||||
|
minute = (gint) gtk_adjustment_get_value (selector->minute_adjustment);
|
||||||
|
|
||||||
|
if (!selector->format_24h && gtk_combo_box_get_active (GTK_COMBO_BOX (selector->period_combo)) == PM)
|
||||||
|
{
|
||||||
|
g_signal_handlers_block_by_func (selector->period_combo, update_time, selector);
|
||||||
|
|
||||||
|
gtk_combo_box_set_active (GTK_COMBO_BOX (selector->period_combo), hour > 12);
|
||||||
|
hour *= 2;
|
||||||
|
|
||||||
|
g_signal_handlers_unblock_by_func (selector->period_combo, update_time, selector);
|
||||||
|
}
|
||||||
|
|
||||||
|
now = g_date_time_new_now_local ();
|
||||||
|
new_time = g_date_time_new_local (g_date_time_get_year (now),
|
||||||
|
g_date_time_get_month (now),
|
||||||
|
g_date_time_get_day_of_month (now),
|
||||||
|
hour, minute, 0);
|
||||||
|
|
||||||
|
/* Set the new time */
|
||||||
|
gcal_time_selector_set_time (selector, new_time);
|
||||||
|
|
||||||
|
g_clear_pointer (&new_time, g_date_time_unref);
|
||||||
|
g_clear_pointer (&now, g_date_time_unref);
|
||||||
}
|
}
|
||||||
|
|
||||||
static gboolean
|
static gboolean
|
||||||
on_output (GtkSpinButton *button,
|
on_output (GtkWidget *widget,
|
||||||
gpointer user_data)
|
GcalTimeSelector *selector)
|
||||||
{
|
{
|
||||||
|
GtkAdjustment *adjustment;
|
||||||
gchar *text;
|
gchar *text;
|
||||||
gint value;
|
gint value;
|
||||||
|
|
||||||
value = (gint) gtk_adjustment_get_value (gtk_spin_button_get_adjustment (button));
|
adjustment = gtk_spin_button_get_adjustment (GTK_SPIN_BUTTON (widget));
|
||||||
|
value = (gint) gtk_adjustment_get_value (adjustment);
|
||||||
text = g_strdup_printf ("%02d", value);
|
text = g_strdup_printf ("%02d", value);
|
||||||
gtk_entry_set_text (GTK_ENTRY (button), text);
|
gtk_entry_set_text (GTK_ENTRY (widget), text);
|
||||||
|
|
||||||
g_free (text);
|
g_free (text);
|
||||||
|
|
||||||
@@ -119,18 +143,49 @@ on_output (GtkSpinButton *button,
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
period_changed (GtkComboBox *combo,
|
gcal_time_selector_get_property (GObject *object,
|
||||||
gpointer user_data)
|
guint prop_id,
|
||||||
|
GValue *value,
|
||||||
|
GParamSpec *pspec)
|
||||||
{
|
{
|
||||||
format_date_label (GCAL_TIME_SELECTOR (user_data));
|
GcalTimeSelector *self = (GcalTimeSelector*) object;
|
||||||
|
|
||||||
g_signal_emit (user_data, signals[MODIFIED], 0);
|
switch (prop_id)
|
||||||
|
{
|
||||||
|
case PROP_TIME:
|
||||||
|
g_value_set_boxed (value, self->time);
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
gcal_time_selector_set_property (GObject *object,
|
||||||
|
guint prop_id,
|
||||||
|
const GValue *value,
|
||||||
|
GParamSpec *pspec)
|
||||||
|
{
|
||||||
|
GcalTimeSelector *self = (GcalTimeSelector*) object;
|
||||||
|
|
||||||
|
switch (prop_id)
|
||||||
|
{
|
||||||
|
case PROP_TIME:
|
||||||
|
gcal_time_selector_set_time (self, g_value_get_boxed (value));
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
gcal_time_selector_set_time_format (GcalTimeSelector *selector,
|
gcal_time_selector_set_time_format (GcalTimeSelector *selector,
|
||||||
gboolean format_24h)
|
gboolean format_24h)
|
||||||
{
|
{
|
||||||
|
g_return_if_fail (GCAL_IS_TIME_SELECTOR (selector));
|
||||||
|
|
||||||
selector->format_24h = format_24h;
|
selector->format_24h = format_24h;
|
||||||
gtk_widget_set_visible (selector->period_combo, !format_24h);
|
gtk_widget_set_visible (selector->period_combo, !format_24h);
|
||||||
|
|
||||||
@@ -140,15 +195,6 @@ gcal_time_selector_set_time_format (GcalTimeSelector *selector,
|
|||||||
gtk_adjustment_set_upper (gtk_spin_button_get_adjustment (GTK_SPIN_BUTTON (selector->hour_spin)), 11.0);
|
gtk_adjustment_set_upper (gtk_spin_button_get_adjustment (GTK_SPIN_BUTTON (selector->hour_spin)), 11.0);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
|
||||||
time_changed (GtkAdjustment *adjustment,
|
|
||||||
gpointer user_data)
|
|
||||||
{
|
|
||||||
format_date_label (GCAL_TIME_SELECTOR (user_data));
|
|
||||||
|
|
||||||
g_signal_emit (user_data, signals[MODIFIED], 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
static void
|
||||||
gcal_time_selector_class_init (GcalTimeSelectorClass *klass)
|
gcal_time_selector_class_init (GcalTimeSelectorClass *klass)
|
||||||
{
|
{
|
||||||
@@ -156,32 +202,42 @@ gcal_time_selector_class_init (GcalTimeSelectorClass *klass)
|
|||||||
|
|
||||||
object_class = G_OBJECT_CLASS (klass);
|
object_class = G_OBJECT_CLASS (klass);
|
||||||
object_class->constructed = gcal_time_selector_constructed;
|
object_class->constructed = gcal_time_selector_constructed;
|
||||||
|
object_class->get_property = gcal_time_selector_get_property;
|
||||||
|
object_class->set_property = gcal_time_selector_set_property;
|
||||||
|
|
||||||
signals[MODIFIED] = g_signal_new ("modified",
|
/**
|
||||||
GCAL_TYPE_TIME_SELECTOR,
|
* GcalTimeSelector::time:
|
||||||
G_SIGNAL_RUN_LAST,
|
*
|
||||||
0,
|
* The current time of the selector.
|
||||||
NULL, NULL,
|
*/
|
||||||
g_cclosure_marshal_VOID__VOID,
|
g_object_class_install_property (object_class,
|
||||||
G_TYPE_NONE,
|
PROP_TIME,
|
||||||
0);
|
g_param_spec_boxed ("time",
|
||||||
|
"Time of the selector",
|
||||||
|
"The current time of the selector",
|
||||||
|
G_TYPE_DATE_TIME,
|
||||||
|
G_PARAM_READWRITE));
|
||||||
|
|
||||||
gtk_widget_class_set_template_from_resource (GTK_WIDGET_CLASS (klass), "/org/gnome/calendar/time-selector.ui");
|
gtk_widget_class_set_template_from_resource (GTK_WIDGET_CLASS (klass), "/org/gnome/calendar/time-selector.ui");
|
||||||
|
|
||||||
gtk_widget_class_bind_template_child (GTK_WIDGET_CLASS (klass), GcalTimeSelector, time_label);
|
gtk_widget_class_bind_template_child (GTK_WIDGET_CLASS (klass), GcalTimeSelector, time_label);
|
||||||
|
gtk_widget_class_bind_template_child (GTK_WIDGET_CLASS (klass), GcalTimeSelector, hour_adjustment);
|
||||||
gtk_widget_class_bind_template_child (GTK_WIDGET_CLASS (klass), GcalTimeSelector, hour_spin);
|
gtk_widget_class_bind_template_child (GTK_WIDGET_CLASS (klass), GcalTimeSelector, hour_spin);
|
||||||
|
gtk_widget_class_bind_template_child (GTK_WIDGET_CLASS (klass), GcalTimeSelector, minute_adjustment);
|
||||||
gtk_widget_class_bind_template_child (GTK_WIDGET_CLASS (klass), GcalTimeSelector, minute_spin);
|
gtk_widget_class_bind_template_child (GTK_WIDGET_CLASS (klass), GcalTimeSelector, minute_spin);
|
||||||
gtk_widget_class_bind_template_child (GTK_WIDGET_CLASS (klass), GcalTimeSelector, period_combo);
|
gtk_widget_class_bind_template_child (GTK_WIDGET_CLASS (klass), GcalTimeSelector, period_combo);
|
||||||
gtk_widget_class_bind_template_child (GTK_WIDGET_CLASS (klass), GcalTimeSelector, grid);
|
gtk_widget_class_bind_template_child (GTK_WIDGET_CLASS (klass), GcalTimeSelector, grid);
|
||||||
|
|
||||||
gtk_widget_class_bind_template_callback (GTK_WIDGET_CLASS (klass), on_output);
|
gtk_widget_class_bind_template_callback (GTK_WIDGET_CLASS (klass), on_output);
|
||||||
gtk_widget_class_bind_template_callback (GTK_WIDGET_CLASS (klass), period_changed);
|
gtk_widget_class_bind_template_callback (GTK_WIDGET_CLASS (klass), update_time);
|
||||||
gtk_widget_class_bind_template_callback (GTK_WIDGET_CLASS (klass), time_changed);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
gcal_time_selector_init (GcalTimeSelector *self)
|
gcal_time_selector_init (GcalTimeSelector *self)
|
||||||
{
|
{
|
||||||
|
self->format_24h = TRUE;
|
||||||
|
self->time = g_date_time_new_now_local ();
|
||||||
|
|
||||||
gtk_widget_init_template (GTK_WIDGET (self));
|
gtk_widget_init_template (GTK_WIDGET (self));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -205,70 +261,55 @@ gcal_time_selector_new (void)
|
|||||||
|
|
||||||
void
|
void
|
||||||
gcal_time_selector_set_time (GcalTimeSelector *selector,
|
gcal_time_selector_set_time (GcalTimeSelector *selector,
|
||||||
gint hours,
|
GDateTime *time)
|
||||||
gint minutes)
|
|
||||||
{
|
{
|
||||||
GtkAdjustment *hour_adj;
|
|
||||||
GtkAdjustment *minute_adj;
|
|
||||||
|
|
||||||
g_return_if_fail (GCAL_IS_TIME_SELECTOR (selector));
|
g_return_if_fail (GCAL_IS_TIME_SELECTOR (selector));
|
||||||
|
|
||||||
hour_adj = gtk_spin_button_get_adjustment (GTK_SPIN_BUTTON (selector->hour_spin));
|
if (selector->time != time)
|
||||||
minute_adj = gtk_spin_button_get_adjustment (GTK_SPIN_BUTTON (selector->minute_spin));
|
|
||||||
g_warn_if_fail (hours < 24);
|
|
||||||
g_warn_if_fail (minutes < 60);
|
|
||||||
|
|
||||||
/* setup spin buttons according to the format */
|
|
||||||
if (selector->format_24h)
|
|
||||||
{
|
{
|
||||||
gtk_adjustment_set_value (hour_adj, hours < 24 ? hours : 0);
|
gint hour, minute;
|
||||||
}
|
|
||||||
else
|
g_clear_pointer (&selector->time, g_date_time_unref);
|
||||||
|
selector->time = g_date_time_new_local (g_date_time_get_year (time),
|
||||||
|
g_date_time_get_month (time),
|
||||||
|
g_date_time_get_day_of_month (time),
|
||||||
|
g_date_time_get_hour (time),
|
||||||
|
g_date_time_get_minute (time),
|
||||||
|
0);
|
||||||
|
|
||||||
|
/* Update the spinners */
|
||||||
|
g_signal_handlers_block_by_func (selector->hour_adjustment, update_time, selector);
|
||||||
|
g_signal_handlers_block_by_func (selector->minute_adjustment, update_time, selector);
|
||||||
|
|
||||||
|
hour = g_date_time_get_hour (time);
|
||||||
|
minute = g_date_time_get_minute (time);
|
||||||
|
|
||||||
|
if (!selector->format_24h)
|
||||||
{
|
{
|
||||||
gint period;
|
g_signal_handlers_block_by_func (selector->period_combo, update_time, selector);
|
||||||
|
|
||||||
period = hours < 12? AM : PM;
|
gtk_combo_box_set_active (GTK_COMBO_BOX (selector->period_combo), hour >= 12);
|
||||||
hours = hours % 12;
|
hour = hour % 12;
|
||||||
|
|
||||||
gtk_combo_box_set_active (GTK_COMBO_BOX (selector->period_combo), period);
|
g_signal_handlers_unblock_by_func (selector->period_combo, update_time, selector);
|
||||||
gtk_adjustment_set_value (hour_adj, hours);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
gtk_adjustment_set_value (minute_adj, minutes < 60 ? minutes : 0);
|
gtk_adjustment_set_value (selector->hour_adjustment, hour);
|
||||||
|
gtk_adjustment_set_value (selector->minute_adjustment, minute);
|
||||||
|
|
||||||
/* format time label accordingly */
|
update_label (selector);
|
||||||
format_date_label (selector);
|
|
||||||
|
g_signal_handlers_unblock_by_func (selector->hour_adjustment, update_time, selector);
|
||||||
|
g_signal_handlers_unblock_by_func (selector->minute_adjustment, update_time, selector);
|
||||||
|
|
||||||
|
g_object_notify (G_OBJECT (selector), "time");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
GDateTime*
|
||||||
gcal_time_selector_get_time (GcalTimeSelector *selector,
|
gcal_time_selector_get_time (GcalTimeSelector *selector)
|
||||||
gint *hours,
|
|
||||||
gint *minutes)
|
|
||||||
{
|
{
|
||||||
GtkAdjustment *hour_adj;
|
g_return_val_if_fail (GCAL_IS_TIME_SELECTOR (selector), NULL);
|
||||||
GtkAdjustment *minute_adj;
|
|
||||||
|
|
||||||
g_return_if_fail (GCAL_IS_TIME_SELECTOR (selector));
|
return selector->time;
|
||||||
|
|
||||||
hour_adj = gtk_spin_button_get_adjustment (GTK_SPIN_BUTTON (selector->hour_spin));
|
|
||||||
minute_adj = gtk_spin_button_get_adjustment (GTK_SPIN_BUTTON (selector->minute_spin));
|
|
||||||
|
|
||||||
/* 24h, the easy one*/
|
|
||||||
if (selector->format_24h)
|
|
||||||
{
|
|
||||||
*hours = (gint) gtk_adjustment_get_value (hour_adj);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* 12h format must calculate the time
|
|
||||||
* according to the AM/PM combo box */
|
|
||||||
else
|
|
||||||
{
|
|
||||||
gint am_pm;
|
|
||||||
|
|
||||||
am_pm = gtk_combo_box_get_active (GTK_COMBO_BOX (selector->period_combo));
|
|
||||||
*hours = (gint) gtk_adjustment_get_value (hour_adj) + 12 * am_pm;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* minute field isn't dependant on 12h/24h format */
|
|
||||||
*minutes = (gint) gtk_adjustment_get_value (minute_adj);
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -33,13 +33,10 @@ GtkWidget* gcal_time_selector_new (void);
|
|||||||
void gcal_time_selector_set_time_format (GcalTimeSelector *selector,
|
void gcal_time_selector_set_time_format (GcalTimeSelector *selector,
|
||||||
gboolean format_24h);
|
gboolean format_24h);
|
||||||
|
|
||||||
void gcal_time_selector_set_time (GcalTimeSelector *selector,
|
GDateTime* gcal_time_selector_get_time (GcalTimeSelector *selector);
|
||||||
gint hours,
|
|
||||||
gint minutes);
|
|
||||||
|
|
||||||
void gcal_time_selector_get_time (GcalTimeSelector *selector,
|
void gcal_time_selector_set_time (GcalTimeSelector *selector,
|
||||||
gint *hours,
|
GDateTime *time);
|
||||||
gint *minutes);
|
|
||||||
|
|
||||||
G_END_DECLS
|
G_END_DECLS
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user