gdm r5922 - in trunk: . gui/simple-chooser



Author: mccann
Date: Tue Mar  4 19:48:22 2008
New Revision: 5922
URL: http://svn.gnome.org/viewvc/gdm?rev=5922&view=rev

Log:
2008-03-04  William Jon McCann  <jmccann redhat com>

	* gui/simple-chooser/Makefile.am:
	* gui/simple-chooser/gdm-chooser-host.c:
	(gdm_chooser_host_get_address), (gdm_chooser_host_get_description),
	(gdm_chooser_host_get_kind), (gdm_chooser_host_get_willing),
	(_gdm_chooser_host_set_address),
	(_gdm_chooser_host_set_description), (_gdm_chooser_host_set_kind),
	(_gdm_chooser_host_set_willing), (gdm_chooser_host_set_property),
	(gdm_chooser_host_get_property), (gdm_chooser_host_class_init),
	(gdm_chooser_host_init), (gdm_chooser_host_finalize):
	* gui/simple-chooser/gdm-chooser-host.h:
	* gui/simple-chooser/gdm-chooser-session.c: (on_dialog_response),
	(gdm_chooser_session_start):
	* gui/simple-chooser/gdm-host-chooser-dialog.c:
	(gdm_host_chooser_dialog_get_host),
	(_gdm_host_chooser_dialog_set_kind_mask),
	(gdm_host_chooser_dialog_set_property), (on_response),
	(gdm_host_chooser_dialog_constructor),
	(gdm_host_chooser_dialog_class_init),
	(gdm_host_chooser_dialog_init), (gdm_host_chooser_dialog_new):
	* gui/simple-chooser/gdm-host-chooser-dialog.h:
	* gui/simple-chooser/gdm-host-chooser-widget.c: (find_known_host),
	(browser_add_host), (decode_packet), (xdmcp_init),
	(gdm_host_chooser_widget_refresh),
	(gdm_host_chooser_widget_get_host),
	(_gdm_host_chooser_widget_set_kind_mask),
	(gdm_host_chooser_widget_set_property),
	(gdm_host_chooser_widget_constructor),
	(gdm_host_chooser_widget_dispose),
	(gdm_host_chooser_widget_class_init),
	(gdm_host_chooser_widget_init), (gdm_host_chooser_widget_new):
	* gui/simple-chooser/gdm-host-chooser-widget.h:
	* gui/simple-chooser/gdm-host-chooser.c: (main):
	Abstract the host selection to be able to support
	other kinds in addition to XDMCP.



Added:
   trunk/gui/simple-chooser/gdm-chooser-host.c
   trunk/gui/simple-chooser/gdm-chooser-host.h
Modified:
   trunk/ChangeLog
   trunk/gui/simple-chooser/Makefile.am
   trunk/gui/simple-chooser/gdm-chooser-session.c
   trunk/gui/simple-chooser/gdm-host-chooser-dialog.c
   trunk/gui/simple-chooser/gdm-host-chooser-dialog.h
   trunk/gui/simple-chooser/gdm-host-chooser-widget.c
   trunk/gui/simple-chooser/gdm-host-chooser-widget.h
   trunk/gui/simple-chooser/gdm-host-chooser.c

Modified: trunk/gui/simple-chooser/Makefile.am
==============================================================================
--- trunk/gui/simple-chooser/Makefile.am	(original)
+++ trunk/gui/simple-chooser/Makefile.am	Tue Mar  4 19:48:22 2008
@@ -25,6 +25,8 @@
 
 gdm_simple_chooser_SOURCES =  		\
 	chooser-main.c 			\
+	gdm-chooser-host.c		\
+	gdm-chooser-host.h		\
 	gdm-host-chooser-widget.c	\
 	gdm-host-chooser-widget.h	\
 	gdm-host-chooser-dialog.c	\
@@ -45,6 +47,8 @@
 
 gdm_host_chooser_SOURCES = 		\
 	gdm-host-chooser.c 		\
+	gdm-chooser-host.c		\
+	gdm-chooser-host.h		\
 	gdm-host-chooser-widget.c	\
 	gdm-host-chooser-widget.h	\
 	gdm-host-chooser-dialog.c	\

Added: trunk/gui/simple-chooser/gdm-chooser-host.c
==============================================================================
--- (empty file)
+++ trunk/gui/simple-chooser/gdm-chooser-host.c	Tue Mar  4 19:48:22 2008
@@ -0,0 +1,258 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*-
+ *
+ * Copyright (C) 2008 Red Hat, Inc.
+ *
+ * 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 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ *
+ */
+
+#include "config.h"
+
+#include <stdlib.h>
+#include <stdio.h>
+#include <unistd.h>
+#include <string.h>
+#include <errno.h>
+
+#include <glib.h>
+#include <glib/gi18n.h>
+#include <glib-object.h>
+
+#include "gdm-address.h"
+#include "gdm-chooser-host.h"
+
+#define GDM_CHOOSER_HOST_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), GDM_TYPE_CHOOSER_HOST, GdmChooserHostPrivate))
+
+struct GdmChooserHostPrivate
+{
+        GdmAddress        *address;
+        char              *description;
+        GdmChooserHostKind kind;
+        gboolean           willing;
+};
+
+enum {
+        PROP_0,
+        PROP_ADDRESS,
+        PROP_DESCRIPTION,
+        PROP_KIND,
+        PROP_WILLING,
+};
+
+static void     gdm_chooser_host_class_init  (GdmChooserHostClass *klass);
+static void     gdm_chooser_host_init        (GdmChooserHost      *chooser_host);
+static void     gdm_chooser_host_finalize    (GObject             *object);
+
+G_DEFINE_TYPE (GdmChooserHost, gdm_chooser_host, G_TYPE_OBJECT)
+
+GdmAddress *
+gdm_chooser_host_get_address (GdmChooserHost *host)
+{
+        g_return_val_if_fail (GDM_IS_CHOOSER_HOST (host), NULL);
+
+        return host->priv->address;
+}
+
+G_CONST_RETURN char *
+gdm_chooser_host_get_description (GdmChooserHost *host)
+{
+        g_return_val_if_fail (GDM_IS_CHOOSER_HOST (host), NULL);
+
+        return host->priv->description;
+}
+
+GdmChooserHostKind
+gdm_chooser_host_get_kind (GdmChooserHost *host)
+{
+        g_return_val_if_fail (GDM_IS_CHOOSER_HOST (host), 0);
+
+        return host->priv->kind;
+}
+
+gboolean
+gdm_chooser_host_get_willing (GdmChooserHost *host)
+{
+        g_return_val_if_fail (GDM_IS_CHOOSER_HOST (host), FALSE);
+
+        return host->priv->willing;
+}
+
+static void
+_gdm_chooser_host_set_address (GdmChooserHost *host,
+                               GdmAddress     *address)
+{
+        if (host->priv->address != NULL) {
+                gdm_address_free (host->priv->address);
+        }
+
+        g_assert (address != NULL);
+
+        gdm_address_debug (address);
+        host->priv->address = gdm_address_copy (address);
+}
+
+static void
+_gdm_chooser_host_set_description (GdmChooserHost *host,
+                                   const char     *description)
+{
+        g_free (host->priv->description);
+        host->priv->description = g_strdup (description);
+}
+
+static void
+_gdm_chooser_host_set_kind (GdmChooserHost *host,
+                            int             kind)
+{
+        if (host->priv->kind != kind) {
+                host->priv->kind = kind;
+        }
+}
+
+static void
+_gdm_chooser_host_set_willing (GdmChooserHost *host,
+                               gboolean        willing)
+{
+        if (host->priv->willing != willing) {
+                host->priv->willing = willing;
+        }
+}
+
+static void
+gdm_chooser_host_set_property (GObject      *object,
+                               guint         param_id,
+                               const GValue *value,
+                               GParamSpec   *pspec)
+{
+        GdmChooserHost *host;
+
+        host = GDM_CHOOSER_HOST (object);
+
+        switch (param_id) {
+        case PROP_ADDRESS:
+                _gdm_chooser_host_set_address (host, g_value_get_boxed (value));
+                break;
+        case PROP_DESCRIPTION:
+                _gdm_chooser_host_set_description (host, g_value_get_string (value));
+                break;
+        case PROP_KIND:
+                _gdm_chooser_host_set_kind (host, g_value_get_int (value));
+                break;
+        case PROP_WILLING:
+                _gdm_chooser_host_set_willing (host, g_value_get_boolean (value));
+                break;
+        default:
+                G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
+                break;
+        }
+}
+
+static void
+gdm_chooser_host_get_property (GObject    *object,
+                               guint       param_id,
+                               GValue     *value,
+                               GParamSpec *pspec)
+{
+        GdmChooserHost *host;
+
+        host = GDM_CHOOSER_HOST (object);
+
+        switch (param_id) {
+        case PROP_ADDRESS:
+                g_value_set_boxed (value, host->priv->address);
+                break;
+        case PROP_DESCRIPTION:
+                g_value_set_string (value, host->priv->description);
+                break;
+        case PROP_KIND:
+                g_value_set_int (value, host->priv->kind);
+                break;
+        case PROP_WILLING:
+                g_value_set_boolean (value, host->priv->willing);
+                break;
+        default:
+                G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
+                break;
+        }
+}
+
+static void
+gdm_chooser_host_class_init (GdmChooserHostClass *klass)
+{
+        GObjectClass   *object_class = G_OBJECT_CLASS (klass);
+
+        object_class->set_property = gdm_chooser_host_set_property;
+        object_class->get_property = gdm_chooser_host_get_property;
+        object_class->finalize = gdm_chooser_host_finalize;
+
+
+        g_object_class_install_property (object_class,
+                                         PROP_ADDRESS,
+                                         g_param_spec_boxed ("address",
+                                                             "address",
+                                                             "address",
+                                                             GDM_TYPE_ADDRESS,
+                                                             G_PARAM_READWRITE | G_PARAM_CONSTRUCT));
+        g_object_class_install_property (object_class,
+                                         PROP_DESCRIPTION,
+                                         g_param_spec_string ("description",
+                                                              "description",
+                                                              "description",
+                                                              NULL,
+                                                              G_PARAM_READWRITE | G_PARAM_CONSTRUCT));
+
+        g_object_class_install_property (object_class,
+                                         PROP_KIND,
+                                         g_param_spec_int ("kind",
+                                                           "kind",
+                                                           "kind",
+                                                           0,
+                                                           G_MAXINT,
+                                                           0,
+                                                           G_PARAM_READWRITE | G_PARAM_CONSTRUCT));
+        g_object_class_install_property (object_class,
+                                         PROP_WILLING,
+                                         g_param_spec_boolean ("willing",
+                                                               "willing",
+                                                               "willing",
+                                                               FALSE,
+                                                               G_PARAM_READWRITE | G_PARAM_CONSTRUCT));
+
+
+        g_type_class_add_private (klass, sizeof (GdmChooserHostPrivate));
+}
+
+static void
+gdm_chooser_host_init (GdmChooserHost *widget)
+{
+        widget->priv = GDM_CHOOSER_HOST_GET_PRIVATE (widget);
+}
+
+static void
+gdm_chooser_host_finalize (GObject *object)
+{
+        GdmChooserHost *host;
+
+        g_return_if_fail (object != NULL);
+        g_return_if_fail (GDM_IS_CHOOSER_HOST (object));
+
+        host = GDM_CHOOSER_HOST (object);
+
+        g_return_if_fail (host->priv != NULL);
+
+        g_free (host->priv->description);
+        gdm_address_free (host->priv->address);
+
+        G_OBJECT_CLASS (gdm_chooser_host_parent_class)->finalize (object);
+}

Added: trunk/gui/simple-chooser/gdm-chooser-host.h
==============================================================================
--- (empty file)
+++ trunk/gui/simple-chooser/gdm-chooser-host.h	Tue Mar  4 19:48:22 2008
@@ -0,0 +1,63 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*-
+ *
+ * Copyright (C) 2008 Red Hat, Inc.
+ *
+ * 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 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+
+#ifndef __GDM_CHOOSER_HOST__
+#define __GDM_CHOOSER_HOST__
+
+#include <glib-object.h>
+#include "gdm-address.h"
+
+G_BEGIN_DECLS
+
+#define GDM_TYPE_CHOOSER_HOST         (gdm_chooser_host_get_type ())
+#define GDM_CHOOSER_HOST(o)           (G_TYPE_CHECK_INSTANCE_CAST ((o), GDM_TYPE_CHOOSER_HOST, GdmChooserHost))
+#define GDM_CHOOSER_HOST_CLASS(k)     (G_TYPE_CHECK_CLASS_CAST((k), GDM_TYPE_CHOOSER_HOST, GdmChooserHostClass))
+#define GDM_IS_CHOOSER_HOST(o)        (G_TYPE_CHECK_INSTANCE_TYPE ((o), GDM_TYPE_CHOOSER_HOST))
+#define GDM_IS_CHOOSER_HOST_CLASS(k)  (G_TYPE_CHECK_CLASS_TYPE ((k), GDM_TYPE_CHOOSER_HOST))
+#define GDM_CHOOSER_HOST_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), GDM_TYPE_CHOOSER_HOST, GdmChooserHostClass))
+
+typedef enum {
+        GDM_CHOOSER_HOST_KIND_XDMCP = 1 << 0,
+} GdmChooserHostKind;
+
+#define GDM_CHOOSER_HOST_KIND_MASK_ALL (GDM_CHOOSER_HOST_KIND_XDMCP)
+
+typedef struct GdmChooserHostPrivate GdmChooserHostPrivate;
+
+typedef struct
+{
+        GObject                parent;
+        GdmChooserHostPrivate *priv;
+} GdmChooserHost;
+
+typedef struct
+{
+        GObjectClass   parent_class;
+} GdmChooserHostClass;
+
+GType                 gdm_chooser_host_get_type            (void) G_GNUC_CONST;
+
+G_CONST_RETURN char  *gdm_chooser_host_get_description     (GdmChooserHost   *chooser_host);
+GdmAddress *          gdm_chooser_host_get_address         (GdmChooserHost   *chooser_host);
+gboolean              gdm_chooser_host_get_willing         (GdmChooserHost   *chooser_host);
+GdmChooserHostKind    gdm_chooser_host_get_kind            (GdmChooserHost   *chooser_host);
+
+G_END_DECLS
+
+#endif

Modified: trunk/gui/simple-chooser/gdm-chooser-session.c
==============================================================================
--- trunk/gui/simple-chooser/gdm-chooser-session.c	(original)
+++ trunk/gui/simple-chooser/gdm-chooser-session.c	Tue Mar  4 19:48:22 2008
@@ -149,22 +149,32 @@
                     int                response_id,
                     GdmChooserSession *session)
 {
-        char *hostname;
+        GdmChooserHost *host;
 
-        hostname = NULL;
+        host = NULL;
         switch (response_id) {
         case GTK_RESPONSE_OK:
-                hostname = gdm_host_chooser_dialog_get_current_hostname (GDM_HOST_CHOOSER_DIALOG (dialog));
+                host = gdm_host_chooser_dialog_get_host (GDM_HOST_CHOOSER_DIALOG (dialog));
         case GTK_RESPONSE_NONE:
                 /* delete event */
         default:
                 break;
         }
 
-        if (hostname != NULL) {
-                g_debug ("GdmChooserSession: Selected hostname '%s'", hostname);
-                gdm_chooser_client_call_select_hostname (session->priv->client, hostname);
-                g_free (hostname);
+        if (host != NULL) {
+                char *hostname;
+
+                /* only support XDMCP hosts in remote chooser */
+                g_assert (gdm_chooser_host_get_kind (host) == GDM_CHOOSER_HOST_KIND_XDMCP);
+
+                hostname = NULL;
+                gdm_address_get_hostname (gdm_chooser_host_get_address (host), &hostname);
+                /* FIXME: fall back to numerical address? */
+                if (hostname != NULL) {
+                        g_debug ("GdmChooserSession: Selected hostname '%s'", hostname);
+                        gdm_chooser_client_call_select_hostname (session->priv->client, hostname);
+                        g_free (hostname);
+                }
         }
 
         gdm_chooser_client_call_disconnect (session->priv->client);
@@ -184,7 +194,8 @@
                 start_settings_daemon (session);
                 start_window_manager (session);
 
-                session->priv->chooser_dialog = gdm_host_chooser_dialog_new ();
+                /* Only support XDMCP on remote choosers */
+                session->priv->chooser_dialog = gdm_host_chooser_dialog_new (GDM_CHOOSER_HOST_KIND_XDMCP);
                 g_signal_connect (session->priv->chooser_dialog,
                                   "response",
                                   G_CALLBACK (on_dialog_response),

Modified: trunk/gui/simple-chooser/gdm-host-chooser-dialog.c
==============================================================================
--- trunk/gui/simple-chooser/gdm-host-chooser-dialog.c	(original)
+++ trunk/gui/simple-chooser/gdm-host-chooser-dialog.c	Tue Mar  4 19:48:22 2008
@@ -38,10 +38,12 @@
 struct GdmHostChooserDialogPrivate
 {
         GtkWidget *chooser_widget;
+        int        kind_mask;
 };
 
 enum {
         PROP_0,
+        PROP_KIND_MASK,
 };
 
 static void     gdm_host_chooser_dialog_class_init  (GdmHostChooserDialogClass *klass);
@@ -50,24 +52,41 @@
 
 G_DEFINE_TYPE (GdmHostChooserDialog, gdm_host_chooser_dialog, GTK_TYPE_DIALOG)
 
-char *
-gdm_host_chooser_dialog_get_current_hostname (GdmHostChooserDialog *dialog)
+GdmChooserHost *
+gdm_host_chooser_dialog_get_host (GdmHostChooserDialog *dialog)
 {
-        char *hostname;
+        GdmChooserHost *host;
 
         g_return_val_if_fail (GDM_IS_HOST_CHOOSER_DIALOG (dialog), NULL);
 
-        hostname = gdm_host_chooser_widget_get_current_hostname (GDM_HOST_CHOOSER_WIDGET (dialog->priv->chooser_widget));
+        host = gdm_host_chooser_widget_get_host (GDM_HOST_CHOOSER_WIDGET (dialog->priv->chooser_widget));
 
-        return hostname;
+        return host;
 }
+
+static void
+_gdm_host_chooser_dialog_set_kind_mask (GdmHostChooserDialog *dialog,
+                                        int                   kind_mask)
+{
+        if (dialog->priv->kind_mask != kind_mask) {
+                dialog->priv->kind_mask = kind_mask;
+        }
+}
+
 static void
 gdm_host_chooser_dialog_set_property (GObject        *object,
                                       guint           prop_id,
                                       const GValue   *value,
                                       GParamSpec     *pspec)
 {
+        GdmHostChooserDialog *self;
+
+        self = GDM_HOST_CHOOSER_DIALOG (object);
+
         switch (prop_id) {
+        case PROP_KIND_MASK:
+                _gdm_host_chooser_dialog_set_kind_mask (self, g_value_get_int (value));
+                break;
         default:
                 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
                 break;
@@ -87,18 +106,55 @@
         }
 }
 
+static void
+on_response (GdmHostChooserDialog *dialog,
+             gint                  response_id)
+{
+        switch (response_id) {
+        case GTK_RESPONSE_APPLY:
+                gdm_host_chooser_widget_refresh (GDM_HOST_CHOOSER_WIDGET (dialog->priv->chooser_widget));
+                g_signal_stop_emission_by_name (dialog, "response");
+                break;
+        default:
+                break;
+        }
+}
+
 static GObject *
 gdm_host_chooser_dialog_constructor (GType                  type,
                                      guint                  n_construct_properties,
                                      GObjectConstructParam *construct_properties)
 {
-        GdmHostChooserDialog      *host_chooser_dialog;
+        GdmHostChooserDialog      *dialog;
 
-        host_chooser_dialog = GDM_HOST_CHOOSER_DIALOG (G_OBJECT_CLASS (gdm_host_chooser_dialog_parent_class)->constructor (type,
+        dialog = GDM_HOST_CHOOSER_DIALOG (G_OBJECT_CLASS (gdm_host_chooser_dialog_parent_class)->constructor (type,
                                                                                                                            n_construct_properties,
                                                                                                                            construct_properties));
 
-        return G_OBJECT (host_chooser_dialog);
+
+        dialog->priv->chooser_widget = gdm_host_chooser_widget_new (dialog->priv->kind_mask);
+        gtk_container_add (GTK_CONTAINER (GTK_DIALOG (dialog)->vbox), dialog->priv->chooser_widget);
+        gtk_container_set_border_width (GTK_CONTAINER (dialog->priv->chooser_widget), 5);
+
+        gtk_dialog_add_buttons (GTK_DIALOG (dialog),
+                                GTK_STOCK_REFRESH, GTK_RESPONSE_APPLY,
+                                GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
+                                GTK_STOCK_OK, GTK_RESPONSE_OK,
+                                NULL);
+
+        gtk_container_set_border_width (GTK_CONTAINER (dialog), 12);
+        gtk_dialog_set_has_separator (GTK_DIALOG (dialog), FALSE);
+        gtk_window_set_title (GTK_WINDOW (dialog), _("Select System"));
+        gtk_window_set_icon_name (GTK_WINDOW (dialog), "computer");
+
+        g_signal_connect (dialog,
+                          "response",
+                          G_CALLBACK (on_response),
+                          dialog);
+
+        gtk_widget_show_all (GTK_WIDGET (dialog));
+
+        return G_OBJECT (dialog);
 }
 
 static void
@@ -120,50 +176,23 @@
         object_class->dispose = gdm_host_chooser_dialog_dispose;
         object_class->finalize = gdm_host_chooser_dialog_finalize;
 
-        g_type_class_add_private (klass, sizeof (GdmHostChooserDialogPrivate));
-}
+        g_object_class_install_property (object_class,
+                                         PROP_KIND_MASK,
+                                         g_param_spec_int ("kind-mask",
+                                                           "kind mask",
+                                                           "kind mask",
+                                                           0,
+                                                           G_MAXINT,
+                                                           0,
+                                                           G_PARAM_READWRITE | G_PARAM_CONSTRUCT));
 
-static void
-on_response (GdmHostChooserDialog *dialog,
-             gint                  response_id)
-{
-        switch (response_id) {
-        case GTK_RESPONSE_APPLY:
-                gdm_host_chooser_widget_refresh (GDM_HOST_CHOOSER_WIDGET (dialog->priv->chooser_widget));
-                g_signal_stop_emission_by_name (dialog, "response");
-                break;
-        default:
-                break;
-        }
+        g_type_class_add_private (klass, sizeof (GdmHostChooserDialogPrivate));
 }
 
 static void
 gdm_host_chooser_dialog_init (GdmHostChooserDialog *dialog)
 {
-
         dialog->priv = GDM_HOST_CHOOSER_DIALOG_GET_PRIVATE (dialog);
-
-        dialog->priv->chooser_widget = gdm_host_chooser_widget_new ();
-        gtk_container_add (GTK_CONTAINER (GTK_DIALOG (dialog)->vbox), dialog->priv->chooser_widget);
-
-        gtk_dialog_add_buttons (GTK_DIALOG (dialog),
-                                GTK_STOCK_REFRESH, GTK_RESPONSE_APPLY,
-                                GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
-                                GTK_STOCK_OK, GTK_RESPONSE_OK,
-                                NULL);
-
-        gtk_container_set_border_width (GTK_CONTAINER (dialog), 12);
-        gtk_container_set_border_width (GTK_CONTAINER (dialog->priv->chooser_widget), 5);
-        gtk_dialog_set_has_separator (GTK_DIALOG (dialog), FALSE);
-        gtk_window_set_title (GTK_WINDOW (dialog), _("Select System"));
-        gtk_window_set_icon_name (GTK_WINDOW (dialog), "computer");
-
-        g_signal_connect (dialog,
-                          "response",
-                          G_CALLBACK (on_response),
-                          dialog);
-
-        gtk_widget_show_all (GTK_WIDGET (dialog));
 }
 
 static void
@@ -182,11 +211,12 @@
 }
 
 GtkWidget *
-gdm_host_chooser_dialog_new (void)
+gdm_host_chooser_dialog_new (int kind_mask)
 {
         GObject *object;
 
         object = g_object_new (GDM_TYPE_HOST_CHOOSER_DIALOG,
+                               "kind-mask", kind_mask,
                                NULL);
 
         return GTK_WIDGET (object);

Modified: trunk/gui/simple-chooser/gdm-host-chooser-dialog.h
==============================================================================
--- trunk/gui/simple-chooser/gdm-host-chooser-dialog.h	(original)
+++ trunk/gui/simple-chooser/gdm-host-chooser-dialog.h	Tue Mar  4 19:48:22 2008
@@ -23,6 +23,7 @@
 
 #include <glib-object.h>
 #include <gtk/gtkdialog.h>
+#include "gdm-chooser-host.h"
 
 G_BEGIN_DECLS
 
@@ -46,11 +47,13 @@
         GtkDialogClass   parent_class;
 } GdmHostChooserDialogClass;
 
-GType                  gdm_host_chooser_dialog_get_type                       (void);
+GType                  gdm_host_chooser_dialog_get_type           (void);
 
-GtkWidget            * gdm_host_chooser_dialog_new                            (void);
+GtkWidget            * gdm_host_chooser_dialog_new                (int                   kind_mask);
+void                   gdm_host_chooser_dialog_set_kind_mask      (GdmHostChooserDialog *dialog,
+                                                                   int                   kind_mask);
 
-char *                 gdm_host_chooser_dialog_get_current_hostname           (GdmHostChooserDialog *dialog);
+GdmChooserHost *       gdm_host_chooser_dialog_get_host           (GdmHostChooserDialog *dialog);
 
 G_END_DECLS
 

Modified: trunk/gui/simple-chooser/gdm-host-chooser-widget.c
==============================================================================
--- trunk/gui/simple-chooser/gdm-host-chooser-widget.c	(original)
+++ trunk/gui/simple-chooser/gdm-host-chooser-widget.c	Tue Mar  4 19:48:22 2008
@@ -44,20 +44,17 @@
 #include <gtk/gtk.h>
 
 #include "gdm-address.h"
+#include "gdm-chooser-host.h"
 #include "gdm-host-chooser-widget.h"
 
 #define GDM_HOST_CHOOSER_WIDGET_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), GDM_TYPE_HOST_CHOOSER_WIDGET, GdmHostChooserWidgetPrivate))
 
-typedef struct _GdmChooserHost {
-        GdmAddress *address;
-        char       *description;
-        gboolean    willing;
-} GdmChooserHost;
-
 struct GdmHostChooserWidgetPrivate
 {
         GtkWidget      *treeview;
 
+        int             kind_mask;
+
         char          **hosts;
 
         XdmcpBuffer     broadcast_buf;
@@ -79,6 +76,7 @@
 
 enum {
         PROP_0,
+        PROP_KIND_MASK,
 };
 
 enum {
@@ -121,18 +119,6 @@
 }
 #endif
 
-static void
-chooser_host_free (GdmChooserHost *host)
-{
-        if (host == NULL) {
-                return;
-        }
-
-        g_free (host->description);
-        gdm_address_free (host->address);
-        g_free (host);
-}
-
 static GdmChooserHost *
 find_known_host (GdmHostChooserWidget *widget,
                  GdmAddress           *address)
@@ -142,7 +128,7 @@
 
         for (li = widget->priv->chooser_hosts; li != NULL; li = li->next) {
                 host = li->data;
-                if (gdm_address_equal (host->address, address)) {
+                if (gdm_address_equal (gdm_chooser_host_get_address (host), address)) {
                         goto out;
                 }
         }
@@ -167,18 +153,18 @@
 
         g_assert (host != NULL);
 
-        if (! host->willing) {
+        if (! gdm_chooser_host_get_willing (host)) {
                 gtk_widget_set_sensitive (GTK_WIDGET (widget), TRUE);
                 return;
         }
 
-        res = gdm_address_get_hostname (host->address, &hostname);
+        res = gdm_address_get_hostname (gdm_chooser_host_get_address (host), &hostname);
         if (! res) {
-                gdm_address_get_numeric_info (host->address, &hostname, NULL);
+                gdm_address_get_numeric_info (gdm_chooser_host_get_address (host), &hostname, NULL);
         }
 
         name = g_markup_escape_text (hostname, -1);
-        desc = g_markup_escape_text (host->description, -1);
+        desc = g_markup_escape_text (gdm_chooser_host_get_description (host), -1);
         label = g_strdup_printf ("<b>%s</b>\n%s", name, desc);
         g_free (name);
         g_free (desc);
@@ -274,19 +260,22 @@
 
         chooser_host = find_known_host (widget, address);
         if (chooser_host == NULL) {
-
-                chooser_host = g_new0 (GdmChooserHost, 1);
-                chooser_host->address = gdm_address_copy (address);
-                chooser_host->description = g_strdup (status);
-                chooser_host->willing = (header.opcode == WILLING);
+                chooser_host = g_object_new (GDM_TYPE_CHOOSER_HOST,
+                                             "address", address,
+                                             "description", status,
+                                             "willing", (header.opcode == WILLING),
+                                             "kind", GDM_CHOOSER_HOST_KIND_XDMCP,
+                                             NULL);
                 chooser_host_add (widget, chooser_host);
                 browser_add_host (widget, chooser_host);
         } else {
                 /* server changed it's mind */
-                if (header.opcode == WILLING && ! chooser_host->willing) {
-                        chooser_host->willing = TRUE;
+                if (header.opcode == WILLING
+                    && ! gdm_chooser_host_get_willing (chooser_host)) {
+                        g_object_set (chooser_host, "willing", TRUE, NULL);
                         browser_add_host (widget, chooser_host);
                 }
+                /* FIXME: handle unwilling? */
         }
 
  done:
@@ -600,29 +589,38 @@
                                                     (GIOFunc)decode_packet,
                                                     widget);
         g_io_channel_unref (ioc);
-
-        xdmcp_discover (widget);
 }
 
 void
 gdm_host_chooser_widget_refresh (GdmHostChooserWidget *widget)
 {
         g_return_if_fail (GDM_IS_HOST_CHOOSER_WIDGET (widget));
+
+        xdmcp_discover (widget);
 }
 
-char *
-gdm_host_chooser_widget_get_current_hostname (GdmHostChooserWidget *widget)
+GdmChooserHost *
+gdm_host_chooser_widget_get_host (GdmHostChooserWidget *widget)
 {
-        char *hostname;
+        GdmChooserHost *host;
 
         g_return_val_if_fail (GDM_IS_HOST_CHOOSER_WIDGET (widget), NULL);
 
-        hostname = NULL;
+        host = NULL;
         if (widget->priv->current_host != NULL) {
-                gdm_address_get_hostname (widget->priv->current_host->address, &hostname);
+                host = g_object_ref (widget->priv->current_host);
         }
 
-        return hostname;
+        return host;
+}
+
+static void
+_gdm_host_chooser_widget_set_kind_mask (GdmHostChooserWidget *widget,
+                                        int                   kind_mask)
+{
+        if (widget->priv->kind_mask != kind_mask) {
+                widget->priv->kind_mask = kind_mask;
+        }
 }
 
 static void
@@ -631,7 +629,14 @@
                                       const GValue   *value,
                                       GParamSpec     *pspec)
 {
+        GdmHostChooserWidget *self;
+
+        self = GDM_HOST_CHOOSER_WIDGET (object);
+
         switch (prop_id) {
+        case PROP_KIND_MASK:
+                _gdm_host_chooser_widget_set_kind_mask (self, g_value_get_int (value));
+                break;
         default:
                 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
                 break;
@@ -656,13 +661,16 @@
                                      guint                  n_construct_properties,
                                      GObjectConstructParam *construct_properties)
 {
-        GdmHostChooserWidget      *host_chooser_widget;
+        GdmHostChooserWidget      *widget;
 
-        host_chooser_widget = GDM_HOST_CHOOSER_WIDGET (G_OBJECT_CLASS (gdm_host_chooser_widget_parent_class)->constructor (type,
+        widget = GDM_HOST_CHOOSER_WIDGET (G_OBJECT_CLASS (gdm_host_chooser_widget_parent_class)->constructor (type,
                                                                                                                            n_construct_properties,
                                                                                                                            construct_properties));
 
-        return G_OBJECT (host_chooser_widget);
+        xdmcp_init (widget);
+        xdmcp_discover (widget);
+
+        return G_OBJECT (widget);
 }
 
 static void
@@ -690,7 +698,7 @@
         }
         if (widget->priv->chooser_hosts != NULL) {
                 g_slist_foreach (widget->priv->chooser_hosts,
-                                 (GFunc)chooser_host_free,
+                                 (GFunc)g_object_unref,
                                  NULL);
                 g_slist_free (widget->priv->chooser_hosts);
                 widget->priv->chooser_hosts = NULL;
@@ -712,6 +720,16 @@
         object_class->dispose = gdm_host_chooser_widget_dispose;
         object_class->finalize = gdm_host_chooser_widget_finalize;
 
+        g_object_class_install_property (object_class,
+                                         PROP_KIND_MASK,
+                                         g_param_spec_int ("kind-mask",
+                                                           "kind mask",
+                                                           "kind mask",
+                                                           0,
+                                                           G_MAXINT,
+                                                           0,
+                                                           G_PARAM_READWRITE | G_PARAM_CONSTRUCT));
+
         signals [HOST_ACTIVATED] = g_signal_new ("host-activated",
                                                  G_TYPE_FROM_CLASS (object_class),
                                                  G_SIGNAL_RUN_LAST,
@@ -803,8 +821,6 @@
         gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (model),
                                               CHOOSER_LIST_LABEL_COLUMN,
                                               GTK_SORT_ASCENDING);
-
-        xdmcp_init (widget);
 }
 
 static void
@@ -823,11 +839,12 @@
 }
 
 GtkWidget *
-gdm_host_chooser_widget_new (void)
+gdm_host_chooser_widget_new (int kind_mask)
 {
         GObject *object;
 
         object = g_object_new (GDM_TYPE_HOST_CHOOSER_WIDGET,
+                               "kind-mask", kind_mask,
                                NULL);
 
         return GTK_WIDGET (object);

Modified: trunk/gui/simple-chooser/gdm-host-chooser-widget.h
==============================================================================
--- trunk/gui/simple-chooser/gdm-host-chooser-widget.h	(original)
+++ trunk/gui/simple-chooser/gdm-host-chooser-widget.h	Tue Mar  4 19:48:22 2008
@@ -23,6 +23,7 @@
 
 #include <glib-object.h>
 #include <gtk/gtkvbox.h>
+#include "gdm-chooser-host.h"
 
 G_BEGIN_DECLS
 
@@ -49,12 +50,15 @@
         void (* host_activated)        (GdmHostChooserWidget *widget);
 } GdmHostChooserWidgetClass;
 
-GType                  gdm_host_chooser_widget_get_type                       (void);
-GtkWidget *            gdm_host_chooser_widget_new                            (void);
+GType                  gdm_host_chooser_widget_get_type           (void);
+GtkWidget *            gdm_host_chooser_widget_new                (int                   kind_mask);
 
-void                   gdm_host_chooser_widget_refresh                        (GdmHostChooserWidget *widget);
+void                   gdm_host_chooser_widget_set_kind_mask      (GdmHostChooserWidget *widget,
+                                                                   int                   kind_mask);
 
-char *                 gdm_host_chooser_widget_get_current_hostname           (GdmHostChooserWidget *widget);
+void                   gdm_host_chooser_widget_refresh            (GdmHostChooserWidget *widget);
+
+GdmChooserHost *       gdm_host_chooser_widget_get_host           (GdmHostChooserWidget *widget);
 
 G_END_DECLS
 

Modified: trunk/gui/simple-chooser/gdm-host-chooser.c
==============================================================================
--- trunk/gui/simple-chooser/gdm-host-chooser.c	(original)
+++ trunk/gui/simple-chooser/gdm-host-chooser.c	Tue Mar  4 19:48:22 2008
@@ -37,6 +37,7 @@
 #include "gdm-settings-client.h"
 #include "gdm-settings-keys.h"
 
+#include "gdm-chooser-host.h"
 #include "gdm-host-chooser-dialog.h"
 
 #define ACCESSIBILITY_KEY         "/desktop/gnome/interface/accessibility"
@@ -248,13 +249,23 @@
 
         gtk_init (&argc, &argv);
 
-        chooser = gdm_host_chooser_dialog_new ();
+        chooser = gdm_host_chooser_dialog_new (GDM_CHOOSER_HOST_KIND_MASK_ALL);
         if (gtk_dialog_run (GTK_DIALOG (chooser)) == GTK_RESPONSE_OK) {
-                char *hostname;
+                GdmChooserHost *host;
 
-                hostname = gdm_host_chooser_dialog_get_current_hostname (GDM_HOST_CHOOSER_DIALOG (chooser));
-                g_print ("hostname: %s\n", hostname);
-                g_free (hostname);
+                host = gdm_host_chooser_dialog_get_host (GDM_HOST_CHOOSER_DIALOG (chooser));
+                if (host != NULL) {
+                        char *hostname;
+                        /* FIXME: handle different host types here? */
+
+                        hostname = NULL;
+                        gdm_address_get_hostname (gdm_chooser_host_get_address (host), &hostname);
+                        /* FIXME: fall back to numerical address? */
+                        if (hostname != NULL) {
+                                g_print ("hostname: %s\n", hostname);
+                                g_free (hostname);
+                        }
+                }
         }
 
         gtk_widget_destroy (chooser);



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]