Fixing the way logical colors/fonts are being applied + adding a test case. Fixes...
[hildon] / src / hildon-code-dialog.c
1 /*
2  * This file is a part of hildon
3  *
4  * Copyright (C) 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, or (at your option) any later version.
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-code-dialog
27  * @short_description: A keypad-like widget used to enter pincodes.
28  *
29  * #HildonCodeDialog displays a keypad that can be used to enter 
30  * numerical pin codes or lock codes. It emits a 'input' signal each time 
31  * an input action is performed on the dialog.
32  *
33  */
34
35 /* FIXME We need property access in this widget */
36
37 #ifdef                                          HAVE_CONFIG_H
38 #include                                        <config.h>
39 #endif
40
41 #include                                        "hildon-code-dialog.h"
42 #include                                        "hildon-defines.h"
43 #include                                        "hildon-banner.h"
44
45 #include                                        <gdk/gdkkeysyms.h>
46 #include                                        <gtk/gtkbutton.h>
47 #include                                        <gtk/gtkentry.h>
48 #include                                        <gtk/gtkicontheme.h>
49 #include                                        <gtk/gtktable.h>
50 #include                                        <gtk/gtkvbox.h>
51 #include                                        <gtk/gtkbbox.h>
52 #include                                        <gtk/gtklabel.h>
53 #include                                        <gtk/gtkalignment.h>
54 #include                                        <libintl.h>
55 #include                                        "hildon-code-dialog-private.h"
56
57 #define                                         HEIGHT (48-HILDON_MARGIN_DEFAULT)
58
59 #define                                         WIDTH  (100-HILDON_MARGIN_DEFAULT)
60
61 #define                                         BACKSPACE_ICON "qgn_calculator_backspace"
62
63 #define                                         _(String) \
64                                                 dgettext("hildon-libs", String)
65
66 #define                                         c_(String) \
67                                                 dgettext("hildon-common-strings", String)
68
69 #define                                         DEVICELOCK_OK _("secu_enter_lock_code_dialog_ok")
70
71 #define                                         DEVICELOCK_CANCEL _("secu_enter_lock_code_dialog_cancel")
72
73 #define                                         DEVICELOCK_TITLE _("secu_application_title")
74
75 #define                                         DEVICELOCK_MAX_CHAR_REACHED c_("ckdg_ib_maximum_characters_reached")
76         
77 #define                                         MAX_PINCODE_LEN (10)
78
79 static void 
80 hildon_code_dialog_class_init                   (HildonCodeDialogClass *cd_class);
81
82 static void 
83 hildon_code_dialog_init                         (HildonCodeDialog *self);
84
85 static void
86 hildon_code_dialog_realize                      (GtkWidget *widget);
87
88 static void
89 hildon_code_dialog_unrealize                    (GtkWidget *widget);
90
91 static void
92 hildon_code_dialog_finalize                     (GObject *object);
93
94 static void 
95 hildon_code_dialog_button_clicked               (GtkButton *buttonm,
96                                                  gpointer user_data);
97
98 static void
99 hildon_code_dialog_backspace                    (HildonCodeDialog *dialog);
100
101 static void
102 hildon_code_dialog_im_commit                    (GtkIMContext *im_context,
103                                                  gchar *utf8,
104                                                  gpointer user_data);
105
106 static void 
107 hildon_code_dialog_insert_text                  (GtkEditable *editable,
108                                                  gchar *new_text,
109                                                  gint new_text_length,
110                                                  gint *position,
111                                                  gpointer user_data);
112
113 static gboolean 
114 hildon_code_dialog_key_press_event              (GtkWidget *widget,
115                                                  GdkEventKey *event,
116                                                  gpointer user_data);
117
118 static void 
119 hildon_code_dialog_real_input                   (HildonCodeDialog *dialog);
120
121 static void
122 hildon_code_dialog_input                        (HildonCodeDialog *dialog);
123
124 static GtkDialogClass*                          parent_class = NULL;
125
126 static guint                                    input_signal;
127
128 /**
129  * hildon_code_dialog_get_type:
130  *
131  * Initializes and returns the type of a hildon code dialog.
132  *
133  * @Returns: GType of #HildonCodeDialog
134  */
135 GType G_GNUC_CONST
136 hildon_code_dialog_get_type                     (void)
137 {
138     static GType type = 0;
139
140     if (!type)
141     {
142         static const GTypeInfo info = 
143         {
144             sizeof (HildonCodeDialogClass),
145             NULL, /* base_init */
146             NULL, /* base_finalize */
147             (GClassInitFunc) hildon_code_dialog_class_init,
148             NULL,       /* class_finalize */
149             NULL,       /* class_data */
150             sizeof (HildonCodeDialog),
151             0,  /* n_preallocs */
152             (GInstanceInitFunc) hildon_code_dialog_init
153         };
154         type = g_type_register_static (GTK_TYPE_DIALOG,
155                 "HildonCodeDialog", &info, 0);
156     }
157     return type;
158 }
159
160 static void
161 hildon_code_dialog_class_init                   (HildonCodeDialogClass *cd_class)
162 {
163     GObjectClass *gobject_class = G_OBJECT_CLASS (cd_class);
164     GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (cd_class);
165
166     parent_class = GTK_DIALOG_CLASS (g_type_class_peek_parent (cd_class));
167     g_type_class_add_private (cd_class, sizeof (HildonCodeDialogPrivate));
168
169     gobject_class->finalize = hildon_code_dialog_finalize;
170
171     widget_class->realize = hildon_code_dialog_realize;
172     widget_class->unrealize = hildon_code_dialog_unrealize;
173
174     cd_class->input = hildon_code_dialog_real_input;
175
176     /* FIXME Document this signal! */
177     input_signal = g_signal_new("input",
178                                 HILDON_TYPE_CODE_DIALOG,
179                                 G_SIGNAL_RUN_LAST,
180                                 G_STRUCT_OFFSET (HildonCodeDialogClass, input),
181                                 NULL, NULL,
182                                 g_cclosure_marshal_VOID__VOID,
183                                 G_TYPE_NONE,
184                                 0);
185 }
186
187 static void 
188 hildon_code_dialog_init                         (HildonCodeDialog *dialog)
189 {
190     HildonCodeDialogPrivate *priv;
191     gint i, x, y;
192     GtkWidget *dialog_vbox1 = NULL;
193     GtkWidget *table = NULL;
194     GtkWidget *alignment = NULL;
195     GtkWidget *vbox1 = NULL;
196     GtkWidget *image1 = NULL;
197     GtkWidget *dialog_action_area1 = NULL;
198     GdkGeometry hints;
199     GtkWidget *okButton;
200     GtkWidget *cancelButton;
201
202     priv = HILDON_CODE_DIALOG_GET_PRIVATE (dialog);
203     g_assert (priv);
204     
205     const gchar* numstrs[10] = {
206         "0","1","2","3","4","5","6","7","8","9"
207     };
208
209     GdkPixbuf* pixbuf = NULL;
210     GtkIconTheme* icon_theme = NULL;
211     GtkIconInfo *icon_info = NULL;
212     gint base_size = 0;
213
214     /* Set default title */
215     gtk_window_set_title (GTK_WINDOW (dialog), DEVICELOCK_TITLE);
216
217     gtk_window_set_type_hint (GTK_WINDOW (dialog), GDK_WINDOW_TYPE_HINT_DIALOG);
218     gtk_dialog_set_has_separator ((GtkDialog *) dialog, FALSE);
219
220     hints.min_width  = -1;
221     hints.min_height = -1;
222     hints.max_width  = -1;
223     hints.max_height = -1;
224
225     gtk_window_set_geometry_hints (GTK_WINDOW (dialog), GTK_WIDGET (dialog), &hints,
226             GDK_HINT_MIN_SIZE | GDK_HINT_MAX_SIZE);
227
228     table = gtk_table_new (4, 3, FALSE);
229     gtk_table_set_row_spacings (GTK_TABLE (table), HILDON_MARGIN_DEFAULT );
230     gtk_table_set_col_spacings (GTK_TABLE (table), HILDON_MARGIN_DEFAULT );
231
232     dialog_vbox1 = GTK_DIALOG (dialog)->vbox;
233     vbox1 = gtk_vbox_new (FALSE, 0);
234     gtk_box_set_spacing (GTK_BOX (vbox1), HILDON_MARGIN_DOUBLE);
235
236     priv->help_text = gtk_label_new ("");
237     alignment = gtk_alignment_new (0.5,0,1,1);
238     gtk_container_add (GTK_CONTAINER (alignment), priv->help_text);
239
240     priv->entry = gtk_entry_new ();
241     
242     GTK_WIDGET_UNSET_FLAGS (GTK_WIDGET (priv->entry), GTK_CAN_FOCUS);
243     gtk_entry_set_invisible_char (GTK_ENTRY (priv->entry), g_utf8_get_char ("*"));
244     gtk_entry_set_alignment (GTK_ENTRY (priv->entry), 1.0);
245
246     gtk_editable_set_editable (GTK_EDITABLE (priv->entry),FALSE);
247     gtk_entry_set_visibility (GTK_ENTRY (priv->entry), FALSE);
248
249     gtk_box_pack_start (GTK_BOX (vbox1), alignment, TRUE,FALSE,0);
250     gtk_box_pack_start (GTK_BOX (vbox1), priv->entry, TRUE,FALSE,0);
251     gtk_box_pack_start (GTK_BOX (vbox1), table, FALSE,TRUE,0);
252
253     gtk_box_pack_start (GTK_BOX (dialog_vbox1), vbox1, FALSE,TRUE,0);
254
255     for(i = 1;i <= 3; i++) {
256         priv->buttons[0][i-1] = gtk_button_new_with_mnemonic (numstrs[i]);
257         gtk_widget_set_size_request (priv->buttons[0][i-1], WIDTH, HEIGHT);
258         gtk_table_attach_defaults (GTK_TABLE (table), priv->buttons[0][i-1],
259                 i-1, i, 0, 1);
260     }
261
262     for(i = 4;i <= 6;i++) {
263         priv->buttons[1][i-4] = gtk_button_new_with_mnemonic (numstrs[i]);
264         gtk_widget_set_size_request (priv->buttons[1][i-4], WIDTH, HEIGHT);
265         gtk_table_attach_defaults (GTK_TABLE (table), priv->buttons[1][i-4],
266                 i-4, i-3, 1, 2);
267     }
268
269     for(i=7;i<=9;i++) {
270         priv->buttons[2][i-7] = gtk_button_new_with_mnemonic (numstrs[i]);
271         gtk_widget_set_size_request (priv->buttons[2][i-7], WIDTH, HEIGHT);
272         gtk_table_attach_defaults (GTK_TABLE (table), priv->buttons[2][i-7],
273                 i-7, i-6, 2, 3);
274     }
275
276     priv->buttons[3][0] = priv->buttons[3][1] = 
277         gtk_button_new_with_mnemonic (numstrs[0]);
278     gtk_widget_set_size_request (priv->buttons[3][0], WIDTH, HEIGHT);
279     gtk_table_attach (GTK_TABLE (table), priv->buttons[3][0],
280             0,2,3,4, (GtkAttachOptions) (GTK_FILL),
281             (GtkAttachOptions) (0), 0, 0);
282
283     priv->buttons[3][2] = gtk_button_new ();
284     gtk_widget_set_size_request (priv->buttons[3][2], WIDTH, HEIGHT);
285     gtk_table_attach_defaults (GTK_TABLE (table), priv->buttons[3][2],
286             2, 3, 3, 4);
287
288     icon_theme = gtk_icon_theme_get_default ();
289
290     icon_info = gtk_icon_theme_lookup_icon (icon_theme, BACKSPACE_ICON, 1,
291             GTK_ICON_LOOKUP_NO_SVG);
292     base_size = gtk_icon_info_get_base_size (icon_info);
293     gtk_icon_info_free (icon_info);
294     icon_info = NULL;
295     pixbuf = gtk_icon_theme_load_icon (icon_theme,
296             BACKSPACE_ICON, base_size,
297             GTK_ICON_LOOKUP_NO_SVG,
298             NULL);
299
300     image1 = gtk_image_new_from_pixbuf (pixbuf);
301     g_object_unref (G_OBJECT(pixbuf));
302     gtk_container_add (GTK_CONTAINER (priv->buttons[3][2]), image1);
303     dialog_action_area1 = GTK_DIALOG (dialog)->action_area;
304     gtk_button_box_set_layout (GTK_BUTTON_BOX (dialog_action_area1),
305             GTK_BUTTONBOX_CENTER);
306
307     okButton = gtk_dialog_add_button (GTK_DIALOG (dialog) ,DEVICELOCK_OK,
308             GTK_RESPONSE_OK);
309     cancelButton =
310         gtk_dialog_add_button (GTK_DIALOG (dialog), DEVICELOCK_CANCEL,
311                 GTK_RESPONSE_CANCEL);
312     
313     gtk_widget_set_sensitive (okButton, FALSE);
314
315     priv->buttons[4][0] = priv->buttons[4][1] = okButton;
316     priv->buttons[4][2] = cancelButton;
317
318     priv->im_context = gtk_im_multicontext_new();
319 #ifdef MAEMO_GTK
320     g_object_set (G_OBJECT (priv->im_context), "hildon-input-mode",
321                   HILDON_GTK_INPUT_MODE_NUMERIC, NULL);
322 #endif
323
324     /*
325        Connect signals.
326     */
327     g_signal_connect (G_OBJECT (priv->im_context), "commit",
328                       G_CALLBACK (hildon_code_dialog_im_commit), dialog);
329
330     g_signal_connect (G_OBJECT (priv->entry), "insert_text",
331             G_CALLBACK (hildon_code_dialog_insert_text), dialog);
332     
333     gtk_entry_set_max_length (GTK_ENTRY (priv->entry), MAX_PINCODE_LEN);
334
335     for (x = 0; x < 3; x++)
336     {
337         for (y = 0; y < 3; y++)
338         {
339             g_signal_connect (G_OBJECT (priv->buttons[x][y]), "clicked",
340                 G_CALLBACK (hildon_code_dialog_button_clicked), dialog);
341             g_signal_connect (G_OBJECT (priv->buttons[x][y]), "key-press-event",
342                 G_CALLBACK (hildon_code_dialog_key_press_event), dialog);
343         }
344     }
345             
346     g_signal_connect (G_OBJECT (priv->buttons[3][0]), "clicked",
347                 G_CALLBACK (hildon_code_dialog_button_clicked), dialog);
348     g_signal_connect (G_OBJECT (priv->buttons[3][0]), "key-press-event",
349                 G_CALLBACK (hildon_code_dialog_key_press_event), dialog);
350     
351     g_signal_connect (G_OBJECT (priv->buttons[3][2]), "clicked",
352                 G_CALLBACK (hildon_code_dialog_button_clicked), dialog);
353     g_signal_connect (G_OBJECT (priv->buttons[3][2]), "key-press-event",
354                 G_CALLBACK (hildon_code_dialog_key_press_event), dialog);
355         
356     g_signal_connect (G_OBJECT (okButton), "key-press-event",
357                 G_CALLBACK(hildon_code_dialog_key_press_event), dialog);
358     
359     g_signal_connect (G_OBJECT (cancelButton), "key-press-event",
360                 G_CALLBACK (hildon_code_dialog_key_press_event), dialog);
361
362     gtk_widget_show_all (GTK_WIDGET (GTK_DIALOG (dialog)->vbox));
363 }
364
365 static void
366 hildon_code_dialog_realize                      (GtkWidget *widget)
367 {
368     HildonCodeDialog *dialog = HILDON_CODE_DIALOG (widget);
369     HildonCodeDialogPrivate *priv = HILDON_CODE_DIALOG_GET_PRIVATE (dialog);
370
371     if (GTK_WIDGET_CLASS (parent_class)->realize)
372       (* GTK_WIDGET_CLASS (parent_class)->realize) (widget);
373
374     gtk_im_context_set_client_window (GTK_IM_CONTEXT (priv->im_context),
375                                      GTK_WIDGET (dialog)->window);
376     gtk_im_context_focus_in (priv->im_context);
377 }
378
379 static void
380 hildon_code_dialog_unrealize                    (GtkWidget *widget)
381 {
382     HildonCodeDialog *dialog = HILDON_CODE_DIALOG (widget);
383     HildonCodeDialogPrivate *priv = HILDON_CODE_DIALOG_GET_PRIVATE (dialog);
384
385     gtk_im_context_set_client_window (GTK_IM_CONTEXT (priv->im_context), NULL);
386
387     if (GTK_WIDGET_CLASS (parent_class)->unrealize)
388       (* GTK_WIDGET_CLASS (parent_class)->unrealize) (widget);
389 }
390
391 static void
392 hildon_code_dialog_finalize                     (GObject *object)
393 {
394     HildonCodeDialog *dialog = HILDON_CODE_DIALOG (object);
395     HildonCodeDialogPrivate *priv = HILDON_CODE_DIALOG_GET_PRIVATE (dialog);
396
397     g_object_unref (priv->im_context);
398
399     G_OBJECT_CLASS(parent_class)->finalize(object);
400 }
401
402 static void
403 hildon_code_dialog_backspace                    (HildonCodeDialog *dialog)
404 {
405     HildonCodeDialogPrivate *priv = HILDON_CODE_DIALOG_GET_PRIVATE (dialog);
406     gchar *text, *pos;
407
408     g_assert (priv);
409
410     text = g_strdup (gtk_entry_get_text (GTK_ENTRY (priv->entry)));
411         
412     pos = text;
413
414     while (*pos != '\0')
415     {
416       pos ++;
417     }
418
419     pos = g_utf8_find_prev_char (text, pos);
420
421     if (pos)
422     {
423       *pos=0;
424     }
425
426     gtk_entry_set_text (GTK_ENTRY (priv->entry), text);
427
428     if (*text == 0)
429     {
430       gtk_widget_set_sensitive (priv->buttons[4][0], FALSE);
431     }
432
433     g_free (text);
434 }
435
436 static void 
437 hildon_code_dialog_button_clicked               (GtkButton *button, 
438                                                  gpointer user_data)
439 {
440     HildonCodeDialog *dialog = HILDON_CODE_DIALOG (user_data);
441     HildonCodeDialogPrivate *priv = HILDON_CODE_DIALOG_GET_PRIVATE (dialog);
442     g_assert (priv);
443
444     const char *number = gtk_button_get_label (button);
445
446     if (number && *number )
447     {
448         gtk_entry_append_text (GTK_ENTRY (priv->entry), number);
449     }
450     else
451     {
452         hildon_code_dialog_backspace (dialog);
453     }
454 }
455
456 static void
457 hildon_code_dialog_im_commit                    (GtkIMContext *im_context,
458                                                  gchar *utf8,
459                                                  gpointer user_data)
460 {
461     HildonCodeDialog *dialog = HILDON_CODE_DIALOG (user_data);
462     HildonCodeDialogPrivate *priv = HILDON_CODE_DIALOG_GET_PRIVATE (dialog);
463     gint digit;
464
465     g_assert (priv);
466
467     digit = g_ascii_strtod(utf8, NULL);
468
469     if (g_ascii_isdigit(*utf8))
470     {
471         gtk_entry_append_text (GTK_ENTRY (priv->entry), utf8);
472     }
473 }
474
475 static void 
476 hildon_code_dialog_insert_text                  (GtkEditable *editable,
477                                                  gchar *new_text,
478                                                  gint new_text_length,
479                                                  gint *position,
480                                                  gpointer user_data)
481 {
482     HildonCodeDialog *dialog = HILDON_CODE_DIALOG (user_data);
483     HildonCodeDialogPrivate *priv = HILDON_CODE_DIALOG_GET_PRIVATE (dialog);
484     gchar *text = g_strdup(gtk_entry_get_text (GTK_ENTRY (priv->entry)));
485     glong length = g_utf8_strlen (text, -1);
486     g_free (text);
487     g_assert (priv);
488
489     if (length == MAX_PINCODE_LEN)
490     {
491         hildon_banner_show_information (GTK_WIDGET (dialog),
492                                         NULL,
493                                         DEVICELOCK_MAX_CHAR_REACHED);
494     }
495
496     else if (! length)
497     { 
498         /* make the Ok button sensitive */
499         gtk_widget_set_sensitive (priv->buttons[4][0], TRUE);
500     }
501
502     hildon_code_dialog_input (dialog);
503 }
504
505 static gboolean 
506 hildon_code_dialog_key_press_event              (GtkWidget *widget,
507                                                  GdkEventKey *event,
508                                                  gpointer user_data)
509 {
510     HildonCodeDialog *dialog = HILDON_CODE_DIALOG (user_data);
511     HildonCodeDialogPrivate *priv = HILDON_CODE_DIALOG_GET_PRIVATE (dialog);
512     GtkWidget *new_widget = widget;
513     gint x, y;
514     
515     g_assert (priv);
516
517     if (gtk_im_context_filter_keypress (priv->im_context, event))
518         return TRUE;
519
520     if (event->keyval == GDK_BackSpace)
521     {
522         hildon_code_dialog_backspace (dialog);
523         return TRUE;
524     }
525
526     for (x = 0; x < 5; x++)
527     {
528         for (y = 0; y < 3; y++)
529         {
530             if (priv->buttons[x][y] == widget)
531                 goto found;
532         }
533     }
534     return FALSE;
535
536 found:
537
538     while (new_widget == widget)
539     {
540         switch (event->keyval)
541         {
542             case GDK_Up:
543                 x = (x+4)%5;
544                 break;
545
546             case GDK_Down:
547                 x = (x+1)%5;
548                 break;
549
550             case GDK_Left:
551                 y = (y+2)%3;
552                 break;
553
554             case GDK_Right:
555                 y = (y+1)%3;
556                 break;
557
558             default:
559                 return FALSE;
560         }
561                 
562         new_widget = priv->buttons[x][y];
563     }
564
565     gtk_widget_grab_focus (new_widget);
566
567     return TRUE;
568 }
569
570 /**
571  * hildon_code_dialog_new:
572  *
573  * Use this function to create a new HildonCodeDialog.
574  *
575  * Return value: A @HildonCodeDialog.
576  **/
577 GtkWidget*
578 hildon_code_dialog_new                          (void)
579 {
580     HildonCodeDialog *dialog = g_object_new (HILDON_TYPE_CODE_DIALOG, NULL);
581
582     return GTK_WIDGET (dialog);
583 }
584
585 /**
586  * hildon_code_dialog_get_code:
587  * @dialog: The #HildonCodeDialog from which to get the entered code
588  *
589  * Use this function to access the code entered by the user.
590  *
591  * Return value: The entered code.
592  **/
593 const gchar*
594 hildon_code_dialog_get_code                     (HildonCodeDialog *dialog)
595 {
596     g_return_val_if_fail (HILDON_IS_CODE_DIALOG (dialog), NULL);
597     
598     HildonCodeDialogPrivate *priv = HILDON_CODE_DIALOG_GET_PRIVATE (dialog);
599     g_assert (priv);
600
601     return gtk_entry_get_text (GTK_ENTRY (priv->entry));
602 }
603
604 /**
605  * hildon_code_dialog_clear_clode:
606  * @dialog: The #HildonCodeDialog whose entry should be cleared:
607  *
608  * Use this function to clear the user entered code.
609  **/
610 void 
611 hildon_code_dialog_clear_code                   (HildonCodeDialog *dialog)
612 {
613     g_return_if_fail (HILDON_IS_CODE_DIALOG (dialog));
614
615     HildonCodeDialogPrivate *priv = HILDON_CODE_DIALOG_GET_PRIVATE (dialog);
616     g_assert (priv);
617
618     gtk_entry_set_text (GTK_ENTRY (priv->entry), "");
619     gtk_widget_set_sensitive (priv->buttons[4][0], FALSE);
620 }
621
622 /**
623  * hildon_code_dialog_set_help_text:
624  * @dialog: The #HildonCodeDialog whose entry should be cleared:
625  * @text: The text to use in the help label.
626  *
627  * Use this function to set the text that will be displayd in the
628  * help label
629  **/
630 void 
631 hildon_code_dialog_set_help_text                (HildonCodeDialog *dialog, 
632                                                  const gchar *text)
633 {
634     g_return_if_fail (HILDON_IS_CODE_DIALOG (dialog));
635
636     HildonCodeDialogPrivate *priv = HILDON_CODE_DIALOG_GET_PRIVATE (dialog);
637     g_assert (priv);
638
639     gtk_label_set_text (GTK_LABEL (priv->help_text), text);
640 }
641
642 static void 
643 hildon_code_dialog_real_input                   (HildonCodeDialog *dialog)
644 {
645 }
646
647 static void 
648 hildon_code_dialog_input                        (HildonCodeDialog *dialog)
649 {
650     /* Emit the signal */
651     g_signal_emit (dialog, input_signal, 0);
652 }
653
654 /**
655  * hildon_code_dialog_set_input_sensitive
656  * @dialog: The #HildonCodeDialog whose state is to be changed
657  * @sensitive: The new state 
658  *
659  * This function will block or enable the input on the code dialog by
660  * making the input button sensitive (or not).
661  **/
662 void
663 hildon_code_dialog_set_input_sensitive          (HildonCodeDialog *dialog, 
664                                                  gboolean sensitive)
665 {
666     int i;
667     int k;
668
669     g_return_if_fail (HILDON_IS_CODE_DIALOG (dialog));
670
671     HildonCodeDialogPrivate *priv = HILDON_CODE_DIALOG_GET_PRIVATE (dialog);
672     g_assert (priv);
673
674     for (i = 0; i < 5; i++)
675         for (k = 0; k < 3; k++) 
676             if (i != 4 && (k != 0 || k != 2))
677                 gtk_widget_set_sensitive (priv->buttons [i][k], sensitive);
678
679     gtk_widget_set_sensitive (priv->help_text, sensitive);
680     gtk_widget_set_sensitive (priv->entry, sensitive);
681 }