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_copy (fy_end);
277 period->fy_end = NULL;
282 for (i = GNC_ACCOUNTING_PERIOD_CYEAR_LAST; i < GNC_ACCOUNTING_PERIOD_FYEAR_LAST; i++)
284 label = period->start ? _(start_strings[i]) : _(end_strings[i]);
285 gtk_combo_box_text_append_text(GTK_COMBO_BOX_TEXT(period->selector), label);
290 for (i = GNC_ACCOUNTING_PERIOD_FYEAR_LAST - 1; i >= GNC_ACCOUNTING_PERIOD_FYEAR_LAST; i--)
292 gtk_combo_box_text_remove(GTK_COMBO_BOX_TEXT(period->selector), i);
299 gnc_period_select_set_date_common (GncPeriodSelect *period,
const GDate *date)
303 if (period->date_base)
304 g_date_free(period->date_base);
305 period->date_base = g_date_new_dmy(g_date_get_day(date),
306 g_date_get_month(date),
307 g_date_get_year(date));
308 if (period->date_label == NULL)
310 period->date_label = gtk_label_new(
"");
311 gtk_widget_set_margin_start (GTK_WIDGET(period->date_label), 6);
312 gtk_box_pack_start(GTK_BOX(period), period->date_label, TRUE, TRUE, 0);
313 gtk_widget_show_all(period->date_label);
315 gnc_period_sample_update_date_label(period);
319 if (period->date_base)
321 g_date_free(period->date_base);
322 period->date_base = NULL;
323 gtk_widget_destroy(period->date_label);
324 period->date_label = NULL;
335 g_return_val_if_fail(period != NULL, FALSE);
336 g_return_val_if_fail(GNC_IS_PERIOD_SELECT(period), FALSE);
338 return (period->date_base != NULL);
350 g_return_if_fail(period != NULL);
351 g_return_if_fail(GNC_IS_PERIOD_SELECT(period));
355 g_date_clear(&date, 1);
357 gnc_period_select_set_date_common(period, &date);
361 gnc_period_select_set_date_common(period, NULL);
367 gnc_period_select_get_date_base (GncPeriodSelect *period)
369 g_return_val_if_fail(period != NULL, NULL);
370 g_return_val_if_fail(GNC_IS_PERIOD_SELECT(period), NULL);
372 if (!period->date_base)
374 return g_date_new_dmy(g_date_get_day(period->date_base),
375 g_date_get_month(period->date_base),
376 g_date_get_year(period->date_base));
384 gnc_period_select_set_date_base (GncPeriodSelect *period,
const GDate *date_base)
386 g_return_if_fail(period != NULL);
387 g_return_if_fail(GNC_IS_PERIOD_SELECT(period));
389 gnc_period_select_set_date_common(period, date_base);
401 gnc_period_select_get_property (GObject *
object,
406 GncPeriodSelect *period = GNC_PERIOD_SELECT(
object);
417 g_value_set_pointer(value, gnc_period_select_get_date_base(period));
423 G_OBJECT_WARN_INVALID_PROPERTY_ID(
object, prop_id, pspec);
438 gnc_period_select_set_property (GObject *
object,
443 GncPeriodSelect *period = GNC_PERIOD_SELECT(
object);
454 gnc_period_select_set_date_base(period, g_value_get_pointer(value));
457 gnc_period_select_set_active_internal(period, g_value_get_int(value));
460 G_OBJECT_WARN_INVALID_PROPERTY_ID(
object, prop_id, pspec);
484 gnc_period_select_class_init (GncPeriodSelectClass *klass)
486 GObjectClass *gobject_class;
488 gobject_class = G_OBJECT_CLASS(klass);
489 gobject_class->set_property = gnc_period_select_set_property;
490 gobject_class->get_property = gnc_period_select_get_property;
491 gobject_class->finalize = gnc_period_select_finalize;
494 signals[CHANGED] = g_signal_new(
"changed",
495 G_OBJECT_CLASS_TYPE (klass),
499 g_cclosure_marshal_VOID__VOID,
504 g_object_class_install_property(gobject_class,
506 g_param_spec_pointer(
"fy-end",
508 "The fiscal year to use for this widget",
510 g_object_class_install_property(gobject_class,
512 g_param_spec_boolean(
"show-date",
514 "Show the start/end date of the accounting period in this widget",
517 g_object_class_install_property(gobject_class,
519 g_param_spec_pointer(
"date-base",
521 "The starting date to use for display calculations",
523 g_object_class_install_property(gobject_class,
525 g_param_spec_int(
"active",
527 "The currently selected period in the list of periods",
543 gnc_period_select_init (GncPeriodSelect *period)
545 gtk_orientable_set_orientation (GTK_ORIENTABLE(period), GTK_ORIENTATION_HORIZONTAL);
548 gtk_widget_set_name (GTK_WIDGET(period),
"gnc-id-period-select");
550 period->start = TRUE;
565 gnc_period_select_finalize (GObject *
object)
567 GncPeriodSelect *period;
569 g_return_if_fail (
object != NULL);
570 g_return_if_fail (GNC_IS_PERIOD_SELECT (
object));
572 period = GNC_PERIOD_SELECT(
object);
576 gnc_period_sample_new_date_format, period);
581 g_date_free(period->fy_end);
582 if (period->date_base)
583 g_date_free(period->date_base);
588 G_OBJECT_CLASS(gnc_period_select_parent_class)->finalize (
object);
604 GncPeriodSelect *period;
608 period = g_object_new(GNC_TYPE_PERIOD_SELECT, NULL);
611 period->selector = gtk_combo_box_text_new();
612 period->start = starting_labels;
615 gtk_box_pack_start(GTK_BOX(period), period->selector, TRUE, TRUE, 0);
616 gtk_widget_show(period->selector);
619 g_signal_connect(G_OBJECT(period->selector),
"changed",
620 G_CALLBACK(gnc_period_sample_combobox_changed), period);
623 for (i = 0; i < GNC_ACCOUNTING_PERIOD_CYEAR_LAST; i++)
625 label = starting_labels ? _(start_strings[i]) : _(end_strings[i]);
626 gtk_combo_box_text_append_text(GTK_COMBO_BOX_TEXT(period->selector), label);
631 gnc_period_sample_new_date_format, period);
633 return GTK_WIDGET (period);
644 gchar *string1, gchar *string2,
645 gint int1, gint int2)
651 gtk_widget_show(widget);
670 g_return_if_fail(period != NULL);
671 g_return_if_fail(GNC_IS_PERIOD_SELECT(period));
672 g_return_if_fail(which >= 0);
673 g_return_if_fail(which < GNC_ACCOUNTING_PERIOD_LAST);
675 g_object_set (G_OBJECT (period),
"active", which, NULL);
686 g_return_val_if_fail(period != NULL, -1);
687 g_return_val_if_fail(GNC_IS_PERIOD_SELECT(period), -1);
689 return gtk_combo_box_get_active(GTK_COMBO_BOX(period->selector));
702 g_return_val_if_fail(period != NULL, 0);
703 g_return_val_if_fail(GNC_IS_PERIOD_SELECT(period), 0);
705 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.