35 #include <glib/gi18n.h> 40 #include "dialog-utils.h" 57 static guint signals[LAST_SIGNAL] = { 0 };
60 static void gnc_period_select_finalize (GObject *
object);
62 const gchar *start_strings[GNC_ACCOUNTING_PERIOD_LAST] =
66 N_(
"Start of this month"),
67 N_(
"Start of previous month"),
68 N_(
"Start of this quarter"),
69 N_(
"Start of previous quarter"),
70 N_(
"Start of this year"),
71 N_(
"Start of previous year"),
74 N_(
"Start of this accounting period"),
75 N_(
"Start of previous accounting period"),
78 const gchar *end_strings[GNC_ACCOUNTING_PERIOD_LAST] =
82 N_(
"End of this month"),
83 N_(
"End of previous month"),
84 N_(
"End of this quarter"),
85 N_(
"End of previous quarter"),
86 N_(
"End of this year"),
87 N_(
"End of previous year"),
90 N_(
"End of this accounting period"),
91 N_(
"End of previous accounting period"),
107 GtkWidget *date_label;
110 G_DEFINE_TYPE(GncPeriodSelect, gnc_period_select, GTK_TYPE_BOX)
120 gnc_period_select_changed (GncPeriodSelect *period)
122 g_return_if_fail(GNC_IS_PERIOD_SELECT(period));
124 g_signal_emit(G_OBJECT(period), signals[CHANGED], 0);
134 gnc_period_sample_update_date_label (GncPeriodSelect *period)
140 g_return_if_fail(GNC_IS_PERIOD_SELECT(period));
141 if (!period->date_label)
143 which = gtk_combo_box_get_active (GTK_COMBO_BOX (period->selector));
145 date = g_date_new_dmy (31, 7, 2013);
147 else if (period->start)
154 gtk_label_set_label (GTK_LABEL(period->date_label), time_string);
169 gnc_period_sample_combobox_changed (GtkComboBox *box, GncPeriodSelect *period)
171 g_return_if_fail(GNC_IS_PERIOD_SELECT(period));
173 g_object_set (G_OBJECT (period),
175 gtk_combo_box_get_active (box),
193 gnc_period_sample_new_date_format (gpointer prefs, gchar *pref,
194 GncPeriodSelect *period)
196 gnc_period_sample_update_date_label(period);
212 gnc_period_select_set_active_internal (GncPeriodSelect *period,
215 g_return_if_fail(period != NULL);
216 g_return_if_fail(GNC_IS_PERIOD_SELECT(period));
217 g_return_if_fail(which >= 0);
218 g_return_if_fail(which < GNC_ACCOUNTING_PERIOD_LAST);
220 g_signal_handlers_block_by_func(G_OBJECT(period),
221 G_CALLBACK(gnc_period_sample_combobox_changed), period);
222 gtk_combo_box_set_active(GTK_COMBO_BOX(period->selector), which);
223 g_signal_handlers_unblock_by_func(G_OBJECT(period),
224 G_CALLBACK(gnc_period_sample_combobox_changed), period);
227 gnc_period_sample_update_date_label(period);
230 gnc_period_select_changed(period);
244 g_return_val_if_fail(period != NULL, NULL);
245 g_return_val_if_fail(GNC_IS_PERIOD_SELECT(period), NULL);
249 return g_date_new_dmy(g_date_get_day(period->fy_end),
250 g_date_get_month(period->fy_end),
265 g_return_if_fail(period != NULL);
266 g_return_if_fail(GNC_IS_PERIOD_SELECT(period));
269 g_date_free(period->fy_end);
273 period->fy_end = g_date_new_dmy(g_date_get_day(fy_end),
274 g_date_get_month(fy_end),
279 period->fy_end = NULL;
284 for (i = GNC_ACCOUNTING_PERIOD_CYEAR_LAST; i < GNC_ACCOUNTING_PERIOD_FYEAR_LAST; i++)
286 label = period->start ? _(start_strings[i]) : _(end_strings[i]);
287 gtk_combo_box_text_append_text(GTK_COMBO_BOX_TEXT(period->selector), label);
292 for (i = GNC_ACCOUNTING_PERIOD_FYEAR_LAST - 1; i >= GNC_ACCOUNTING_PERIOD_FYEAR_LAST; i--)
294 gtk_combo_box_text_remove(GTK_COMBO_BOX_TEXT(period->selector), i);
301 gnc_period_select_set_date_common (GncPeriodSelect *period,
const GDate *date)
305 if (period->date_base)
306 g_date_free(period->date_base);
307 period->date_base = g_date_new_dmy(g_date_get_day(date),
308 g_date_get_month(date),
309 g_date_get_year(date));
310 if (period->date_label == NULL)
312 period->date_label = gtk_label_new(
"");
313 gtk_widget_set_margin_start (GTK_WIDGET(period->date_label), 6);
314 gtk_box_pack_start(GTK_BOX(period), period->date_label, TRUE, TRUE, 0);
315 gtk_widget_show_all(period->date_label);
317 gnc_period_sample_update_date_label(period);
321 if (period->date_base)
323 g_date_free(period->date_base);
324 period->date_base = NULL;
325 gtk_widget_destroy(period->date_label);
326 period->date_label = NULL;
337 g_return_val_if_fail(period != NULL, FALSE);
338 g_return_val_if_fail(GNC_IS_PERIOD_SELECT(period), FALSE);
340 return (period->date_base != NULL);
352 g_return_if_fail(period != NULL);
353 g_return_if_fail(GNC_IS_PERIOD_SELECT(period));
357 g_date_clear(&date, 1);
359 gnc_period_select_set_date_common(period, &date);
363 gnc_period_select_set_date_common(period, NULL);
369 gnc_period_select_get_date_base (GncPeriodSelect *period)
371 g_return_val_if_fail(period != NULL, NULL);
372 g_return_val_if_fail(GNC_IS_PERIOD_SELECT(period), NULL);
374 if (!period->date_base)
376 return g_date_new_dmy(g_date_get_day(period->date_base),
377 g_date_get_month(period->date_base),
378 g_date_get_year(period->date_base));
386 gnc_period_select_set_date_base (GncPeriodSelect *period,
const GDate *date_base)
388 g_return_if_fail(period != NULL);
389 g_return_if_fail(GNC_IS_PERIOD_SELECT(period));
391 gnc_period_select_set_date_common(period, date_base);
403 gnc_period_select_get_property (GObject *
object,
408 GncPeriodSelect *period = GNC_PERIOD_SELECT(
object);
419 g_value_set_pointer(value, gnc_period_select_get_date_base(period));
425 G_OBJECT_WARN_INVALID_PROPERTY_ID(
object, prop_id, pspec);
440 gnc_period_select_set_property (GObject *
object,
445 GncPeriodSelect *period = GNC_PERIOD_SELECT(
object);
456 gnc_period_select_set_date_base(period, g_value_get_pointer(value));
459 gnc_period_select_set_active_internal(period, g_value_get_int(value));
462 G_OBJECT_WARN_INVALID_PROPERTY_ID(
object, prop_id, pspec);
486 gnc_period_select_class_init (GncPeriodSelectClass *klass)
488 GObjectClass *gobject_class;
490 gobject_class = G_OBJECT_CLASS(klass);
491 gobject_class->set_property = gnc_period_select_set_property;
492 gobject_class->get_property = gnc_period_select_get_property;
493 gobject_class->finalize = gnc_period_select_finalize;
496 signals[CHANGED] = g_signal_new(
"changed",
497 G_OBJECT_CLASS_TYPE (klass),
501 g_cclosure_marshal_VOID__VOID,
506 g_object_class_install_property(gobject_class,
508 g_param_spec_pointer(
"fy-end",
510 "The fiscal year to use for this widget",
512 g_object_class_install_property(gobject_class,
514 g_param_spec_boolean(
"show-date",
516 "Show the start/end date of the accounting period in this widget",
519 g_object_class_install_property(gobject_class,
521 g_param_spec_pointer(
"date-base",
523 "The starting date to use for display calculations",
525 g_object_class_install_property(gobject_class,
527 g_param_spec_int(
"active",
529 "The currently selected period in the list of periods",
545 gnc_period_select_init (GncPeriodSelect *period)
547 gtk_orientable_set_orientation (GTK_ORIENTABLE(period), GTK_ORIENTATION_HORIZONTAL);
550 gtk_widget_set_name (GTK_WIDGET(period),
"gnc-id-period-select");
552 period->start = TRUE;
567 gnc_period_select_finalize (GObject *
object)
569 GncPeriodSelect *period;
571 g_return_if_fail (
object != NULL);
572 g_return_if_fail (GNC_IS_PERIOD_SELECT (
object));
574 period = GNC_PERIOD_SELECT(
object);
578 gnc_period_sample_new_date_format, period);
583 g_date_free(period->fy_end);
584 if (period->date_base)
585 g_date_free(period->date_base);
590 G_OBJECT_CLASS(gnc_period_select_parent_class)->finalize (
object);
606 GncPeriodSelect *period;
610 period = g_object_new(GNC_TYPE_PERIOD_SELECT, NULL);
613 period->selector = gtk_combo_box_text_new();
614 period->start = starting_labels;
617 gtk_box_pack_start(GTK_BOX(period), period->selector, TRUE, TRUE, 0);
618 gtk_widget_show(period->selector);
621 g_signal_connect(G_OBJECT(period->selector),
"changed",
622 G_CALLBACK(gnc_period_sample_combobox_changed), period);
625 for (i = 0; i < GNC_ACCOUNTING_PERIOD_CYEAR_LAST; i++)
627 label = starting_labels ? _(start_strings[i]) : _(end_strings[i]);
628 gtk_combo_box_text_append_text(GTK_COMBO_BOX_TEXT(period->selector), label);
633 gnc_period_sample_new_date_format, period);
635 return GTK_WIDGET (period);
646 gchar *string1, gchar *string2,
647 gint int1, gint int2)
653 gtk_widget_show(widget);
672 g_return_if_fail(period != NULL);
673 g_return_if_fail(GNC_IS_PERIOD_SELECT(period));
674 g_return_if_fail(which >= 0);
675 g_return_if_fail(which < GNC_ACCOUNTING_PERIOD_LAST);
677 g_object_set (G_OBJECT (period),
"active", which, NULL);
688 g_return_val_if_fail(period != NULL, -1);
689 g_return_val_if_fail(GNC_IS_PERIOD_SELECT(period), -1);
691 return gtk_combo_box_get_active(GTK_COMBO_BOX(period->selector));
704 g_return_val_if_fail(period != NULL, 0);
705 g_return_val_if_fail(GNC_IS_PERIOD_SELECT(period), 0);
707 which = gtk_combo_box_get_active(GTK_COMBO_BOX(period->selector));
Date and Time handling routines.
gulong gnc_prefs_register_cb(const char *group, const gchar *pref_name, gpointer func, gpointer user_data)
Register a callback that gets triggered when the given preference changes.
size_t qof_print_gdate(char *buf, size_t bufflen, const GDate *gd)
Convenience; calls through to qof_print_date_dmy_buff().
GncAccountingPeriod gnc_period_select_get_active(GncPeriodSelect *period)
Get the currently selected accounting period from a GncPeriodSelect widget.
void gnc_period_select_set_show_date(GncPeriodSelect *period, const gboolean show_date)
Set the "show sample" setting on a GncPeriodSelect widget.
GDate * gnc_period_select_get_date(GncPeriodSelect *period)
Get the currently selected accounting period choice from a GncPeriodSelect widget.
GncAccountingPeriod
This specifies a time interval.
GDate * gnc_period_select_get_fy_end(GncPeriodSelect *period)
Get the current value of the fiscal year end setting from a GncPeriodSelect widget.
void gnc_period_select_set_fy_end(GncPeriodSelect *period, const GDate *fy_end)
Set the fiscal year end on a GncPeriodSelect widget.
#define MAX_DATE_LENGTH
The maximum length of a string created by the date printers.
Generic api to store and retrieve preferences.
GDate * gnc_accounting_period_end_gdate(GncAccountingPeriod which, const GDate *fy_end, const GDate *contains)
This function returns the ending date for an accounting period.
GDate * gnc_accounting_period_start_gdate(GncAccountingPeriod which, const GDate *fy_end, const GDate *contains)
This function returns the starting date for an accounting period.
gboolean gnc_period_select_get_show_date(GncPeriodSelect *period)
Get the current value of the "show sample" setting from a GncPeriodSelect widget. ...
void gnc_gdate_set_time64(GDate *gd, time64 time)
Set a GDate to a time64.
GtkWidget * gnc_period_select_new_glade(gchar *widget_name, gchar *string1, gchar *string2, gint int1, gint int2)
Create a new GncPeriodSelect widget from a glade file.
time64 gnc_time(time64 *tbuf)
get the current time
GtkWidget * gnc_period_select_new(gboolean starting_labels)
Create a new GncPeriodSelect widget which is used to select a accounting period like "previous month"...
void gnc_period_select_set_active(GncPeriodSelect *period, GncAccountingPeriod which)
Set which item in the GncPeriodSelect is initially selected.
A custom widget for selecting accounting periods.
void gnc_prefs_remove_cb_by_func(const gchar *group, const gchar *pref_name, gpointer func, gpointer user_data)
Remove a function that was registered for a callback when the given preference changed.