aboutsummaryrefslogtreecommitdiff
path: root/libindicate/indicator.c
diff options
context:
space:
mode:
authorTed Gould <ted@canonical.com>2009-01-13 23:23:58 -0600
committerTed Gould <ted@canonical.com>2009-01-13 23:23:58 -0600
commitcb3ce99f56585ff6f4c5b9ca2fe1e6b1eb7a972c (patch)
tree1efd94e3f85836b7837448958c54789302a3aac9 /libindicate/indicator.c
parent4670fee8fe07e67098788396d4d124181d2ecd38 (diff)
downloadlibayatana-indicator-cb3ce99f56585ff6f4c5b9ca2fe1e6b1eb7a972c.tar.gz
libayatana-indicator-cb3ce99f56585ff6f4c5b9ca2fe1e6b1eb7a972c.tar.bz2
libayatana-indicator-cb3ce99f56585ff6f4c5b9ca2fe1e6b1eb7a972c.zip
Adding in some properties to the mix
Diffstat (limited to 'libindicate/indicator.c')
-rw-r--r--libindicate/indicator.c89
1 files changed, 89 insertions, 0 deletions
diff --git a/libindicate/indicator.c b/libindicate/indicator.c
index 5d45c93..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;
}
@@ -60,6 +68,10 @@ indicate_indicator_init (IndicateIndicator * indicator)
g_debug("Indicator Object Initialized.");
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);
@@ -152,3 +164,80 @@ indicate_indicator_user_display (IndicateIndicator * indicator)
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;
+}