From dd60c6238ffa4e3e48bdb35a8f9235b732607926 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Thu, 29 Jan 2009 12:44:17 -0600 Subject: Adding a property modified signal to the indicator object --- libindicate/indicator.c | 18 ++++++++++++++++-- libindicate/indicator.h | 2 ++ 2 files changed, 18 insertions(+), 2 deletions(-) (limited to 'libindicate') diff --git a/libindicate/indicator.c b/libindicate/indicator.c index f1eb6f3..94af726 100644 --- a/libindicate/indicator.c +++ b/libindicate/indicator.c @@ -9,6 +9,7 @@ enum { HIDE, SHOW, USER_DISPLAY, + MODIFIED, LAST_SIGNAL }; @@ -68,6 +69,13 @@ indicate_indicator_class_init (IndicateIndicatorClass * class) NULL, NULL, g_cclosure_marshal_VOID__VOID, G_TYPE_NONE, 0); + signals[MODIFIED] = g_signal_new(INDICATE_INDICATOR_SIGNAL_MODIFIED, + G_TYPE_FROM_CLASS(class), + G_SIGNAL_RUN_LAST, + G_STRUCT_OFFSET(IndicateIndicatorClass, modified), + NULL, NULL, + g_cclosure_marshal_VOID__STRING, + G_TYPE_NONE, 1, G_TYPE_STRING); class->get_type = NULL; class->set_property = set_property; @@ -235,8 +243,14 @@ set_property (IndicateIndicator * indicator, const gchar * key, const gchar * da IndicateIndicatorPrivate * priv = INDICATE_INDICATOR_GET_PRIVATE(indicator); - g_hash_table_insert(priv->properties, g_strdup(key), g_strdup(data)); - // TODO: Signal + gchar * current = g_hash_table_lookup(priv->properties, key); + if (current == NULL || strcmp(current, data)) { + /* If the value has changed or there is no value */ + gchar * newkey = g_strdup(key); + g_hash_table_insert(priv->properties, newkey, g_strdup(data)); + g_signal_emit(indicator, signals[MODIFIED], 0, newkey, TRUE); + } + return; } diff --git a/libindicate/indicator.h b/libindicate/indicator.h index 3fd7afd..8823757 100644 --- a/libindicate/indicator.h +++ b/libindicate/indicator.h @@ -21,6 +21,7 @@ G_BEGIN_DECLS #define INDICATE_INDICATOR_SIGNAL_HIDE "hide" #define INDICATE_INDICATOR_SIGNAL_SHOW "show" #define INDICATE_INDICATOR_SIGNAL_DISPLAY "user-display" +#define INDICATE_INDICATOR_SIGNAL_MODIFIED "modified" typedef struct _IndicateIndicator IndicateIndicator; typedef struct _IndicateIndicatorClass IndicateIndicatorClass; @@ -35,6 +36,7 @@ struct _IndicateIndicatorClass { void (*hide) (IndicateIndicator * indicator, gpointer data); void (*show) (IndicateIndicator * indicator, gpointer data); void (*user_display) (IndicateIndicator * indicator, gpointer data); + void (*modified) (IndicateIndicator * indicator, gchar * property, gpointer data); const gchar * (*get_type) (IndicateIndicator * indicator); void (*set_property) (IndicateIndicator * indicator, const gchar * key, const gchar * data); -- cgit v1.2.3