Commit 6f173e38 authored by Jonh Wendell's avatar Jonh Wendell Committed by Jonh Wendell S. Santana
Browse files

Fix bug #515816 - connect dialog should remember Host/Port address. Also

2008-05-31  Jonh Wendell <jwendell@gnome.org>

	Fix bug #515816 - connect dialog should remember Host/Port address.
	Also added options to connect in fullscreen, view only and with scaling
	directly in the connection dialog.

svn path=/trunk/; revision=350
parent 4d906170
2008-05-31 Jonh Wendell <jwendell@gnome.org>
Fix bug #515816 - connect dialog should remember Host/Port address.
Also added options to connect in fullscreen, view only and with scaling
directly in the connection dialog.
2008-05-31 Jonh Wendell <jwendell@gnome.org>
* src/vinagre-app.c: Persist changes in menu shortcuts (Ubuntu #233918).
......
This diff is collapsed.
......@@ -73,5 +73,17 @@
</locale>
</schema>
<schema>
<key>/schemas/apps/vinagre/history_size</key>
<applyto>/apps/vinagre/history_size</applyto>
<owner>vinagre</owner>
<type>int</type>
<default>15</default>
<locale name="C">
<short>Maximum number of history items in connect dialog</short>
<long>Specifies the maximum number of items in the host dropdown entry.</long>
</locale>
</schema>
</schemalist>
</gconfschemafile>
......@@ -23,19 +23,157 @@
#include <glib.h>
#include <glade/glade.h>
#include <avahi-ui/avahi-ui.h>
#include <string.h>
#include "vinagre-connect.h"
#include "vinagre-utils.h"
#include "vinagre-bookmarks.h"
#include "vinagre-prefs.h"
typedef struct {
GladeXML *xml;
GtkWidget *dialog;
GtkWidget *host_entry;
GtkWidget *port_entry;
GtkWidget *find_button;
GtkWidget *fullscreen_check;
GtkWidget *scaling_check;
GtkWidget *viewonly_check;
} VinagreConnectDialog;
enum {
COLUMN_TEXT,
N_COLUMNS
};
static gchar*
history_filename () {
return g_build_filename (g_get_user_config_dir (),
"vinagre",
"history",
NULL);
}
static GPtrArray *
saved_history (void)
{
gchar *filename, *file_contents = NULL;
gchar **history_from_file = NULL, **list;
gboolean success;
gint len;
GPtrArray *array;
array = g_ptr_array_new ();
filename = history_filename ();
success = g_file_get_contents (filename,
&file_contents,
NULL,
NULL);
if (success)
{
history_from_file = g_strsplit (file_contents, "\n", 0);
len = g_strv_length (history_from_file);
if (strlen (history_from_file[len-1]) == 0)
{
g_free (history_from_file[len-1]);
history_from_file[len-1] = NULL;
}
list = history_from_file;
while (*list != NULL)
g_ptr_array_add (array, *list++);
}
g_free (filename);
g_free (file_contents);
return array;
}
static void
setup_combo (GtkWidget *combo)
{
GtkListStore *store;
GtkTreeIter iter;
GtkEntryCompletion *completion;
GPtrArray *history;
gint i, size;
store = gtk_list_store_new (N_COLUMNS, G_TYPE_STRING);
history = saved_history ();
g_object_get (vinagre_prefs_get_default (), "history-size", &size, NULL);
if (size <= 0)
size = G_MAXINT;
for (i=history->len-1; i>=0 && i>=(gint)history->len-size; i--)
{
GtkTreeIter iter;
gtk_list_store_append (store, &iter);
gtk_list_store_set (store, &iter, COLUMN_TEXT, g_ptr_array_index (history, i), -1);
}
g_ptr_array_free (history, TRUE);
gtk_combo_box_set_model (GTK_COMBO_BOX (combo),
GTK_TREE_MODEL (store));
gtk_combo_box_entry_set_text_column (GTK_COMBO_BOX_ENTRY (combo),
0);
completion = gtk_entry_completion_new ();
gtk_entry_completion_set_model (completion, GTK_TREE_MODEL (store));
gtk_entry_completion_set_text_column (completion, 0);
gtk_entry_completion_set_inline_completion (completion, TRUE);
gtk_entry_set_completion (GTK_ENTRY(gtk_bin_get_child(GTK_BIN(combo))), completion);
g_object_unref (completion);
}
void
save_history (GtkWidget *combo) {
gchar *host;
GPtrArray *history;
guint i;
gchar *filename, *path;
GString *content;
GError *error = NULL;
host = gtk_combo_box_get_active_text (GTK_COMBO_BOX (combo));
history = saved_history ();
for (i=0; i<history->len; i++)
if (!g_strcmp0 (g_ptr_array_index (history, i), host))
{
g_ptr_array_remove_index (history, i);
break;
}
g_ptr_array_add (history, host);
content = g_string_new (NULL);
for (i=0; i<history->len; i++)
g_string_append_printf (content, "%s\n", g_ptr_array_index (history, i));
filename = history_filename ();
path = g_path_get_dirname (filename);
g_mkdir_with_parents (path, 0755);
g_file_set_contents (filename,
content->str,
-1,
&error);
g_free (filename);
g_free (path);
g_ptr_array_free (history, TRUE);
g_string_free (content, TRUE);
if (error) {
g_warning (_("Error while saving history file: %s"), error->message);
g_error_free (error);
}
}
static void
vinagre_connect_find_button_cb (GtkButton *button,
VinagreConnectDialog *dialog)
......@@ -56,11 +194,16 @@ vinagre_connect_find_button_cb (GtkButton *button,
if (gtk_dialog_run(GTK_DIALOG(d)) == GTK_RESPONSE_ACCEPT)
{
gtk_entry_set_text (GTK_ENTRY (dialog->host_entry),
aui_service_dialog_get_host_name(AUI_SERVICE_DIALOG(d)));
gchar *tmp;
tmp = g_strdup_printf ("%s::%d",
aui_service_dialog_get_host_name(AUI_SERVICE_DIALOG(d)),
aui_service_dialog_get_port(AUI_SERVICE_DIALOG(d)));
gtk_entry_set_text (GTK_ENTRY (gtk_bin_get_child (GTK_BIN (dialog->host_entry))),
tmp);
gtk_spin_button_set_value (GTK_SPIN_BUTTON (dialog->port_entry),
aui_service_dialog_get_port(AUI_SERVICE_DIALOG(d)));
g_free (tmp);
}
gtk_widget_destroy (d);
......@@ -70,8 +213,6 @@ VinagreConnection *vinagre_connect (VinagreWindow *window)
{
VinagreConnection *conn = NULL;
gint result;
const gchar *host;
int port;
VinagreConnectDialog dialog;
dialog.xml = glade_xml_new (vinagre_utils_get_glade_filename (), NULL, NULL);
......@@ -79,10 +220,13 @@ VinagreConnection *vinagre_connect (VinagreWindow *window)
gtk_window_set_transient_for (GTK_WINDOW (dialog.dialog), GTK_WINDOW (window));
dialog.host_entry = glade_xml_get_widget (dialog.xml, "host_entry");
dialog.port_entry = glade_xml_get_widget (dialog.xml, "port_entry");
dialog.find_button = glade_xml_get_widget (dialog.xml, "find_button");
dialog.fullscreen_check = glade_xml_get_widget (dialog.xml, "fullscreen_check");
dialog.viewonly_check = glade_xml_get_widget (dialog.xml, "viewonly_check");
dialog.scaling_check = glade_xml_get_widget (dialog.xml, "scaling_check");
setup_combo (dialog.host_entry);
gtk_widget_show (dialog.find_button);
g_signal_connect (dialog.find_button,
"clicked",
G_CALLBACK (vinagre_connect_find_button_cb),
......@@ -93,20 +237,33 @@ VinagreConnection *vinagre_connect (VinagreWindow *window)
if (result == GTK_RESPONSE_OK)
{
host = gtk_entry_get_text (GTK_ENTRY(dialog.host_entry));
port = gtk_spin_button_get_value_as_int (GTK_SPIN_BUTTON (dialog.port_entry));
gchar *host = NULL, *error_msg = NULL;
host = gtk_combo_box_get_active_text (GTK_COMBO_BOX (dialog.host_entry));
gtk_widget_hide (GTK_WIDGET (dialog.dialog));
conn = vinagre_bookmarks_exists (vinagre_bookmarks_get_default (),
host,
port);
if (!conn)
if (!host || !g_strcmp0 (host, ""))
goto fail;
save_history (dialog.host_entry);
conn = vinagre_connection_new_from_string (host, &error_msg);
if (conn)
{
g_object_set (conn,
"scaling", gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (dialog.scaling_check)),
"view-only", gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (dialog.viewonly_check)),
"fullscreen", gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (dialog.fullscreen_check)),
NULL);
}
else
{
conn = vinagre_connection_new ();
vinagre_connection_set_host (conn, host);
vinagre_connection_set_port (conn, port);
vinagre_utils_show_error (error_msg ? error_msg : _("Unknown error"),
GTK_WINDOW (window));
}
fail:
g_free (host);
g_free (error_msg);
}
gtk_widget_destroy (dialog.dialog);
......
......@@ -35,6 +35,9 @@ struct _VinagreConnectionPrivate
gchar *name;
gchar *password;
gchar *desktop_name;
gboolean view_only;
gboolean scaling;
gboolean fullscreen;
};
enum
......@@ -47,7 +50,10 @@ enum
PROP_PASSWORD,
PROP_DESKTOP_NAME,
PROP_BEST_NAME,
PROP_ICON
PROP_ICON,
PROP_VIEW_ONLY,
PROP_SCALING,
PROP_FULLSCREEN
};
#define VINAGRE_CONNECTION_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), VINAGRE_TYPE_CONNECTION, VinagreConnectionPrivate))
......@@ -64,6 +70,9 @@ vinagre_connection_init (VinagreConnection *conn)
conn->priv->password = NULL;
conn->priv->name = NULL;
conn->priv->desktop_name = NULL;
conn->priv->view_only = FALSE;
conn->priv->scaling = FALSE;
conn->priv->fullscreen = FALSE;
}
static void
......@@ -125,6 +134,18 @@ vinagre_connection_set_property (GObject *object, guint prop_id, const GValue *v
vinagre_connection_set_desktop_name (conn, g_value_get_string (value));
break;
case PROP_VIEW_ONLY:
vinagre_connection_set_view_only (conn, g_value_get_boolean (value));
break;
case PROP_SCALING:
vinagre_connection_set_scaling (conn, g_value_get_boolean (value));
break;
case PROP_FULLSCREEN:
vinagre_connection_set_fullscreen (conn, g_value_get_boolean (value));
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
......@@ -175,6 +196,18 @@ vinagre_connection_get_property (GObject *object, guint prop_id, GValue *value,
g_value_set_object (value, vinagre_connection_get_icon (conn));
break;
case PROP_VIEW_ONLY:
g_value_set_boolean (value, conn->priv->view_only);
break;
case PROP_SCALING:
g_value_set_boolean (value, conn->priv->scaling);
break;
case PROP_FULLSCREEN:
g_value_set_boolean (value, conn->priv->fullscreen);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
......@@ -289,6 +322,39 @@ vinagre_connection_class_init (VinagreConnectionClass *klass)
G_PARAM_STATIC_NICK |
G_PARAM_STATIC_NAME |
G_PARAM_STATIC_BLURB));
g_object_class_install_property (object_class,
PROP_VIEW_ONLY,
g_param_spec_boolean ("view-only",
"View-only connection",
"Whether this connection is a view-only one",
FALSE,
G_PARAM_READWRITE |
G_PARAM_CONSTRUCT |
G_PARAM_STATIC_NICK |
G_PARAM_STATIC_NAME |
G_PARAM_STATIC_BLURB));
g_object_class_install_property (object_class,
PROP_SCALING,
g_param_spec_boolean ("scaling",
"Use scaling",
"Whether to use scaling on this connection",
FALSE,
G_PARAM_READWRITE |
G_PARAM_CONSTRUCT |
G_PARAM_STATIC_NICK |
G_PARAM_STATIC_NAME |
G_PARAM_STATIC_BLURB));
g_object_class_install_property (object_class,
PROP_FULLSCREEN,
g_param_spec_boolean ("fullscreen",
"Full screen connection",
"Whether this connection is a view-only one",
FALSE,
G_PARAM_READWRITE |
G_PARAM_CONSTRUCT |
G_PARAM_STATIC_NICK |
G_PARAM_STATIC_NAME |
G_PARAM_STATIC_BLURB));
}
......@@ -589,4 +655,53 @@ vinagre_connection_get_icon (VinagreConnection *conn)
return pixbuf;
}
void
vinagre_connection_set_view_only (VinagreConnection *conn,
gboolean value)
{
g_return_if_fail (VINAGRE_IS_CONNECTION (conn));
conn->priv->view_only = value;
}
gboolean
vinagre_connection_get_view_only (VinagreConnection *conn)
{
g_return_val_if_fail (VINAGRE_IS_CONNECTION (conn), FALSE);
return conn->priv->view_only;
}
void
vinagre_connection_set_scaling (VinagreConnection *conn,
gboolean value)
{
g_return_if_fail (VINAGRE_IS_CONNECTION (conn));
conn->priv->scaling = value;
}
gboolean
vinagre_connection_get_scaling (VinagreConnection *conn)
{
g_return_val_if_fail (VINAGRE_IS_CONNECTION (conn), FALSE);
return conn->priv->scaling;
}
void
vinagre_connection_set_fullscreen (VinagreConnection *conn,
gboolean value)
{
g_return_if_fail (VINAGRE_IS_CONNECTION (conn));
conn->priv->fullscreen = value;
}
gboolean
vinagre_connection_get_fullscreen (VinagreConnection *conn)
{
g_return_val_if_fail (VINAGRE_IS_CONNECTION (conn), FALSE);
return conn->priv->fullscreen;
}
/* vim: ts=8 */
......@@ -92,6 +92,18 @@ VinagreConnection* vinagre_connection_new_from_file (const gchar *uri, gchar **
GdkPixbuf* vinagre_connection_get_icon (VinagreConnection *conn);
gboolean vinagre_connection_get_view_only (VinagreConnection *conn);
void vinagre_connection_set_view_only (VinagreConnection *conn,
gboolean value);
gboolean vinagre_connection_get_scaling (VinagreConnection *conn);
void vinagre_connection_set_scaling (VinagreConnection *conn,
gboolean value);
gboolean vinagre_connection_get_fullscreen (VinagreConnection *conn);
void vinagre_connection_set_fullscreen (VinagreConnection *conn,
gboolean value);
G_END_DECLS
#endif /* __VINAGRE_CONNECTION_H__ */
......
......@@ -29,6 +29,7 @@
#define VM_STATUSBAR_VISIBLE VINAGRE_BASE_KEY "/statusbar_visible"
#define VM_SIDE_PANEL_VISIBLE VINAGRE_BASE_KEY "/side_pane_visible"
#define VM_SHOW_ACCELS VINAGRE_BASE_KEY "/show_accels"
#define VM_HISTORY_SIZE VINAGRE_BASE_KEY "/history_size"
#define VM_WINDOW_STATE VINAGRE_BASE_KEY "/window_state"
#define VM_WINDOW_WIDTH VINAGRE_BASE_KEY "/window_width"
......@@ -53,7 +54,8 @@ enum
PROP_WINDOW_WIDTH,
PROP_WINDOW_HEIGHT,
PROP_SIDE_PANEL_SIZE,
PROP_SHOW_ACCELS
PROP_SHOW_ACCELS,
PROP_HISTORY_SIZE
};
G_DEFINE_TYPE (VinagrePrefs, vinagre_prefs, G_TYPE_OBJECT);
......@@ -231,6 +233,9 @@ vinagre_prefs_set_property (GObject *object, guint prop_id, const GValue *value,
case PROP_SHOW_ACCELS:
vinagre_prefs_set_bool (prefs, VM_SHOW_ACCELS, g_value_get_boolean (value));
break;
case PROP_HISTORY_SIZE:
vinagre_prefs_set_int (prefs, VM_HISTORY_SIZE, g_value_get_int (value));
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
......@@ -274,6 +279,9 @@ vinagre_prefs_get_property (GObject *object, guint prop_id, GValue *value, GPara
case PROP_SHOW_ACCELS:
g_value_set_boolean (value, vinagre_prefs_get_bool (prefs, VM_SHOW_ACCELS, TRUE));
break;
case PROP_HISTORY_SIZE:
g_value_set_int (value, vinagre_prefs_get_int (prefs, VM_HISTORY_SIZE, 15));
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
......@@ -362,6 +370,13 @@ vinagre_prefs_class_init (VinagrePrefsClass *klass)
"Whether we should show the menu accelerators (keyboard shortcuts)",
TRUE,
G_PARAM_READWRITE));
g_object_class_install_property (object_class,
PROP_HISTORY_SIZE,
g_param_spec_int ("history-size",
"History size",
"Max number of items in history dropdown entry",
0, G_MAXINT, 15,
G_PARAM_READWRITE));
}
/* vim: ts=8 */
......@@ -259,18 +259,35 @@ static void
open_vnc (VinagreTab *tab)
{
gchar *port;
gboolean scaling, view_only, fullscreen;
port = g_strdup_printf ("%d", vinagre_connection_get_port (tab->priv->conn));
if (!vnc_display_open_host (VNC_DISPLAY(tab->priv->vnc), vinagre_connection_get_host (tab->priv->conn), port))
vinagre_utils_show_error (_("Error connecting to host."), NULL);
g_object_get (tab->priv->conn,
"view-only", &view_only,
"scaling", &scaling,
"fullscreen", &fullscreen,
NULL);
vinagre_tab_set_scaling (tab, scaling);
vinagre_tab_set_readonly (tab, view_only);
vnc_display_set_pointer_local (VNC_DISPLAY(tab->priv->vnc), TRUE);
vnc_display_set_keyboard_grab (VNC_DISPLAY(tab->priv->vnc), TRUE);
vnc_display_set_pointer_grab (VNC_DISPLAY(tab->priv->vnc), TRUE);
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);
if (fullscreen)
vinagre_window_toggle_fullscreen (tab->priv->window);
}
else
{
vinagre_utils_show_error (_("Error connecting to host."), NULL);
}
g_free (port);
gtk_widget_grab_focus (tab->priv->vnc);
}
static void
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment