Add notification for property setters

This commit is contained in:
Gergely Polonkai 2014-08-11 13:21:26 +02:00
parent 6e736c9b87
commit 5d028b5e17

View File

@ -30,6 +30,7 @@ enum {
PROP_COUNTRY, PROP_COUNTRY,
PROP_CITY, PROP_CITY,
PROP_NOTE, PROP_NOTE,
PROP_LAST
}; };
typedef enum { typedef enum {
@ -42,6 +43,8 @@ G_DEFINE_QUARK(ag_chart_error_quark, ag_chart_error);
G_DEFINE_TYPE_WITH_PRIVATE(AgChart, ag_chart, GSWE_TYPE_MOMENT); G_DEFINE_TYPE_WITH_PRIVATE(AgChart, ag_chart, GSWE_TYPE_MOMENT);
static GParamSpec *properties[PROP_LAST];
#define ag_g_variant_unref(v) \ #define ag_g_variant_unref(v) \
if ((v) != NULL) { \ if ((v) != NULL) { \
g_variant_unref((v)); \ g_variant_unref((v)); \
@ -66,49 +69,56 @@ ag_chart_class_init(AgChartClass *klass)
gobject_class->get_property = ag_chart_get_property; gobject_class->get_property = ag_chart_get_property;
gobject_class->finalize = ag_chart_finalize; gobject_class->finalize = ag_chart_finalize;
g_object_class_install_property( properties[PROP_NAME] = g_param_spec_string(
gobject_class,
PROP_NAME,
g_param_spec_string(
"name", "name",
"Chart name", "Chart name",
"Name of the person on this chart", "Name of the person on this chart",
NULL, NULL,
G_PARAM_READWRITE G_PARAM_READWRITE
) );
g_object_class_install_property(
gobject_class,
PROP_NAME,
properties[PROP_NAME]
);
properties[PROP_COUNTRY] = g_param_spec_string(
"country",
"Country",
"Name of the country of birth",
NULL,
G_PARAM_READWRITE
); );
g_object_class_install_property( g_object_class_install_property(
gobject_class, gobject_class,
PROP_COUNTRY, PROP_COUNTRY,
g_param_spec_string( properties[PROP_COUNTRY]
"country",
"Country name",
"Name of the country of birth",
NULL,
G_PARAM_READWRITE
)
); );
g_object_class_install_property(
gobject_class, properties[PROP_CITY] = g_param_spec_string(
PROP_CITY,
g_param_spec_string(
"city", "city",
"City name", "City name",
"Name of the city of birth", "Name of the city of birth",
NULL, NULL,
G_PARAM_READWRITE G_PARAM_READWRITE
)
); );
g_object_class_install_property( g_object_class_install_property(
gobject_class, gobject_class,
PROP_NOTE, PROP_CITY,
g_param_spec_string( properties[PROP_CITY]
);
properties[PROP_NOTE] = g_param_spec_string(
"note", "note",
"Note", "Note",
"Chart notes", "Chart notes",
NULL, NULL,
G_PARAM_READWRITE G_PARAM_READWRITE
) );
g_object_class_install_property(
gobject_class,
PROP_NOTE,
properties[PROP_NOTE]
); );
} }
@ -388,6 +398,8 @@ ag_chart_set_name(AgChart *chart, const gchar *name)
} }
priv->name = g_strdup(name); priv->name = g_strdup(name);
g_object_notify_by_pspec(G_OBJECT(chart), properties[PROP_NAME]);
} }
gchar * gchar *
@ -408,6 +420,8 @@ ag_chart_set_country(AgChart *chart, const gchar *country)
} }
priv->country = g_strdup(country); priv->country = g_strdup(country);
g_object_notify_by_pspec(G_OBJECT(chart), properties[PROP_COUNTRY]);
} }
gchar * gchar *
@ -428,6 +442,8 @@ ag_chart_set_city(AgChart *chart, const gchar *city)
} }
priv->city = g_strdup(city); priv->city = g_strdup(city);
g_object_notify_by_pspec(G_OBJECT(chart), properties[PROP_CITY]);
} }
gchar * gchar *
@ -1868,6 +1884,8 @@ ag_chart_set_note(AgChart *chart, const gchar *note)
AgChartPrivate *priv = ag_chart_get_instance_private(chart); AgChartPrivate *priv = ag_chart_get_instance_private(chart);
priv->note = g_strdup(note); priv->note = g_strdup(note);
g_object_notify_by_pspec(G_OBJECT(chart), properties[PROP_NOTE]);
} }
const gchar *ag_chart_get_note(AgChart *chart) const gchar *ag_chart_get_note(AgChart *chart)