]> rtime.felk.cvut.cz Git - sojka/lightdm.git/blob - src/session-config.c
Make a login1 service object (not currently required, but will be used for automatic...
[sojka/lightdm.git] / src / session-config.c
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     /* Compositor command to run (for type mir-container) */
26     gchar *compositor_command;
27 };
28
29 G_DEFINE_TYPE (SessionConfig, session_config, G_TYPE_OBJECT);
30
31 SessionConfig *
32 session_config_new_from_file (const gchar *filename, GError **error)
33 {
34     GKeyFile *desktop_file;
35     SessionConfig *config;
36     gchar *command;
37
38     desktop_file = g_key_file_new ();
39     if (!g_key_file_load_from_file (desktop_file, filename, G_KEY_FILE_NONE, error))
40         return NULL;
41     command = g_key_file_get_string (desktop_file, G_KEY_FILE_DESKTOP_GROUP, G_KEY_FILE_DESKTOP_KEY_EXEC, NULL);
42     if (!command)
43     {
44         g_set_error (error,
45                      G_KEY_FILE_ERROR,
46                      G_KEY_FILE_ERROR_KEY_NOT_FOUND,
47                      "No Exec option in session file: %s", filename);
48         return NULL;
49     }
50
51     config = g_object_new (SESSION_CONFIG_TYPE, NULL);
52     config->priv->command = command;
53     config->priv->session_type = g_key_file_get_string (desktop_file, G_KEY_FILE_DESKTOP_GROUP, "X-LightDM-Session-Type", NULL);
54     if (!config->priv->session_type)
55         config->priv->session_type = g_strdup ("x");
56
57     config->priv->desktop_name = g_key_file_get_string (desktop_file, G_KEY_FILE_DESKTOP_GROUP, "DesktopNames", NULL);
58     if (!config->priv->desktop_name)
59         config->priv->desktop_name = g_key_file_get_string (desktop_file, G_KEY_FILE_DESKTOP_GROUP, "X-LightDM-DesktopName", NULL);
60     if (!config->priv->compositor_command)
61         config->priv->compositor_command = g_key_file_get_string (desktop_file, G_KEY_FILE_DESKTOP_GROUP, "X-LightDM-System-Compositor-Command", NULL);
62
63     g_key_file_free (desktop_file);
64
65     return config;
66 }
67
68 const gchar *
69 session_config_get_command (SessionConfig *config)
70 {
71     g_return_val_if_fail (config != NULL, NULL);
72     return config->priv->command;
73 }
74
75 const gchar *
76 session_config_get_session_type (SessionConfig *config)
77 {
78     g_return_val_if_fail (config != NULL, NULL);
79     return config->priv->session_type;
80 }
81
82 const gchar *
83 session_config_get_desktop_name (SessionConfig *config)
84 {
85     g_return_val_if_fail (config != NULL, NULL);
86     return config->priv->desktop_name;
87 }
88
89 const gchar *
90 session_config_get_compositor_command (SessionConfig *config)
91 {
92     g_return_val_if_fail (config != NULL, NULL);
93     return config->priv->compositor_command;
94 }
95
96 static void
97 session_config_init (SessionConfig *config)
98 {
99     config->priv = G_TYPE_INSTANCE_GET_PRIVATE (config, SESSION_CONFIG_TYPE, SessionConfigPrivate);
100 }
101
102 static void
103 session_config_finalize (GObject *object)
104 {
105     SessionConfig *self = SESSION_CONFIG (object);
106
107     g_free (self->priv->session_type);
108     g_free (self->priv->desktop_name);
109     g_free (self->priv->command);
110     g_free (self->priv->compositor_command);
111
112     G_OBJECT_CLASS (session_config_parent_class)->finalize (object);
113 }
114
115 static void
116 session_config_class_init (SessionConfigClass *klass)
117 {
118     GObjectClass *object_class = G_OBJECT_CLASS (klass);
119
120     object_class->finalize = session_config_finalize;
121
122     g_type_class_add_private (klass, sizeof (SessionConfigPrivate));
123 }