]> rtime.felk.cvut.cz Git - sojka/lightdm.git/blob - liblightdm-gobject/layout.c
Add g_return_if_fail macros to all the liblightdm-gobject methods
[sojka/lightdm.git] / liblightdm-gobject / layout.c
1 /*
2  * Copyright (C) 2010 Robert Ancell.
3  * Author: Robert Ancell <robert.ancell@canonical.com>
4  * 
5  * This library is free software; you can redistribute it and/or modify it under
6  * the terms of the GNU Lesser General Public License as published by the Free
7  * Software Foundation; either version 3 of the License, or (at your option) any
8  * later version. See http://www.gnu.org/copyleft/lgpl.html the full text of the
9  * license.
10  */
11
12 #include "layout.h"
13
14 enum {
15     PROP_0,
16     PROP_NAME,
17     PROP_SHORT_DESCRIPTION,
18     PROP_DESCRIPTION
19 };
20
21 struct _LdmLayoutPrivate
22 {
23     gchar *name;
24     gchar *short_description;
25     gchar *description;
26 };
27
28 G_DEFINE_TYPE (LdmLayout, ldm_layout, G_TYPE_OBJECT);
29
30 /**
31  * ldm_layout_new:
32  * 
33  * Create a new layout.
34  * @name: The layout name
35  * @short_description: Short description for the layout
36  * @description: Long description for the layout
37  * 
38  * Return value: the new #LdmLayout
39  **/
40 LdmLayout *
41 ldm_layout_new (const gchar *name, const gchar *short_description, const gchar *description)
42 {
43     return g_object_new (LDM_TYPE_LAYOUT, "name", name, "short-description", short_description, "description", description, NULL);
44 }
45
46 /**
47  * ldm_layout_get_name:
48  * @layout: A #LdmLayout
49  * 
50  * Get the name of a layout.
51  * 
52  * Return value: The name of the layout
53  **/
54 const gchar *
55 ldm_layout_get_name (LdmLayout *layout)
56 {
57     g_return_val_if_fail (LDM_IS_LAYOUT (layout), NULL);
58     return layout->priv->name;
59 }
60
61 /**
62  * ldm_layout_get_short_description:
63  * @layout: A #LdmLayout
64  * 
65  * Get the short description of a layout.
66  *
67  * Return value: A short description of the layout
68  **/
69 const gchar *
70 ldm_layout_get_short_description (LdmLayout *layout)
71 {
72     g_return_val_if_fail (LDM_IS_LAYOUT (layout), NULL);
73     return layout->priv->short_description;
74 }
75
76 /**
77  * ldm_layout_get_description:
78  * @layout: A #LdmLayout
79  * 
80  * Get the long description of a layout.
81  * 
82  * Return value: A long description of the layout
83  **/
84 const gchar *
85 ldm_layout_get_description (LdmLayout *layout)
86 {
87     g_return_val_if_fail (LDM_IS_LAYOUT (layout), NULL);
88     return layout->priv->description;
89 }
90
91 static void
92 ldm_layout_init (LdmLayout *layout)
93 {
94     layout->priv = G_TYPE_INSTANCE_GET_PRIVATE (layout, LDM_TYPE_LAYOUT, LdmLayoutPrivate);
95 }
96
97 static void
98 ldm_layout_set_property (GObject      *object,
99                          guint         prop_id,
100                          const GValue *value,
101                          GParamSpec   *pspec)
102 {
103     LdmLayout *self;
104
105     self = LDM_LAYOUT (object);
106
107     switch (prop_id) {
108     case PROP_NAME:
109         g_free (self->priv->name);
110         self->priv->name = g_strdup (g_value_get_string (value));
111         break;
112     case PROP_SHORT_DESCRIPTION:
113         g_free (self->priv->short_description);
114         self->priv->short_description = g_strdup (g_value_get_string (value));
115         break;
116     case PROP_DESCRIPTION:
117         g_free (self->priv->description);
118         self->priv->description = g_strdup (g_value_get_string (value));
119         break;
120     default:
121         G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
122         break;
123     }
124 }
125
126 static void
127 ldm_layout_get_property (GObject    *object,
128                          guint       prop_id,
129                          GValue     *value,
130                          GParamSpec *pspec)
131 {
132     LdmLayout *self;
133
134     self = LDM_LAYOUT (object);
135
136     switch (prop_id) {
137     case PROP_NAME:
138         g_value_set_string (value, ldm_layout_get_name (self));
139         break;
140     case PROP_SHORT_DESCRIPTION:
141         g_value_set_string (value, ldm_layout_get_short_description (self));
142         break;
143     case PROP_DESCRIPTION:
144         g_value_set_string (value, ldm_layout_get_description (self));
145         break;
146     default:
147         G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
148         break;
149     }
150 }
151
152 static void
153 ldm_layout_class_init (LdmLayoutClass *klass)
154 {
155     GObjectClass *object_class = G_OBJECT_CLASS (klass);
156   
157     g_type_class_add_private (klass, sizeof (LdmLayoutPrivate));
158
159     object_class->set_property = ldm_layout_set_property;
160     object_class->get_property = ldm_layout_get_property;
161
162     g_object_class_install_property(object_class,
163                                     PROP_NAME,
164                                     g_param_spec_string("name",
165                                                         "name",
166                                                         "Name of the layout",
167                                                         NULL,
168                                                         G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
169     g_object_class_install_property(object_class,
170                                     PROP_SHORT_DESCRIPTION,
171                                     g_param_spec_string("short-description",
172                                                         "short-description",
173                                                         "Short description of the layout",
174                                                         NULL,
175                                                         G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
176     g_object_class_install_property(object_class,
177                                     PROP_DESCRIPTION,
178                                     g_param_spec_string("description",
179                                                         "description",
180                                                         "Long description of the layout",
181                                                         NULL,
182                                                         G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
183 }