~skypce/indicator-session/indicator-session

« back to all changes in this revision

Viewing changes to src/session-dbus.c

  • Committer: Package Import Robot
  • Author(s): Evgeni Golov
  • Date: 2011-11-05 19:02:56 UTC
  • mfrom: (13.1.56 precise)
  • Revision ID: package-import@ubuntu.com-20111105190256-aqsmsm26md8va6o8
Tags: 0.3.7.1-1
* Merge from Ubuntu.
  + Doesn't FTBFS with -Werror.
    Closes: #625356
* Update debian/copyright.
* Add lintian override for desktop-command-not-in-package,
  we need an own xdg-screensaver .desktop file.

Show diffs side-by-side

added added

removed removed

Lines of Context:
5
5
 
6
6
Authors:
7
7
    Ted Gould <ted@canonical.com>
 
8
    Conor Curran <conor.curran@canonical.com>
8
9
 
9
10
This program is free software: you can redistribute it and/or modify it 
10
11
under the terms of the GNU General Public License version 3, as published 
28
29
#include "session-dbus.h"
29
30
#include "dbus-shared-names.h"
30
31
 
31
 
static GVariant * get_icon (SessionDbus * service);
 
32
static GVariant * get_users_real_name (SessionDbus * service);
32
33
static void bus_get_cb (GObject * object, GAsyncResult * res, gpointer user_data);
33
34
static void bus_method_call (GDBusConnection * connection, const gchar * sender, const gchar * path, const gchar * interface, const gchar * method, GVariant * params, GDBusMethodInvocation * invocation, gpointer user_data);
34
35
 
37
38
typedef struct _SessionDbusPrivate SessionDbusPrivate;
38
39
struct _SessionDbusPrivate {
39
40
        gchar * name;
 
41
  gboolean user_menu_is_visible;
40
42
        GDBusConnection * bus;
41
43
        GCancellable * bus_cancel;
42
44
        guint dbus_registration;
98
100
{
99
101
        SessionDbusPrivate * priv = SESSION_DBUS_GET_PRIVATE(self);
100
102
 
101
 
        priv->name = g_strdup(ICON_DEFAULT);
 
103
        priv->name = NULL;
102
104
        priv->bus = NULL;
103
105
        priv->bus_cancel = NULL;
104
106
        priv->dbus_registration = 0;
 
107
  priv->user_menu_is_visible = FALSE;
105
108
 
106
109
        priv->bus_cancel = g_cancellable_new();
107
110
        g_bus_get(G_BUS_TYPE_SESSION,
160
163
                 const gchar * method, GVariant * params,
161
164
                 GDBusMethodInvocation * invocation, gpointer user_data)
162
165
{
163
 
        SessionDbus * service = SESSION_DBUS(user_data);
 
166
        SessionDbus * service = SESSION_DBUS (user_data);
 
167
        SessionDbusPrivate * priv = SESSION_DBUS_GET_PRIVATE (service);
 
168
 
164
169
        GVariant * retval = NULL;
165
170
 
166
 
        if (g_strcmp0(method, "GetIcon") == 0) {
167
 
                retval = get_icon(service);
168
 
        } else {
169
 
                g_warning("Calling method '%s' on the indicator service and it's unknown", method);
170
 
        }
171
 
 
 
171
        if (g_strcmp0(method, "GetUserRealName") == 0) {
 
172
                retval = get_users_real_name (service);
 
173
        }
 
174
  else if (g_strcmp0 (method, "GetUserMenuVisibility") == 0){
 
175
    retval =  g_variant_new ("(b)", priv->user_menu_is_visible);
 
176
  }
 
177
  else {
 
178
    g_warning("Calling method '%s' on the indicator service and it's unknown", method);
 
179
        }
172
180
        g_dbus_method_invocation_return_value(invocation, retval);
173
181
        return;
174
182
}
214
222
}
215
223
 
216
224
static GVariant *
217
 
get_icon (SessionDbus * service)
 
225
get_users_real_name (SessionDbus * service)
218
226
{
219
227
        SessionDbusPrivate * priv = SESSION_DBUS_GET_PRIVATE(service);
220
 
        return g_variant_new("(s)", priv->name);
 
228
        return g_variant_new ("(s)", priv->name);
221
229
}
222
230
 
223
231
SessionDbus *
229
237
void
230
238
session_dbus_set_name (SessionDbus * session, const gchar * name)
231
239
{
 
240
}
 
241
 
 
242
void
 
243
session_dbus_set_users_real_name (SessionDbus * session, const gchar * name)
 
244
{
232
245
        SessionDbusPrivate * priv = SESSION_DBUS_GET_PRIVATE(session);
233
246
        GError * error = NULL;
234
247
        if (priv->name != NULL) {
235
248
                g_free(priv->name);
236
249
                priv->name = NULL;
237
250
        }
 
251
    
238
252
        priv->name = g_strdup(name);
239
253
 
240
254
        if (priv->bus != NULL) {
241
255
                g_dbus_connection_emit_signal (priv->bus,
242
 
                                               NULL,
243
 
                                               INDICATOR_SESSION_SERVICE_DBUS_OBJECT,
244
 
                                               INDICATOR_SESSION_SERVICE_DBUS_IFACE,
245
 
                                               "IconUpdated",
246
 
                                               g_variant_new ("(s)", priv->name, NULL),
247
 
                                               &error);
 
256
                                   NULL,
 
257
                                   INDICATOR_SESSION_SERVICE_DBUS_OBJECT,
 
258
                                   INDICATOR_SESSION_SERVICE_DBUS_IFACE,
 
259
                                   "UserRealNameUpdated",
 
260
                                   g_variant_new ("(s)", priv->name, NULL),
 
261
                                   &error);
248
262
 
249
263
                if (error != NULL) {
250
 
                        g_warning("Unable to send IconUpdated signal: %s", error->message);
 
264
                        g_warning("Unable to send UserRealNameUpdated signal: %s", error->message);
251
265
                        g_error_free(error);
252
266
                        return;
253
267
                }
254
268
        }
255
 
 
256
269
        return;
257
270
}
 
271
 
 
272
void 
 
273
session_dbus_set_user_menu_visibility (SessionDbus* session,
 
274
                                       gboolean visible)
 
275
{
 
276
        SessionDbusPrivate * priv = SESSION_DBUS_GET_PRIVATE(session);
 
277
        GError * error = NULL;
 
278
    
 
279
        priv->user_menu_is_visible = visible;
 
280
 
 
281
        if (priv->bus != NULL) {
 
282
                g_dbus_connection_emit_signal (priv->bus,
 
283
                                   NULL,
 
284
                                   INDICATOR_SESSION_SERVICE_DBUS_OBJECT,
 
285
                                   INDICATOR_SESSION_SERVICE_DBUS_IFACE,
 
286
                                   "UserMenuIsVisible",
 
287
                                   g_variant_new ("(b)", priv->user_menu_is_visible),
 
288
                                   &error);
 
289
 
 
290
                if (error != NULL) {
 
291
                        g_warning("Unable to send UserMenuIsVisible signal: %s", error->message);
 
292
                        g_error_free(error);
 
293
                }
 
294
        }  
 
295
}
 
296
 
 
297
void session_dbus_restart_required (SessionDbus* session)
 
298
{
 
299
        SessionDbusPrivate * priv = SESSION_DBUS_GET_PRIVATE(session);
 
300
        GError * error = NULL;
 
301
    
 
302
        if (priv->bus != NULL) {
 
303
    g_debug("About to send RebootRequired signal");
 
304
 
 
305
                g_dbus_connection_emit_signal (priv->bus,
 
306
                                   NULL,
 
307
                                   INDICATOR_SESSION_SERVICE_DBUS_OBJECT,
 
308
                                   INDICATOR_SESSION_SERVICE_DBUS_IFACE,
 
309
                                   "RestartRequired",
 
310
                                   NULL,
 
311
                                   &error);
 
312
 
 
313
                if (error != NULL) {
 
314
                        g_warning("Unable to send reboot-required signal: %s", error->message);
 
315
                        g_error_free(error);
 
316
                }
 
317
        }  
 
318
  
 
319
}