summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLukas Venhoda <lvenhoda@redhat.com>2015-06-16 16:23:32 +0200
committerChristophe Fergeau <cfergeau@redhat.com>2015-06-18 17:06:42 +0200
commitd28dfda35e1c1e6d1da42fef42e8831b24167cfb (patch)
tree7b03edac7bfad4f688762955d599bc16ad8e8f36
parent07cfbe929acbf3fe233f1d642e4ee1b57e920dd3 (diff)
spicy: Host and port (or tls) are now required
Connect button is now non-sensitive when host and port (or tls) entry is empty. Pressing enter will now also NOT connect, when the entries are empty.
-rw-r--r--src/spicy-connect.c32
1 files changed, 27 insertions, 5 deletions
diff --git a/src/spicy-connect.c b/src/spicy-connect.c
index a23ff03..767ad06 100644
--- a/src/spicy-connect.c
+++ b/src/spicy-connect.c
@@ -39,6 +39,16 @@ static struct {
{ .text = N_("TLS Port"), .prop = "tls-port" },
};
+static gboolean can_connect(void)
+{
+ if ((gtk_entry_get_text_length(GTK_ENTRY(connect_entries[0].entry)) > 0) &&
+ ((gtk_entry_get_text_length(GTK_ENTRY(connect_entries[1].entry)) > 0) ||
+ (gtk_entry_get_text_length(GTK_ENTRY(connect_entries[2].entry)) > 0)))
+ return TRUE;
+
+ return FALSE;
+}
+
static void set_connection_info(SpiceSession *session)
{
const gchar *txt;
@@ -60,6 +70,12 @@ static gboolean close_cb(gpointer data)
return TRUE;
}
+static void entry_changed_cb(GtkEditable* entry, gpointer data)
+{
+ GtkButton *connect_button = data;
+ gtk_widget_set_sensitive(GTK_WIDGET(connect_button), can_connect());
+}
+
static gboolean entry_focus_in_cb(GtkWidget *widget, GdkEvent *event, gpointer data)
{
GtkRecentChooser *recent = GTK_RECENT_CHOOSER(data);
@@ -119,11 +135,13 @@ static void recent_selection_changed_dialog_cb(GtkRecentChooser *chooser, gpoint
static void connect_cb(gpointer data)
{
ConnectionInfo *info = data;
- info->connecting = TRUE;
- set_connection_info(info->session);
-
- if (g_main_loop_is_running(info->loop))
- g_main_loop_quit(info->loop);
+ if (can_connect())
+ {
+ info->connecting = TRUE;
+ set_connection_info(info->session);
+ if (g_main_loop_is_running(info->loop))
+ g_main_loop_quit(info->loop);
+ }
}
gboolean spicy_connect_dialog(SpiceSession *session)
@@ -190,6 +208,8 @@ gboolean spicy_connect_dialog(SpiceSession *session)
gtk_box_pack_start(main_box, GTK_WIDGET(button_box), FALSE, TRUE, 0);
+ gtk_widget_set_sensitive(GTK_WIDGET(connect_button), can_connect());
+
g_signal_connect(window, "key-press-event",
G_CALLBACK(key_pressed_cb), window);
g_signal_connect_swapped(window, "delete-event",
@@ -220,6 +240,8 @@ gboolean spicy_connect_dialog(SpiceSession *session)
for (i = 0; i < SPICE_N_ELEMENTS(connect_entries); i++) {
g_signal_connect_swapped(connect_entries[i].entry, "activate",
G_CALLBACK(connect_cb), &info);
+ g_signal_connect(connect_entries[i].entry, "changed",
+ G_CALLBACK(entry_changed_cb), connect_button);
#ifndef G_OS_WIN32
g_signal_connect(connect_entries[i].entry, "focus-in-event",
G_CALLBACK(entry_focus_in_cb), recent);