r23231 - gnucash/trunk/src/gnome-utils - GncPeriodSelect: add gobject property active
Geert Janssens
gjanssens at code.gnucash.org
Mon Oct 7 10:10:05 EDT 2013
Author: gjanssens
Date: 2013-10-07 10:10:05 -0400 (Mon, 07 Oct 2013)
New Revision: 23231
Trac: http://svn.gnucash.org/trac/changeset/23231
Modified:
gnucash/trunk/src/gnome-utils/gnc-period-select.c
gnucash/trunk/src/gnome-utils/gnc-period-select.h
Log:
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.
Modified: gnucash/trunk/src/gnome-utils/gnc-period-select.c
===================================================================
--- gnucash/trunk/src/gnome-utils/gnc-period-select.c 2013-10-07 14:09:42 UTC (rev 23230)
+++ gnucash/trunk/src/gnome-utils/gnc-period-select.c 2013-10-07 14:10:05 UTC (rev 23231)
@@ -45,6 +45,7 @@
PROP_FY_END,
PROP_SHOW_DATE,
PROP_DATE_BASE,
+ PROP_PS_ACTIVE,
};
enum
@@ -121,7 +122,7 @@
/* 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 @@
/** 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 @@
{
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 @@
/* 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 @@
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 @@
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 @@
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 @@
"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 @@
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);
}
Modified: gnucash/trunk/src/gnome-utils/gnc-period-select.h
===================================================================
--- gnucash/trunk/src/gnome-utils/gnc-period-select.h 2013-10-07 14:09:42 UTC (rev 23230)
+++ gnucash/trunk/src/gnome-utils/gnc-period-select.h 2013-10-07 14:10:05 UTC (rev 23231)
@@ -65,14 +65,6 @@
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".
*
More information about the gnucash-changes
mailing list