]> rtime.felk.cvut.cz Git - sojka/lightdm.git/blob - liblightdm-gobject/session.c
Merge in Qt changes
[sojka/lightdm.git] / liblightdm-gobject / session.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 "session.h"
13
14 enum {
15     PROP_0,
16     PROP_KEY,
17     PROP_NAME,
18     PROP_COMMENT
19 };
20
21 struct _LdmSessionPrivate
22 {
23     gchar *key;
24     gchar *name;
25     gchar *comment;
26 };
27
28 G_DEFINE_TYPE (LdmSession, ldm_session, G_TYPE_OBJECT);
29
30 /**
31  * ldm_session_new:
32  * 
33  * Create a new session.
34  * @key: The unique key for this session
35  * @name: The name of this session
36  * @comment: The comment for this session
37  * 
38  * Return value: the new #LdmSession
39  **/
40 LdmSession *
41 ldm_session_new (const gchar *key, const gchar *name, const gchar *comment)
42 {
43     return g_object_new (LDM_TYPE_SESSION, "key", key, "name", name, "comment", comment, NULL);
44 }
45
46 /**
47  * ldm_session_get_key
48  * @session: A #LdmSession
49  * 
50  * Get the key for a session
51  * 
52  * Return value: The session key
53  **/
54 const gchar *
55 ldm_session_get_key (LdmSession *session)
56 {
57     g_return_val_if_fail (LDM_IS_SESSION (session), NULL);
58     return session->priv->key;
59 }
60
61 /**
62  * ldm_session_get_name
63  * @session: A #LdmSession
64  * 
65  * Get the name for a session
66  * 
67  * Return value: The session name
68  **/
69 const gchar *
70 ldm_session_get_name (LdmSession *session)
71 {
72     g_return_val_if_fail (LDM_IS_SESSION (session), NULL);
73     return session->priv->name;
74 }
75
76 /**
77  * ldm_session_get_comment
78  * @session: A #LdmSession
79  * 
80  * Get the comment for a session
81  * 
82  * Return value: The session comment
83  **/
84 const gchar *
85 ldm_session_get_comment (LdmSession *session)
86 {
87     g_return_val_if_fail (LDM_IS_SESSION (session), NULL);
88     return session->priv->comment;
89 }
90
91 static void
92 ldm_session_init (LdmSession *session)
93 {
94     session->priv = G_TYPE_INSTANCE_GET_PRIVATE (session, LDM_TYPE_SESSION, LdmSessionPrivate);
95 }
96
97 static void
98 ldm_session_set_property (GObject      *object,
99                           guint         prop_id,
100                           const GValue *value,
101                           GParamSpec   *pspec)
102 {
103     LdmSession *self;
104
105     self = LDM_SESSION (object);
106
107     switch (prop_id) {
108     case PROP_KEY:
109         g_free (self->priv->key);
110         self->priv->key = g_strdup (g_value_get_string (value));
111         break;
112     case PROP_NAME:
113         g_free (self->priv->name);
114         self->priv->name = g_strdup (g_value_get_string (value));
115         break;
116     case PROP_COMMENT:
117         g_free (self->priv->comment);
118         self->priv->comment = 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_session_get_property (GObject    *object,
128                           guint       prop_id,
129                           GValue     *value,
130                           GParamSpec *pspec)
131 {
132     LdmSession *self;
133
134     self = LDM_SESSION (object);
135
136     switch (prop_id) {
137     case PROP_KEY:
138         g_value_set_string (value, ldm_session_get_key (self));
139         break;
140     case PROP_NAME:
141         g_value_set_string (value, ldm_session_get_name (self));
142         break;
143     case PROP_COMMENT:
144         g_value_set_string (value, ldm_session_get_comment (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_session_class_init (LdmSessionClass *klass)
154 {
155     GObjectClass *object_class = G_OBJECT_CLASS (klass);
156   
157     g_type_class_add_private (klass, sizeof (LdmSessionPrivate));
158
159     object_class->set_property = ldm_session_set_property;
160     object_class->get_property = ldm_session_get_property;
161
162     g_object_class_install_property(object_class,
163                                     PROP_KEY,
164                                     g_param_spec_string("key",
165                                                         "key",
166                                                         "Session key",
167                                                         NULL,
168                                                         G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
169     g_object_class_install_property(object_class,
170                                     PROP_NAME,
171                                     g_param_spec_string("name",
172                                                         "name",
173                                                         "Session name",
174                                                         NULL,
175                                                         G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
176     g_object_class_install_property(object_class,
177                                     PROP_COMMENT,
178                                     g_param_spec_string("comment",
179                                                         "comment",
180                                                         "Session comment",
181                                                         NULL,
182                                                         G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
183 }