Back to index

libindicate  12.10.0
listen-and-print.c
Go to the documentation of this file.
00001 /*
00002 A test for libindicate to ensure its quality.
00003 
00004 Copyright 2009 Canonical Ltd.
00005 
00006 Authors:
00007     Ted Gould <ted@canonical.com>
00008 
00009 This program is free software: you can redistribute it and/or modify it 
00010 under the terms of the GNU General Public License version 3, as published 
00011 by the Free Software Foundation.
00012 
00013 This program is distributed in the hope that it will be useful, but 
00014 WITHOUT ANY WARRANTY; without even the implied warranties of 
00015 MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR 
00016 PURPOSE.  See the GNU General Public License for more details.
00017 
00018 You should have received a copy of the GNU General Public License along 
00019 with this program.  If not, see <http://www.gnu.org/licenses/>.
00020 */
00021 
00022 #include <glib.h>
00023 #include "libindicate/listener.h"
00024 #include "libindicate-gtk/listener.h"
00025 
00026 static void
00027 show_property_cb (IndicateListener * listener, IndicateListenerServer * server, IndicateListenerIndicator * indicator, gchar * property, const gchar * propertydata, gpointer data)
00028 {
00029        g_debug("Indicator Property:       %s %d %s %s", INDICATE_LISTENER_SERVER_DBUS_NAME(server), INDICATE_LISTENER_INDICATOR_ID(indicator), property, propertydata);
00030        return;
00031 }
00032 
00033 static void 
00034 show_property_time_cb (IndicateListener * listener, IndicateListenerServer * server, IndicateListenerIndicator * indicator, gchar * property, const GTimeVal * propertydata, gpointer data)
00035 {
00036        time_t timet;
00037        struct tm * structtm;
00038 
00039        timet = propertydata->tv_sec;
00040        structtm = localtime(&timet);
00041 
00042        gchar timestring[80];
00043        strftime(timestring, 80, "%I:%M", structtm);
00044 
00045        g_debug("Indicator Property:       %s %d %s %s", INDICATE_LISTENER_SERVER_DBUS_NAME(server), INDICATE_LISTENER_INDICATOR_ID(indicator), property, timestring);
00046        return;
00047 }
00048 
00049 static void 
00050 show_property_icon_cb (IndicateListener * listener, IndicateListenerServer * server, IndicateListenerIndicator * indicator, gchar * property, GdkPixbuf * propertydata, gpointer data)
00051 {
00052        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));
00053        g_object_unref(G_OBJECT(propertydata));
00054        return;
00055 }
00056 
00057 static void
00058 show_property (IndicateListener * listener, IndicateListenerServer * server, IndicateListenerIndicator * indicator, gchar * property)
00059 {
00060        if (!g_strcmp0(property, "icon")) {
00061               indicate_gtk_listener_get_property_icon(listener, server, indicator, property, show_property_icon_cb, NULL);
00062        } else if (!g_strcmp0(property, "time")) {
00063               indicate_listener_get_property_time(listener, server, indicator, property, show_property_time_cb, NULL);
00064        } else {
00065               indicate_listener_get_property(listener, server, indicator, property, show_property_cb, NULL);
00066        }
00067 
00068        return;
00069 }
00070 
00071 static void
00072 get_properties (IndicateListener * listener, IndicateListenerServer * server, IndicateListenerIndicator * indicator)
00073 {
00074        //TODO: Not in API yet.
00075 }
00076 
00077 static void
00078 indicator_added (IndicateListener * listener, IndicateListenerServer * server, IndicateListenerIndicator * indicator, gpointer data)
00079 {
00080        g_debug("Indicator Added:          %s %d", INDICATE_LISTENER_SERVER_DBUS_NAME(server), INDICATE_LISTENER_INDICATOR_ID(indicator));
00081        get_properties(listener, server, indicator);
00082 }
00083 
00084 static void
00085 indicator_removed (IndicateListener * listener, IndicateListenerServer * server, IndicateListenerIndicator * indicator, gpointer data)
00086 {
00087        g_debug("Indicator Removed:        %s %d", INDICATE_LISTENER_SERVER_DBUS_NAME(server), INDICATE_LISTENER_INDICATOR_ID(indicator));
00088 }
00089 
00090 static void
00091 indicator_modified (IndicateListener * listener, IndicateListenerServer * server, IndicateListenerIndicator * indicator, gchar * property, gpointer data)
00092 {
00093        g_debug("Indicator Modified:       %s %d %s", INDICATE_LISTENER_SERVER_DBUS_NAME(server), INDICATE_LISTENER_INDICATOR_ID(indicator), property);
00094        show_property(listener, server, indicator, property);
00095 }
00096 
00097 static void
00098 type_cb (IndicateListener * listener, IndicateListenerServer * server, const gchar * value, gpointer data)
00099 {
00100        g_debug("Indicator Server Type:    %s %s", INDICATE_LISTENER_SERVER_DBUS_NAME(server), value);
00101 }
00102 
00103 static void
00104 desktop_cb (IndicateListener * listener, IndicateListenerServer * server, const gchar * value, gpointer data)
00105 {
00106        g_debug("Indicator Server Desktop: %s %s", INDICATE_LISTENER_SERVER_DBUS_NAME(server), value);
00107 }
00108 
00109 static void
00110 server_added (IndicateListener * listener, IndicateListenerServer * server, gchar * type, gpointer data)
00111 {
00112        g_debug("Indicator Server Added:   %s %s", INDICATE_LISTENER_SERVER_DBUS_NAME(server), type);
00113        indicate_listener_server_get_type(listener, server, type_cb, NULL);
00114        indicate_listener_server_get_desktop(listener, server, desktop_cb, NULL);
00115 
00116        indicate_listener_server_show_interest(listener, server, INDICATE_INTEREST_SERVER_DISPLAY);
00117        indicate_listener_server_show_interest(listener, server, INDICATE_INTEREST_INDICATOR_DISPLAY);
00118 
00119        return;
00120 }
00121 
00122 static void
00123 server_removed (IndicateListener * listener, IndicateListenerServer * server, gchar * type, gpointer data)
00124 {
00125        g_debug("Indicator Server Removed: %s %s", INDICATE_LISTENER_SERVER_DBUS_NAME(server), type);
00126 }
00127 
00128 int
00129 main (int argc, char ** argv)
00130 {
00131        g_type_init();
00132 
00133        IndicateListener * listener = indicate_listener_ref_default();
00134 
00135        g_signal_connect(listener, INDICATE_LISTENER_SIGNAL_INDICATOR_ADDED, G_CALLBACK(indicator_added), NULL);
00136        g_signal_connect(listener, INDICATE_LISTENER_SIGNAL_INDICATOR_REMOVED, G_CALLBACK(indicator_removed), NULL);
00137        g_signal_connect(listener, INDICATE_LISTENER_SIGNAL_INDICATOR_MODIFIED, G_CALLBACK(indicator_modified), NULL);
00138        g_signal_connect(listener, INDICATE_LISTENER_SIGNAL_SERVER_ADDED, G_CALLBACK(server_added), NULL);
00139        g_signal_connect(listener, INDICATE_LISTENER_SIGNAL_SERVER_REMOVED, G_CALLBACK(server_removed), NULL);
00140 
00141        g_main_loop_run(g_main_loop_new(NULL, FALSE));
00142 
00143        return 0;
00144 }