2 * Copyright (C) 2013 Robert Ancell.
3 * Author: Robert Ancell <robert.ancell@canonical.com>
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
12 #include "session-config.h"
14 struct SessionConfigPrivate
25 /* Compositor command to run (for type mir-container) */
26 gchar *compositor_command;
29 G_DEFINE_TYPE (SessionConfig, session_config, G_TYPE_OBJECT);
32 session_config_new_from_file (const gchar *filename, GError **error)
34 GKeyFile *desktop_file;
35 SessionConfig *config;
37 gchar **desktop_names;
39 desktop_file = g_key_file_new ();
40 if (!g_key_file_load_from_file (desktop_file, filename, G_KEY_FILE_NONE, error))
42 command = g_key_file_get_string (desktop_file, G_KEY_FILE_DESKTOP_GROUP, G_KEY_FILE_DESKTOP_KEY_EXEC, NULL);
47 G_KEY_FILE_ERROR_KEY_NOT_FOUND,
48 "No Exec option in session file: %s", filename);
52 config = g_object_new (SESSION_CONFIG_TYPE, NULL);
53 config->priv->command = command;
54 config->priv->session_type = g_key_file_get_string (desktop_file, G_KEY_FILE_DESKTOP_GROUP, "X-LightDM-Session-Type", NULL);
55 if (!config->priv->session_type)
56 config->priv->session_type = g_strdup ("x");
58 desktop_names = g_key_file_get_string_list (desktop_file, G_KEY_FILE_DESKTOP_GROUP, "DesktopNames", NULL, NULL);
59 if (desktop_names != NULL)
61 config->priv->desktop_name = g_strjoinv (":", desktop_names);
62 g_strfreev (desktop_names);
64 if (!config->priv->desktop_name)
65 config->priv->desktop_name = g_key_file_get_string (desktop_file, G_KEY_FILE_DESKTOP_GROUP, "X-LightDM-DesktopName", NULL);
66 config->priv->compositor_command = g_key_file_get_string (desktop_file, G_KEY_FILE_DESKTOP_GROUP, "X-LightDM-System-Compositor-Command", NULL);
68 g_key_file_free (desktop_file);
74 session_config_get_command (SessionConfig *config)
76 g_return_val_if_fail (config != NULL, NULL);
77 return config->priv->command;
81 session_config_get_session_type (SessionConfig *config)
83 g_return_val_if_fail (config != NULL, NULL);
84 return config->priv->session_type;
88 session_config_get_desktop_name (SessionConfig *config)
90 g_return_val_if_fail (config != NULL, NULL);
91 return config->priv->desktop_name;
95 session_config_get_compositor_command (SessionConfig *config)
97 g_return_val_if_fail (config != NULL, NULL);
98 return config->priv->compositor_command;
102 session_config_init (SessionConfig *config)
104 config->priv = G_TYPE_INSTANCE_GET_PRIVATE (config, SESSION_CONFIG_TYPE, SessionConfigPrivate);
105 config->priv->desktop_name = NULL;
109 session_config_finalize (GObject *object)
111 SessionConfig *self = SESSION_CONFIG (object);
113 g_free (self->priv->session_type);
114 g_free (self->priv->desktop_name);
115 g_free (self->priv->command);
116 g_free (self->priv->compositor_command);
118 G_OBJECT_CLASS (session_config_parent_class)->finalize (object);
122 session_config_class_init (SessionConfigClass *klass)
124 GObjectClass *object_class = G_OBJECT_CLASS (klass);
126 object_class->finalize = session_config_finalize;
128 g_type_class_add_private (klass, sizeof (SessionConfigPrivate));