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
This commit is contained in:
committed by
Christian Kellner
parent
519ba608ee
commit
e1092e9a60
@ -77,6 +77,7 @@ noinst_PROGRAMS = $(TEST_PROGS) \
|
||||
testinput \
|
||||
testmenus \
|
||||
testmenubars \
|
||||
testmountoperation \
|
||||
testmultidisplay \
|
||||
testmultiscreen \
|
||||
testnotebookdnd \
|
||||
@ -150,6 +151,7 @@ testinput_DEPENDENCIES = $(TEST_DEPS)
|
||||
testimage_DEPENDENCIES = $(TEST_DEPS)
|
||||
testmenus_DEPENDENCIES = $(TEST_DEPS)
|
||||
testmenubars_DEPENDENCIES = $(TEST_DEPS)
|
||||
testmountoperation_DEPENDENCIES = $(TEST_DEPS)
|
||||
testmultidisplay_DEPENDENCIES = $(TEST_DEPS)
|
||||
testmultiscreen_DEPENDENCIES = $(TEST_DEPS)
|
||||
testnotebookdnd_DEPENDENCIES = $(TEST_DEPS)
|
||||
@ -203,6 +205,7 @@ testinput_LDADD = $(LDADDS)
|
||||
testimage_LDADD = $(LDADDS)
|
||||
testmenus_LDADD = $(LDADDS)
|
||||
testmenubars_LDADD = $(LDADDS)
|
||||
testmountoperation_LDADD = $(LDADDS)
|
||||
testmultidisplay_LDADD = $(LDADDS)
|
||||
testmultiscreen_LDADD = $(LDADDS)
|
||||
testnotebookdnd_LDADD = $(LDADDS)
|
||||
|
||||
165
tests/testmountoperation.c
Normal file
165
tests/testmountoperation.c
Normal file
@ -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;
|
||||
}
|
||||
Reference in New Issue
Block a user