[vinagre] Improved the password dialog for the SSH tunneling



commit 62eb823e5131b9c9d1067b461f097ff06e9cd620
Author: Jonh Wendell <jwendell gnome org>
Date:   Tue Jan 26 17:52:18 2010 -0300

    Improved the password dialog for the SSH tunneling

 data/vinagre.ui                  |    2 +-
 plugins/vnc/vinagre-vnc-tab.c    |  137 ++++++-------------------------------
 plugins/vnc/vinagre-vnc-tunnel.c |    9 ++-
 plugins/vnc/vinagre-vnc-tunnel.h |    8 ++-
 vinagre/vinagre-ssh.c            |  121 +++++++++++++++------------------
 vinagre/vinagre-ssh.h            |    5 +-
 vinagre/vinagre-utils.c          |  123 +++++++++++++++++++++++++++++++++-
 vinagre/vinagre-utils.h          |   10 +++
 8 files changed, 226 insertions(+), 189 deletions(-)
---
diff --git a/data/vinagre.ui b/data/vinagre.ui
index 4cd1c72..ce7135f 100644
--- a/data/vinagre.ui
+++ b/data/vinagre.ui
@@ -289,7 +289,7 @@
             <property name="orientation">vertical</property>
             <property name="spacing">6</property>
             <child>
-              <object class="GtkLabel" id="label5">
+              <object class="GtkLabel" id="auth_required_label">
                 <property name="visible">True</property>
                 <property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
                 <property name="xalign">0</property>
diff --git a/plugins/vnc/vinagre-vnc-tab.c b/plugins/vnc/vinagre-vnc-tab.c
index da5b295..ad8dfba 100644
--- a/plugins/vnc/vinagre-vnc-tab.c
+++ b/plugins/vnc/vinagre-vnc-tab.c
@@ -259,6 +259,7 @@ open_vnc (VinagreVncTab *vnc_tab)
   GError     *error;
   VncDisplay *vnc = VNC_DISPLAY (vnc_tab->priv->vnc);
   VinagreTab *tab = VINAGRE_TAB (vnc_tab);
+  GtkWindow  *window = GTK_WINDOW (vinagre_tab_get_window (tab));
 
   success = TRUE;
   error = NULL;
@@ -290,12 +291,12 @@ open_vnc (VinagreVncTab *vnc_tab)
   else
     {
       if (ssh_tunnel_host && *ssh_tunnel_host)
-	if (!vinagre_vnc_tunnel_create (&host, &port_str, ssh_tunnel_host, &error))
+	if (!vinagre_vnc_tunnel_create (window, &host, &port_str, ssh_tunnel_host, &error))
 	  {
 	    success = FALSE;
 	    vinagre_utils_show_error (_("Error creating the SSH tunnel"),
 				      error ? error->message : _("Unknown reason"),
-				      GTK_WINDOW (vinagre_tab_get_window (tab)));
+				      window);
 	    goto out;
 	  }
       success = vnc_display_open_host (vnc, host, port_str);
@@ -306,7 +307,7 @@ open_vnc (VinagreVncTab *vnc_tab)
   else
     vinagre_utils_show_error (_("Error connecting to host."),
 			      error ? error->message : _("Unknown reason"),
-			      GTK_WINDOW (vinagre_tab_get_window (tab)));
+			      window);
 
 out:
   g_free (port_str);
@@ -441,128 +442,25 @@ vnc_initialized_cb (VncDisplay *vnc, VinagreVncTab *vnc_tab)
   g_signal_emit_by_name (G_OBJECT (tab), "tab-initialized");
 }
 
-typedef struct {
-  GtkWidget *uname, *pw, *button;
-} ControlOKButton;
-
-static void
-control_ok_button (GtkEditable *entry, ControlOKButton *data)
-{
-  gboolean enabled = TRUE;
-
-  if (GTK_WIDGET_VISIBLE (data->uname))
-    enabled = enabled && gtk_entry_get_text_length (GTK_ENTRY (data->uname)) > 0;
-
-  if (GTK_WIDGET_VISIBLE (data->pw))
-    enabled = enabled && gtk_entry_get_text_length (GTK_ENTRY (data->pw)) > 0;
-
-  gtk_widget_set_sensitive (data->button, enabled);
-}
-
-static gboolean
-ask_credential (VinagreVncTab *vnc_tab,
-		gboolean      need_username,
-		gboolean      need_password,
-		gchar         **username,
-		gchar         **password)
-{
-  GtkBuilder      *xml;
-  GtkWidget       *password_dialog, *host_label, *save_credential_check;
-  GtkWidget       *password_label, *username_label, *image;
-  gchar           *name;
-  int             result;
-  ControlOKButton control;
-  VinagreTab      *tab = VINAGRE_TAB (vnc_tab);
-  VinagreConnection *conn = vinagre_tab_get_conn (tab);
-
-  xml = vinagre_utils_get_builder (NULL, NULL);
-
-  password_dialog = GTK_WIDGET (gtk_builder_get_object (xml, "auth_required_dialog"));
-  gtk_window_set_transient_for (GTK_WINDOW(password_dialog),
-				GTK_WINDOW(vinagre_tab_get_window (tab)));
-
-  host_label = GTK_WIDGET (gtk_builder_get_object (xml, "host_label"));
-  name = vinagre_connection_get_best_name (conn);
-  gtk_label_set_label (GTK_LABEL (host_label), name);
-  g_free (name);
-
-  control.uname  = GTK_WIDGET (gtk_builder_get_object (xml, "username_entry"));
-  control.pw     = GTK_WIDGET (gtk_builder_get_object (xml, "password_entry"));
-  control.button = GTK_WIDGET (gtk_builder_get_object (xml, "ok_button"));
-  password_label = GTK_WIDGET (gtk_builder_get_object (xml, "password_label"));
-  username_label = GTK_WIDGET (gtk_builder_get_object (xml, "username_label"));
-  save_credential_check = GTK_WIDGET (gtk_builder_get_object (xml, "save_credential_check"));
-
-  image = gtk_image_new_from_stock (GTK_STOCK_DIALOG_AUTHENTICATION, GTK_ICON_SIZE_BUTTON);
-  gtk_button_set_image (GTK_BUTTON (control.button), image);
-
-  g_signal_connect (control.uname, "changed", G_CALLBACK (control_ok_button), &control);
-  g_signal_connect (control.pw, "changed", G_CALLBACK (control_ok_button), &control);
-
-  if (need_username)
-    {
-      if (*username)
-        gtk_entry_set_text (GTK_ENTRY (control.uname), *username);
-    }
-  else
-    {
-      gtk_widget_hide (username_label);
-      gtk_widget_hide (control.uname);
-    }
-
-  if (need_password)
-    {
-      if (*password)
-        gtk_entry_set_text (GTK_ENTRY (control.pw), *password);
-    }
-  else
-    {
-      gtk_widget_hide (password_label);
-      gtk_widget_hide (control.pw);
-    }
-
-  result = gtk_dialog_run (GTK_DIALOG (password_dialog));
-  if (result == -5)
-    {
-      g_free (*username);
-      if (gtk_entry_get_text_length (GTK_ENTRY (control.uname)) > 0)
-	*username = g_strdup (gtk_entry_get_text (GTK_ENTRY (control.uname)));
-      else
-	*username = NULL;
-
-      g_free (*password);
-      if (gtk_entry_get_text_length (GTK_ENTRY (control.pw)) > 0)
-	*password = g_strdup (gtk_entry_get_text (GTK_ENTRY (control.pw)));
-      else
-	*password = NULL;
-
-      vinagre_tab_set_save_credentials (tab,
-					gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (save_credential_check)));
-    }
-
-  gtk_widget_destroy (GTK_WIDGET (password_dialog));
-  g_object_unref (xml);
-
-  return result == -5;
-}
-
 static void
 vnc_authentication_cb (VncDisplay *vnc, GValueArray *credList, VinagreVncTab *vnc_tab)
 {
-  gchar *username, *password;
-  gboolean need_password, need_username;
+  gchar *username, *password, *host;
+  gboolean need_password, need_username, save_in_keyring;
   int i;
   VinagreTab *tab = VINAGRE_TAB (vnc_tab);
   VinagreConnection *conn = vinagre_tab_get_conn (tab);
-  VinagreWindow *window = vinagre_tab_get_window (tab);
+  GtkWindow *window = GTK_WINDOW (vinagre_tab_get_window (tab));
 
   if (credList == NULL)
     return;
 
   need_password = FALSE;
   need_username = FALSE;
+  save_in_keyring = FALSE;
   username = NULL;
   password = NULL;
+  host = NULL;
 
   for (i = 0; i < credList->n_values; i++) {
     switch (g_value_get_enum (&credList->values[i]))
@@ -596,7 +494,15 @@ vnc_authentication_cb (VncDisplay *vnc, GValueArray *credList, VinagreVncTab *vn
       vinagre_tab_find_credentials_in_keyring (tab, &username, &password);
       if ( (need_username && !username) || (need_password && !password) )
 	{
-	  if (!ask_credential (vnc_tab, need_username, need_password, &username, &password))
+	  host = vinagre_connection_get_best_name (conn);
+	  if (!vinagre_utils_ask_credential (window,
+					     "VNC",
+					     host,
+					     need_username,
+					     need_password,
+					     &username,
+					     &password,
+					     &save_in_keyring))
 	    {
 	      vinagre_tab_remove_from_notebook (tab);
 	      goto out;
@@ -615,7 +521,7 @@ vnc_authentication_cb (VncDisplay *vnc, GValueArray *credList, VinagreVncTab *vn
 	      vinagre_tab_remove_from_notebook (tab);
 	      vinagre_utils_show_error (_("Authentication error"),
 					_("A username is required in order to access this machine."),
-					GTK_WINDOW (window));
+					window);
 	      goto out;
 	    }
 	}
@@ -632,14 +538,17 @@ vnc_authentication_cb (VncDisplay *vnc, GValueArray *credList, VinagreVncTab *vn
 	      vinagre_tab_remove_from_notebook (tab);
 	      vinagre_utils_show_error (_("Authentication error"),
 					_("A password is required in order to access this machine."),
-					GTK_WINDOW (window));
+					window);
 	      goto out;
 	    }
 	}
 
+      vinagre_tab_set_save_credentials (tab, save_in_keyring);
+
 out:
       g_free (username);
       g_free (password);
+      g_free (host);
     }
 }
 
diff --git a/plugins/vnc/vinagre-vnc-tunnel.c b/plugins/vnc/vinagre-vnc-tunnel.c
index 00eb0a3..2a5fe9b 100644
--- a/plugins/vnc/vinagre-vnc-tunnel.c
+++ b/plugins/vnc/vinagre-vnc-tunnel.c
@@ -58,7 +58,11 @@ find_free_port (void)
 }
 
 gboolean
-vinagre_vnc_tunnel_create (gchar **original_host, gchar **original_port, gchar *gateway, GError **error)
+vinagre_vnc_tunnel_create (GtkWindow *parent,
+			   gchar **original_host,
+			   gchar **original_port,
+			   gchar *gateway,
+			   GError **error)
 {
   int local_port;
   gchar **tunnel_str, **command_str;
@@ -89,7 +93,8 @@ vinagre_vnc_tunnel_create (gchar **original_host, gchar **original_port, gchar *
   command_str[3] = g_strdup ("15");
   command_str[4] = NULL;
 
-  if (!vinagre_ssh_connect (gateway,
+  if (!vinagre_ssh_connect (parent,
+			    gateway,
 			    22,
 			    NULL,
 			    tunnel_str,
diff --git a/plugins/vnc/vinagre-vnc-tunnel.h b/plugins/vnc/vinagre-vnc-tunnel.h
index c9e695c..db5900b 100644
--- a/plugins/vnc/vinagre-vnc-tunnel.h
+++ b/plugins/vnc/vinagre-vnc-tunnel.h
@@ -22,7 +22,7 @@
 #ifndef __VINAGRE_VNC_TUNNEL_H__
 #define __VINAGRE_VNC_TUNNEL_H__
 
-#include <glib.h>
+#include <gtk/gtk.h>
 
 G_BEGIN_DECLS
 
@@ -34,7 +34,11 @@ typedef enum
 #define VINAGRE_VNC_TUNNEL_ERROR vinagre_vnc_tunnel_error_quark()
 GQuark vinagre_vnc_tunnel_error_quark (void);
 
-gboolean vinagre_vnc_tunnel_create (gchar **original_host, gchar **original_port, gchar *gateway, GError **error);
+gboolean vinagre_vnc_tunnel_create (GtkWindow *parent,
+				    gchar **original_host,
+				    gchar **original_port,
+				    gchar *gateway,
+				    GError **error);
 
 G_END_DECLS
 
diff --git a/vinagre/vinagre-ssh.c b/vinagre/vinagre-ssh.c
index da34e64..e26c63f 100644
--- a/vinagre/vinagre-ssh.c
+++ b/vinagre/vinagre-ssh.c
@@ -294,44 +294,9 @@ get_hostname_and_fingerprint_from_line (const gchar *buffer,
   return TRUE;
 }
 
-static gchar *
-ask_password (const gchar *user, const gchar *host)
-{
-  GtkWidget *dialog, *label, *entry, *content_area;
-  gchar *str, *result;
-
-  result = NULL;
-  dialog = gtk_dialog_new_with_buttons (_("Authentication needed"),
-                                        NULL,
-                                        GTK_DIALOG_DESTROY_WITH_PARENT | GTK_DIALOG_MODAL,
-                                        GTK_STOCK_OK, GTK_RESPONSE_ACCEPT,
-                                        GTK_STOCK_CANCEL, GTK_RESPONSE_NONE,
-                                        NULL);
-  content_area = gtk_dialog_get_content_area (GTK_DIALOG (dialog));
-
-  str = g_strdup_printf (_("Enter the SSH password for the username and host %s %s:"), user, host);
-  label = gtk_label_new (str);
-  g_free (str);
-  gtk_container_add (GTK_CONTAINER (content_area), label);
-
-  entry = gtk_entry_new ();
-  gtk_entry_set_visibility (GTK_ENTRY (entry), FALSE);
-  gtk_container_add (GTK_CONTAINER (content_area), entry);
-
-  gtk_widget_show_all (dialog);
-  if (gtk_dialog_run (GTK_DIALOG (dialog)) == GTK_RESPONSE_ACCEPT)
-    {
-      str = (gchar *)gtk_entry_get_text (GTK_ENTRY (entry));
-      if (str && *str)
-        result = g_strdup (str);
-    }
-
-  gtk_widget_destroy (dialog);
-  return result;
-}
-
 static gboolean
-handle_login (const   gchar *host,
+handle_login (GtkWindow *parent,
+	      const   gchar *host,
 	      int     port,
 	      const   gchar *user,
 	      int     tty_fd,
@@ -347,17 +312,19 @@ handle_login (const   gchar *host,
   int prompt_fd;
   char buffer[1024];
   gsize len;
-  gboolean aborted = FALSE;
-  gboolean ret_val;
-  char *password = NULL;
+  gboolean ret_val, aborted, save_in_keyring;
   gsize bytes_written;
-  gboolean password_in_keyring = FALSE;
-  const gchar *authtype = NULL;
-  gchar *object = NULL;
+  const gchar *authtype;
+  gchar *object, *password;
   GnomeKeyringResult result;
   GList *matches;
   GnomeKeyringNetworkPasswordData *found_item;
-  
+
+  object = password = NULL;
+  authtype = NULL;
+  ret_val = TRUE;
+  aborted = save_in_keyring = FALSE;
+
   if (vendor == SSH_VENDOR_SSH) 
     prompt_fd = stderr_fd;
   else
@@ -367,7 +334,6 @@ handle_login (const   gchar *host,
   stdout_stream = g_unix_input_stream_new (stdout_fd, FALSE);
   reply_stream = g_unix_output_stream_new (tty_fd, FALSE);
 
-  ret_val = TRUE;
   while (1)
     {
       FD_ZERO (&ifds);
@@ -426,8 +392,11 @@ handle_login (const   gchar *host,
 
       if (strncmp (buffer, "\r\n", 2) == 0)
         continue;
-        
-      else if (g_str_has_suffix (buffer, "password: ") ||
+
+      g_free (password);
+      password = NULL;
+
+      if (g_str_has_suffix (buffer, "password: ") ||
           g_str_has_suffix (buffer, "Password: ") ||
           g_str_has_suffix (buffer, "Password:")  ||
           g_str_has_prefix (buffer, "Password for ") ||
@@ -450,8 +419,20 @@ handle_login (const   gchar *host,
 	  /* If the password was not found in keyring then ask for it */
 	  if (result != GNOME_KEYRING_RESULT_OK || matches == NULL || matches->data == NULL)
 	    {
-	      password = ask_password (user, host);
-              if (!password)
+	      gchar *full_host;
+	      gboolean res;
+
+	      full_host = g_strjoin ("@", user, host, NULL);
+	      res = vinagre_utils_ask_credential (parent,
+						  "SSH",
+						  full_host,
+						  FALSE,
+						  TRUE,
+						  NULL,
+						  &password,
+						  &save_in_keyring);
+	      g_free (full_host);
+              if (!res)
                 {
                   g_set_error_literal (error,
 				       VINAGRE_SSH_ERROR,
@@ -465,7 +446,6 @@ handle_login (const   gchar *host,
 	    {
 	      found_item = (GnomeKeyringNetworkPasswordData *) matches->data;
 	      password = g_strdup (found_item->password);
-	      password_in_keyring = TRUE;
 	      gnome_keyring_network_password_list_free (matches);
 	    }
 
@@ -550,25 +530,31 @@ handle_login (const   gchar *host,
 	  ret_val = FALSE;
 	  break;
         }
-      g_free (password);
     }
   
-  if (ret_val)
+  if (ret_val && save_in_keyring)
     {
       /* Login succeed, save password in keyring */
-/*      g_vfs_keyring_save_password (op_backend->user,
-                                   op_backend->host,
-                                   NULL,
-                                   "sftp",
-				   object,
-				   authtype,
-				   op_backend->port != -1 ?
-				   op_backend->port
-				   :
-				   0, 
-                                   new_password,
-                                   password_save);
-*/
+      GnomeKeyringResult result;
+      guint32            keyring_item_id;
+
+      result = gnome_keyring_set_network_password_sync (
+                NULL,         /* default keyring */
+                user,         /* user            */
+                NULL,         /* domain          */
+                host,         /* server          */
+                object,       /* object          */
+                "ssh",        /* protocol        */
+                authtype,     /* authtype        */
+                port,         /* port            */
+                password,     /* password        */
+                &keyring_item_id);
+
+      if (result != GNOME_KEYRING_RESULT_OK)
+        vinagre_utils_show_error (_("Error saving the credentials on the keyring."),
+				  gnome_keyring_result_to_message (result),
+				  parent);
+
     }
 
   g_free (object);
@@ -662,7 +648,8 @@ look_for_stderr_errors (GDataInputStream *error_stream, GError **error)
 }
 
 gboolean
-vinagre_ssh_connect (const gchar *hostname,
+vinagre_ssh_connect (GtkWindow *parent,
+		     const gchar *hostname,
 		     gint port,
 		     const gchar *username,
 		     gchar **extra_arguments,
@@ -711,7 +698,7 @@ vinagre_ssh_connect (const gchar *hostname,
   if (tty_fd == -1)
     res = wait_for_reply (stdout_fd, error);
   else
-    res = handle_login (host, port, user, tty_fd, stdout_fd, stderr_fd, error);
+    res = handle_login (parent, host, port, user, tty_fd, stdout_fd, stderr_fd, error);
 
   g_strfreev (args);
   g_free (user);
diff --git a/vinagre/vinagre-ssh.h b/vinagre/vinagre-ssh.h
index 277516a..ef4229c 100644
--- a/vinagre/vinagre-ssh.h
+++ b/vinagre/vinagre-ssh.h
@@ -25,7 +25,7 @@
 #define VINAGRE_SSH_CHECK "ViNagRE_CHEck"
 #define VINAGRE_SSH_CHECK_LENGTH 13
 
-#include <glib.h>
+#include <gtk/gtk.h>
 
 G_BEGIN_DECLS
 
@@ -43,7 +43,8 @@ typedef enum
 #define VINAGRE_SSH_ERROR vinagre_ssh_error_quark()
 GQuark vinagre_ssh_error_quark (void);
 
-gboolean vinagre_ssh_connect (const gchar *hostname,
+gboolean vinagre_ssh_connect (GtkWindow *parent,
+			      const gchar *hostname,
 			      gint port,
 			      const gchar *username,
 			      gchar **extra_arguments,
diff --git a/vinagre/vinagre-utils.c b/vinagre/vinagre-utils.c
index 3469312..ad2130e 100644
--- a/vinagre/vinagre-utils.c
+++ b/vinagre/vinagre-utils.c
@@ -605,7 +605,128 @@ vinagre_utils_ask_question (GtkWindow  *parent,
 static void
 shit (void)
 {
-  vinagre_ssh_connect (NULL, -1, NULL, NULL, NULL, NULL, NULL);
+  vinagre_ssh_connect (NULL, NULL, -1, NULL, NULL, NULL, NULL, NULL);
+}
+
+typedef struct {
+  GtkWidget *uname, *pw, *button;
+} ControlOKButton;
+
+static void
+control_ok_button (GtkEditable *entry, ControlOKButton *data)
+{
+  gboolean enabled = TRUE;
+
+  if (GTK_WIDGET_VISIBLE (data->uname))
+    enabled = enabled && gtk_entry_get_text_length (GTK_ENTRY (data->uname)) > 0;
+
+  if (GTK_WIDGET_VISIBLE (data->pw))
+    enabled = enabled && gtk_entry_get_text_length (GTK_ENTRY (data->pw)) > 0;
+
+  gtk_widget_set_sensitive (data->button, enabled);
+}
+
+gboolean
+vinagre_utils_ask_credential (GtkWindow *parent,
+			      gchar *kind,
+			      gchar *host,
+			      gboolean need_username,
+			      gboolean need_password,
+			      gchar **username,
+			      gchar **password,
+			      gboolean *save_in_keyring)
+{
+  GtkBuilder      *xml;
+  GtkWidget       *password_dialog, *save_credential_check;
+  GtkWidget       *password_label, *username_label, *image;
+  int             result;
+  ControlOKButton control;
+
+  xml = vinagre_utils_get_builder (NULL, NULL);
+
+  password_dialog = GTK_WIDGET (gtk_builder_get_object (xml, "auth_required_dialog"));
+  if (parent)
+    gtk_window_set_transient_for (GTK_WINDOW (password_dialog), parent);
+
+  if (kind)
+    {
+       /* Translators: %s is a protocol, like VNC or SSH */
+       gchar *str = g_strdup_printf ("%s authentication is required", kind);
+       GtkWidget *auth_label = GTK_WIDGET (gtk_builder_get_object (xml, "auth_required_label"));
+       gtk_label_set_label (GTK_LABEL (auth_label), str);
+       g_free (str);
+    }
+
+  if (host)
+    {
+       GtkWidget *host_label = GTK_WIDGET (gtk_builder_get_object (xml, "host_label"));
+       gtk_label_set_label (GTK_LABEL (host_label), host);
+    }
+
+  control.uname  = GTK_WIDGET (gtk_builder_get_object (xml, "username_entry"));
+  control.pw     = GTK_WIDGET (gtk_builder_get_object (xml, "password_entry"));
+  control.button = GTK_WIDGET (gtk_builder_get_object (xml, "ok_button"));
+  password_label = GTK_WIDGET (gtk_builder_get_object (xml, "password_label"));
+  username_label = GTK_WIDGET (gtk_builder_get_object (xml, "username_label"));
+  save_credential_check = GTK_WIDGET (gtk_builder_get_object (xml, "save_credential_check"));
+
+  image = gtk_image_new_from_stock (GTK_STOCK_DIALOG_AUTHENTICATION, GTK_ICON_SIZE_BUTTON);
+  gtk_button_set_image (GTK_BUTTON (control.button), image);
+
+  g_signal_connect (control.uname, "changed", G_CALLBACK (control_ok_button), &control);
+  g_signal_connect (control.pw, "changed", G_CALLBACK (control_ok_button), &control);
+
+  if (need_username)
+    {
+      if (username && *username)
+        gtk_entry_set_text (GTK_ENTRY (control.uname), *username);
+    }
+  else
+    {
+      gtk_widget_hide (username_label);
+      gtk_widget_hide (control.uname);
+    }
+
+  if (need_password)
+    {
+      if (password && *password)
+        gtk_entry_set_text (GTK_ENTRY (control.pw), *password);
+    }
+  else
+    {
+      gtk_widget_hide (password_label);
+      gtk_widget_hide (control.pw);
+    }
+
+  result = gtk_dialog_run (GTK_DIALOG (password_dialog));
+  if (result == -5)
+    {
+      if (username)
+        {
+          g_free (*username);
+          if (gtk_entry_get_text_length (GTK_ENTRY (control.uname)) > 0)
+	    *username = g_strdup (gtk_entry_get_text (GTK_ENTRY (control.uname)));
+          else
+	    *username = NULL;
+	}
+
+      if (password)
+        {
+          g_free (*password);
+          if (gtk_entry_get_text_length (GTK_ENTRY (control.pw)) > 0)
+	    *password = g_strdup (gtk_entry_get_text (GTK_ENTRY (control.pw)));
+          else
+	    *password = NULL;
+	}
+
+      if (save_in_keyring)
+        *save_in_keyring = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (save_credential_check));
+    }
+
+  gtk_widget_destroy (GTK_WIDGET (password_dialog));
+  g_object_unref (xml);
+
+  return result == -5;
 }
 
 /* vim: set ts=8: */
diff --git a/vinagre/vinagre-utils.h b/vinagre/vinagre-utils.h
index 69b119e..7e84f8d 100644
--- a/vinagre/vinagre-utils.h
+++ b/vinagre/vinagre-utils.h
@@ -71,5 +71,15 @@ gboolean	vinagre_utils_ask_question		(GtkWindow  *parent,
 							 const char *message,
 							 char       **choices,
 							 int        *choice);
+
+gboolean	vinagre_utils_ask_credential		(GtkWindow *parent,
+							 gchar *kind,
+							 gchar *host,
+							 gboolean need_username,
+							 gboolean need_password,
+							 gchar **username,
+							 gchar **password,
+							 gboolean *save_in_keyring);
+
 #endif  /* __VINAGRE_UTILS_H__  */
 /* vim: set ts=8: */



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