diff options
author | Ted Gould <ted@canonical.com> | 2009-01-29 09:59:19 -0600 |
---|---|---|
committer | Ted Gould <ted@canonical.com> | 2009-01-29 09:59:19 -0600 |
commit | c0a32384fac2c236dca7bb5681e3584bc469d596 (patch) | |
tree | 21cd34de52253f7223969d30639de175600d9df5 /libindicate/indicator.c | |
parent | d898b213ea8ffd0b09b2c630c47cda386b4977df (diff) | |
download | libayatana-indicator-c0a32384fac2c236dca7bb5681e3584bc469d596.tar.gz libayatana-indicator-c0a32384fac2c236dca7bb5681e3584bc469d596.tar.bz2 libayatana-indicator-c0a32384fac2c236dca7bb5681e3584bc469d596.zip |
Making the indicator properties private, they should be. Also cleans
up some deps.
Diffstat (limited to 'libindicate/indicator.c')
-rw-r--r-- | libindicate/indicator.c | 70 |
1 files changed, 50 insertions, 20 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")); |