~cairo-dock-team/ubuntu/quantal/cairo-dock-plug-ins/3.0.2

« back to all changes in this revision

Viewing changes to MeMenu/src/applet-me.c

Tags: upstream-2.2.0~0beta4
ImportĀ upstreamĀ versionĀ 2.2.0~0beta4

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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-me.h"
 
33
 
 
34
#define INDICATOR_ME_DBUS_OBJECT "/org/ayatana/indicator/me/menu"
 
35
#define INDICATOR_ME_SERVICE_DBUS_OBJECT "/org/ayatana/indicator/me/service"
 
36
#define INDICATOR_ME_SERVICE_DBUS_INTERFACE "org.ayatana.indicator.me.service"
 
37
#define INDICATOR_ME_DBUS_NAME  "org.ayatana.indicator.me"
 
38
#define INDICATOR_ME_DBUS_VERSION  1
 
39
#define DEFAULT_ICON "user-offline"
 
40
 
 
41
 
 
42
  ///////////
 
43
 // PROXY //
 
44
///////////
 
45
 
 
46
static void
 
47
username_cb (DBusGProxy * proxy, const char * username, GError *error, CairoDockModuleInstance *myApplet)
 
48
{
 
49
        g_print (" + new username: '%s'\n", username);
 
50
        CD_APPLET_SET_NAME_FOR_MY_ICON (username);  // username peut etre NULL ou vide, c'est pas genant.
 
51
}
 
52
 
 
53
static void
 
54
username_changed (DBusGProxy * proxy, gchar * username, CairoDockModuleInstance *myApplet)
 
55
{
 
56
        g_print ("Changing username: '%s'\n", username);
 
57
        
 
58
        return username_cb(proxy, username, NULL, myApplet);
 
59
}
 
60
 
 
61
static void
 
62
status_icon_cb (DBusGProxy * proxy, const char * icons, GError *error, CairoDockModuleInstance *myApplet)
 
63
{
 
64
        g_return_if_fail(icons != NULL);
 
65
        g_return_if_fail(icons[0] != '\0');
 
66
        g_print (" + new icon: '%s'\n", icons);
 
67
        
 
68
        cd_indicator_set_icon (myData.pIndicator, icons);
 
69
        CD_APPLET_REDRAW_MY_ICON;
 
70
        
 
71
        return;
 
72
}
 
73
 
 
74
static void
 
75
status_icon_changed (DBusGProxy * proxy, gchar * icon, CairoDockModuleInstance *myApplet)
 
76
{
 
77
        g_print ("Changing status icon: '%s'\n", icon);
 
78
        
 
79
        return status_icon_cb(proxy, icon, NULL, myApplet);
 
80
}
 
81
 
 
82
void cd_me_on_connect (CairoDockModuleInstance *myApplet)
 
83
{
 
84
        DBusGProxy * pServiceProxy = myData.pIndicator->pServiceProxy;
 
85
        
 
86
        dbus_g_proxy_add_signal (pServiceProxy, "StatusIconsChanged", G_TYPE_STRING, G_TYPE_INVALID);
 
87
        dbus_g_proxy_connect_signal (pServiceProxy, "StatusIconsChanged", G_CALLBACK(status_icon_changed), myApplet, NULL);
 
88
        
 
89
        dbus_g_proxy_add_signal (pServiceProxy, "UserChanged", G_TYPE_STRING, G_TYPE_INVALID);
 
90
        dbus_g_proxy_connect_signal (pServiceProxy, "UserChanged", G_CALLBACK(username_changed), myApplet, NULL);
 
91
}
 
92
 
 
93
void cd_me_on_disconnect (CairoDockModuleInstance *myApplet)
 
94
{
 
95
        cd_warning ("It seems that the MeMenu is not available on this system");
 
96
        status_icon_cb (NULL, DEFAULT_ICON, NULL, myApplet);  // If we're disconnecting, go back to offline.
 
97
}
 
98
 
 
99
void cd_me_get_initial_values (CairoDockModuleInstance *myApplet)
 
100
{
 
101
        // query the service to display initial values.
 
102
        DBusGProxy * pServiceProxy = myData.pIndicator->pServiceProxy;
 
103
        
 
104
        org_ayatana_indicator_me_service_status_icons_async (pServiceProxy,
 
105
                (org_ayatana_indicator_me_service_status_icons_reply)status_icon_cb,
 
106
                myApplet);
 
107
        
 
108
        org_ayatana_indicator_me_service_pretty_user_name_async (pServiceProxy,
 
109
                (org_ayatana_indicator_me_service_status_icons_reply)username_cb,
 
110
                myApplet);
 
111
}