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, write to the
17 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 * Boston, MA 02111-1307, USA.
24 static gboolean ask_question = FALSE;
25 static gboolean anonymous = FALSE;
26 static gboolean dont_ask_username = FALSE;
27 static gboolean dont_ask_domain = FALSE;
28 static gboolean dont_ask_password = FALSE;
29 static gboolean dont_save_password = FALSE;
33 got_reply (GMountOperation *op,
34 GMountOperationResult result,
37 if (result == G_MOUNT_OPERATION_HANDLED)
42 gint choice = g_mount_operation_get_choice (op);
43 g_print ("User chose: %d\n", choice);
48 g_print ("Anymous: %s\n",
49 g_mount_operation_get_anonymous (op) ? "true" : "false");
51 if (!dont_ask_username)
52 g_print ("Username: %s\n", g_mount_operation_get_username (op));
55 g_print ("Domain: %s\n", g_mount_operation_get_domain (op));
57 if (!dont_ask_password)
58 g_print ("Password: %s\n", g_mount_operation_get_password (op));
60 if (!dont_save_password)
62 GPasswordSave pw_save;
64 pw_save = g_mount_operation_get_password_save (op);
65 g_print ("Save password: ");
68 case G_PASSWORD_SAVE_NEVER:
72 case G_PASSWORD_SAVE_FOR_SESSION:
76 case G_PASSWORD_SAVE_PERMANENTLY:
81 g_assert_not_reached ();
87 else if (result == G_MOUNT_OPERATION_ABORTED)
88 g_print ("Operation aborted.\n");
89 else if (G_MOUNT_OPERATION_UNHANDLED)
90 g_assert_not_reached ();
96 main (int argc, char *argv[])
99 gboolean force_rtl = FALSE;
100 GError *error = NULL;
101 GOptionEntry options[] = {
102 { "ask-question", 'q', 0, G_OPTION_ARG_NONE, &ask_question, "Ask a question not a password.", NULL },
103 { "right-to-left", 'r', 0, G_OPTION_ARG_NONE, &force_rtl, "Force right-to-left layout.", NULL },
104 { "anonymous", 'a', 0, G_OPTION_ARG_NONE, &anonymous, "Anonymous login allowed.", NULL },
105 { "no-username", 'u', 0, G_OPTION_ARG_NONE, &dont_ask_username, "Don't ask for the username.", NULL },
106 { "no-password", 'p', 0, G_OPTION_ARG_NONE, &dont_ask_password, "Don't ask for the password.", NULL },
107 { "no-domain", 'd', 0, G_OPTION_ARG_NONE, &dont_ask_domain, "Don't ask for the domain.", NULL },
108 { "no-pw-save", 's', 0, G_OPTION_ARG_NONE, &dont_save_password, "Don't show password save options.", NULL },
112 if (!gtk_init_with_args (&argc, &argv, "", options, NULL, &error))
114 g_print ("Failed to parse args: %s\n", error->message);
115 g_error_free (error);
120 gtk_widget_set_default_direction (GTK_TEXT_DIR_RTL);
122 op = gtk_mount_operation_new (NULL);
124 g_signal_connect (op, "reply", G_CALLBACK (got_reply), NULL);
128 static const char *choices[] = {
129 "Yes", "No", "Sauerkraut", NULL
132 g_signal_emit_by_name (op, "ask_question", "Foo\nbar", choices);
136 GAskPasswordFlags flags;
140 if (!dont_ask_password)
141 flags |= G_ASK_PASSWORD_NEED_PASSWORD;
143 if (!dont_ask_username)
144 flags |= G_ASK_PASSWORD_NEED_USERNAME;
146 if (!dont_ask_domain)
147 flags |= G_ASK_PASSWORD_NEED_DOMAIN;
150 flags |= G_ASK_PASSWORD_ANONYMOUS_SUPPORTED;
152 if (!dont_save_password)
153 flags |= G_ASK_PASSWORD_SAVING_SUPPORTED;
155 g_signal_emit_by_name (op, "ask_password",
156 argc > 1 ? argv[1] : "Credentials needed",
157 argc > 2 ? argv[2] : "default user",
158 argc > 3 ? argv[3] : "default domain",