~ubuntu-branches/ubuntu/trusty/gcr/trusty-proposed

« back to all changes in this revision

Viewing changes to gcr/gcr-prompt.c

  • Committer: Package Import Robot
  • Author(s): Jordi Mallach
  • Date: 2012-05-03 10:18:39 UTC
  • Revision ID: package-import@ubuntu.com-20120503101839-wuvloldm7gmdsnij
Tags: upstream-3.4.1
ImportĀ upstreamĀ versionĀ 3.4.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * gnome-keyring
 
3
 *
 
4
 * Copyright (C) 2011 Stefan Walter
 
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, write to the Free Software
 
18
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
 
19
 * 02111-1307, USA.
 
20
 *
 
21
 * Author: Stef Walter <stef@thewalter.net>
 
22
 */
 
23
 
 
24
#include "config.h"
 
25
 
 
26
#include "gcr-prompt.h"
 
27
 
 
28
#include <glib/gi18n-lib.h>
 
29
 
 
30
/**
 
31
 * SECTION:gcr-prompt
 
32
 * @title: GcrPrompt
 
33
 * @short_description: a user prompt
 
34
 *
 
35
 * A #GcrPrompt represents a prompt displayed to the user. It is an interface
 
36
 * with various implementations.
 
37
 *
 
38
 * Various properties are set on the prompt, and then the prompt is displayed
 
39
 * the various prompt methods like gcr_prompt_password_run().
 
40
 *
 
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.
 
45
 *
 
46
 * Use #GcrPromptDialog to create an in-process GTK+ dialog prompt. Use
 
47
 * #GcrSystemPrompt to create a system prompt in a prompter process.
 
48
 *
 
49
 * The prompt implementation will always display the GcrPrompt:message property,
 
50
 * but may choose not to display the GcrPrompt:description or GcrPrompt:title
 
51
 * properties.
 
52
 */
 
53
 
 
54
/**
 
55
 * GcrPrompt:
 
56
 *
 
57
 * Represents a #GcrPrompt displayed to the user.
 
58
 */
 
59
 
 
60
/**
 
61
 * GcrPromptIface:
 
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
 
67
 *
 
68
 * The interface for implementing #GcrPrompt.
 
69
 */
 
70
 
 
71
/**
 
72
 * GcrPromptReply:
 
73
 * @GCR_PROMPT_REPLY_CONTINUE: the user replied with 'ok'
 
74
 * @GCR_PROMPT_REPLY_CANCEL: the prompt was cancelled
 
75
 *
 
76
 * Various replies returned by gcr_prompt_confirm() and friends.
 
77
 */
 
78
typedef struct {
 
79
        GAsyncResult *result;
 
80
        GMainLoop *loop;
 
81
        GMainContext *context;
 
82
} RunClosure;
 
83
 
 
84
typedef GcrPromptIface GcrPromptInterface;
 
85
 
 
86
static void   gcr_prompt_default_init    (GcrPromptIface *iface);
 
87
 
 
88
G_DEFINE_INTERFACE (GcrPrompt, gcr_prompt, G_TYPE_OBJECT);
 
89
 
 
90
static void
 
91
gcr_prompt_default_init (GcrPromptIface *iface)
 
92
{
 
93
        static gsize initialized = 0;
 
94
 
 
95
        if (g_once_init_enter (&initialized)) {
 
96
 
 
97
                /**
 
98
                 * GcrPrompt:title:
 
99
                 *
 
100
                 * The title of the prompt.
 
101
                 *
 
102
                 * A prompt implementation may choose not to display the prompt title. The
 
103
                 * #GcrPrompt:message should contain relevant information.
 
104
                 */
 
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));
 
108
 
 
109
                /**
 
110
                 * GcrPrompt:message:
 
111
                 *
 
112
                 * The prompt message for the user.
 
113
                 *
 
114
                 * A prompt implementation should always display this message.
 
115
                 */
 
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));
 
119
 
 
120
                /**
 
121
                 * GcrPrompt:description:
 
122
                 *
 
123
                 * The detailed description of the prompt.
 
124
                 *
 
125
                 * A prompt implementation may choose not to display this detailed description.
 
126
                 * The prompt message should contain relevant information.
 
127
                 */
 
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));
 
131
 
 
132
                /**
 
133
                 * GcrPrompt:warning:
 
134
                 *
 
135
                 * A prompt warning displayed on the prompt, or %NULL for no warning.
 
136
                 *
 
137
                 * This is a warning like "The password is incorrect." usually displayed to the
 
138
                 * user about a previous 'unsuccessful' prompt.
 
139
                 */
 
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));
 
143
 
 
144
                /**
 
145
                 * GcrPrompt:password-new:
 
146
                 *
 
147
                 * Whether the prompt will prompt for a new password.
 
148
                 *
 
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
 
151
                 * password.
 
152
                 */
 
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));
 
156
 
 
157
                /**
 
158
                 * GcrPrompt:password-strength:
 
159
                 *
 
160
                 * Indication of the password strength.
 
161
                 *
 
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.
 
164
                 *
 
165
                 * This is only valid after a successful prompt for a password.
 
166
                 */
 
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));
 
170
 
 
171
                /**
 
172
                 * GcrPrompt:choice-label:
 
173
                 *
 
174
                 * The label for the additional choice.
 
175
                 *
 
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.
 
178
                 *
 
179
                 * If %NULL, then no additional choice is displayed.
 
180
                 *
 
181
                 * The initial value of the choice can be set with #GcrPrompt:choice-chosen.
 
182
                 */
 
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));
 
186
 
 
187
                /**
 
188
                 * GcrPrompt:choice-chosen:
 
189
                 *
 
190
                 * Whether the additional choice is chosen or not.
 
191
                 *
 
192
                 * The additional choice would have been setup using #GcrPrompt:choice-label.
 
193
                 */
 
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));
 
197
 
 
198
                /**
 
199
                 * GcrPrompt:caller-window:
 
200
                 *
 
201
                 * The string handle of the caller's window.
 
202
                 *
 
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
 
205
                 * way it sees fit.
 
206
                 */
 
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));
 
210
 
 
211
                /**
 
212
                 * GcrPrompt:continue-label:
 
213
                 *
 
214
                 * The label for the continue button in the prompt.
 
215
                 */
 
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));
 
219
 
 
220
                /**
 
221
                 * GcrPrompt:cancel-label:
 
222
                 *
 
223
                 * The label for the cancel button in the prompt.
 
224
                 */
 
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));
 
228
 
 
229
                g_once_init_leave (&initialized, 1);
 
230
        }
 
231
}
 
232
 
 
233
static void
 
234
run_closure_end (gpointer data)
 
235
{
 
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);
 
242
        }
 
243
        g_free (closure);
 
244
}
 
245
 
 
246
static RunClosure *
 
247
run_closure_begin (GMainContext *context)
 
248
{
 
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;
 
252
 
 
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);
 
257
 
 
258
        return closure;
 
259
}
 
260
 
 
261
static void
 
262
on_run_complete (GObject *source,
 
263
                 GAsyncResult *result,
 
264
                 gpointer user_data)
 
265
{
 
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);
 
270
}
 
271
 
 
272
void
 
273
gcr_prompt_reset (GcrPrompt *prompt)
 
274
{
 
275
        GParamSpec **params;
 
276
        GcrPromptIface *iface;
 
277
        guint i, n_params;
 
278
 
 
279
        g_return_if_fail (GCR_IS_PROMPT (prompt));
 
280
 
 
281
        iface = GCR_PROMPT_GET_INTERFACE (prompt);
 
282
        params = g_object_interface_list_properties (iface, &n_params);
 
283
 
 
284
        g_object_freeze_notify (G_OBJECT (prompt));
 
285
 
 
286
        for (i = 0; i < n_params; i++) {
 
287
                if (!(params[i]->flags & G_PARAM_WRITABLE))
 
288
                        continue;
 
289
 
 
290
                if (params[i]->value_type == G_TYPE_STRING)
 
291
                        g_object_set (prompt, params[i]->name,
 
292
                                      ((GParamSpecString *)params[i])->default_value,
 
293
                                      NULL);
 
294
 
 
295
                else if (params[i]->value_type == G_TYPE_INT)
 
296
                        g_object_set (prompt, params[i]->name,
 
297
                                      ((GParamSpecInt *)params[i])->default_value,
 
298
                                      NULL);
 
299
 
 
300
                else if (params[i]->value_type == G_TYPE_BOOLEAN)
 
301
                        g_object_set (prompt, params[i]->name,
 
302
                                      ((GParamSpecBoolean *)params[i])->default_value,
 
303
                                      NULL);
 
304
 
 
305
                else
 
306
                        g_assert_not_reached ();
 
307
        }
 
308
 
 
309
        g_free (params);
 
310
 
 
311
        g_object_thaw_notify (G_OBJECT (prompt));
 
312
}
 
313
 
 
314
/**
 
315
 * gcr_prompt_get_title:
 
316
 * @prompt: the prompt
 
317
 *
 
318
 * Gets the title of the prompt.
 
319
 *
 
320
 * A prompt implementation may choose not to display the prompt title. The
 
321
 * prompt message should contain relevant information.
 
322
 *
 
323
 * Returns: (transfer full): a newly allocated string containing the prompt
 
324
 *          title.
 
325
 */
 
326
gchar *
 
327
gcr_prompt_get_title (GcrPrompt *prompt)
 
328
{
 
329
        gchar *title = NULL;
 
330
        g_return_val_if_fail (GCR_IS_PROMPT (prompt), NULL);
 
331
        g_object_get (prompt, "title", &title, NULL);
 
332
        return title;
 
333
}
 
334
 
 
335
/**
 
336
 * gcr_prompt_set_title:
 
337
 * @prompt: the prompt
 
338
 * @title: the prompt title
 
339
 *
 
340
 * Sets the title of the prompt.
 
341
 *
 
342
 * A prompt implementation may choose not to display the prompt title. The
 
343
 * prompt message should contain relevant information.
 
344
 */
 
345
void
 
346
gcr_prompt_set_title (GcrPrompt *prompt,
 
347
                      const gchar *title)
 
348
{
 
349
        g_return_if_fail (GCR_IS_PROMPT (prompt));
 
350
        g_object_set (prompt, "title", title, NULL);
 
351
}
 
352
 
 
353
/**
 
354
 * gcr_prompt_get_message:
 
355
 * @prompt: the prompt
 
356
 *
 
357
 * Gets the prompt message for the user.
 
358
 *
 
359
 * A prompt implementation should always display this message.
 
360
 *
 
361
 * Returns: (transfer full): a newly allocated string containing the detailed
 
362
 *          description of the prompt
 
363
 */
 
364
gchar *
 
365
gcr_prompt_get_message (GcrPrompt *prompt)
 
366
{
 
367
        gchar *message = NULL;
 
368
        g_return_val_if_fail (GCR_IS_PROMPT (prompt), NULL);
 
369
        g_object_get (prompt, "message", &message, NULL);
 
370
        return message;
 
371
}
 
372
 
 
373
/**
 
374
 * gcr_prompt_set_message:
 
375
 * @prompt: the prompt
 
376
 * @message: the prompt message
 
377
 *
 
378
 * Sets the prompt message for the user.
 
379
 *
 
380
 * A prompt implementation should always display this message.
 
381
 */
 
382
void
 
383
gcr_prompt_set_message (GcrPrompt *prompt,
 
384
                        const gchar *message)
 
385
{
 
386
        g_return_if_fail (GCR_IS_PROMPT (prompt));
 
387
        g_object_set (prompt, "message", message, NULL);
 
388
}
 
389
 
 
390
/**
 
391
 * gcr_prompt_get_description:
 
392
 * @prompt: the prompt
 
393
 *
 
394
 * Get the detailed description of the prompt.
 
395
 *
 
396
 * A prompt implementation may choose not to display this detailed description.
 
397
 * The prompt message should contain relevant information.
 
398
 *
 
399
 * Returns: (transfer full): a newly allocated string containing the detailed
 
400
 *          description of the prompt
 
401
 */
 
402
gchar *
 
403
gcr_prompt_get_description (GcrPrompt *prompt)
 
404
{
 
405
        gchar *description = NULL;
 
406
        g_return_val_if_fail (GCR_IS_PROMPT (prompt), NULL);
 
407
        g_object_get (prompt, "description", &description, NULL);
 
408
        return description;
 
409
}
 
410
 
 
411
/**
 
412
 * gcr_prompt_set_description:
 
413
 * @prompt: the prompt
 
414
 * @description: the detailed description
 
415
 *
 
416
 * Set the detailed description of the prompt.
 
417
 *
 
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
 
420
 * information.
 
421
 */
 
422
void
 
423
gcr_prompt_set_description (GcrPrompt *prompt,
 
424
                            const gchar *description)
 
425
{
 
426
        g_return_if_fail (GCR_IS_PROMPT (prompt));
 
427
        g_object_set (prompt, "description", description, NULL);
 
428
}
 
429
 
 
430
/**
 
431
 * gcr_prompt_get_warning:
 
432
 * @prompt: the prompt
 
433
 *
 
434
 * Get a prompt warning displayed on the prompt.
 
435
 *
 
436
 * This is a warning like "The password is incorrect." usually displayed to the
 
437
 * user about a previous 'unsuccessful' prompt.
 
438
 *
 
439
 * If this string is %NULL then no warning is displayed.
 
440
 *
 
441
 * Returns: (transfer full): a newly allocated string containing the prompt
 
442
 *          warning, or %NULL if no warning
 
443
 */
 
444
gchar *
 
445
gcr_prompt_get_warning (GcrPrompt *prompt)
 
446
{
 
447
        gchar *warning = NULL;
 
448
        g_return_val_if_fail (GCR_IS_PROMPT (prompt), NULL);
 
449
        g_object_get (prompt, "warning", &warning, NULL);
 
450
        return warning;
 
451
}
 
452
 
 
453
/**
 
454
 * gcr_prompt_set_warning:
 
455
 * @prompt: the prompt
 
456
 * @warning: (allow-none): the warning or %NULL
 
457
 *
 
458
 * Set a prompt warning displayed on the prompt.
 
459
 *
 
460
 * This is a warning like "The password is incorrect." usually displayed to the
 
461
 * user about a previous 'unsuccessful' prompt.
 
462
 *
 
463
 * If this string is %NULL then no warning is displayed.
 
464
 */
 
465
void
 
466
gcr_prompt_set_warning (GcrPrompt *prompt,
 
467
                        const gchar *warning)
 
468
{
 
469
        g_return_if_fail (GCR_IS_PROMPT (prompt));
 
470
        g_object_set (prompt, "warning", warning, NULL);
 
471
}
 
472
 
 
473
/**
 
474
 * gcr_prompt_get_choice_label:
 
475
 * @prompt: the prompt
 
476
 *
 
477
 * Get the label for the additional choice.
 
478
 *
 
479
 * This will be %NULL if no additional choice is being displayed.
 
480
 *
 
481
 * Returns: (transfer full): a newly allocated string containing the additional
 
482
 *          choice or %NULL
 
483
 */
 
484
gchar *
 
485
gcr_prompt_get_choice_label (GcrPrompt *prompt)
 
486
{
 
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);
 
490
        return choice_label;
 
491
}
 
492
 
 
493
/**
 
494
 * gcr_prompt_set_choice_label:
 
495
 * @prompt: the prompt
 
496
 * @choice_label: (allow-none): the additional choice or %NULL
 
497
 *
 
498
 * Set the label for the additional choice.
 
499
 *
 
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.
 
502
 *
 
503
 * The initial value of the choice can be set with the
 
504
 * gcr_prompt_set_choice_label() method.
 
505
 *
 
506
 * If this is %NULL, then no additional choice is being displayed.
 
507
 */
 
508
void
 
509
gcr_prompt_set_choice_label (GcrPrompt *prompt,
 
510
                             const gchar *choice_label)
 
511
{
 
512
        g_return_if_fail (GCR_IS_PROMPT (prompt));
 
513
        g_object_set (prompt, "choice-label", choice_label, NULL);
 
514
}
 
515
 
 
516
/**
 
517
 * gcr_prompt_get_choice_chosen:
 
518
 * @prompt: the prompt
 
519
 *
 
520
 * Get whether the additional choice was chosen or not.
 
521
 *
 
522
 * The additional choice would have been setup using
 
523
 * gcr_prompt_set_choice_label().
 
524
 *
 
525
 * Returns: whether chosen
 
526
 */
 
527
gboolean
 
528
gcr_prompt_get_choice_chosen (GcrPrompt *prompt)
 
529
{
 
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;
 
534
}
 
535
 
 
536
/**
 
537
 * gcr_prompt_set_choice_chosen:
 
538
 * @prompt: the prompt
 
539
 * @chosen: whether chosen
 
540
 *
 
541
 * Set whether the additional choice is chosen or not.
 
542
 *
 
543
 * The additional choice should be set up using gcr_prompt_set_choice_label().
 
544
 */
 
545
void
 
546
gcr_prompt_set_choice_chosen (GcrPrompt *prompt,
 
547
                              gboolean chosen)
 
548
{
 
549
        g_return_if_fail (GCR_IS_PROMPT (prompt));
 
550
        g_object_set (prompt, "choice-chosen", chosen, NULL);
 
551
}
 
552
 
 
553
/**
 
554
 * gcr_prompt_get_password_new:
 
555
 * @prompt: the prompt
 
556
 *
 
557
 * Get whether the prompt will prompt for a new password.
 
558
 *
 
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
 
561
 * password.
 
562
 *
 
563
 * Returns: whether in new password mode or not
 
564
 */
 
565
gboolean
 
566
gcr_prompt_get_password_new (GcrPrompt *prompt)
 
567
{
 
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);
 
571
        return password_new;
 
572
}
 
573
 
 
574
/**
 
575
 * gcr_prompt_set_password_new:
 
576
 * @prompt: the prompt
 
577
 * @new_password: whether in new password mode or not
 
578
 *
 
579
 * Set whether the prompt will prompt for a new password.
 
580
 *
 
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
 
583
 * password.
 
584
 */
 
585
void
 
586
gcr_prompt_set_password_new (GcrPrompt *prompt,
 
587
                             gboolean new_password)
 
588
{
 
589
        g_return_if_fail (GCR_IS_PROMPT (prompt));
 
590
        g_object_set (prompt, "password-new", new_password, NULL);
 
591
}
 
592
 
 
593
/**
 
594
 * gcr_prompt_get_password_strength:
 
595
 * @prompt: the prompt
 
596
 *
 
597
 * Get indication of the password strength.
 
598
 *
 
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.
 
601
 *
 
602
 * This is only valid after a successful prompt for a password.
 
603
 *
 
604
 * Returns: zero if the password is empty, greater than zero if not
 
605
 */
 
606
gint
 
607
gcr_prompt_get_password_strength (GcrPrompt *prompt)
 
608
{
 
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;
 
613
}
 
614
 
 
615
/**
 
616
 * gcr_prompt_get_caller_window:
 
617
 * @prompt: the prompt
 
618
 *
 
619
 * Get the string handle of the caller's window.
 
620
 *
 
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
 
623
 * way it sees fit.
 
624
 *
 
625
 * Returns: (transfer full): a newly allocated string containing the string
 
626
 *          handle of the window.
 
627
 */
 
628
gchar *
 
629
gcr_prompt_get_caller_window (GcrPrompt *prompt)
 
630
{
 
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;
 
635
}
 
636
 
 
637
/**
 
638
 * gcr_prompt_set_caller_window:
 
639
 * @prompt: the prompt
 
640
 * @window_id: the window id
 
641
 *
 
642
 * Set the string handle of the caller's window.
 
643
 *
 
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
 
646
 * way it sees fit.
 
647
 */
 
648
void
 
649
gcr_prompt_set_caller_window (GcrPrompt *prompt,
 
650
                              const gchar *window_id)
 
651
{
 
652
        g_return_if_fail (GCR_IS_PROMPT (prompt));
 
653
        g_object_set (prompt, "caller-window", window_id, NULL);
 
654
}
 
655
 
 
656
/**
 
657
 * gcr_prompt_get_continue_label:
 
658
 * @prompt: the prompt
 
659
 *
 
660
 * Get the label for the continue button.
 
661
 *
 
662
 * This is the button that results in a %GCR_PROMPT_REPLY_CONTINUE reply
 
663
 * from the prompt.
 
664
 *
 
665
 * Returns: (transfer full): a newly allocated string containing the label
 
666
 */
 
667
gchar *
 
668
gcr_prompt_get_continue_label (GcrPrompt *prompt)
 
669
{
 
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;
 
674
}
 
675
 
 
676
/**
 
677
 * gcr_prompt_set_continue_label:
 
678
 * @prompt: the prompt
 
679
 * @continue_label: the label
 
680
 *
 
681
 * Set the label for the continue button.
 
682
 *
 
683
 * This is the button that results in a %GCR_PROMPT_REPLY_CONTINUE reply
 
684
 * from the prompt.
 
685
 */
 
686
void
 
687
gcr_prompt_set_continue_label (GcrPrompt *prompt,
 
688
                               const gchar *continue_label)
 
689
{
 
690
        g_return_if_fail (GCR_IS_PROMPT (prompt));
 
691
        g_object_set (prompt, "continue-label", continue_label, NULL);
 
692
}
 
693
 
 
694
/**
 
695
 * gcr_prompt_get_cancel_label:
 
696
 * @prompt: the prompt
 
697
 *
 
698
 * Get the label for the cancel button.
 
699
 *
 
700
 * This is the button that results in a %GCR_PROMPT_REPLY_CANCEL reply
 
701
 * from the prompt.
 
702
 *
 
703
 * Returns: (transfer full): a newly allocated string containing the label
 
704
 */
 
705
gchar *
 
706
gcr_prompt_get_cancel_label (GcrPrompt *prompt)
 
707
{
 
708
        gchar *cancel_label = NULL;
 
709
        g_object_get (prompt, "cancel-label", &cancel_label, NULL);
 
710
        return cancel_label;
 
711
}
 
712
 
 
713
/**
 
714
 * gcr_prompt_set_cancel_label:
 
715
 * @prompt: the prompt
 
716
 * @cancel_label: the label
 
717
 *
 
718
 * Set the label for the continue button.
 
719
 *
 
720
 * This is the button that results in a %GCR_PROMPT_REPLY_CANCEL reply
 
721
 * from the prompt.
 
722
 */
 
723
void
 
724
gcr_prompt_set_cancel_label (GcrPrompt *prompt,
 
725
                             const gchar *cancel_label)
 
726
{
 
727
        g_return_if_fail (GCR_IS_PROMPT (prompt));
 
728
        g_object_set (prompt, "cancel-label", cancel_label, NULL);
 
729
}
 
730
 
 
731
/**
 
732
 * gcr_prompt_password_async:
 
733
 * @prompt: a prompt
 
734
 * @cancellable: optional cancellation object
 
735
 * @callback: called when the operation completes
 
736
 * @user_data: data to pass to the callback
 
737
 *
 
738
 * Prompts for password. Set the various properties on the prompt before calling
 
739
 * this method to explain which password should be entered.
 
740
 *
 
741
 * This method will return immediately and complete asynchronously.
 
742
 */
 
743
void
 
744
gcr_prompt_password_async (GcrPrompt *prompt,
 
745
                           GCancellable *cancellable,
 
746
                           GAsyncReadyCallback callback,
 
747
                           gpointer user_data)
 
748
{
 
749
        GcrPromptIface *iface;
 
750
 
 
751
        g_return_if_fail (GCR_IS_PROMPT (prompt));
 
752
        g_return_if_fail (cancellable == NULL || G_IS_CANCELLABLE (cancellable));
 
753
 
 
754
        iface = GCR_PROMPT_GET_INTERFACE (prompt);
 
755
        g_return_if_fail (iface->prompt_password_async);
 
756
 
 
757
        (iface->prompt_password_async) (prompt, cancellable, callback, user_data);
 
758
}
 
759
 
 
760
/**
 
761
 * gcr_prompt_password_finish:
 
762
 * @prompt: a prompt
 
763
 * @result: asynchronous result passed to callback
 
764
 * @error: location to place error on failure
 
765
 *
 
766
 * Complete an operation to prompt for a password.
 
767
 *
 
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.
 
771
 *
 
772
 * %NULL will be returned if the user cancels or if an error occurs. Check the
 
773
 * @error argument to tell the difference.
 
774
 *
 
775
 * Returns: the password owned by the prompt, or %NULL
 
776
 */
 
777
const gchar *
 
778
gcr_prompt_password_finish (GcrPrompt *prompt,
 
779
                            GAsyncResult *result,
 
780
                            GError **error)
 
781
{
 
782
        GcrPromptIface *iface;
 
783
 
 
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);
 
787
 
 
788
        iface = GCR_PROMPT_GET_INTERFACE (prompt);
 
789
        g_return_val_if_fail (iface->prompt_password_async, NULL);
 
790
 
 
791
        return (iface->prompt_password_finish) (prompt, result, error);
 
792
}
 
793
 
 
794
/**
 
795
 * gcr_prompt_password:
 
796
 * @prompt: a prompt
 
797
 * @cancellable: optional cancellation object
 
798
 * @error: location to place error on failure
 
799
 *
 
800
 * Prompts for password. Set the various properties on the prompt before calling
 
801
 * this method to explain which password should be entered.
 
802
 *
 
803
 * This method will block until the a response is returned from the prompter.
 
804
 *
 
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.
 
808
 *
 
809
 * %NULL will be returned if the user cancels or if an error occurs. Check the
 
810
 * @error argument to tell the difference.
 
811
 *
 
812
 * Returns: the password owned by the prompt, or %NULL
 
813
 */
 
814
const gchar *
 
815
gcr_prompt_password (GcrPrompt *prompt,
 
816
                     GCancellable *cancellable,
 
817
                     GError **error)
 
818
{
 
819
        RunClosure *closure;
 
820
        const gchar *reply;
 
821
 
 
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);
 
825
 
 
826
        closure = run_closure_begin (g_main_context_new ());
 
827
 
 
828
        gcr_prompt_password_async (prompt, cancellable, on_run_complete, closure);
 
829
 
 
830
        g_main_loop_run (closure->loop);
 
831
 
 
832
        reply = gcr_prompt_password_finish (prompt, closure->result, error);
 
833
        run_closure_end (closure);
 
834
 
 
835
        return reply;
 
836
}
 
837
 
 
838
/**
 
839
 * gcr_prompt_password_run:
 
840
 * @prompt: a prompt
 
841
 * @cancellable: optional cancellation object
 
842
 * @error: location to place error on failure
 
843
 *
 
844
 * Prompts for password. Set the various properties on the prompt before calling
 
845
 * this method to explain which password should be entered.
 
846
 *
 
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.
 
850
 *
 
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.
 
854
 *
 
855
 * %NULL will be returned if the user cancels or if an error occurs. Check the
 
856
 * @error argument to tell the difference.
 
857
 *
 
858
 * Returns: the password owned by the prompt, or %NULL
 
859
 */
 
860
const gchar *
 
861
gcr_prompt_password_run (GcrPrompt *prompt,
 
862
                         GCancellable *cancellable,
 
863
                         GError **error)
 
864
{
 
865
        RunClosure *closure;
 
866
        const gchar *reply;
 
867
 
 
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);
 
871
 
 
872
        closure = run_closure_begin (NULL);
 
873
 
 
874
        gcr_prompt_password_async (prompt, cancellable, on_run_complete, closure);
 
875
 
 
876
        g_main_loop_run (closure->loop);
 
877
 
 
878
        reply = gcr_prompt_password_finish (prompt, closure->result, error);
 
879
        run_closure_end (closure);
 
880
 
 
881
        return reply;
 
882
}
 
883
 
 
884
/**
 
885
 * gcr_prompt_confirm_async:
 
886
 * @prompt: a prompt
 
887
 * @cancellable: optional cancellation object
 
888
 * @callback: called when the operation completes
 
889
 * @user_data: data to pass to the callback
 
890
 *
 
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.
 
894
 *
 
895
 * This method will return immediately and complete asynchronously.
 
896
 */
 
897
void
 
898
gcr_prompt_confirm_async (GcrPrompt *prompt,
 
899
                          GCancellable *cancellable,
 
900
                          GAsyncReadyCallback callback,
 
901
                          gpointer user_data)
 
902
{
 
903
        GcrPromptIface *iface;
 
904
 
 
905
        g_return_if_fail (GCR_IS_PROMPT (prompt));
 
906
        g_return_if_fail (cancellable == NULL || G_IS_CANCELLABLE (cancellable));
 
907
 
 
908
        iface = GCR_PROMPT_GET_INTERFACE (prompt);
 
909
        g_return_if_fail (iface->prompt_confirm_async);
 
910
 
 
911
        (iface->prompt_confirm_async) (prompt, cancellable, callback, user_data);
 
912
}
 
913
 
 
914
/**
 
915
 * gcr_prompt_confirm_finish:
 
916
 * @prompt: a prompt
 
917
 * @result: asynchronous result passed to callback
 
918
 * @error: location to place error on failure
 
919
 *
 
920
 * Complete an operation to prompt for confirmation.
 
921
 *
 
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.
 
925
 *
 
926
 * Returns: the reply from the prompt
 
927
 */
 
928
GcrPromptReply
 
929
gcr_prompt_confirm_finish (GcrPrompt *prompt,
 
930
                           GAsyncResult *result,
 
931
                           GError **error)
 
932
{
 
933
        GcrPromptIface *iface;
 
934
 
 
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);
 
938
 
 
939
        iface = GCR_PROMPT_GET_INTERFACE (prompt);
 
940
        g_return_val_if_fail (iface->prompt_confirm_async, GCR_PROMPT_REPLY_CANCEL);
 
941
 
 
942
        return (iface->prompt_confirm_finish) (prompt, result, error);
 
943
}
 
944
 
 
945
/**
 
946
 * gcr_prompt_confirm:
 
947
 * @prompt: a prompt
 
948
 * @cancellable: optional cancellation object
 
949
 * @error: location to place error on failure
 
950
 *
 
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.
 
954
 *
 
955
 * This method will block until the a response is returned from the prompter.
 
956
 *
 
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.
 
960
 *
 
961
 * Returns: the reply from the prompt
 
962
 */
 
963
GcrPromptReply
 
964
gcr_prompt_confirm (GcrPrompt *prompt,
 
965
                    GCancellable *cancellable,
 
966
                    GError **error)
 
967
{
 
968
        RunClosure *closure;
 
969
        GcrPromptReply reply;
 
970
 
 
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);
 
974
 
 
975
        closure = run_closure_begin (g_main_context_new ());
 
976
 
 
977
        gcr_prompt_confirm_async (prompt, cancellable, on_run_complete, closure);
 
978
 
 
979
        g_main_loop_run (closure->loop);
 
980
 
 
981
        reply = gcr_prompt_confirm_finish (prompt, closure->result, error);
 
982
        run_closure_end (closure);
 
983
 
 
984
        return reply;
 
985
}
 
986
 
 
987
/**
 
988
 * gcr_prompt_confirm_run:
 
989
 * @prompt: a prompt
 
990
 * @cancellable: optional cancellation object
 
991
 * @error: location to place error on failure
 
992
 *
 
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.
 
996
 *
 
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.
 
1000
 *
 
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.
 
1004
 *
 
1005
 * Returns: the reply from the prompt
 
1006
 */
 
1007
GcrPromptReply
 
1008
gcr_prompt_confirm_run (GcrPrompt *prompt,
 
1009
                        GCancellable *cancellable,
 
1010
                        GError **error)
 
1011
{
 
1012
        RunClosure *closure;
 
1013
        GcrPromptReply reply;
 
1014
 
 
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);
 
1018
 
 
1019
        closure = run_closure_begin (NULL);
 
1020
 
 
1021
        gcr_prompt_confirm_async (prompt, cancellable, on_run_complete, closure);
 
1022
 
 
1023
        g_main_loop_run (closure->loop);
 
1024
 
 
1025
        reply = gcr_prompt_confirm_finish (prompt, closure->result, error);
 
1026
        run_closure_end (closure);
 
1027
 
 
1028
        return reply;
 
1029
}