GncPeriodSelect: add gobject property active

That will allow a one on one mapping between a widget property
and a preference in the preferences backend in a future commit.

git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@23231 57a11ea4-9604-0410-9ed3-97b8803252fd
This commit is contained in:
Geert Janssens 2013-10-07 14:10:05 +00:00
parent dd0a9b1564
commit 336d3cb6fd
2 changed files with 59 additions and 22 deletions

View File

@ -45,6 +45,7 @@ enum
PROP_FY_END,
PROP_SHOW_DATE,
PROP_DATE_BASE,
PROP_PS_ACTIVE,
};
enum
@ -121,7 +122,7 @@ struct _GncPeriodSelectPrivate
/* Tells a GncPeriodSelect object to emit a "changed" signal.
*/
void
static void
gnc_period_select_changed (GncPeriodSelect *period)
{
g_return_if_fail(GNC_IS_PERIOD_SELECT(period));
@ -165,9 +166,8 @@ gnc_period_sample_update_date_label (GncPeriodSelect *period)
/** Handle the "changed" signal from the GtkComboBox that is embedded
* in this GncPeriodSelect object. When called, this function
* updates the feedback label embedded in the object, then generates
* another "changed" signal so that a developer can see that
* something in the object changed.
* 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.
*
@ -178,11 +178,10 @@ gnc_period_sample_combobox_changed (GtkComboBox *box, GncPeriodSelect *period)
{
g_return_if_fail(GNC_IS_PERIOD_SELECT(period));
/* Update this widget */
gnc_period_sample_update_date_label(period);
/* Pass it on... */
gnc_period_select_changed(period);
g_object_set (G_OBJECT (period),
"active",
gtk_combo_box_get_active (box),
NULL);
}
@ -208,6 +207,40 @@ gnc_period_sample_new_date_format (GConfEntry *unused,
/* Property Functions */
/************************************************************/
/* 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);
}
/** @name GncPeriodSelect Properties
@{ */
@ -413,6 +446,9 @@ gnc_period_select_get_property (GObject *object,
case PROP_DATE_BASE:
g_value_set_pointer(value, gnc_period_select_get_date_base(period));
break;
case PROP_PS_ACTIVE:
g_value_set_int(value, gnc_period_select_get_active(period));
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
break;
@ -447,6 +483,9 @@ gnc_period_select_set_property (GObject *object,
case PROP_DATE_BASE:
gnc_period_select_set_date_base(period, g_value_get_pointer(value));
break;
case PROP_PS_ACTIVE:
gnc_period_select_set_active_internal(period, g_value_get_int(value));
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
break;
@ -536,7 +575,7 @@ gnc_period_select_class_init (GncPeriodSelectClass *klass)
PROP_SHOW_DATE,
g_param_spec_boolean("show-date",
"Show Date",
"Show the start/end date of the accouting period in this widget",
"Show the start/end date of the accounting period in this widget",
FALSE,
G_PARAM_READWRITE));
g_object_class_install_property(gobject_class,
@ -545,6 +584,15 @@ gnc_period_select_class_init (GncPeriodSelectClass *klass)
"Date Base",
"The starting date to use for display calculations",
G_PARAM_READWRITE));
g_object_class_install_property(gobject_class,
PROP_PS_ACTIVE,
g_param_spec_int("active",
"Active period",
"The currently selected period in the list of periods",
-1,
G_MAXINT,
0,
G_PARAM_READWRITE));
g_type_class_add_private(klass, sizeof(GncPeriodSelectPrivate));
}
@ -689,15 +737,12 @@ void
gnc_period_select_set_active (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);
gtk_combo_box_set_active(GTK_COMBO_BOX(priv->selector), which);
g_object_set (G_OBJECT (period), "active", which, NULL);
}

View File

@ -65,14 +65,6 @@ typedef struct
GType gnc_period_select_get_type (void);
/** Tells a GncPeriodSelect object to emit a "changed" signal.
*
* @param period The GncPeriodSelect object that should emit the
* signal.
*/
void gnc_period_select_changed (GncPeriodSelect *period);
/** Create a new GncPeriodSelect widget which is used to select a
* accounting period like "previous month" or "this year".
*