diff options
Diffstat (limited to 'libindicate-gtk')
-rw-r--r-- | libindicate-gtk/Makefile.am | 71 | ||||
-rw-r--r-- | libindicate-gtk/indicate-gtk.pc.in | 14 | ||||
-rw-r--r-- | libindicate-gtk/indicator.c | 74 | ||||
-rw-r--r-- | libindicate-gtk/indicator.h | 44 | ||||
-rw-r--r-- | libindicate-gtk/listener.c | 148 | ||||
-rw-r--r-- | libindicate-gtk/listener.h | 57 |
6 files changed, 408 insertions, 0 deletions
diff --git a/libindicate-gtk/Makefile.am b/libindicate-gtk/Makefile.am new file mode 100644 index 0000000..7d3206d --- /dev/null +++ b/libindicate-gtk/Makefile.am @@ -0,0 +1,71 @@ + +INCLUDES= \ + -DG_LOG_DOMAIN=\"libindicate-gtk\" + +EXTRA_DIST = \ + indicate-gtk.pc.in + +lib_LTLIBRARIES = \ + libindicate-gtk.la + +libindicate_gtkincludedir=$(includedir)/libindicate-0.1/libindicate-gtk + +indicate_gtk_headers = \ + indicator.h \ + listener.h + +libindicate_gtkinclude_HEADERS = \ + $(indicate_gtk_headers) + +libindicate_gtk_la_SOURCES = \ + $(indicate_gtk_headers) \ + indicator.c \ + listener.c + +libindicate_gtk_la_LDFLAGS = \ + -version-info $(LIBINDICATEGTK_CURRENT):$(LIBINDICATEGTK_REVISION):$(LIBINDICATEGTK_AGE) \ + -no-undefined \ + -export-symbols-regex "^[^_d].*" + +libindicate_gtk_la_CFLAGS = \ + -I $(srcdir)/.. \ + $(LIBINDICATEGTK_CFLAGS) + +libindicate_gtk_la_LIBADD = \ + $(LIBINDICATEGTK_LIBS) + +pkgconfig_DATA = indicate-gtk.pc +pkgconfigdir = $(libdir)/pkgconfig + +if USE_GIR + +gobjectintrospection_gir_DATA = \ + Indicate-gtk-0.1.gir +gobjectintrospection_girdir = $(datadir)/gir + +gobjectintrospection_type_DATA = \ + Indicate-gtk-0.1.typelib +gobjectintrospection_typedir = $(libdir)/girepository + +irscanner_headers = $(patsubst %,$(srcdir)/%,$(indicate_headers)) +Indicate-gtk-0.1.gir: $(irscanner_headers) + $(G_IR_SCANNER) \ + -v --namespace IndicateGtk \ + --nsversion=0.1 \ + --add-include-path=$(srcdir) \ + --include=GObject-2.0 \ + --include=GLib-2.0 \ + --include=GdkPixbuf-2.0 \ + --library=indicate --pkg indicate \ + --output Indicate-gtk-0.1.gir $(irscanner_headers) + +Indicate-gtk-0.1.typelib: Indicate-gtk-0.1.gir + $(G_IR_COMPILER) \ + --includedir=$(srcdir) Indicate-gtk-0.1.gir \ + -o Indicate-gtk-0.1.typelib + +DISTCLEANFILES = \ + Indicate-gtk-0.1.gir \ + Indicate-gtk-0.1.typelib + +endif diff --git a/libindicate-gtk/indicate-gtk.pc.in b/libindicate-gtk/indicate-gtk.pc.in new file mode 100644 index 0000000..28e3c81 --- /dev/null +++ b/libindicate-gtk/indicate-gtk.pc.in @@ -0,0 +1,14 @@ +prefix=@prefix@ +exec_prefix=@exec_prefix@ +libdir=@libdir@ +bindir=@bindir@ +includedir=@includedir@ + +Cflags: -I${includedir}/libindicate-0.1 +Requires: gtk+-2.0 indicate +Libs: -L${libdir} -lindicate-gtk + +Name: libindicate-gtk +Description: libindicate GTK stuff. +Version: @VERSION@ + diff --git a/libindicate-gtk/indicator.c b/libindicate-gtk/indicator.c new file mode 100644 index 0000000..a575849 --- /dev/null +++ b/libindicate-gtk/indicator.c @@ -0,0 +1,74 @@ +/* +A library to allow applictions to provide simple indications of +information to be displayed to users of the application through the +interface shell. + +Copyright 2009 Canonical Ltd. + +Authors: + Ted Gould <ted@canonical.com> + +This program is free software: you can redistribute it and/or modify it +under the terms of either or both of the following licenses: + +1) the GNU Lesser General Public License version 3, as published by the +Free Software Foundation; and/or +2) the GNU Lesser General Public License version 2.1, as published by +the Free Software Foundation. + +This program is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranties of +MERCHANTABILITY, SATISFACTORY QUALITY or FITNESS FOR A PARTICULAR +PURPOSE. See the applicable version of the GNU Lesser General Public +License for more details. + +You should have received a copy of both the GNU Lesser General Public +License version 3 and version 2.1 along with this program. If not, see +<http://www.gnu.org/licenses/> +*/ + +#include "indicator.h" + +/** + indicate_indicator_set_property_icon: + @indicator: a #IndicateIndicator to act on + @key: name of the property + @data: icon to set property with + + This is a helper function that wraps around #indicate_indicator_set_property + but takes an #GdkPixbuf parameter. It then takes the @data + parameter, turns it into a PNG, base64 encodes it and then + uses that data to call #indicate_indicator_set_property. +*/ +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((GdkPixbuf *)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((guchar *)png_data, png_data_len); + indicate_indicator_set_property(indicator, key, prop_str); + + g_free(prop_str); + g_free(png_data); + + return; +} diff --git a/libindicate-gtk/indicator.h b/libindicate-gtk/indicator.h new file mode 100644 index 0000000..43e264f --- /dev/null +++ b/libindicate-gtk/indicator.h @@ -0,0 +1,44 @@ +/* +A library to allow applictions to provide simple indications of +information to be displayed to users of the application through the +interface shell. + +Copyright 2009 Canonical Ltd. + +Authors: + Ted Gould <ted@canonical.com> + +This program is free software: you can redistribute it and/or modify it +under the terms of either or both of the following licenses: + +1) the GNU Lesser General Public License version 3, as published by the +Free Software Foundation; and/or +2) the GNU Lesser General Public License version 2.1, as published by +the Free Software Foundation. + +This program is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranties of +MERCHANTABILITY, SATISFACTORY QUALITY or FITNESS FOR A PARTICULAR +PURPOSE. See the applicable version of the GNU Lesser General Public +License for more details. + +You should have received a copy of both the GNU Lesser General Public +License version 3 and version 2.1 along with this program. If not, see +<http://www.gnu.org/licenses/> +*/ + +#ifndef INDICATE_GTK_INDICATOR_H_INCLUDED__ +#define INDICATE_GTK_INDICATOR_H_INCLUDED__ 1 + +#include <glib.h> +#include <gdk-pixbuf/gdk-pixbuf.h> +#include "libindicate/indicator.h" + +G_BEGIN_DECLS + +/* Properties handling */ +void indicate_indicator_set_property_icon (IndicateIndicator * indicator, const gchar * key, const GdkPixbuf * data); + +G_END_DECLS + +#endif /* INDICATE_GTK_INDICATOR_H_INCLUDED__ */ diff --git a/libindicate-gtk/listener.c b/libindicate-gtk/listener.c new file mode 100644 index 0000000..dceb05b --- /dev/null +++ b/libindicate-gtk/listener.c @@ -0,0 +1,148 @@ +/* +A library to allow applictions to provide simple indications of +information to be displayed to users of the application through the +interface shell. + +Copyright 2009 Canonical Ltd. + +Authors: + Ted Gould <ted@canonical.com> + +This program is free software: you can redistribute it and/or modify it +under the terms of either or both of the following licenses: + +1) the GNU Lesser General Public License version 3, as published by the +Free Software Foundation; and/or +2) the GNU Lesser General Public License version 2.1, as published by +the Free Software Foundation. + +This program is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranties of +MERCHANTABILITY, SATISFACTORY QUALITY or FITNESS FOR A PARTICULAR +PURPOSE. See the applicable version of the GNU Lesser General Public +License for more details. + +You should have received a copy of both the GNU Lesser General Public +License version 3 and version 2.1 along with this program. If not, see +<http://www.gnu.org/licenses/> +*/ + +#include "listener.h" +#include <dbus/dbus-glib-bindings.h> + +#include "../libindicate/dbus-indicate-client.h" +#include "../libindicate/listener-private.h" + +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 { + GCallback cb; + gpointer data; + IndicateListener * listener; + IndicateListenerServer * server; + IndicateListenerIndicator * indicator; + gchar * property; + get_property_type type; +}; + +static void +get_property_cb (DBusGProxy *proxy, char * OUT_value, GError *error, gpointer userdata) +{ + get_property_t * get_property_data = (get_property_t *)userdata; + + if (error != NULL) { + g_warning("Unable to get property data: %s", error->message); + g_error_free(error); + return; + } + + 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; + + /* There is no icon */ + if (OUT_value == NULL || OUT_value[0] == '\0') { + break; + } + + 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); + + return; +}; + +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? */ + get_property_t * get_property_data = g_new(get_property_t, 1); + get_property_data->cb = callback; + get_property_data->data = data; + get_property_data->listener = listener; + 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 (server->proxy , INDICATE_LISTENER_INDICATOR_ID(indicator), property, get_property_cb, get_property_data); + return; +} + +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); +} + diff --git a/libindicate-gtk/listener.h b/libindicate-gtk/listener.h new file mode 100644 index 0000000..cedc9a3 --- /dev/null +++ b/libindicate-gtk/listener.h @@ -0,0 +1,57 @@ +/* +A library to allow applictions to provide simple indications of +information to be displayed to users of the application through the +interface shell. + +Copyright 2009 Canonical Ltd. + +Authors: + Ted Gould <ted@canonical.com> + +This program is free software: you can redistribute it and/or modify it +under the terms of either or both of the following licenses: + +1) the GNU Lesser General Public License version 3, as published by the +Free Software Foundation; and/or +2) the GNU Lesser General Public License version 2.1, as published by +the Free Software Foundation. + +This program is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranties of +MERCHANTABILITY, SATISFACTORY QUALITY or FITNESS FOR A PARTICULAR +PURPOSE. See the applicable version of the GNU Lesser General Public +License for more details. + +You should have received a copy of both the GNU Lesser General Public +License version 3 and version 2.1 along with this program. If not, see +<http://www.gnu.org/licenses/> +*/ + +#ifndef INDICATE_GTK_LISTENER_H_INCLUDED__ +#define INDICATE_GTK_LISTENER_H_INCLUDED__ 1 + +#include <glib.h> +#include <gdk-pixbuf/gdk-pixbuf.h> + +#include "libindicate/listener.h" + +G_BEGIN_DECLS + +typedef void (*indicate_listener_get_property_icon_cb) (IndicateListener * listener, + IndicateListenerServer * server, + IndicateListenerIndicator * indicator, + gchar * property, + GdkPixbuf * propertydata, + 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); + +G_END_DECLS + +#endif /* INDICATE_GTK_LISTENER_H_INCLUDED__ */ + |