aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--docs/reference/libindicate-decl.txt5
-rw-r--r--libindicate/indicator.c41
-rw-r--r--libindicate/indicator.h1
-rw-r--r--libindicate/listener.c84
-rw-r--r--libindicate/listener.h16
-rw-r--r--libindicate/server.c1
-rw-r--r--tests/im-client.c46
-rw-r--r--tests/listen-and-print.c53
8 files changed, 235 insertions, 12 deletions
diff --git a/docs/reference/libindicate-decl.txt b/docs/reference/libindicate-decl.txt
index 7143c16..b9657c5 100644
--- a/docs/reference/libindicate-decl.txt
+++ b/docs/reference/libindicate-decl.txt
@@ -124,6 +124,11 @@ IndicateIndicator * indicator, const gchar * key, const gchar * data
IndicateIndicator * indicator, const gchar * key, const GdkPixbuf * data
</FUNCTION>
<FUNCTION>
+<NAME>indicate_indicator_set_property_time</NAME>
+<RETURNS>void </RETURNS>
+IndicateIndicator * indicator, const gchar * key, GTimeVal * time
+</FUNCTION>
+<FUNCTION>
<NAME>indicate_indicator_get_property</NAME>
<RETURNS>const gchar *</RETURNS>
IndicateIndicator * indicator, const gchar * key
diff --git a/libindicate/indicator.c b/libindicate/indicator.c
index c6df80a..e4bae76 100644
--- a/libindicate/indicator.c
+++ b/libindicate/indicator.c
@@ -240,8 +240,45 @@ indicate_indicator_set_property (IndicateIndicator * indicator, const gchar * ke
void
indicate_indicator_set_property_icon (IndicateIndicator * indicator, const gchar * key, const GdkPixbuf * data)
{
+ if (!GDK_IS_PIXBUF(data)) {
+ g_warning("Invalide GdkPixbuf");
+ return;
+ }
+
+ GError * error = NULL;
+ gchar * png_data;
+ gsize png_data_len;
+
+ if (!gdk_pixbuf_save_to_buffer(data, &png_data, &png_data_len, "png", &error, NULL)) {
+ if (error == NULL) {
+ g_warning("Unable to create pixbuf data stream: %d", png_data_len);
+ } else {
+ g_warning("Unable to create pixbuf data stream: %s", error->message);
+ g_error_free(error);
+ error = NULL;
+ }
+
+ return;
+ }
+
+ gchar * prop_str = g_base64_encode(png_data, png_data_len);
+ indicate_indicator_set_property(indicator, key, prop_str);
+ g_free(prop_str);
+ g_free(png_data);
+ return;
+}
+
+void
+indicate_indicator_set_property_time (IndicateIndicator * indicator, const gchar * key, GTimeVal * time)
+{
+ gchar * timestr = g_time_val_to_iso8601(time);
+ if (timestr != NULL) {
+ indicate_indicator_set_property(indicator, key, timestr);
+ g_free(timestr);
+ }
+ return;
}
const gchar *
@@ -282,9 +319,11 @@ set_property (IndicateIndicator * indicator, const gchar * key, const gchar * da
if (current == NULL || strcmp(current, data)) {
/* If the value has changed or there is no value */
gchar * newkey = g_strdup(key);
+ /* g_debug("What is newkey? %s", newkey); */
g_hash_table_insert(priv->properties, newkey, g_strdup(data));
if (indicate_indicator_is_visible(indicator)) {
- g_signal_emit(indicator, signals[MODIFIED], 0, newkey, TRUE);
+ /* g_debug("Indicator property modified: %s %s", key, data); */
+ g_signal_emit(indicator, signals[MODIFIED], 0, key, TRUE);
}
}
diff --git a/libindicate/indicator.h b/libindicate/indicator.h
index 5423247..5faea3c 100644
--- a/libindicate/indicator.h
+++ b/libindicate/indicator.h
@@ -99,6 +99,7 @@ void indicate_indicator_user_display (IndicateIndicator * indicator);
/* Properties handling */
void indicate_indicator_set_property (IndicateIndicator * indicator, const gchar * key, const gchar * data);
void indicate_indicator_set_property_icon (IndicateIndicator * indicator, const gchar * key, const GdkPixbuf * data);
+void indicate_indicator_set_property_time (IndicateIndicator * indicator, const gchar * key, GTimeVal * time);
const gchar * indicate_indicator_get_property (IndicateIndicator * indicator, const gchar * key);
GPtrArray * indicate_indicator_list_properties (IndicateIndicator * indicator);
diff --git a/libindicate/listener.c b/libindicate/listener.c
index 4da6d59..b704236 100644
--- a/libindicate/listener.c
+++ b/libindicate/listener.c
@@ -650,14 +650,22 @@ proxy_indicators_free (gpointer data)
return;
}
+typedef enum _get_property_type get_property_type;
+enum _get_property_type {
+ PROPERTY_TYPE_STRING,
+ PROPERTY_TYPE_TIME,
+ PROPERTY_TYPE_ICON
+};
+
typedef struct _get_property_t get_property_t;
struct _get_property_t {
- indicate_listener_get_property_cb cb;
+ GCallback cb;
gpointer data;
IndicateListener * listener;
IndicateListenerServer * server;
IndicateListenerIndicator * indicator;
gchar * property;
+ get_property_type type;
};
static void
@@ -671,7 +679,54 @@ get_property_cb (DBusGProxy *proxy, char * OUT_value, GError *error, gpointer us
return;
}
- get_property_data->cb(get_property_data->listener, get_property_data->server, get_property_data->indicator, get_property_data->property, OUT_value, get_property_data->data);
+ switch (get_property_data->type) {
+ case PROPERTY_TYPE_STRING: {
+ indicate_listener_get_property_cb cb = (indicate_listener_get_property_cb)get_property_data->cb;
+ cb(get_property_data->listener, get_property_data->server, get_property_data->indicator, get_property_data->property, OUT_value, get_property_data->data);
+ break;
+ }
+ case PROPERTY_TYPE_ICON: {
+ indicate_listener_get_property_icon_cb cb = (indicate_listener_get_property_icon_cb)get_property_data->cb;
+
+ gsize length = 0;
+ guchar * icondata = g_base64_decode(OUT_value, &length);
+
+ GInputStream * input = g_memory_input_stream_new_from_data(icondata, length, NULL);
+ if (input == NULL) {
+ g_warning("Cound not create input stream from icon property data");
+ g_free(icondata);
+ break;
+ }
+
+ GError * error = NULL;
+ GdkPixbuf * icon = gdk_pixbuf_new_from_stream(input, NULL, &error);
+ if (icon != NULL) {
+ cb(get_property_data->listener, get_property_data->server, get_property_data->indicator, get_property_data->property, icon, get_property_data->data);
+ }
+
+ if (error != NULL) {
+ g_warning("Unable to build Pixbuf from icon data: %s", error->message);
+ g_error_free(error);
+ }
+
+ error = NULL;
+ g_input_stream_close(input, NULL, &error);
+ if (error != NULL) {
+ g_warning("Unable to close input stream: %s", error->message);
+ g_error_free(error);
+ }
+ g_free(icondata);
+ break;
+ }
+ case PROPERTY_TYPE_TIME: {
+ indicate_listener_get_property_time_cb cb = (indicate_listener_get_property_time_cb)get_property_data->cb;
+ GTimeVal time;
+ if (g_time_val_from_iso8601(OUT_value, &time)) {
+ cb(get_property_data->listener, get_property_data->server, get_property_data->indicator, get_property_data->property, &time, get_property_data->data);
+ }
+ break;
+ }
+ }
g_free(get_property_data->property);
g_free(get_property_data);
@@ -679,9 +734,10 @@ get_property_cb (DBusGProxy *proxy, char * OUT_value, GError *error, gpointer us
return;
};
-void
-indicate_listener_get_property (IndicateListener * listener, IndicateListenerServer * server, IndicateListenerIndicator * indicator, gchar * property, indicate_listener_get_property_cb callback, gpointer data)
+static void
+get_property_helper (IndicateListener * listener, IndicateListenerServer * server, IndicateListenerIndicator * indicator, gchar * property, GCallback callback, gpointer data, get_property_type prop_type)
{
+ /* g_debug("get_property_helper: %s %d", property, prop_type); */
/* TODO: Do we need to somehow refcount the server/indicator while we're waiting on this? */
IndicateListenerPrivate * priv = INDICATE_LISTENER_GET_PRIVATE(listener);
@@ -698,11 +754,30 @@ indicate_listener_get_property (IndicateListener * listener, IndicateListenerSer
get_property_data->server = server;
get_property_data->indicator = indicator;
get_property_data->property = g_strdup(property);
+ get_property_data->type = prop_type;
org_freedesktop_indicator_get_indicator_property_async (proxyt->proxy , INDICATE_LISTENER_INDICATOR_ID(indicator), property, get_property_cb, get_property_data);
return;
}
+void
+indicate_listener_get_property (IndicateListener * listener, IndicateListenerServer * server, IndicateListenerIndicator * indicator, gchar * property, indicate_listener_get_property_cb callback, gpointer data)
+{
+ return get_property_helper(listener, server, indicator, property, G_CALLBACK(callback), data, PROPERTY_TYPE_STRING);
+}
+
+void
+indicate_listener_get_property_time (IndicateListener * listener, IndicateListenerServer * server, IndicateListenerIndicator * indicator, gchar * property, indicate_listener_get_property_time_cb callback, gpointer data)
+{
+ return get_property_helper(listener, server, indicator, property, G_CALLBACK(callback), data, PROPERTY_TYPE_TIME);
+}
+
+void
+indicate_listener_get_property_icon (IndicateListener * listener, IndicateListenerServer * server, IndicateListenerIndicator * indicator, gchar * property, indicate_listener_get_property_icon_cb callback, gpointer data)
+{
+ return get_property_helper(listener, server, indicator, property, G_CALLBACK(callback), data, PROPERTY_TYPE_ICON);
+}
+
static void
listener_display_cb (DBusGProxy *proxy, GError *error, gpointer userdata)
{
@@ -819,3 +894,4 @@ indicate_listener_server_get_desktop (IndicateListener * listener, IndicateListe
{
return get_server_property(listener, server, callback, "desktop", data);
}
+
diff --git a/libindicate/listener.h b/libindicate/listener.h
index 3d8c7ef..ed40630 100644
--- a/libindicate/listener.h
+++ b/libindicate/listener.h
@@ -33,6 +33,8 @@ License version 3 and version 2.1 along with this program. If not, see
#include <glib.h>
#include <glib-object.h>
+#include <gdk-pixbuf/gdk-pixbuf.h>
+
#include "indicator.h"
#include "server.h"
@@ -79,6 +81,8 @@ struct _IndicateListenerClass {
GType indicate_listener_get_type (void) G_GNUC_CONST;
typedef void (*indicate_listener_get_property_cb) (IndicateListener * listener, IndicateListenerServer * server, IndicateListenerIndicator * indicator, gchar * property, gchar * propertydata, gpointer data);
+typedef void (*indicate_listener_get_property_time_cb) (IndicateListener * listener, IndicateListenerServer * server, IndicateListenerIndicator * indicator, gchar * property, GTimeVal * propertydata, gpointer data);
+typedef void (*indicate_listener_get_property_icon_cb) (IndicateListener * listener, IndicateListenerServer * server, IndicateListenerIndicator * indicator, gchar * property, GdkPixbuf * propertydata, gpointer data);
typedef void (*indicate_listener_get_server_property_cb) (IndicateListener * listener, IndicateListenerServer * server, gchar * value, gpointer data);
/* Create a new listener */
@@ -90,6 +94,18 @@ void indicate_listener_get_property (IndicateListener * l
gchar * property,
indicate_listener_get_property_cb callback,
gpointer data);
+void indicate_listener_get_property_time (IndicateListener * listener,
+ IndicateListenerServer * server,
+ IndicateListenerIndicator * indicator,
+ gchar * property,
+ indicate_listener_get_property_time_cb callback,
+ gpointer data);
+void indicate_listener_get_property_icon (IndicateListener * listener,
+ IndicateListenerServer * server,
+ IndicateListenerIndicator * indicator,
+ gchar * property,
+ indicate_listener_get_property_icon_cb callback,
+ gpointer data);
void indicate_listener_display (IndicateListener * listener,
IndicateListenerServer * server,
IndicateListenerIndicator * indicator);
diff --git a/libindicate/server.c b/libindicate/server.c
index 0c74376..ee20321 100644
--- a/libindicate/server.c
+++ b/libindicate/server.c
@@ -352,6 +352,7 @@ indicator_hide_cb (IndicateIndicator * indicator, IndicateServer * server)
static void
indicator_modified_cb (IndicateIndicator * indicator, gchar * property, IndicateServer * server)
{
+ /* g_debug("Indicator Modified: %d %s", indicate_indicator_get_id(indicator), property); */
g_signal_emit(server, signals[INDICATOR_MODIFIED], 0, indicate_indicator_get_id(indicator), property, TRUE);
}
diff --git a/tests/im-client.c b/tests/im-client.c
index db04b8e..3419a9d 100644
--- a/tests/im-client.c
+++ b/tests/im-client.c
@@ -23,6 +23,36 @@ with this program. If not, see <http://www.gnu.org/licenses/>.
#include "libindicate/server.h"
#include "libindicate/indicator-message.h"
+gchar * patha = "/usr/share/icons/hicolor/16x16/apps/empathy.png";
+gchar * pathb = "/usr/share/icons/hicolor/22x22/apps/empathy.png";
+gchar * lastpath = NULL;
+
+static gboolean
+timeout_cb (gpointer data)
+{
+ g_debug("Modifying properties");
+
+ IndicateIndicator * indicator = INDICATE_INDICATOR(data);
+
+ GTimeVal time;
+ g_get_current_time(&time);
+ indicate_indicator_set_property_time(INDICATE_INDICATOR(indicator), "time", &time);
+
+ if (lastpath == patha) {
+ lastpath = pathb;
+ } else {
+ lastpath = patha;
+ }
+
+ GdkPixbuf * pixbuf = gdk_pixbuf_new_from_file(lastpath, NULL);
+ g_return_val_if_fail(pixbuf != NULL, TRUE);
+
+ indicate_indicator_set_property_icon(INDICATE_INDICATOR(indicator), "icon", pixbuf);
+ g_object_unref(G_OBJECT(pixbuf));
+
+ return TRUE;
+}
+
static void
display (IndicateIndicator * indicator, gpointer data)
{
@@ -35,23 +65,25 @@ main (int argc, char ** argv)
g_type_init();
IndicateServer * server = indicate_server_ref_default();
- GValue value = {0};
- g_value_init(&value, G_TYPE_STRING);
- g_value_set_static_string(&value, "message.im");
- g_object_set_property(G_OBJECT(server), "type", &value);
+ indicate_server_set_type(server, "message.im");
+ indicate_server_set_desktop_file(server, "/usr/share/applications/empathy.desktop");
IndicateIndicatorMessage * indicator;
indicator = indicate_indicator_message_new();
indicate_indicator_set_property(INDICATE_INDICATOR(indicator), "subtype", "im");
- indicate_indicator_set_property(INDICATE_INDICATOR(indicator), "sender", "Ted Gould");
- indicate_indicator_set_property(INDICATE_INDICATOR(indicator), "time", "11:11");
+ indicate_indicator_set_property(INDICATE_INDICATOR(indicator), "sender", "IM Client Test");
+ GTimeVal time; g_get_current_time(&time);
+ indicate_indicator_set_property_time(INDICATE_INDICATOR(indicator), "time", &time);
indicate_indicator_show(INDICATE_INDICATOR(indicator));
- indicate_indicator_set_property(INDICATE_INDICATOR(indicator), "time", "11:12");
+ g_get_current_time(&time);
+ indicate_indicator_set_property_time(INDICATE_INDICATOR(indicator), "time", &time);
g_signal_connect(G_OBJECT(indicator), INDICATE_INDICATOR_SIGNAL_DISPLAY, G_CALLBACK(display), NULL);
+ g_timeout_add_seconds(180, timeout_cb, indicator);
+
g_main_loop_run(g_main_loop_new(NULL, FALSE));
return 0;
diff --git a/tests/listen-and-print.c b/tests/listen-and-print.c
index 6e1104d..a4c8c25 100644
--- a/tests/listen-and-print.c
+++ b/tests/listen-and-print.c
@@ -23,9 +23,61 @@ with this program. If not, see <http://www.gnu.org/licenses/>.
#include "libindicate/listener.h"
static void
+show_property_cb (IndicateListener * listener, IndicateListenerServer * server, IndicateListenerIndicator * indicator, gchar * property, gchar * propertydata, gpointer data)
+{
+ g_debug("Indicator Property: %s %d %s %s", INDICATE_LISTENER_SERVER_DBUS_NAME(server), INDICATE_LISTENER_INDICATOR_ID(indicator), property, propertydata);
+ return;
+}
+
+static void
+show_property_time_cb (IndicateListener * listener, IndicateListenerServer * server, IndicateListenerIndicator * indicator, gchar * property, GTimeVal * propertydata, gpointer data)
+{
+ time_t timet;
+ struct tm * structtm;
+
+ timet = propertydata->tv_sec;
+ structtm = localtime(&timet);
+
+ gchar timestring[80];
+ strftime(timestring, 80, "%I:%M", structtm);
+
+ g_debug("Indicator Property: %s %d %s %s", INDICATE_LISTENER_SERVER_DBUS_NAME(server), INDICATE_LISTENER_INDICATOR_ID(indicator), property, timestring);
+ return;
+}
+
+static void
+show_property_icon_cb (IndicateListener * listener, IndicateListenerServer * server, IndicateListenerIndicator * indicator, gchar * property, GdkPixbuf * propertydata, gpointer data)
+{
+ g_debug("Indicator Property: %s %d %s %dx%d", INDICATE_LISTENER_SERVER_DBUS_NAME(server), INDICATE_LISTENER_INDICATOR_ID(indicator), property, gdk_pixbuf_get_width(propertydata), gdk_pixbuf_get_height(propertydata));
+ g_object_unref(G_OBJECT(propertydata));
+ return;
+}
+
+static void
+show_property (IndicateListener * listener, IndicateListenerServer * server, IndicateListenerIndicator * indicator, gchar * property)
+{
+ if (!strcmp(property, "icon")) {
+ indicate_listener_get_property_icon(listener, server, indicator, property, show_property_icon_cb, NULL);
+ } else if (!strcmp(property, "time")) {
+ indicate_listener_get_property_time(listener, server, indicator, property, show_property_time_cb, NULL);
+ } else {
+ indicate_listener_get_property(listener, server, indicator, property, show_property_cb, NULL);
+ }
+
+ return;
+}
+
+static void
+get_properties (IndicateListener * listener, IndicateListenerServer * server, IndicateListenerIndicator * indicator)
+{
+ //TODO: Not in API yet.
+}
+
+static void
indicator_added (IndicateListener * listener, IndicateListenerServer * server, IndicateListenerIndicator * indicator, gchar * type, gpointer data)
{
g_debug("Indicator Added: %s %d %s", INDICATE_LISTENER_SERVER_DBUS_NAME(server), INDICATE_LISTENER_INDICATOR_ID(indicator), type);
+ get_properties(listener, server, indicator);
}
static void
@@ -38,6 +90,7 @@ static void
indicator_modified (IndicateListener * listener, IndicateListenerServer * server, IndicateListenerIndicator * indicator, gchar * type, gchar * property, gpointer data)
{
g_debug("Indicator Modified: %s %d %s %s", INDICATE_LISTENER_SERVER_DBUS_NAME(server), INDICATE_LISTENER_INDICATOR_ID(indicator), type, property);
+ show_property(listener, server, indicator, property);
}
static void