[virt-tools-list] [virt-viewer v2 1/2] Return full response from virt_viewer_auth_collect_credentials()

Victor Toso victortoso at redhat.com
Fri Jun 2 11:35:50 UTC 2017


From: Victor Toso <me at victortoso.com>

For whom is trying to collect the credentials, it might be necessary
to know if a failure is due bad user input of credentials or if the
user has cancelled or closed the dialog.

Prior to this patch anything but GTK_RESPONSE_OK was considered a
failure without any extra information.

This patch changes makes GtkResponseType be the return value of
virt_viewer_auth_collect_credentials().

The follow up patch will use this change.

Related: https://bugzilla.redhat.com/show_bug.cgi?id=1446161
Signed-off-by: Victor Toso <victortoso at redhat.com>
---
 src/remote-viewer.c             | 14 +++++++-------
 src/virt-viewer-auth.c          |  6 +++---
 src/virt-viewer-auth.h          | 10 +++++-----
 src/virt-viewer-session-spice.c | 22 +++++++++++-----------
 src/virt-viewer-session-vnc.c   | 10 +++++-----
 src/virt-viewer.c               | 10 ++++++----
 6 files changed, 37 insertions(+), 35 deletions(-)

diff --git a/src/remote-viewer.c b/src/remote-viewer.c
index 2db76bc..b6b0843 100644
--- a/src/remote-viewer.c
+++ b/src/remote-viewer.c
@@ -737,7 +737,7 @@ authenticate_cb(RestProxy *proxy, G_GNUC_UNUSED RestProxyAuth *auth,
     gchar *username = NULL;
     gchar *password = NULL;
     VirtViewerWindow *window;
-    gboolean success = FALSE;
+    GtkResponseType response;
 
     g_object_get(proxy,
                  "username", &username,
@@ -747,11 +747,11 @@ authenticate_cb(RestProxy *proxy, G_GNUC_UNUSED RestProxyAuth *auth,
         username = g_strdup(g_get_user_name());
 
     window = virt_viewer_app_get_main_window(VIRT_VIEWER_APP(user_data));
-    success = virt_viewer_auth_collect_credentials(virt_viewer_window_get_window(window),
-                                                   "oVirt",
-                                                   NULL,
-                                                   &username, &password);
-    if (success) {
+    response = virt_viewer_auth_collect_credentials(virt_viewer_window_get_window(window),
+                                                    "oVirt",
+                                                    NULL,
+                                                    &username, &password);
+    if (response == GTK_RESPONSE_OK) {
         g_object_set(G_OBJECT(proxy),
                      "username", username,
                      "password", password,
@@ -764,7 +764,7 @@ authenticate_cb(RestProxy *proxy, G_GNUC_UNUSED RestProxyAuth *auth,
 
     g_free(username);
     g_free(password);
-    return success;
+    return (response == GTK_RESPONSE_OK);
 }
 
 static void
diff --git a/src/virt-viewer-auth.c b/src/virt-viewer-auth.c
index 67c770c..aafad89 100644
--- a/src/virt-viewer-auth.c
+++ b/src/virt-viewer-auth.c
@@ -44,7 +44,7 @@ show_password(GtkCheckButton *check_button G_GNUC_UNUSED,
  * field will be pre-filled with this value. The existing string will be freed
  * before setting the output parameter to the user-entered value.
  */
-gboolean
+GtkResponseType
 virt_viewer_auth_collect_credentials(GtkWindow *window,
                                      const char *type,
                                      const char *address,
@@ -59,7 +59,7 @@ virt_viewer_auth_collect_credentials(GtkWindow *window,
     GtkWidget *promptPassword;
     GtkWidget *labelMessage;
     GtkWidget *checkPassword;
-    int response;
+    GtkResponseType response;
     char *message;
 
     dialog = GTK_WIDGET(gtk_builder_get_object(creds, "auth"));
@@ -113,7 +113,7 @@ virt_viewer_auth_collect_credentials(GtkWindow *window,
     gtk_widget_destroy(GTK_WIDGET(dialog));
     g_object_unref(G_OBJECT(creds));
 
-    return response == GTK_RESPONSE_OK;
+    return response;
 }
 
 /*
diff --git a/src/virt-viewer-auth.h b/src/virt-viewer-auth.h
index 25463fc..a748292 100644
--- a/src/virt-viewer-auth.h
+++ b/src/virt-viewer-auth.h
@@ -27,11 +27,11 @@
 
 #include "virt-viewer-session.h"
 
-gboolean virt_viewer_auth_collect_credentials(GtkWindow *window,
-                                              const char *type,
-                                              const char *address,
-                                              char **username,
-                                              char **password);
+GtkResponseType virt_viewer_auth_collect_credentials(GtkWindow *window,
+                                                     const char *type,
+                                                     const char *address,
+                                                     char **username,
+                                                     char **password);
 
 #endif
 /*
diff --git a/src/virt-viewer-session-spice.c b/src/virt-viewer-session-spice.c
index 5f326aa..0870e7f 100644
--- a/src/virt-viewer-session-spice.c
+++ b/src/virt-viewer-session-spice.c
@@ -668,7 +668,7 @@ virt_viewer_session_spice_main_channel_event(SpiceChannel *channel,
 {
     VirtViewerSessionSpice *self = VIRT_VIEWER_SESSION_SPICE(session);
     gchar *password = NULL, *user = NULL;
-    gboolean ret;
+    GtkResponseType response;
     static gboolean username_required = FALSE;
 
     g_return_if_fail(self != NULL);
@@ -717,13 +717,13 @@ virt_viewer_session_spice_main_channel_event(SpiceChannel *channel,
         }
 
         g_object_get(self->priv->session, "host", &host, NULL);
-        ret = virt_viewer_auth_collect_credentials(self->priv->main_window,
-                                                   "SPICE",
-                                                   host,
-                                                   username_required ? &user : NULL,
-                                                   &password);
+        response = virt_viewer_auth_collect_credentials(self->priv->main_window,
+                                                        "SPICE",
+                                                        host,
+                                                        username_required ? &user : NULL,
+                                                        &password);
         g_free(host);
-        if (!ret) {
+        if (response != GTK_RESPONSE_OK) {
             g_signal_emit_by_name(session, "session-cancelled");
         } else {
             gboolean openfd;
@@ -750,10 +750,10 @@ virt_viewer_session_spice_main_channel_event(SpiceChannel *channel,
             SpiceURI *proxy = spice_session_get_proxy_uri(self->priv->session);
             g_warn_if_fail(proxy != NULL);
 
-            ret = virt_viewer_auth_collect_credentials(self->priv->main_window,
-                                                       "proxy", spice_uri_get_hostname(proxy),
-                                                       &user, &password);
-            if (!ret) {
+            response = virt_viewer_auth_collect_credentials(self->priv->main_window,
+                                                            "proxy", spice_uri_get_hostname(proxy),
+                                                            &user, &password);
+            if (response != GTK_RESPONSE_OK) {
                 g_signal_emit_by_name(session, "session-cancelled");
             } else {
                 spice_uri_set_user(proxy, user);
diff --git a/src/virt-viewer-session-vnc.c b/src/virt-viewer-session-vnc.c
index 26fb405..5bd2664 100644
--- a/src/virt-viewer-session-vnc.c
+++ b/src/virt-viewer-session-vnc.c
@@ -307,12 +307,12 @@ virt_viewer_session_vnc_auth_credential(GtkWidget *src G_GNUC_UNUSED,
     }
 
     if (wantUsername || wantPassword) {
-        gboolean ret = virt_viewer_auth_collect_credentials(self->priv->main_window,
-                                                            "VNC", NULL,
-                                                            wantUsername ? &username : NULL,
-                                                            wantPassword ? &password : NULL);
+        GtkResponseType response = virt_viewer_auth_collect_credentials(self->priv->main_window,
+                                                                        "VNC", NULL,
+                                                                        wantUsername ? &username : NULL,
+                                                                        wantPassword ? &password : NULL);
 
-        if (!ret) {
+        if (response != GTK_RESPONSE_OK) {
             vnc_display_close(self->priv->vnc);
             g_signal_emit_by_name(self, "session-cancelled");
             goto cleanup;
diff --git a/src/virt-viewer.c b/src/virt-viewer.c
index 5c321db..0925494 100644
--- a/src/virt-viewer.c
+++ b/src/virt-viewer.c
@@ -988,14 +988,16 @@ virt_viewer_auth_libvirt_credentials(virConnectCredentialPtr cred,
     if (username || password) {
         VirtViewerWindow *vwin = virt_viewer_app_get_main_window(VIRT_VIEWER_APP(app));
         GtkWindow *win = virt_viewer_window_get_window(vwin);
+        GtkResponseType response;
 
         if (username && (*username == NULL || **username == '\0'))
             *username = g_strdup(g_get_user_name());
 
-        priv->auth_cancelled = !virt_viewer_auth_collect_credentials(win,
-                                                                     "libvirt",
-                                                                     app->priv->uri,
-                                                                     username, password);
+        response = virt_viewer_auth_collect_credentials(win,
+                                                        "libvirt",
+                                                        app->priv->uri,
+                                                        username, password);
+        priv->auth_cancelled = (response != GTK_RESPONSE_OK);
         if (priv->auth_cancelled) {
             ret = -1;
             goto cleanup;
-- 
2.13.0




More information about the virt-tools-list mailing list