]> rtime.felk.cvut.cz Git - sojka/lightdm.git/blob - libldmgreeter-gobject/session.c
37e1609353000939cc8aec5cfdc36024eab73072
[sojka/lightdm.git] / libldmgreeter-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     return session->priv->key;
58 }
59
60 /**
61  * ldm_session_get_name
62  * @session: A #LdmSession
63  * 
64  * Get the name for a session
65  * 
66  * Return value: The session name
67  **/
68 const gchar *
69 ldm_session_get_name (LdmSession *session)
70 {
71     return session->priv->name;
72 }
73
74 /**
75  * ldm_session_get_comment
76  * @session: A #LdmSession
77  * 
78  * Get the comment for a session
79  * 
80  * Return value: The session comment
81  **/
82 const gchar *
83 ldm_session_get_comment (LdmSession *session)
84 {
85     return session->priv->comment;
86 }
87
88 static void
89 ldm_session_init (LdmSession *session)
90 {
91     session->priv = G_TYPE_INSTANCE_GET_PRIVATE (session, LDM_TYPE_SESSION, LdmSessionPrivate);
92 }
93
94 static void
95 ldm_session_set_property (GObject      *object,
96                           guint         prop_id,
97                           const GValue *value,
98                           GParamSpec   *pspec)
99 {
100     LdmSession *self;
101     gint i, n_pages;
102
103     self = LDM_SESSION (object);
104
105     switch (prop_id) {
106     case PROP_KEY:
107         g_free (self->priv->key);
108         self->priv->key = g_strdup (g_value_get_string (value));
109         break;
110     case PROP_NAME:
111         g_free (self->priv->name);
112         self->priv->name = g_strdup (g_value_get_string (value));
113         break;
114     case PROP_COMMENT:
115         g_free (self->priv->comment);
116         self->priv->comment = g_strdup (g_value_get_string (value));
117         break;
118     default:
119         G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
120         break;
121     }
122 }
123
124 static void
125 ldm_session_get_property (GObject    *object,
126                           guint       prop_id,
127                           GValue     *value,
128                           GParamSpec *pspec)
129 {
130     LdmSession *self;
131
132     self = LDM_SESSION (object);
133
134     switch (prop_id) {
135     case PROP_KEY:
136         g_value_set_string (value, ldm_session_get_key (self));
137         break;
138     case PROP_NAME:
139         g_value_set_string (value, ldm_session_get_name (self));
140         break;
141     case PROP_COMMENT:
142         g_value_set_string (value, ldm_session_get_comment (self));
143         break;
144     default:
145         G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
146         break;
147     }
148 }
149
150 static void
151 ldm_session_class_init (LdmSessionClass *klass)
152 {
153     GObjectClass *object_class = G_OBJECT_CLASS (klass);
154   
155     g_type_class_add_private (klass, sizeof (LdmSessionPrivate));
156
157     object_class->set_property = ldm_session_set_property;
158     object_class->get_property = ldm_session_get_property;
159
160     g_object_class_install_property(object_class,
161                                     PROP_KEY,
162                                     g_param_spec_string("key",
163                                                         "key",
164                                                         "Session key",
165                                                         NULL,
166                                                         G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
167     g_object_class_install_property(object_class,
168                                     PROP_NAME,
169                                     g_param_spec_string("name",
170                                                         "name",
171                                                         "Session name",
172                                                         NULL,
173                                                         G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
174     g_object_class_install_property(object_class,
175                                     PROP_COMMENT,
176                                     g_param_spec_string("comment",
177                                                         "comment",
178                                                         "Session comment",
179                                                         NULL,
180                                                         G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
181 }