[Spice-devel] [spicy PATCH 5/7 v4] spicy: Host and port (or tls) are now required
Lukas Venhoda
lvenhoda at redhat.com
Tue Jun 16 02:41:55 PDT 2015
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.
---
Changes since v3
- Changed required entries from HOST and PORT to HOST and (PORT or TLS-PORT)
Changes since v2
- New patch
- Split from the v2 patch as requested
- Changed response type from GtkResponseType to gboolean
---
src/spicy-connect.c | 33 ++++++++++++++++++++++++++++++---
1 file changed, 30 insertions(+), 3 deletions(-)
diff --git a/src/spicy-connect.c b/src/spicy-connect.c
index 1b90217..c5f1dfb 100644
--- a/src/spicy-connect.c
+++ b/src/spicy-connect.c
@@ -44,6 +44,16 @@ static void shutdown_loop(GMainLoop *loop)
g_main_loop_quit(loop);
}
+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;
@@ -63,6 +73,14 @@ static gboolean close_cb(gpointer data)
return TRUE;
}
+static void entry_changed_cb(GtkEditable* entry, gpointer data)
+{
+ GtkButton *connect_button = data;
+ gboolean active = can_connect();
+
+ gtk_widget_set_sensitive(GTK_WIDGET(connect_button), active);
+}
+
static gboolean entry_focus_in_cb(GtkWidget *widget, GdkEvent *event, gpointer data)
{
GtkRecentChooser *recent = data;
@@ -121,9 +139,12 @@ static void recent_selection_changed_dialog_cb(GtkRecentChooser *chooser, gpoint
static void connect_cb(gpointer data)
{
ConnectionInfo *ci = data;
- ci->response_id = TRUE;
- set_connection_info(ci->session);
- shutdown_loop(ci->loop);
+ if (can_connect())
+ {
+ ci->response_id = TRUE;
+ set_connection_info(ci->session);
+ shutdown_loop(ci->loop);
+ }
}
#endif
@@ -131,6 +152,7 @@ gboolean spicy_connect_dialog(SpiceSession *session)
{
GtkWidget *connect_button, *cancel_button, *label;
GtkBox *main_box, *recent_box, *button_box;
+ gboolean entry_filled;
GtkWindow *window;
GtkTable *table;
int i;
@@ -194,6 +216,9 @@ gboolean spicy_connect_dialog(SpiceSession *session)
gtk_box_pack_start(main_box, GTK_WIDGET(button_box), FALSE, TRUE, 0);
+ entry_filled = can_connect();
+ gtk_widget_set_sensitive(GTK_WIDGET(connect_button), entry_filled);
+
g_signal_connect(window, "key-press-event",
G_CALLBACK(key_pressed_cb), window);
g_signal_connect_swapped(window, "delete-event",
@@ -224,6 +249,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), &ci);
+ 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);
--
2.4.2
More information about the Spice-devel
mailing list