src: cancel auth dialog when closing session

This ensures that the application exits when the user presses Ctrl-C
while an auth dialog is open.

Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
This commit is contained in:
Daniel P. Berrangé 2021-02-19 14:05:02 +00:00 committed by Daniel P. Berrangé
parent 247d91d889
commit 1d11dd55da
2 changed files with 14 additions and 6 deletions

View File

@ -44,6 +44,7 @@
struct _VirtViewerSessionSpice {
VirtViewerSession parent;
GtkWindow *main_window;
VirtViewerAuth *auth;
SpiceSession *session;
SpiceGtkSession *gtk_session;
SpiceMainChannel *main_channel;
@ -138,6 +139,7 @@ virt_viewer_session_spice_set_property(GObject *object, guint property_id,
switch (property_id) {
case PROP_MAIN_WINDOW:
self->main_window = g_value_dup_object(value);
self->auth = virt_viewer_auth_new(self->main_window);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
@ -157,6 +159,7 @@ virt_viewer_session_spice_dispose(GObject *obj)
self->audio = NULL;
gtk_widget_destroy(GTK_WIDGET(self->auth));
g_clear_object(&self->main_window);
if (self->file_transfer_dialog) {
gtk_widget_destroy(GTK_WIDGET(self->file_transfer_dialog));
@ -480,6 +483,8 @@ virt_viewer_session_spice_close(VirtViewerSession *session)
virt_viewer_session_spice_clear_displays(self);
if (self->session) {
gtk_dialog_response(GTK_DIALOG(self->auth),
GTK_RESPONSE_CANCEL);
spice_session_disconnect(self->session);
if (!self)
return;
@ -720,7 +725,6 @@ virt_viewer_session_spice_main_channel_event(SpiceChannel *channel,
{
const GError *error = NULL;
gchar *host = NULL;
VirtViewerAuth *auth = virt_viewer_auth_new(self->main_window);
g_debug("main channel: auth failure (wrong username/password?)");
error = spice_channel_get_error(channel);
@ -746,12 +750,12 @@ virt_viewer_session_spice_main_channel_event(SpiceChannel *channel,
}
g_object_get(self->session, "host", &host, NULL);
ret = virt_viewer_auth_collect_credentials(auth,
ret = virt_viewer_auth_collect_credentials(self->auth,
"SPICE",
host,
username_required ? &user : NULL,
&password);
gtk_widget_destroy(GTK_WIDGET(auth));
g_free(host);
if (!ret) {
/* ret is false when dialog did not return GTK_RESPONSE_OK. We

View File

@ -37,6 +37,7 @@
struct _VirtViewerSessionVnc {
VirtViewerSession parent;
GtkWindow *main_window;
VirtViewerAuth *auth;
/* XXX we should really just have a VncConnection */
VncDisplay *vnc;
gboolean auth_dialog_cancelled;
@ -62,6 +63,7 @@ virt_viewer_session_vnc_finalize(GObject *obj)
vnc_display_close(self->vnc);
g_object_unref(self->vnc);
}
gtk_widget_destroy(GTK_WIDGET(self->auth));
if (self->main_window)
g_object_unref(self->main_window);
g_free(self->error_msg);
@ -324,12 +326,10 @@ virt_viewer_session_vnc_auth_credential(GtkWidget *src G_GNUC_UNUSED,
}
if (wantUsername || wantPassword) {
VirtViewerAuth *auth = virt_viewer_auth_new(self->main_window);
gboolean ret = virt_viewer_auth_collect_credentials(auth,
gboolean ret = virt_viewer_auth_collect_credentials(self->auth,
"VNC", NULL,
wantUsername ? &username : NULL,
wantPassword ? &password : NULL);
gtk_widget_destroy(GTK_WIDGET(auth));
if (!ret) {
vnc_display_close(self->vnc);
@ -389,6 +389,9 @@ virt_viewer_session_vnc_close(VirtViewerSession* session)
g_debug("close vnc=%p", self->vnc);
if (self->vnc != NULL) {
gtk_dialog_response(GTK_DIALOG(self->auth),
GTK_RESPONSE_CANCEL);
virt_viewer_session_clear_displays(session);
vnc_display_close(self->vnc);
g_object_unref(self->vnc);
@ -430,6 +433,7 @@ virt_viewer_session_vnc_new(VirtViewerApp *app, GtkWindow *main_window)
self->vnc = VNC_DISPLAY(vnc_display_new());
g_object_ref_sink(self->vnc);
self->main_window = g_object_ref(main_window);
self->auth = virt_viewer_auth_new(self->main_window);
vnc_display_set_shared_flag(self->vnc,
virt_viewer_app_get_shared(app));