35 #include <glib/gi18n.h>
57 static guint signals[LAST_SIGNAL] = { 0 };
62 static void gnc_period_select_finalize (GObject *
object);
64 static GtkComboBoxClass *parent_class;
67 const gchar *start_strings[GNC_ACCOUNTING_PERIOD_LAST] =
71 N_(
"Start of this month"),
72 N_(
"Start of previous month"),
73 N_(
"Start of this quarter"),
74 N_(
"Start of previous quarter"),
75 N_(
"Start of this year"),
76 N_(
"Start of previous year"),
79 N_(
"Start of this accounting period"),
80 N_(
"Start of previous accounting period"),
83 const gchar *end_strings[GNC_ACCOUNTING_PERIOD_LAST] =
87 N_(
"End of this month"),
88 N_(
"End of previous month"),
89 N_(
"End of this quarter"),
90 N_(
"End of previous quarter"),
91 N_(
"End of this year"),
92 N_(
"End of previous year"),
95 N_(
"End of this accounting period"),
96 N_(
"End of previous accounting period"),
111 GtkWidget *date_label;
112 GtkWidget *date_align;
115 #define GNC_PERIOD_SELECT_GET_PRIVATE(o) \
116 (G_TYPE_INSTANCE_GET_PRIVATE ((o), GNC_TYPE_PERIOD_SELECT, GncPeriodSelectPrivate))
128 g_return_if_fail(GNC_IS_PERIOD_SELECT(period));
130 g_signal_emit(G_OBJECT(period), signals[CHANGED], 0);
147 g_return_if_fail(GNC_IS_PERIOD_SELECT(period));
148 priv = GNC_PERIOD_SELECT_GET_PRIVATE(period);
149 if (!priv->date_label)
151 which = gtk_combo_box_get_active (GTK_COMBO_BOX (priv->selector));
153 date = g_date_new_dmy (31, 7, 2013);
155 else if (priv->start)
162 gtk_label_set_label (GTK_LABEL(priv->date_label), time_string);
177 gnc_period_sample_combobox_changed (GtkComboBox *box,
GncPeriodSelect *period)
179 g_return_if_fail(GNC_IS_PERIOD_SELECT(period));
181 g_object_set (G_OBJECT (period),
183 gtk_combo_box_get_active (box),
201 gnc_period_sample_new_date_format (gpointer prefs, gchar *pref,
204 gnc_period_sample_update_date_label(period);
225 g_return_if_fail(period != NULL);
226 g_return_if_fail(GNC_IS_PERIOD_SELECT(period));
227 g_return_if_fail(which >= 0);
228 g_return_if_fail(which < GNC_ACCOUNTING_PERIOD_LAST);
230 priv = GNC_PERIOD_SELECT_GET_PRIVATE(period);
232 g_signal_handlers_block_by_func(G_OBJECT(period),
233 G_CALLBACK(gnc_period_sample_combobox_changed), period);
234 gtk_combo_box_set_active(GTK_COMBO_BOX(priv->selector), which);
235 g_signal_handlers_unblock_by_func(G_OBJECT(period),
236 G_CALLBACK(gnc_period_sample_combobox_changed), period);
239 gnc_period_sample_update_date_label(period);
242 gnc_period_select_changed(period);
257 priv = GNC_PERIOD_SELECT_GET_PRIVATE(period);
259 g_return_val_if_fail(period != NULL, NULL);
260 g_return_val_if_fail(GNC_IS_PERIOD_SELECT(period), NULL);
262 priv = GNC_PERIOD_SELECT_GET_PRIVATE(period);
265 return g_date_new_dmy(g_date_get_day(priv->fy_end),
266 g_date_get_month(priv->fy_end),
282 g_return_if_fail(period != NULL);
283 g_return_if_fail(GNC_IS_PERIOD_SELECT(period));
285 priv = GNC_PERIOD_SELECT_GET_PRIVATE(period);
287 g_date_free(priv->fy_end);
291 priv->fy_end = g_date_new_dmy(g_date_get_day(fy_end),
292 g_date_get_month(fy_end),
302 for (i = GNC_ACCOUNTING_PERIOD_CYEAR_LAST; i < GNC_ACCOUNTING_PERIOD_FYEAR_LAST; i++)
304 label = priv->start ? _(start_strings[i]) : _(end_strings[i]);
305 gtk_combo_box_text_append_text(GTK_COMBO_BOX_TEXT(priv->selector), label);
310 for (i = GNC_ACCOUNTING_PERIOD_FYEAR_LAST - 1; i >= GNC_ACCOUNTING_PERIOD_FYEAR_LAST; i--)
312 gtk_combo_box_text_remove(GTK_COMBO_BOX_TEXT(priv->selector), i);
319 gnc_period_select_set_date_common (
GncPeriodSelect *period,
const GDate *date)
323 priv = GNC_PERIOD_SELECT_GET_PRIVATE(period);
327 g_date_free(priv->date_base);
328 priv->date_base = g_date_new_dmy(g_date_get_day(date),
329 g_date_get_month(date),
330 g_date_get_year(date));
331 if (priv->date_label == NULL)
333 priv->date_align = gtk_alignment_new(0.5, 0.5, 0, 0);
334 gtk_alignment_set_padding(GTK_ALIGNMENT(priv->date_align), 0, 0, 6, 0);
335 gtk_box_pack_start(GTK_BOX(period), priv->date_align, TRUE, TRUE, 0);
336 priv->date_label = gtk_label_new(
"");
337 gtk_container_add(GTK_CONTAINER(priv->date_align), priv->date_label);
338 gtk_widget_show_all(priv->date_align);
340 gnc_period_sample_update_date_label(period);
346 g_date_free(priv->date_base);
347 priv->date_base = NULL;
348 gtk_widget_destroy(priv->date_align);
349 priv->date_align = NULL;
350 priv->date_label = NULL;
363 g_return_val_if_fail(period != NULL, FALSE);
364 g_return_val_if_fail(GNC_IS_PERIOD_SELECT(period), FALSE);
366 priv = GNC_PERIOD_SELECT_GET_PRIVATE(period);
367 return (priv->date_base != NULL);
379 g_return_if_fail(period != NULL);
380 g_return_if_fail(GNC_IS_PERIOD_SELECT(period));
384 g_date_clear(&date, 1);
386 gnc_period_select_set_date_common(period, &date);
390 gnc_period_select_set_date_common(period, NULL);
400 g_return_val_if_fail(period != NULL, NULL);
401 g_return_val_if_fail(GNC_IS_PERIOD_SELECT(period), NULL);
403 priv = GNC_PERIOD_SELECT_GET_PRIVATE(period);
404 if (!priv->date_base)
406 return g_date_new_dmy(g_date_get_day(priv->date_base),
407 g_date_get_month(priv->date_base),
408 g_date_get_year(priv->date_base));
416 gnc_period_select_set_date_base (
GncPeriodSelect *period,
const GDate *date_base)
418 g_return_if_fail(period != NULL);
419 g_return_if_fail(GNC_IS_PERIOD_SELECT(period));
421 gnc_period_select_set_date_common(period, date_base);
433 gnc_period_select_get_property (GObject *
object,
449 g_value_set_pointer(value, gnc_period_select_get_date_base(period));
455 G_OBJECT_WARN_INVALID_PROPERTY_ID(
object, prop_id, pspec);
470 gnc_period_select_set_property (GObject *
object,
486 gnc_period_select_set_date_base(period, g_value_get_pointer(value));
489 gnc_period_select_set_active_internal(period, g_value_get_int(value));
492 G_OBJECT_WARN_INVALID_PROPERTY_ID(
object, prop_id, pspec);
511 static GType period_select_type = 0;
513 if (period_select_type == 0)
515 static const GTypeInfo period_select_info =
520 (GClassInitFunc) gnc_period_select_class_init,
525 (GInstanceInitFunc) gnc_period_select_init,
529 period_select_type = g_type_register_static(GTK_TYPE_HBOX,
531 &period_select_info, 0);
534 return period_select_type;
550 GObjectClass *gobject_class;
552 parent_class = g_type_class_peek_parent(klass);
554 gobject_class = G_OBJECT_CLASS(klass);
555 gobject_class->set_property = gnc_period_select_set_property;
556 gobject_class->get_property = gnc_period_select_get_property;
557 gobject_class->finalize = gnc_period_select_finalize;
560 signals[CHANGED] = g_signal_new(
"changed",
561 G_OBJECT_CLASS_TYPE (klass),
565 g_cclosure_marshal_VOID__VOID,
570 g_object_class_install_property(gobject_class,
572 g_param_spec_pointer(
"fy-end",
574 "The fiscal year to use for this widget",
576 g_object_class_install_property(gobject_class,
578 g_param_spec_boolean(
"show-date",
580 "Show the start/end date of the accounting period in this widget",
583 g_object_class_install_property(gobject_class,
585 g_param_spec_pointer(
"date-base",
587 "The starting date to use for display calculations",
589 g_object_class_install_property(gobject_class,
591 g_param_spec_int(
"active",
593 "The currently selected period in the list of periods",
616 priv = GNC_PERIOD_SELECT_GET_PRIVATE(period);
632 gnc_period_select_finalize (GObject *
object)
637 g_return_if_fail (
object != NULL);
638 g_return_if_fail (GNC_IS_PERIOD_SELECT (
object));
640 period = GNC_PERIOD_SELECT(
object);
641 priv = GNC_PERIOD_SELECT_GET_PRIVATE(period);
645 gnc_period_sample_new_date_format, period);
650 g_date_free(priv->fy_end);
652 g_date_free(priv->date_base);
657 if (G_OBJECT_CLASS(parent_class)->finalize)
658 (* G_OBJECT_CLASS(parent_class)->finalize) (
object);
679 period = g_object_new(GNC_TYPE_PERIOD_SELECT, NULL);
682 priv = GNC_PERIOD_SELECT_GET_PRIVATE(period);
683 priv->selector = gtk_combo_box_text_new();
684 priv->start = starting_labels;
687 gtk_box_pack_start(GTK_BOX(period), priv->selector, TRUE, TRUE, 0);
688 gtk_widget_show(priv->selector);
691 g_signal_connect(G_OBJECT(priv->selector),
"changed",
692 G_CALLBACK(gnc_period_sample_combobox_changed), period);
695 for (i = 0; i < GNC_ACCOUNTING_PERIOD_CYEAR_LAST; i++)
697 label = starting_labels ? _(start_strings[i]) : _(end_strings[i]);
698 gtk_combo_box_text_append_text(GTK_COMBO_BOX_TEXT(priv->selector), label);
703 gnc_period_sample_new_date_format, period);
705 return GTK_WIDGET (period);
716 gchar *string1, gchar *string2,
717 gint int1, gint int2)
723 gtk_widget_show(widget);
742 g_return_if_fail(period != NULL);
743 g_return_if_fail(GNC_IS_PERIOD_SELECT(period));
744 g_return_if_fail(which >= 0);
745 g_return_if_fail(which < GNC_ACCOUNTING_PERIOD_LAST);
747 g_object_set (G_OBJECT (period),
"active", which, NULL);
760 g_return_val_if_fail(period != NULL, -1);
761 g_return_val_if_fail(GNC_IS_PERIOD_SELECT(period), -1);
763 priv = GNC_PERIOD_SELECT_GET_PRIVATE(period);
764 return gtk_combo_box_get_active(GTK_COMBO_BOX(priv->selector));
778 g_return_val_if_fail(period != NULL, 0);
779 g_return_val_if_fail(GNC_IS_PERIOD_SELECT(period), 0);
781 priv = GNC_PERIOD_SELECT_GET_PRIVATE(period);
782 which = gtk_combo_box_get_active(GTK_COMBO_BOX(priv->selector));
Date and Time handling routines.
gulong gnc_prefs_register_cb(const char *group, const gchar *pref_name, gpointer func, gpointer user_data)
GncAccountingPeriod gnc_period_select_get_active(GncPeriodSelect *period)
void gnc_period_select_set_show_date(GncPeriodSelect *period, const gboolean show_date)
GDate * gnc_period_select_get_date(GncPeriodSelect *period)
GType gnc_period_select_get_type(void)
GDate * gnc_period_select_get_fy_end(GncPeriodSelect *period)
void gnc_period_select_set_fy_end(GncPeriodSelect *period, const GDate *fy_end)
Generic api to store and retrieve preferences.
GDate * gnc_accounting_period_end_gdate(GncAccountingPeriod which, const GDate *fy_end, const GDate *contains)
GDate * gnc_accounting_period_start_gdate(GncAccountingPeriod which, const GDate *fy_end, const GDate *contains)
gboolean gnc_period_select_get_show_date(GncPeriodSelect *period)
GtkWidget * gnc_period_select_new_glade(gchar *widget_name, gchar *string1, gchar *string2, gint int1, gint int2)
time64 gnc_time(time64 *tbuf)
get the current local time
GtkWidget * gnc_period_select_new(gboolean starting_labels)
void gnc_period_select_set_active(GncPeriodSelect *period, GncAccountingPeriod which)
A custom widget for selecting accounting periods.
size_t qof_print_gdate(char *buf, size_t bufflen, const GDate *gd)
void gnc_gdate_set_time64(GDate *gd, time64 time)
void gnc_prefs_remove_cb_by_func(const gchar *group, const gchar *pref_name, gpointer func, gpointer user_data)