[Spice-commits] 6 commits - po/POTFILES.in src/Makefile.am src/spicy-connect.c src/spicy-connect.h src/spicy.c

Christophe Fergau teuf at kemper.freedesktop.org
Thu Jun 18 08:16:01 PDT 2015


 po/POTFILES.in      |    1 
 src/Makefile.am     |    2 
 src/spicy-connect.c |  249 ++++++++++++++++++++++++++++++++++++++++++++++++++++
 src/spicy-connect.h |   26 +++++
 src/spicy.c         |  135 ----------------------------
 5 files changed, 282 insertions(+), 131 deletions(-)

New commits:
commit 4245ebf6df3e136a37abe858980f3c993c34750d
Author: Lukas Venhoda <lvenhoda at redhat.com>
Date:   Tue Jun 16 16:23:34 2015 +0200

    spicy: Enable recent chooser on windows
    
    Recent chooser is working correctly in windows.

diff --git a/src/spicy-connect.c b/src/spicy-connect.c
index 3eee40f..4fff75d 100644
--- a/src/spicy-connect.c
+++ b/src/spicy-connect.c
@@ -99,7 +99,6 @@ static gboolean key_pressed_cb(GtkWidget *widget, GdkEvent *event, gpointer data
     return FALSE;
 }
 
-#ifndef G_OS_WIN32
 static void recent_selection_changed_dialog_cb(GtkRecentChooser *chooser, gpointer data)
 {
     GtkRecentInfo *info;
@@ -125,7 +124,6 @@ static void recent_selection_changed_dialog_cb(GtkRecentChooser *chooser, gpoint
 
     gtk_recent_info_unref(info);
 }
-#endif
 
 static void connect_cb(gpointer data)
 {
@@ -214,7 +212,6 @@ gboolean spicy_connect_dialog(SpiceSession *session)
     g_signal_connect_swapped(cancel_button, "clicked",
                              G_CALLBACK(close_cb), &info);
 
-#ifndef G_OS_WIN32
     GtkRecentFilter *rfilter;
     GtkWidget *recent;
 
@@ -230,17 +227,14 @@ gboolean spicy_connect_dialog(SpiceSession *session)
                      G_CALLBACK(recent_selection_changed_dialog_cb), session);
     g_signal_connect_swapped(recent, "item-activated",
                              G_CALLBACK(connect_cb), &info);
-#endif
 
     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);
-#endif
     }
 
     /* show and wait for response */
diff --git a/src/spicy.c b/src/spicy.c
index 3442db0..15ef377 100644
--- a/src/spicy.c
+++ b/src/spicy.c
@@ -810,7 +810,6 @@ static gboolean is_gtk_session_property(const gchar *property)
     return FALSE;
 }
 
-#ifndef G_OS_WIN32
 static void recent_item_activated_cb(GtkRecentChooser *chooser, gpointer data)
 {
     GtkRecentInfo *info;
@@ -827,7 +826,6 @@ static void recent_item_activated_cb(GtkRecentChooser *chooser, gpointer data)
     gtk_recent_info_unref(info);
     connection_connect(conn);
 }
-#endif
 
 static gboolean configure_event_cb(GtkWidget         *widget,
                                    GdkEventConfigure *event,
@@ -910,7 +908,6 @@ static SpiceWindow *create_spice_window(spice_connection *conn, SpiceChannel *ch
     win->ritem  = gtk_ui_manager_get_widget
         (win->ui, "/MainMenu/FileMenu/FileRecentMenu");
 
-#ifndef G_OS_WIN32
     GtkRecentFilter  *rfilter;
 
     win->rmenu = gtk_recent_chooser_menu_new();
@@ -922,7 +919,6 @@ static SpiceWindow *create_spice_window(spice_connection *conn, SpiceChannel *ch
     gtk_menu_item_set_submenu(GTK_MENU_ITEM(win->ritem), win->rmenu);
     g_signal_connect(win->rmenu, "item-activated",
                      G_CALLBACK(recent_item_activated_cb), win);
-#endif
 
     /* spice display */
     win->spice = GTK_WIDGET(spice_display_new_with_monitor(conn->session, id, monitor_id));
commit af145bc0de97fb28e75a29e13404b3f3fc5bbb17
Author: Lukas Venhoda <lvenhoda at redhat.com>
Date:   Tue Jun 16 16:23:33 2015 +0200

    spicy: Replace duplicated code with a for loop
    
    Changed piece of code working with fixed size array into a for loop.

diff --git a/src/spicy-connect.c b/src/spicy-connect.c
index 767ad06..3eee40f 100644
--- a/src/spicy-connect.c
+++ b/src/spicy-connect.c
@@ -106,6 +106,7 @@ static void recent_selection_changed_dialog_cb(GtkRecentChooser *chooser, gpoint
     gchar *txt = NULL;
     const gchar *uri;
     SpiceSession *session = data;
+    int i;
 
     info = gtk_recent_chooser_get_current_item(chooser);
     if (info == NULL)
@@ -116,17 +117,11 @@ static void recent_selection_changed_dialog_cb(GtkRecentChooser *chooser, gpoint
 
     g_object_set(session, "uri", uri, NULL);
 
-    g_object_get(session, "host", &txt, NULL);
-    gtk_entry_set_text(GTK_ENTRY(connect_entries[0].entry), txt ? txt : "");
-    g_free(txt);
-
-    g_object_get(session, "port", &txt, NULL);
-    gtk_entry_set_text(GTK_ENTRY(connect_entries[1].entry), txt ? txt : "");
-    g_free(txt);
-
-    g_object_get(session, "tls-port", &txt, NULL);
-    gtk_entry_set_text(GTK_ENTRY(connect_entries[2].entry), txt ? txt : "");
-    g_free(txt);
+    for (i = 0; i < SPICE_N_ELEMENTS(connect_entries); i++) {
+        g_object_get(session, connect_entries[i].prop, &txt, NULL);
+        gtk_entry_set_text(GTK_ENTRY(connect_entries[i].entry), txt ? txt : "");
+        g_free(txt);
+    }
 
     gtk_recent_info_unref(info);
 }
commit d28dfda35e1c1e6d1da42fef42e8831b24167cfb
Author: Lukas Venhoda <lvenhoda at redhat.com>
Date:   Tue Jun 16 16:23:32 2015 +0200

    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.

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);
commit 07cfbe929acbf3fe233f1d642e4ee1b57e920dd3
Author: Lukas Venhoda <lvenhoda at redhat.com>
Date:   Tue Jun 16 16:23:31 2015 +0200

    spicy: Fixed reselecting in recent chooser
    
    Selecting an entry in the recent connections list, and then modifying
    the host/port/TLS port, and double-clicking on that same entry in the
    list would cause spicy to connect to the edited address rather than
    the one which was picked in the recent chooser.
    
    After this commit, the selection will be cleared from the recent
    chooser, and double-clicking on an entry after editing it will always
    trigger a 'selection-changed' signal, which will properly set the
    address to connect to.

diff --git a/src/spicy-connect.c b/src/spicy-connect.c
index 5305840..a23ff03 100644
--- a/src/spicy-connect.c
+++ b/src/spicy-connect.c
@@ -60,6 +60,13 @@ static gboolean close_cb(gpointer data)
     return TRUE;
 }
 
+static gboolean entry_focus_in_cb(GtkWidget *widget, GdkEvent *event, gpointer data)
+{
+    GtkRecentChooser *recent = GTK_RECENT_CHOOSER(data);
+    gtk_recent_chooser_unselect_all(recent);
+    return TRUE;
+}
+
 static gboolean key_pressed_cb(GtkWidget *widget, GdkEvent *event, gpointer data)
 {
     gboolean tst;
@@ -213,6 +220,10 @@ 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);
+#ifndef G_OS_WIN32
+        g_signal_connect(connect_entries[i].entry, "focus-in-event",
+                         G_CALLBACK(entry_focus_in_cb), recent);
+#endif
     }
 
     /* show and wait for response */
commit 4f7605a35f1ba99a8d10a42873f5d1515043a7c2
Author: Lukas Venhoda <lvenhoda at redhat.com>
Date:   Thu Jun 18 16:35:24 2015 +0200

    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).
    
    spicy_connect_dialog now returns TRUE and FALSE instead of 0 and -1.

diff --git a/src/spicy-connect.c b/src/spicy-connect.c
index 991aaab..5305840 100644
--- a/src/spicy-connect.c
+++ b/src/spicy-connect.c
@@ -18,9 +18,17 @@
 
 #include <gtk/gtk.h>
 #include <glib/gi18n.h>
+#include <gdk/gdkkeysyms.h>
 #include "spice-common.h"
 #include "spicy-connect.h"
 
+typedef struct
+{
+    gboolean connecting;
+    GMainLoop *loop;
+    SpiceSession *session;
+} ConnectionInfo;
+
 static struct {
     const char *text;
     const char *prop;
@@ -31,6 +39,43 @@ static struct {
     { .text = N_("TLS Port"),   .prop = "tls-port"  },
 };
 
+static void set_connection_info(SpiceSession *session)
+{
+    const gchar *txt;
+    int i;
+
+    for (i = 0; i < SPICE_N_ELEMENTS(connect_entries); i++) {
+        txt = gtk_entry_get_text(GTK_ENTRY(connect_entries[i].entry));
+        g_object_set(session, connect_entries[i].prop, txt, NULL);
+    }
+}
+
+static gboolean close_cb(gpointer data)
+{
+    ConnectionInfo *info = data;
+    info->connecting = FALSE;
+    if (g_main_loop_is_running(info->loop))
+        g_main_loop_quit(info->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)
 {
@@ -62,32 +107,44 @@ static void recent_selection_changed_dialog_cb(GtkRecentChooser *chooser, gpoint
 
     gtk_recent_info_unref(info);
 }
+#endif
 
-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 *info = data;
+    info->connecting = TRUE;
+    set_connection_info(info->session);
+
+    if (g_main_loop_is_running(info->loop))
+        g_main_loop_quit(info->loop);
 }
-#endif
 
-int spicy_connect_dialog(SpiceSession *session)
+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;
-    int i, retval;
+    int i;
+
+    ConnectionInfo info = {
+        FALSE,
+        NULL,
+        session
+    };
 
     /* 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);
 
@@ -107,16 +164,41 @@ int 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), &info);
+    g_signal_connect_swapped(connect_button, "clicked",
+                             G_CALLBACK(connect_cb), &info);
+    g_signal_connect_swapped(cancel_button, "clicked",
+                             G_CALLBACK(close_cb), &info);
+
 #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");
@@ -124,20 +206,22 @@ int 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), &info);
 #endif
+
+    for (i = 0; i < SPICE_N_ELEMENTS(connect_entries); i++) {
+        g_signal_connect_swapped(connect_entries[i].entry, "activate",
+                                 G_CALLBACK(connect_cb), &info);
+    }
+
     /* 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 = 0;
-    } else
-        retval = -1;
-    gtk_widget_destroy(dialog);
-    return retval;
+    gtk_widget_show_all(GTK_WIDGET(window));
+
+    info.loop = g_main_loop_new(NULL, FALSE);
+    g_main_loop_run(info.loop);
+
+    gtk_widget_destroy(GTK_WIDGET(window));
+
+    return info.connecting;
 }
diff --git a/src/spicy-connect.h b/src/spicy-connect.h
index e693f2b..56b2d80 100644
--- a/src/spicy-connect.h
+++ b/src/spicy-connect.h
@@ -21,6 +21,6 @@
 
 #include "spice-widget.h"
 
-int spicy_connect_dialog(SpiceSession *session);
+gboolean spicy_connect_dialog(SpiceSession *session);
 
 #endif
diff --git a/src/spicy.c b/src/spicy.c
index f58d33e..3442db0 100644
--- a/src/spicy.c
+++ b/src/spicy.c
@@ -1119,8 +1119,7 @@ static void main_channel_event(SpiceChannel *channel, SpiceChannelEvent event,
             g_message("channel error: %s", error->message);
         }
 
-        rc = spicy_connect_dialog(conn->session);
-        if (rc == 0) {
+        if (spicy_connect_dialog(conn->session)) {
             connection_connect(conn);
         } else {
             connection_disconnect(conn);
@@ -1699,8 +1698,7 @@ int main(int argc, char *argv[])
     /* If user doesn't provide hostname and port, show the dialog window
        instead of connecting to server automatically */
     if ((host == NULL || (port == NULL && tls_port == NULL)) && unix_path == NULL) {
-        int ret = spicy_connect_dialog(conn->session);
-        if (ret != 0) {
+        if (!spicy_connect_dialog(conn->session)) {
             exit(0);
         }
     }
commit 8a7058190a43e26d0ebec9e3e5774dcab5ec0f90
Author: Lukas Venhoda <lvenhoda at redhat.com>
Date:   Tue Jun 16 16:23:29 2015 +0200

    spicy: Move connect dialog to its own file
    
    Connect dialog from spicy is now in its own file.
    
    Renamed connect_dialog to spicy_connect_dialog.
    
    Added new file for translation.

diff --git a/po/POTFILES.in b/po/POTFILES.in
index f629270..793dd78 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -6,6 +6,7 @@ src/spice-option.c
 src/spicy-screenshot.c
 src/spicy-stats.c
 src/spicy.c
+src/spicy-connect.c
 src/usb-device-manager.c
 src/usb-device-widget.c
 src/usbutil.c
diff --git a/src/Makefile.am b/src/Makefile.am
index 25e2255..cf02198 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -379,6 +379,8 @@ endif
 
 spicy_SOURCES =					\
 	spicy.c					\
+	spicy-connect.h 			\
+	spicy-connect.c 			\
 	spice-cmdline.h				\
 	spice-cmdline.c				\
 	$(NULL)
diff --git a/src/spicy-connect.c b/src/spicy-connect.c
new file mode 100644
index 0000000..991aaab
--- /dev/null
+++ b/src/spicy-connect.c
@@ -0,0 +1,143 @@
+/* -*- Mode: C; c-basic-offset: 4; indent-tabs-mode: nil -*- */
+/*
+   Copyright (C) 2010-2015 Red Hat, Inc.
+
+   This library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   This library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with this library; if not, see <http://www.gnu.org/licenses/>.
+*/
+
+#include <gtk/gtk.h>
+#include <glib/gi18n.h>
+#include "spice-common.h"
+#include "spicy-connect.h"
+
+static struct {
+    const char *text;
+    const char *prop;
+    GtkWidget *entry;
+} connect_entries[] = {
+    { .text = N_("Hostname"),   .prop = "host"      },
+    { .text = N_("Port"),       .prop = "port"      },
+    { .text = N_("TLS Port"),   .prop = "tls-port"  },
+};
+
+#ifndef G_OS_WIN32
+static void recent_selection_changed_dialog_cb(GtkRecentChooser *chooser, gpointer data)
+{
+    GtkRecentInfo *info;
+    gchar *txt = NULL;
+    const gchar *uri;
+    SpiceSession *session = data;
+
+    info = gtk_recent_chooser_get_current_item(chooser);
+    if (info == NULL)
+        return;
+
+    uri = gtk_recent_info_get_uri(info);
+    g_return_if_fail(uri != NULL);
+
+    g_object_set(session, "uri", uri, NULL);
+
+    g_object_get(session, "host", &txt, NULL);
+    gtk_entry_set_text(GTK_ENTRY(connect_entries[0].entry), txt ? txt : "");
+    g_free(txt);
+
+    g_object_get(session, "port", &txt, NULL);
+    gtk_entry_set_text(GTK_ENTRY(connect_entries[1].entry), txt ? txt : "");
+    g_free(txt);
+
+    g_object_get(session, "tls-port", &txt, NULL);
+    gtk_entry_set_text(GTK_ENTRY(connect_entries[2].entry), txt ? txt : "");
+    g_free(txt);
+
+    gtk_recent_info_unref(info);
+}
+
+static void recent_item_activated_dialog_cb(GtkRecentChooser *chooser, gpointer data)
+{
+   gtk_dialog_response (GTK_DIALOG (data), GTK_RESPONSE_ACCEPT);
+}
+#endif
+
+int spicy_connect_dialog(SpiceSession *session)
+{
+    GtkWidget *dialog, *area, *label;
+    GtkTable *table;
+    int i, retval;
+
+    /* 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));
+    table = GTK_TABLE(gtk_table_new(3, 2, 0));
+    gtk_box_pack_start(GTK_BOX(area), GTK_WIDGET(table), TRUE, TRUE, 0);
+    gtk_table_set_row_spacings(table, 5);
+    gtk_table_set_col_spacings(table, 5);
+
+    for (i = 0; i < SPICE_N_ELEMENTS(connect_entries); i++) {
+        gchar *txt;
+        label = gtk_label_new(connect_entries[i].text);
+        gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5);
+        gtk_table_attach_defaults(table, label, 0, 1, i, i+1);
+        connect_entries[i].entry = GTK_WIDGET(gtk_entry_new());
+        gtk_table_attach_defaults(table, connect_entries[i].entry, 1, 2, i, i+1);
+        g_object_get(session, connect_entries[i].prop, &txt, NULL);
+        SPICE_DEBUG("%s: #%i [%s]: \"%s\"",
+                __FUNCTION__, i, connect_entries[i].prop, txt);
+        if (txt) {
+            gtk_entry_set_text(GTK_ENTRY(connect_entries[i].entry), txt);
+            g_free(txt);
+        }
+    }
+
+    label = gtk_label_new(_("Recent connections:"));
+    gtk_box_pack_start(GTK_BOX(area), label, TRUE, TRUE, 0);
+    gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5);
+#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);
+
+    rfilter = gtk_recent_filter_new();
+    gtk_recent_filter_add_mime_type(rfilter, "application/x-spice");
+    gtk_recent_chooser_set_filter(GTK_RECENT_CHOOSER(recent), rfilter);
+    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);
+#endif
+    /* 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 = 0;
+    } else
+        retval = -1;
+    gtk_widget_destroy(dialog);
+    return retval;
+}
diff --git a/src/spicy-connect.h b/src/spicy-connect.h
new file mode 100644
index 0000000..e693f2b
--- /dev/null
+++ b/src/spicy-connect.h
@@ -0,0 +1,26 @@
+/* -*- Mode: C; c-basic-offset: 4; indent-tabs-mode: nil -*- */
+/*
+   Copyright (C) 2010-2015 Red Hat, Inc.
+
+   This library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   This library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with this library; if not, see <http://www.gnu.org/licenses/>.
+*/
+
+#ifndef SPICY_CONNECT_H
+#define SPICY_CONNECT_H
+
+#include "spice-widget.h"
+
+int spicy_connect_dialog(SpiceSession *session);
+
+#endif
diff --git a/src/spicy.c b/src/spicy.c
index 9cd6ee5..f58d33e 100644
--- a/src/spicy.c
+++ b/src/spicy.c
@@ -38,6 +38,8 @@
 #include "spice-option.h"
 #include "usb-device-widget.h"
 
+#include "spicy-connect.h"
+
 typedef struct spice_connection spice_connection;
 
 enum {
@@ -173,129 +175,6 @@ static int ask_user(GtkWidget *parent, char *title, char *message,
     return retval;
 }
 
-static struct {
-    const char *text;
-    const char *prop;
-    GtkWidget *entry;
-} connect_entries[] = {
-    { .text = N_("Hostname"),   .prop = "host"      },
-    { .text = N_("Port"),       .prop = "port"      },
-    { .text = N_("TLS Port"),   .prop = "tls-port"  },
-};
-
-#ifndef G_OS_WIN32
-static void recent_selection_changed_dialog_cb(GtkRecentChooser *chooser, gpointer data)
-{
-    GtkRecentInfo *info;
-    gchar *txt = NULL;
-    const gchar *uri;
-    SpiceSession *session = data;
-
-    info = gtk_recent_chooser_get_current_item(chooser);
-    if (info == NULL)
-        return;
-
-    uri = gtk_recent_info_get_uri(info);
-    g_return_if_fail(uri != NULL);
-
-    g_object_set(session, "uri", uri, NULL);
-
-    g_object_get(session, "host", &txt, NULL);
-    gtk_entry_set_text(GTK_ENTRY(connect_entries[0].entry), txt ? txt : "");
-    g_free(txt);
-
-    g_object_get(session, "port", &txt, NULL);
-    gtk_entry_set_text(GTK_ENTRY(connect_entries[1].entry), txt ? txt : "");
-    g_free(txt);
-
-    g_object_get(session, "tls-port", &txt, NULL);
-    gtk_entry_set_text(GTK_ENTRY(connect_entries[2].entry), txt ? txt : "");
-    g_free(txt);
-
-    gtk_recent_info_unref(info);
-}
-
-static void recent_item_activated_dialog_cb(GtkRecentChooser *chooser, gpointer data)
-{
-   gtk_dialog_response (GTK_DIALOG (data), GTK_RESPONSE_ACCEPT);
-}
-#endif
-
-static int connect_dialog(SpiceSession *session)
-{
-    GtkWidget *dialog, *area, *label;
-    GtkTable *table;
-    int i, retval;
-
-    /* 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));
-    table = GTK_TABLE(gtk_table_new(3, 2, 0));
-    gtk_box_pack_start(GTK_BOX(area), GTK_WIDGET(table), TRUE, TRUE, 0);
-    gtk_table_set_row_spacings(table, 5);
-    gtk_table_set_col_spacings(table, 5);
-
-    for (i = 0; i < SPICE_N_ELEMENTS(connect_entries); i++) {
-        gchar *txt;
-        label = gtk_label_new(connect_entries[i].text);
-        gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5);
-        gtk_table_attach_defaults(table, label, 0, 1, i, i+1);
-        connect_entries[i].entry = GTK_WIDGET(gtk_entry_new());
-        gtk_table_attach_defaults(table, connect_entries[i].entry, 1, 2, i, i+1);
-        g_object_get(session, connect_entries[i].prop, &txt, NULL);
-        SPICE_DEBUG("%s: #%i [%s]: \"%s\"",
-                __FUNCTION__, i, connect_entries[i].prop, txt);
-        if (txt) {
-            gtk_entry_set_text(GTK_ENTRY(connect_entries[i].entry), txt);
-            g_free(txt);
-        }
-    }
-
-    label = gtk_label_new("Recent connections:");
-    gtk_box_pack_start(GTK_BOX(area), label, TRUE, TRUE, 0);
-    gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5);
-#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);
-
-    rfilter = gtk_recent_filter_new();
-    gtk_recent_filter_add_mime_type(rfilter, "application/x-spice");
-    gtk_recent_chooser_set_filter(GTK_RECENT_CHOOSER(recent), rfilter);
-    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);
-#endif
-    /* 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 = 0;
-    } else
-        retval = -1;
-    gtk_widget_destroy(dialog);
-    return retval;
-}
-
-/* ------------------------------------------------------------------ */
-
 static void update_status_window(SpiceWindow *win)
 {
     gchar *status;
@@ -1240,7 +1119,7 @@ static void main_channel_event(SpiceChannel *channel, SpiceChannelEvent event,
             g_message("channel error: %s", error->message);
         }
 
-        rc = connect_dialog(conn->session);
+        rc = spicy_connect_dialog(conn->session);
         if (rc == 0) {
             connection_connect(conn);
         } else {
@@ -1820,7 +1699,7 @@ int main(int argc, char *argv[])
     /* If user doesn't provide hostname and port, show the dialog window
        instead of connecting to server automatically */
     if ((host == NULL || (port == NULL && tls_port == NULL)) && unix_path == NULL) {
-        int ret = connect_dialog(conn->session);
+        int ret = spicy_connect_dialog(conn->session);
         if (ret != 0) {
             exit(0);
         }


More information about the Spice-commits mailing list