]> rtime.felk.cvut.cz Git - sojka/lightdm.git/blobdiff - liblightdm-gobject/layout.c
Add missing finalize for LightDMLayout
[sojka/lightdm.git] / liblightdm-gobject / layout.c
index 6d0ab19a352e93cd138a5821e2c4d1f3e3ce9c17..13c974f318212455552b1cf47d14f95a01d1d9c5 100644 (file)
@@ -2,7 +2,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/layout.h"
 
 enum {
-    PROP_0,
-    PROP_NAME,
+    PROP_NAME = 1,
     PROP_SHORT_DESCRIPTION,
     PROP_DESCRIPTION
 };
 
-typedef struct
+struct _LightDMLayout
 {
+    GObject parent_instance;
+
     gchar *name;
     gchar *short_description;
     gchar *description;
-} LightDMLayoutPrivate;
+};
 
 G_DEFINE_TYPE (LightDMLayout, lightdm_layout, G_TYPE_OBJECT);
 
-#define GET_PRIVATE(obj) G_TYPE_INSTANCE_GET_PRIVATE ((obj), LIGHTDM_TYPE_LAYOUT, LightDMLayoutPrivate)
-
 static gboolean have_layouts = FALSE;
 static Display *display = NULL;
 static XklEngine *xkl_engine = NULL;
@@ -109,30 +108,26 @@ layout_cb (XklConfigRegistry *config,
 GList *
 lightdm_get_layouts (void)
 {
+    XklConfigRegistry *registry;
+
     if (have_layouts)
         return layouts;
 
     display = XOpenDisplay (NULL);
-    xkl_engine = xkl_engine_get_instance (display);
-    if (xkl_engine == NULL)
-    {
-        g_warning ("Failed to get Xkl engine for display '%p'", display);
-    }
-    else
-    {
-        XklConfigRegistry *registry;
+    if (display == NULL)
+        return NULL;
 
-        xkl_config = xkl_config_rec_new ();
-        if (!xkl_config_rec_get_from_server (xkl_config, xkl_engine))
-            g_warning ("Failed to get Xkl configuration from server");
+    xkl_engine = xkl_engine_get_instance (display);
+    xkl_config = xkl_config_rec_new ();
+    if (!xkl_config_rec_get_from_server (xkl_config, xkl_engine))
+        g_warning ("Failed to get Xkl configuration from server");
 
-        registry = xkl_config_registry_get_instance (xkl_engine);
-        xkl_config_registry_load (registry, FALSE);
-        xkl_config_registry_foreach_layout (registry, layout_cb, NULL);
-        g_object_unref (registry);
+    registry = xkl_config_registry_get_instance (xkl_engine);
+    xkl_config_registry_load (registry, FALSE);
+    xkl_config_registry_foreach_layout (registry, layout_cb, NULL);
+    g_object_unref (registry);
 
-        have_layouts = TRUE;
-    }
+    have_layouts = TRUE;
 
     return layouts;
 }
@@ -207,22 +202,22 @@ lightdm_get_layout (void)
 /**
  * lightdm_layout_get_name:
  * @layout: A #LightDMLayout
- * 
+ *
  * Get the name of a layout.
- * 
+ *
  * Return value: The name of the layout
  **/
 const gchar *
 lightdm_layout_get_name (LightDMLayout *layout)
 {
     g_return_val_if_fail (LIGHTDM_IS_LAYOUT (layout), NULL);
-    return GET_PRIVATE (layout)->name;
+    return layout->name;
 }
 
 /**
  * lightdm_layout_get_short_description:
  * @layout: A #LightDMLayout
- * 
+ *
  * Get the short description of a layout.
  *
  * Return value: A short description of the layout
@@ -231,22 +226,22 @@ const gchar *
 lightdm_layout_get_short_description (LightDMLayout *layout)
 {
     g_return_val_if_fail (LIGHTDM_IS_LAYOUT (layout), NULL);
-    return GET_PRIVATE (layout)->short_description;
+    return layout->short_description;
 }
 
 /**
  * lightdm_layout_get_description:
  * @layout: A #LightDMLayout
- * 
+ *
  * Get the long description of a layout.
- * 
+ *
  * Return value: A long description of the layout
  **/
 const gchar *
 lightdm_layout_get_description (LightDMLayout *layout)
 {
     g_return_val_if_fail (LIGHTDM_IS_LAYOUT (layout), NULL);
-    return GET_PRIVATE (layout)->description;
+    return layout->description;
 }
 
 static void
@@ -256,25 +251,24 @@ lightdm_layout_init (LightDMLayout *layout)
 
 static void
 lightdm_layout_set_property (GObject      *object,
-                         guint         prop_id,
-                         const GValue *value,
-                         GParamSpec   *pspec)
+                             guint         prop_id,
+                             const GValue *value,
+                             GParamSpec   *pspec)
 {
     LightDMLayout *self = LIGHTDM_LAYOUT (object);
-    LightDMLayoutPrivate *priv = GET_PRIVATE (self);
 
     switch (prop_id) {
     case PROP_NAME:
-        g_free (priv->name);
-        priv->name = g_strdup (g_value_get_string (value));
+        g_free (self->name);
+        self->name = g_strdup (g_value_get_string (value));
         break;
     case PROP_SHORT_DESCRIPTION:
-        g_free (priv->short_description);
-        priv->short_description = g_strdup (g_value_get_string (value));
+        g_free (self->short_description);
+        self->short_description = g_strdup (g_value_get_string (value));
         break;
     case PROP_DESCRIPTION:
-        g_free (priv->description);
-        priv->description = g_strdup (g_value_get_string (value));
+        g_free (self->description);
+        self->description = g_strdup (g_value_get_string (value));
         break;
     default:
         G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
@@ -284,9 +278,9 @@ lightdm_layout_set_property (GObject      *object,
 
 static void
 lightdm_layout_get_property (GObject    *object,
-                         guint       prop_id,
-                         GValue     *value,
-                         GParamSpec *pspec)
+                             guint       prop_id,
+                             GValue     *value,
+                             GParamSpec *pspec)
 {
     LightDMLayout *self;
 
@@ -308,15 +302,24 @@ lightdm_layout_get_property (GObject    *object,
     }
 }
 
+static void
+lightdm_layout_finalize (GObject *object)
+{
+    LightDMLayout *self = LIGHTDM_LAYOUT (object);
+
+    g_free (self->name);
+    g_free (self->short_description);  
+    g_free (self->description);
+}
+
 static void
 lightdm_layout_class_init (LightDMLayoutClass *klass)
 {
     GObjectClass *object_class = G_OBJECT_CLASS (klass);
-  
-    g_type_class_add_private (klass, sizeof (LightDMLayoutPrivate));
 
     object_class->set_property = lightdm_layout_set_property;
     object_class->get_property = lightdm_layout_get_property;
+    object_class->finalize = lightdm_layout_finalize;
 
     g_object_class_install_property (object_class,
                                      PROP_NAME,