[vinagre] Added ability to plugins parse the txt data of mdns.



commit 18d532a685af7d18c567f2cab7dc0ca8471a7dac
Author: Jonh Wendell <jwendell gnome org>
Date:   Mon Feb 1 21:21:26 2010 -0300

    Added ability to plugins parse the txt data of mdns.
    
    Also, make SSH plugin use the username provided from mdns.
    Closes #598592.

 plugins/ssh/vinagre-ssh-plugin.c |   43 ++++++++++++++++++++++++++++++++++++++
 vinagre/vinagre-connect.c        |   20 ++++++++++++++---
 vinagre/vinagre-mdns.c           |   17 ++++++++++++++-
 vinagre/vinagre-plugin.c         |   18 +++++++++++++++
 vinagre/vinagre-plugin.h         |    7 ++++++
 5 files changed, 100 insertions(+), 5 deletions(-)
---
diff --git a/plugins/ssh/vinagre-ssh-plugin.c b/plugins/ssh/vinagre-ssh-plugin.c
index c75cf9e..b257a20 100644
--- a/plugins/ssh/vinagre-ssh-plugin.c
+++ b/plugins/ssh/vinagre-ssh-plugin.c
@@ -32,6 +32,11 @@
 #include "vinagre-ssh-connection.h"
 #include "vinagre-ssh-tab.h"
 
+#ifdef VINAGRE_ENABLE_AVAHI
+#include <avahi-ui/avahi-ui.h>
+#include <avahi-common/malloc.h>
+#endif
+
 #define VINAGRE_SSH_PLUGIN_GET_PRIVATE(object)(G_TYPE_INSTANCE_GET_PRIVATE ((object), VINAGRE_TYPE_SSH_PLUGIN, VinagreSshPluginPrivate))
 
 VINAGRE_PLUGIN_REGISTER_TYPE(VinagreSshPlugin, vinagre_ssh_plugin)
@@ -157,6 +162,43 @@ impl_get_connect_widget (VinagrePlugin *plugin, VinagreConnection *conn)
 }
 
 static void
+ssh_parse_mdns_dialog (VinagrePlugin *plugin,
+		       GtkWidget *connect_widget,
+		       GtkWidget *dialog)
+{
+#ifdef VINAGRE_ENABLE_AVAHI
+  const AvahiStringList *txt;
+  gchar *u = NULL;
+
+  for (txt = aui_service_dialog_get_txt_data (AUI_SERVICE_DIALOG (dialog)); txt; txt = txt->next)
+    {
+      char *key, *value;
+
+      if (avahi_string_list_get_pair ((AvahiStringList*) txt, &key, &value, NULL) < 0)
+	break;
+
+      if (strcmp(key, "u") == 0)
+	u = g_strdup(value);
+
+      avahi_free (key);
+      avahi_free (value);
+    }
+
+  if (u)
+    {
+      GtkEntry *u_entry = g_object_get_data (G_OBJECT (connect_widget), "username_entry");
+
+      if (u_entry)
+        gtk_entry_set_text (u_entry, u);
+      else
+	g_warning ("Wrong widget passed to ssh_parse_mdns_dialog()");
+
+      g_free (u);
+    }
+#endif
+}
+
+static void
 vinagre_ssh_plugin_class_init (VinagreSshPluginClass *klass)
 {
   GObjectClass *object_class = G_OBJECT_CLASS (klass);
@@ -174,5 +216,6 @@ vinagre_ssh_plugin_class_init (VinagreSshPluginClass *klass)
   plugin_class->new_tab = impl_new_tab;
   plugin_class->get_default_port = impl_get_default_port;
   plugin_class->get_connect_widget = impl_get_connect_widget;
+  plugin_class->parse_mdns_dialog = ssh_parse_mdns_dialog;
 }
 /* vim: set ts=8: */
diff --git a/vinagre/vinagre-connect.c b/vinagre/vinagre-connect.c
index 7cbe5f7..86b12d8 100644
--- a/vinagre/vinagre-connect.c
+++ b/vinagre/vinagre-connect.c
@@ -322,9 +322,11 @@ static void
 vinagre_connect_find_button_cb (GtkButton            *button,
 				VinagreConnectDialog *dialog)
 {
-  GtkWidget   *d;
-  GtkTreeIter tree_iter;
-  gchar       *service;
+  GtkWidget     *d;
+  GtkTreeIter   tree_iter;
+  gchar         *service;
+  GtkWidget     *options = NULL;
+  VinagrePlugin *plugin = NULL;
 
   if (!gtk_combo_box_get_active_iter (GTK_COMBO_BOX (dialog->protocol_combo),
 				      &tree_iter))
@@ -335,9 +337,15 @@ vinagre_connect_find_button_cb (GtkButton            *button,
 
   gtk_tree_model_get (GTK_TREE_MODEL (dialog->protocol_store), &tree_iter,
 		      PROTOCOL_MDNS, &service,
+		      PROTOCOL_PLUGIN, &plugin,
+		      PROTOCOL_OPTIONS, &options,
 		      -1);
   if (!service)
-    return;
+    {
+      if (plugin)
+	g_object_unref (plugin);
+      return;
+    }
 
   d = aui_service_dialog_new (_("Choose a Remote Desktop"),
 				GTK_WINDOW(dialog->dialog),
@@ -367,10 +375,14 @@ vinagre_connect_find_button_cb (GtkButton            *button,
 			  tmp);
 
       g_free (tmp);
+      if (plugin && options)
+	vinagre_plugin_parse_mdns_dialog (plugin, options, d);
     }
 
   g_free (service);
   gtk_widget_destroy (d);
+  if (plugin)
+    g_object_unref (plugin);
 }
 #endif
 
diff --git a/vinagre/vinagre-mdns.c b/vinagre/vinagre-mdns.c
index 6d6eb31..adf7107 100644
--- a/vinagre/vinagre-mdns.c
+++ b/vinagre/vinagre-mdns.c
@@ -71,7 +71,7 @@ mdns_resolver_found (GaServiceResolver *resolver,
   VinagreConnection     *conn;
   VinagreBookmarksEntry *entry;
   BrowserEntry          *b_entry;
-  char                  a[AVAHI_ADDRESS_STR_MAX];
+  char                  a[AVAHI_ADDRESS_STR_MAX], *u = NULL;
 
   b_entry = g_hash_table_lookup (mdns->priv->browsers, type);
   if (!b_entry)
@@ -80,12 +80,27 @@ mdns_resolver_found (GaServiceResolver *resolver,
       return;
     }
 
+  for (; txt; txt = txt->next)
+    {
+      char *key, *value;
+
+      if (avahi_string_list_get_pair (txt, &key, &value, NULL) < 0)
+	break;
+
+      if (strcmp(key, "u") == 0)
+	u = g_strdup (value);
+
+      avahi_free (key);
+      avahi_free (value);
+    }
+
   avahi_address_snprint (a, sizeof(a), address);
   conn = vinagre_plugin_new_connection (b_entry->info->plugin);
   g_object_set (conn,
                 "name", name,
                 "port", port,
                 "host", a,
+                "username", u,
                 NULL);
   entry = vinagre_bookmarks_entry_new_conn (conn);
   g_object_unref (conn);
diff --git a/vinagre/vinagre-plugin.c b/vinagre/vinagre-plugin.c
index 59a6497..0c17ed5 100644
--- a/vinagre/vinagre-plugin.c
+++ b/vinagre/vinagre-plugin.c
@@ -129,6 +129,13 @@ default_get_file_filter (VinagrePlugin *plugin)
 }
 
 static void
+default_parse_mdns_dialog (VinagrePlugin *plugin,
+			   GtkWidget *connect_widget,
+			   GtkWidget *dialog)
+{
+}
+
+static void
 vinagre_plugin_get_property (GObject    *object,
 			   guint       prop_id,
 			   GValue     *value,
@@ -197,6 +204,7 @@ vinagre_plugin_class_init (VinagrePluginClass *klass)
 	klass->new_tab = default_new_tab;
 	klass->get_connect_widget = default_get_connect_widget;
 	klass->get_file_filter = default_get_file_filter;
+	klass->parse_mdns_dialog = default_parse_mdns_dialog;
 	
 	klass->create_configure_dialog = create_configure_dialog;
 	klass->is_configurable = is_configurable;
@@ -584,4 +592,14 @@ vinagre_plugin_get_icon_name (VinagrePlugin *plugin)
   return vinagre_plugin_info_get_icon_name (info);
 }
 
+void
+vinagre_plugin_parse_mdns_dialog (VinagrePlugin *plugin,
+				  GtkWidget *connect_widget,
+				  GtkWidget *dialog)
+{
+  g_return_if_fail (VINAGRE_IS_PLUGIN (plugin));
+
+  VINAGRE_PLUGIN_GET_CLASS (plugin)->parse_mdns_dialog (plugin, connect_widget, dialog);
+}
+
 /* vim: set ts=8: */
diff --git a/vinagre/vinagre-plugin.h b/vinagre/vinagre-plugin.h
index 41830a6..2782a1f 100644
--- a/vinagre/vinagre-plugin.h
+++ b/vinagre/vinagre-plugin.h
@@ -90,6 +90,10 @@ struct _VinagrePluginClass
 
   GtkWidget 	*(*get_connect_widget)		(VinagrePlugin     *plugin,
 						 VinagreConnection *initial_settings);
+  void		(*parse_mdns_dialog)		(VinagrePlugin *plugin,
+						 GtkWidget *connect_widget,
+						 GtkWidget *dialog);
+
 
   GtkFileFilter	*(*get_file_filter)		(VinagrePlugin     *plugin);
 
@@ -122,6 +126,9 @@ void 		 vinagre_plugin_update_ui		(VinagrePlugin *plugin,
 
 gboolean	 vinagre_plugin_is_configurable		(VinagrePlugin *plugin);
 GtkWidget	*vinagre_plugin_create_configure_dialog	(VinagrePlugin *plugin);
+void		 vinagre_plugin_parse_mdns_dialog	(VinagrePlugin *plugin,
+							 GtkWidget *connect_widget,
+							 GtkWidget *dialog);
 
 GSList		*vinagre_plugin_get_context_groups	(VinagrePlugin *plugin);
 const gchar	*vinagre_plugin_get_protocol		(VinagrePlugin *plugin);



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