vinagre r510 - in trunk: . src



Author: jwendell
Date: Fri Nov 14 17:17:00 2008
New Revision: 510
URL: http://svn.gnome.org/viewvc/vinagre?rev=510&view=rev

Log:
2008-11-14  Jonh Wendell <jwendell gnome org>

	* src/vinagre-connection.[ch],
	* src/vinagre-tab.c: Better parse a .vnc file. Closes #559525.



Modified:
   trunk/ChangeLog
   trunk/src/vinagre-connection.c
   trunk/src/vinagre-connection.h
   trunk/src/vinagre-tab.c

Modified: trunk/src/vinagre-connection.c
==============================================================================
--- trunk/src/vinagre-connection.c	(original)
+++ trunk/src/vinagre-connection.c	Fri Nov 14 17:17:00 2008
@@ -36,6 +36,7 @@
   gchar *username;
   gchar *password;
   gchar *desktop_name;
+  gint   shared;
   gboolean view_only;
   gboolean scaling;
   gboolean fullscreen;
@@ -55,7 +56,8 @@
   PROP_ICON,
   PROP_VIEW_ONLY,
   PROP_SCALING,
-  PROP_FULLSCREEN
+  PROP_FULLSCREEN,
+  PROP_SHARED,
 };
 
 gint   vinagre_connection_default_port [VINAGRE_CONNECTION_PROTOCOL_INVALID-1] = {5900, 3389};
@@ -79,6 +81,7 @@
   conn->priv->view_only = FALSE;
   conn->priv->scaling = FALSE;
   conn->priv->fullscreen = FALSE;
+  conn->priv->shared = -1;
 }
 
 static void
@@ -155,6 +158,10 @@
 	vinagre_connection_set_fullscreen (conn, g_value_get_boolean (value));
 	break;
 
+      case PROP_SHARED:
+	vinagre_connection_set_shared (conn, g_value_get_int (value));
+	break;
+
       default:
 	G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
 	break;
@@ -221,6 +228,10 @@
 	g_value_set_boolean (value, conn->priv->fullscreen);
 	break;
 
+      case PROP_SHARED:
+	g_value_set_int (value, conn->priv->shared);
+	break;
+
       default:
 	G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
 	break;
@@ -381,6 +392,20 @@
                                                         G_PARAM_STATIC_NAME |
                                                         G_PARAM_STATIC_BLURB));
 
+  g_object_class_install_property (object_class,
+                                   PROP_PORT,
+                                   g_param_spec_int ("shared",
+                                                     "shared flag",
+	                                              "if the server should allow more than one client connected",
+                                                      -1,
+                                                      1,
+                                                      -1,
+	                                              G_PARAM_READWRITE |
+                                                      G_PARAM_CONSTRUCT |
+                                                      G_PARAM_STATIC_NICK |
+                                                      G_PARAM_STATIC_NAME |
+                                                      G_PARAM_STATIC_BLURB));
+
 }
 
 VinagreConnection *
@@ -525,6 +550,23 @@
   return NULL;
 }
 
+void
+vinagre_connection_set_shared (VinagreConnection *conn,
+			       gint value)
+{
+  g_return_if_fail (VINAGRE_IS_CONNECTION (conn));
+  g_return_if_fail (value >=0 && value <=1);
+
+  conn->priv->shared = value;
+}
+gint
+vinagre_connection_get_shared (VinagreConnection *conn)
+{
+  g_return_val_if_fail (VINAGRE_IS_CONNECTION (conn), -1);
+
+  return conn->priv->shared;
+}
+
 VinagreConnection *
 vinagre_connection_clone (VinagreConnection *conn)
 {
@@ -627,16 +669,20 @@
 vinagre_connection_new_from_file (const gchar *uri, gchar **error_msg)
 {
   GKeyFile          *file;
-  GError            *error = NULL;
+  GError            *error;
   gboolean           loaded;
-  VinagreConnection *conn = NULL;
-  gchar             *host = NULL;
+  VinagreConnection *conn;
+  gchar             *host, *actual_host, *data;
   gint               port;
   int                file_size;
-  char              *data = NULL;
   GFile             *file_a;
 
   *error_msg = NULL;
+  host = NULL;
+  data = NULL;
+  conn = NULL;
+  error = NULL;
+  file = NULL;
 
   file_a = g_file_new_for_commandline_arg (uri);
   loaded = g_file_load_contents (file_a,
@@ -652,12 +698,10 @@
 	  *error_msg = g_strdup (error->message);
 	  g_error_free (error);
 	}
+      else
+	*error_msg = g_strdup (_("Could not open the file."));
 
-      if (data)
-	g_free (data);
-
-      g_object_unref (file_a);
-      return NULL;
+      goto the_end;
     }
 
   file = g_key_file_new ();
@@ -666,38 +710,71 @@
 				      file_size,
 				      G_KEY_FILE_NONE,
 				      &error);
-  if (loaded)
-    {
-      host = g_key_file_get_string (file, "connection", "host", NULL);
-      port = g_key_file_get_integer (file, "connection", "port", NULL);
-      if (host)
-	{
-	  conn = vinagre_bookmarks_exists (vinagre_bookmarks_get_default (),
-                                           host,
-                                           port);
-	  if (!conn)
-	    {
-	      conn = vinagre_connection_new ();
-	      vinagre_connection_set_host (conn, host);
-	      vinagre_connection_set_port (conn, port);
-	    }
-	  g_free (host);
-	}
-    }
-  else
+  if (!loaded)
     {
       if (error)
 	{
 	  *error_msg = g_strdup (error->message);
 	  g_error_free (error);
 	}
+      else
+	*error_msg = g_strdup (_("Could not parse the file."));
+
+      goto the_end;
     }
 
-  if (data)
-    g_free (data);
+  host = g_key_file_get_string (file, "connection", "host", NULL);
+  port = g_key_file_get_integer (file, "connection", "port", NULL);
+  if (host)
+    {
+      if (!port)
+	{
+	  if (!vinagre_connection_split_string (host, &actual_host, &port, error_msg))
+	    goto the_end;
+
+	  g_free (host);
+	  host = actual_host;
+	}
+
+      conn = vinagre_bookmarks_exists (vinagre_bookmarks_get_default (), host, port);
+      if (!conn)
+	{
+	  gchar *username, *password;
+	  gint shared;
+	  GError *e = NULL;
+
+	  conn = vinagre_connection_new ();
+	  vinagre_connection_set_host (conn, host);
+	  vinagre_connection_set_port (conn, port);
+
+	  username = g_key_file_get_string  (file, "connection", "username", NULL);
+	  vinagre_connection_set_username (conn, username);
+	  g_free (username);
+
+	  password = g_key_file_get_string  (file, "connection", "password", NULL);
+	  vinagre_connection_set_password (conn, password);
+	  g_free (password);
+
+	  shared = g_key_file_get_integer (file, "options", "shared", &e);
+	  if (e)
+	    g_error_free (e);
+	  else
+	    if (shared == 0 || shared == 1)
+	      vinagre_connection_set_shared (conn, shared);
+	    else
+	      g_message (_("Bad value for 'shared' flag: %d. It is supposed to be 0 or 1. Ignoring it."), shared);
+	}
+
+      g_free (host);
+    }
+  else
+    *error_msg = g_strdup (_("Could not find the host address in the file."));
 
-  g_key_file_free (file);
+the_end:
+  g_free (data);
   g_object_unref (file_a);
+  if (file)
+    g_key_file_free (file);
 
   return conn;
 }

Modified: trunk/src/vinagre-connection.h
==============================================================================
--- trunk/src/vinagre-connection.h	(original)
+++ trunk/src/vinagre-connection.h	Fri Nov 14 17:17:00 2008
@@ -108,6 +108,10 @@
 void		    vinagre_connection_set_fullscreen	(VinagreConnection *conn,
 							 gboolean value);
 
+gint		    vinagre_connection_get_shared	(VinagreConnection *conn);
+void		    vinagre_connection_set_shared	(VinagreConnection *conn,
+							 gint value);
+
 gboolean	    vinagre_connection_split_string	(const gchar *uri,
 							 gchar **host,
 							 gint *port,

Modified: trunk/src/vinagre-tab.c
==============================================================================
--- trunk/src/vinagre-tab.c	(original)
+++ trunk/src/vinagre-tab.c	Fri Nov 14 17:17:00 2008
@@ -289,12 +289,21 @@
 open_vnc (VinagreTab *tab)
 {
   gchar *port;
+  gint  shared;
 
   vnc_display_set_force_size (VNC_DISPLAY(tab->priv->vnc),
 			      !vinagre_connection_get_scaling (tab->priv->conn));
 
   port = g_strdup_printf ("%d", vinagre_connection_get_port (tab->priv->conn));
 
+  shared = vinagre_connection_get_shared (tab->priv->conn);
+  if (shared == -1)
+    g_object_get (vinagre_prefs_get_default (),
+		  "shared-flag", &shared,
+		  NULL);
+  vnc_display_set_shared_flag (VNC_DISPLAY (tab->priv->vnc),
+			       shared);
+
   if (vnc_display_open_host (VNC_DISPLAY(tab->priv->vnc), vinagre_connection_get_host (tab->priv->conn), port))
     gtk_widget_grab_focus (tab->priv->vnc);
   else
@@ -637,10 +646,20 @@
     switch (g_value_get_enum (&credList->values[i]))
       {
 	case VNC_DISPLAY_CREDENTIAL_USERNAME:
+	  if (vinagre_connection_get_username (tab->priv->conn))
+	    {
+	      vnc_display_set_credential (vnc, VNC_DISPLAY_CREDENTIAL_USERNAME, vinagre_connection_get_username (tab->priv->conn));
+	      break;
+	    }
 	  need_username= TRUE;
 	  break;
 
 	case VNC_DISPLAY_CREDENTIAL_PASSWORD:
+	  if (vinagre_connection_get_password (tab->priv->conn))
+	    {
+	      vnc_display_set_credential (vnc, VNC_DISPLAY_CREDENTIAL_PASSWORD, vinagre_connection_get_password (tab->priv->conn));
+	      break;
+	    }
 	  need_password = TRUE;
 	  break;
 
@@ -839,8 +858,7 @@
 static void
 vinagre_tab_init (VinagreTab *tab)
 {
-  GtkWidget     *viewport;
-  gboolean       shared;
+  GtkWidget *viewport;
 
   tab->priv = VINAGRE_TAB_GET_PRIVATE (tab);
   tab->priv->save_credential = FALSE;
@@ -865,12 +883,6 @@
   viewport = gtk_bin_get_child (GTK_BIN (tab->priv->scroll));
   gtk_viewport_set_shadow_type(GTK_VIEWPORT (viewport), GTK_SHADOW_NONE);
 
-  g_object_get (vinagre_prefs_get_default (),
-		"shared-flag", &shared,
-		NULL);
-  vnc_display_set_shared_flag (VNC_DISPLAY (tab->priv->vnc),
-			       shared);
-
   g_signal_connect (tab->priv->vnc,
 		    "vnc-connected",
 		    G_CALLBACK (vnc_connected_cb),



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