]> rtime.felk.cvut.cz Git - sojka/lightdm.git/blobdiff - liblightdm-gobject/session.c
Use G_DECLARE_*_TYPE to simplify code and fix docs
[sojka/lightdm.git] / liblightdm-gobject / session.c
index e3ef2953b23f356057ae4299bf4c013088694ba4..fbbc5f794c2e7be46936036fe9fe69e0be15169a 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * Copyright (C) 2010 Robert Ancell.
  * Author: Robert Ancell <robert.ancell@canonical.com>
- * 
+ *
  * This library is free software; you can redistribute it and/or modify it under
  * the terms of the GNU Lesser General Public License as published by the Free
  * Software Foundation; either version 2 or version 3 of the License.
 #include "lightdm/session.h"
 
 enum {
-    PROP_0,
-    PROP_KEY,
+    PROP_KEY = 1,
     PROP_NAME,
     PROP_COMMENT
 };
 
-typedef struct
+struct _LightDMSession
 {
     gchar *key;
     gchar *type;
     gchar *name;
     gchar *comment;
-} LightDMSessionPrivate;
+};
 
 G_DEFINE_TYPE (LightDMSession, lightdm_session, G_TYPE_OBJECT);
 
-#define GET_PRIVATE(obj) G_TYPE_INSTANCE_GET_PRIVATE ((obj), LIGHTDM_TYPE_SESSION, LightDMSessionPrivate)
-
 static gboolean have_sessions = FALSE;
 static GList *local_sessions = NULL;
 static GList *remote_sessions = NULL;
 
-static gint 
+static gint
 compare_session (gconstpointer a, gconstpointer b)
 {
-    LightDMSessionPrivate *priv_a = GET_PRIVATE (a);
-    LightDMSessionPrivate *priv_b = GET_PRIVATE (b);
-    return strcmp (priv_a->name, priv_b->name);
+    const LightDMSession *sa = a, *sb = b;
+    return strcmp (sa->name, sb->name);
 }
 
 static LightDMSession *
-load_session (GKeyFile *key_file, const gchar *key)
+load_session (GKeyFile *key_file, const gchar *key, const gchar *default_type)
 {
-    gchar *type, *domain, *name;
+    gchar *domain, *name, *type;
     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;
 
-    type = g_key_file_get_string (key_file, G_KEY_FILE_DESKTOP_GROUP, "X-LightDM-Session-Type", NULL);
-    if (!type)
-        type = "x";
-
 #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
@@ -91,22 +82,25 @@ load_session (GKeyFile *key_file, const gchar *key)
         g_free (full_path);
     }
 
+    type = g_key_file_get_string (key_file, G_KEY_FILE_DESKTOP_GROUP, "X-LightDM-Session-Type", NULL);
+    if (!type)
+        type = strdup (default_type);
+
     session = g_object_new (LIGHTDM_TYPE_SESSION, NULL);
-    priv = GET_PRIVATE (session);
 
-    g_free (priv->key);
-    priv->key = g_strdup (key);
+    g_free (session->key);
+    session->key = g_strdup (key);
 
-    g_free (priv->type);
-    priv->type = g_strdup (type);
+    g_free (session->type);
+    session->type = type;
 
-    g_free (priv->name);
-    priv->name = name;
+    g_free (session->name);
+    session->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 ("");
+    g_free (session->comment);
+    session->comment = g_key_file_get_locale_string (key_file, G_KEY_FILE_DESKTOP_GROUP, G_KEY_FILE_DESKTOP_KEY_COMMENT, domain, NULL);
+    if (!session->comment)
+        session->comment = g_strdup ("");
 
     g_free (domain);
 
@@ -114,7 +108,7 @@ load_session (GKeyFile *key_file, const gchar *key)
 }
 
 static GList *
-load_sessions_dir (GList *sessions, const gchar *sessions_dir)
+load_sessions_dir (GList *sessions, const gchar *sessions_dir, const gchar *default_type)
 {
     GDir *directory;
     GError *error = NULL;
@@ -154,10 +148,10 @@ load_sessions_dir (GList *sessions, const gchar *sessions_dir)
             LightDMSession *session;
 
             key = g_strndup (filename, strlen (filename) - strlen (".desktop"));
-            session = load_session (key_file, key);
+            session = load_session (key_file, key, default_type);
             if (session)
             {
-                g_debug ("Loaded session %s (%s, %s)", path, GET_PRIVATE (session)->name, GET_PRIVATE (session)->comment);
+                g_debug ("Loaded session %s (%s, %s)", path, session->name, session->comment);
                 sessions = g_list_insert_sorted (sessions, session, compare_session);
             }
             else
@@ -170,7 +164,7 @@ load_sessions_dir (GList *sessions, const gchar *sessions_dir)
     }
 
     g_dir_close (directory);
-  
+
     return sessions;
 }
 
@@ -182,10 +176,18 @@ load_sessions (const gchar *sessions_dir)
     int i;
 
     dirs = g_strsplit (sessions_dir, ":", -1);
-    for (i = 0; dirs[i]; i++)
-        sessions = load_sessions_dir (sessions, dirs[i]);
+    for (i = 0; dirs[i]; i++) 
+    {
+        const gchar *default_type = "x";
+
+        if (strcmp (dirs[i], WAYLAND_SESSIONS_DIR) == 0)
+            default_type = "wayland";
+
+        sessions = load_sessions_dir (sessions, dirs[i], default_type);
+    }
     g_strfreev (dirs);
-  
+
     return sessions;
 }
 
@@ -194,7 +196,6 @@ update_sessions (void)
 {
     gchar *sessions_dir;
     gchar *remote_sessions_dir;
-    gboolean result;
     gchar *value;
 
     if (have_sessions)
@@ -205,7 +206,7 @@ update_sessions (void)
 
     /* Use session directory from configuration */
     config_load_from_standard_locations (config_get_instance (), NULL, NULL);
-      
+
     value = config_get_string (config_get_instance (), "LightDM", "sessions-directory");
     if (value)
     {
@@ -260,61 +261,61 @@ lightdm_get_remote_sessions (void)
 /**
  * lightdm_session_get_key:
  * @session: A #LightDMSession
- * 
+ *
  * Get the key for a session
- * 
+ *
  * Return value: The session key
  **/
 const gchar *
 lightdm_session_get_key (LightDMSession *session)
 {
     g_return_val_if_fail (LIGHTDM_IS_SESSION (session), NULL);
-    return GET_PRIVATE (session)->key;
+    return session->key;
 }
 
 /**
  * lightdm_session_get_session_type:
  * @session: A #LightDMSession
- * 
+ *
  * Get the type a session
- * 
+ *
  * Return value: The session type, e.g. x or mir
  **/
 const gchar *
 lightdm_session_get_session_type (LightDMSession *session)
 {
     g_return_val_if_fail (LIGHTDM_IS_SESSION (session), NULL);
-    return GET_PRIVATE (session)->type;
+    return session->type;
 }
 
 /**
  * lightdm_session_get_name:
  * @session: A #LightDMSession
- * 
+ *
  * Get the name for a session
- * 
+ *
  * Return value: The session name
  **/
 const gchar *
 lightdm_session_get_name (LightDMSession *session)
 {
     g_return_val_if_fail (LIGHTDM_IS_SESSION (session), NULL);
-    return GET_PRIVATE (session)->name;
+    return session->name;
 }
 
 /**
  * lightdm_session_get_comment:
  * @session: A #LightDMSession
- * 
+ *
  * Get the comment for a session
- * 
+ *
  * Return value: The session comment
  **/
 const gchar *
 lightdm_session_get_comment (LightDMSession *session)
 {
     g_return_val_if_fail (LIGHTDM_IS_SESSION (session), NULL);
-    return GET_PRIVATE (session)->comment;
+    return session->comment;
 }
 
 static void
@@ -324,18 +325,18 @@ lightdm_session_init (LightDMSession *session)
 
 static void
 lightdm_session_set_property (GObject      *object,
-                          guint         prop_id,
-                          const GValue *value,
-                          GParamSpec   *pspec)
+                              guint         prop_id,
+                              const GValue *value,
+                              GParamSpec   *pspec)
 {
     G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
 }
 
 static void
 lightdm_session_get_property (GObject    *object,
-                          guint       prop_id,
-                          GValue     *value,
-                          GParamSpec *pspec)
+                              guint       prop_id,
+                              GValue     *value,
+                              GParamSpec *pspec)
 {
     LightDMSession *self;
 
@@ -361,20 +362,17 @@ static void
 lightdm_session_finalize (GObject *object)
 {
     LightDMSession *self = LIGHTDM_SESSION (object);
-    LightDMSessionPrivate *priv = GET_PRIVATE (self);
 
-    g_free (priv->key);
-    g_free (priv->type);
-    g_free (priv->name);
-    g_free (priv->comment);
+    g_free (self->key);
+    g_free (self->type);
+    g_free (self->name);
+    g_free (self->comment);
 }
 
 static void
 lightdm_session_class_init (LightDMSessionClass *klass)
 {
     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;