aboutsummaryrefslogtreecommitdiff
path: root/libindicate/indicator.c
diff options
context:
space:
mode:
authorTed Gould <ted@canonical.com>2009-01-14 10:26:09 -0600
committerTed Gould <ted@canonical.com>2009-01-14 10:26:09 -0600
commit89bf87a36bb6e71b205d1d447d75dc0727065ff0 (patch)
tree25bc2e9aa7b2f2dc18e9df8cdf9d9e0a97e05026 /libindicate/indicator.c
parent71820cb18ffb779c39e15e758515c6bcad8ac455 (diff)
parentc14592279f3feaad53e397155ecc515e5623d940 (diff)
downloadlibayatana-indicator-89bf87a36bb6e71b205d1d447d75dc0727065ff0.tar.gz
libayatana-indicator-89bf87a36bb6e71b205d1d447d75dc0727065ff0.tar.bz2
libayatana-indicator-89bf87a36bb6e71b205d1d447d75dc0727065ff0.zip
Merging in code from yesterday. Got many of the functions working with
real IDs and making lists. The basis for all the properties stuff is there but it still needs a touch of fleshing out. Also a new test for debugging.
Diffstat (limited to 'libindicate/indicator.c')
-rw-r--r--libindicate/indicator.c103
1 files changed, 102 insertions, 1 deletions
diff --git a/libindicate/indicator.c b/libindicate/indicator.c
index e16492d..8caf8e4 100644
--- a/libindicate/indicator.c
+++ b/libindicate/indicator.c
@@ -16,6 +16,9 @@ static guint signals[LAST_SIGNAL] = { 0 };
G_DEFINE_TYPE (IndicateIndicator, indicate_indicator, G_TYPE_OBJECT);
static void indicate_indicator_finalize (GObject * object);
+static void set_property (IndicateIndicator * indicator, const gchar * key, const gchar * data);
+static const gchar * get_property (IndicateIndicator * indicator, const gchar * key);
+static GPtrArray * list_properties (IndicateIndicator * indicator);
/* Functions */
@@ -51,6 +54,11 @@ indicate_indicator_class_init (IndicateIndicatorClass * class)
g_cclosure_marshal_VOID__VOID,
G_TYPE_NONE, 0);
+ class->get_type = NULL;
+ class->set_property = set_property;
+ class->get_property = get_property;
+ class->list_properties = list_properties;
+
return;
}
@@ -59,10 +67,13 @@ indicate_indicator_init (IndicateIndicator * indicator)
{
g_debug("Indicator Object Initialized.");
- indicator->id = 0;
indicator->is_visible = FALSE;
+ indicator->properties = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, g_free);
+
+
indicator->server = indicate_server_ref_default();
+ indicator->id = indicate_server_get_next_id(indicator->server);
indicate_server_add_indicator(indicator->server, indicator);
return;
@@ -100,6 +111,8 @@ indicate_indicator_show (IndicateIndicator * indicator)
indicator->is_visible = TRUE;
g_signal_emit(indicator, signals[SHOW], 0, TRUE);
+
+ return;
}
void
@@ -111,6 +124,8 @@ indicate_indicator_hide (IndicateIndicator * indicator)
indicator->is_visible = FALSE;
g_signal_emit(indicator, signals[HIDE], 0, TRUE);
+
+ return;
}
gboolean
@@ -139,4 +154,90 @@ indicate_indicator_get_indicator_type (IndicateIndicator * indicator)
return NULL;
}
+void
+indicate_indicator_user_display (IndicateIndicator * indicator)
+{
+ if (!indicator->is_visible) {
+ return;
+ }
+
+ g_signal_emit(indicator, signals[USER_DISPLAY], 0, TRUE);
+ return;
+}
+
+void
+indicate_indicator_set_property (IndicateIndicator * indicator, const gchar * key, const gchar * data)
+{
+ IndicateIndicatorClass * class = INDICATE_INDICATOR_GET_CLASS(indicator);
+ if (class->set_property == NULL) {
+ return;
+ }
+
+ return class->set_property(indicator, key, data);
+}
+
+const gchar *
+indicate_indicator_get_property (IndicateIndicator * indicator, const gchar * key)
+{
+ IndicateIndicatorClass * class = INDICATE_INDICATOR_GET_CLASS(indicator);
+ if (class->get_property == NULL) {
+ return NULL;
+ }
+
+ return class->get_property(indicator, key);
+}
+
+GPtrArray *
+indicate_indicator_list_properties (IndicateIndicator * indicator)
+{
+ IndicateIndicatorClass * class = INDICATE_INDICATOR_GET_CLASS(indicator);
+ if (class->list_properties == NULL) {
+ return g_ptr_array_new();
+ }
+
+ return class->list_properties(indicator);
+}
+static void
+set_property (IndicateIndicator * indicator, const gchar * key, const gchar * data)
+{
+ g_return_if_fail(INDICATE_IS_INDICATOR(indicator));
+
+ if (key != NULL && !strcmp(key, "type")) {
+ g_warning("Trying to set the 'type' of an indicator which should be done through subclassing.");
+ return;
+ }
+
+ g_hash_table_insert(indicator->properties, g_strdup(key), g_strdup(data));
+ // TODO: Signal
+ return;
+}
+
+static const gchar *
+get_property (IndicateIndicator * indicator, const gchar * key)
+{
+ g_return_val_if_fail(INDICATE_IS_INDICATOR(indicator), NULL);
+
+ if (key != NULL && !strcmp(key, "type")) {
+ return indicate_indicator_get_indicator_type(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);
+}
+
+static GPtrArray *
+list_properties (IndicateIndicator * indicator)
+{
+ g_return_val_if_fail(INDICATE_IS_INDICATOR(indicator), g_ptr_array_new());
+
+ GList * keys = g_hash_table_get_keys(indicator->properties);
+ GPtrArray * properties = g_ptr_array_sized_new(g_list_length(keys) + 1);
+
+ g_ptr_array_add(properties, g_strdup("type"));
+ for (; keys != NULL; keys = keys->next) {
+ g_ptr_array_add(properties, g_strdup(keys->data));
+ }
+
+ return properties;
+}