Adding an example test program to check icon-lookup functionality. Doc updates.
[hildon] / src / hildon-set-password-dialog.c
1 /*
2  * This file is a part of hildon
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 #include                                        "hildon-set-password-dialog.h"
47 #include                                        <gdk/gdkkeysyms.h>
48 #include                                        <gtk/gtk.h>
49 #include                                        <glib.h>
50 #include                                        <errno.h>
51 #include                                        <string.h>
52 #include                                        <strings.h>
53 #include                                        <unistd.h>
54 #include                                        <stdio.h>
55 #include                                        "hildon-caption.h"
56 #include                                        "hildon-note.h"
57 #include                                        "hildon-defines.h"
58 #include                                        "hildon-banner.h"
59 #include                                        <libintl.h>
60 #include                                        "hildon-set-password-dialog-private.h"
61
62 #define                                         HILDON_SET_PASSWORD_DIALOG_TITLE "ecdg_ti_set_password"
63
64 #define                                         HILDON_SET_PASSWORD_DIALOG_PASSWORD "ecdg_fi_set_passwd_enter_pwd"
65
66 #define                                         HILDON_SET_PASSWORD_DIALOG_VERIFY_PASSWORD "ecdg_fi_set_passwd_confirm"
67
68 #define                                         HILDON_SET_PASSWORD_DIALOG_OK "ecdg_bd_set_password_dialog_ok"
69
70 #define                                         HILDON_SET_PASSWORD_DIALOG_CANCEL "ecdg_bd_set_password_dialog_cancel"
71
72 #define                                         HILDON_SET_MODIFY_PASSWORD_DIALOG_TITLE "ckdg_ti_dialog_c_passwd_change_password"
73
74 #define                                         HILDON_SET_MODIFY_PASSWORD_DIALOG_LABEL "ckdg_fi_dialog_c_passwd_pwd_protect"
75
76 #define                                         HILDON_SET_MODIFY_PASSWORD_DIALOG_PASSWORD "ckdg_fi_dialog_c_passwd_new_pwd"
77
78 #define                                         HILDON_SET_MODIFY_PASSWORD_DIALOG_VERIFY_PASSWORD "ckdg_fi_dialog_c_passwd_ver_pwd"
79
80 #define                                         HILDON_SET_MODIFY_PASSWORD_DIALOG_OK "ckdg_bd_change_password_dialog_ok"
81
82 #define                                         HILDON_SET_MODIFY_PASSWORD_DIALOG_CANCEL "ckdg_bd_change_password_dialog_cancel"
83
84 #define                                         HILDON_SET_PASSWORD_DIALOG_MISMATCH "ecdg_ib_passwords_do_not_match"
85
86 #define                                         HILDON_SET_PASSWORD_DIALOG_EMPTY "ecdg_ib_password_is_empty"
87
88 #define                                         HILDON_SET_PASSWORD_DIALOG_REMOVE_PROTECTION "ckdg_nc_dialog_c_passwd_remove_pwd"
89
90 #define                                         HILDON_REMOVE_PROTECTION_CONFIRMATION_REMOVE "ckdg_bd_dialog_c_passwd_remove_button"
91
92 #define                                         HILDON_REMOVE_PROTECTION_CONFIRMATION_CANCEL "ckdg_bd_dialog_c_passwd_cancel_button"
93
94 #define                                         _(String) dgettext("hildon-libs", String)
95
96 #define                                         c_(String) dgettext("hildon-common-strings", String)
97
98 static GtkDialogClass*                          parent_class;
99
100 static void
101 hildon_set_password_dialog_class_init           (HildonSetPasswordDialogClass *class);
102
103 static void 
104 hildon_set_password_dialog_init                 (HildonSetPasswordDialog *dialog);
105
106 static void 
107 hildon_checkbox_toggled                         (GtkWidget *widget, 
108                                                  gpointer dialog);
109
110 static void
111 hildon_set_password_response_change             (GtkDialog *d,
112                                                  gint arg1, 
113                                                  gpointer unused);
114
115 static void
116 hildon_set_password_response_set                (GtkDialog * d, 
117                                                  gint arg1, 
118                                                  gpointer unused);
119
120 static void 
121 create_contents                                 (HildonSetPasswordDialog *dialog);
122
123 static void
124 hildon_set_password_set_property                (GObject *object,
125                                                  guint prop_id,
126                                                  const GValue *value,
127                                                  GParamSpec *pspec);
128
129 static void
130 hildon_set_password_get_property                (GObject *object,
131                                                  guint prop_id, 
132                                                  GValue *value,
133                                                  GParamSpec *pspec);
134
135 enum 
136 {
137     PROP_0,
138     PROP_MESSAGE,
139     PROP_PASSWORD,
140     PROP_HILDON_PASSWORD_DIALOG
141 };
142
143 static void
144 hildon_set_password_set_property                (GObject *object,
145                                                  guint prop_id,
146                                                  const GValue *value, 
147                                                  GParamSpec *pspec)
148 {
149     HildonSetPasswordDialog *dialog = HILDON_SET_PASSWORD_DIALOG (object);
150     HildonSetPasswordDialogPrivate *priv;
151
152     priv = HILDON_SET_PASSWORD_DIALOG_GET_PRIVATE (dialog);
153     g_assert (priv);
154
155     switch (prop_id) {
156
157         case PROP_MESSAGE:
158             /* Update domain label to display new value */
159             gtk_label_set_text (priv->message_label, g_value_get_string (value));
160             break;
161
162         case PROP_PASSWORD:
163             /* Update password entry to display new value */
164             gtk_entry_set_text (GTK_ENTRY (priv->pwd1st_entry), g_value_get_string (value));
165             break;
166
167         case PROP_HILDON_PASSWORD_DIALOG:
168             /* Note this is a G_PARAM_CONSTRUCT_ONLY type property */
169             priv->protection = g_value_get_boolean (value);
170
171             /* We now have the necessary information to populate the dialog */
172             /* FIXME It looks kinda extremally bad that this is here... 
173              * what about situations where this prop is NOT set during 
174              * constructing? */
175             create_contents (dialog);
176             break;
177
178         default:
179             G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
180             break;
181     }
182 }
183
184 static void
185 hildon_set_password_get_property                (GObject *object,
186                                                  guint prop_id,
187                                                  GValue *value,
188                                                  GParamSpec *pspec)
189 {
190     HildonSetPasswordDialogPrivate *priv = NULL;
191
192     priv = HILDON_SET_PASSWORD_DIALOG_GET_PRIVATE (object);
193     g_assert (priv);
194
195     switch (prop_id) {
196
197         case PROP_MESSAGE:
198             g_value_set_string (value, gtk_label_get_text (priv->message_label));
199             break;
200
201         case PROP_PASSWORD:
202             g_value_set_string (value,
203                     gtk_entry_get_text (GTK_ENTRY (priv->pwd1st_entry)));
204             break;
205
206         case PROP_HILDON_PASSWORD_DIALOG:
207             g_value_set_boolean (value, priv->protection);
208             break;
209
210         default:
211             G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
212             break;
213     }
214 }
215
216
217 static void
218 create_contents                                 (HildonSetPasswordDialog *dialog)
219 {
220     HildonSetPasswordDialogPrivate *priv = NULL;
221
222     GtkSizeGroup *group;
223
224     priv = HILDON_SET_PASSWORD_DIALOG_GET_PRIVATE (dialog);
225     g_assert (priv);
226     priv->checkbox = NULL;
227
228     /* Size group for labels */
229     group = GTK_SIZE_GROUP (gtk_size_group_new (GTK_SIZE_GROUP_HORIZONTAL));
230
231     gtk_dialog_set_has_separator (GTK_DIALOG (dialog), FALSE);
232
233     /* Setup and pack domain label */
234     priv->message_label = GTK_LABEL (gtk_label_new (NULL));
235     gtk_box_pack_start (GTK_BOX (GTK_DIALOG (dialog)->vbox),
236             GTK_WIDGET(priv->message_label), FALSE, FALSE, 0);
237     gtk_widget_show (GTK_WIDGET (priv->message_label));
238
239     if (priv->protection == TRUE) {
240         /* Use Change Password Dialog strings */
241         priv->pwd1st_caption_string = _(HILDON_SET_MODIFY_PASSWORD_DIALOG_PASSWORD);
242         priv->pwd2nd_caption_string = _(HILDON_SET_MODIFY_PASSWORD_DIALOG_VERIFY_PASSWORD);
243
244         /* Setup checkbox to enable/disable password protection */
245         priv->checkbox = gtk_check_button_new ();
246         gtk_widget_show (priv->checkbox);
247         priv->checkbox_caption = hildon_caption_new
248             (group,
249              _(HILDON_SET_MODIFY_PASSWORD_DIALOG_LABEL),
250              priv->checkbox,
251              NULL, HILDON_CAPTION_OPTIONAL);
252         hildon_caption_set_separator (HILDON_CAPTION (priv->checkbox_caption), "");
253         gtk_box_pack_start (GTK_BOX (GTK_DIALOG (dialog)->vbox),
254                 priv->checkbox_caption, TRUE, TRUE, 0);
255         gtk_widget_show (priv->checkbox_caption);
256         gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (priv->checkbox),
257                 TRUE);
258         gtk_signal_connect (GTK_OBJECT (priv->checkbox), "toggled",
259                 G_CALLBACK (hildon_checkbox_toggled), dialog);
260
261         /* Setup appropriate response handler */
262         g_signal_connect (G_OBJECT (dialog), "response",
263                 G_CALLBACK (hildon_set_password_response_change),
264                 NULL);
265     } else {
266         /* Use Set Password Dialog strings */
267         priv->pwd1st_caption_string = _(HILDON_SET_PASSWORD_DIALOG_PASSWORD);
268         priv->pwd2nd_caption_string = _(HILDON_SET_PASSWORD_DIALOG_VERIFY_PASSWORD);
269
270         /* Setup appropriate response handler */
271         g_signal_connect (G_OBJECT (dialog), "response",
272                 G_CALLBACK(hildon_set_password_response_set),
273                 NULL);
274     }
275
276     /* Create the password field */
277     priv->pwd1st_entry = gtk_entry_new ();
278     g_object_set (priv->pwd1st_entry, "hildon-input-mode", HILDON_GTK_INPUT_MODE_FULL, NULL);
279     gtk_entry_set_visibility (GTK_ENTRY(priv->pwd1st_entry), FALSE);
280     gtk_widget_show (priv->pwd1st_entry);
281     priv->pwd1st_caption = hildon_caption_new (group,
282             priv->pwd1st_caption_string,
283             priv->pwd1st_entry,
284             NULL, HILDON_CAPTION_OPTIONAL);
285
286     hildon_caption_set_separator (HILDON_CAPTION(priv->pwd1st_caption), "");
287     gtk_entry_set_visibility (GTK_ENTRY (priv->pwd1st_entry), FALSE);
288     gtk_box_pack_start (GTK_BOX(GTK_DIALOG (dialog)->vbox),
289             priv->pwd1st_caption, TRUE, TRUE, 0);
290     gtk_widget_show (priv->pwd1st_caption);
291
292     /* Create the password verify field */
293     priv->pwd2nd_entry = gtk_entry_new();
294     g_object_set (priv->pwd2nd_entry, "hildon-input-mode", HILDON_GTK_INPUT_MODE_FULL, NULL);
295     gtk_widget_show (priv->pwd2nd_entry);
296     priv->pwd2nd_caption = hildon_caption_new (group,
297             priv->pwd2nd_caption_string,
298             priv->pwd2nd_entry,
299             NULL, HILDON_CAPTION_OPTIONAL);
300     hildon_caption_set_separator (HILDON_CAPTION (priv->pwd2nd_caption), "");
301     gtk_entry_set_visibility (GTK_ENTRY (priv->pwd2nd_entry), FALSE);
302     gtk_box_pack_start (GTK_BOX(GTK_DIALOG (dialog)->vbox),
303             priv->pwd2nd_caption, TRUE, TRUE, 0);
304     gtk_widget_show (priv->pwd2nd_caption);
305
306     /* Set dialog title */
307     gtk_window_set_title (GTK_WINDOW (dialog),
308             _(priv->protection
309                 ? HILDON_SET_MODIFY_PASSWORD_DIALOG_TITLE
310                 : HILDON_SET_PASSWORD_DIALOG_TITLE));
311
312     /* Create the OK/CANCEL buttons */
313     gtk_dialog_add_button (GTK_DIALOG (dialog),  _(priv->protection
314                                 ? HILDON_SET_MODIFY_PASSWORD_DIALOG_OK
315                                 : HILDON_SET_PASSWORD_DIALOG_OK), GTK_RESPONSE_OK);
316
317     gtk_dialog_add_button (GTK_DIALOG (dialog), _(priv->protection
318                                ? HILDON_SET_MODIFY_PASSWORD_DIALOG_CANCEL
319                                : HILDON_SET_PASSWORD_DIALOG_CANCEL), GTK_RESPONSE_CANCEL);
320
321     gtk_widget_show_all (GTK_DIALOG (dialog)->vbox);
322     gtk_widget_show_all (GTK_DIALOG (dialog)->action_area);
323  
324     /* Ensure group is freed when all its contents have been removed */
325     g_object_unref (group);
326 }
327
328 static void
329 hildon_set_password_dialog_class_init           (HildonSetPasswordDialogClass *class)
330 {
331     GObjectClass *object_class = G_OBJECT_CLASS (class);
332
333     parent_class = g_type_class_peek_parent (class);
334
335     /* Override virtual methods */
336     object_class->set_property = hildon_set_password_set_property;
337     object_class->get_property = hildon_set_password_get_property;
338
339     /* Install new properties */
340     g_object_class_install_property (object_class, 
341             PROP_MESSAGE, 
342             g_param_spec_string ("message",
343                 "Message",
344                 "A message to display to the user",
345                 NULL,
346                 G_PARAM_READWRITE));
347
348     /**
349      * HildonSetPasswordDialog:modify-protection:
350      *
351      * Password type.
352      */
353     g_object_class_install_property (object_class, 
354             PROP_HILDON_PASSWORD_DIALOG, 
355             g_param_spec_boolean ("modify-protection",
356                 "Password type",
357                 "Set type to dialog",
358                 TRUE, 
359                 G_PARAM_CONSTRUCT_ONLY |
360                 G_PARAM_READWRITE));
361
362     /**
363      * HildonSetPasswordDialog:password:
364      *
365      * Content of the password field.
366      */
367     g_object_class_install_property (object_class, 
368             PROP_PASSWORD, 
369             g_param_spec_string ("password",
370                 "Password content",
371                 "Set content to dialog",
372                 "DEFAULT",
373                 G_PARAM_READWRITE));
374
375     /* Install private structure */
376     g_type_class_add_private (class,
377             sizeof (HildonSetPasswordDialogPrivate));
378 }
379
380 static void
381 hildon_set_password_dialog_init                 (HildonSetPasswordDialog *dialog)
382 {
383     /* Most of the initializations are done in create_contents()
384        after the 'modify_protection' property has been set */
385
386     gtk_window_set_modal (GTK_WINDOW (dialog), TRUE);
387 }
388
389
390 /* We come here when response button is clicked and dialog 
391    is used to change existing password. */
392 static void
393 hildon_set_password_response_change             (GtkDialog *dialog, 
394                                                  gint arg1,
395                                                  gpointer unused)
396 {
397     GtkEntry *pwd1st_entry;
398     GtkEntry *pwd2nd_entry;
399     gchar *text1;
400     gchar *text2;
401     HildonNote *note;
402     gint i;
403     HildonSetPasswordDialogPrivate *priv;
404
405     priv = HILDON_SET_PASSWORD_DIALOG_GET_PRIVATE (dialog);
406     g_assert (priv);
407
408     /* Password and verification */
409     pwd1st_entry = GTK_ENTRY (gtk_bin_get_child
410             (GTK_BIN (priv->pwd1st_caption)));
411     pwd2nd_entry = GTK_ENTRY (gtk_bin_get_child
412             (GTK_BIN (priv->pwd2nd_caption)));
413     text1 = GTK_ENTRY (pwd1st_entry)->text;
414     text2 = GTK_ENTRY (pwd2nd_entry)->text;
415
416     /* User accepted the dialog */
417     if (arg1 == GTK_RESPONSE_OK) {
418         /* Is the checkbox marked, so password protection is still in use? */  
419         if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (priv->checkbox))){
420             /* Yes, Something is given as password as well? */
421             if (text1[0] != '\0') {
422                 if (strcmp (text1, text2) == 0) {
423                     /* Passwords match, so accept change password */
424                     priv->protection = TRUE;
425
426                 } else if (text2[0] == '\0') {
427                     /* Second field is empty, so show error, but don't clear fields */
428                     g_signal_stop_emission_by_name (G_OBJECT(dialog),
429                             "response");
430
431                     hildon_banner_show_information (GTK_WIDGET (dialog), NULL,
432                             c_(HILDON_SET_PASSWORD_DIALOG_MISMATCH));
433
434                     gtk_widget_grab_focus (GTK_WIDGET (pwd2nd_entry));
435
436                 } else {
437                     /* Error: Passwords don't match, so start over */
438                     g_signal_stop_emission_by_name (G_OBJECT(dialog),
439                             "response");
440
441                     gtk_entry_set_text (pwd1st_entry, "");
442                     gtk_entry_set_text (pwd2nd_entry, "");
443
444                     hildon_banner_show_information (GTK_WIDGET (dialog), NULL,
445                             c_(HILDON_SET_PASSWORD_DIALOG_MISMATCH));
446
447                     gtk_widget_grab_focus (GTK_WIDGET (pwd1st_entry));
448                 }
449             } else {
450                 /* No, the password is empty */
451                 g_signal_stop_emission_by_name (G_OBJECT (dialog), "response");
452
453                 if (text2[0] == '\0') {
454                     /* Error: Both fields are empty */
455                     hildon_banner_show_information (GTK_WIDGET (dialog), NULL, c_(HILDON_SET_PASSWORD_DIALOG_EMPTY));
456                 } else {
457                     /* Error: Second field doesn't match
458                        the empty first field, so start over */
459                     hildon_banner_show_information (GTK_WIDGET (dialog), NULL, c_(HILDON_SET_PASSWORD_DIALOG_MISMATCH));
460                     gtk_entry_set_text(pwd2nd_entry, "");
461                 }
462
463                 gtk_widget_grab_focus (GTK_WIDGET (pwd1st_entry));
464             }
465         } else {
466             /* No, user wants to remove password protection. 
467                Confirm remove password protection */
468             note = HILDON_NOTE (hildon_note_new_confirmation
469                     (GTK_WINDOW (dialog),
470                      c_(HILDON_SET_PASSWORD_DIALOG_REMOVE_PROTECTION)));
471
472             hildon_note_set_button_texts
473                 (HILDON_NOTE (note),
474                  c_(HILDON_REMOVE_PROTECTION_CONFIRMATION_REMOVE), 
475                  c_(HILDON_REMOVE_PROTECTION_CONFIRMATION_CANCEL));
476
477             /* Display confirmation note */
478             i = gtk_dialog_run (GTK_DIALOG (note));
479
480             gtk_widget_destroy (GTK_WIDGET (note));
481
482             if (i == GTK_RESPONSE_OK)
483                 /* Remove password protection */
484                 priv->protection = FALSE;
485             else {
486                 /* Remove password protection cancelled */
487                 priv->protection = TRUE;
488                 g_signal_stop_emission_by_name (G_OBJECT(dialog), "response");
489             }
490         }
491
492     } else {
493         /* Watch out for fading boolean values */
494         priv->protection = TRUE;
495     }
496 }
497
498 /* We come here when response button is clicked and dialog 
499    is used to set new password. */
500 static void
501 hildon_set_password_response_set                (GtkDialog *dialog, 
502                                                  gint arg1,
503                                                  gpointer unused)
504 {
505     GtkEntry *pwd1st_entry;
506     GtkEntry *pwd2nd_entry;
507     gchar *text1;
508     gchar *text2;
509
510     HildonSetPasswordDialogPrivate *priv;
511
512     priv = HILDON_SET_PASSWORD_DIALOG_GET_PRIVATE (dialog);
513     g_assert (priv);
514
515     /* Password and confirmation */
516     pwd1st_entry = GTK_ENTRY (gtk_bin_get_child
517             (GTK_BIN (priv->pwd1st_caption)));
518
519     pwd2nd_entry = GTK_ENTRY (gtk_bin_get_child
520             (GTK_BIN (priv->pwd2nd_caption)));
521
522     text1 = GTK_ENTRY (pwd1st_entry)->text;
523     text2 = GTK_ENTRY (pwd2nd_entry)->text;
524
525     if (arg1 == GTK_RESPONSE_OK) {
526         /* User provided something for password? */
527         if (text1[0] != '\0') {
528             if (strcmp (text1, text2) == 0) {
529                 /* Passwords match, so accept set password */
530                 priv->protection = TRUE;
531
532             } else if (text2[0] == '\0') {
533                 /* Second field is empty, so show error,
534                    but don't clear the fields */
535                 g_signal_stop_emission_by_name (G_OBJECT(dialog), "response");
536                 hildon_banner_show_information (GTK_WIDGET (dialog), NULL, c_(HILDON_SET_PASSWORD_DIALOG_MISMATCH));
537
538                 gtk_widget_grab_focus (GTK_WIDGET (priv->pwd2nd_entry));
539
540             } else {
541                 /* Error: Passwords don't match, so start over */
542                 g_signal_stop_emission_by_name (G_OBJECT(dialog), "response");
543                 gtk_entry_set_text (pwd1st_entry, "");
544                 gtk_entry_set_text (pwd2nd_entry, "");
545                 hildon_banner_show_information (GTK_WIDGET (dialog), NULL, c_(HILDON_SET_PASSWORD_DIALOG_MISMATCH));
546
547                 gtk_widget_grab_focus (GTK_WIDGET (priv->pwd1st_entry));
548             }
549         } else {
550             /* First field is empty */
551             g_signal_stop_emission_by_name (G_OBJECT (dialog), "response");
552             if (text2[0] == '\0') {
553                 /* Error: Both fields are empty */
554                 hildon_banner_show_information (GTK_WIDGET (dialog), NULL, c_(HILDON_SET_PASSWORD_DIALOG_EMPTY));
555             } else {
556                 /* Error: Second field doesn't match
557                    the empty first field, so start over */
558                 hildon_banner_show_information (GTK_WIDGET (dialog), NULL, c_(HILDON_SET_PASSWORD_DIALOG_MISMATCH));
559                 gtk_entry_set_text (pwd2nd_entry, "");
560             }
561
562             gtk_widget_grab_focus (GTK_WIDGET (pwd1st_entry));
563         }
564     } else { 
565         /* Watch out for fading boolean values */
566         priv->protection = FALSE;
567     }         
568 }
569
570 static void
571 hildon_checkbox_toggled                         (GtkWidget *widget, 
572                                                  gpointer dialog)
573 {
574     HildonSetPasswordDialogPrivate *priv = HILDON_SET_PASSWORD_DIALOG_GET_PRIVATE (dialog);
575     gboolean active;
576
577     g_assert (priv);
578
579     /* If the user enabled/disabled the password protection feature
580        we enable/disable password entries accordingly */
581     active = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (widget));
582     gtk_widget_set_sensitive (GTK_WIDGET (priv->pwd1st_entry), active);
583     gtk_widget_set_sensitive (GTK_WIDGET (priv->pwd2nd_entry), active);
584 }
585
586 /**
587  * hildon_set_password_dialog_get_type:
588  *
589  * Returns GType for HildonPasswordDialog as produced by
590  * g_type_register_static().
591  *
592  * Returns: HildonSetPasswordDialog type
593  */
594 GType G_GNUC_CONST
595 hildon_set_password_dialog_get_type             (void)
596 {
597     static GType dialog_type = 0;
598
599     if (! dialog_type) {
600         static const GTypeInfo dialog_info = {
601             sizeof (HildonSetPasswordDialogClass),
602             NULL,       /* base_init */
603             NULL,       /* base_finalize */
604             (GClassInitFunc) hildon_set_password_dialog_class_init,
605             NULL,       /* class_finalize */
606             NULL,       /* class_data */
607             sizeof (HildonSetPasswordDialog),
608             0,  /* n_preallocs */
609             (GInstanceInitFunc) hildon_set_password_dialog_init
610         };
611
612         dialog_type = g_type_register_static (GTK_TYPE_DIALOG,
613                 "HildonSetPasswordDialog",
614                 &dialog_info, 0);
615     }
616
617     return dialog_type;
618 }
619
620 /**
621  * hildon_set_password_dialog_new:
622  * @parent: parent window; can be NULL
623  * @modify_protection: TRUE creates a new change password dialog and FALSE
624  *                     creates a new set password dialog 
625  * 
626  * Constructs a new HildonSetPasswordDialog.
627  *
628  * Returns: a new #GtkWidget of type HildonSetPasswordDialog
629  */
630 GtkWidget*
631 hildon_set_password_dialog_new                  (GtkWindow *parent,
632                                                  gboolean modify_protection)
633 {
634     return hildon_set_password_dialog_new_with_default (parent, "", modify_protection);
635 }
636
637 /**
638  * hildon_set_password_dialog_new_with_default:
639  * @parent: parent window; can be NULL
640  * @password: a default password to be shown in password field
641  * @modify_protection: TRUE creates a new change password dialog and FALSE
642  *                     creates a new set password dialog 
643  * 
644  * Same as #hildon_set_password_dialog_new, but with a default password
645  * in password field.
646  *
647  * Returns: a new #GtkWidget of type HildonSetPasswordDialog
648  */
649
650 GtkWidget*
651 hildon_set_password_dialog_new_with_default     (GtkWindow *parent,
652                                                  const gchar *password,
653                                                  gboolean modify_protection)
654 {
655     GtkWidget *dialog = g_object_new (HILDON_TYPE_SET_PASSWORD_DIALOG,
656             "modify_protection", modify_protection,
657             "password", password, NULL);
658
659     if (parent != NULL) {
660         gtk_window_set_transient_for (GTK_WINDOW (dialog), parent);
661     }
662
663     return dialog;
664 }
665
666 /**
667  * hildon_set_password_dialog_get_password:
668  * @dialog: pointer to HildonSetPasswordDialog
669  * 
670  * Returns current password.
671  *
672  * Returns: changed password ( if the dialog is successfully 
673  * accepted with 'OK' ( and when the check box is 'ON' ( in Change Password
674  * Dialog ))
675  */
676 const gchar*
677 hildon_set_password_dialog_get_password         (HildonSetPasswordDialog *dialog)
678 {
679     HildonSetPasswordDialogPrivate *priv;
680
681     g_return_val_if_fail (HILDON_IS_SET_PASSWORD_DIALOG (dialog), NULL);
682
683     priv = HILDON_SET_PASSWORD_DIALOG_GET_PRIVATE (dialog);
684     g_assert (priv);
685
686     return GTK_ENTRY (priv->pwd1st_entry)->text;
687 }
688
689 /**
690  * hildon_set_password_dialog_get_protected:
691  * @dialog: pointer to HildonSetPasswordDialog
692  * 
693  * Returns the protection mode.
694  *
695  * Returns: password protection mode ( TRUE when the protection is
696  *               'ON' and FALSE when the protection is 'OFF' )
697  */
698 gboolean
699 hildon_set_password_dialog_get_protected        (HildonSetPasswordDialog *dialog)
700 {
701     HildonSetPasswordDialogPrivate *priv;
702
703     g_return_val_if_fail (HILDON_IS_SET_PASSWORD_DIALOG (dialog), FALSE);
704
705     priv = HILDON_SET_PASSWORD_DIALOG_GET_PRIVATE (dialog);
706     g_assert (priv);
707
708     return priv->protection;
709 }
710
711 /**
712  * hildon_set_password_dialog_set_message:
713  * @dialog: the dialog
714  * @message: the message or some other descriptive text to be set
715  * 
716  * Sets the optional descriptive text.
717  */
718 void 
719 hildon_set_password_dialog_set_message          (HildonSetPasswordDialog *dialog, 
720                                                  const gchar *message)
721 {
722     HildonSetPasswordDialogPrivate *priv = NULL;
723
724     g_return_if_fail (HILDON_IS_SET_PASSWORD_DIALOG (dialog));
725
726     priv = HILDON_SET_PASSWORD_DIALOG_GET_PRIVATE (dialog);
727     g_assert (priv);
728
729     gtk_label_set_text (priv->message_label, message);  
730 }