Back to index

lightdm  1.3.2
Classes | Defines | Enumerations | Functions | Variables
session.c File Reference
#include <string.h>
#include <gio/gdesktopappinfo.h>
#include "lightdm/session.h"

Go to the source code of this file.

Classes

struct  LightDMSessionPrivate

Defines

#define GET_PRIVATE(obj)   G_TYPE_INSTANCE_GET_PRIVATE ((obj), LIGHTDM_TYPE_SESSION, LightDMSessionPrivate)

Enumerations

enum  { PROP_0, PROP_KEY, PROP_NAME, PROP_COMMENT }

Functions

 G_DEFINE_TYPE (LightDMSession, lightdm_session, G_TYPE_OBJECT)
static gint compare_session (gconstpointer a, gconstpointer b)
static LightDMSessionload_session (GKeyFile *key_file, const gchar *key)
static void update_sessions (void)
GList * lightdm_get_sessions (void)
 lightdm_get_sessions:
const gchar * lightdm_session_get_key (LightDMSession *session)
 lightdm_session_get_key: : A LightDMSession
const gchar * lightdm_session_get_name (LightDMSession *session)
 lightdm_session_get_name: : A LightDMSession
const gchar * lightdm_session_get_comment (LightDMSession *session)
 lightdm_session_get_comment: : A LightDMSession
static void lightdm_session_init (LightDMSession *session)
static void lightdm_session_set_property (GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec)
static void lightdm_session_get_property (GObject *object, guint prop_id, GValue *value, GParamSpec *pspec)
static void lightdm_session_finalize (GObject *object)
static void lightdm_session_class_init (LightDMSessionClass *klass)

Variables

static gboolean have_sessions = FALSE
static GList * sessions = NULL

Class Documentation

struct LightDMSessionPrivate

Definition at line 24 of file session.c.

Class Members
gchar * comment
gchar * key
gchar * name

Define Documentation

#define GET_PRIVATE (   obj)    G_TYPE_INSTANCE_GET_PRIVATE ((obj), LIGHTDM_TYPE_SESSION, LightDMSessionPrivate)

Definition at line 33 of file session.c.


Enumeration Type Documentation

anonymous enum
Enumerator:
PROP_0 
PROP_KEY 
PROP_NAME 
PROP_COMMENT 

Definition at line 17 of file session.c.


Function Documentation

static gint compare_session ( gconstpointer  a,
gconstpointer  b 
) [static]

Definition at line 39 of file session.c.

{
    LightDMSessionPrivate *priv_a = GET_PRIVATE (a);
    LightDMSessionPrivate *priv_b = GET_PRIVATE (b);
    return strcmp (priv_a->name, priv_b->name);
}

Here is the caller graph for this function:

G_DEFINE_TYPE ( LightDMSession  ,
lightdm_session  ,
G_TYPE_OBJECT   
)
GList* lightdm_get_sessions ( void  )

lightdm_get_sessions:

Get the available sessions.

Return value: (element-type LightDMSession) (transfer none): A list of LightDMSession

Definition at line 205 of file session.c.

{
    update_sessions ();
    return sessions;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static void lightdm_session_class_init ( LightDMSessionClass klass) [static]

Definition at line 308 of file session.c.

{
    GObjectClass *object_class = G_OBJECT_CLASS (klass);
  
    g_type_class_add_private (klass, sizeof (LightDMSessionPrivate));

    object_class->set_property = lightdm_session_set_property;
    object_class->get_property = lightdm_session_get_property;
    object_class->finalize = lightdm_session_finalize;

    g_object_class_install_property (object_class,
                                     PROP_KEY,
                                     g_param_spec_string ("key",
                                                          "key",
                                                          "Session key",
                                                          NULL,
                                                          G_PARAM_READABLE));
    g_object_class_install_property (object_class,
                                     PROP_NAME,
                                     g_param_spec_string ("name",
                                                          "name",
                                                          "Session name",
                                                          NULL,
                                                          G_PARAM_READABLE));
    g_object_class_install_property (object_class,
                                     PROP_COMMENT,
                                     g_param_spec_string ("comment",
                                                          "comment",
                                                          "Session comment",
                                                          NULL,
                                                          G_PARAM_READABLE));
}

Here is the call graph for this function:

static void lightdm_session_finalize ( GObject *  object) [static]

Definition at line 297 of file session.c.

{
    LightDMSession *self = LIGHTDM_SESSION (object);
    LightDMSessionPrivate *priv = GET_PRIVATE (self);

    g_free (priv->key);
    g_free (priv->name);
    g_free (priv->comment);
}

Here is the caller graph for this function:

const gchar* lightdm_session_get_comment ( LightDMSession session)

lightdm_session_get_comment: : A LightDMSession

Get the comment for a session

Return value: The session comment

Definition at line 250 of file session.c.

{
    g_return_val_if_fail (LIGHTDM_IS_SESSION (session), NULL);
    return GET_PRIVATE (session)->comment;
}

Here is the caller graph for this function:

const gchar* lightdm_session_get_key ( LightDMSession session)

lightdm_session_get_key: : A LightDMSession

Get the key for a session

Return value: The session key

Definition at line 220 of file session.c.

{
    g_return_val_if_fail (LIGHTDM_IS_SESSION (session), NULL);
    return GET_PRIVATE (session)->key;
}

Here is the caller graph for this function:

const gchar* lightdm_session_get_name ( LightDMSession session)

lightdm_session_get_name: : A LightDMSession

Get the name for a session

Return value: The session name

Definition at line 235 of file session.c.

{
    g_return_val_if_fail (LIGHTDM_IS_SESSION (session), NULL);
    return GET_PRIVATE (session)->name;
}

Here is the caller graph for this function:

static void lightdm_session_get_property ( GObject *  object,
guint  prop_id,
GValue *  value,
GParamSpec *  pspec 
) [static]

Definition at line 271 of file session.c.

{
    LightDMSession *self;

    self = LIGHTDM_SESSION (object);

    switch (prop_id) {
    case PROP_KEY:
        g_value_set_string (value, lightdm_session_get_key (self));
        break;
    case PROP_NAME:
        g_value_set_string (value, lightdm_session_get_name (self));
        break;
    case PROP_COMMENT:
        g_value_set_string (value, lightdm_session_get_comment (self));
        break;
    default:
        G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
        break;
    }
}

Here is the call graph for this function:

Here is the caller graph for this function:

static void lightdm_session_init ( LightDMSession session) [static]

Definition at line 257 of file session.c.

{
}
static void lightdm_session_set_property ( GObject *  object,
guint  prop_id,
const GValue *  value,
GParamSpec *  pspec 
) [static]

Definition at line 262 of file session.c.

{
    G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
}

Here is the caller graph for this function:

static LightDMSession* load_session ( GKeyFile *  key_file,
const gchar *  key 
) [static]

Definition at line 47 of file session.c.

{
    gchar *domain, *name;
    LightDMSession *session;
    LightDMSessionPrivate *priv;
    gchar *try_exec;
  
    if (g_key_file_get_boolean (key_file, G_KEY_FILE_DESKTOP_GROUP, G_KEY_FILE_DESKTOP_KEY_NO_DISPLAY, NULL) ||
        g_key_file_get_boolean (key_file, G_KEY_FILE_DESKTOP_GROUP, G_KEY_FILE_DESKTOP_KEY_HIDDEN, NULL))
        return NULL;

#ifdef G_KEY_FILE_DESKTOP_KEY_GETTEXT_DOMAIN
    domain = g_key_file_get_string (key_file, G_KEY_FILE_DESKTOP_GROUP, G_KEY_FILE_DESKTOP_KEY_GETTEXT_DOMAIN, NULL);
#else
    domain = g_key_file_get_string (key_file, G_KEY_FILE_DESKTOP_GROUP, "X-GNOME-Gettext-Domain", NULL);
#endif
    name = g_key_file_get_locale_string (key_file, G_KEY_FILE_DESKTOP_GROUP, G_KEY_FILE_DESKTOP_KEY_NAME, domain, NULL);
    if (!name)
    {
        g_warning ("Ignoring session without name");
        g_free (domain);
        return NULL;
    }

    try_exec = g_key_file_get_locale_string (key_file, G_KEY_FILE_DESKTOP_GROUP, G_KEY_FILE_DESKTOP_KEY_TRY_EXEC, domain, NULL);
    if (try_exec)
    {
        gchar *full_path;

        full_path = g_find_program_in_path (try_exec);
        g_free (try_exec);

        if (!full_path)
        {
            g_free (name);
            g_free (domain);
            return NULL;
        }
        g_free (full_path);
    }

    session = g_object_new (LIGHTDM_TYPE_SESSION, NULL);
    priv = GET_PRIVATE (session);

    g_free (priv->key);
    priv->key = g_strdup (key);

    g_free (priv->name);
    priv->name = name;

    g_free (priv->comment);
    priv->comment = g_key_file_get_locale_string (key_file, G_KEY_FILE_DESKTOP_GROUP, G_KEY_FILE_DESKTOP_KEY_COMMENT, domain, NULL);
    if (!priv->comment)
        priv->comment = g_strdup ("");

    sessions = g_list_insert_sorted (sessions, session, compare_session);

    g_free (domain);

    return session;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static void update_sessions ( void  ) [static]

Definition at line 110 of file session.c.

{
    GDir *directory;
    gboolean result;
    GError *error = NULL;

    GKeyFile *config_key_file = NULL;
    gchar *config_path = NULL;
    gchar *xsessions_dir = g_strdup (XSESSIONS_DIR);

    if (have_sessions)
        return;

    config_path = g_build_filename (CONFIG_DIR, "lightdm.conf", NULL);
    config_key_file = g_key_file_new ();
    result = g_key_file_load_from_file (config_key_file, config_path, G_KEY_FILE_NONE, &error);
    if (error)
        g_warning ("Failed to open configuration file: %s", error->message);
    g_clear_error (&error);
    if (result)
    {
        gchar *xd_value = g_key_file_get_string (config_key_file, "LightDM", "xsessions-directory", NULL);
        if (xd_value)
        {
            g_free (xsessions_dir);
            xsessions_dir = xd_value;
        }
    }
    g_key_file_free (config_key_file);
    g_free (config_path);
    
    directory = g_dir_open (xsessions_dir, 0, &error);
    if (error)
        g_warning ("Failed to open sessions directory: %s", error->message);
    g_clear_error (&error);
    if (!directory)
    {
        g_free (xsessions_dir);
        return;
    }

    while (TRUE)
    {
        const gchar *filename;
        gchar *path;
        GKeyFile *key_file;
        gboolean result;

        filename = g_dir_read_name (directory);
        if (filename == NULL)
            break;

        if (!g_str_has_suffix (filename, ".desktop"))
            continue;

        path = g_build_filename (xsessions_dir, filename, NULL);

        key_file = g_key_file_new ();
        result = g_key_file_load_from_file (key_file, path, G_KEY_FILE_NONE, &error);
        if (error)
            g_warning ("Failed to load session file %s: %s:", path, error->message);
        g_clear_error (&error);

        if (result)
        {
            gchar *key;
            LightDMSession *session;

            key = g_strndup (filename, strlen (filename) - strlen (".desktop"));
            session = load_session (key_file, key);
            if (session)
                g_debug ("Loaded session %s (%s, %s)", path, GET_PRIVATE (session)->name, GET_PRIVATE (session)->comment);
            else
                g_debug ("Ignoring session %s", path);
            g_free (key);
        }

        g_free (path);
        g_key_file_free (key_file);
    }

    g_dir_close (directory);
    g_free (xsessions_dir);

    have_sessions = TRUE;
}

Here is the call graph for this function:

Here is the caller graph for this function:


Variable Documentation

gboolean have_sessions = FALSE [static]

Definition at line 35 of file session.c.

GList* sessions = NULL [static]

Definition at line 36 of file session.c.