summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLukas Venhoda <lvenhoda@redhat.com>2015-06-18 16:35:24 +0200
committerChristophe Fergeau <cfergeau@redhat.com>2015-06-18 17:06:42 +0200
commit4f7605a35f1ba99a8d10a42873f5d1515043a7c2 (patch)
tree6bca545e745cd9575f9ecbbbbe298a3eb315bde8
parent8a7058190a43e26d0ebec9e3e5774dcab5ec0f90 (diff)
downloadspice-gtk-4f7605a35f1ba99a8d10a42873f5d1515043a7c2.tar.gz
spice-gtk-4f7605a35f1ba99a8d10a42873f5d1515043a7c2.tar.xz
spice-gtk-4f7605a35f1ba99a8d10a42873f5d1515043a7c2.zip
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.
-rw-r--r--src/spicy-connect.c150
-rw-r--r--src/spicy-connect.h2
-rw-r--r--src/spicy.c6
3 files changed, 120 insertions, 38 deletions
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);
}
}