| File: | tests/testmountoperation.c |
| Warning: | line 148, column 11 This statement is never executed |
Press '?' to see keyboard shortcuts
Keyboard shortcuts:
| 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 <ctk/ctk.h> |
| 21 | |
| 22 | static gboolean ask_question = FALSE(0); |
| 23 | static gboolean anonymous = FALSE(0); |
| 24 | static gboolean dont_ask_username = FALSE(0); |
| 25 | static gboolean dont_ask_domain = FALSE(0); |
| 26 | static gboolean dont_ask_password = FALSE(0); |
| 27 | static gboolean dont_save_password = FALSE(0); |
| 28 | |
| 29 | |
| 30 | static void |
| 31 | got_reply (GMountOperation *op, |
| 32 | GMountOperationResult result, |
| 33 | gpointer user_data G_GNUC_UNUSED__attribute__ ((__unused__))) |
| 34 | { |
| 35 | if (result == G_MOUNT_OPERATION_HANDLED) |
| 36 | { |
| 37 | |
| 38 | if (ask_question) |
| 39 | { |
| 40 | gint choice = g_mount_operation_get_choice (op); |
| 41 | g_print ("User chose: %d\n", choice); |
| 42 | } |
| 43 | else |
| 44 | { |
| 45 | if (anonymous) |
| 46 | g_print ("Anymous: %s\n", |
| 47 | g_mount_operation_get_anonymous (op) ? "true" : "false"); |
| 48 | |
| 49 | if (!dont_ask_username) |
| 50 | g_print ("Username: %s\n", g_mount_operation_get_username (op)); |
| 51 | |
| 52 | if (!dont_ask_domain) |
| 53 | g_print ("Domain: %s\n", g_mount_operation_get_domain (op)); |
| 54 | |
| 55 | if (!dont_ask_password) |
| 56 | g_print ("Password: %s\n", g_mount_operation_get_password (op)); |
| 57 | |
| 58 | if (!dont_save_password) |
| 59 | { |
| 60 | GPasswordSave pw_save; |
| 61 | |
| 62 | pw_save = g_mount_operation_get_password_save (op); |
| 63 | g_print ("Save password: "); |
| 64 | switch (pw_save) |
| 65 | { |
| 66 | case G_PASSWORD_SAVE_NEVER: |
| 67 | g_print ("never"); |
| 68 | break; |
| 69 | |
| 70 | case G_PASSWORD_SAVE_FOR_SESSION: |
| 71 | g_print ("session"); |
| 72 | break; |
| 73 | |
| 74 | case G_PASSWORD_SAVE_PERMANENTLY: |
| 75 | g_print ("forever"); |
| 76 | break; |
| 77 | |
| 78 | default: |
| 79 | g_assert_not_reached ()do { g_assertion_message_expr (((gchar*) 0), "testmountoperation.c" , 79, ((const char*) (__func__)), ((void*)0)); } while (0); |
| 80 | } |
| 81 | g_print ("\n"); |
| 82 | } |
| 83 | } |
| 84 | } |
| 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 ()do { g_assertion_message_expr (((gchar*) 0), "testmountoperation.c" , 88, ((const char*) (__func__)), ((void*)0)); } while (0); |
| 89 | |
| 90 | ctk_main_quit (); |
| 91 | } |
| 92 | |
| 93 | int |
| 94 | main (int argc, char *argv[]) |
| 95 | { |
| 96 | GMountOperation *op; |
| 97 | gboolean force_rtl = FALSE(0); |
| 98 | GError *error = NULL((void*)0); |
| 99 | GOptionEntry options[] = { |
| 100 | { "ask-question", 'q', 0, G_OPTION_ARG_NONE, &ask_question, "Ask a question not a password.", NULL((void*)0) }, |
| 101 | { "right-to-left", 'r', 0, G_OPTION_ARG_NONE, &force_rtl, "Force right-to-left layout.", NULL((void*)0) }, |
| 102 | { "anonymous", 'a', 0, G_OPTION_ARG_NONE, &anonymous, "Anonymous login allowed.", NULL((void*)0) }, |
| 103 | { "no-username", 'u', 0, G_OPTION_ARG_NONE, &dont_ask_username, "Don't ask for the username.", NULL((void*)0) }, |
| 104 | { "no-password", 'p', 0, G_OPTION_ARG_NONE, &dont_ask_password, "Don't ask for the password.", NULL((void*)0) }, |
| 105 | { "no-domain", 'd', 0, G_OPTION_ARG_NONE, &dont_ask_domain, "Don't ask for the domain.", NULL((void*)0) }, |
| 106 | { "no-pw-save", 's', 0, G_OPTION_ARG_NONE, &dont_save_password, "Don't show password save options.", NULL((void*)0) }, |
| 107 | { NULL((void*)0) } |
| 108 | }; |
| 109 | |
| 110 | if (!ctk_init_with_args (&argc, &argv, "", options, NULL((void*)0), &error)) |
| 111 | { |
| 112 | g_print ("Failed to parse args: %s\n", error->message); |
| 113 | g_error_free (error); |
| 114 | return 1; |
| 115 | } |
| 116 | |
| 117 | if (force_rtl) |
| 118 | ctk_widget_set_default_direction (CTK_TEXT_DIR_RTL); |
| 119 | |
| 120 | op = ctk_mount_operation_new (NULL((void*)0)); |
| 121 | |
| 122 | g_signal_connect (op, "reply", G_CALLBACK (got_reply), NULL)g_signal_connect_data ((op), ("reply"), (((GCallback) (got_reply ))), (((void*)0)), ((void*)0), (GConnectFlags) 0); |
| 123 | |
| 124 | if (ask_question) |
| 125 | { |
| 126 | static const char *choices[] = { |
| 127 | "Yes", "No", "Sauerkraut", NULL((void*)0) |
| 128 | }; |
| 129 | |
| 130 | g_signal_emit_by_name (op, "ask_question", "Foo\nbar", choices); |
| 131 | } |
| 132 | else |
| 133 | { |
| 134 | GAskPasswordFlags flags; |
| 135 | |
| 136 | flags = 0; |
| 137 | |
| 138 | if (!dont_ask_password) |
| 139 | flags |= G_ASK_PASSWORD_NEED_PASSWORD; |
| 140 | |
| 141 | if (!dont_ask_username) |
| 142 | flags |= G_ASK_PASSWORD_NEED_USERNAME; |
| 143 | |
| 144 | if (!dont_ask_domain) |
| 145 | flags |= G_ASK_PASSWORD_NEED_DOMAIN; |
| 146 | |
| 147 | if (anonymous) |
| 148 | flags |= G_ASK_PASSWORD_ANONYMOUS_SUPPORTED; |
This statement is never executed | |
| 149 | |
| 150 | if (!dont_save_password) |
| 151 | flags |= G_ASK_PASSWORD_SAVING_SUPPORTED; |
| 152 | |
| 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", |
| 157 | flags); |
| 158 | } |
| 159 | |
| 160 | ctk_main (); |
| 161 | return 0; |
| 162 | } |