aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--libindicate/indicator.c39
-rw-r--r--libindicate/indicator.h7
-rw-r--r--libindicate/server.c36
-rw-r--r--libindicate/server.h3
4 files changed, 83 insertions, 2 deletions
diff --git a/libindicate/indicator.c b/libindicate/indicator.c
index a319af2..e16492d 100644
--- a/libindicate/indicator.c
+++ b/libindicate/indicator.c
@@ -1,5 +1,6 @@
#include "glib.h"
+#include "glib/gmessages.h"
#include "indicator.h"
/* Signals */
@@ -59,6 +60,7 @@ indicate_indicator_init (IndicateIndicator * indicator)
g_debug("Indicator Object Initialized.");
indicator->id = 0;
+ indicator->is_visible = FALSE;
indicator->server = indicate_server_ref_default();
indicate_server_add_indicator(indicator->server, indicator);
@@ -88,16 +90,53 @@ indicate_indicator_new (void)
void
indicate_indicator_show (IndicateIndicator * indicator)
{
+ if (indicator->is_visible) {
+ return;
+ }
+
if (indicator->server) {
indicate_server_show(indicator->server);
}
+ indicator->is_visible = TRUE;
g_signal_emit(indicator, signals[SHOW], 0, TRUE);
}
void
indicate_indicator_hide (IndicateIndicator * indicator)
{
+ if (!indicator->is_visible) {
+ return;
+ }
+
+ indicator->is_visible = FALSE;
g_signal_emit(indicator, signals[HIDE], 0, TRUE);
}
+gboolean
+indicate_indicator_is_visible (IndicateIndicator * indicator)
+{
+ return indicator->is_visible;
+}
+
+guint
+indicate_indicator_get_id (IndicateIndicator * indicator)
+{
+ g_return_val_if_fail(INDICATE_IS_INDICATOR(indicator), 0);
+ return indicator->id;
+}
+
+const gchar *
+indicate_indicator_get_indicator_type (IndicateIndicator * indicator)
+{
+ g_return_val_if_fail(INDICATE_IS_INDICATOR(indicator), NULL);
+ IndicateIndicatorClass * class = INDICATE_INDICATOR_GET_CLASS(indicator);
+
+ if (class->get_type != NULL) {
+ return INDICATE_INDICATOR_GET_CLASS(indicator)->get_type(indicator);
+ }
+
+ return NULL;
+}
+
+
diff --git a/libindicate/indicator.h b/libindicate/indicator.h
index cfa93aa..3c8efc8 100644
--- a/libindicate/indicator.h
+++ b/libindicate/indicator.h
@@ -11,7 +11,7 @@
#define INDICATE_IS_INDICATOR(object) (G_TYPE_CHECK_INSTANCE_TYPE((object), INDICATE_TYPE_INDICATOR))
#define INDICATE_INDICATOR_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), INDICATE_TYPE_INDICATOR, IndicateIndicatorClass))
#define INDICATE_IS_INDICATOR_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), INDICATE_TYPE_INDICATOR))
-#define INDICATE_INDICATOR_GET_CLASS(object) (G_TYPE_INSTANCE_GET_CLASS((object), INDICATE_TYPE_INDICATOR, IndicateIndicatorCLass))
+#define INDICATE_INDICATOR_GET_CLASS(object) (G_TYPE_INSTANCE_GET_CLASS((object), INDICATE_TYPE_INDICATOR, IndicateIndicatorClass))
/* This is a signal that signals to the indicator that the user
* has done an action where they'd like this indicator to be
@@ -29,6 +29,7 @@ struct _IndicateIndicator {
GObject parent;
guint id;
+ gboolean is_visible;
IndicateServer * server;
};
@@ -39,7 +40,7 @@ struct _IndicateIndicatorClass {
void (*show) (IndicateIndicator * indicator, gpointer data);
void (*user_display) (IndicateIndicator * indicator, gpointer data);
- gchar * (*get_type) (IndicateIndicator * indicator);
+ const gchar * (*get_type) (IndicateIndicator * indicator);
};
IndicateIndicator * indicate_indicator_new (void);
@@ -51,6 +52,8 @@ void indicate_indicator_set_property (IndicateIndicator * indicator, const gchar
void indicate_indicator_show (IndicateIndicator * indicator);
void indicate_indicator_hide (IndicateIndicator * indicator);
+gboolean indicate_indicator_is_visible (IndicateIndicator * indicator);
+
/* Every entry has an ID, here's how to get it */
guint indicate_indicator_get_id (IndicateIndicator * indicator);
diff --git a/libindicate/server.c b/libindicate/server.c
index 95c0a2c..17db3dc 100644
--- a/libindicate/server.c
+++ b/libindicate/server.c
@@ -95,6 +95,7 @@ indicate_server_init (IndicateServer * server)
server->path = g_strdup("/org/freedesktop/indicate");
server->indicators = NULL;
+ server->num_hidden = 0;
return;
}
@@ -136,11 +137,37 @@ indicate_server_show (IndicateServer * server)
return;
}
+static void
+indicator_show_cb (IndicateIndicator * indicator, IndicateServer * server)
+{
+ server->num_hidden--;
+ g_signal_emit(server, signals[INDICATOR_ADDED], 0, indicate_indicator_get_id(indicator), indicate_indicator_get_indicator_type(indicator), TRUE);
+ return;
+}
+
+static void
+indicator_hide_cb (IndicateIndicator * indicator, IndicateServer * server)
+{
+ server->num_hidden++;
+ g_signal_emit(server, signals[INDICATOR_REMOVED], 0, indicate_indicator_get_id(indicator), indicate_indicator_get_indicator_type(indicator), TRUE);
+ return;
+}
+
void
indicate_server_add_indicator (IndicateServer * server, IndicateIndicator * indicator)
{
g_object_ref(indicator);
server->indicators = g_slist_prepend(server->indicators, indicator);
+
+ if (!indicate_indicator_is_visible(indicator)) {
+ server->num_hidden++;
+ } else {
+ g_signal_emit(server, signals[INDICATOR_ADDED], 0, indicate_indicator_get_id(indicator), indicate_indicator_get_indicator_type(indicator), TRUE);
+ }
+
+ g_signal_connect(indicator, INDICATE_INDICATOR_SIGNAL_SHOW, indicator_show_cb, server);
+ g_signal_connect(indicator, INDICATE_INDICATOR_SIGNAL_HIDE, indicator_hide_cb, server);
+
return;
}
@@ -148,6 +175,15 @@ void
indicate_server_remove_indicator (IndicateServer * server, IndicateIndicator * indicator)
{
server->indicators = g_slist_remove(server->indicators, indicator);
+ if (indicate_indicator_is_visible(indicator)) {
+ g_signal_emit(server, signals[INDICATOR_REMOVED], 0, indicate_indicator_get_id(indicator), indicate_indicator_get_indicator_type(indicator), TRUE);
+ } else {
+ server->num_hidden--;
+ }
+
+ g_signal_handlers_disconnect_by_func(indicator, indicator_show_cb, server);
+ g_signal_handlers_disconnect_by_func(indicator, indicator_hide_cb, server);
+
g_object_unref(indicator);
return;
}
diff --git a/libindicate/server.h b/libindicate/server.h
index 78c4d4b..486252c 100644
--- a/libindicate/server.h
+++ b/libindicate/server.h
@@ -22,6 +22,9 @@ struct _IndicateServer {
gchar * path;
GSList * indicators;
+
+ // TODO: Should have a more robust way to track this, but this'll work for now
+ guint num_hidden;
};
typedef struct _IndicateServerClass IndicateServerClass;