2
* This file is a part of the Cairo-Dock project
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.
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.
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/>.
26
#include "indicator-applet.h"
28
#define INDICATOR_APPLET_DBUS_VERSION 1
31
static void _cd_indicator_make_menu (CDAppletIndicator *pIndicator)
33
if (pIndicator->pMenu == NULL)
35
pIndicator->pMenu = dbusmenu_gtkmenu_new (pIndicator->cBusName, pIndicator->cMenuObject);
36
if (pIndicator->pMenu != NULL)
38
DbusmenuGtkClient * client = dbusmenu_gtkmenu_get_client (pIndicator->pMenu);
40
if (pIndicator->add_menu_handler)
41
pIndicator->add_menu_handler (client);
46
static gboolean _get_menu_once (CDAppletIndicator *pIndicator)
48
_cd_indicator_make_menu (pIndicator);
49
pIndicator->iSidGetMenuOnce = 0;
54
connection_changed (IndicatorServiceManager * sm, gboolean connected, CDAppletIndicator *pIndicator)
56
CairoDockModuleInstance *myApplet = pIndicator->pApplet;
59
// connect to the service.
60
if (pIndicator->pServiceProxy == NULL)
62
GError * error = NULL;
63
DBusGConnection * sbus = cairo_dock_get_session_connection ();
64
pIndicator->pServiceProxy = dbus_g_proxy_new_for_name_owner(sbus,
66
pIndicator->cServiceObject,
67
pIndicator->cServiceInterface,
71
cd_warning ("'%s' service not found on the bus : %s", pIndicator->cServiceObject, error->message);
74
if (pIndicator->pServiceProxy == NULL)
77
if (pIndicator->on_connect)
78
pIndicator->on_connect (myApplet);
81
// query the service to display initial values.
82
if (pIndicator->get_initial_values)
83
pIndicator->get_initial_values (myApplet);
85
pIndicator->iSidGetMenuOnce = g_idle_add ((GSourceFunc)_get_menu_once, pIndicator);
86
pIndicator->bConnected = TRUE;
88
else // If we're disconnecting, go back to offline.
90
if (pIndicator->on_disconnect)
91
pIndicator->on_disconnect (myApplet);
92
pIndicator->bConnected = FALSE;
98
CDAppletIndicator *cd_indicator_new (CairoDockModuleInstance *pApplet, const gchar *cBusName, const gchar *cServiceObject, const gchar *cServiceInterface, const gchar *cMenuObject)
100
CDAppletIndicator *pIndicator = g_new0 (CDAppletIndicator, 1);
101
pIndicator->pApplet = pApplet;
102
pIndicator->cBusName = cBusName;
103
pIndicator->cServiceObject = cServiceObject;
104
pIndicator->cServiceInterface = cServiceInterface;
105
pIndicator->cMenuObject = cMenuObject;
107
pIndicator->service = indicator_service_manager_new_version (cBusName, INDICATOR_APPLET_DBUS_VERSION);
108
g_signal_connect (G_OBJECT(pIndicator->service), INDICATOR_SERVICE_MANAGER_SIGNAL_CONNECTION_CHANGE, G_CALLBACK(connection_changed), pIndicator); // on sera appele une fois la connexion etablie.
114
void cd_indicator_destroy (CDAppletIndicator *pIndicator)
118
if (pIndicator->iSidGetMenuOnce != 0)
119
g_source_remove (pIndicator->iSidGetMenuOnce);
120
if (pIndicator->service)
121
g_object_unref (pIndicator->service);
122
if (pIndicator->pServiceProxy)
123
g_object_unref (pIndicator->pServiceProxy);
124
g_print ("destroy menu...\n");
125
if (pIndicator->pMenu)
126
g_object_ref_sink (pIndicator->pMenu);
132
void cd_indicator_set_icon (CDAppletIndicator *pIndicator, const gchar *cStatusIcon)
134
CairoDockModuleInstance *myApplet = pIndicator->pApplet;
135
if (cStatusIcon != pIndicator->cStatusIcon)
137
g_free (pIndicator->cStatusIcon);
138
pIndicator->cStatusIcon = g_strdup (cStatusIcon);
140
if (cStatusIcon == NULL)
143
gchar *cIconPath = cairo_dock_search_icon_s_path (cStatusIcon);
144
gchar *cIconPathFallback = NULL;
145
if (cIconPath == NULL) // l'icone ne sera pas trouvee, on met une icone par defaut.
146
cIconPathFallback = g_strdup_printf ("%s/%s.svg", myApplet->pModule->pVisitCard->cShareDataDir, cStatusIcon);
148
g_print ("set %s\n", cIconPathFallback ? cIconPathFallback : cStatusIcon);
149
CD_APPLET_SET_IMAGE_ON_MY_ICON (cIconPathFallback ? cIconPathFallback : cStatusIcon);
152
g_free (cIconPathFallback);
156
void cd_indicator_reload_icon (CDAppletIndicator *pIndicator)
158
cd_indicator_set_icon (pIndicator, pIndicator->cStatusIcon);
162
gboolean cd_indicator_show_menu (CDAppletIndicator *pIndicator)
164
_cd_indicator_make_menu (pIndicator);
165
if (pIndicator->pMenu != NULL)
167
cairo_dock_popup_menu_on_container (GTK_WIDGET (pIndicator->pMenu), myContainer);