[vinagre] Allow to customize desktop size for RDP protocol



commit 01eadc757024cb8c3d3047f0dc912df2f4ba564f
Author: Marek Kasik <mkasik redhat com>
Date:   Tue May 14 17:10:48 2013 +0200

    Allow to customize desktop size for RDP protocol
    
    Add spin buttons for specifying of width and height
    of remote desktop together with corresponding
    properties of VinagreConnection.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=628006

 plugins/rdp/vinagre-rdp-connection.c |   31 +++++++++++-
 plugins/rdp/vinagre-rdp-plugin.c     |   60 ++++++++++++++++++----
 plugins/rdp/vinagre-rdp-tab.c        |    7 ++-
 vinagre/vinagre-connection.c         |   91 +++++++++++++++++++++++++++++++++-
 vinagre/vinagre-connection.h         |    8 +++
 5 files changed, 183 insertions(+), 14 deletions(-)
---
diff --git a/plugins/rdp/vinagre-rdp-connection.c b/plugins/rdp/vinagre-rdp-connection.c
index dfa9399..99182c7 100644
--- a/plugins/rdp/vinagre-rdp-connection.c
+++ b/plugins/rdp/vinagre-rdp-connection.c
@@ -58,7 +58,8 @@ rdp_parse_item (VinagreConnection *conn, xmlNode *root)
 static void
 rdp_parse_options_widget (VinagreConnection *conn, GtkWidget *widget)
 {
-  GtkWidget *u_entry;
+  GtkWidget *u_entry, *spin_button;
+  guint      width, height;
 
   u_entry = g_object_get_data (G_OBJECT (widget), "username_entry");
   if (!u_entry)
@@ -72,6 +73,34 @@ rdp_parse_options_widget (VinagreConnection *conn, GtkWidget *widget)
   g_object_set (conn,
                "username", gtk_entry_get_text (GTK_ENTRY (u_entry)),
                NULL);
+
+
+  spin_button = g_object_get_data (G_OBJECT (widget), "width_spin_button");
+  if (!spin_button)
+    {
+      g_warning ("Wrong widget passed to rdp_parse_options_widget()");
+      return;
+    }
+
+  width = (guint) gtk_spin_button_get_value (GTK_SPIN_BUTTON (spin_button));
+
+  vinagre_cache_prefs_set_integer  ("rdp-connection", "width", width);
+
+  vinagre_connection_set_width (conn, width);
+
+
+  spin_button = g_object_get_data (G_OBJECT (widget), "height_spin_button");
+  if (!spin_button)
+    {
+      g_warning ("Wrong widget passed to rdp_parse_options_widget()");
+      return;
+    }
+
+  height = (guint) gtk_spin_button_get_value (GTK_SPIN_BUTTON (spin_button));
+
+  vinagre_cache_prefs_set_integer  ("rdp-connection", "height", height);
+
+  vinagre_connection_set_height (conn, height);
 }
 
 static void
diff --git a/plugins/rdp/vinagre-rdp-plugin.c b/plugins/rdp/vinagre-rdp-plugin.c
index 41d7cd0..149f7fa 100644
--- a/plugins/rdp/vinagre-rdp-plugin.c
+++ b/plugins/rdp/vinagre-rdp-plugin.c
@@ -32,6 +32,11 @@
 #include "vinagre-rdp-connection.h"
 #include "vinagre-rdp-tab.h"
 
+#define DEFAULT_WIDTH   800
+#define DEFAULT_HEIGHT  600
+#define MIN_SIZE          1
+#define MAX_SIZE       8192
+
 void rdp_register_types (void);
 static void vinagre_rdp_protocol_iface_init (VinagreProtocolInterface *iface);
 
@@ -89,28 +94,30 @@ vinagre_rdp_plugin_init (VinagreRdpPlugin *plugin)
 static GtkWidget *
 impl_get_connect_widget (VinagreProtocol *plugin, VinagreConnection *conn)
 {
-  GtkWidget *box, *label, *u_box, *u_entry;
+  GtkWidget *grid, *label, *u_entry, *spin_button;
   gchar     *str;
 
-  box = gtk_box_new (GTK_ORIENTATION_VERTICAL, 6);
+  grid = gtk_grid_new ();
+  gtk_grid_set_row_spacing (GTK_GRID (grid), 6);
+  gtk_grid_set_column_spacing (GTK_GRID (grid), 6);
 
   str = g_strdup_printf ("<b>%s</b>", _("RDP Options"));
   label = gtk_label_new (str);
   g_free (str);
   gtk_label_set_use_markup (GTK_LABEL (label), TRUE);
   gtk_misc_set_alignment (GTK_MISC (label), 0, 0.5);
-  gtk_container_add (GTK_CONTAINER (box), label);
-
-  u_box = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 6);
+  gtk_grid_attach (GTK_GRID (grid), label, 0, 0, 1, 1);
 
   label = gtk_label_new_with_mnemonic (_("_Username:"));
-  gtk_box_pack_start (GTK_BOX (u_box), label, FALSE, FALSE, 0);
+  gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
+  gtk_grid_attach (GTK_GRID (grid), label, 0, 1, 1, 1);
+  gtk_widget_set_margin_left (label, 12);
 
   u_entry = gtk_entry_new ();
   /* Translators: This is the tooltip for the username field in a RDP connection */
   gtk_widget_set_tooltip_text (u_entry, _("Optional. If blank, your username will be used. Also, it can be 
supplied in the Host field above, in the form username hostname "));
-  g_object_set_data (G_OBJECT (box), "username_entry", u_entry);
-  gtk_container_add (GTK_CONTAINER (u_box), u_entry);
+  g_object_set_data (G_OBJECT (grid), "username_entry", u_entry);
+  gtk_grid_attach (GTK_GRID (grid), u_entry, 1, 1, 1, 1);
   gtk_label_set_mnemonic_widget (GTK_LABEL (label), u_entry);
   str = g_strdup (VINAGRE_IS_CONNECTION (conn) ?
                  vinagre_connection_get_username (conn) :
@@ -119,9 +126,40 @@ impl_get_connect_widget (VinagreProtocol *plugin, VinagreConnection *conn)
   gtk_entry_set_activates_default (GTK_ENTRY (u_entry), TRUE);
   g_free (str);
 
-  gtk_widget_set_margin_left (u_box, 12);
-  gtk_container_add (GTK_CONTAINER (box), u_box);
-  return box;
+
+  /* Host width */
+  label = gtk_label_new_with_mnemonic (_("_Width:"));
+  gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
+  gtk_grid_attach (GTK_GRID (grid), label, 0, 2, 1, 1);
+  gtk_widget_set_margin_left (label, 12);
+
+  spin_button = gtk_spin_button_new_with_range (MIN_SIZE, MAX_SIZE, 1);
+  /* Translators: This is the tooltip for the width field in a RDP connection */
+  gtk_widget_set_tooltip_text (spin_button, _("Set width of the remote desktop"));
+  gtk_spin_button_set_value (GTK_SPIN_BUTTON (spin_button), DEFAULT_WIDTH);
+  g_object_set_data (G_OBJECT (grid), "width_spin_button", spin_button);
+  gtk_grid_attach (GTK_GRID (grid), spin_button, 1, 2, 1, 1);
+  gtk_label_set_mnemonic_widget (GTK_LABEL (label), spin_button);
+  gtk_entry_set_activates_default (GTK_ENTRY (spin_button), TRUE);
+
+
+  /* Host height */
+  label = gtk_label_new_with_mnemonic (_("_Height:"));
+  gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
+  gtk_grid_attach (GTK_GRID (grid), label, 0, 3, 1, 1);
+  gtk_widget_set_margin_left (label, 12);
+
+  spin_button = gtk_spin_button_new_with_range (MIN_SIZE, MAX_SIZE, 1);
+  /* Translators: This is the tooltip for the height field in a RDP connection */
+  gtk_widget_set_tooltip_text (spin_button, _("Set height of the remote desktop"));
+  gtk_spin_button_set_value (GTK_SPIN_BUTTON (spin_button), DEFAULT_HEIGHT);
+  g_object_set_data (G_OBJECT (grid), "height_spin_button", spin_button);
+  gtk_grid_attach (GTK_GRID (grid), spin_button, 1, 3, 1, 1);
+  gtk_label_set_mnemonic_widget (GTK_LABEL (label), spin_button);
+  gtk_entry_set_activates_default (GTK_ENTRY (spin_button), TRUE);
+
+
+  return grid;
 }
 
 static void
diff --git a/plugins/rdp/vinagre-rdp-tab.c b/plugins/rdp/vinagre-rdp-tab.c
index 389b678..1dca538 100644
--- a/plugins/rdp/vinagre-rdp-tab.c
+++ b/plugins/rdp/vinagre-rdp-tab.c
@@ -90,7 +90,7 @@ delay_connect (GObject *object)
   username = vinagre_connection_get_username (conn);
   i = 0;
 
-  arg = g_new (gchar *, 9);
+  arg = g_new (gchar *, 11);
   arg[i++] = g_strdup ("rdesktop");
 
   arg[i++] = g_strdup ("-K");
@@ -98,6 +98,11 @@ delay_connect (GObject *object)
   if (vinagre_connection_get_fullscreen (conn))
     arg[i++] = g_strdup ("-f");
 
+  arg[i++] = g_strdup ("-g");
+  arg[i++] = g_strdup_printf ("%dx%d",
+                             vinagre_connection_get_width (conn),
+                             vinagre_connection_get_height (conn));
+
   arg[i++] = g_strdup ("-X");
   arg[i++] = g_strdup_printf ("%d", (int)gtk_socket_get_id (GTK_SOCKET (rdp_tab->priv->box)));
 
diff --git a/vinagre/vinagre-connection.c b/vinagre/vinagre-connection.c
index 60a9c1b..7a39177 100644
--- a/vinagre/vinagre-connection.c
+++ b/vinagre/vinagre-connection.c
@@ -29,6 +29,11 @@
 #include "vinagre-plugins-engine.h"
 #include "vinagre-vala.h"
 
+#define DEFAULT_WIDTH   800
+#define DEFAULT_HEIGHT  600
+#define MIN_SIZE          1
+#define MAX_SIZE       8192
+
 struct _VinagreConnectionPrivate
 {
   gchar *protocol;
@@ -38,6 +43,8 @@ struct _VinagreConnectionPrivate
   gchar *password;
   gchar *name;
   gboolean fullscreen;
+  guint  width;
+  guint  height;
 };
 
 enum
@@ -50,7 +57,9 @@ enum
   PROP_PASSWORD,
   PROP_NAME,
   PROP_BEST_NAME,
-  PROP_FULLSCREEN
+  PROP_FULLSCREEN,
+  PROP_WIDTH,
+  PROP_HEIGHT
 };
 
 #define VINAGRE_CONNECTION_PRIVATE(o)  (G_TYPE_INSTANCE_GET_PRIVATE ((o), VINAGRE_TYPE_CONNECTION, 
VinagreConnectionPrivate))
@@ -68,6 +77,8 @@ vinagre_connection_init (VinagreConnection *conn)
   conn->priv->username = NULL;
   conn->priv->name = NULL;
   conn->priv->fullscreen = FALSE;
+  conn->priv->width = DEFAULT_WIDTH;
+  conn->priv->height = DEFAULT_HEIGHT;
 }
 
 static void
@@ -123,6 +134,14 @@ vinagre_connection_set_property (GObject *object, guint prop_id, const GValue *v
        vinagre_connection_set_name (conn, g_value_get_string (value));
        break;
 
+      case PROP_WIDTH:
+       vinagre_connection_set_width (conn, g_value_get_uint (value));
+       break;
+
+      case PROP_HEIGHT:
+       vinagre_connection_set_height (conn, g_value_get_uint (value));
+       break;
+
       default:
        G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
        break;
@@ -173,6 +192,14 @@ vinagre_connection_get_property (GObject *object, guint prop_id, GValue *value,
        g_value_set_string (value, vinagre_connection_get_best_name (conn));
        break;
 
+      case PROP_WIDTH:
+       g_value_set_uint (value, conn->priv->width);
+       break;
+
+      case PROP_HEIGHT:
+       g_value_set_uint (value, conn->priv->height);
+       break;
+
       default:
        G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
        break;
@@ -189,6 +216,8 @@ default_fill_writer (VinagreConnection *conn, xmlTextWriter *writer)
   xmlTextWriterWriteElement (writer, BAD_CAST "username", BAD_CAST (conn->priv->username ? 
conn->priv->username : ""));
   xmlTextWriterWriteFormatElement (writer, BAD_CAST "port", "%d", conn->priv->port);
   xmlTextWriterWriteFormatElement (writer, BAD_CAST "fullscreen", "%d", conn->priv->fullscreen);
+  xmlTextWriterWriteFormatElement (writer, BAD_CAST "width", "%d", conn->priv->width);
+  xmlTextWriterWriteFormatElement (writer, BAD_CAST "height", "%d", conn->priv->height);
 }
 
 static void
@@ -211,6 +240,10 @@ default_parse_item (VinagreConnection *conn, xmlNode *root)
        vinagre_connection_set_port (conn, atoi ((const char *)s_value));
       else if (!xmlStrcmp(curr->name, BAD_CAST "fullscreen"))
        vinagre_connection_set_fullscreen (conn, vinagre_utils_parse_boolean ((const gchar *)s_value));
+      else if (!xmlStrcmp(curr->name, BAD_CAST "width"))
+       vinagre_connection_set_width (conn, atoi ((const char *)s_value));
+      else if (!xmlStrcmp(curr->name, BAD_CAST "height"))
+       vinagre_connection_set_height (conn, atoi ((const char *)s_value));
 
       xmlFree (s_value);
     }
@@ -347,6 +380,30 @@ vinagre_connection_class_init (VinagreConnectionClass *klass)
                                                         G_PARAM_STATIC_NAME |
                                                         G_PARAM_STATIC_BLURB));
 
+  g_object_class_install_property (object_class,
+                                   PROP_WIDTH,
+                                   g_param_spec_uint ("width",
+                                                      "width",
+                                                      "width of screen",
+                                                       MIN_SIZE,
+                                                       MAX_SIZE,
+                                                       DEFAULT_WIDTH,
+                                                       G_PARAM_READWRITE |
+                                                       G_PARAM_CONSTRUCT |
+                                                       G_PARAM_STATIC_STRINGS));
+
+  g_object_class_install_property (object_class,
+                                   PROP_HEIGHT,
+                                   g_param_spec_uint ("height",
+                                                      "height",
+                                                      "height of screen",
+                                                       MIN_SIZE,
+                                                       MAX_SIZE,
+                                                       DEFAULT_HEIGHT,
+                                                       G_PARAM_READWRITE |
+                                                       G_PARAM_CONSTRUCT |
+                                                       G_PARAM_STATIC_STRINGS));
+
 }
 
 void
@@ -469,6 +526,38 @@ vinagre_connection_get_name (VinagreConnection *conn)
   return conn->priv->name;
 }
 
+void
+vinagre_connection_set_width (VinagreConnection *conn,
+                             guint width)
+{
+  g_return_if_fail (VINAGRE_IS_CONNECTION (conn));
+
+  conn->priv->width = width;
+}
+guint
+vinagre_connection_get_width (VinagreConnection *conn)
+{
+  g_return_val_if_fail (VINAGRE_IS_CONNECTION (conn), 0);
+
+  return conn->priv->width;
+}
+
+void
+vinagre_connection_set_height (VinagreConnection *conn,
+                              guint height)
+{
+  g_return_if_fail (VINAGRE_IS_CONNECTION (conn));
+
+  conn->priv->height = height;
+}
+guint
+vinagre_connection_get_height (VinagreConnection *conn)
+{
+  g_return_val_if_fail (VINAGRE_IS_CONNECTION (conn), 0);
+
+  return conn->priv->height;
+}
+
 /**
  * vinagre_connection_split_string:
  * @uri: The URI to be splitted.
diff --git a/vinagre/vinagre-connection.h b/vinagre/vinagre-connection.h
index 16b8971..7fc130c 100644
--- a/vinagre/vinagre-connection.h
+++ b/vinagre/vinagre-connection.h
@@ -88,6 +88,14 @@ gboolean         vinagre_connection_get_fullscreen   (VinagreConnection *conn);
 void               vinagre_connection_set_fullscreen   (VinagreConnection *conn,
                                                         gboolean value);
 
+guint              vinagre_connection_get_width        (VinagreConnection *conn);
+void               vinagre_connection_set_width        (VinagreConnection *conn,
+                                                        guint width);
+
+guint              vinagre_connection_get_height       (VinagreConnection *conn);
+void               vinagre_connection_set_height       (VinagreConnection *conn,
+                                                        guint height);
+
 VinagreConnection*  vinagre_connection_new_from_string (const gchar *url, gchar **error_msg, gboolean 
use_bookmarks);
 VinagreConnection*  vinagre_connection_new_from_file   (const gchar *uri, gchar **error_msg, gboolean 
use_bookmarks);
 


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