~lightdm-team/lightdm/1.4

« back to all changes in this revision

Viewing changes to src/lightdm.c

  • Committer: Robert Ancell
  • Date: 2011-05-05 06:11:16 UTC
  • Revision ID: robert.ancell@canonical.com-20110505061116-4nhrdw6k0huve3ek
Move user manager into liblightdm

Show diffs side-by-side

added added

removed removed

Lines of Context:
18
18
#include <unistd.h>
19
19
 
20
20
#include "display-manager.h"
21
 
#include "user-manager.h"
22
21
#include "xserver.h"
23
22
 
24
23
static GKeyFile *config_file = NULL;
30
29
static FILE *log_file;
31
30
static gboolean debug = FALSE;
32
31
 
33
 
static UserManager *user_manager = NULL;
34
32
static DisplayManager *display_manager = NULL;
35
33
 
36
34
static GDBusConnection *bus = NULL;
251
249
}
252
250
 
253
251
static GVariant *
254
 
user_info_to_args (UserInfo *info)
255
 
{
256
 
    return g_variant_new ("(sssb)",
257
 
                          info->name,
258
 
                          info->real_name ? info->real_name : "",
259
 
                          info->image ? info->image : "",
260
 
                          info->logged_in);
261
 
}
262
 
 
263
 
static void
264
 
handle_user_manager_call (GDBusConnection       *connection,
265
 
                          const gchar           *sender,
266
 
                          const gchar           *object_path,
267
 
                          const gchar           *interface_name,
268
 
                          const gchar           *method_name,
269
 
                          GVariant              *parameters,
270
 
                          GDBusMethodInvocation *invocation,
271
 
                          gpointer               user_data)
272
 
{
273
 
    if (g_strcmp0 (method_name, "GetUsers") == 0)
274
 
    {
275
 
        GVariantBuilder *builder;
276
 
        GVariant *arg0;
277
 
        GList *users, *iter;
278
 
 
279
 
        if (!g_variant_is_of_type (parameters, G_VARIANT_TYPE ("()")))
280
 
            return;
281
 
 
282
 
        builder = g_variant_builder_new (G_VARIANT_TYPE ("a(sssb)"));
283
 
        users = user_manager_get_users (user_manager);
284
 
        for (iter = users; iter; iter = iter->next)
285
 
        {
286
 
            UserInfo *info = iter->data;
287
 
            g_variant_builder_add_value (builder, user_info_to_args (info));
288
 
        }
289
 
        arg0 = g_variant_builder_end (builder);
290
 
        g_dbus_method_invocation_return_value (invocation, g_variant_new_tuple (&arg0, 1));
291
 
        g_variant_builder_unref (builder);
292
 
    }
293
 
    else if (g_strcmp0 (method_name, "GetUserDefaults") == 0)
294
 
    {
295
 
        gchar *username, *language, *layout, *session;
296
 
 
297
 
        if (!g_variant_is_of_type (parameters, G_VARIANT_TYPE ("(s)")))
298
 
            return;
299
 
 
300
 
        g_variant_get (parameters, "(s)", &username);
301
 
        if (user_manager_get_user_defaults (user_manager, username, &language, &layout, &session))
302
 
        {
303
 
            g_dbus_method_invocation_return_value (invocation, g_variant_new ("(sss)", language, layout, session));
304
 
            g_free (language);
305
 
            g_free (layout);
306
 
            g_free (session);
307
 
        }
308
 
        g_free (username);
309
 
    }
310
 
}
311
 
 
312
 
static void
313
 
user_added_cb (UserManager *user_manager, UserInfo *info)
314
 
{
315
 
    g_dbus_connection_emit_signal (bus,
316
 
                                   NULL,
317
 
                                   "/org/lightdm/LightDisplayManager/Users",
318
 
                                   "org.lightdm.LightDisplayManager.Users",
319
 
                                   "UserAdded",
320
 
                                   user_info_to_args (info),
321
 
                                   NULL);
322
 
}
323
 
 
324
 
static void
325
 
user_changed_cb (UserManager *user_manager, UserInfo *info)
326
 
{
327
 
    g_dbus_connection_emit_signal (bus,
328
 
                                   NULL,
329
 
                                   "/org/lightdm/LightDisplayManager/Users",
330
 
                                   "org.lightdm.LightDisplayManager.Users",
331
 
                                   "UserChanged",
332
 
                                   user_info_to_args (info),
333
 
                                   NULL); 
334
 
}
335
 
 
336
 
static void
337
 
user_removed_cb (UserManager *user_manager, UserInfo *info)
338
 
{
339
 
    g_dbus_connection_emit_signal (bus,
340
 
                                   NULL,
341
 
                                   "/org/lightdm/LightDisplayManager/Users",
342
 
                                   "org.lightdm.LightDisplayManager.Users",
343
 
                                   "UserRemoved",
344
 
                                   g_variant_new ("(s)", info->name),
345
 
                                   NULL);
 
252
handle_display_manager_get_property (GDBusConnection       *connection,
 
253
                                     const gchar           *sender,
 
254
                                     const gchar           *object_path,
 
255
                                     const gchar           *interface_name,
 
256
                                     const gchar           *property_name,
 
257
                                     GError               **error,
 
258
                                     gpointer               user_data)
 
259
{
 
260
    if (g_strcmp0 (property_name, "ConfigFile") == 0)
 
261
    {
 
262
        return g_variant_new_string (config_path);
 
263
    }
 
264
 
 
265
    return NULL;
346
266
}
347
267
 
348
268
static void
353
273
    const gchar *display_manager_interface =
354
274
        "<node>"
355
275
        "  <interface name='org.lightdm.LightDisplayManager'>"
 
276
        "    <property name='ConfigFile' type='s' access='read'/>"
356
277
        "    <method name='AddDisplay'/>"
357
278
        "    <method name='SwitchToUser'>"
358
279
        "      <arg name='username' direction='in' type='s'/>"
361
282
        "</node>";
362
283
    static const GDBusInterfaceVTable display_manager_vtable =
363
284
    {
364
 
        handle_display_manager_call
365
 
    };
366
 
 
367
 
    const gchar *user_manager_interface =
368
 
        "<node>"
369
 
        "  <interface name='org.lightdm.LightDisplayManager.Users'>"
370
 
        "    <method name='GetUsers'>"
371
 
        "      <arg name='users' direction='out' type='a(sssb)'/>"
372
 
        "    </method>"
373
 
        "    <method name='GetUserDefaults'>"
374
 
        "      <arg name='username' direction='in' type='s'/>"
375
 
        "      <arg name='language' direction='out' type='s'/>"
376
 
        "      <arg name='layout' direction='out' type='s'/>"
377
 
        "      <arg name='session' direction='out' type='s'/>"
378
 
        "    </method>"
379
 
        "    <signal name='UserAdded'>"
380
 
        "      <arg name='username' type='s'/>"
381
 
        "      <arg name='real-name' type='s'/>"
382
 
        "      <arg name='image' type='s'/>"
383
 
        "      <arg name='username' type='b'/>"
384
 
        "    </signal>"
385
 
        "    <signal name='UserChanged'>"
386
 
        "      <arg name='username' type='s'/>"
387
 
        "      <arg name='real-name' type='s'/>"
388
 
        "      <arg name='image' type='s'/>"
389
 
        "      <arg name='username' type='b'/>"
390
 
        "    </signal>"
391
 
        "    <signal name='UserRemoved'>"
392
 
        "      <arg name='username' type='s'/>"
393
 
        "    </signal>"
394
 
        "  </interface>"
395
 
        "</node>";
396
 
    static const GDBusInterfaceVTable user_manager_vtable =
397
 
    {
398
 
        handle_user_manager_call
399
 
    };
400
 
    GDBusNodeInfo *display_manager_info, *user_manager_info;
 
285
        handle_display_manager_call,
 
286
        handle_display_manager_get_property
 
287
    };
 
288
    GDBusNodeInfo *display_manager_info;
401
289
 
402
290
    bus = connection;
403
291
 
409
297
                                       &display_manager_vtable,
410
298
                                       NULL, NULL,
411
299
                                       NULL);
412
 
 
413
 
    user_manager_info = g_dbus_node_info_new_for_xml (user_manager_interface, NULL);
414
 
    g_assert (user_manager_info != NULL);
415
 
    g_dbus_connection_register_object (connection,
416
 
                                       "/org/lightdm/LightDisplayManager/Users",
417
 
                                       user_manager_info->interfaces[0],
418
 
                                       &user_manager_vtable,
419
 
                                       NULL, NULL,
420
 
                                       NULL);
421
 
 
422
 
    g_signal_connect (user_manager, "user-added", G_CALLBACK (user_added_cb), NULL);
423
 
    g_signal_connect (user_manager, "user-changed", G_CALLBACK (user_changed_cb), NULL);
424
 
    g_signal_connect (user_manager, "user-removed", G_CALLBACK (user_removed_cb), NULL);
425
300
}
426
301
 
427
302
static void
500
375
 
501
376
    g_debug ("Loaded configuration from %s", config_path);
502
377
 
503
 
    user_manager = user_manager_new (config_file);
504
378
    display_manager = display_manager_new (config_file);
505
379
 
506
380
    display_manager_start (display_manager);