Back to index

libindicate  12.10.0
im-client.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/server.h"
00024 #include "libindicate/indicator.h"
00025 #include "libindicate-gtk/indicator.h"
00026 
00027 gchar * patha = "/usr/share/icons/hicolor/16x16/apps/empathy.png";
00028 gchar * pathb = "/usr/share/icons/hicolor/22x22/apps/empathy.png";
00029 gchar * lastpath = NULL;
00030 
00031 static gboolean
00032 timeout_cb (gpointer data)
00033 {
00034        g_debug("Modifying properties");
00035 
00036        IndicateIndicator * indicator = INDICATE_INDICATOR(data);
00037 
00038        GTimeVal time;
00039        g_get_current_time(&time);
00040        indicate_indicator_set_property_time(INDICATE_INDICATOR(indicator), "time", &time);
00041 
00042        if (lastpath == patha) {
00043               lastpath = pathb;
00044        } else {
00045               lastpath = patha;
00046        }
00047        
00048        GdkPixbuf * pixbuf = gdk_pixbuf_new_from_file(lastpath, NULL);
00049        g_return_val_if_fail(pixbuf != NULL, TRUE);
00050 
00051        indicate_gtk_indicator_set_property_icon(INDICATE_INDICATOR(indicator), "icon", pixbuf);
00052        g_object_unref(G_OBJECT(pixbuf));
00053 
00054        return TRUE;
00055 }
00056 
00057 static void
00058 display (IndicateIndicator * indicator, gpointer data)
00059 {
00060        g_debug("Ah, my indicator has been displayed");
00061 }
00062 
00063 static void
00064 server_display (IndicateServer * server, gpointer data)
00065 {
00066        g_debug("Ah, my server has been displayed");
00067 }
00068 
00069 static void
00070 interest_added (IndicateServer * server, IndicateInterests interest)
00071 {
00072        g_debug("Oh, someone is interested in me for: %d", interest);
00073 }
00074 
00075 void
00076 interest_removed (IndicateServer * server, IndicateInterests interest)
00077 {
00078        g_debug("Someone is no longer interested in my for: %d", interest);
00079 }
00080 
00081 void
00082 menuitem_click (DbusmenuMenuitem * menuitem, guint timestamp, gpointer data)
00083 {
00084        g_debug("Menuitem '%s' clicked at %d", (gchar *)data, timestamp);
00085 }
00086 
00087 int
00088 main (int argc, char ** argv)
00089 {
00090        g_type_init();
00091 
00092        IndicateServer * server = indicate_server_ref_default();
00093        indicate_server_set_type(server, "message.im");
00094        indicate_server_set_desktop_file(server, "/usr/share/applications/empathy.desktop");
00095        g_signal_connect(G_OBJECT(server), INDICATE_SERVER_SIGNAL_SERVER_DISPLAY, G_CALLBACK(server_display), NULL);
00096        g_signal_connect(G_OBJECT(server), INDICATE_SERVER_SIGNAL_INTEREST_ADDED, G_CALLBACK(interest_added), NULL);
00097        g_signal_connect(G_OBJECT(server), INDICATE_SERVER_SIGNAL_INTEREST_REMOVED, G_CALLBACK(interest_removed), NULL);
00098 
00099        DbusmenuServer * dmserver = dbusmenu_server_new("/dbusmenu/path");
00100        DbusmenuMenuitem * root = dbusmenu_menuitem_new();
00101        dbusmenu_server_set_root(dmserver, root);
00102        DbusmenuMenuitem * item;
00103 
00104        item = dbusmenu_menuitem_new();
00105        dbusmenu_menuitem_property_set(item, DBUSMENU_MENUITEM_PROP_LABEL, "Label 1");
00106        dbusmenu_menuitem_child_append(root, item);
00107        g_signal_connect(G_OBJECT(item), DBUSMENU_MENUITEM_SIGNAL_ITEM_ACTIVATED, G_CALLBACK(menuitem_click), "Label 1");
00108 
00109        item = dbusmenu_menuitem_new();
00110        dbusmenu_menuitem_property_set(item, DBUSMENU_MENUITEM_PROP_LABEL, "Label 2");
00111        dbusmenu_menuitem_child_append(root, item);
00112        g_signal_connect(G_OBJECT(item), DBUSMENU_MENUITEM_SIGNAL_ITEM_ACTIVATED, G_CALLBACK(menuitem_click), "Label 2");
00113 
00114        indicate_server_set_menu(server, dmserver);
00115 
00116        IndicateIndicator * indicator;
00117 
00118        indicator = indicate_indicator_new();
00119        indicate_indicator_set_property(INDICATE_INDICATOR(indicator), "subtype", "im");
00120        indicate_indicator_set_property(INDICATE_INDICATOR(indicator), "sender", "IM Client Test");
00121        GTimeVal time; g_get_current_time(&time);
00122        indicate_indicator_set_property_time(INDICATE_INDICATOR(indicator), "time", &time);
00123        indicate_indicator_show(INDICATE_INDICATOR(indicator));
00124 
00125        g_get_current_time(&time);
00126        indicate_indicator_set_property_time(INDICATE_INDICATOR(indicator), "time", &time);
00127 
00128        g_signal_connect(G_OBJECT(indicator), INDICATE_INDICATOR_SIGNAL_DISPLAY, G_CALLBACK(display), NULL);
00129 
00130        g_timeout_add_seconds(180, timeout_cb, indicator);
00131 
00132        g_main_loop_run(g_main_loop_new(NULL, FALSE));
00133 
00134        return 0;
00135 }