60c6849aa20d278271aaf0da74b248d1eb05d104
[hildon] / src / hildon-note.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-note
27  * @short_description: A widget to ask confirmation from the user
28  *
29  * Notes are used to for confirmation (OK/Cancel/etc.) from the user.
30  * A simple note contains an information text and an OK button to be
31  * pressed.  Additional features such as progress bars or animation can
32  * also be included. 
33  */
34
35 #ifdef                                          HAVE_CONFIG_H
36 #include                                        <config.h>
37 #endif
38
39 #include                                        "hildon-note.h"
40 #include                                        <gtk/gtklabel.h>
41 #include                                        <gtk/gtkimage.h>
42 #include                                        <gtk/gtkhbox.h>
43 #include                                        <gtk/gtkalignment.h>
44 #include                                        <gtk/gtkvbox.h>
45 #include                                        <gtk/gtkbutton.h>
46 #include                                        <libintl.h>
47 #include                                        "hildon-defines.h"
48 #include                                        "hildon-sound.h"
49 #include                                        "hildon-banner.h" 
50 #include                                        "hildon-enum-types.h"
51 #include                                        <stdio.h>
52 #include                                        <string.h>
53 #include                                        "hildon-note-private.h"
54
55 #define                                         CONFIRMATION_SOUND_PATH \
56                                                 "/usr/share/sounds/ui-confirmation_note.wav"
57
58 #define                                         INFORMATION_SOUND_PATH \
59                                                 "/usr/share/sounds/ui-information_note.wav"
60
61 #define                                         HILDON_NOTE_CONFIRMATION_ICON \
62                                                 "qgn_note_confirm"
63
64 #define                                         HILDON_NOTE_INFORMATION_ICON \
65                                                 "qgn_note_info"
66
67 #define                                         _(String) dgettext(PACKAGE, String)
68
69 static void 
70 hildon_note_class_init                          (HildonNoteClass *class);
71
72 static void
73 hildon_note_init                                (HildonNote *dialog);
74
75 static void 
76 hildon_note_rebuild                             (HildonNote *note);
77
78 static void
79 hildon_note_finalize                            (GObject *obj_self);
80
81 static void
82 hildon_note_realize                             (GtkWidget *widget);
83
84 static void 
85 hildon_note_set_property                        (GObject *object,
86                                                  guint prop_id,
87                                                  const GValue *value,
88                                                  GParamSpec *pspec);
89
90 static void
91 hildon_note_get_property                        (GObject *object,
92                                                  guint prop_id,
93                                                  GValue *value, 
94                                                  GParamSpec *pspec);
95
96 static gboolean
97 sound_handling                                  (GtkWidget *widget, 
98                                                  GdkEventExpose *event, 
99                                                  gpointer data);
100
101 enum 
102 {
103     PROP_0,
104     PROP_HILDON_NOTE_TYPE,
105     PROP_HILDON_NOTE_DESCRIPTION,
106     PROP_HILDON_NOTE_ICON,
107     PROP_HILDON_NOTE_PROGRESSBAR,
108     PROP_HILDON_NOTE_STOCK_ICON
109 };
110
111 static GtkDialogClass*                          parent_class;
112
113 static void
114 hildon_note_set_property                        (GObject *object,
115                                                  guint prop_id,
116                                                  const GValue *value, 
117                                                  GParamSpec * pspec)
118 {
119     HildonNote *note = HILDON_NOTE (object);
120     HildonNotePrivate *priv;
121     GtkWidget *widget;
122
123     priv = HILDON_NOTE_GET_PRIVATE (note);
124     g_assert (priv);
125
126     switch (prop_id) {
127
128         case PROP_HILDON_NOTE_TYPE:
129             priv->note_n = g_value_get_enum (value);
130             hildon_note_rebuild (note);
131             break;
132
133         case PROP_HILDON_NOTE_DESCRIPTION:
134             g_free (priv->original_description);
135             priv->original_description = g_value_dup_string (value);
136
137             hildon_gtk_label_set_text_n_lines (GTK_LABEL (priv->label),
138                     priv->original_description, 
139                     priv->note_n == HILDON_NOTE_PROGRESSBAR_TYPE ? 1 : 5);
140
141             break;
142
143         case PROP_HILDON_NOTE_ICON:
144             gtk_image_set_from_icon_name (GTK_IMAGE (priv->icon), 
145                     g_value_get_string(value), HILDON_ICON_SIZE_BIG_NOTE);
146             break;
147
148         case PROP_HILDON_NOTE_STOCK_ICON:
149             gtk_image_set_from_stock (GTK_IMAGE (priv->icon), 
150                     g_value_get_string (value), HILDON_ICON_SIZE_BIG_NOTE);
151             break;
152
153         case PROP_HILDON_NOTE_PROGRESSBAR:
154             widget = g_value_get_object (value);
155             if (widget != priv->progressbar)
156             {
157                 if (priv->progressbar)
158                     g_object_unref (priv->progressbar);
159
160                 priv->progressbar = widget;
161
162                 if (widget)
163                 {
164                     g_object_ref (widget);
165                     gtk_object_sink (GTK_OBJECT (widget));
166                 }
167
168                 hildon_note_rebuild (note);
169             }
170             break;
171
172         default:
173             G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
174             break;
175     }
176 }
177
178 static void
179 hildon_note_get_property                        (GObject *object,
180                                                  guint prop_id, 
181                                                  GValue *value, 
182                                                  GParamSpec *pspec)
183 {
184     HildonNote *note = HILDON_NOTE (object);
185     HildonNotePrivate *priv;
186
187     priv = HILDON_NOTE_GET_PRIVATE (note);
188
189     switch (prop_id) {
190
191         case PROP_HILDON_NOTE_TYPE:
192             g_value_set_enum (value, priv->note_n);
193             break;
194
195         case PROP_HILDON_NOTE_DESCRIPTION:
196             g_value_set_string (value, priv->original_description);
197             break;
198
199         case PROP_HILDON_NOTE_ICON:
200             g_object_get_property (G_OBJECT (priv->icon), "icon-name", value);
201             break;
202
203         case PROP_HILDON_NOTE_STOCK_ICON:
204             g_object_get_property (G_OBJECT (priv->icon), "stock", value);
205             break;
206
207         case PROP_HILDON_NOTE_PROGRESSBAR:
208             g_value_set_object (value, priv->progressbar);
209             break;
210
211         default:
212             G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
213             break;
214     }
215 }
216
217 GType G_GNUC_CONST
218 hildon_note_get_type                            (void)
219 {
220     static GType dialog_type = 0;
221
222     if (! dialog_type) {
223         static const GTypeInfo dialog_info = {
224             sizeof(HildonNoteClass),
225             NULL,       /* base_init */
226             NULL,       /* base_finalize */
227             (GClassInitFunc) hildon_note_class_init,
228             NULL,       /* class_finalize */
229             NULL,       /* class_data */
230             sizeof(HildonNote),
231             0,  /* n_preallocs */
232             (GInstanceInitFunc) hildon_note_init
233         };
234         dialog_type = g_type_register_static (GTK_TYPE_DIALOG,
235                 "HildonNote",
236                 &dialog_info, 0);
237     }
238     return dialog_type;
239 }
240
241 static void 
242 hildon_note_class_init                          (HildonNoteClass *class)
243 {
244     GObjectClass *object_class = G_OBJECT_CLASS (class);
245     GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (class);
246
247     /* set the global parent_class */
248     parent_class = g_type_class_peek_parent (class);
249
250     g_type_class_add_private (class, sizeof (HildonNotePrivate));
251
252     object_class->finalize      = hildon_note_finalize;
253     object_class->set_property  = hildon_note_set_property;
254     object_class->get_property  = hildon_note_get_property;
255     widget_class->realize       = hildon_note_realize;
256
257     g_object_class_install_property (object_class,
258             PROP_HILDON_NOTE_TYPE,
259             g_param_spec_enum ("note_type",
260                 "note type",
261                 "The type of the note dialog",
262                 hildon_note_type_get_type(),
263                 HILDON_NOTE_CONFIRMATION_TYPE,
264                 G_PARAM_READWRITE | G_PARAM_CONSTRUCT));
265
266     /**
267      * HildonNote:description:
268      *
269      * Description for note.
270      */
271     g_object_class_install_property (object_class,
272             PROP_HILDON_NOTE_DESCRIPTION,
273             g_param_spec_string ("description",
274                 "note description",
275                 "The text that appears in the note dialog",
276                 "",
277                 G_PARAM_READWRITE));
278
279     /**
280      * HildonNote:icon:
281      *
282      * Icon for note.
283      */
284     g_object_class_install_property (object_class,
285             PROP_HILDON_NOTE_ICON,
286             g_param_spec_string ("icon",
287                 "note icon",
288                 "The name of the icon that appears in the note dialog",
289                 "",
290                 G_PARAM_READWRITE));
291
292     /**
293      * HildonNote:stock-icon:
294      *
295      * Stock icon for note.
296      */
297     g_object_class_install_property (object_class,
298             PROP_HILDON_NOTE_STOCK_ICON,
299             g_param_spec_string ("stock-icon",
300                 "Stock note icon",
301                 "The stock name of the icon that appears in the note dialog",
302                 "",
303                 G_PARAM_READWRITE));
304
305     /**
306      * HildonNote:progressbar:
307      *
308      * Progressbar for note.
309      */
310     g_object_class_install_property (object_class,
311             PROP_HILDON_NOTE_PROGRESSBAR,
312             g_param_spec_object ("progressbar",
313                 "Progressbar widget",
314                 "The progressbar that appears in the note dialog",
315                 GTK_TYPE_PROGRESS_BAR,
316                 G_PARAM_READWRITE));
317 }
318
319 static void 
320 hildon_note_init                                (HildonNote *dialog)
321 {
322     HildonNotePrivate *priv = HILDON_NOTE_GET_PRIVATE (dialog);
323     g_assert (priv);
324
325     priv->label = gtk_label_new (NULL);
326     priv->icon  = gtk_image_new ();
327
328     /* Acquire real references to our internal children, since
329        they are not nessecarily packed into container in each
330        layout */
331     g_object_ref (priv->label);
332     g_object_ref (priv->icon);
333
334     gtk_object_sink (GTK_OBJECT (priv->label));
335     gtk_object_sink (GTK_OBJECT (priv->icon));
336
337     gtk_dialog_set_has_separator (GTK_DIALOG (dialog), FALSE);
338     gtk_window_set_modal (GTK_WINDOW (dialog), TRUE);
339 }
340
341
342 static void 
343 hildon_note_finalize                            (GObject *obj_self)
344 {
345     HildonNotePrivate *priv = HILDON_NOTE_GET_PRIVATE (obj_self);
346     g_assert (priv);
347
348     /* FIXME Some of this stuff should be moved to dispose */
349
350     /* Free internal data */
351     if (priv->label)
352         g_object_unref (priv->label);
353
354     if (priv->icon)
355         g_object_unref (priv->icon);
356
357     if (priv->progressbar)
358         g_object_unref (priv->progressbar);
359
360     if (priv->original_description)
361         g_free (priv->original_description);
362
363     G_OBJECT_CLASS (parent_class)->finalize (obj_self);
364 }
365
366 static void
367 hildon_note_realize                             (GtkWidget *widget)
368 {
369     HildonNotePrivate *priv = HILDON_NOTE_GET_PRIVATE (widget);
370     g_assert (priv);
371
372     /* Make widget->window accessible */
373     GTK_WIDGET_CLASS (parent_class)->realize (widget);
374
375     /* Border only, no titlebar */
376     gdk_window_set_decorations (widget->window, GDK_DECOR_BORDER);
377
378     /* Because ESD is synchronous, we wish to play sound after the
379        note is already on screen to avoid blocking its appearance */
380     if (priv->sound_signal_handler == 0)
381         priv->sound_signal_handler = g_signal_connect_after(widget, 
382                 "expose-event", G_CALLBACK (sound_handling), NULL);
383 }
384
385 /* Helper function for removing a widget from it's container.
386    we own a separate reference to each object we try to unpack,
387    so extra referencing is not needed. */
388 static void 
389 unpack_widget                                   (GtkWidget *widget)
390 {
391     g_assert (widget == NULL || GTK_IS_WIDGET (widget));
392
393     if (widget && widget->parent)
394         gtk_container_remove (GTK_CONTAINER (widget->parent), widget);
395 }
396
397 static void
398 hildon_note_rebuild                             (HildonNote *note)
399 {
400     GtkDialog *dialog;
401     HildonNotePrivate *priv;
402     gboolean IsHorizontal = TRUE;
403
404     g_assert (HILDON_IS_NOTE (note));
405
406     priv = HILDON_NOTE_GET_PRIVATE (note);
407     g_assert (priv);
408
409     dialog = GTK_DIALOG (note);
410
411     /* Reuse exiting content widgets for new layout */
412     unpack_widget (priv->label);
413     unpack_widget (priv->icon);
414     unpack_widget (priv->progressbar);
415
416     /* Destroy old layout and buttons */
417     if (priv->box) {
418         gtk_widget_destroy (priv->box);
419         priv->box = NULL;
420     }
421     if (priv->okButton) {
422         gtk_widget_destroy (priv->okButton);
423         priv->okButton = NULL;
424     }
425     if (priv->cancelButton) {
426         gtk_widget_destroy (priv->cancelButton);
427         priv->cancelButton = NULL;
428     }
429
430     /* Add needed buttons and images for each note type */
431     switch (priv->note_n)
432     {
433         case HILDON_NOTE_CONFIRMATION_TYPE:
434             priv->okButton = gtk_dialog_add_button (dialog,
435                     _("ecdg_bd_confirmation_note_ok"), GTK_RESPONSE_OK);
436             priv->cancelButton = gtk_dialog_add_button (dialog,
437                     _("ecdg_bd_confirmation_note_cancel"), GTK_RESPONSE_CANCEL);
438
439             /* Fall through */
440         case HILDON_NOTE_CONFIRMATION_BUTTON_TYPE:
441             gtk_image_set_from_icon_name (GTK_IMAGE (priv->icon),
442                     HILDON_NOTE_CONFIRMATION_ICON, 
443                     HILDON_ICON_SIZE_BIG_NOTE);
444             break;
445
446         case HILDON_NOTE_INFORMATION_THEME_TYPE:
447         case HILDON_NOTE_INFORMATION_TYPE:
448             /* Add clickable OK button (cancel really,
449                but doesn't matter since this is info) */
450             priv->cancelButton = gtk_dialog_add_button (dialog,
451                     _("ecdg_bd_information_note_ok"), GTK_RESPONSE_CANCEL);
452             gtk_image_set_from_icon_name (GTK_IMAGE (priv->icon),
453                     HILDON_NOTE_INFORMATION_ICON,
454                     HILDON_ICON_SIZE_BIG_NOTE);
455             break;
456
457         case HILDON_NOTE_PROGRESSBAR_TYPE:
458             priv->cancelButton = gtk_dialog_add_button (dialog,
459                     _("ecdg_bd_cancel_note_cancel"), GTK_RESPONSE_CANCEL);
460             IsHorizontal = FALSE;
461             break;
462
463         default:
464             break;
465     }
466
467     if (IsHorizontal) {
468         /* Pack item with label horizontally */
469         priv->box = gtk_hbox_new (FALSE, HILDON_MARGIN_DEFAULT);
470         gtk_container_add (GTK_CONTAINER (dialog->vbox), priv->box);
471
472         if (priv->icon) {
473             GtkWidget *alignment = gtk_alignment_new (0, 0, 0, 0);
474
475             gtk_box_pack_start (GTK_BOX (priv->box), alignment, FALSE, FALSE, 0);
476             gtk_container_add (GTK_CONTAINER (alignment), priv->icon);
477         }
478         gtk_box_pack_start (GTK_BOX (priv->box), priv->label, TRUE, TRUE, 0);
479
480     } else {
481         /* Pack item with label vertically */
482         priv->box = gtk_vbox_new (FALSE, HILDON_MARGIN_DOUBLE);
483         gtk_container_add (GTK_CONTAINER (dialog->vbox), priv->box);
484         gtk_box_pack_start (GTK_BOX (priv->box), priv->label, TRUE, TRUE, 0);
485
486         if (priv->progressbar)
487             gtk_box_pack_start (GTK_BOX (priv->box), priv->progressbar, FALSE, FALSE, 0);
488     }
489
490     gtk_widget_show_all (priv->box);
491 }
492
493 /**
494  * hildon_note_new_confirmation_add_buttons:
495  * @parent: the parent window. The X window ID of the parent window
496  *   has to be the same as the X window ID of the application. This is
497  *   important so that the window manager could handle the windows
498  *   correctly.
499  *   In GTK the X window ID can be checked using
500  *   GDK_WINDOW_XID(GTK_WIDGET(parent)->window).
501  * @description: the message to confirm
502  * @Varargs: arguments pairs for new buttons(label and return value). 
503  *   Terminate the list with %NULL value.
504  * 
505  * Create a new confirmation note with custom buttons. Confirmation
506  * note has a text and any number of buttons. It's important to note
507  * that even though the name of the function might suggest, the
508  * default ok/cancel buttons are not appended but you have to provide
509  * all of the buttons.
510  *
511  * FIXME: This doc seems to be wrong, the two buttons aren't added so
512  * it would only contain the "additional" buttons? However, changing
513  * this would break those applications that rely on current behaviour.
514  *
515  * Returns: A #GtkWidget pointer of the note
516  */
517 GtkWidget*
518 hildon_note_new_confirmation_add_buttons        (GtkWindow *parent,
519                                                  const gchar *description,
520                                                  ...)
521 {
522     va_list args;
523     char *message;
524     int value;
525
526     g_return_val_if_fail (GTK_IS_WINDOW (parent), NULL);
527
528     GtkWidget *conf_note =
529         g_object_new (HILDON_TYPE_NOTE,
530                 "note_type", HILDON_NOTE_CONFIRMATION_BUTTON_TYPE,
531                 "description", description,
532                 "icon", HILDON_NOTE_CONFIRMATION_ICON, 
533                 NULL);
534
535     if (parent != NULL)
536         gtk_window_set_transient_for (GTK_WINDOW (conf_note), parent);
537
538     /* Add the buttons from varargs */
539     va_start(args, description);
540
541     while (TRUE) {
542         message = va_arg (args, char *);
543
544         if (! message) {
545             break;
546         }
547         value = va_arg (args, int);
548
549         gtk_dialog_add_button (GTK_DIALOG (conf_note), message, value);
550     }
551
552     va_end (args);
553
554     return conf_note;
555 }
556
557
558 /**
559  * hildon_note_new_confirmation:
560  * @parent: the parent window. The X window ID of the parent window
561  *   has to be the same as the X window ID of the application. This is
562  *   important so that the window manager could handle the windows
563  *   correctly. In GTK the X window ID can be checked using
564  *   GDK_WINDOW_XID(GTK_WIDGET(parent)->window).
565  * @description: the message to confirm
566  * 
567  * Create a new confirmation note. Confirmation note has text (description)
568  * that you specify, two buttons and a default confirmation stock icon.
569  *
570  * Returns: a #GtkWidget pointer of the note
571  */
572 GtkWidget*
573 hildon_note_new_confirmation                    (GtkWindow *parent,
574                                                  const gchar *description)
575 {
576     return hildon_note_new_confirmation_with_icon_name
577         (parent, description, HILDON_NOTE_CONFIRMATION_ICON);
578 }
579
580 /**
581  * hildon_note_new_confirmation_with_icon_name:
582  * @parent: the parent window. The X window ID of the parent window
583  *   has to be the same as the X window ID of the application. This is
584  *   important so that the window manager could handle the windows
585  *   correctly. In GTK the X window ID can be checked using
586  *   GDK_WINDOW_XID(GTK_WIDGET(parent)->window).
587  * @description: the message to confirm
588  * @icon_name: icon to be displayed. If NULL, default icon is used.
589  * 
590  * Create a new confirmation note. Confirmation note has text(description) 
591  * that you specify, two buttons and an icon.
592  *
593  * Returns: a #GtkWidget pointer of the note
594  */
595 GtkWidget*
596 hildon_note_new_confirmation_with_icon_name     (GtkWindow *parent,
597                                                  const gchar *description,
598                                                  const gchar *icon_name)
599 {
600     GtkWidget *dialog = NULL;
601
602     g_return_val_if_fail (GTK_IS_WINDOW (parent), NULL);
603
604     dialog = g_object_new (HILDON_TYPE_NOTE,
605             "note_type",
606             HILDON_NOTE_CONFIRMATION_TYPE,
607             "description", description, "icon",
608             icon_name, NULL);
609
610     if (parent != NULL)
611         gtk_window_set_transient_for (GTK_WINDOW (dialog), parent);
612
613     return dialog;
614 }
615
616 /**
617  * hildon_note_new_information:
618  * @parent: the parent window. The X window ID of the parent window
619  *   has to be the same as the X window ID of the application. This is
620  *   important so that the window manager could handle the windows
621  *   correctly. In GTK the X window ID can be checked using
622  *   GDK_WINDOW_XID(GTK_WIDGET(parent)->window).
623  * @description: the message to confirm
624  * 
625  * Create a new information note. Information note has a text(description) 
626  * that you specify, an OK button and an icon.
627  * 
628  * Returns: a #GtkWidget pointer of the note
629  */
630 GtkWidget*
631 hildon_note_new_information                     (GtkWindow *parent,
632                                                  const gchar *description)
633 {
634     return hildon_note_new_information_with_icon_name
635         (parent, description, HILDON_NOTE_INFORMATION_ICON);
636 }
637
638 /**
639  * hildon_note_new_information_with_icon_name:
640  * @parent: the parent window. The X window ID of the parent window
641  *   has to be the same as the X window ID of the application. This is
642  *   important so that the window manager could handle the windows
643  *   correctly. In GTK the X window ID can be checked using
644  *   GDK_WINDOW_XID(GTK_WIDGET(parent)->window).
645  * @description: the message to confirm
646  * @icon_name: icon to be displayed. If NULL, default icon is used.
647  * 
648  * Create a new information note. Information note has text(description) 
649  * that you specify, an OK button and an icon.
650  * 
651  * Returns: a #GtkWidget pointer of the note
652  */
653 GtkWidget*
654 hildon_note_new_information_with_icon_name      (GtkWindow * parent,
655                                                  const gchar *description,
656                                                  const gchar *icon_name)
657 {
658     GtkWidget *dialog = NULL;
659
660     g_return_val_if_fail (GTK_IS_WINDOW (parent), NULL);
661
662     dialog = g_object_new (HILDON_TYPE_NOTE,
663             "note_type",
664             HILDON_NOTE_INFORMATION_THEME_TYPE,
665             "description", description,
666             "icon", icon_name, NULL);
667
668     if (parent != NULL)
669         gtk_window_set_transient_for (GTK_WINDOW (dialog), parent);
670
671     return dialog;
672 }
673
674 /**
675  * hildon_note_new_cancel_with_progress_bar:
676  * @parent: the parent window. The X window ID of the parent window
677  *   has to be the same as the X window ID of the application. This is
678  *   important so that the window manager could handle the windows
679  *   correctly. In GTK the X window ID can be checked using
680  *   GDK_WINDOW_XID(GTK_WIDGET(parent)->window).
681  * @description: the action to cancel
682  * @progressbar: a pointer to #GtkProgressBar to be filled with the
683  *   progressbar assigned to this note. Use this to set the fraction of
684  *   progressbar done. This parameter can be %NULL as well, in which
685  *   case plain text cancel note appears.
686  *
687  * Create a new cancel note with a progress bar. Cancel note has 
688  * text(description) that you specify, a Cancel button and a progress bar.
689  *
690  * Returns: a #GtkDialog. Use this to get rid of this note when you
691  *   no longer need it.
692  */
693 GtkWidget*
694 hildon_note_new_cancel_with_progress_bar        (GtkWindow *parent,
695                                                  const gchar *description,
696                                                  GtkProgressBar *progressbar)
697 {
698     GtkWidget *dialog = NULL;
699
700     g_return_val_if_fail (GTK_IS_WINDOW (parent), NULL);
701
702     dialog = g_object_new (HILDON_TYPE_NOTE,
703             "note_type",
704             HILDON_NOTE_PROGRESSBAR_TYPE,
705             "description", description,
706             "progressbar",
707             progressbar, NULL);
708
709     if (parent != NULL)
710         gtk_window_set_transient_for (GTK_WINDOW (dialog), parent);
711
712     return dialog;
713 }
714
715
716 /**
717  * hildon_note_set_button_text:
718  * @note: a #HildonNote
719  * @text: sets the button text and if there is two buttons in dialog, 
720  *   the button texts will be &lt;text&gt;, "Cancel".  
721  *
722  * Sets the button text to be used by the hildon_note widget.
723  */
724 void 
725 hildon_note_set_button_text                     (HildonNote *note, 
726                                                  const gchar *text)
727 {
728     HildonNotePrivate *priv;
729
730     g_return_if_fail (HILDON_IS_NOTE (note));
731
732     priv = HILDON_NOTE_GET_PRIVATE (HILDON_NOTE (note));
733     g_assert (priv);
734
735     if (priv->okButton) {
736         gtk_button_set_label (GTK_BUTTON (priv->okButton), text);
737         gtk_button_set_label (GTK_BUTTON (priv->cancelButton),
738                 _("ecdg_bd_confirmation_note_cancel"));
739     } else {
740         gtk_button_set_label (GTK_BUTTON (priv->cancelButton), text);
741     }
742 }
743
744 /**
745  * hildon_note_set_button_texts:
746  * @note: a #HildonNote
747  * @textOk: the new text of the default OK button
748  * @textCancel: the new text of the default cancel button 
749  *
750  * Sets the button texts to be used by this hildon_note widget.
751  */
752 void 
753 hildon_note_set_button_texts                    (HildonNote *note,
754                                                  const gchar *text_ok,
755                                                  const gchar *text_cancel)
756 {
757     HildonNotePrivate *priv;
758
759     g_return_if_fail (HILDON_IS_NOTE (note));
760
761     priv = HILDON_NOTE_GET_PRIVATE (HILDON_NOTE (note));
762     g_assert (priv);
763
764     if (priv->okButton) {
765         gtk_button_set_label (GTK_BUTTON (priv->okButton), text_ok);
766         gtk_button_set_label (GTK_BUTTON (priv->cancelButton), text_cancel);
767     } else {
768         gtk_button_set_label (GTK_BUTTON (priv->cancelButton), text_cancel);
769     }
770 }
771
772 /* We play a system sound when the note comes visible */
773 static gboolean
774 sound_handling                                  (GtkWidget *widget, 
775                                                  GdkEventExpose *event, 
776                                                  gpointer data)
777 {
778     HildonNotePrivate *priv = HILDON_NOTE_GET_PRIVATE (widget);
779     g_assert (priv);
780
781     g_signal_handler_disconnect (widget, priv->sound_signal_handler);
782
783     priv->sound_signal_handler = 0;
784
785     switch (priv->note_n)
786     {
787         case HILDON_NOTE_INFORMATION_TYPE:
788         case HILDON_NOTE_INFORMATION_THEME_TYPE:
789             hildon_play_system_sound (INFORMATION_SOUND_PATH);
790             break;
791
792         case HILDON_NOTE_CONFIRMATION_TYPE:
793         case HILDON_NOTE_CONFIRMATION_BUTTON_TYPE:
794             hildon_play_system_sound (CONFIRMATION_SOUND_PATH);
795             break;
796
797         default:
798             break;
799     };
800
801     return FALSE;
802 }