Commit ae982e9d authored by Jeremy White's avatar Jeremy White

Implement the disconnect button.

parent f3d2cf29
......@@ -26,6 +26,7 @@
** loop, which is one of the main running threads of the x11spice program.
**--------------------------------------------------------------------------*/
#include "gui.h"
#include "session.h"
#include "x11spice.h"
gui_t *cached_gui;
......@@ -45,7 +46,6 @@ void gui_remote_connected(gui_t *gui, const char *details)
g_source_remove(gui->timeout_id);
gui->timeout_id = 0;
}
// FIXME - disconnect should do something, but that looks hard
}
void gui_remote_disconnected(gui_t *gui)
......@@ -54,6 +54,12 @@ void gui_remote_disconnected(gui_t *gui)
gtk_widget_set_sensitive(gui->disconnect_button, FALSE);
}
void gui_disconnect_clicked(GtkWidget *widget, gpointer data)
{
gui_t *gui = (gui_t *)data;
session_disconnect_client(gui->session);
}
static gboolean timeout_if_no_connection(gpointer user_data)
{
g_debug("Timeout waiting for connection.");
......@@ -61,11 +67,12 @@ static gboolean timeout_if_no_connection(gpointer user_data)
return FALSE;
}
int gui_create(gui_t *gui, int argc, char *argv[], int minimize, int hidden, int timeout)
int gui_create(gui_t *gui, session_t *session, int argc, char *argv[])
{
if (!gtk_init_check(&argc, &argv))
return X11SPICE_ERR_GTK_FAILED;
gui->session = session;
gui->window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
g_signal_connect(gui->window, "destroy", G_CALLBACK(gui_sigterm), NULL);
......@@ -77,6 +84,7 @@ int gui_create(gui_t *gui, int argc, char *argv[], int minimize, int hidden, int
gui->disconnect_button = gtk_button_new_from_stock(GTK_STOCK_DISCONNECT);
gtk_container_add(GTK_CONTAINER(gui->button_box), gui->disconnect_button);
g_signal_connect(gui->disconnect_button, "clicked", G_CALLBACK(gui_disconnect_clicked), gui);
gui_remote_disconnected(gui);
gui->quit_button = gtk_button_new_from_stock(GTK_STOCK_QUIT);
......@@ -89,13 +97,15 @@ int gui_create(gui_t *gui, int argc, char *argv[], int minimize, int hidden, int
gtk_widget_show(gui->quit_button);
gtk_widget_show(gui->button_box);
if (!hidden)
if (!session->options.hide)
gtk_widget_show(gui->window);
if (minimize)
if (session->options.minimize)
gtk_window_iconify(GTK_WINDOW(gui->window));
if (timeout)
gui->timeout_id = g_timeout_add_seconds(timeout, timeout_if_no_connection, gui);
gui->timeout_id = 0;
if (session->options.timeout)
gui->timeout_id = g_timeout_add_seconds(session->options.timeout,
timeout_if_no_connection, gui);
return 0;
}
......
......@@ -23,6 +23,8 @@
#include <gtk/gtk.h>
typedef struct session_struct session_t;
/*----------------------------------------------------------------------------
** Structure definitions
**--------------------------------------------------------------------------*/
......@@ -32,13 +34,14 @@ typedef struct {
GtkWidget *quit_button;
GtkWidget *disconnect_button;
GtkWidget *status_label;
session_t *session;
int timeout_id;
} gui_t;
/*----------------------------------------------------------------------------
** Prototypes
**--------------------------------------------------------------------------*/
int gui_create(gui_t *gui, int argc, char *argv[], int minimize, int hidden, int timeout);
int gui_create(gui_t *gui, session_t *session, int argc, char *argv[]);
void gui_sigterm(void);
void gui_run(gui_t *gui);
void gui_destroy(gui_t *gui);
......
......@@ -95,8 +95,7 @@ int main(int argc, char *argv[])
/*------------------------------------------------------------------------
** Initialize the GUI
**----------------------------------------------------------------------*/
rc = gui_create(&session.gui, argc, argv, session.options.minimize,
session.options.hide, session.options.timeout);
rc = gui_create(&session.gui, &session, argc, argv);
if (rc)
goto exit;
gui_created = 1;
......
......@@ -47,7 +47,7 @@
** So we use this global variable to enable the use of the session connect
** and disconnect notices from spice
----------------------------------------------------------------------------*/
session_t *global_session;
session_t *global_session = NULL;
void free_cursor_queue_item(gpointer data)
......@@ -354,6 +354,18 @@ int session_get_one_led(session_t *session, const char *name)
return ret;
}
void session_disconnect_client(session_t *session)
{
/*
** TODO: This is using a side effect of set_ticket that is not intentional.
** It would be better to ask for a deliberate method of achieving this result.
*/
g_debug("client disconnect");
spice_server_set_ticket(session->spice.server, session->options.spice_password, 0, 0, TRUE);
if (! session->options.spice_password || session->options.disable_ticketing)
spice_server_set_noauth(session->spice.server);
}
void session_remote_connected(const char *from)
{
if (!global_session)
......
......@@ -78,4 +78,5 @@ int session_push_cursor_image(session_t *s,
void session_remote_connected(const char *from);
void session_remote_disconnected(void);
void session_disconnect_client(session_t *session);
#endif
......@@ -657,10 +657,10 @@ void spice_end(spice_t *s)
spice_server_remove_interface(&s->keyboard_sin.base);
spice_server_remove_interface(&s->display_sin.base);
spice_destroy_primary(s);
spice_server_destroy(s->server);
// FIXME - can't always destroy...
spice_destroy_primary(s);
}
spice_release_t *spice_create_release(spice_t *s, release_type_t type, void *data)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment