From 55256284a380043320b61b0f5f38741b083e94ab Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Mon, 12 Jan 2009 23:14:09 -0600 Subject: Fleshing out more functions, we can now return a list of ids. Need to test with more. --- libindicate/server.c | 73 +++++++++++++++++++++++++++++++++++++++++++++++++--- libindicate/server.h | 4 +-- 2 files changed, 71 insertions(+), 6 deletions(-) diff --git a/libindicate/server.c b/libindicate/server.c index 48f1c71..f79c78e 100644 --- a/libindicate/server.c +++ b/libindicate/server.c @@ -33,7 +33,7 @@ static void indicate_server_finalize (GObject * obj); static gboolean get_desktop (IndicateServer * server, gchar ** desktop_path, GError **error); static gboolean get_indicator_count (IndicateServer * server, guint * count, GError **error); static gboolean get_indicator_count_by_type (IndicateServer * server, gchar * type, guint * count, GError **error); -static gboolean get_indicator_list (IndicateServer * server, guint ** indicators, GError ** error); +static gboolean get_indicator_list (IndicateServer * server, GArray ** indicators, GError ** error); static gboolean get_indicator_list_by_type (IndicateServer * server, gchar * type, guint ** indicators, GError ** error); static gboolean get_indicator_property (IndicateServer * server, guint id, gchar * property, gchar ** value, GError **error); static gboolean get_indicator_property_group (IndicateServer * server, guint id, gchar ** properties, gchar *** value, GError **error); @@ -223,7 +223,10 @@ indicate_server_set_default (IndicateServer * server) static gboolean get_desktop (IndicateServer * server, gchar ** desktop_path, GError **error) { - + if (server->path != NULL) { + // TODO: This might be a memory leak, check into that. + *desktop_path = g_strdup(server->path); + } return TRUE; } @@ -239,16 +242,69 @@ get_indicator_count (IndicateServer * server, guint * count, GError **error) return TRUE; } +typedef struct { + gchar * type; + guint count; +} count_by_t; + +static void +count_by_type (IndicateIndicator * indicator, count_by_t * cbt) +{ + g_return_if_fail(INDICATE_IS_INDICATOR(indicator)); + if (indicate_indicator_is_visible(indicator)) { + return; + } + + const gchar * type = indicate_indicator_get_indicator_type(indicator); + + if (type == NULL && cbt->type == NULL) { + cbt->count++; + } else if (type == NULL || cbt->type == NULL) { + } else if (!strcmp(type, cbt->type)) { + cbt->count++; + } + + return; +} + static gboolean get_indicator_count_by_type (IndicateServer * server, gchar * type, guint * count, GError **error) { + count_by_t cbt; + cbt.type = type; + cbt.count = 0; + + /* Handle the NULL string case as NULL itself, we're a big + boy language; we have pointers. */ + if (cbt.type != NULL && cbt.type[0] == '\0') { + cbt.type = NULL; + } + + g_slist_foreach(server->indicators, count_by_type, &cbt); + *count = cbt.count; return TRUE; } static gboolean -get_indicator_list (IndicateServer * server, guint ** indicators, GError ** error) +get_indicator_list (IndicateServer * server, GArray ** indicators, GError ** error) { + g_return_val_if_fail(INDICATE_IS_SERVER(server), TRUE); + + IndicateServerClass * class = INDICATE_SERVER_GET_CLASS(server); + g_return_val_if_fail(class->get_indicator_count != NULL, TRUE); + + *indicators = g_array_sized_new(FALSE, FALSE, sizeof(guint), g_slist_length(server->indicators) - server->num_hidden); + + GSList * iter; + int i; + for (iter = server->indicators, i = 0; iter != NULL; iter = iter->next, i++) { + IndicateIndicator * indicator = INDICATE_INDICATOR(iter->data); + if (indicate_indicator_is_visible(indicator)) { + guint id = indicate_indicator_get_id(indicator); + g_array_insert_val(*indicators, i, id); + } + } return TRUE; } @@ -305,6 +361,7 @@ indicate_server_get_desktop (IndicateServer * server, gchar ** desktop_path, GEr NO_GET_DESKTOP, "get_desktop function doesn't exist for this server class: %s", G_OBJECT_TYPE_NAME(server)); + return FALSE; } return TRUE; @@ -325,6 +382,7 @@ indicate_server_get_indicator_count (IndicateServer * server, guint * count, GEr NO_GET_INDICATOR_COUNT, "get_indicator_count function doesn't exist for this server class: %s", G_OBJECT_TYPE_NAME(server)); + return FALSE; } return TRUE; @@ -345,13 +403,14 @@ indicate_server_get_indicator_count_by_type (IndicateServer * server, gchar * ty NO_GET_INDICATOR_COUNT_BY_TYPE, "get_indicator_count_by_type function doesn't exist for this server class: %s", G_OBJECT_TYPE_NAME(server)); + return FALSE; } return TRUE; } gboolean -indicate_server_get_indicator_list (IndicateServer * server, guint ** indicators, GError ** error) +indicate_server_get_indicator_list (IndicateServer * server, GArray ** indicators, GError ** error) { IndicateServerClass * class = INDICATE_SERVER_GET_CLASS(server); @@ -365,6 +424,7 @@ indicate_server_get_indicator_list (IndicateServer * server, guint ** indicators NO_GET_INDICATOR_LIST, "get_indicator_list function doesn't exist for this server class: %s", G_OBJECT_TYPE_NAME(server)); + return FALSE; } return TRUE; @@ -385,6 +445,7 @@ indicate_server_get_indicator_list_by_type (IndicateServer * server, gchar * typ NO_GET_INDICATOR_LIST_BY_TYPE, "get_indicator_list_by_type function doesn't exist for this server class: %s", G_OBJECT_TYPE_NAME(server)); + return FALSE; } return TRUE; @@ -405,6 +466,7 @@ indicate_server_get_indicator_property (IndicateServer * server, guint id, gchar NO_GET_INDICATOR_PROPERTY, "get_indicator_property function doesn't exist for this server class: %s", G_OBJECT_TYPE_NAME(server)); + return FALSE; } return TRUE; @@ -425,6 +487,7 @@ indicate_server_get_indicator_property_group (IndicateServer * server, guint id, NO_GET_INDICATOR_PROPERTY_GROUP, "get_indicator_property_group function doesn't exist for this server class: %s", G_OBJECT_TYPE_NAME(server)); + return FALSE; } return TRUE; @@ -445,6 +508,7 @@ indicate_server_get_indicator_properties (IndicateServer * server, guint id, gch NO_GET_INDICATOR_PROPERTIES, "get_indicator_properties function doesn't exist for this server class: %s", G_OBJECT_TYPE_NAME(server)); + return FALSE; } return TRUE; @@ -465,6 +529,7 @@ indicate_server_show_indicator_to_user (IndicateServer * server, guint id, GErro NO_SHOW_INDICATOR_TO_USER, "show_indicator_to_user function doesn't exist for this server class: %s", G_OBJECT_TYPE_NAME(server)); + return FALSE; } return TRUE; diff --git a/libindicate/server.h b/libindicate/server.h index 486252c..8a61293 100644 --- a/libindicate/server.h +++ b/libindicate/server.h @@ -40,7 +40,7 @@ struct _IndicateServerClass { gboolean (*get_desktop) (IndicateServer * server, gchar ** desktop_path, GError **error); gboolean (*get_indicator_count) (IndicateServer * server, guint * count, GError **error); gboolean (*get_indicator_count_by_type) (IndicateServer * server, gchar * type, guint * count, GError **error); - gboolean (*get_indicator_list) (IndicateServer * server, guint ** indicators, GError ** error); + gboolean (*get_indicator_list) (IndicateServer * server, GArray ** indicators, GError ** error); gboolean (*get_indicator_list_by_type) (IndicateServer * server, gchar * type, guint ** indicators, GError ** error); gboolean (*get_indicator_property) (IndicateServer * server, guint id, gchar * property, gchar ** value, GError **error); gboolean (*get_indicator_property_group) (IndicateServer * server, guint id, gchar ** properties, gchar *** value, GError **error); @@ -75,7 +75,7 @@ void indicate_server_set_default (IndicateServer * server); gboolean indicate_server_get_desktop (IndicateServer * server, gchar ** desktop_path, GError **error); gboolean indicate_server_get_indicator_count (IndicateServer * server, guint * count, GError **error); gboolean indicate_server_get_indicator_count_by_type (IndicateServer * server, gchar * type, guint * count, GError **error); -gboolean indicate_server_get_indicator_list (IndicateServer * server, guint ** indicators, GError ** error); +gboolean indicate_server_get_indicator_list (IndicateServer * server, GArray ** indicators, GError ** error); gboolean indicate_server_get_indicator_list_by_type (IndicateServer * server, gchar * type, guint ** indicators, GError ** error); gboolean indicate_server_get_indicator_property (IndicateServer * server, guint id, gchar * property, gchar ** value, GError **error); gboolean indicate_server_get_indicator_property_group (IndicateServer * server, guint id, gchar ** properties, gchar *** value, GError **error); -- cgit v1.2.3 From 3dbe51dcc3772279ad0351fb9b1f183d288ec025 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Tue, 13 Jan 2009 13:38:12 -0600 Subject: Add a test to create a lot of indicators. --- libindicate/tests/Makefile.am | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/libindicate/tests/Makefile.am b/libindicate/tests/Makefile.am index 1fe4856..814a50b 100644 --- a/libindicate/tests/Makefile.am +++ b/libindicate/tests/Makefile.am @@ -1,6 +1,7 @@ noinst_PROGRAMS = \ - indicate-and-crash + indicate-and-crash \ + indicate-alot indicate_and_crash_SOURCES = \ indicate-and-crash.c @@ -12,3 +13,14 @@ indicate_and_crash_CFLAGS = \ indicate_and_crash_LDADD = \ ../libindicate.la \ $(LIBINDICATE_LIBS) + +indicate_alot_SOURCES = \ + indicate-alot.c + +indicate_alot_CFLAGS = \ + -I $(srcdir)/../.. \ + $(LIBINDICATE_CFLAGS) + +indicate_alot_LDADD = \ + ../libindicate.la \ + $(LIBINDICATE_LIBS) -- cgit v1.2.3 From bba89edeba9b17832b1f6971c603541ee5877c8c Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Tue, 13 Jan 2009 13:38:29 -0600 Subject: Return to crashing beauty --- libindicate/tests/indicate-and-crash.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libindicate/tests/indicate-and-crash.c b/libindicate/tests/indicate-and-crash.c index 3cf4428..44be76e 100644 --- a/libindicate/tests/indicate-and-crash.c +++ b/libindicate/tests/indicate-and-crash.c @@ -12,7 +12,7 @@ main (int argc, char ** argv) IndicateIndicator * indicator = indicate_indicator_new(); indicate_indicator_show(indicator); - //g_timeout_add_seconds(15, crashfunc, NULL); + g_timeout_add_seconds(15, crashfunc, NULL); g_main_loop_run(g_main_loop_new(NULL, FALSE)); -- cgit v1.2.3 From 0b4e54d7e08c652fd0468b307f0fe6eeb987a149 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Tue, 13 Jan 2009 13:43:32 -0600 Subject: Ah, we weren't checking if we were visible. Now things are better. --- libindicate/server.c | 7 +++++++ libindicate/server.h | 1 + 2 files changed, 8 insertions(+) diff --git a/libindicate/server.c b/libindicate/server.c index f79c78e..8878f69 100644 --- a/libindicate/server.c +++ b/libindicate/server.c @@ -96,6 +96,7 @@ indicate_server_init (IndicateServer * server) server->path = g_strdup("/org/freedesktop/indicate"); server->indicators = NULL; server->num_hidden = 0; + server->visible = FALSE; return; } @@ -126,6 +127,11 @@ indicate_server_error_quark (void) void indicate_server_show (IndicateServer * server) { + g_return_if_fail(INDICATE_IS_SERVER(server)); + + if (server->visible) + return; + DBusGConnection * connection; connection = dbus_g_bus_get(DBUS_BUS_SESSION, NULL); @@ -133,6 +139,7 @@ indicate_server_show (IndicateServer * server) dbus_g_connection_register_g_object(connection, server->path, G_OBJECT(server)); + server->visible = TRUE; return; } diff --git a/libindicate/server.h b/libindicate/server.h index e119cfd..3844b03 100644 --- a/libindicate/server.h +++ b/libindicate/server.h @@ -24,6 +24,7 @@ struct _IndicateServer { gchar * path; GSList * indicators; + gboolean visible; // TODO: Should have a more robust way to track this, but this'll work for now guint num_hidden; -- cgit v1.2.3 From f64b5d9528ff05508224d48652edbfde1d497243 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Tue, 13 Jan 2009 13:44:00 -0600 Subject: Forgot to actually add the test --- libindicate/tests/indicate-alot.c | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 libindicate/tests/indicate-alot.c diff --git a/libindicate/tests/indicate-alot.c b/libindicate/tests/indicate-alot.c new file mode 100644 index 0000000..bebf726 --- /dev/null +++ b/libindicate/tests/indicate-alot.c @@ -0,0 +1,24 @@ + +#include +#include "libindicate/indicator.h" + +#define ALOT 30 + + +int +main (int argc, char ** argv) +{ + g_type_init(); + + IndicateIndicator * indicators[ALOT]; + int i; + + for (i = 0; i < ALOT; i++) { + indicators[i] = indicate_indicator_new(); + indicate_indicator_show(indicators[i]); + } + + g_main_loop_run(g_main_loop_new(NULL, FALSE)); + + return 0; +} -- cgit v1.2.3 From 82dee9414fc6ae41006f1664c1be0636a15ca4dd Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Tue, 13 Jan 2009 14:18:47 -0600 Subject: Making it so that the indicators all have unique IDs --- libindicate/indicator.c | 3 +-- libindicate/server.c | 22 ++++++++++++++++++++++ libindicate/server.h | 3 +++ 3 files changed, 26 insertions(+), 2 deletions(-) diff --git a/libindicate/indicator.c b/libindicate/indicator.c index e16492d..8121ceb 100644 --- a/libindicate/indicator.c +++ b/libindicate/indicator.c @@ -59,10 +59,9 @@ indicate_indicator_init (IndicateIndicator * indicator) { g_debug("Indicator Object Initialized."); - indicator->id = 0; indicator->is_visible = FALSE; - indicator->server = indicate_server_ref_default(); + indicator->id = indicate_server_get_next_id(indicator->server); indicate_server_add_indicator(indicator->server, indicator); return; diff --git a/libindicate/server.c b/libindicate/server.c index 8878f69..8c0f956 100644 --- a/libindicate/server.c +++ b/libindicate/server.c @@ -39,6 +39,7 @@ static gboolean get_indicator_property (IndicateServer * server, guint id, gchar static gboolean get_indicator_property_group (IndicateServer * server, guint id, gchar ** properties, gchar *** value, GError **error); static gboolean get_indicator_properties (IndicateServer * server, guint id, gchar *** properties, GError **error); static gboolean show_indicator_to_user (IndicateServer * server, guint id, GError ** error); +static guint get_next_id (IndicateServer * server); /* Code */ static void @@ -84,6 +85,7 @@ indicate_server_class_init (IndicateServerClass * class) class->get_indicator_property_group = get_indicator_property_group; class->get_indicator_properties = get_indicator_properties; class->show_indicator_to_user = show_indicator_to_user; + class->get_next_id = get_next_id; return; } @@ -97,6 +99,7 @@ indicate_server_init (IndicateServer * server) server->indicators = NULL; server->num_hidden = 0; server->visible = FALSE; + server->current_id = 0; return; } @@ -144,6 +147,13 @@ indicate_server_show (IndicateServer * server) return; } +static guint +get_next_id (IndicateServer * server) +{ + server->current_id++; + return server->current_id; +} + static void indicator_show_cb (IndicateIndicator * indicator, IndicateServer * server) { @@ -542,3 +552,15 @@ indicate_server_show_indicator_to_user (IndicateServer * server, guint id, GErro return TRUE; } +guint +indicate_server_get_next_id (IndicateServer * server) +{ + IndicateServerClass * class = INDICATE_SERVER_GET_CLASS(server); + + if (class != NULL) { + return class->get_next_id (server); + } + + return 0; +} + diff --git a/libindicate/server.h b/libindicate/server.h index 3844b03..4eb45cb 100644 --- a/libindicate/server.h +++ b/libindicate/server.h @@ -25,6 +25,7 @@ struct _IndicateServer { gchar * path; GSList * indicators; gboolean visible; + guint current_id; // TODO: Should have a more robust way to track this, but this'll work for now guint num_hidden; @@ -49,6 +50,7 @@ struct _IndicateServerClass { gboolean (*get_indicator_property_group) (IndicateServer * server, guint id, gchar ** properties, gchar *** value, GError **error); gboolean (*get_indicator_properties) (IndicateServer * server, guint id, gchar *** properties, GError **error); gboolean (*show_indicator_to_user) (IndicateServer * server, guint id, GError ** error); + guint (*get_next_id) (IndicateServer * server); }; GType indicate_server_get_type (void) G_GNUC_CONST; @@ -70,6 +72,7 @@ void indicate_server_set_desktop_file (const gchar * path); void indicate_server_show (IndicateServer * server); void indicate_server_hide (IndicateServer * server); +guint indicate_server_get_next_id (IndicateServer * server); void indicate_server_add_indicator (IndicateServer * server, IndicateIndicator * indicator); void indicate_server_remove_indicator (IndicateServer * server, IndicateIndicator * indicator); -- cgit v1.2.3 From 1c7343c65ff2951229e028edaeffee25dd4482f9 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Tue, 13 Jan 2009 14:55:06 -0600 Subject: Man, a lot of work for messing up one explaination point. --- libindicate/indicator.c | 4 ++++ libindicate/server.c | 4 +++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/libindicate/indicator.c b/libindicate/indicator.c index 8121ceb..119a479 100644 --- a/libindicate/indicator.c +++ b/libindicate/indicator.c @@ -99,6 +99,8 @@ indicate_indicator_show (IndicateIndicator * indicator) indicator->is_visible = TRUE; g_signal_emit(indicator, signals[SHOW], 0, TRUE); + + return; } void @@ -110,6 +112,8 @@ indicate_indicator_hide (IndicateIndicator * indicator) indicator->is_visible = FALSE; g_signal_emit(indicator, signals[HIDE], 0, TRUE); + + return; } gboolean diff --git a/libindicate/server.c b/libindicate/server.c index 8c0f956..08b6849 100644 --- a/libindicate/server.c +++ b/libindicate/server.c @@ -268,11 +268,12 @@ static void count_by_type (IndicateIndicator * indicator, count_by_t * cbt) { g_return_if_fail(INDICATE_IS_INDICATOR(indicator)); - if (indicate_indicator_is_visible(indicator)) { + if (!indicate_indicator_is_visible(indicator)) { return; } const gchar * type = indicate_indicator_get_indicator_type(indicator); + /* g_debug("Looking for indicator of type '%s' and have type '%s'", cbt->type, type); */ if (type == NULL && cbt->type == NULL) { cbt->count++; @@ -287,6 +288,7 @@ count_by_type (IndicateIndicator * indicator, count_by_t * cbt) static gboolean get_indicator_count_by_type (IndicateServer * server, gchar * type, guint * count, GError **error) { + /* g_debug("get_indicator_count_by_type: '%s'", type); */ count_by_t cbt; cbt.type = type; cbt.count = 0; -- cgit v1.2.3 From 4670fee8fe07e67098788396d4d124181d2ecd38 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Tue, 13 Jan 2009 15:43:14 -0600 Subject: Adding in a display function and a list by type. --- libindicate/indicator.c | 9 +++++++++ libindicate/indicator.h | 2 ++ libindicate/server.c | 49 ++++++++++++++++++++++++++++++++++++++++++++++++- 3 files changed, 59 insertions(+), 1 deletion(-) diff --git a/libindicate/indicator.c b/libindicate/indicator.c index 119a479..5d45c93 100644 --- a/libindicate/indicator.c +++ b/libindicate/indicator.c @@ -142,4 +142,13 @@ 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; +} diff --git a/libindicate/indicator.h b/libindicate/indicator.h index 2a15e3b..45c4128 100644 --- a/libindicate/indicator.h +++ b/libindicate/indicator.h @@ -65,6 +65,8 @@ guint indicate_indicator_get_id (IndicateIndicator * indicator); * subclass and exported through this pretty function */ const gchar * indicate_indicator_get_indicator_type (IndicateIndicator * indicator); +void indicate_indicator_user_display (IndicateIndicator * indicator); + G_END_DECLS #endif /* INDICATE_INDICATOR_H_INCLUDED__ */ diff --git a/libindicate/server.c b/libindicate/server.c index 08b6849..01e9e35 100644 --- a/libindicate/server.c +++ b/libindicate/server.c @@ -13,6 +13,7 @@ enum { NO_GET_INDICATOR_PROPERTY_GROUP, NO_GET_INDICATOR_PROPERTIES, NO_SHOW_INDICATOR_TO_USER, + INVALID_INDICATOR_ID, LAST_ERROR }; @@ -331,6 +332,35 @@ get_indicator_list (IndicateServer * server, GArray ** indicators, GError ** err static gboolean get_indicator_list_by_type (IndicateServer * server, gchar * type, guint ** indicators, GError ** error) { + g_return_val_if_fail(INDICATE_IS_SERVER(server), TRUE); + + IndicateServerClass * class = INDICATE_SERVER_GET_CLASS(server); + g_return_val_if_fail(class->get_indicator_count != NULL, TRUE); + + if (type != NULL && type[0] == '\0') { + type = NULL; + } + + /* Can't be larger than this and it's not worth the reallocation + for the small number we have. The memory isn't worth the time. */ + *indicators = g_array_sized_new(FALSE, FALSE, sizeof(guint), g_slist_length(server->indicators) - server->num_hidden); + + GSList * iter; + int i; + for (iter = server->indicators, i = 0; iter != NULL; iter = iter->next) { + IndicateIndicator * indicator = INDICATE_INDICATOR(iter->data); + if (indicate_indicator_is_visible(indicator)) { + const gchar * itype = indicate_indicator_get_indicator_type(indicator); + guint id = indicate_indicator_get_id(indicator); + + if (type == NULL && itype == NULL) { + g_array_insert_val(*indicators, i++, id); + } else if (type == NULL || itype == NULL) { + } else if (!strcmp(type, itype)) { + g_array_insert_val(*indicators, i++, id); + } + } + } return TRUE; } @@ -359,8 +389,25 @@ get_indicator_properties (IndicateServer * server, guint id, gchar *** propertie static gboolean show_indicator_to_user (IndicateServer * server, guint id, GError ** error) { + g_return_val_if_fail(INDICATE_IS_SERVER(server), TRUE); - return TRUE; + GSList * iter; + for (iter = server->indicators; iter != NULL; iter = iter->next) { + IndicateIndicator * indicator = INDICATE_INDICATOR(iter->data); + if (indicate_indicator_get_id(indicator) == id) { + indicate_indicator_user_display(indicator); + return TRUE; + } + } + + if (error) { + g_set_error(error, + indicate_server_error_quark(), + INVALID_INDICATOR_ID, + "show_indicator_id can't be done on and invalid ID: %d", + id); + } + return FALSE; } -- cgit v1.2.3 From cb3ce99f56585ff6f4c5b9ca2fe1e6b1eb7a972c Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Tue, 13 Jan 2009 23:23:58 -0600 Subject: Adding in some properties to the mix --- libindicate/indicator.c | 89 +++++++++++++++++++++++++++++++++++++++++++++++++ libindicate/indicator.h | 9 +++++ 2 files changed, 98 insertions(+) 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; +} diff --git a/libindicate/indicator.h b/libindicate/indicator.h index 45c4128..91f08a7 100644 --- a/libindicate/indicator.h +++ b/libindicate/indicator.h @@ -33,6 +33,7 @@ struct _IndicateIndicator { guint id; gboolean is_visible; IndicateServer * server; + GHashTable * properties; }; struct _IndicateIndicatorClass { @@ -43,6 +44,9 @@ struct _IndicateIndicatorClass { void (*user_display) (IndicateIndicator * indicator, gpointer data); const gchar * (*get_type) (IndicateIndicator * indicator); + void (*set_property) (IndicateIndicator * indicator, const gchar * key, const gchar * data); + const gchar * (*get_property) (IndicateIndicator * indicator, const gchar * key); + GPtrArray * (*list_properties) (IndicateIndicator * indicator); }; GType indicate_indicator_get_type(void) G_GNUC_CONST; @@ -67,6 +71,11 @@ const gchar * indicate_indicator_get_indicator_type (IndicateIndicator * indicat void indicate_indicator_user_display (IndicateIndicator * indicator); +/* Properties handling */ +void indicate_indicator_set_property (IndicateIndicator * indicator, const gchar * key, const gchar * data); +const gchar * indicate_indicator_get_property (IndicateIndicator * indicator, const gchar * key); +GPtrArray * indicate_indicator_list_properties (IndicateIndicator * indicator); + G_END_DECLS #endif /* INDICATE_INDICATOR_H_INCLUDED__ */ -- cgit v1.2.3 From a72a4cec884ad2da923084c23e16cda6717c97b2 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Tue, 13 Jan 2009 23:24:39 -0600 Subject: Making the indicator lookup it's own function and trying it out in another function to get a property. --- libindicate/server.c | 52 +++++++++++++++++++++++++++++++++------------------- 1 file changed, 33 insertions(+), 19 deletions(-) diff --git a/libindicate/server.c b/libindicate/server.c index 01e9e35..41b8d56 100644 --- a/libindicate/server.c +++ b/libindicate/server.c @@ -365,10 +365,38 @@ get_indicator_list_by_type (IndicateServer * server, gchar * type, guint ** indi return TRUE; } +static IndicateIndicator * +get_indicator (IndicateServer * server, guint id, GError **error) +{ + g_return_val_if_fail(INDICATE_IS_SERVER(server), TRUE); + + GSList * iter; + for (iter = server->indicators; iter != NULL; iter = iter->next) { + IndicateIndicator * indicator = INDICATE_INDICATOR(iter->data); + if (indicate_indicator_get_id(indicator) == id) { + return indicator; + } + } + + if (error) { + g_set_error(error, + indicate_server_error_quark(), + INVALID_INDICATOR_ID, + "Invalid Indicator ID: %d", + id); + } + return NULL; +} + static gboolean get_indicator_property (IndicateServer * server, guint id, gchar * property, gchar ** value, GError **error) { + IndicateIndicator * indicator = get_indicator(server, id, error); + if (indicator == NULL) { + return FALSE; + } + *value = indicate_indicator_get_property(indicator, property); return TRUE; } @@ -376,38 +404,24 @@ static gboolean get_indicator_property_group (IndicateServer * server, guint id, gchar ** properties, gchar *** value, GError **error) { - return TRUE; } static gboolean get_indicator_properties (IndicateServer * server, guint id, gchar *** properties, GError **error) { - return TRUE; } static gboolean show_indicator_to_user (IndicateServer * server, guint id, GError ** error) { - g_return_val_if_fail(INDICATE_IS_SERVER(server), TRUE); - - GSList * iter; - for (iter = server->indicators; iter != NULL; iter = iter->next) { - IndicateIndicator * indicator = INDICATE_INDICATOR(iter->data); - if (indicate_indicator_get_id(indicator) == id) { - indicate_indicator_user_display(indicator); - return TRUE; - } + IndicateIndicator * indicator = get_indicator(server, id, error); + if (indicator == NULL) { + return FALSE; } - if (error) { - g_set_error(error, - indicate_server_error_quark(), - INVALID_INDICATOR_ID, - "show_indicator_id can't be done on and invalid ID: %d", - id); - } - return FALSE; + indicate_indicator_user_display(indicator); + return TRUE; } -- cgit v1.2.3 From c14592279f3feaad53e397155ecc515e5623d940 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Wed, 14 Jan 2009 10:11:17 -0600 Subject: Chaning the property list parameters to be pointer arrays. --- libindicate/server.c | 12 ++++++------ libindicate/server.h | 8 ++++---- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/libindicate/server.c b/libindicate/server.c index 41b8d56..fe32f57 100644 --- a/libindicate/server.c +++ b/libindicate/server.c @@ -37,8 +37,8 @@ static gboolean get_indicator_count_by_type (IndicateServer * server, gchar * ty static gboolean get_indicator_list (IndicateServer * server, GArray ** indicators, GError ** error); static gboolean get_indicator_list_by_type (IndicateServer * server, gchar * type, guint ** indicators, GError ** error); static gboolean get_indicator_property (IndicateServer * server, guint id, gchar * property, gchar ** value, GError **error); -static gboolean get_indicator_property_group (IndicateServer * server, guint id, gchar ** properties, gchar *** value, GError **error); -static gboolean get_indicator_properties (IndicateServer * server, guint id, gchar *** properties, GError **error); +static gboolean get_indicator_property_group (IndicateServer * server, guint id, GPtrArray * properties, GPtrArray ** value, GError **error); +static gboolean get_indicator_properties (IndicateServer * server, guint id, GPtrArray ** properties, GError **error); static gboolean show_indicator_to_user (IndicateServer * server, guint id, GError ** error); static guint get_next_id (IndicateServer * server); @@ -401,13 +401,13 @@ get_indicator_property (IndicateServer * server, guint id, gchar * property, gch } static gboolean -get_indicator_property_group (IndicateServer * server, guint id, gchar ** properties, gchar *** value, GError **error) +get_indicator_property_group (IndicateServer * server, guint id, GPtrArray * properties, GPtrArray ** value, GError **error) { } static gboolean -get_indicator_properties (IndicateServer * server, guint id, gchar *** properties, GError **error) +get_indicator_properties (IndicateServer * server, guint id, GPtrArray ** properties, GError **error) { } @@ -553,7 +553,7 @@ indicate_server_get_indicator_property (IndicateServer * server, guint id, gchar } gboolean -indicate_server_get_indicator_property_group (IndicateServer * server, guint id, gchar ** properties, gchar *** value, GError **error) +indicate_server_get_indicator_property_group (IndicateServer * server, guint id, GPtrArray * properties, GPtrArray ** value, GError **error) { IndicateServerClass * class = INDICATE_SERVER_GET_CLASS(server); @@ -574,7 +574,7 @@ indicate_server_get_indicator_property_group (IndicateServer * server, guint id, } gboolean -indicate_server_get_indicator_properties (IndicateServer * server, guint id, gchar *** properties, GError **error) +indicate_server_get_indicator_properties (IndicateServer * server, guint id, GPtrArray ** properties, GError **error) { IndicateServerClass * class = INDICATE_SERVER_GET_CLASS(server); diff --git a/libindicate/server.h b/libindicate/server.h index 4eb45cb..75a1ffb 100644 --- a/libindicate/server.h +++ b/libindicate/server.h @@ -47,8 +47,8 @@ struct _IndicateServerClass { gboolean (*get_indicator_list) (IndicateServer * server, GArray ** indicators, GError ** error); gboolean (*get_indicator_list_by_type) (IndicateServer * server, gchar * type, guint ** indicators, GError ** error); gboolean (*get_indicator_property) (IndicateServer * server, guint id, gchar * property, gchar ** value, GError **error); - gboolean (*get_indicator_property_group) (IndicateServer * server, guint id, gchar ** properties, gchar *** value, GError **error); - gboolean (*get_indicator_properties) (IndicateServer * server, guint id, gchar *** properties, GError **error); + gboolean (*get_indicator_property_group) (IndicateServer * server, guint id, GPtrArray * properties, GPtrArray ** value, GError **error); + gboolean (*get_indicator_properties) (IndicateServer * server, guint id, GPtrArray ** properties, GError **error); gboolean (*show_indicator_to_user) (IndicateServer * server, guint id, GError ** error); guint (*get_next_id) (IndicateServer * server); }; @@ -86,8 +86,8 @@ gboolean indicate_server_get_indicator_count_by_type (IndicateServer * server, g gboolean indicate_server_get_indicator_list (IndicateServer * server, GArray ** indicators, GError ** error); gboolean indicate_server_get_indicator_list_by_type (IndicateServer * server, gchar * type, guint ** indicators, GError ** error); gboolean indicate_server_get_indicator_property (IndicateServer * server, guint id, gchar * property, gchar ** value, GError **error); -gboolean indicate_server_get_indicator_property_group (IndicateServer * server, guint id, gchar ** properties, gchar *** value, GError **error); -gboolean indicate_server_get_indicator_properties (IndicateServer * server, guint id, gchar *** properties, GError **error); +gboolean indicate_server_get_indicator_property_group (IndicateServer * server, guint id, GPtrArray * properties, GPtrArray ** value, GError **error); +gboolean indicate_server_get_indicator_properties (IndicateServer * server, guint id, GPtrArray ** properties, GError **error); gboolean indicate_server_show_indicator_to_user (IndicateServer * server, guint id, GError ** error); G_END_DECLS -- cgit v1.2.3