Beispiel #1
0
/*  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);
}
Beispiel #2
0
/** 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);
}
Beispiel #3
0
/** 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);
}
Beispiel #4
0
/*  Tells a GncPeriodSelect object to emit a "changed" signal.
 */
static void
gnc_period_select_changed (GncPeriodSelect *period)
{
    g_return_if_fail(GNC_IS_PERIOD_SELECT(period));

    g_signal_emit(G_OBJECT(period), signals[CHANGED], 0);
}
Beispiel #5
0
/*  Set the base date used by a GncPeriodSelect widget.  All example
 *  dates presented by the widget will be computed from this date.
 */
void
gnc_period_select_set_date_base (GncPeriodSelect *period, const GDate *date_base)
{
    g_return_if_fail(period != NULL);
    g_return_if_fail(GNC_IS_PERIOD_SELECT(period));

    gnc_period_select_set_date_common(period, date_base);
}
Beispiel #6
0
/** Handle the "changed" signal from the GtkComboBox that is embedded
 *  in this GncPeriodSelect object.  When called, this function
 *  will delegate the actual update work to the GncPeriodSelect widget
 *  to do the necessary updates of internal widgets and state.
 *
 *  @param box The combo box that changed.
 *
 *  @param period The GncPeriodSelect containing the combo box.
 */
static void
gnc_period_sample_combobox_changed (GtkComboBox *box, GncPeriodSelect *period)
{
    g_return_if_fail(GNC_IS_PERIOD_SELECT(period));

    g_object_set (G_OBJECT (period),
                  "active",
                  gtk_combo_box_get_active (box),
                  NULL);
}
Beispiel #7
0
/*  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));
}
Beispiel #8
0
/*  Set which item in the GncPeriodSelect is initially selected.  This
 *  is used to set the initial selection before the widget is shown to
 *  the user.
 */
void
gnc_period_select_set_active (GncPeriodSelect *period,
                              GncAccountingPeriod which)
{
    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);

    g_object_set (G_OBJECT (period), "active", which, NULL);
}
Beispiel #9
0
/*  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);
}
Beispiel #10
0
/** Connect a GncPeriodSelect widget to its stored value in the preferences database.
 *
 *  @internal
 *
 *  @param period A pointer to the GncPeriodSelect that should be connected.
 */
static void
gnc_prefs_connect_period_select (GncPeriodSelect *period, const gchar *boxname )
{
    gchar *group, *pref;

    g_return_if_fail(GNC_IS_PERIOD_SELECT(period));

    gnc_prefs_split_widget_name (boxname, &group, &pref);

    gnc_prefs_bind (group, pref, G_OBJECT (period), "active");

    g_free (group);
    g_free (pref);
}
Beispiel #11
0
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));
}
Beispiel #12
0
/*  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);
}
Beispiel #13
0
/*  Set the "show date" setting on a GncPeriodSelect widget.  If set
 *  to TRUE then a GtkLabel will be used to show the date
 *  corresponding to the selected time period.
 */
void
gnc_period_select_set_show_date (GncPeriodSelect *period, const gboolean show_date)
{
    GDate date;

    g_return_if_fail(period != NULL);
    g_return_if_fail(GNC_IS_PERIOD_SELECT(period));

    if (show_date)
    {
        g_date_clear(&date, 1);
        gnc_gdate_set_time64(&date, gnc_time (NULL));
        gnc_period_select_set_date_common(period, &date);
    }
    else
    {
        gnc_period_select_set_date_common(period, NULL);
    }
}
Beispiel #14
0
/*  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);
}
Beispiel #15
0
/*  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);
        }
    }
}
Beispiel #16
0
/** Connect one dialog widget to the appropriate callback function for
 *  its type.
 *
 *  @internal
 *
 *  @param name The name of the widget.
 *
 *  @param widget A pointer to the widget.
 *
 *  @param dialog A pointer to the dialog.
 */
static void
gnc_prefs_connect_one (const gchar *name,
                       GtkWidget *widget,
                       gpointer user_data)
{
    /* These tests must be ordered from more specific widget to less
     * specific widget. */

    if (GTK_IS_FONT_BUTTON(widget))
    {
        DEBUG("  %s - entry", name);
        gnc_prefs_connect_font_button(GTK_FONT_BUTTON(widget));
    }
    else if (GTK_IS_RADIO_BUTTON(widget))
    {
        DEBUG("  %s - radio button", name);
        gnc_prefs_connect_radio_button(GTK_RADIO_BUTTON(widget));
    }
    else if (GTK_IS_CHECK_BUTTON(widget))
    {
        DEBUG("  %s - check button", name);
        gnc_prefs_connect_check_button(GTK_CHECK_BUTTON(widget));
    }
    else if (GTK_IS_SPIN_BUTTON(widget))
    {
        DEBUG("  %s - spin button", name);
        gnc_prefs_connect_spin_button(GTK_SPIN_BUTTON(widget));
    }
    else if (GTK_IS_COMBO_BOX(widget))
    {
        DEBUG("  %s - combo box", name);
        gnc_prefs_connect_combo_box(GTK_COMBO_BOX(widget));
    }
    else if (GTK_IS_ENTRY(widget))
    {
        DEBUG("  %s - entry", name);
        gnc_prefs_connect_entry(GTK_ENTRY(widget));
    }
    else if (GTK_IS_HBOX(widget))
    {
        /* Test custom widgets are all children of a hbox */
        GtkWidget *widget_child;
        GList* child = gtk_container_get_children(GTK_CONTAINER(widget));
        widget_child = child->data;
        g_list_free(child);
        DEBUG("  %s - hbox", name);
        DEBUG("Hbox widget type is %s and name is %s", gtk_widget_get_name(GTK_WIDGET(widget_child)), name);

        if (GNC_IS_CURRENCY_EDIT(widget_child))
        {
            DEBUG("  %s - currency_edit", name);
            gnc_prefs_connect_currency_edit(GNC_CURRENCY_EDIT(widget_child), name );
        }
        else if (GNC_IS_PERIOD_SELECT(widget_child))
        {
            DEBUG("  %s - period_Select", name);
            gnc_prefs_connect_period_select(GNC_PERIOD_SELECT(widget_child), name );
        }
        else if (GNC_IS_DATE_EDIT(widget_child))
        {
            DEBUG("  %s - date_edit", name);
            gnc_prefs_connect_date_edit(GNC_DATE_EDIT(widget_child), name );
        }
    }
    else
    {
        DEBUG("  %s - unsupported %s", name,
              G_OBJECT_TYPE_NAME(G_OBJECT(widget)));
    }
}