/* Get the current value of the fiscal year end setting from a * GncPeriodSelect widget. If the result is NULL then fiscal years * are not currently supported. */ GDate * gnc_period_select_get_fy_end (GncPeriodSelect *period) { GncPeriodSelectPrivate *priv; priv = GNC_PERIOD_SELECT_GET_PRIVATE(period); g_return_val_if_fail(period != NULL, NULL); g_return_val_if_fail(GNC_IS_PERIOD_SELECT(period), NULL); priv = GNC_PERIOD_SELECT_GET_PRIVATE(period); if (!priv->fy_end) return NULL; return g_date_new_dmy(g_date_get_day(priv->fy_end), g_date_get_month(priv->fy_end), G_DATE_BAD_YEAR); }
/** Finalize the GncPeriodSelect object. This function is called from * the G_Object level to complete the destruction of the object. It * should release any memory not previously released by the destroy * function (i.e. the private data structure), then chain up to the * parent's destroy function. * * @param object The object being destroyed. * * @internal */ static void gnc_period_select_finalize (GObject *object) { GncPeriodSelectPrivate *priv; GncPeriodSelect *period; g_return_if_fail (object != NULL); g_return_if_fail (GNC_IS_PERIOD_SELECT (object)); period = GNC_PERIOD_SELECT(object); priv = GNC_PERIOD_SELECT_GET_PRIVATE(period); /* Stop tracking changes to date formatting */ gnc_prefs_remove_cb_by_func (GNC_PREFS_GROUP_GENERAL, GNC_PREF_DATE_FORMAT, gnc_period_sample_new_date_format, period); /* The selector and date_label were added to the hbox. They will be * freed automatically. */ if (priv->fy_end) g_date_free(priv->fy_end); if (priv->date_base) g_date_free(priv->date_base); /* Do not free the private data structure. It is part of a larger * memory block allocated by the type system. */ if (G_OBJECT_CLASS(parent_class)->finalize) (* G_OBJECT_CLASS(parent_class)->finalize) (object); }
static void gnc_period_select_set_date_common (GncPeriodSelect *period, const GDate *date) { GncPeriodSelectPrivate *priv; priv = GNC_PERIOD_SELECT_GET_PRIVATE(period); if (date) { if (priv->date_base) g_date_free(priv->date_base); priv->date_base = g_date_new_dmy(g_date_get_day(date), g_date_get_month(date), g_date_get_year(date)); if (priv->date_label == NULL) { priv->date_align = gtk_alignment_new(0.5, 0.5, 0, 0); gtk_alignment_set_padding(GTK_ALIGNMENT(priv->date_align), 0, 0, 6, 0); gtk_box_pack_start(GTK_BOX(period), priv->date_align, TRUE, TRUE, 0); priv->date_label = gtk_label_new(""); gtk_container_add(GTK_CONTAINER(priv->date_align), priv->date_label); gtk_widget_show_all(priv->date_align); } gnc_period_sample_update_date_label(period); return; } if (priv->date_base) { g_date_free(priv->date_base); priv->date_base = NULL; gtk_widget_destroy(priv->date_align); priv->date_align = NULL; priv->date_label = NULL; } }
/* Set an item in the GncPeriodSelect to be the active one. * This will first update the internal GtkCombobox (blocking * its "changed" callback to prevent an infinite loop). * Then it will update the sample label and finally it will * emit a "changed" signal of it's own for other objects * listening for this signal. */ static void gnc_period_select_set_active_internal (GncPeriodSelect *period, GncAccountingPeriod which) { GncPeriodSelectPrivate *priv; g_return_if_fail(period != NULL); g_return_if_fail(GNC_IS_PERIOD_SELECT(period)); g_return_if_fail(which >= 0); g_return_if_fail(which < GNC_ACCOUNTING_PERIOD_LAST); priv = GNC_PERIOD_SELECT_GET_PRIVATE(period); g_signal_handlers_block_by_func(G_OBJECT(period), G_CALLBACK(gnc_period_sample_combobox_changed), period); gtk_combo_box_set_active(GTK_COMBO_BOX(priv->selector), which); g_signal_handlers_unblock_by_func(G_OBJECT(period), G_CALLBACK(gnc_period_sample_combobox_changed), period); /* Update this widget */ gnc_period_sample_update_date_label(period); /* Pass it on... */ gnc_period_select_changed(period); }
/** Update the user visible sample date label if it exists on this * widget. This label is for user feedback only. * * @param period The GncPeriodSelect object to update. */ static void gnc_period_sample_update_date_label (GncPeriodSelect *period) { GncPeriodSelectPrivate *priv; gchar time_string[MAX_DATE_LENGTH]; GDate *date; GncAccountingPeriod which; g_return_if_fail(GNC_IS_PERIOD_SELECT(period)); priv = GNC_PERIOD_SELECT_GET_PRIVATE(period); if (!priv->date_label) return; which = gtk_combo_box_get_active (GTK_COMBO_BOX (priv->selector)); if (which == -1) date = g_date_new_dmy (31, 7, 2013); else if (priv->start) date = gnc_accounting_period_start_gdate (which, priv->fy_end, priv->date_base); else date = gnc_accounting_period_end_gdate (which, priv->fy_end, priv->date_base); qof_print_gdate (time_string, MAX_DATE_LENGTH, date); gtk_label_set_label (GTK_LABEL(priv->date_label), time_string); g_date_free (date); }
/** Initialize a new instance of a gnucash accounting period selection * widget. This function allocates and initializes the object * private storage space. * * @param period The new object instance created by the object system. * * @internal */ static void gnc_period_select_init (GncPeriodSelect *period) { GncPeriodSelectPrivate *priv; priv = GNC_PERIOD_SELECT_GET_PRIVATE(period); priv->start = TRUE; }
/* Get the currently selected accounting period from a * GncPeriodSelect widget. This is used to retrieve the user's * selection in the form of an enum. */ GncAccountingPeriod gnc_period_select_get_active (GncPeriodSelect *period) { GncPeriodSelectPrivate *priv; g_return_val_if_fail(period != NULL, -1); g_return_val_if_fail(GNC_IS_PERIOD_SELECT(period), -1); priv = GNC_PERIOD_SELECT_GET_PRIVATE(period); return gtk_combo_box_get_active(GTK_COMBO_BOX(priv->selector)); }
/* Get the current value of the "show date" setting from a * GncPeriodSelect widget. */ gboolean gnc_period_select_get_show_date (GncPeriodSelect *period) { GncPeriodSelectPrivate *priv; g_return_val_if_fail(period != NULL, FALSE); g_return_val_if_fail(GNC_IS_PERIOD_SELECT(period), FALSE); priv = GNC_PERIOD_SELECT_GET_PRIVATE(period); return (priv->date_base != NULL); }
/** Initialize a new instance of a gnucash accounting period selection * widget. This function allocates and initializes the object * private storage space. * * @param period The new object instance created by the object system. * * @internal */ static void gnc_period_select_init (GncPeriodSelect *period) { GncPeriodSelectPrivate *priv; gtk_orientable_set_orientation (GTK_ORIENTABLE(period), GTK_ORIENTATION_HORIZONTAL); // Set the style context for this widget so it can be easily manipulated with css gnc_widget_set_style_context (GTK_WIDGET(period), "GncPeriodSelect"); priv = GNC_PERIOD_SELECT_GET_PRIVATE(period); priv->start = TRUE; }
GDate * gnc_period_select_get_date_base (GncPeriodSelect *period) { GncPeriodSelectPrivate *priv; g_return_val_if_fail(period != NULL, NULL); g_return_val_if_fail(GNC_IS_PERIOD_SELECT(period), NULL); priv = GNC_PERIOD_SELECT_GET_PRIVATE(period); if (!priv->date_base) return NULL; return g_date_new_dmy(g_date_get_day(priv->date_base), g_date_get_month(priv->date_base), g_date_get_year(priv->date_base)); }
/* Get the currently selected accounting period choice from a * GncPeriodSelect widget. This is used to retrieve the user's * selection in the form of a GDate. */ GDate * gnc_period_select_get_date (GncPeriodSelect *period) { GncPeriodSelectPrivate *priv; GncAccountingPeriod which; g_return_val_if_fail(period != NULL, 0); g_return_val_if_fail(GNC_IS_PERIOD_SELECT(period), 0); priv = GNC_PERIOD_SELECT_GET_PRIVATE(period); which = gtk_combo_box_get_active(GTK_COMBO_BOX(priv->selector)); if (which == -1) return NULL; if (priv->start) return gnc_accounting_period_start_gdate(which, priv->fy_end, priv->date_base); return gnc_accounting_period_end_gdate(which, priv->fy_end, priv->date_base); }
/* Set the fiscal year end on a GncPeriodSelect widget. If set to a * value other than NULL then widget will include fiscal accounting * period like "this fiscal year". */ void gnc_period_select_set_fy_end (GncPeriodSelect *period, const GDate *fy_end) { GncPeriodSelectPrivate *priv; const gchar *label; gint i; g_return_if_fail(period != NULL); g_return_if_fail(GNC_IS_PERIOD_SELECT(period)); priv = GNC_PERIOD_SELECT_GET_PRIVATE(period); if (priv->fy_end) g_date_free(priv->fy_end); if (fy_end) { priv->fy_end = g_date_new_dmy(g_date_get_day(fy_end), g_date_get_month(fy_end), G_DATE_BAD_YEAR); } else { priv->fy_end = NULL; } if (fy_end) { for (i = GNC_ACCOUNTING_PERIOD_CYEAR_LAST; i < GNC_ACCOUNTING_PERIOD_FYEAR_LAST; i++) { label = priv->start ? _(start_strings[i]) : _(end_strings[i]); gtk_combo_box_text_append_text(GTK_COMBO_BOX_TEXT(priv->selector), label); } } else { for (i = GNC_ACCOUNTING_PERIOD_FYEAR_LAST - 1; i >= GNC_ACCOUNTING_PERIOD_FYEAR_LAST; i--) { gtk_combo_box_text_remove(GTK_COMBO_BOX_TEXT(priv->selector), i); } } }
/* Create a new GncPeriodSelect widget which is used to select a * accounting period like "previous month" or "this year". * * @param starting_labels If set to TRUE then all the labels will * refer to the "Start of...". If FALSE, labels will refer to "End * of...". * * @return A GncPeriodSelect widget. */ GtkWidget * gnc_period_select_new (gboolean starting_labels) { GncPeriodSelectPrivate *priv; GncPeriodSelect *period; const gchar *label; gint i; period = g_object_new(GNC_TYPE_PERIOD_SELECT, NULL); /* Set up private data structures */ priv = GNC_PERIOD_SELECT_GET_PRIVATE(period); priv->selector = gtk_combo_box_text_new(); priv->start = starting_labels; /* Add the internal widgets to the hbox */ gtk_box_pack_start(GTK_BOX(period), priv->selector, TRUE, TRUE, 0); gtk_widget_show(priv->selector); /* Find out when the combo box changes */ g_signal_connect(G_OBJECT(priv->selector), "changed", G_CALLBACK(gnc_period_sample_combobox_changed), period); /* Build all the labels except the fiscal year labels */ for (i = 0; i < GNC_ACCOUNTING_PERIOD_CYEAR_LAST; i++) { label = starting_labels ? _(start_strings[i]) : _(end_strings[i]); gtk_combo_box_text_append_text(GTK_COMBO_BOX_TEXT(priv->selector), label); } /* Track changes to date formatting */ gnc_prefs_register_cb (GNC_PREFS_GROUP_GENERAL, GNC_PREF_DATE_FORMAT, gnc_period_sample_new_date_format, period); return GTK_WIDGET (period); }
static void gnc_period_select_set_date_common (GncPeriodSelect *period, const GDate *date) { GncPeriodSelectPrivate *priv; priv = GNC_PERIOD_SELECT_GET_PRIVATE(period); if (date) { if (priv->date_base) g_date_free(priv->date_base); priv->date_base = g_date_new_dmy(g_date_get_day(date), g_date_get_month(date), g_date_get_year(date)); if (priv->date_label == NULL) { priv->date_label = gtk_label_new(""); #if GTK_CHECK_VERSION(3,12,0) gtk_widget_set_margin_start (GTK_WIDGET(priv->date_label), 6); #else gtk_widget_set_margin_left (GTK_WIDGET(priv->date_label), 6); #endif gtk_box_pack_start(GTK_BOX(period), priv->date_label, TRUE, TRUE, 0); gtk_widget_show_all(priv->date_label); } gnc_period_sample_update_date_label(period); return; } if (priv->date_base) { g_date_free(priv->date_base); priv->date_base = NULL; gtk_widget_destroy(priv->date_label); priv->date_label = NULL; } }