summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--greeters/ldm-gtk-greeter.c8
-rw-r--r--greeters/ldm-webkit-greeter.c15
-rw-r--r--libldmgreeter/Makefile.am2
-rw-r--r--libldmgreeter/greeter.c15
-rw-r--r--libldmgreeter/greeter.h8
-rw-r--r--libldmgreeter/session.c147
-rw-r--r--libldmgreeter/session.h51
7 files changed, 222 insertions, 24 deletions
diff --git a/greeters/ldm-gtk-greeter.c b/greeters/ldm-gtk-greeter.c
index 8cd993cb..e8a18f3e 100644
--- a/greeters/ldm-gtk-greeter.c
+++ b/greeters/ldm-gtk-greeter.c
@@ -237,16 +237,16 @@ main(int argc, char **argv)
sessions = ldm_greeter_get_sessions (greeter);
for (link = sessions; link; link = link->next)
{
- Session *session = link->data;
+ LdmSession *session = link->data;
- item = gtk_radio_menu_item_new_with_label (session_radio_list, session->name);
+ item = gtk_radio_menu_item_new_with_label (session_radio_list, ldm_session_get_name (session));
session_radio_list = gtk_radio_menu_item_get_group (GTK_RADIO_MENU_ITEM (item));
gtk_menu_shell_append (GTK_MENU_SHELL (menu), item);
- if (g_str_equal (session->key, ldm_greeter_get_session (greeter)))
+ if (g_str_equal (ldm_session_get_key (session), ldm_greeter_get_session (greeter)))
gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM (item), TRUE);
- g_object_set_data (G_OBJECT (item), "key", g_strdup (session->key));
+ g_object_set_data (G_OBJECT (item), "key", g_strdup (ldm_session_get_key (session)));
g_signal_connect (item, "toggled", G_CALLBACK (session_changed_cb), NULL);
}
diff --git a/greeters/ldm-webkit-greeter.c b/greeters/ldm-webkit-greeter.c
index 6c30bccd..0f7398eb 100644
--- a/greeters/ldm-webkit-greeter.c
+++ b/greeters/ldm-webkit-greeter.c
@@ -106,10 +106,10 @@ get_session_key_cb (JSContextRef context,
JSStringRef propertyName,
JSValueRef *exception)
{
- Session *session = JSObjectGetPrivate (thisObject);
+ LdmSession *session = JSObjectGetPrivate (thisObject);
JSStringRef string;
- string = JSStringCreateWithUTF8CString (session->key);
+ string = JSStringCreateWithUTF8CString (ldm_session_get_key (session));
return JSValueMakeString (context, string);
}
@@ -119,10 +119,10 @@ get_session_name_cb (JSContextRef context,
JSStringRef propertyName,
JSValueRef *exception)
{
- Session *session = JSObjectGetPrivate (thisObject);
+ LdmSession *session = JSObjectGetPrivate (thisObject);
JSStringRef string;
- string = JSStringCreateWithUTF8CString (session->name);
+ string = JSStringCreateWithUTF8CString (ldm_session_get_name (session));
return JSValueMakeString (context, string);
}
@@ -132,10 +132,10 @@ get_session_comment_cb (JSContextRef context,
JSStringRef propertyName,
JSValueRef *exception)
{
- Session *session = JSObjectGetPrivate (thisObject);
+ LdmSession *session = JSObjectGetPrivate (thisObject);
JSStringRef string;
- string = JSStringCreateWithUTF8CString (session->comment);
+ string = JSStringCreateWithUTF8CString (ldm_session_get_comment (session));
return JSValueMakeString (context, string);
}
@@ -196,7 +196,8 @@ get_sessions_cb (JSContextRef context,
args = g_malloc (sizeof (JSValueRef) * (n_sessions + 1));
for (i = 0, link = sessions; link; i++, link = link->next)
{
- Session *session = link->data;
+ LdmSession *session = link->data;
+ g_object_ref (session);
args[i] = JSObjectMake (context, ldm_session_class, session);
}
diff --git a/libldmgreeter/Makefile.am b/libldmgreeter/Makefile.am
index 536c5e42..07a04551 100644
--- a/libldmgreeter/Makefile.am
+++ b/libldmgreeter/Makefile.am
@@ -2,6 +2,7 @@ lib_LTLIBRARIES = libldmgreeter.la
libldmgreeterinclude_HEADERS = \
greeter.h \
+ session.h \
user.h
libldmgreeter_la_LIBADD = $(LIBLDMGREETER_LIBS)
@@ -9,6 +10,7 @@ libldmgreeter_la_CFLAGS = $(LIBLDMGREETER_CFLAGS)
libldmgreeter_la_SOURCES= \
greeter.c \
+ session.c \
user.c
libldmgreeterincludedir=$(includedir)/lightdm-1.0
diff --git a/libldmgreeter/greeter.c b/libldmgreeter/greeter.c
index 33e65433..54c2f773 100644
--- a/libldmgreeter/greeter.c
+++ b/libldmgreeter/greeter.c
@@ -229,16 +229,19 @@ update_sessions (LdmGreeter *greeter)
for (i = 0; i < sessions->len; i++)
{
GValue value = { 0 };
- Session *session;
-
- session = g_malloc0 (sizeof (Session));
-
+ LdmSession *session;
+ gchar *key, *name, *comment;
+
g_value_init (&value, TYPE_SESSION);
g_value_set_static_boxed (&value, sessions->pdata[i]);
- dbus_g_type_struct_get (&value, 0, &session->key, 1, &session->name, 2, &session->comment, G_MAXUINT);
-
+ dbus_g_type_struct_get (&value, 0, &key, 1, &name, 2, &comment, G_MAXUINT);
g_value_unset (&value);
+ session = ldm_session_new (key, name, comment);
+ g_free (key);
+ g_free (name);
+ g_free (comment);
+
greeter->priv->sessions = g_list_append (greeter->priv->sessions, session);
}
diff --git a/libldmgreeter/greeter.h b/libldmgreeter/greeter.h
index e1172f83..73627c31 100644
--- a/libldmgreeter/greeter.h
+++ b/libldmgreeter/greeter.h
@@ -15,6 +15,7 @@
#include <glib-object.h>
#include "user.h"
+#include "session.h"
G_BEGIN_DECLS
@@ -48,13 +49,6 @@ typedef struct
void (*timed_login)(LdmGreeter *greeter, const gchar *username);
} LdmGreeterClass;
-typedef struct
-{
- gchar *key;
- gchar *name;
- gchar *comment;
-} Session;
-
GType ldm_greeter_get_type (void);
LdmGreeter *ldm_greeter_new (void);
diff --git a/libldmgreeter/session.c b/libldmgreeter/session.c
new file mode 100644
index 00000000..4c87374c
--- /dev/null
+++ b/libldmgreeter/session.c
@@ -0,0 +1,147 @@
+/*
+ * Copyright (C) 2010 Robert Ancell.
+ * Author: Robert Ancell <robert.ancell@canonical.com>
+ *
+ * This program is free software: you can redistribute it and/or modify it under
+ * the terms of the GNU General Public License as published by the Free Software
+ * Foundation, either version 3 of the License, or (at your option) any later
+ * version. See http://www.gnu.org/copyleft/gpl.html the full text of the
+ * license.
+ */
+
+#include "session.h"
+
+enum {
+ PROP_0,
+ PROP_KEY,
+ PROP_NAME,
+ PROP_COMMENT
+};
+
+struct LdmSessionPrivate
+{
+ gchar *key;
+ gchar *name;
+ gchar *comment;
+};
+
+G_DEFINE_TYPE (LdmSession, ldm_session, G_TYPE_OBJECT);
+
+LdmSession *
+ldm_session_new (const gchar *key, const gchar *name, const gchar *comment)
+{
+ return g_object_new (LDM_TYPE_SESSION, "key", key, "name", name, "comment", comment, NULL);
+}
+
+const gchar *
+ldm_session_get_key (LdmSession *user)
+{
+ return user->priv->key;
+}
+
+const gchar *
+ldm_session_get_name (LdmSession *user)
+{
+ return user->priv->name;
+}
+
+const gchar *
+ldm_session_get_comment (LdmSession *user)
+{
+ return user->priv->comment;
+}
+
+static void
+ldm_session_init (LdmSession *user)
+{
+ user->priv = G_TYPE_INSTANCE_GET_PRIVATE (user, LDM_TYPE_SESSION, LdmSessionPrivate);
+}
+
+static void
+ldm_session_set_property(GObject *object,
+ guint prop_id,
+ const GValue *value,
+ GParamSpec *pspec)
+{
+ LdmSession *self;
+ gint i, n_pages;
+
+ self = LDM_SESSION (object);
+
+ switch (prop_id) {
+ case PROP_KEY:
+ g_free (self->priv->key);
+ self->priv->key = g_strdup (g_value_get_string (value));
+ break;
+ case PROP_NAME:
+ g_free (self->priv->name);
+ self->priv->name = g_strdup (g_value_get_string (value));
+ break;
+ case PROP_COMMENT:
+ g_free (self->priv->comment);
+ self->priv->comment = g_strdup (g_value_get_string (value));
+ break;
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+ break;
+ }
+}
+
+static void
+ldm_session_get_property(GObject *object,
+ guint prop_id,
+ GValue *value,
+ GParamSpec *pspec)
+{
+ LdmSession *self;
+
+ self = LDM_SESSION (object);
+
+ switch (prop_id) {
+ case PROP_KEY:
+ g_value_set_string (value, ldm_session_get_key (self));
+ break;
+ case PROP_NAME:
+ g_value_set_string (value, ldm_session_get_name (self));
+ break;
+ case PROP_COMMENT:
+ g_value_set_string (value, ldm_session_get_comment (self));
+ break;
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+ break;
+ }
+}
+
+static void
+ldm_session_class_init (LdmSessionClass *klass)
+{
+ GObjectClass *object_class = G_OBJECT_CLASS (klass);
+
+ g_type_class_add_private (klass, sizeof (LdmSessionPrivate));
+
+ object_class->set_property = ldm_session_set_property;
+ object_class->get_property = ldm_session_get_property;
+
+ g_object_class_install_property(object_class,
+ PROP_KEY,
+ g_param_spec_string("key",
+ "key",
+ "Session key",
+ NULL,
+ G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
+ g_object_class_install_property(object_class,
+ PROP_NAME,
+ g_param_spec_string("name",
+ "name",
+ "Session name",
+ NULL,
+ G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
+ g_object_class_install_property(object_class,
+ PROP_COMMENT,
+ g_param_spec_string("comment",
+ "comment",
+ "Session comment",
+ NULL,
+ G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
+}
diff --git a/libldmgreeter/session.h b/libldmgreeter/session.h
new file mode 100644
index 00000000..d97a0c1f
--- /dev/null
+++ b/libldmgreeter/session.h
@@ -0,0 +1,51 @@
+/*
+ * Copyright (C) 2010 Robert Ancell.
+ * Author: Robert Ancell <robert.ancell@canonical.com>
+ *
+ * This program is free software: you can redistribute it and/or modify it under
+ * the terms of the GNU General Public License as published by the Free Software
+ * Foundation, either version 3 of the License, or (at your option) any later
+ * version. See http://www.gnu.org/copyleft/gpl.html the full text of the
+ * license.
+ */
+
+#ifndef _LDM_SESSION_H_
+#define _LDM_SESSION_H_
+
+#include <glib-object.h>
+
+G_BEGIN_DECLS
+
+#define LDM_TYPE_SESSION (ldm_session_get_type())
+#define LDM_SESSION(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), LDM_TYPE_SESSION, LdmSession));
+#define LDM_SESSION_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), LDM_TYPE_SESSION, LdmSessionClass))
+#define LDM_IS_SESSION(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), LDM_TYPE_SESSION))
+#define LDM_IS_SESSION_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), LDM_TYPE_SESSION))
+#define LDM_SESSION_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), LDM_TYPE_SESSION, LdmSessionClass))
+
+typedef struct LdmSessionPrivate LdmSessionPrivate;
+
+typedef struct
+{
+ GObject parent_instance;
+ LdmSessionPrivate *priv;
+} LdmSession;
+
+typedef struct
+{
+ GObjectClass parent_class;
+} LdmSessionClass;
+
+GType ldm_session_get_type (void);
+
+LdmSession *ldm_session_new (const gchar *key, const gchar *name, const gchar *comment);
+
+const gchar *ldm_session_get_key (LdmSession *user);
+
+const gchar *ldm_session_get_name (LdmSession *user);
+
+const gchar *ldm_session_get_comment (LdmSession *user);
+
+G_END_DECLS
+
+#endif /* _LDM_SESSION_H_ */