Branch data Line data Source code
1 : : /* 2 : : * gnome-keyring 3 : : * 4 : : * Copyright (C) 2011 Collabora Ltd. 5 : : * 6 : : * This program is free software; you can redistribute it and/or modify 7 : : * it under the terms of the GNU Lesser General Public License as 8 : : * published by the Free Software Foundation; either version 2.1 of 9 : : * the License, or (at your option) any later version. 10 : : * 11 : : * This program is distributed in the hope that it will be useful, but 12 : : * WITHOUT ANY WARRANTY; without even the implied warranty of 13 : : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 : : * Lesser General Public License for more details. 15 : : * 16 : : * You should have received a copy of the GNU Lesser General Public 17 : : * License along with this program; if not, see <http://www.gnu.org/licenses/>. 18 : : * 19 : : * Author: Stef Walter <stefw@collabora.co.uk> 20 : : */ 21 : : 22 : : #include "config.h" 23 : : 24 : : #include "gcr-import-interaction.h" 25 : : 26 : : /** 27 : : * GcrImportInteraction: 28 : : * 29 : : * This is an interface implemented by a caller performing an import. It allows 30 : : * the importer to ask the caller for further information about the import. 31 : : * 32 : : * It must be implemented on a derived class of [class@Gio.TlsInteraction] 33 : : */ 34 : : 35 : : /** 36 : : * GcrImportInteractionInterface: 37 : : * @parent: parent interface 38 : : * @supplement_prep: method which prepares for supplementing the given attributes before import 39 : : * @supplement: method which synchronously supplements attributes before import 40 : : * @supplement_async: method which asynchronously supplements attributes before import 41 : : * @supplement_finish: method which completes @supplement_async 42 : : * 43 : : * Interface implemented by implementations of [iface@ImportInteraction]. 44 : : */ 45 : : 46 [ # # # # : 0 : G_DEFINE_INTERFACE (GcrImportInteraction, gcr_import_interaction, G_TYPE_TLS_INTERACTION); # # # # ] 47 : : 48 : : static void 49 : 0 : gcr_import_interaction_default_init (GcrImportInteractionInterface *iface) 50 : : { 51 : 0 : } 52 : : 53 : : /** 54 : : * gcr_import_interaction_supplement_prep: 55 : : * @interaction: the interaction 56 : : * @builder: attributes to supplement 57 : : * 58 : : * Prepare for supplementing the given attributes before import. This means 59 : : * prompting the user for things like labels and the like. The attributes 60 : : * will contain attributes for values that the importer needs, either empty 61 : : * or prefilled with suggested values. 62 : : * 63 : : * This method does not prompt the user, but rather just prepares the 64 : : * interaction that these are the attributes that are needed. 65 : : */ 66 : : void 67 : 0 : gcr_import_interaction_supplement_prep (GcrImportInteraction *interaction, 68 : : GckBuilder *builder) 69 : : { 70 : : GcrImportInteractionInterface *iface; 71 : : 72 [ # # ]: 0 : g_return_if_fail (GCR_IS_IMPORT_INTERACTION (interaction)); 73 [ # # ]: 0 : g_return_if_fail (builder != NULL); 74 : : 75 : 0 : iface = GCR_IMPORT_INTERACTION_GET_IFACE (interaction); 76 [ # # ]: 0 : if (iface->supplement != NULL) 77 : 0 : (iface->supplement_prep) (interaction, builder); 78 : : } 79 : : 80 : : /** 81 : : * gcr_import_interaction_supplement: 82 : : * @interaction: the interaction 83 : : * @builder: supplemented attributes 84 : : * @cancellable: optional cancellable object 85 : : * @error: location to store error on failure 86 : : * 87 : : * Supplement attributes before import. This means prompting the user for 88 : : * things like labels and the like. The needed attributes will have been passed 89 : : * to gcr_import_interaction_supplement_prep(). 90 : : * 91 : : * This method prompts the user and fills in the attributes. If the user or 92 : : * cancellable cancels the operation the error should be set with %G_IO_ERROR_CANCELLED. 93 : : * 94 : : * Returns: %G_TLS_INTERACTION_HANDLED if successful or %G_TLS_INTERACTION_FAILED 95 : : */ 96 : : GTlsInteractionResult 97 : 0 : gcr_import_interaction_supplement (GcrImportInteraction *interaction, 98 : : GckBuilder *builder, 99 : : GCancellable *cancellable, 100 : : GError **error) 101 : : { 102 : : GcrImportInteractionInterface *iface; 103 : : 104 [ # # ]: 0 : g_return_val_if_fail (GCR_IS_IMPORT_INTERACTION (interaction), G_TLS_INTERACTION_UNHANDLED); 105 [ # # ]: 0 : g_return_val_if_fail (builder != NULL, G_TLS_INTERACTION_UNHANDLED); 106 [ # # # # : 0 : g_return_val_if_fail (cancellable == NULL || G_IS_CANCELLABLE (cancellable), G_TLS_INTERACTION_UNHANDLED); # # # # # # ] 107 [ # # # # ]: 0 : g_return_val_if_fail (error == NULL || *error == NULL, G_TLS_INTERACTION_UNHANDLED); 108 : : 109 : 0 : iface = GCR_IMPORT_INTERACTION_GET_IFACE (interaction); 110 [ # # ]: 0 : g_return_val_if_fail (iface->supplement != NULL, G_TLS_INTERACTION_UNHANDLED); 111 : : 112 : 0 : return (iface->supplement) (interaction, builder, cancellable, error); 113 : : } 114 : : 115 : : 116 : : /** 117 : : * gcr_import_interaction_supplement_async: 118 : : * @interaction: the interaction 119 : : * @builder: supplemented attributes 120 : : * @cancellable: optional cancellable object 121 : : * @callback: called when the operation completes 122 : : * @user_data: data to be passed to the callback 123 : : * 124 : : * Asynchronously supplement attributes before import. This means prompting the 125 : : * user for things like labels and the like. The needed attributes will have 126 : : * been passed to gcr_import_interaction_supplement_prep(). 127 : : * 128 : : * This method prompts the user and fills in the attributes. 129 : : */ 130 : : void 131 : 0 : gcr_import_interaction_supplement_async (GcrImportInteraction *interaction, 132 : : GckBuilder *builder, 133 : : GCancellable *cancellable, 134 : : GAsyncReadyCallback callback, 135 : : gpointer user_data) 136 : : { 137 : : GcrImportInteractionInterface *iface; 138 : : 139 [ # # ]: 0 : g_return_if_fail (GCR_IS_IMPORT_INTERACTION (interaction)); 140 [ # # ]: 0 : g_return_if_fail (builder != NULL); 141 [ # # # # : 0 : g_return_if_fail (cancellable == NULL || G_IS_CANCELLABLE (cancellable)); # # # # # # ] 142 : : 143 : 0 : iface = GCR_IMPORT_INTERACTION_GET_IFACE (interaction); 144 [ # # ]: 0 : g_return_if_fail (iface->supplement != NULL); 145 : : 146 : 0 : (iface->supplement_async) (interaction, builder, cancellable, callback, user_data); 147 : : } 148 : : 149 : : /** 150 : : * gcr_import_interaction_supplement_finish: 151 : : * @interaction: the interaction 152 : : * @result: the asynchronous result 153 : : * @error: location to place an error on failure 154 : : * 155 : : * Complete operation to asynchronously supplement attributes before import. 156 : : * 157 : : * If the user or cancellable cancels the operation the error should be set 158 : : * with %G_IO_ERROR_CANCELLED. 159 : : * 160 : : * Returns: %G_TLS_INTERACTION_HANDLED if successful or %G_TLS_INTERACTION_FAILED 161 : : */ 162 : : GTlsInteractionResult 163 : 0 : gcr_import_interaction_supplement_finish (GcrImportInteraction *interaction, 164 : : GAsyncResult *result, 165 : : GError **error) 166 : : { 167 : : GcrImportInteractionInterface *iface; 168 : : 169 [ # # ]: 0 : g_return_val_if_fail (GCR_IS_IMPORT_INTERACTION (interaction), G_TLS_INTERACTION_UNHANDLED); 170 [ # # # # : 0 : g_return_val_if_fail (G_IS_ASYNC_RESULT (result), G_TLS_INTERACTION_UNHANDLED); # # # # ] 171 [ # # # # ]: 0 : g_return_val_if_fail (error == NULL || *error == NULL, G_TLS_INTERACTION_UNHANDLED); 172 : : 173 : 0 : iface = GCR_IMPORT_INTERACTION_GET_IFACE (interaction); 174 [ # # ]: 0 : g_return_val_if_fail (iface->supplement != NULL, G_TLS_INTERACTION_UNHANDLED); 175 : : 176 : 0 : return (iface->supplement_finish) (interaction, result, error); 177 : : }