2 * Copyright (C) 2008 Christian Kellner
3 * Author: Christian Kellner <gicmo@gnome.org>
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Library General Public
7 * License as published by the Free Software Foundation; either
8 * version 2 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Library General Public License for more details.
15 * You should have received a copy of the GNU Library General Public
16 * License along with this library. If not, see <http://www.gnu.org/licenses/>.
22 static gboolean ask_question = FALSE;
23 static gboolean anonymous = FALSE;
24 static gboolean dont_ask_username = FALSE;
25 static gboolean dont_ask_domain = FALSE;
26 static gboolean dont_ask_password = FALSE;
27 static gboolean dont_save_password = FALSE;
31 got_reply (GMountOperation *op,
32 GMountOperationResult result,
35 if (result == G_MOUNT_OPERATION_HANDLED)
40 gint choice = g_mount_operation_get_choice (op);
41 g_print ("User chose: %d\n", choice);
46 g_print ("Anymous: %s\n",
47 g_mount_operation_get_anonymous (op) ? "true" : "false");
49 if (!dont_ask_username)
50 g_print ("Username: %s\n", g_mount_operation_get_username (op));
53 g_print ("Domain: %s\n", g_mount_operation_get_domain (op));
55 if (!dont_ask_password)
56 g_print ("Password: %s\n", g_mount_operation_get_password (op));
58 if (!dont_save_password)
60 GPasswordSave pw_save;
62 pw_save = g_mount_operation_get_password_save (op);
63 g_print ("Save password: ");
66 case G_PASSWORD_SAVE_NEVER:
70 case G_PASSWORD_SAVE_FOR_SESSION:
74 case G_PASSWORD_SAVE_PERMANENTLY:
79 g_assert_not_reached ();
85 else if (result == G_MOUNT_OPERATION_ABORTED)
86 g_print ("Operation aborted.\n");
87 else if (G_MOUNT_OPERATION_UNHANDLED)
88 g_assert_not_reached ();
94 main (int argc, char *argv[])
97 gboolean force_rtl = FALSE;
99 GOptionEntry options[] = {
100 { "ask-question", 'q', 0, G_OPTION_ARG_NONE, &ask_question, "Ask a question not a password.", NULL },
101 { "right-to-left", 'r', 0, G_OPTION_ARG_NONE, &force_rtl, "Force right-to-left layout.", NULL },
102 { "anonymous", 'a', 0, G_OPTION_ARG_NONE, &anonymous, "Anonymous login allowed.", NULL },
103 { "no-username", 'u', 0, G_OPTION_ARG_NONE, &dont_ask_username, "Don't ask for the username.", NULL },
104 { "no-password", 'p', 0, G_OPTION_ARG_NONE, &dont_ask_password, "Don't ask for the password.", NULL },
105 { "no-domain", 'd', 0, G_OPTION_ARG_NONE, &dont_ask_domain, "Don't ask for the domain.", NULL },
106 { "no-pw-save", 's', 0, G_OPTION_ARG_NONE, &dont_save_password, "Don't show password save options.", NULL },
110 if (!gtk_init_with_args (&argc, &argv, "", options, NULL, &error))
112 g_print ("Failed to parse args: %s\n", error->message);
113 g_error_free (error);
118 gtk_widget_set_default_direction (GTK_TEXT_DIR_RTL);
120 op = gtk_mount_operation_new (NULL);
122 g_signal_connect (op, "reply", G_CALLBACK (got_reply), NULL);
126 static const char *choices[] = {
127 "Yes", "No", "Sauerkraut", NULL
130 g_signal_emit_by_name (op, "ask_question", "Foo\nbar", choices);
134 GAskPasswordFlags flags;
138 if (!dont_ask_password)
139 flags |= G_ASK_PASSWORD_NEED_PASSWORD;
141 if (!dont_ask_username)
142 flags |= G_ASK_PASSWORD_NEED_USERNAME;
144 if (!dont_ask_domain)
145 flags |= G_ASK_PASSWORD_NEED_DOMAIN;
148 flags |= G_ASK_PASSWORD_ANONYMOUS_SUPPORTED;
150 if (!dont_save_password)
151 flags |= G_ASK_PASSWORD_SAVING_SUPPORTED;
153 g_signal_emit_by_name (op, "ask_password",
154 argc > 1 ? argv[1] : "Credentials needed",
155 argc > 2 ? argv[2] : "default user",
156 argc > 3 ? argv[3] : "default domain",