From 84dc778fa5901f02b0b02fb258b0e401db510c85 Mon Sep 17 00:00:00 2001 From: Ross Lagerwall Date: Sun, 4 May 2014 23:28:07 +0100 Subject: 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 file changed, 31 insertions(+) diff --git a/programs/gvfs-mount.c b/programs/gvfs-mount.c index e35fc025..69f24bda 100644 --- a/programs/gvfs-mount.c +++ b/programs/gvfs-mount.c @@ -23,6 +23,7 @@ #include +#include #include #include @@ -156,6 +157,35 @@ ask_password_cb (GMountOperation *op, g_mount_operation_reply (op, G_MOUNT_OPERATION_HANDLED); } +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, @@ -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 -- cgit v1.2.1