[Spice-devel] [spicy PATCH 3/5 v3] spicy: Changed the dialog into a window

Lukas Venhoda lvenhoda at redhat.com
Mon Jun 15 05:40:04 PDT 2015


Slight error.

> Changes since v2
>  - Now only contains changing dialog to window
>     - UX changes to XML in later patches

Should read

Changes since v2
 - Now only contains changing dialog to window
    - UX changes in later patches

----- Original Message -----
> From: "Lukas Venhoda" <lvenhoda at redhat.com>
> To: spice-devel at lists.freedesktop.org
> Cc: "Lukas Venhoda" <lvenhoda at redhat.com>
> Sent: Monday, June 15, 2015 2:31:37 PM
> Subject: [spicy PATCH 3/5 v3] spicy: Changed the dialog into a window
> 
> Changed connect dialog from GtkDialog to GtkWindow.
> Added the necessary signals and buttons, to keep then
> behaviour of a dialog (ESC to close, ENTER to submit).
> ---
> Changes since v2
>  - Now only contains changing dialog to window
>     - UX changes to XML in later patches
>  - Changed response type from GtkResponseType to gboolean
> ---
>  src/spicy-connect.c | 151
>  +++++++++++++++++++++++++++++++++++++++++-----------
>  1 file changed, 120 insertions(+), 31 deletions(-)
> 
> diff --git a/src/spicy-connect.c b/src/spicy-connect.c
> index 2656c24..3d3a31f 100644
> --- a/src/spicy-connect.c
> +++ b/src/spicy-connect.c
> @@ -21,6 +21,13 @@
>  #include "spice-common.h"
>  #include "spicy-connect.h"
> 
> +typedef struct
> +{
> +    gboolean response_id;
> +    GMainLoop *loop;
> +    SpiceSession *session;
> +} ConnectionInfo;
> +
>  static struct {
>      const char *text;
>      const char *prop;
> @@ -31,6 +38,49 @@ static struct {
>      { .text = N_("TLS Port"),   .prop = "tls-port"  },
>  };
> 
> +static void shutdown_loop(GMainLoop *loop)
> +{
> +    if (g_main_loop_is_running(loop))
> +        g_main_loop_quit(loop);
> +}
> +
> +static void set_connection_info(SpiceSession *session)
> +{
> +    const gchar *txt;
> +    txt = gtk_entry_get_text(GTK_ENTRY(connect_entries[0].entry));
> +    g_object_set(session, "host", txt, NULL);
> +
> +    txt = gtk_entry_get_text(GTK_ENTRY(connect_entries[1].entry));
> +    g_object_set(session, "port", txt, NULL);
> +
> +    txt = gtk_entry_get_text(GTK_ENTRY(connect_entries[2].entry));
> +    g_object_set(session, "tls-port", txt, NULL);
> +}
> +
> +static gboolean close_cb(gpointer data)
> +{
> +    ConnectionInfo *ci = data;
> +    ci->response_id = FALSE;
> +    shutdown_loop(ci->loop);
> +    return TRUE;
> +}
> +
> +static gboolean key_pressed_cb(GtkWidget *widget, GdkEvent *event, gpointer
> data)
> +{
> +    gboolean tst;
> +    if (event->type == GDK_KEY_PRESS) {
> +        switch (event->key.keyval) {
> +            case GDK_KEY_Escape:
> +                g_signal_emit_by_name(GTK_WIDGET(data), "delete-event",
> NULL, &tst);
> +                return TRUE;
> +            default:
> +                return FALSE;
> +        }
> +    }
> +
> +    return FALSE;
> +}
> +
>  #ifndef G_OS_WIN32
>  static void recent_selection_changed_dialog_cb(GtkRecentChooser *chooser,
>  gpointer data)
>  {
> @@ -63,32 +113,44 @@ static void
> recent_selection_changed_dialog_cb(GtkRecentChooser *chooser, gpoint
>      gtk_recent_info_unref(info);
>  }
> 
> -static void recent_item_activated_dialog_cb(GtkRecentChooser *chooser,
> gpointer data)
> +static void connect_cb(gpointer data)
>  {
> -   gtk_dialog_response (GTK_DIALOG (data), GTK_RESPONSE_ACCEPT);
> +    ConnectionInfo *ci = data;
> +    ci->response_id = TRUE;
> +    set_connection_info(ci->session);
> +    shutdown_loop(ci->loop);
>  }
>  #endif
> 
>  gboolean spicy_connect_dialog(SpiceSession *session)
>  {
> -    GtkWidget *dialog, *area, *label;
> +    GtkWidget *connect_button, *cancel_button, *label;
> +    GtkBox *main_box, *recent_box, *button_box;
> +    GtkWindow *window;
>      GtkTable *table;
> -    gboolean retval;
>      int i;
> 
> +    ConnectionInfo ci = {
> +        FALSE,
> +        NULL,
> +        session,
> +        NULL,
> +        NULL,
> +        NULL
> +    };
> +
>      /* Create the widgets */
> -    dialog = gtk_dialog_new_with_buttons(_("Connect to SPICE"),
> -                                         NULL,
> -                                         GTK_DIALOG_DESTROY_WITH_PARENT,
> -                                         GTK_STOCK_CANCEL,
> -                                         GTK_RESPONSE_REJECT,
> -                                         GTK_STOCK_CONNECT,
> -                                         GTK_RESPONSE_ACCEPT,
> -                                         NULL);
> -    gtk_dialog_set_default_response(GTK_DIALOG(dialog),
> GTK_RESPONSE_ACCEPT);
> -    area = gtk_dialog_get_content_area(GTK_DIALOG(dialog));
> +    window = GTK_WINDOW(gtk_window_new(GTK_WINDOW_TOPLEVEL));
> +    gtk_window_set_title(window, _("Connect to SPICE"));
> +    gtk_window_set_resizable(window, FALSE);
> +    gtk_container_set_border_width(GTK_CONTAINER(window), 5);
> +
> +    main_box = GTK_BOX(gtk_vbox_new(FALSE, 0));
> +    gtk_container_add(GTK_CONTAINER(window), GTK_WIDGET(main_box));
> +
>      table = GTK_TABLE(gtk_table_new(3, 2, 0));
> -    gtk_box_pack_start(GTK_BOX(area), GTK_WIDGET(table), TRUE, TRUE, 0);
> +    gtk_box_pack_start(main_box, GTK_WIDGET(table), FALSE, TRUE, 0);
> +    gtk_container_set_border_width(GTK_CONTAINER(table), 5);
>      gtk_table_set_row_spacings(table, 5);
>      gtk_table_set_col_spacings(table, 5);
> 
> @@ -108,16 +170,41 @@ gboolean spicy_connect_dialog(SpiceSession *session)
>          }
>      }
> 
> +    recent_box = GTK_BOX(gtk_vbox_new(FALSE, 0));
> +    gtk_box_pack_start(main_box, GTK_WIDGET(recent_box), TRUE, TRUE, 0);
> +    gtk_container_set_border_width(GTK_CONTAINER(recent_box), 5);
> +
>      label = gtk_label_new(_("Recent connections:"));
> -    gtk_box_pack_start(GTK_BOX(area), label, TRUE, TRUE, 0);
> +    gtk_box_pack_start(recent_box, label, FALSE, TRUE, 0);
>      gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5);
> +
> +    button_box = GTK_BOX(gtk_hbutton_box_new());
> +    gtk_button_box_set_layout(GTK_BUTTON_BOX(button_box),
> GTK_BUTTONBOX_END);
> +    gtk_box_set_spacing(button_box, 5);
> +    gtk_container_set_border_width(GTK_CONTAINER(button_box), 5);
> +    connect_button = gtk_button_new_with_label(_("Connect"));
> +    cancel_button = gtk_button_new_with_label(_("Cancel"));
> +    gtk_box_pack_start(button_box, cancel_button, FALSE, TRUE, 0);
> +    gtk_box_pack_start(button_box, connect_button, FALSE, TRUE, 1);
> +
> +    gtk_box_pack_start(main_box, GTK_WIDGET(button_box), FALSE, TRUE, 0);
> +
> +    g_signal_connect(window, "key-press-event",
> +                     G_CALLBACK(key_pressed_cb), window);
> +    g_signal_connect_swapped(window, "delete-event",
> +                             G_CALLBACK(close_cb), &ci);
> +    g_signal_connect_swapped(connect_button, "clicked",
> +                             G_CALLBACK(connect_cb), &ci);
> +    g_signal_connect_swapped(cancel_button, "clicked",
> +                             G_CALLBACK(close_cb), &ci);
> +
>  #ifndef G_OS_WIN32
>      GtkRecentFilter *rfilter;
>      GtkWidget *recent;
> 
>      recent = GTK_WIDGET(gtk_recent_chooser_widget_new());
>      gtk_recent_chooser_set_show_icons(GTK_RECENT_CHOOSER(recent), FALSE);
> -    gtk_box_pack_start(GTK_BOX(area), recent, TRUE, TRUE, 0);
> +    gtk_box_pack_start(recent_box, recent, TRUE, TRUE, 0);
> 
>      rfilter = gtk_recent_filter_new();
>      gtk_recent_filter_add_mime_type(rfilter, "application/x-spice");
> @@ -125,20 +212,22 @@ gboolean spicy_connect_dialog(SpiceSession *session)
>      gtk_recent_chooser_set_local_only(GTK_RECENT_CHOOSER(recent), FALSE);
>      g_signal_connect(recent, "selection-changed",
>                       G_CALLBACK(recent_selection_changed_dialog_cb),
>                       session);
> -    g_signal_connect(recent, "item-activated",
> -                     G_CALLBACK(recent_item_activated_dialog_cb), dialog);
> +    g_signal_connect_swapped(recent, "item-activated",
> +                             G_CALLBACK(connect_cb), &ci);
>  #endif
> +
> +    for (i = 0; i < SPICE_N_ELEMENTS(connect_entries); i++) {
> +        g_signal_connect_swapped(connect_entries[i].entry, "activate",
> +                                 G_CALLBACK(connect_cb), &ci);
> +    }
> +
>      /* show and wait for response */
> -    gtk_widget_show_all(dialog);
> -    if (gtk_dialog_run(GTK_DIALOG(dialog)) == GTK_RESPONSE_ACCEPT) {
> -        for (i = 0; i < SPICE_N_ELEMENTS(connect_entries); i++) {
> -            const gchar *txt;
> -            txt = gtk_entry_get_text(GTK_ENTRY(connect_entries[i].entry));
> -            g_object_set(session, connect_entries[i].prop, txt, NULL);
> -        }
> -        retval = TRUE;
> -    } else
> -        retval = FALSE;
> -    gtk_widget_destroy(dialog);
> -    return retval;
> +    gtk_widget_show_all(GTK_WIDGET(window));
> +
> +    ci.loop = g_main_loop_new(NULL, FALSE);
> +    g_main_loop_run(ci.loop);
> +
> +    gtk_widget_destroy(GTK_WIDGET(window));
> +
> +    return ci.response_id;
>  }
> --
> 2.4.2
> 
> 


More information about the Spice-devel mailing list