1 | /* testmultidisplay.c |
2 | * Copyright (C) 2008 Christian Kellner |
3 | * Author: Christian Kellner <gicmo@gnome.org> |
4 | * |
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. |
9 | * |
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. |
14 | * |
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/>. |
17 | */ |
18 | |
19 | #include "config.h" |
20 | #include <gtk/gtk.h> |
21 | |
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; |
28 | |
29 | static gboolean done = FALSE; |
30 | |
31 | static void |
32 | got_reply (GMountOperation *op, |
33 | GMountOperationResult result, |
34 | gpointer user_data) |
35 | { |
36 | if (result == G_MOUNT_OPERATION_HANDLED) |
37 | { |
38 | |
39 | if (ask_question) |
40 | { |
41 | int choice = g_mount_operation_get_choice (op); |
42 | g_print (format: "User chose: %d\n" , choice); |
43 | } |
44 | else |
45 | { |
46 | if (anonymous) |
47 | g_print (format: "Anymous: %s\n" , |
48 | g_mount_operation_get_anonymous (op) ? "true" : "false" ); |
49 | |
50 | if (!dont_ask_username) |
51 | g_print (format: "Username: %s\n" , g_mount_operation_get_username (op)); |
52 | |
53 | if (!dont_ask_domain) |
54 | g_print (format: "Domain: %s\n" , g_mount_operation_get_domain (op)); |
55 | |
56 | if (!dont_ask_password) |
57 | g_print (format: "Password: %s\n" , g_mount_operation_get_password (op)); |
58 | |
59 | if (!dont_save_password) |
60 | { |
61 | GPasswordSave pw_save; |
62 | |
63 | pw_save = g_mount_operation_get_password_save (op); |
64 | g_print (format: "Save password: " ); |
65 | switch (pw_save) |
66 | { |
67 | case G_PASSWORD_SAVE_NEVER: |
68 | g_print (format: "never" ); |
69 | break; |
70 | |
71 | case G_PASSWORD_SAVE_FOR_SESSION: |
72 | g_print (format: "session" ); |
73 | break; |
74 | |
75 | case G_PASSWORD_SAVE_PERMANENTLY: |
76 | g_print (format: "forever" ); |
77 | break; |
78 | |
79 | default: |
80 | g_assert_not_reached (); |
81 | } |
82 | g_print (format: "\n" ); |
83 | } |
84 | } |
85 | } |
86 | else if (result == G_MOUNT_OPERATION_ABORTED) |
87 | g_print (format: "Operation aborted.\n" ); |
88 | else if (G_MOUNT_OPERATION_UNHANDLED) |
89 | g_assert_not_reached (); |
90 | |
91 | done = TRUE; |
92 | g_main_context_wakeup (NULL); |
93 | } |
94 | |
95 | int |
96 | main (int argc, char *argv[]) |
97 | { |
98 | GMountOperation *op; |
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 }, |
109 | { NULL } |
110 | }; |
111 | GOptionContext *context; |
112 | |
113 | context = g_option_context_new (parameter_string: "" ); |
114 | g_option_context_add_main_entries (context, entries: options, NULL); |
115 | if (!g_option_context_parse (context, argc: &argc, argv: &argv, error: &error)) |
116 | { |
117 | g_print (format: "Failed to parse args: %s\n" , error->message); |
118 | g_error_free (error); |
119 | return 1; |
120 | } |
121 | g_option_context_free (context); |
122 | |
123 | gtk_init (); |
124 | |
125 | if (force_rtl) |
126 | gtk_widget_set_default_direction (dir: GTK_TEXT_DIR_RTL); |
127 | |
128 | op = gtk_mount_operation_new (NULL); |
129 | |
130 | g_signal_connect (op, "reply" , G_CALLBACK (got_reply), NULL); |
131 | |
132 | if (ask_question) |
133 | { |
134 | static const char *choices[] = { |
135 | "Yes" , "No" , "Sauerkraut" , NULL |
136 | }; |
137 | |
138 | g_signal_emit_by_name (instance: op, detailed_signal: "ask_question" , "Foo\nbar" , choices); |
139 | } |
140 | else |
141 | { |
142 | GAskPasswordFlags flags; |
143 | |
144 | flags = 0; |
145 | |
146 | if (!dont_ask_password) |
147 | flags |= G_ASK_PASSWORD_NEED_PASSWORD; |
148 | |
149 | if (!dont_ask_username) |
150 | flags |= G_ASK_PASSWORD_NEED_USERNAME; |
151 | |
152 | if (!dont_ask_domain) |
153 | flags |= G_ASK_PASSWORD_NEED_DOMAIN; |
154 | |
155 | if (anonymous) |
156 | flags |= G_ASK_PASSWORD_ANONYMOUS_SUPPORTED; |
157 | |
158 | if (!dont_save_password) |
159 | flags |= G_ASK_PASSWORD_SAVING_SUPPORTED; |
160 | |
161 | g_signal_emit_by_name (instance: op, detailed_signal: "ask_password" , |
162 | argc > 1 ? argv[1] : "Credentials needed" , |
163 | argc > 2 ? argv[2] : "default user" , |
164 | argc > 3 ? argv[3] : "default domain" , |
165 | flags); |
166 | } |
167 | |
168 | while (!done) |
169 | g_main_context_iteration (NULL, TRUE); |
170 | return 0; |
171 | } |
172 | |