1 /**
2 * This file is a part of the Cairo-Dock project
3 *
4 * Copyright : (C) see the 'copyright' file.
5 * based on indicator-me.c written by :
6 *  Ted Gould <ted@canonical.com>
7 *  Cody Russell <cody.russell@canonical.com>
8 * E-mail    : see the 'copyright' file.
9 *
10 * This program is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU General Public License
12 * as published by the Free Software Foundation; either version 3
13 * of the License, or (at your option) any later version.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
21 */
22 
23 #include <stdlib.h>
24 #include <string.h>
25 
26 #include <libindicator/indicator.h>
27 #include <libindicator/indicator-object.h>
28 #include <libindicator/indicator-service-manager.h>
29 
30 #include "applet-struct.h"
31 #include "me-service-client.h"
32 #include "applet-menu.h"
33 #include "applet-me.h"
34 
35 #define DEFAULT_ICON "user-offline"
36 
37 
38   ///////////
39  // PROXY //
40 ///////////
41 
42 static void
username_cb(DBusGProxy * proxy,const char * username,GError * error,GldiModuleInstance * myApplet)43 username_cb (DBusGProxy * proxy, const char * username, GError *error, GldiModuleInstance *myApplet)
44 {
45 	//g_print (" + new username: '%s'\n", username);
46 	CD_APPLET_SET_NAME_FOR_MY_ICON (username);  // username peut etre NULL ou vide, c'est pas genant.
47 }
48 
49 static void
username_changed(DBusGProxy * proxy,gchar * username,GldiModuleInstance * myApplet)50 username_changed (DBusGProxy * proxy, gchar * username, GldiModuleInstance *myApplet)
51 {
52 	//g_print ("Changing username: '%s'\n", username);
53 
54 	return username_cb(proxy, username, NULL, myApplet);
55 }
56 
57 static void
status_icon_cb(DBusGProxy * proxy,const char * icons,GError * error,GldiModuleInstance * myApplet)58 status_icon_cb (DBusGProxy * proxy, const char * icons, GError *error, GldiModuleInstance *myApplet)
59 {
60 	g_return_if_fail(icons != NULL);
61 	g_return_if_fail(icons[0] != '\0');
62 	//g_print (" + new icon: '%s'\n", icons);
63 
64 	cd_indicator_set_icon (myData.pIndicator, icons);
65 	CD_APPLET_REDRAW_MY_ICON;
66 
67 	return;
68 }
69 
70 static void
status_icon_changed(DBusGProxy * proxy,gchar * icon,GldiModuleInstance * myApplet)71 status_icon_changed (DBusGProxy * proxy, gchar * icon, GldiModuleInstance *myApplet)
72 {
73 	//g_print ("Changing status icon: '%s'\n", icon);
74 
75 	return status_icon_cb(proxy, icon, NULL, myApplet);
76 }
77 
cd_me_on_connect(GldiModuleInstance * myApplet)78 void cd_me_on_connect (GldiModuleInstance *myApplet)
79 {
80 	DBusGProxy * pServiceProxy = myData.pIndicator->pServiceProxy;
81 
82 	dbus_g_proxy_add_signal (pServiceProxy, "StatusIconsChanged", G_TYPE_STRING, G_TYPE_INVALID);
83 	dbus_g_proxy_connect_signal (pServiceProxy, "StatusIconsChanged", G_CALLBACK(status_icon_changed), myApplet, NULL);
84 
85 	dbus_g_proxy_add_signal (pServiceProxy, "UserChanged", G_TYPE_STRING, G_TYPE_INVALID);
86 	dbus_g_proxy_connect_signal (pServiceProxy, "UserChanged", G_CALLBACK(username_changed), myApplet, NULL);
87 }
88 
cd_me_on_disconnect(GldiModuleInstance * myApplet)89 void cd_me_on_disconnect (GldiModuleInstance *myApplet)
90 {
91 	cd_warning ("It seems that the MeMenu is not available on this system");
92 	status_icon_cb (NULL, DEFAULT_ICON, NULL, myApplet);  // If we're disconnecting, go back to offline.
93 
94 	///cd_me_delete_entry ();
95 }
96 
cd_me_get_initial_values(GldiModuleInstance * myApplet)97 void cd_me_get_initial_values (GldiModuleInstance *myApplet)
98 {
99 	// query the service to display initial values.
100 	DBusGProxy * pServiceProxy = myData.pIndicator->pServiceProxy;
101 
102 	org_ayatana_indicator_me_service_status_icons_async (pServiceProxy,
103 		(org_ayatana_indicator_me_service_status_icons_reply)status_icon_cb,
104 		myApplet);
105 
106 	org_ayatana_indicator_me_service_pretty_user_name_async (pServiceProxy,
107 		(org_ayatana_indicator_me_service_status_icons_reply)username_cb,
108 		myApplet);
109 }
110