~ubuntu-branches/debian/stretch/lightdm/stretch

« back to all changes in this revision

Viewing changes to src/session-config.c

  • Committer: Package Import Robot
  • Author(s): Yves-Alexis Perez
  • Date: 2013-10-20 20:45:55 UTC
  • mfrom: (1.1.17)
  • Revision ID: package-import@ubuntu.com-20131020204555-0ht6bt0lw5bof9fn
Tags: 1.8.2-1
* New upstream release.
* debian/patches:
  - 01_set-default-path, 02_default-config, 05_debianize-pam-files
    refreshed.
  - 03_quit-plymouth disabled for now, to check if problem is really fixed
    upstream.
* debian/control:
  - rename liblightdm-qt-2-0 to liblightdm-qt-3-0 to match updated soname.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Copyright (C) 2013 Robert Ancell.
 
3
 * Author: Robert Ancell <robert.ancell@canonical.com>
 
4
 *
 
5
 * This program is free software: you can redistribute it and/or modify it under
 
6
 * the terms of the GNU General Public License as published by the Free Software
 
7
 * Foundation, either version 3 of the License, or (at your option) any later
 
8
 * version. See http://www.gnu.org/copyleft/gpl.html the full text of the
 
9
 * license.
 
10
 */
 
11
 
 
12
#include "session-config.h"
 
13
 
 
14
struct SessionConfigPrivate
 
15
{
 
16
    /* Session type */
 
17
    gchar *session_type;
 
18
 
 
19
    /* Desktop name */
 
20
    gchar *desktop_name;
 
21
 
 
22
    /* Command to run */
 
23
    gchar *command;
 
24
};
 
25
 
 
26
G_DEFINE_TYPE (SessionConfig, session_config, G_TYPE_OBJECT);
 
27
 
 
28
SessionConfig *
 
29
session_config_new_from_file (const gchar *filename, GError **error)
 
30
{
 
31
    GKeyFile *desktop_file;
 
32
    SessionConfig *config;
 
33
    gchar *command;
 
34
 
 
35
    desktop_file = g_key_file_new ();
 
36
    if (!g_key_file_load_from_file (desktop_file, filename, G_KEY_FILE_NONE, error))
 
37
        return NULL;
 
38
    command = g_key_file_get_string (desktop_file, G_KEY_FILE_DESKTOP_GROUP, G_KEY_FILE_DESKTOP_KEY_EXEC, NULL);
 
39
    if (!command)
 
40
    {
 
41
        g_set_error (error,
 
42
                     G_KEY_FILE_ERROR,
 
43
                     G_KEY_FILE_ERROR_KEY_NOT_FOUND,
 
44
                     "No Exec option in session file: %s", filename);
 
45
        return NULL;
 
46
    }
 
47
 
 
48
    config = g_object_new (SESSION_CONFIG_TYPE, NULL);
 
49
    config->priv->command = command;
 
50
    config->priv->session_type = g_key_file_get_string (desktop_file, G_KEY_FILE_DESKTOP_GROUP, "X-LightDM-Session-Type", NULL);
 
51
    if (!config->priv->session_type)
 
52
        config->priv->session_type = g_strdup ("x");
 
53
    config->priv->desktop_name = g_key_file_get_string (desktop_file, G_KEY_FILE_DESKTOP_GROUP, "X-LightDM-DesktopName", NULL);
 
54
 
 
55
    g_key_file_free (desktop_file);
 
56
 
 
57
    return config;
 
58
}
 
59
 
 
60
const gchar *
 
61
session_config_get_command (SessionConfig *config)
 
62
{
 
63
    g_return_val_if_fail (config != NULL, NULL);
 
64
    return config->priv->command;
 
65
}
 
66
 
 
67
const gchar *
 
68
session_config_get_session_type (SessionConfig *config)
 
69
{
 
70
    g_return_val_if_fail (config != NULL, NULL);
 
71
    return config->priv->session_type;
 
72
}
 
73
 
 
74
const gchar *
 
75
session_config_get_desktop_name (SessionConfig *config)
 
76
{
 
77
    g_return_val_if_fail (config != NULL, NULL);
 
78
    return config->priv->desktop_name;
 
79
}
 
80
 
 
81
static void
 
82
session_config_init (SessionConfig *config)
 
83
{
 
84
    config->priv = G_TYPE_INSTANCE_GET_PRIVATE (config, SESSION_CONFIG_TYPE, SessionConfigPrivate);
 
85
}
 
86
 
 
87
static void
 
88
session_config_finalize (GObject *object)
 
89
{
 
90
    SessionConfig *self = SESSION_CONFIG (object);
 
91
 
 
92
    g_free (self->priv->session_type);
 
93
    g_free (self->priv->desktop_name);
 
94
    g_free (self->priv->command);
 
95
 
 
96
    G_OBJECT_CLASS (session_config_parent_class)->finalize (object);
 
97
}
 
98
 
 
99
static void
 
100
session_config_class_init (SessionConfigClass *klass)
 
101
{
 
102
    GObjectClass *object_class = G_OBJECT_CLASS (klass);
 
103
 
 
104
    object_class->finalize = session_config_finalize;
 
105
 
 
106
    g_type_class_add_private (klass, sizeof (SessionConfigPrivate));
 
107
}