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
26 G_DEFINE_TYPE (SessionConfig, session_config, G_TYPE_OBJECT);
29 session_config_new_from_file (const gchar *filename, GError **error)
31 GKeyFile *desktop_file;
32 SessionConfig *config;
35 desktop_file = g_key_file_new ();
36 if (!g_key_file_load_from_file (desktop_file, filename, G_KEY_FILE_NONE, error))
38 command = g_key_file_get_string (desktop_file, G_KEY_FILE_DESKTOP_GROUP, G_KEY_FILE_DESKTOP_KEY_EXEC, NULL);
43 G_KEY_FILE_ERROR_KEY_NOT_FOUND,
44 "No Exec option in session file: %s", filename);
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");
54 config->priv->desktop_name = g_key_file_get_string (desktop_file, G_KEY_FILE_DESKTOP_GROUP, "DesktopNames", NULL);
55 if (!config->priv->desktop_name)
56 config->priv->desktop_name = g_key_file_get_string (desktop_file, G_KEY_FILE_DESKTOP_GROUP, "X-LightDM-DesktopName", NULL);
58 g_key_file_free (desktop_file);
64 session_config_get_command (SessionConfig *config)
66 g_return_val_if_fail (config != NULL, NULL);
67 return config->priv->command;
71 session_config_get_session_type (SessionConfig *config)
73 g_return_val_if_fail (config != NULL, NULL);
74 return config->priv->session_type;
78 session_config_get_desktop_name (SessionConfig *config)
80 g_return_val_if_fail (config != NULL, NULL);
81 return config->priv->desktop_name;
85 session_config_init (SessionConfig *config)
87 config->priv = G_TYPE_INSTANCE_GET_PRIVATE (config, SESSION_CONFIG_TYPE, SessionConfigPrivate);
91 session_config_finalize (GObject *object)
93 SessionConfig *self = SESSION_CONFIG (object);
95 g_free (self->priv->session_type);
96 g_free (self->priv->desktop_name);
97 g_free (self->priv->command);
99 G_OBJECT_CLASS (session_config_parent_class)->finalize (object);
103 session_config_class_init (SessionConfigClass *klass)
105 GObjectClass *object_class = G_OBJECT_CLASS (klass);
107 object_class->finalize = session_config_finalize;
109 g_type_class_add_private (klass, sizeof (SessionConfigPrivate));