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