diff options
author | Christian Kellner <gicmo@gnome.org> | 2008-03-17 17:29:55 +0000 |
---|---|---|
committer | Christian Kellner <gicmo@src.gnome.org> | 2008-03-17 17:29:55 +0000 |
commit | e1092e9a60c6ff1faa8cf0e89f3d39ee334e17cd (patch) | |
tree | 304b8cda58a9dc2f8ea653cbef711d4370b5aa60 /tests/testmountoperation.c | |
parent | 519ba608ee8d8f954e2421254b6c7272750e2d6e (diff) | |
download | gtk+-e1092e9a60c6ff1faa8cf0e89f3d39ee334e17cd.tar.gz |
Implement GtkMountOperation, a subclass of GMountOperation to be used with
2008-03-17 Christian Kellner <gicmo@gnome.org>
Implement GtkMountOperation, a subclass of GMountOperation
to be used with gio wherever there is the need to ask the
user for credentials or questions while mounting a volume.
This is bug #522245
* gtk/gtkmountoperation.c:
* gtk/gtkmountoperation.h:
Implement GtkMountOperation.
* gtk/gtk.h: Add gtkmountoperation.h
* gtk/Makefile.am: Add gtkmountoperation.[hc]
* gtk/gtk.symbols: Add symbols of GtkMountOperation.
* tests/testmountoperation.c: Test program for it.
* tests/Makefile.am: Add testmountoperation.
svn path=/trunk/; revision=19894
Diffstat (limited to 'tests/testmountoperation.c')
-rw-r--r-- | tests/testmountoperation.c | 165 |
1 files changed, 165 insertions, 0 deletions
diff --git a/tests/testmountoperation.c b/tests/testmountoperation.c new file mode 100644 index 0000000000..92edf3324e --- /dev/null +++ b/tests/testmountoperation.c @@ -0,0 +1,165 @@ +/* testmultidisplay.c + * Copyright (C) 2008 Christian Kellner + * Author: Christian Kellner <gicmo@gnome.org> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public + * License along with this library; if not, write to the + * Free Software Foundation, Inc., 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + */ + +#include <config.h> +#include <gtk/gtk.h> +#include <gtk/gtkmountoperation.h> + +static gboolean ask_question = FALSE; +static gboolean anonymous = FALSE; +static gboolean dont_ask_username = FALSE; +static gboolean dont_ask_domain = FALSE; +static gboolean dont_ask_password = FALSE; +static gboolean dont_save_password = FALSE; + + +static void +got_reply (GMountOperation *op, + GMountOperationResult result, + gpointer user_data) +{ + if (result == G_MOUNT_OPERATION_HANDLED) + { + + if (ask_question) + { + gint choice = g_mount_operation_get_choice (op); + g_print ("User chose: %d\n", choice); + } + else + { + if (anonymous) + g_print ("Anymous: %s\n", + g_mount_operation_get_anonymous (op) ? "true" : "false"); + + if (!dont_ask_username) + g_print ("Username: %s\n", g_mount_operation_get_username (op)); + + if (!dont_ask_domain) + g_print ("Domain: %s\n", g_mount_operation_get_domain (op)); + + if (!dont_ask_password) + g_print ("Password: %s\n", g_mount_operation_get_password (op)); + + if (!dont_save_password) + { + GPasswordSave pw_save; + + pw_save = g_mount_operation_get_password_save (op); + g_print ("Save password: "); + switch (pw_save) + { + case G_PASSWORD_SAVE_NEVER: + g_print ("never"); + break; + + case G_PASSWORD_SAVE_FOR_SESSION: + g_print ("session"); + break; + + case G_PASSWORD_SAVE_PERMANENTLY: + g_print ("forever"); + break; + + default: + g_assert_not_reached (); + } + g_print ("\n"); + } + } + } + else if (result == G_MOUNT_OPERATION_ABORTED) + g_print ("Operation aborted.\n"); + else if (G_MOUNT_OPERATION_UNHANDLED) + g_assert_not_reached (); + + gtk_main_quit (); +} + +int +main (int argc, char *argv[]) +{ + GMountOperation *op; + gboolean force_rtl = FALSE; + GError *error = NULL; + GOptionEntry options[] = { + { "ask-question", 'q', 0, G_OPTION_ARG_NONE, &ask_question, "Ask a question not a password.", NULL }, + { "right-to-left", 'r', 0, G_OPTION_ARG_NONE, &force_rtl, "Force right-to-left layout.", NULL }, + { "anonymous", 'a', 0, G_OPTION_ARG_NONE, &anonymous, "Anonymous login allowed.", NULL }, + { "no-username", 'u', 0, G_OPTION_ARG_NONE, &dont_ask_username, "Don't ask for the username.", NULL }, + { "no-password", 'p', 0, G_OPTION_ARG_NONE, &dont_ask_password, "Don't ask for the password.", NULL }, + { "no-domain", 'd', 0, G_OPTION_ARG_NONE, &dont_ask_domain, "Don't ask for the domain.", NULL }, + { "no-pw-save", 's', 0, G_OPTION_ARG_NONE, &dont_save_password, "Don't show password save options.", NULL }, + { NULL } + }; + + if (!gtk_init_with_args (&argc, &argv, "", options, NULL, &error)) + { + g_print ("Failed to parse args: %s\n", error->message); + g_error_free (error); + return 1; + } + + if (force_rtl) + gtk_widget_set_default_direction (GTK_TEXT_DIR_RTL); + + op = gtk_mount_operation_new (NULL); + + g_signal_connect (op, "reply", G_CALLBACK (got_reply), NULL); + + if (ask_question) + { + static const char *choices[] = { + "Yes", "No", "Sauerkraut", NULL + }; + + g_signal_emit_by_name (op, "ask_question", "Foo\nbar", choices); + } + else + { + GAskPasswordFlags flags; + + flags = 0; + + if (!dont_ask_password) + flags |= G_ASK_PASSWORD_NEED_PASSWORD; + + if (!dont_ask_username) + flags |= G_ASK_PASSWORD_NEED_USERNAME; + + if (!dont_ask_domain) + flags |= G_ASK_PASSWORD_NEED_DOMAIN; + + if (anonymous) + flags |= G_ASK_PASSWORD_ANONYMOUS_SUPPORTED; + + if (!dont_save_password) + flags |= G_ASK_PASSWORD_SAVING_SUPPORTED; + + g_signal_emit_by_name (op, "ask_password", + argc > 1 ? argv[1] : "Credentials needed", + argc > 2 ? argv[2] : "default user", + argc > 3 ? argv[3] : "default domain", + flags); + } + + gtk_main (); + return 0; +} |