[gvfs] gvfs-mount: Handle the ask-question signal



commit 84dc778fa5901f02b0b02fb258b0e401db510c85
Author: Ross Lagerwall <rosslagerwall gmail com>
Date:   Sun May 4 23:28:07 2014 +0100

    gvfs-mount: Handle the ask-question signal
    
    Present questions as a message and a numbered list of choices such
    that the user must enter one of the numbers.
    
    For example:
    """
    Can't verify the identity of ...
    This happens when you log in to a computer the first time.
    
    The identity sent by the remote computer is ... If you want to be
    absolutely sure it is safe to continue, contact the system
    administrator.
    [1] Log In Anyway
    [2] Cancel Login
    Choice: 1
    """
    
    https://bugzilla.gnome.org/show_bug.cgi?id=728959

 programs/gvfs-mount.c |   31 +++++++++++++++++++++++++++++++
 1 files changed, 31 insertions(+), 0 deletions(-)
---
diff --git a/programs/gvfs-mount.c b/programs/gvfs-mount.c
index e35fc02..69f24bd 100644
--- a/programs/gvfs-mount.c
+++ b/programs/gvfs-mount.c
@@ -23,6 +23,7 @@
 
 #include <config.h>
 
+#include <stdlib.h>
 #include <stdio.h>
 #include <string.h>
 
@@ -157,6 +158,35 @@ ask_password_cb (GMountOperation *op,
 }
 
 static void
+ask_question_cb (GMountOperation *op,
+                 char *message,
+                 char **choices,
+                 gpointer user_data)
+{
+  char **ptr = choices;
+  char *s;
+  int i, choice;
+
+  g_print ("%s\n", message);
+
+  i = 1;
+  while (*ptr)
+    {
+      g_print ("[%d] %s\n", i, *ptr++);
+      i++;
+    }
+
+  s = prompt_for ("Choice", NULL, TRUE);
+  choice = atoi (s);
+  if (choice > 0 && choice < i)
+    {
+      g_mount_operation_set_choice (op, choice - 1);
+      g_mount_operation_reply (op, G_MOUNT_OPERATION_HANDLED);
+    }
+  g_free (s);
+}
+
+static void
 mount_mountable_done_cb (GObject *object,
                          GAsyncResult *res,
                          gpointer user_data)
@@ -210,6 +240,7 @@ new_mount_op (void)
   op = g_mount_operation_new ();
 
   g_signal_connect (op, "ask_password", G_CALLBACK (ask_password_cb), NULL);
+  g_signal_connect (op, "ask_question", G_CALLBACK (ask_question_cb), NULL);
 
   /* TODO: we *should* also connect to the "aborted" signal but since the
    *       main thread is blocked handling input we won't get that signal


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]