[Spice-devel] [spicy PATCH 5/7 v4] spicy: Host and port (or tls) are now required

Christophe Fergeau cfergeau at redhat.com
Tue Jun 16 04:43:15 PDT 2015


On Tue, Jun 16, 2015 at 11:41:55AM +0200, Lukas Venhoda wrote:
> 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);

'active' could be 'sensitive', or even just 
gtk_widget_set_sensitive(GTK_WIDGET(connect_button), can_connect());


> +}
> +
>  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();

'entries_filled' ? I would not try naming this variable, and just pass
can_connect() as an argument to gtk_widget_set_sensitive().

Christophe
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 819 bytes
Desc: not available
URL: <http://lists.freedesktop.org/archives/spice-devel/attachments/20150616/d5a6cdce/attachment.sig>


More information about the Spice-devel mailing list