Commit 4aa2a587 authored by William Jon McCann's avatar William Jon McCann Committed by William Jon McCann

Add SelectHostname, Disconnected, and GetDisplayId methods to the greeter

2007-09-05  William Jon McCann  <mccann@jhu.edu>

	* daemon/gdm-factory-slave.c: (run_greeter):
	* daemon/gdm-greeter-server.c: (handle_disconnect),
	(handle_get_display_id), (greeter_handle_child_message),
	(do_introspect), (_gdm_greeter_server_set_display_id),
	(gdm_greeter_server_set_property),
	(gdm_greeter_server_get_property), (gdm_greeter_server_class_init),
	(gdm_greeter_server_new):
	* daemon/gdm-greeter-server.h:
	* daemon/gdm-simple-slave.c: (run_greeter),
	(gdm_simple_slave_stop):
	* daemon/gdm-slave.c: (gdm_slave_finalize):
	* gui/simple-greeter/gdm-simple-greeter.c:
	(suspend_button_clicked), (gdm_simple_greeter_new):
	* gui/simple-greeter/gdm-simple-greeter.h:
	* gui/simple-greeter/greeter-main.c: (on_select_hostname),
	(on_disconnected), (get_display_id), (main):
	* libgreeter/gdm-greeter.c: (gdm_greeter_display_is_local),
	(gdm_greeter_emit_disconnected), (_gdm_greeter_set_display_id),
	(gdm_greeter_set_property), (gdm_greeter_get_property),
	(cache_display_values), (gdm_greeter_constructor),
	(gdm_greeter_class_init), (gdm_greeter_finalize):
	* libgreeter/gdm-greeter.h:
	Add SelectHostname, Disconnected, and GetDisplayId methods
	to the greeter server interface.


svn path=/branches/mccann-gobject/; revision=5228
parent 8cb6adfa
2007-09-05 William Jon McCann <mccann@jhu.edu>
* daemon/gdm-factory-slave.c: (run_greeter):
* daemon/gdm-greeter-server.c: (handle_disconnect),
(handle_get_display_id), (greeter_handle_child_message),
(do_introspect), (_gdm_greeter_server_set_display_id),
(gdm_greeter_server_set_property),
(gdm_greeter_server_get_property), (gdm_greeter_server_class_init),
(gdm_greeter_server_new):
* daemon/gdm-greeter-server.h:
* daemon/gdm-simple-slave.c: (run_greeter),
(gdm_simple_slave_stop):
* daemon/gdm-slave.c: (gdm_slave_finalize):
* gui/simple-greeter/gdm-simple-greeter.c:
(suspend_button_clicked), (gdm_simple_greeter_new):
* gui/simple-greeter/gdm-simple-greeter.h:
* gui/simple-greeter/greeter-main.c: (on_select_hostname),
(on_disconnected), (get_display_id), (main):
* libgreeter/gdm-greeter.c: (gdm_greeter_display_is_local),
(gdm_greeter_emit_disconnected), (_gdm_greeter_set_display_id),
(gdm_greeter_set_property), (gdm_greeter_get_property),
(cache_display_values), (gdm_greeter_constructor),
(gdm_greeter_class_init), (gdm_greeter_finalize):
* libgreeter/gdm-greeter.h:
Add SelectHostname, Disconnected, and GetDisplayId methods
to the greeter server interface.
2007-09-05 William Jon McCann <mccann@jhu.edu>
* daemon/gdm-greeter-server.c: (handle_select_hostname),
......
......@@ -547,6 +547,7 @@ static void
run_greeter (GdmFactorySlave *slave)
{
gboolean display_is_local;
char *display_id;
char *display_name;
char *display_device;
char *display_hostname;
......@@ -556,6 +557,7 @@ run_greeter (GdmFactorySlave *slave)
g_debug ("Running greeter");
display_is_local = FALSE;
display_id = NULL;
display_name = NULL;
auth_file = NULL;
display_device = NULL;
......@@ -563,6 +565,7 @@ run_greeter (GdmFactorySlave *slave)
g_object_get (slave,
"display-is-local", &display_is_local,
"display-id", &display_id,
"display-name", &display_name,
"display-hostname", &display_hostname,
"display-x11-authority-file", &auth_file,
......@@ -594,7 +597,7 @@ run_greeter (GdmFactorySlave *slave)
GDMCONFDIR"/Init",
"gdm");
slave->priv->greeter_server = gdm_greeter_server_new ();
slave->priv->greeter_server = gdm_greeter_server_new (display_id);
g_signal_connect (slave->priv->greeter_server,
"query-answer",
G_CALLBACK (on_greeter_answer),
......@@ -644,6 +647,7 @@ run_greeter (GdmFactorySlave *slave)
g_free (address);
g_free (display_id);
g_free (display_name);
g_free (display_device);
g_free (display_hostname);
......
......@@ -54,6 +54,7 @@ struct GdmGreeterServerPrivate
{
char *user_name;
char *group_name;
char *display_id;
gboolean interrupted;
gboolean always_restart_greeter;
......@@ -67,6 +68,7 @@ enum {
PROP_0,
PROP_USER_NAME,
PROP_GROUP_NAME,
PROP_DISPLAY_ID,
};
enum {
......@@ -376,6 +378,39 @@ handle_cancel (GdmGreeterServer *greeter_server,
return DBUS_HANDLER_RESULT_HANDLED;
}
static DBusHandlerResult
handle_disconnect (GdmGreeterServer *greeter_server,
DBusConnection *connection,
DBusMessage *message)
{
DBusMessage *reply;
reply = dbus_message_new_method_return (message);
dbus_connection_send (connection, reply, NULL);
dbus_message_unref (reply);
g_signal_emit (greeter_server, signals [DISCONNECTED], 0);
return DBUS_HANDLER_RESULT_HANDLED;
}
static DBusHandlerResult
handle_get_display_id (GdmGreeterServer *greeter_server,
DBusConnection *connection,
DBusMessage *message)
{
DBusMessage *reply;
DBusMessageIter iter;
reply = dbus_message_new_method_return (message);
dbus_message_iter_init_append (reply, &iter);
dbus_message_iter_append_basic (&iter, DBUS_TYPE_G_OBJECT_PATH, &greeter_server->priv->display_id);
dbus_connection_send (connection, reply, NULL);
dbus_message_unref (reply);
return DBUS_HANDLER_RESULT_HANDLED;
}
static DBusHandlerResult
greeter_handle_child_message (DBusConnection *connection,
DBusMessage *message,
......@@ -395,6 +430,10 @@ greeter_handle_child_message (DBusConnection *connection,
return handle_select_user (greeter_server, connection, message);
} else if (dbus_message_is_method_call (message, GDM_GREETER_SERVER_DBUS_INTERFACE, "Cancel")) {
return handle_cancel (greeter_server, connection, message);
} else if (dbus_message_is_method_call (message, GDM_GREETER_SERVER_DBUS_INTERFACE, "Disconnect")) {
return handle_disconnect (greeter_server, connection, message);
} else if (dbus_message_is_method_call (message, GDM_GREETER_SERVER_DBUS_INTERFACE, "GetDisplayId")) {
return handle_get_display_id (greeter_server, connection, message);
}
return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
......@@ -440,6 +479,11 @@ do_introspect (DBusConnection *connection,
" </method>\n"
" <method name=\"Cancel\">\n"
" </method>\n"
" <method name=\"Disconnect\">\n"
" </method>\n"
" <method name=\"GetDisplayId\">\n"
" <arg name=\"id\" direction=\"out\" type=\"o\"/>\n"
" </method>\n"
" <signal name=\"Info\">\n"
" <arg name=\"text\" type=\"s\"/>\n"
" </signal>\n"
......@@ -687,6 +731,14 @@ gdm_greeter_server_get_address (GdmGreeterServer *greeter_server)
return g_strdup (greeter_server->priv->server_address);
}
static void
_gdm_greeter_server_set_display_id (GdmGreeterServer *greeter_server,
const char *display_id)
{
g_free (greeter_server->priv->display_id);
greeter_server->priv->display_id = g_strdup (display_id);
}
static void
_gdm_greeter_server_set_user_name (GdmGreeterServer *greeter_server,
const char *name)
......@@ -714,6 +766,9 @@ gdm_greeter_server_set_property (GObject *object,
self = GDM_GREETER_SERVER (object);
switch (prop_id) {
case PROP_DISPLAY_ID:
_gdm_greeter_server_set_display_id (self, g_value_get_string (value));
break;
case PROP_USER_NAME:
_gdm_greeter_server_set_user_name (self, g_value_get_string (value));
break;
......@@ -737,6 +792,9 @@ gdm_greeter_server_get_property (GObject *object,
self = GDM_GREETER_SERVER (object);
switch (prop_id) {
case PROP_DISPLAY_ID:
g_value_set_string (value, self->priv->display_id);
break;
case PROP_USER_NAME:
g_value_set_string (value, self->priv->user_name);
break;
......@@ -779,6 +837,13 @@ gdm_greeter_server_class_init (GdmGreeterServerClass *klass)
g_type_class_add_private (klass, sizeof (GdmGreeterServerPrivate));
g_object_class_install_property (object_class,
PROP_DISPLAY_ID,
g_param_spec_string ("display-id",
"display id",
"display id",
NULL,
G_PARAM_READWRITE | G_PARAM_CONSTRUCT));
g_object_class_install_property (object_class,
PROP_USER_NAME,
g_param_spec_string ("user-name",
"user name",
......@@ -904,11 +969,12 @@ gdm_greeter_server_finalize (GObject *object)
}
GdmGreeterServer *
gdm_greeter_server_new (void)
gdm_greeter_server_new (const char *display_id)
{
GObject *object;
object = g_object_new (GDM_TYPE_GREETER_SERVER,
"display-id", display_id,
NULL);
return GDM_GREETER_SERVER (object);
......
......@@ -61,7 +61,7 @@ typedef struct
} GdmGreeterServerClass;
GType gdm_greeter_server_get_type (void);
GdmGreeterServer * gdm_greeter_server_new (void);
GdmGreeterServer * gdm_greeter_server_new (const char *display_id);
gboolean gdm_greeter_server_start (GdmGreeterServer *greeter_server);
gboolean gdm_greeter_server_stop (GdmGreeterServer *greeter_server);
......
......@@ -87,13 +87,11 @@ struct GdmSimpleSlavePrivate
GdmGreeterServer *greeter_server;
GdmGreeterProxy *greeter;
GdmSession *session;
DBusGProxy *display_proxy;
DBusGConnection *connection;
};
enum {
PROP_0,
PROP_DISPLAY_ID,
};
enum {
......@@ -955,6 +953,7 @@ static void
run_greeter (GdmSimpleSlave *slave)
{
gboolean display_is_local;
char *display_id;
char *display_name;
char *display_device;
char *display_hostname;
......@@ -964,12 +963,14 @@ run_greeter (GdmSimpleSlave *slave)
g_debug ("Running greeter");
display_is_local = FALSE;
display_id = NULL;
display_name = NULL;
auth_file = NULL;
display_device = NULL;
display_hostname = NULL;
g_object_get (slave,
"display-id", &display_id,
"display-is-local", &display_is_local,
"display-name", &display_name,
"display-hostname", &display_hostname,
......@@ -1011,7 +1012,7 @@ run_greeter (GdmSimpleSlave *slave)
create_new_session (slave);
slave->priv->greeter_server = gdm_greeter_server_new ();
slave->priv->greeter_server = gdm_greeter_server_new (display_id);
g_signal_connect (slave->priv->greeter_server,
"query-answer",
G_CALLBACK (on_greeter_answer),
......@@ -1059,6 +1060,7 @@ run_greeter (GdmSimpleSlave *slave)
gdm_greeter_proxy_set_server_address (slave->priv->greeter, address);
gdm_greeter_proxy_start (slave->priv->greeter);
g_free (display_id);
g_free (display_name);
g_free (display_device);
g_free (display_hostname);
......@@ -1262,10 +1264,6 @@ gdm_simple_slave_stop (GdmSlave *slave)
GDM_SIMPLE_SLAVE (slave)->priv->server = NULL;
}
if (GDM_SIMPLE_SLAVE (slave)->priv->display_proxy != NULL) {
g_object_unref (GDM_SIMPLE_SLAVE (slave)->priv->display_proxy);
}
return TRUE;
}
......
......@@ -675,5 +675,7 @@ gdm_slave_finalize (GObject *object)
gdm_slave_real_stop (slave);
g_free (slave->priv->display_id);
G_OBJECT_CLASS (gdm_slave_parent_class)->finalize (object);
}
......@@ -351,7 +351,6 @@ static void
suspend_button_clicked (GtkButton *button,
GdmSimpleGreeter *greeter)
{
gboolean res;
GError *error;
DBusGConnection *connection;
DBusGProxy *proxy;
......@@ -512,11 +511,12 @@ gdm_simple_greeter_finalize (GObject *object)
}
GdmGreeter *
gdm_simple_greeter_new (void)
gdm_simple_greeter_new (const char *display_id)
{
GObject *object;
object = g_object_new (GDM_TYPE_SIMPLE_GREETER,
"display-id", display_id,
NULL);
return GDM_GREETER (object);
......
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: h; c-basic-offset: 8 -*-
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*-
*
* Copyright (C) 2007 William Jon McCann <mccann@jhu.edu>
*
......@@ -50,7 +50,7 @@ typedef struct
} GdmSimpleGreeterClass;
GType gdm_simple_greeter_get_type (void);
GdmGreeter * gdm_simple_greeter_new (void);
GdmGreeter * gdm_simple_greeter_new (const char *display_id);
G_END_DECLS
......
......@@ -194,6 +194,29 @@ on_select_user (GdmGreeter *greeter,
}
}
static void
on_select_hostname (GdmGreeter *greeter,
const char *text,
gpointer data)
{
gboolean res;
GError *error;
g_debug ("GREETER hostname selected: %s", text);
error = NULL;
res = dbus_g_proxy_call (server_proxy,
"SelectHostname",
&error,
G_TYPE_STRING, text,
G_TYPE_INVALID,
G_TYPE_INVALID);
if (! res) {
g_warning ("Unable to send SelectHostname: %s", error->message);
g_error_free (error);
}
}
static void
on_cancelled (GdmGreeter *greeter,
gpointer data)
......@@ -215,6 +238,52 @@ on_cancelled (GdmGreeter *greeter,
}
}
static void
on_disconnected (GdmGreeter *greeter,
gpointer data)
{
gboolean res;
GError *error;
g_debug ("GREETER disconnected");
error = NULL;
res = dbus_g_proxy_call (server_proxy,
"Disconnect",
&error,
G_TYPE_INVALID,
G_TYPE_INVALID);
if (! res) {
g_warning ("Unable to send Disconnected: %s", error->message);
g_error_free (error);
}
}
static char *
get_display_id (void)
{
gboolean res;
GError *error;
char *id;
g_debug ("GREETER disconnected");
id = NULL;
error = NULL;
res = dbus_g_proxy_call (server_proxy,
"GetDisplayId",
&error,
G_TYPE_INVALID,
G_TYPE_STRING, &id,
G_TYPE_INVALID);
if (! res) {
g_warning ("Unable to GetDisplayId: %s", error->message);
g_error_free (error);
}
return id;
}
static void
proxy_destroyed (GObject *object,
gpointer data)
......@@ -283,6 +352,7 @@ main (int argc, char *argv[])
{
GError *error;
const char *address;
char *display_id;
bindtextdomain (GETTEXT_PACKAGE, GNOMELOCALEDIR);
bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
......@@ -376,7 +446,10 @@ main (int argc, char *argv[])
NULL,
NULL);
greeter = gdm_simple_greeter_new ();
display_id = get_display_id ();
greeter = gdm_simple_greeter_new (display_id);
g_free (display_id);
g_signal_connect (greeter,
"query-answer",
G_CALLBACK (on_query_answer),
......@@ -393,10 +466,18 @@ main (int argc, char *argv[])
"user-selected",
G_CALLBACK (on_select_user),
NULL);
g_signal_connect (greeter,
"hostname-selected",
G_CALLBACK (on_select_hostname),
NULL);
g_signal_connect (greeter,
"cancelled",
G_CALLBACK (on_cancelled),
NULL);
g_signal_connect (greeter,
"disconnected",
G_CALLBACK (on_disconnected),
NULL);
activate_power_manager ();
......
......@@ -33,17 +33,26 @@
#include <glib/gi18n.h>
#include <glib-object.h>
#define DBUS_API_SUBJECT_TO_CHANGE
#include <dbus/dbus-glib.h>
#include <dbus/dbus-glib-lowlevel.h>
#include "gdm-greeter.h"
#define GDM_GREETER_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), GDM_TYPE_GREETER, GdmGreeterPrivate))
#define GDM_DBUS_NAME "org.gnome.DisplayManager"
#define GDM_DBUS_DISPLAY_INTERFACE "org.gnome.DisplayManager.Display"
struct GdmGreeterPrivate
{
gpointer dummy;
char *display_id;
gboolean display_is_local;
};
enum {
PROP_0,
PROP_DISPLAY_ID,
};
enum {
......@@ -51,6 +60,8 @@ enum {
SESSION_SELECTED,
LANGUAGE_SELECTED,
USER_SELECTED,
HOSTNAME_SELECTED,
DISCONNECTED,
CANCELLED,
LAST_SIGNAL
};
......@@ -75,6 +86,14 @@ gdm_greeter_error_quark (void)
return ret;
}
gboolean
gdm_greeter_display_is_local (GdmGreeter *greeter)
{
g_return_val_if_fail (GDM_IS_GREETER (greeter), FALSE);
return greeter->priv->display_is_local;
}
static gboolean
gdm_greeter_real_start (GdmGreeter *greeter)
{
......@@ -301,6 +320,26 @@ gdm_greeter_emit_cancelled (GdmGreeter *greeter)
return TRUE;
}
gboolean
gdm_greeter_emit_disconnected (GdmGreeter *greeter)
{
g_return_val_if_fail (GDM_IS_GREETER (greeter), FALSE);
g_debug ("Disconnected");
g_signal_emit (greeter, signals[DISCONNECTED], 0);
return TRUE;
}
static void
_gdm_greeter_set_display_id (GdmGreeter *greeter,
const char *id)
{
g_free (greeter->priv->display_id);
greeter->priv->display_id = g_strdup (id);
}
static void
gdm_greeter_set_property (GObject *object,
guint prop_id,
......@@ -312,6 +351,9 @@ gdm_greeter_set_property (GObject *object,
self = GDM_GREETER (object);
switch (prop_id) {
case PROP_DISPLAY_ID:
_gdm_greeter_set_display_id (self, g_value_get_string (value));
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
......@@ -329,12 +371,56 @@ gdm_greeter_get_property (GObject *object,
self = GDM_GREETER (object);
switch (prop_id) {
case PROP_DISPLAY_ID:
g_value_set_string (value, self->priv->display_id);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
}
}
static void
cache_display_values (GdmGreeter *greeter)
{
DBusGProxy *display_proxy;
DBusGConnection *connection;
GError *error;
gboolean res;
error = NULL;
connection = dbus_g_bus_get (DBUS_BUS_SYSTEM, &error);
if (connection == NULL) {
if (error != NULL) {
g_critical ("error getting system bus: %s", error->message);
g_error_free (error);
}
exit (1);
}
g_debug ("Creating proxy for %s", greeter->priv->display_id);
display_proxy = dbus_g_proxy_new_for_name (connection,
GDM_DBUS_NAME,
greeter->priv->display_id,
GDM_DBUS_DISPLAY_INTERFACE);
/* cache some values up front */
error = NULL;
res = dbus_g_proxy_call (display_proxy,
"IsLocal",
&error,
G_TYPE_INVALID,
G_TYPE_BOOLEAN, &greeter->priv->display_is_local,
G_TYPE_INVALID);
if (! res) {
if (error != NULL) {
g_warning ("Failed to get value: %s", error->message);
g_error_free (error);
} else {
g_warning ("Failed to get value");
}
}
}
static GObject *
gdm_greeter_constructor (GType type,
guint n_construct_properties,
......@@ -349,6 +435,8 @@ gdm_greeter_constructor (GType type,
n_construct_properties,
construct_properties));
cache_display_values (greeter);
return G_OBJECT (greeter);
}
......@@ -425,6 +513,16 @@ gdm_greeter_class_init (GdmGreeterClass *klass)
g_cclosure_marshal_VOID__STRING,
G_TYPE_NONE,
1, G_TYPE_STRING);
signals [HOSTNAME_SELECTED] =
g_signal_new ("hostname-selected",
G_TYPE_FROM_CLASS (object_class),
G_SIGNAL_RUN_LAST,
G_STRUCT_OFFSET (GdmGreeterClass, hostname_selected),
NULL,
NULL,
g_cclosure_marshal_VOID__STRING,
G_TYPE_NONE,
1, G_TYPE_STRING);
signals [CANCELLED] =
g_signal_new ("cancelled",
G_TYPE_FROM_CLASS (object_class),
......@@ -435,6 +533,24 @@ gdm_greeter_class_init (GdmGreeterClass *klass)
g_cclosure_marshal_VOID__VOID,
G_TYPE_NONE,
0);
signals [DISCONNECTED] =
g_signal_new ("disconnected",
G_TYPE_FROM_CLASS (object_class),
G_SIGNAL_RUN_LAST,
G_STRUCT_OFFSET (GdmGreeterClass, disconnected),
NULL,
NULL,
g_cclosure_marshal_VOID__VOID,
G_TYPE_NONE,
0);
g_object_class_install_property (object_class,
PROP_DISPLAY_ID,
g_param_spec_string ("display-id",
"id",
"id",
NULL,
G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
g_type_class_add_private (klass, sizeof (GdmGreeterPrivate));
}
......@@ -459,5 +575,7 @@ gdm_greeter_finalize (GObject *object)
g_return_if_fail (greeter->priv != NULL);
g_free (greeter->priv->display_id);
G_OBJECT_CLASS (gdm_greeter_parent_class)->finalize (object);
}
......@@ -54,7 +54,10 @@ typedef struct
const char *text);
void (* user_selected) (GdmGreeter *greeter,
const char *text);
void (* hostname_selected) (GdmGreeter *greeter,
const char *text);
void (* cancelled) (GdmGreeter *greeter);
void (* disconnected) (GdmGreeter *greeter);
/* methods */
gboolean (*start) (GdmGreeter *greeter);
......@@ -95,7 +98,10 @@ gboolean gdm_greeter_emit_select_language (GdmGreeter *gree
const char *text);
gboolean gdm_greeter_emit_select_user (GdmGreeter *greeter,
const char *text);
gboolean gdm_greeter_emit_select_hostname (GdmGreeter *greeter,
const char *text);
gboolean gdm_greeter_emit_cancelled (GdmGreeter *greeter);
gboolean gdm_greeter_emit_disconnected (GdmGreeter *greeter);
/* actions */
gboolean gdm_greeter_info_query (GdmGreeter *greeter,
......@@ -106,6 +112,8 @@ gboolean gdm_greeter_info (GdmGreeter *gree
const char *text);
gboolean gdm_greeter_problem (GdmGreeter *greeter,
const char *text);
/* misc */
gboolean gdm_greeter_display_is_local (GdmGreeter *greeter);
G_END_DECLS
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment