2006-11-08 Michael Dominic Kostrzewa <michael.kostrzewa@nokia.com>
[hildon] / hildon-widgets / hildon-set-password-dialog.c
1 /*
2  * This file is part of hildon-libs
3  *
4  * Copyright (C) 2005, 2006 Nokia Corporation, all rights reserved.
5  *
6  * Contact: Michael Dominic Kostrzewa <michael.kostrzewa@nokia.com>
7  *
8  * This library is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU Lesser General Public License
10  * as published by the Free Software Foundation; version 2.1 of
11  * the License.
12  *
13  * This library is distributed in the hope that it will be useful, but
14  * WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16  * Lesser General Public License for more details.
17  *
18  * You should have received a copy of the GNU Lesser General Public
19  * License along with this library; if not, write to the Free Software
20  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
21  * 02110-1301 USA
22  *
23  */
24
25 /**
26  * SECTION:hildon-set-password-dialog
27  * @short_description: A dialog used to set, change or remove a password
28  * @see_also: #HildonGetPasswordDialog
29  *
30  * HildonSetPasswordDialog allows setting and changing a password. 
31  * 
32  * In Change mode: Dialog is used to change or remove an existing
33  * password. Unselecting the check box dims the password fields below
34  * it. If the dialog is accepted with 'OK' while the check box is
35  * unselected, a Confirmation Note is shown.  If the Confirmation Note
36  * Dialog is accepted with 'Remove', the password protection is removed.  
37  * 
38  * In Set mode: Set Password Dialog is used to define a password, or
39  * change a password that cannot be removed.
40  */
41
42 #ifdef HAVE_CONFIG_H
43 #include <config.h>
44 #endif
45
46
47 #include <gdk/gdkkeysyms.h>
48 #include <gtk/gtk.h>
49 #include <glib.h>
50
51 #include <errno.h>
52 #include <string.h>
53 #include <strings.h>
54 #include <unistd.h>
55 #include <stdio.h>
56
57 #include <hildon-widgets/hildon-caption.h>
58 #include <hildon-widgets/gtk-infoprint.h>
59 #include <hildon-widgets/hildon-set-password-dialog.h>
60 #include <hildon-widgets/hildon-note.h>
61 #include <hildon-widgets/hildon-defines.h>
62
63 #include <libintl.h>
64 #define  _(String) dgettext(PACKAGE, String)
65 #define c_(String) dgettext("hildon-common-strings", String)
66
67 static GtkDialogClass *parent_class;
68
69 #define HILDON_SET_PASSWORD_DIALOG_GET_PRIVATE(obj)\
70  (G_TYPE_INSTANCE_GET_PRIVATE ((obj), \
71   HILDON_TYPE_SET_PASSWORD_DIALOG, HildonSetPasswordDialogPrivate));
72
73 typedef struct
74 _HildonSetPasswordDialogPrivate HildonSetPasswordDialogPrivate;
75
76 static void
77 hildon_set_password_dialog_class_init(HildonSetPasswordDialogClass *
78                                       class);
79 static void hildon_set_password_dialog_init(HildonSetPasswordDialog *
80                                             dialog);
81 static void hildon_checkbox_toggled(GtkWidget * widget, gpointer dialog);
82
83 static void
84 hildon_set_password_response_change(GtkDialog * d, gint arg1, gpointer unused);
85 static void
86 hildon_set_password_response_set(GtkDialog * d, gint arg1, gpointer unused);
87
88 static void create_contents(HildonSetPasswordDialog *dialog);
89 static void hildon_set_password_set_property(GObject * object,
90                                              guint prop_id,
91                                              const GValue * value,
92                                              GParamSpec * pspec);
93 static void hildon_set_password_get_property(GObject * object,
94                                              guint prop_id, GValue * value,
95                                              GParamSpec * pspec);
96
97 /* Private struct */
98 struct _HildonSetPasswordDialogPrivate {
99     GtkWidget *checkboxCaption;
100     GtkWidget *checkbox;
101
102     GtkLabel *domainLabel;
103
104     GtkWidget *pwd1stEntry;
105     GtkWidget *pwd1stCaption;
106     gchar *pwd1stCaption_string;
107
108     GtkWidget *pwd2ndEntry;
109     GtkWidget *pwd2ndCaption;
110     gchar *pwd2ndCaption_string;
111
112     GtkWidget *okButton;
113     GtkWidget *cancelButton;
114
115     gboolean protection;
116 };
117
118 enum {
119     PROP_NONE = 0,
120     PROP_DOMAIN,
121     PROP_PASSWORD,
122     PROP_HILDON_PASSWORD_DIALOG
123 };
124
125 /* Private functions */
126 static void
127 hildon_set_password_set_property(GObject * object,
128                                  guint prop_id,
129                                  const GValue * value, GParamSpec * pspec)
130 {
131     HildonSetPasswordDialog *dialog = HILDON_SET_PASSWORD_DIALOG(object);
132     HildonSetPasswordDialogPrivate *priv;
133
134     priv = HILDON_SET_PASSWORD_DIALOG_GET_PRIVATE(dialog);
135     
136     switch (prop_id) {
137     case PROP_DOMAIN:
138         /* Update domain label to display new value */
139         gtk_label_set_text(priv->domainLabel, g_value_get_string(value));
140         break;
141     case PROP_PASSWORD:
142         /* Update password entry to display new value */
143         gtk_entry_set_text(GTK_ENTRY(priv->pwd1stEntry), g_value_get_string(value));
144         break;
145     case PROP_HILDON_PASSWORD_DIALOG:
146         /* Note this is a G_PARAM_CONSTRUCT_ONLY type property */
147         priv->protection = g_value_get_boolean(value);
148
149         /* We now have the necessary information to populate the dialog */
150         create_contents(dialog);
151         break;
152     default:
153         G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
154         break;
155     }
156 }
157
158 static void
159 hildon_set_password_get_property(GObject    * object,
160                                  guint        prop_id,
161                                  GValue     * value,
162                                  GParamSpec * pspec)
163 {
164     HildonSetPasswordDialogPrivate *priv = NULL;
165
166     priv = HILDON_SET_PASSWORD_DIALOG_GET_PRIVATE(object);
167     
168     switch (prop_id) {
169     case PROP_DOMAIN:
170         g_value_set_string(value, gtk_label_get_text(priv->domainLabel));
171         break;
172     case PROP_PASSWORD:
173         g_value_set_string(value,
174                            gtk_entry_get_text(GTK_ENTRY(priv->pwd1stEntry)));
175         break;
176     case PROP_HILDON_PASSWORD_DIALOG:
177         g_value_set_boolean(value, priv->protection);
178         break;
179     default:
180         G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
181         break;
182     }
183 }
184
185
186 static void
187 create_contents(HildonSetPasswordDialog *dialog)
188 {
189     HildonSetPasswordDialogPrivate *priv = NULL;
190
191     GtkSizeGroup *group;
192
193     priv = HILDON_SET_PASSWORD_DIALOG_GET_PRIVATE(dialog);
194     priv->checkbox = NULL;
195
196     /* Size group for labels */
197     group = GTK_SIZE_GROUP(gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL));
198
199     gtk_dialog_set_has_separator(GTK_DIALOG(dialog), FALSE);
200
201     /* Setup and pack domain label */
202     priv->domainLabel = GTK_LABEL(gtk_label_new(NULL));
203     gtk_box_pack_start(GTK_BOX(GTK_DIALOG(dialog)->vbox),
204                        GTK_WIDGET(priv->domainLabel), FALSE, FALSE, 0);
205     gtk_widget_show(GTK_WIDGET(priv->domainLabel));
206
207     if (priv->protection == TRUE) {
208         /* Use Change Password Dialog strings */
209         priv->pwd1stCaption_string = _(HILDON_SET_MODIFY_PASSWORD_DIALOG_PASSWORD);
210         priv->pwd2ndCaption_string = _(HILDON_SET_MODIFY_PASSWORD_DIALOG_VERIFY_PASSWORD);
211
212         /* Setup checkbox to enable/disable password protection */
213         priv->checkbox = gtk_check_button_new();
214         gtk_widget_show(priv->checkbox);
215         priv->checkboxCaption = hildon_caption_new
216           (group,
217            _(HILDON_SET_MODIFY_PASSWORD_DIALOG_LABEL),
218            priv->checkbox,
219            NULL, HILDON_CAPTION_OPTIONAL);
220         hildon_caption_set_separator(HILDON_CAPTION(priv->checkboxCaption), "");
221         gtk_box_pack_start(GTK_BOX(GTK_DIALOG(dialog)->vbox),
222                            priv->checkboxCaption, TRUE, TRUE, 0);
223         gtk_widget_show(priv->checkboxCaption);
224         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(priv->checkbox),
225                                      TRUE);
226         gtk_signal_connect(GTK_OBJECT(priv->checkbox), "toggled",
227                            G_CALLBACK(hildon_checkbox_toggled), dialog);
228  
229         /* Setup appropriate response handler */
230         g_signal_connect(G_OBJECT(dialog), "response",
231                          G_CALLBACK(hildon_set_password_response_change),
232                          NULL);
233     } else {
234         /* Use Set Password Dialog strings */
235         priv->pwd1stCaption_string = _(HILDON_SET_PASSWORD_DIALOG_PASSWORD);
236         priv->pwd2ndCaption_string = _(HILDON_SET_PASSWORD_DIALOG_VERIFY_PASSWORD);
237
238         /* Setup appropriate response handler */
239         g_signal_connect(G_OBJECT(dialog), "response",
240                          G_CALLBACK(hildon_set_password_response_set),
241                          NULL);
242     }
243
244     /* Create the password field */
245     priv->pwd1stEntry = gtk_entry_new();
246     g_object_set (priv->pwd1stEntry, "hildon-input-mode", HILDON_GTK_INPUT_MODE_FULL, NULL);
247     gtk_entry_set_visibility(GTK_ENTRY(priv->pwd1stEntry), FALSE);
248     gtk_widget_show(priv->pwd1stEntry);
249     priv->pwd1stCaption = hildon_caption_new(group,
250                                         priv->pwd1stCaption_string,
251                                         priv->pwd1stEntry,
252                                         NULL, HILDON_CAPTION_OPTIONAL);
253     hildon_caption_set_separator(HILDON_CAPTION(priv->pwd1stCaption), "");
254     gtk_entry_set_visibility(GTK_ENTRY(priv->pwd1stEntry), FALSE);
255     gtk_box_pack_start(GTK_BOX(GTK_DIALOG(dialog)->vbox),
256                        priv->pwd1stCaption, TRUE, TRUE, 0);
257     gtk_widget_show(priv->pwd1stCaption);
258
259     /* Create the password verify field */
260     priv->pwd2ndEntry = gtk_entry_new();
261     g_object_set (priv->pwd2ndEntry, "hildon-input-mode", HILDON_GTK_INPUT_MODE_FULL, NULL);
262     gtk_widget_show(priv->pwd2ndEntry);
263     priv->pwd2ndCaption = hildon_caption_new(group,
264                                         priv->pwd2ndCaption_string,
265                                         priv->pwd2ndEntry,
266                                         NULL, HILDON_CAPTION_OPTIONAL);
267     hildon_caption_set_separator(HILDON_CAPTION(priv->pwd2ndCaption), "");
268     gtk_entry_set_visibility(GTK_ENTRY(priv->pwd2ndEntry), FALSE);
269     gtk_box_pack_start(GTK_BOX(GTK_DIALOG(dialog)->vbox),
270                        priv->pwd2ndCaption, TRUE, TRUE, 0);
271     gtk_widget_show(priv->pwd2ndCaption);
272
273     /* Set dialog title */
274     gtk_window_set_title(GTK_WINDOW(dialog),
275                          _(priv->protection
276                            ? HILDON_SET_MODIFY_PASSWORD_DIALOG_TITLE
277                            : HILDON_SET_PASSWORD_DIALOG_TITLE));
278
279     /* Create the OK/CANCEL buttons */
280     priv->okButton = gtk_dialog_add_button
281       (GTK_DIALOG(dialog),  _(priv->protection
282                               ? HILDON_SET_MODIFY_PASSWORD_DIALOG_OK
283                               : HILDON_SET_PASSWORD_DIALOG_OK),
284        GTK_RESPONSE_OK);
285     priv->cancelButton = gtk_dialog_add_button
286       (GTK_DIALOG(dialog), _(priv->protection
287                              ? HILDON_SET_MODIFY_PASSWORD_DIALOG_CANCEL
288                              : HILDON_SET_PASSWORD_DIALOG_CANCEL),
289        GTK_RESPONSE_CANCEL);
290     
291     gtk_widget_show(priv->okButton);
292     gtk_widget_show(priv->cancelButton);
293
294     /* Ensure group is freed when all its contents have been removed */
295     g_object_unref(group);
296 }
297
298 static void
299 hildon_set_password_dialog_class_init(HildonSetPasswordDialogClass * class)
300 {
301     GObjectClass *object_class = G_OBJECT_CLASS(class);
302
303     parent_class = g_type_class_peek_parent(class);
304
305     /* Override virtual methods */
306     object_class->set_property = hildon_set_password_set_property;
307     object_class->get_property = hildon_set_password_get_property;
308
309     /* Install new properties */
310     g_object_class_install_property(object_class, 
311                      PROP_DOMAIN, 
312                      g_param_spec_string ("domain",
313                                           "Domain",
314                                           "Set Domain (content) for domain label.",
315                                           NULL,
316                                           G_PARAM_READWRITE));
317
318     g_object_class_install_property(object_class, 
319                      PROP_HILDON_PASSWORD_DIALOG, 
320                      g_param_spec_boolean ("modify_protection",
321                                           "Password type",
322                                           "Set type to dialog",
323                                           TRUE, 
324                                           G_PARAM_CONSTRUCT_ONLY |
325                                           G_PARAM_READWRITE));
326
327     g_object_class_install_property(object_class, 
328                      PROP_PASSWORD, 
329                      g_param_spec_string ("password",
330                                           "Password content",
331                                           "Set content to dialog",
332                                           "DEFAULT",
333                                           G_PARAM_READWRITE));
334
335     /* Install private structure */
336     g_type_class_add_private(class,
337                              sizeof(HildonSetPasswordDialogPrivate));
338 }
339
340 static void
341 hildon_set_password_dialog_init(HildonSetPasswordDialog * dialog)
342 {
343     /* Most of the initializations are done in create_contents()
344        after the 'modify_protection' property has been set */
345
346     gtk_window_set_modal(GTK_WINDOW(dialog), TRUE);
347 }
348
349
350 /* We come here when response button is clicked and dialog 
351    is used to change existing password. */
352 static void
353 hildon_set_password_response_change(GtkDialog * dialog, gint arg1,
354                                     gpointer unused)
355 {
356     GtkEntry *pwd1stEntry;
357     GtkEntry *pwd2ndEntry;
358     gchar *text1;
359     gchar *text2;
360     HildonNote *note;
361     gint i;
362     HildonSetPasswordDialogPrivate *priv;
363
364     priv = HILDON_SET_PASSWORD_DIALOG_GET_PRIVATE(dialog);
365
366     /* Password and verification */
367     pwd1stEntry = GTK_ENTRY(gtk_bin_get_child
368                             (GTK_BIN(priv->pwd1stCaption)));
369     pwd2ndEntry = GTK_ENTRY(gtk_bin_get_child
370                             (GTK_BIN(priv->pwd2ndCaption)));
371     text1 = GTK_ENTRY(pwd1stEntry)->text;
372     text2 = GTK_ENTRY(pwd2ndEntry)->text;
373
374     /* User accepted the dialog */
375     if (arg1 == GTK_RESPONSE_OK){
376       /* Is the checkbox marked, so password protection is still in use? */  
377       if(gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(priv->checkbox))){
378     /* Yes, Something is given as password as well? */
379         if (text1[0] != '\0') {
380           if (strcmp (text1, text2) == 0) {
381             /* Passwords match, so accept change password */
382             priv->protection = TRUE;
383           } else if (text2[0] == '\0') {
384             /* Second field is empty, so show error, but don't clear fields */
385             g_signal_stop_emission_by_name(G_OBJECT(dialog),
386                                            "response");
387             gtk_infoprint (NULL,
388                            c_(HILDON_SET_PASSWORD_DIALOG_MISMATCH));
389             gtk_widget_grab_focus(GTK_WIDGET(pwd2ndEntry));
390           } else {
391             /* Error: Passwords don't match, so start over */
392             g_signal_stop_emission_by_name(G_OBJECT(dialog),
393                                            "response");
394             gtk_entry_set_text(pwd1stEntry, "");
395             gtk_entry_set_text(pwd2ndEntry, "");
396             gtk_infoprint (NULL,
397                            c_(HILDON_SET_PASSWORD_DIALOG_MISMATCH));
398             gtk_widget_grab_focus(GTK_WIDGET(pwd1stEntry));
399           }
400         } else {
401           /* No, the password is empty */
402           g_signal_stop_emission_by_name(G_OBJECT(dialog), "response");
403           if (text2[0] == '\0') {
404             /* Error: Both fields are empty */
405             gtk_infoprint (NULL, c_(HILDON_SET_PASSWORD_DIALOG_EMPTY));
406           } else {
407             /* Error: Second field doesn't match
408                the empty first field, so start over */
409             gtk_infoprint (NULL, c_(HILDON_SET_PASSWORD_DIALOG_MISMATCH));
410             gtk_entry_set_text(pwd2ndEntry, "");
411           }
412           gtk_widget_grab_focus(GTK_WIDGET(pwd1stEntry));
413         }
414       } else {
415         /* No, user wants to remove password protection. 
416            Confirm remove password protection */
417         note = HILDON_NOTE(hildon_note_new_confirmation
418                            (GTK_WINDOW(dialog),
419                             c_(HILDON_SET_PASSWORD_DIALOG_REMOVE_PROTECTION
420                               )));
421       
422         hildon_note_set_button_texts
423           (HILDON_NOTE(note),
424            c_(HILDON_REMOVE_PROTECTION_CONFIRMATION_REMOVE), 
425            c_(HILDON_REMOVE_PROTECTION_CONFIRMATION_CANCEL));
426         
427         /* Display confirmation note */
428         i = gtk_dialog_run(GTK_DIALOG(note));
429         
430         gtk_widget_destroy(GTK_WIDGET(note));
431         
432         if (i == GTK_RESPONSE_OK)
433           /* Remove password protection */
434           priv->protection = FALSE;
435         else {
436           /* Remove password protection cancelled */
437           priv->protection = TRUE;
438           g_signal_stop_emission_by_name(G_OBJECT(dialog), "response");
439         }
440       }
441
442     } else {
443       /* Watch out for fading boolean values */
444       priv->protection = TRUE;
445     }
446 }
447
448 /* We come here when response button is clicked and dialog 
449    is used to set new password. */
450 static void
451 hildon_set_password_response_set(GtkDialog * dialog, gint arg1,
452                                  gpointer unused)
453 {
454     GtkEntry *pwd1stEntry;
455     GtkEntry *pwd2ndEntry;
456     gchar *text1;
457     gchar *text2;
458
459     HildonSetPasswordDialogPrivate *priv;
460
461     priv = HILDON_SET_PASSWORD_DIALOG_GET_PRIVATE(dialog);
462
463     /* Password and confirmation */
464     pwd1stEntry = GTK_ENTRY(gtk_bin_get_child
465                             (GTK_BIN(priv->pwd1stCaption)));
466     pwd2ndEntry = GTK_ENTRY(gtk_bin_get_child
467                             (GTK_BIN(priv->pwd2ndCaption)));
468     text1 = GTK_ENTRY(pwd1stEntry)->text;
469     text2 = GTK_ENTRY(pwd2ndEntry)->text;
470
471     if (arg1 == GTK_RESPONSE_OK) {
472         /* User provided something for password? */
473         if (text1[0] != '\0') {
474             if (strcmp (text1, text2) == 0) {
475                 /* Passwords match, so accept set password */
476                 priv->protection = TRUE;
477             } else if (text2[0] == '\0') {
478                 /* Second field is empty, so show error,
479                    but don't clear the fields */
480                 g_signal_stop_emission_by_name(G_OBJECT(dialog), "response");
481                 gtk_infoprint (NULL, c_(HILDON_SET_PASSWORD_DIALOG_MISMATCH));
482                 gtk_widget_grab_focus (GTK_WIDGET (priv->pwd2ndEntry));
483             } else {
484                 /* Error: Passwords don't match, so start over */
485                 g_signal_stop_emission_by_name(G_OBJECT(dialog), "response");
486                 gtk_entry_set_text(pwd1stEntry, "");
487                 gtk_entry_set_text(pwd2ndEntry, "");
488                 gtk_infoprint (NULL, c_(HILDON_SET_PASSWORD_DIALOG_MISMATCH));
489                 gtk_widget_grab_focus(GTK_WIDGET(priv->pwd1stEntry));
490             }
491         } else {
492           /* First field is empty */
493           g_signal_stop_emission_by_name(G_OBJECT(dialog), "response");
494           if (text2[0] == '\0') {
495             /* Error: Both fields are empty */
496             gtk_infoprint (NULL, c_(HILDON_SET_PASSWORD_DIALOG_EMPTY));
497           } else {
498             /* Error: Second field doesn't match
499                the empty first field, so start over */
500             gtk_infoprint (NULL, c_(HILDON_SET_PASSWORD_DIALOG_MISMATCH));
501             gtk_entry_set_text(pwd2ndEntry, "");
502           }
503           gtk_widget_grab_focus(GTK_WIDGET(pwd1stEntry));
504         }
505     } else { 
506         /* Watch out for fading boolean values */
507         priv->protection = FALSE;
508     }             
509 }
510
511 static void hildon_checkbox_toggled(GtkWidget * widget, gpointer dialog)
512 {
513     HildonSetPasswordDialogPrivate *priv =
514       HILDON_SET_PASSWORD_DIALOG_GET_PRIVATE(dialog);
515     gboolean active;
516
517     /* If the user enabled/disabled the password protection feature
518        we enable/disable password entries accordingly */
519     active = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget));
520     gtk_widget_set_sensitive(GTK_WIDGET(priv->pwd1stEntry), active);
521     gtk_widget_set_sensitive(GTK_WIDGET(priv->pwd2ndEntry), active);
522 }
523
524 /* Public functions */
525
526 /**
527  * hildon_set_password_dialog_get_type:
528  *
529  * Returns GType for HildonPasswordDialog as produced by
530  * g_type_register_static().
531  *
532  * Returns: HildonSetPasswordDialog type
533  */
534 GType hildon_set_password_dialog_get_type(void)
535 {
536     static GType dialog_type = 0;
537
538     if (!dialog_type) {
539         static const GTypeInfo dialog_info = {
540             sizeof(HildonSetPasswordDialogClass),
541             NULL,       /* base_init */
542             NULL,       /* base_finalize */
543             (GClassInitFunc) hildon_set_password_dialog_class_init,
544             NULL,       /* class_finalize */
545             NULL,       /* class_data */
546             sizeof(HildonSetPasswordDialog),
547             0,  /* n_preallocs */
548             (GInstanceInitFunc) hildon_set_password_dialog_init
549         };
550
551         dialog_type = g_type_register_static(GTK_TYPE_DIALOG,
552                                              "HildonSetPasswordDialog",
553                                              &dialog_info, 0);
554     }
555     return dialog_type;
556 }
557
558 /**
559  * hildon_set_password_dialog_new:
560  * @parent: parent window; can be NULL
561  * @modify_protection: TRUE creates a new change password dialog and FALSE
562  *                     creates a new set password dialog 
563  * 
564  * Constructs a new HildonSetPasswordDialog.
565  *
566  * Returns: a new #GtkWidget of type HildonSetPasswordDialog
567  */
568
569 GtkWidget *hildon_set_password_dialog_new(GtkWindow * parent,
570                                           gboolean modify_protection)
571 {
572     return hildon_set_password_dialog_new_with_default(parent, "",
573                                                        modify_protection);
574 }
575
576 /**
577  * hildon_set_password_dialog_new_with_default:
578  * @parent: parent window; can be NULL
579  * @password: a default password to be shown in password field
580  * @modify_protection: TRUE creates a new change password dialog and FALSE
581  *                     creates a new set password dialog 
582  * 
583  * Same as #hildon_set_password_dialog_new, but with a default password
584  * in password field.
585  *
586  * Returns: a new #GtkWidget of type HildonSetPasswordDialog
587  */
588
589 GtkWidget *hildon_set_password_dialog_new_with_default
590                                          (GtkWindow *parent,
591                                           const gchar *password,
592                                           gboolean modify_protection)
593 {
594     GtkWidget *dialog = g_object_new(HILDON_TYPE_SET_PASSWORD_DIALOG,
595                                      "modify_protection", modify_protection,
596                                      "password", password, NULL);
597
598     if (parent != NULL) {
599         gtk_window_set_transient_for(GTK_WINDOW(dialog), parent);
600     }
601    
602     return dialog;
603 }
604
605 /**
606  * hildon_set_password_dialog_get_password:
607  * @dialog: pointer to HildonSetPasswordDialog
608  * 
609  * Returns current password.
610  *
611  * Returns: changed password ( if the dialog is successfully 
612  * accepted with 'OK' ( and when the check box is 'ON' ( in Change Password
613  * Dialog ))
614  */
615 const gchar
616     *hildon_set_password_dialog_get_password(HildonSetPasswordDialog *
617                                              dialog)
618 {
619     HildonSetPasswordDialogPrivate *priv;
620
621     g_return_val_if_fail(HILDON_IS_SET_PASSWORD_DIALOG(dialog), NULL);
622
623     priv = HILDON_SET_PASSWORD_DIALOG_GET_PRIVATE(dialog);
624
625     return GTK_ENTRY(priv->pwd1stEntry)->text;
626 }
627
628 /**
629  * hildon_set_password_dialog_get_protected:
630  * @dialog: pointer to HildonSetPasswordDialog
631  * 
632  * Returns the protection mode.
633  *
634  * Returns: password protection mode ( TRUE when the protection is
635  *               'ON' and FALSE when the protection is 'OFF' )
636  */
637 gboolean
638 hildon_set_password_dialog_get_protected(HildonSetPasswordDialog * dialog)
639 {
640     HildonSetPasswordDialogPrivate *priv;
641
642     g_return_val_if_fail(HILDON_IS_SET_PASSWORD_DIALOG(dialog), FALSE);
643
644     priv = HILDON_SET_PASSWORD_DIALOG_GET_PRIVATE(dialog);
645
646     return priv->protection;
647 }
648
649 /**
650  * hildon_set_password_dialog_set_domain(GtkWidget *dialog, 
651  * @dialog: the dialog
652  * @domain: the domain or some other descriptive text to be set
653  * 
654  * Sets the optional descriptive text.
655  */
656
657 void hildon_set_password_dialog_set_domain(HildonSetPasswordDialog *dialog, 
658                                            const gchar *domain)
659 {
660   HildonSetPasswordDialogPrivate *priv = NULL;
661
662   g_return_if_fail(HILDON_IS_SET_PASSWORD_DIALOG(dialog));
663
664   priv = HILDON_SET_PASSWORD_DIALOG_GET_PRIVATE(dialog);
665   gtk_label_set_text(priv->domainLabel, domain);  
666 }