4
* Copyright (C) 2011 Stefan Walter
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.
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.
16
* You should have received a copy of the GNU Lesser General Public
17
* License along with this program; if not, write to the Free Software
18
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
21
* Author: Stef Walter <stef@thewalter.net>
26
#include "gcr-prompt.h"
28
#include <glib/gi18n-lib.h>
33
* @short_description: a user prompt
35
* A #GcrPrompt represents a prompt displayed to the user. It is an interface
36
* with various implementations.
38
* Various properties are set on the prompt, and then the prompt is displayed
39
* the various prompt methods like gcr_prompt_password_run().
41
* A #GcrPrompt may be used to display multiple related prompts. Most
42
* implemantions do not hide the window between display of multiple related
43
* prompts, and the #GcrPrompt must be closed or destroyed in order to make
44
* it go away. This allows the user to see that the prompts are related.
46
* Use #GcrPromptDialog to create an in-process GTK+ dialog prompt. Use
47
* #GcrSystemPrompt to create a system prompt in a prompter process.
49
* The prompt implementation will always display the GcrPrompt:message property,
50
* but may choose not to display the GcrPrompt:description or GcrPrompt:title
57
* Represents a #GcrPrompt displayed to the user.
62
* @parent_iface: parent interface
63
* @prompt_password_async: begin a password prompt
64
* @prompt_password_finish: complete a password prompt
65
* @prompt_confirm_async: begin a confirm prompt
66
* @prompt_confirm_finish: complete a confirm prompt
68
* The interface for implementing #GcrPrompt.
73
* @GCR_PROMPT_REPLY_CONTINUE: the user replied with 'ok'
74
* @GCR_PROMPT_REPLY_CANCEL: the prompt was cancelled
76
* Various replies returned by gcr_prompt_confirm() and friends.
81
GMainContext *context;
84
typedef GcrPromptIface GcrPromptInterface;
86
static void gcr_prompt_default_init (GcrPromptIface *iface);
88
G_DEFINE_INTERFACE (GcrPrompt, gcr_prompt, G_TYPE_OBJECT);
91
gcr_prompt_default_init (GcrPromptIface *iface)
93
static gsize initialized = 0;
95
if (g_once_init_enter (&initialized)) {
100
* The title of the prompt.
102
* A prompt implementation may choose not to display the prompt title. The
103
* #GcrPrompt:message should contain relevant information.
105
g_object_interface_install_property (iface,
106
g_param_spec_string ("title", "Title", "Prompt title",
107
NULL, G_PARAM_READWRITE | G_PARAM_CONSTRUCT | G_PARAM_STATIC_STRINGS));
112
* The prompt message for the user.
114
* A prompt implementation should always display this message.
116
g_object_interface_install_property (iface,
117
g_param_spec_string ("message", "Message", "Prompt message",
118
NULL, G_PARAM_READWRITE | G_PARAM_CONSTRUCT | G_PARAM_STATIC_STRINGS));
121
* GcrPrompt:description:
123
* The detailed description of the prompt.
125
* A prompt implementation may choose not to display this detailed description.
126
* The prompt message should contain relevant information.
128
g_object_interface_install_property (iface,
129
g_param_spec_string ("description", "Description", "Prompt description",
130
NULL, G_PARAM_READWRITE | G_PARAM_CONSTRUCT | G_PARAM_STATIC_STRINGS));
135
* A prompt warning displayed on the prompt, or %NULL for no warning.
137
* This is a warning like "The password is incorrect." usually displayed to the
138
* user about a previous 'unsuccessful' prompt.
140
g_object_interface_install_property (iface,
141
g_param_spec_string ("warning", "Warning", "Prompt warning",
142
NULL, G_PARAM_READWRITE | G_PARAM_CONSTRUCT | G_PARAM_STATIC_STRINGS));
145
* GcrPrompt:password-new:
147
* Whether the prompt will prompt for a new password.
149
* This will cause the prompt implementation to ask the user to confirm the
150
* password and/or display other relevant user interface for creating a new
153
g_object_interface_install_property (iface,
154
g_param_spec_boolean ("password-new", "Password new", "Whether prompting for a new password",
155
FALSE, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
158
* GcrPrompt:password-strength:
160
* Indication of the password strength.
162
* Prompts will return a zero value if the password is empty, and a value
163
* greater than zero if the password has any characters.
165
* This is only valid after a successful prompt for a password.
167
g_object_interface_install_property (iface,
168
g_param_spec_int ("password-strength", "Password strength", "String of new password",
169
0, G_MAXINT, 0, G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
172
* GcrPrompt:choice-label:
174
* The label for the additional choice.
176
* If this is a non-%NULL value then an additional boolean choice will be
177
* displayed by the prompt allowing the user to select or deselect it.
179
* If %NULL, then no additional choice is displayed.
181
* The initial value of the choice can be set with #GcrPrompt:choice-chosen.
183
g_object_interface_install_property (iface,
184
g_param_spec_string ("choice-label", "Choice label", "Label for prompt choice",
185
NULL, G_PARAM_READWRITE | G_PARAM_CONSTRUCT | G_PARAM_STATIC_STRINGS));
188
* GcrPrompt:choice-chosen:
190
* Whether the additional choice is chosen or not.
192
* The additional choice would have been setup using #GcrPrompt:choice-label.
194
g_object_interface_install_property (iface,
195
g_param_spec_boolean ("choice-chosen", "Choice chosen", "Whether prompt choice is chosen",
196
FALSE, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
199
* GcrPrompt:caller-window:
201
* The string handle of the caller's window.
203
* The caller window indicates to the prompt which window is prompting the
204
* user. The prompt may choose to ignore this information or use it in whatever
207
g_object_interface_install_property (iface,
208
g_param_spec_string ("caller-window", "Caller window", "Window ID of application window requesting prompt",
209
NULL, G_PARAM_READWRITE | G_PARAM_CONSTRUCT | G_PARAM_STATIC_STRINGS));
212
* GcrPrompt:continue-label:
214
* The label for the continue button in the prompt.
216
g_object_interface_install_property (iface,
217
g_param_spec_string ("continue-label", "Continue label", "Continue button label",
218
_("Continue"), G_PARAM_READWRITE | G_PARAM_CONSTRUCT | G_PARAM_STATIC_STRINGS));
221
* GcrPrompt:cancel-label:
223
* The label for the cancel button in the prompt.
225
g_object_interface_install_property (iface,
226
g_param_spec_string ("cancel-label", "Cancel label", "Cancel button label",
227
_("Cancel"), G_PARAM_READWRITE | G_PARAM_CONSTRUCT | G_PARAM_STATIC_STRINGS));
229
g_once_init_leave (&initialized, 1);
234
run_closure_end (gpointer data)
236
RunClosure *closure = data;
237
g_clear_object (&closure->result);
238
g_main_loop_unref (closure->loop);
239
if (closure->context != NULL) {
240
g_main_context_pop_thread_default (closure->context);
241
g_main_context_unref (closure->context);
247
run_closure_begin (GMainContext *context)
249
RunClosure *closure = g_new0 (RunClosure, 1);
250
closure->loop = g_main_loop_new (context ? context : g_main_context_get_thread_default (), FALSE);
251
closure->result = NULL;
253
/* We assume ownership of context reference */
254
closure->context = context;
255
if (closure->context != NULL)
256
g_main_context_push_thread_default (closure->context);
262
on_run_complete (GObject *source,
263
GAsyncResult *result,
266
RunClosure *closure = user_data;
267
g_return_if_fail (closure->result == NULL);
268
closure->result = g_object_ref (result);
269
g_main_loop_quit (closure->loop);
273
gcr_prompt_reset (GcrPrompt *prompt)
276
GcrPromptIface *iface;
279
g_return_if_fail (GCR_IS_PROMPT (prompt));
281
iface = GCR_PROMPT_GET_INTERFACE (prompt);
282
params = g_object_interface_list_properties (iface, &n_params);
284
g_object_freeze_notify (G_OBJECT (prompt));
286
for (i = 0; i < n_params; i++) {
287
if (!(params[i]->flags & G_PARAM_WRITABLE))
290
if (params[i]->value_type == G_TYPE_STRING)
291
g_object_set (prompt, params[i]->name,
292
((GParamSpecString *)params[i])->default_value,
295
else if (params[i]->value_type == G_TYPE_INT)
296
g_object_set (prompt, params[i]->name,
297
((GParamSpecInt *)params[i])->default_value,
300
else if (params[i]->value_type == G_TYPE_BOOLEAN)
301
g_object_set (prompt, params[i]->name,
302
((GParamSpecBoolean *)params[i])->default_value,
306
g_assert_not_reached ();
311
g_object_thaw_notify (G_OBJECT (prompt));
315
* gcr_prompt_get_title:
316
* @prompt: the prompt
318
* Gets the title of the prompt.
320
* A prompt implementation may choose not to display the prompt title. The
321
* prompt message should contain relevant information.
323
* Returns: (transfer full): a newly allocated string containing the prompt
327
gcr_prompt_get_title (GcrPrompt *prompt)
330
g_return_val_if_fail (GCR_IS_PROMPT (prompt), NULL);
331
g_object_get (prompt, "title", &title, NULL);
336
* gcr_prompt_set_title:
337
* @prompt: the prompt
338
* @title: the prompt title
340
* Sets the title of the prompt.
342
* A prompt implementation may choose not to display the prompt title. The
343
* prompt message should contain relevant information.
346
gcr_prompt_set_title (GcrPrompt *prompt,
349
g_return_if_fail (GCR_IS_PROMPT (prompt));
350
g_object_set (prompt, "title", title, NULL);
354
* gcr_prompt_get_message:
355
* @prompt: the prompt
357
* Gets the prompt message for the user.
359
* A prompt implementation should always display this message.
361
* Returns: (transfer full): a newly allocated string containing the detailed
362
* description of the prompt
365
gcr_prompt_get_message (GcrPrompt *prompt)
367
gchar *message = NULL;
368
g_return_val_if_fail (GCR_IS_PROMPT (prompt), NULL);
369
g_object_get (prompt, "message", &message, NULL);
374
* gcr_prompt_set_message:
375
* @prompt: the prompt
376
* @message: the prompt message
378
* Sets the prompt message for the user.
380
* A prompt implementation should always display this message.
383
gcr_prompt_set_message (GcrPrompt *prompt,
384
const gchar *message)
386
g_return_if_fail (GCR_IS_PROMPT (prompt));
387
g_object_set (prompt, "message", message, NULL);
391
* gcr_prompt_get_description:
392
* @prompt: the prompt
394
* Get the detailed description of the prompt.
396
* A prompt implementation may choose not to display this detailed description.
397
* The prompt message should contain relevant information.
399
* Returns: (transfer full): a newly allocated string containing the detailed
400
* description of the prompt
403
gcr_prompt_get_description (GcrPrompt *prompt)
405
gchar *description = NULL;
406
g_return_val_if_fail (GCR_IS_PROMPT (prompt), NULL);
407
g_object_get (prompt, "description", &description, NULL);
412
* gcr_prompt_set_description:
413
* @prompt: the prompt
414
* @description: the detailed description
416
* Set the detailed description of the prompt.
418
* A prompt implementation may choose not to display this detailed description.
419
* Use gcr_prompt_set_message() to set a general message containing relevant
423
gcr_prompt_set_description (GcrPrompt *prompt,
424
const gchar *description)
426
g_return_if_fail (GCR_IS_PROMPT (prompt));
427
g_object_set (prompt, "description", description, NULL);
431
* gcr_prompt_get_warning:
432
* @prompt: the prompt
434
* Get a prompt warning displayed on the prompt.
436
* This is a warning like "The password is incorrect." usually displayed to the
437
* user about a previous 'unsuccessful' prompt.
439
* If this string is %NULL then no warning is displayed.
441
* Returns: (transfer full): a newly allocated string containing the prompt
442
* warning, or %NULL if no warning
445
gcr_prompt_get_warning (GcrPrompt *prompt)
447
gchar *warning = NULL;
448
g_return_val_if_fail (GCR_IS_PROMPT (prompt), NULL);
449
g_object_get (prompt, "warning", &warning, NULL);
454
* gcr_prompt_set_warning:
455
* @prompt: the prompt
456
* @warning: (allow-none): the warning or %NULL
458
* Set a prompt warning displayed on the prompt.
460
* This is a warning like "The password is incorrect." usually displayed to the
461
* user about a previous 'unsuccessful' prompt.
463
* If this string is %NULL then no warning is displayed.
466
gcr_prompt_set_warning (GcrPrompt *prompt,
467
const gchar *warning)
469
g_return_if_fail (GCR_IS_PROMPT (prompt));
470
g_object_set (prompt, "warning", warning, NULL);
474
* gcr_prompt_get_choice_label:
475
* @prompt: the prompt
477
* Get the label for the additional choice.
479
* This will be %NULL if no additional choice is being displayed.
481
* Returns: (transfer full): a newly allocated string containing the additional
485
gcr_prompt_get_choice_label (GcrPrompt *prompt)
487
gchar *choice_label = NULL;
488
g_return_val_if_fail (GCR_IS_PROMPT (prompt), NULL);
489
g_object_get (prompt, "choice-label", &choice_label, NULL);
494
* gcr_prompt_set_choice_label:
495
* @prompt: the prompt
496
* @choice_label: (allow-none): the additional choice or %NULL
498
* Set the label for the additional choice.
500
* If this is a non-%NULL value then an additional boolean choice will be
501
* displayed by the prompt allowing the user to select or deselect it.
503
* The initial value of the choice can be set with the
504
* gcr_prompt_set_choice_label() method.
506
* If this is %NULL, then no additional choice is being displayed.
509
gcr_prompt_set_choice_label (GcrPrompt *prompt,
510
const gchar *choice_label)
512
g_return_if_fail (GCR_IS_PROMPT (prompt));
513
g_object_set (prompt, "choice-label", choice_label, NULL);
517
* gcr_prompt_get_choice_chosen:
518
* @prompt: the prompt
520
* Get whether the additional choice was chosen or not.
522
* The additional choice would have been setup using
523
* gcr_prompt_set_choice_label().
525
* Returns: whether chosen
528
gcr_prompt_get_choice_chosen (GcrPrompt *prompt)
530
gboolean choice_chosen;
531
g_return_val_if_fail (GCR_IS_PROMPT (prompt), FALSE);
532
g_object_get (prompt, "choice-chosen", &choice_chosen, NULL);
533
return choice_chosen;
537
* gcr_prompt_set_choice_chosen:
538
* @prompt: the prompt
539
* @chosen: whether chosen
541
* Set whether the additional choice is chosen or not.
543
* The additional choice should be set up using gcr_prompt_set_choice_label().
546
gcr_prompt_set_choice_chosen (GcrPrompt *prompt,
549
g_return_if_fail (GCR_IS_PROMPT (prompt));
550
g_object_set (prompt, "choice-chosen", chosen, NULL);
554
* gcr_prompt_get_password_new:
555
* @prompt: the prompt
557
* Get whether the prompt will prompt for a new password.
559
* This will cause the prompt implementation to ask the user to confirm the
560
* password and/or display other relevant user interface for creating a new
563
* Returns: whether in new password mode or not
566
gcr_prompt_get_password_new (GcrPrompt *prompt)
568
gboolean password_new;
569
g_return_val_if_fail (GCR_IS_PROMPT (prompt), FALSE);
570
g_object_get (prompt, "password-new", &password_new, NULL);
575
* gcr_prompt_set_password_new:
576
* @prompt: the prompt
577
* @new_password: whether in new password mode or not
579
* Set whether the prompt will prompt for a new password.
581
* This will cause the prompt implementation to ask the user to confirm the
582
* password and/or display other relevant user interface for creating a new
586
gcr_prompt_set_password_new (GcrPrompt *prompt,
587
gboolean new_password)
589
g_return_if_fail (GCR_IS_PROMPT (prompt));
590
g_object_set (prompt, "password-new", new_password, NULL);
594
* gcr_prompt_get_password_strength:
595
* @prompt: the prompt
597
* Get indication of the password strength.
599
* Prompts will return a zero value if the password is empty, and a value
600
* greater than zero if the password has any characters.
602
* This is only valid after a successful prompt for a password.
604
* Returns: zero if the password is empty, greater than zero if not
607
gcr_prompt_get_password_strength (GcrPrompt *prompt)
609
gboolean password_strength;
610
g_return_val_if_fail (GCR_IS_PROMPT (prompt), 0);
611
g_object_get (prompt, "password-strength", &password_strength, NULL);
612
return password_strength;
616
* gcr_prompt_get_caller_window:
617
* @prompt: the prompt
619
* Get the string handle of the caller's window.
621
* The caller window indicates to the prompt which window is prompting the
622
* user. The prompt may choose to ignore this information or use it in whatever
625
* Returns: (transfer full): a newly allocated string containing the string
626
* handle of the window.
629
gcr_prompt_get_caller_window (GcrPrompt *prompt)
631
gchar *caller_window = NULL;
632
g_return_val_if_fail (GCR_IS_PROMPT (prompt), NULL);
633
g_object_get (prompt, "caller-window", &caller_window, NULL);
634
return caller_window;
638
* gcr_prompt_set_caller_window:
639
* @prompt: the prompt
640
* @window_id: the window id
642
* Set the string handle of the caller's window.
644
* The caller window indicates to the prompt which window is prompting the
645
* user. The prompt may choose to ignore this information or use it in whatever
649
gcr_prompt_set_caller_window (GcrPrompt *prompt,
650
const gchar *window_id)
652
g_return_if_fail (GCR_IS_PROMPT (prompt));
653
g_object_set (prompt, "caller-window", window_id, NULL);
657
* gcr_prompt_get_continue_label:
658
* @prompt: the prompt
660
* Get the label for the continue button.
662
* This is the button that results in a %GCR_PROMPT_REPLY_CONTINUE reply
665
* Returns: (transfer full): a newly allocated string containing the label
668
gcr_prompt_get_continue_label (GcrPrompt *prompt)
670
gchar *continue_label = NULL;
671
g_return_val_if_fail (GCR_IS_PROMPT (prompt), NULL);
672
g_object_get (prompt, "continue-label", &continue_label, NULL);
673
return continue_label;
677
* gcr_prompt_set_continue_label:
678
* @prompt: the prompt
679
* @continue_label: the label
681
* Set the label for the continue button.
683
* This is the button that results in a %GCR_PROMPT_REPLY_CONTINUE reply
687
gcr_prompt_set_continue_label (GcrPrompt *prompt,
688
const gchar *continue_label)
690
g_return_if_fail (GCR_IS_PROMPT (prompt));
691
g_object_set (prompt, "continue-label", continue_label, NULL);
695
* gcr_prompt_get_cancel_label:
696
* @prompt: the prompt
698
* Get the label for the cancel button.
700
* This is the button that results in a %GCR_PROMPT_REPLY_CANCEL reply
703
* Returns: (transfer full): a newly allocated string containing the label
706
gcr_prompt_get_cancel_label (GcrPrompt *prompt)
708
gchar *cancel_label = NULL;
709
g_object_get (prompt, "cancel-label", &cancel_label, NULL);
714
* gcr_prompt_set_cancel_label:
715
* @prompt: the prompt
716
* @cancel_label: the label
718
* Set the label for the continue button.
720
* This is the button that results in a %GCR_PROMPT_REPLY_CANCEL reply
724
gcr_prompt_set_cancel_label (GcrPrompt *prompt,
725
const gchar *cancel_label)
727
g_return_if_fail (GCR_IS_PROMPT (prompt));
728
g_object_set (prompt, "cancel-label", cancel_label, NULL);
732
* gcr_prompt_password_async:
734
* @cancellable: optional cancellation object
735
* @callback: called when the operation completes
736
* @user_data: data to pass to the callback
738
* Prompts for password. Set the various properties on the prompt before calling
739
* this method to explain which password should be entered.
741
* This method will return immediately and complete asynchronously.
744
gcr_prompt_password_async (GcrPrompt *prompt,
745
GCancellable *cancellable,
746
GAsyncReadyCallback callback,
749
GcrPromptIface *iface;
751
g_return_if_fail (GCR_IS_PROMPT (prompt));
752
g_return_if_fail (cancellable == NULL || G_IS_CANCELLABLE (cancellable));
754
iface = GCR_PROMPT_GET_INTERFACE (prompt);
755
g_return_if_fail (iface->prompt_password_async);
757
(iface->prompt_password_async) (prompt, cancellable, callback, user_data);
761
* gcr_prompt_password_finish:
763
* @result: asynchronous result passed to callback
764
* @error: location to place error on failure
766
* Complete an operation to prompt for a password.
768
* A password will be returned if the user enters a password successfully.
769
* The returned password is valid until the next time a method is called
770
* to display another prompt.
772
* %NULL will be returned if the user cancels or if an error occurs. Check the
773
* @error argument to tell the difference.
775
* Returns: the password owned by the prompt, or %NULL
778
gcr_prompt_password_finish (GcrPrompt *prompt,
779
GAsyncResult *result,
782
GcrPromptIface *iface;
784
g_return_val_if_fail (GCR_IS_PROMPT (prompt), NULL);
785
g_return_val_if_fail (G_IS_ASYNC_RESULT (result), NULL);
786
g_return_val_if_fail (error == NULL || *error == NULL, NULL);
788
iface = GCR_PROMPT_GET_INTERFACE (prompt);
789
g_return_val_if_fail (iface->prompt_password_async, NULL);
791
return (iface->prompt_password_finish) (prompt, result, error);
795
* gcr_prompt_password:
797
* @cancellable: optional cancellation object
798
* @error: location to place error on failure
800
* Prompts for password. Set the various properties on the prompt before calling
801
* this method to explain which password should be entered.
803
* This method will block until the a response is returned from the prompter.
805
* A password will be returned if the user enters a password successfully.
806
* The returned password is valid until the next time a method is called
807
* to display another prompt.
809
* %NULL will be returned if the user cancels or if an error occurs. Check the
810
* @error argument to tell the difference.
812
* Returns: the password owned by the prompt, or %NULL
815
gcr_prompt_password (GcrPrompt *prompt,
816
GCancellable *cancellable,
822
g_return_val_if_fail (GCR_IS_PROMPT (prompt), NULL);
823
g_return_val_if_fail (cancellable == NULL || G_IS_CANCELLABLE (cancellable), NULL);
824
g_return_val_if_fail (error == NULL || *error == NULL, NULL);
826
closure = run_closure_begin (g_main_context_new ());
828
gcr_prompt_password_async (prompt, cancellable, on_run_complete, closure);
830
g_main_loop_run (closure->loop);
832
reply = gcr_prompt_password_finish (prompt, closure->result, error);
833
run_closure_end (closure);
839
* gcr_prompt_password_run:
841
* @cancellable: optional cancellation object
842
* @error: location to place error on failure
844
* Prompts for password. Set the various properties on the prompt before calling
845
* this method to explain which password should be entered.
847
* This method will block until the a response is returned from the prompter
848
* and will run a main loop similar to a gtk_dialog_run(). The application
849
* will remain responsive but care must be taken to handle reentrancy issues.
851
* A password will be returned if the user enters a password successfully.
852
* The returned password is valid until the next time a method is called
853
* to display another prompt.
855
* %NULL will be returned if the user cancels or if an error occurs. Check the
856
* @error argument to tell the difference.
858
* Returns: the password owned by the prompt, or %NULL
861
gcr_prompt_password_run (GcrPrompt *prompt,
862
GCancellable *cancellable,
868
g_return_val_if_fail (GCR_IS_PROMPT (prompt), NULL);
869
g_return_val_if_fail (cancellable == NULL || G_IS_CANCELLABLE (cancellable), NULL);
870
g_return_val_if_fail (error == NULL || *error == NULL, NULL);
872
closure = run_closure_begin (NULL);
874
gcr_prompt_password_async (prompt, cancellable, on_run_complete, closure);
876
g_main_loop_run (closure->loop);
878
reply = gcr_prompt_password_finish (prompt, closure->result, error);
879
run_closure_end (closure);
885
* gcr_prompt_confirm_async:
887
* @cancellable: optional cancellation object
888
* @callback: called when the operation completes
889
* @user_data: data to pass to the callback
891
* Prompts for confirmation asking a cancel/continue style question.
892
* Set the various properties on the prompt before calling this method to
893
* represent the question correctly.
895
* This method will return immediately and complete asynchronously.
898
gcr_prompt_confirm_async (GcrPrompt *prompt,
899
GCancellable *cancellable,
900
GAsyncReadyCallback callback,
903
GcrPromptIface *iface;
905
g_return_if_fail (GCR_IS_PROMPT (prompt));
906
g_return_if_fail (cancellable == NULL || G_IS_CANCELLABLE (cancellable));
908
iface = GCR_PROMPT_GET_INTERFACE (prompt);
909
g_return_if_fail (iface->prompt_confirm_async);
911
(iface->prompt_confirm_async) (prompt, cancellable, callback, user_data);
915
* gcr_prompt_confirm_finish:
917
* @result: asynchronous result passed to callback
918
* @error: location to place error on failure
920
* Complete an operation to prompt for confirmation.
922
* %GCR_PROMPT_REPLY_OK will be returned if the user confirms the prompt. The
923
* return value will also be %GCR_PROMPT_REPLY_CANCEL if the user cancels or if
924
* an error occurs. Check the @error argument to tell the difference.
926
* Returns: the reply from the prompt
929
gcr_prompt_confirm_finish (GcrPrompt *prompt,
930
GAsyncResult *result,
933
GcrPromptIface *iface;
935
g_return_val_if_fail (GCR_IS_PROMPT (prompt), GCR_PROMPT_REPLY_CANCEL);
936
g_return_val_if_fail (G_IS_ASYNC_RESULT (result), GCR_PROMPT_REPLY_CANCEL);
937
g_return_val_if_fail (error == NULL || *error == NULL, GCR_PROMPT_REPLY_CANCEL);
939
iface = GCR_PROMPT_GET_INTERFACE (prompt);
940
g_return_val_if_fail (iface->prompt_confirm_async, GCR_PROMPT_REPLY_CANCEL);
942
return (iface->prompt_confirm_finish) (prompt, result, error);
946
* gcr_prompt_confirm:
948
* @cancellable: optional cancellation object
949
* @error: location to place error on failure
951
* Prompts for confirmation asking a cancel/continue style question.
952
* Set the various properties on the prompt before calling this function to
953
* represent the question correctly.
955
* This method will block until the a response is returned from the prompter.
957
* %GCR_PROMPT_REPLY_OK will be returned if the user confirms the prompt. The
958
* return value will also be %GCR_PROMPT_REPLY_CANCEL if the user cancels or if
959
* an error occurs. Check the @error argument to tell the difference.
961
* Returns: the reply from the prompt
964
gcr_prompt_confirm (GcrPrompt *prompt,
965
GCancellable *cancellable,
969
GcrPromptReply reply;
971
g_return_val_if_fail (GCR_IS_PROMPT (prompt), GCR_PROMPT_REPLY_CANCEL);
972
g_return_val_if_fail (cancellable == NULL || G_IS_CANCELLABLE (cancellable), GCR_PROMPT_REPLY_CANCEL);
973
g_return_val_if_fail (error == NULL || *error == NULL, GCR_PROMPT_REPLY_CANCEL);
975
closure = run_closure_begin (g_main_context_new ());
977
gcr_prompt_confirm_async (prompt, cancellable, on_run_complete, closure);
979
g_main_loop_run (closure->loop);
981
reply = gcr_prompt_confirm_finish (prompt, closure->result, error);
982
run_closure_end (closure);
988
* gcr_prompt_confirm_run:
990
* @cancellable: optional cancellation object
991
* @error: location to place error on failure
993
* Prompts for confirmation asking a cancel/continue style question.
994
* Set the various properties on the prompt before calling this function to
995
* represent the question correctly.
997
* This method will block until the a response is returned from the prompter
998
* and will run a main loop similar to a gtk_dialog_run(). The application
999
* will remain responsive but care must be taken to handle reentrancy issues.
1001
* %GCR_PROMPT_REPLY_OK will be returned if the user confirms the prompt. The
1002
* return value will also be %GCR_PROMPT_REPLY_CANCEL if the user cancels or if
1003
* an error occurs. Check the @error argument to tell the difference.
1005
* Returns: the reply from the prompt
1008
gcr_prompt_confirm_run (GcrPrompt *prompt,
1009
GCancellable *cancellable,
1012
RunClosure *closure;
1013
GcrPromptReply reply;
1015
g_return_val_if_fail (GCR_IS_PROMPT (prompt), GCR_PROMPT_REPLY_CANCEL);
1016
g_return_val_if_fail (cancellable == NULL || G_IS_CANCELLABLE (cancellable), GCR_PROMPT_REPLY_CANCEL);
1017
g_return_val_if_fail (error == NULL || *error == NULL, GCR_PROMPT_REPLY_CANCEL);
1019
closure = run_closure_begin (NULL);
1021
gcr_prompt_confirm_async (prompt, cancellable, on_run_complete, closure);
1023
g_main_loop_run (closure->loop);
1025
reply = gcr_prompt_confirm_finish (prompt, closure->result, error);
1026
run_closure_end (closure);