diff options
-rw-r--r-- | libindicate/indicator.c | 70 | ||||
-rw-r--r-- | libindicate/indicator.h | 7 |
2 files changed, 50 insertions, 27 deletions
diff --git a/libindicate/indicator.c b/libindicate/indicator.c index 8caf8e4..f1eb6f3 100644 --- a/libindicate/indicator.c +++ b/libindicate/indicator.c @@ -2,6 +2,7 @@ #include "glib.h" #include "glib/gmessages.h" #include "indicator.h" +#include "server.h" /* Signals */ enum { @@ -13,6 +14,18 @@ enum { static guint signals[LAST_SIGNAL] = { 0 }; +typedef struct _IndicateIndicatorPrivate IndicateIndicatorPrivate; +struct _IndicateIndicatorPrivate +{ + guint id; + gboolean is_visible; + IndicateServer * server; + GHashTable * properties; +}; + +#define INDICATE_INDICATOR_GET_PRIVATE(o) \ + (G_TYPE_INSTANCE_GET_PRIVATE ((o), INDICATE_TYPE_INDICATOR, IndicateIndicatorPrivate)) + G_DEFINE_TYPE (IndicateIndicator, indicate_indicator, G_TYPE_OBJECT); static void indicate_indicator_finalize (GObject * object); @@ -30,6 +43,8 @@ indicate_indicator_class_init (IndicateIndicatorClass * class) GObjectClass * gobj; gobj = G_OBJECT_CLASS(class); + g_type_class_add_private (class, sizeof (IndicateIndicatorPrivate)); + gobj->finalize = indicate_indicator_finalize; signals[USER_DISPLAY] = g_signal_new(INDICATE_INDICATOR_SIGNAL_DISPLAY, @@ -66,15 +81,16 @@ static void indicate_indicator_init (IndicateIndicator * indicator) { g_debug("Indicator Object Initialized."); + IndicateIndicatorPrivate * priv = INDICATE_INDICATOR_GET_PRIVATE(indicator); - indicator->is_visible = FALSE; + priv->is_visible = FALSE; - indicator->properties = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, g_free); + priv->properties = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, g_free); + priv->server = indicate_server_ref_default(); + priv->id = indicate_server_get_next_id(priv->server); - indicator->server = indicate_server_ref_default(); - indicator->id = indicate_server_get_next_id(indicator->server); - indicate_server_add_indicator(indicator->server, indicator); + indicate_server_add_indicator(priv->server, indicator); return; } @@ -83,10 +99,11 @@ static void indicate_indicator_finalize (GObject * obj) { IndicateIndicator * indicator = INDICATE_INDICATOR(obj); + IndicateIndicatorPrivate * priv = INDICATE_INDICATOR_GET_PRIVATE(indicator); - indicate_server_remove_indicator(indicator->server, indicator); - g_object_unref(indicator->server); - indicator->server = NULL; + indicate_server_remove_indicator(priv->server, indicator); + g_object_unref(priv->server); + priv->server = NULL; return; } @@ -101,15 +118,17 @@ indicate_indicator_new (void) void indicate_indicator_show (IndicateIndicator * indicator) { - if (indicator->is_visible) { + IndicateIndicatorPrivate * priv = INDICATE_INDICATOR_GET_PRIVATE(indicator); + + if (priv->is_visible) { return; } - if (indicator->server) { - indicate_server_show(indicator->server); + if (priv->server) { + indicate_server_show(priv->server); } - indicator->is_visible = TRUE; + priv->is_visible = TRUE; g_signal_emit(indicator, signals[SHOW], 0, TRUE); return; @@ -118,11 +137,13 @@ indicate_indicator_show (IndicateIndicator * indicator) void indicate_indicator_hide (IndicateIndicator * indicator) { - if (!indicator->is_visible) { + IndicateIndicatorPrivate * priv = INDICATE_INDICATOR_GET_PRIVATE(indicator); + + if (!priv->is_visible) { return; } - indicator->is_visible = FALSE; + priv->is_visible = FALSE; g_signal_emit(indicator, signals[HIDE], 0, TRUE); return; @@ -131,14 +152,17 @@ indicate_indicator_hide (IndicateIndicator * indicator) gboolean indicate_indicator_is_visible (IndicateIndicator * indicator) { - return indicator->is_visible; + g_return_val_if_fail(INDICATE_IS_INDICATOR(indicator), FALSE); + IndicateIndicatorPrivate * priv = INDICATE_INDICATOR_GET_PRIVATE(indicator); + return priv->is_visible; } guint indicate_indicator_get_id (IndicateIndicator * indicator) { g_return_val_if_fail(INDICATE_IS_INDICATOR(indicator), 0); - return indicator->id; + IndicateIndicatorPrivate * priv = INDICATE_INDICATOR_GET_PRIVATE(indicator); + return priv->id; } const gchar * @@ -157,7 +181,8 @@ indicate_indicator_get_indicator_type (IndicateIndicator * indicator) void indicate_indicator_user_display (IndicateIndicator * indicator) { - if (!indicator->is_visible) { + IndicateIndicatorPrivate * priv = INDICATE_INDICATOR_GET_PRIVATE(indicator); + if (!priv->is_visible) { return; } @@ -208,7 +233,9 @@ set_property (IndicateIndicator * indicator, const gchar * key, const gchar * da return; } - g_hash_table_insert(indicator->properties, g_strdup(key), g_strdup(data)); + IndicateIndicatorPrivate * priv = INDICATE_INDICATOR_GET_PRIVATE(indicator); + + g_hash_table_insert(priv->properties, g_strdup(key), g_strdup(data)); // TODO: Signal return; } @@ -222,16 +249,19 @@ get_property (IndicateIndicator * indicator, const gchar * key) return indicate_indicator_get_indicator_type(indicator); } + IndicateIndicatorPrivate * priv = INDICATE_INDICATOR_GET_PRIVATE(indicator); + // TODO: Think about whether we should be strdup'ing this. Seems like overkill, but might not be. - return (const gchar *)g_hash_table_lookup(indicator->properties, key); + return (const gchar *)g_hash_table_lookup(priv->properties, key); } static GPtrArray * list_properties (IndicateIndicator * indicator) { g_return_val_if_fail(INDICATE_IS_INDICATOR(indicator), g_ptr_array_new()); + IndicateIndicatorPrivate * priv = INDICATE_INDICATOR_GET_PRIVATE(indicator); - GList * keys = g_hash_table_get_keys(indicator->properties); + GList * keys = g_hash_table_get_keys(priv->properties); GPtrArray * properties = g_ptr_array_sized_new(g_list_length(keys) + 1); g_ptr_array_add(properties, g_strdup("type")); diff --git a/libindicate/indicator.h b/libindicate/indicator.h index 91f08a7..3fd7afd 100644 --- a/libindicate/indicator.h +++ b/libindicate/indicator.h @@ -25,15 +25,8 @@ G_BEGIN_DECLS typedef struct _IndicateIndicator IndicateIndicator; typedef struct _IndicateIndicatorClass IndicateIndicatorClass; -#include "server.h" - struct _IndicateIndicator { GObject parent; - - guint id; - gboolean is_visible; - IndicateServer * server; - GHashTable * properties; }; struct _IndicateIndicatorClass { |