Fix usage of 'Since:' keyword in API documentation
[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 #undef HILDON_DISABLE_DEPRECATED
71
72 #include                                        "hildon-note.h"
73 #include                                        "hildon-defines.h"
74 #include                                        "hildon-sound.h"
75 #include                                        "hildon-banner.h" 
76 #include                                        "hildon-enum-types.h"
77 #include                                        "hildon-note-private.h"
78
79
80 #define                                         CONFIRMATION_SOUND_PATH \
81                                                 "/usr/share/sounds/ui-confirmation_note.wav"
82
83 #define                                         INFORMATION_SOUND_PATH \
84                                                 "/usr/share/sounds/ui-information_note.wav"
85
86 #define                                         _(String) dgettext("hildon-libs", String)
87
88 static void 
89 hildon_note_class_init                          (HildonNoteClass *class);
90
91 static void
92 hildon_note_init                                (HildonNote *dialog);
93
94 static void 
95 hildon_note_rebuild                             (HildonNote *note);
96
97 static void
98 hildon_note_finalize                            (GObject *obj_self);
99
100 static void
101 hildon_note_realize                             (GtkWidget *widget);
102
103 static void 
104 hildon_note_set_property                        (GObject *object,
105                                                  guint prop_id,
106                                                  const GValue *value,
107                                                  GParamSpec *pspec);
108
109 static void
110 hildon_note_get_property                        (GObject *object,
111                                                  guint prop_id,
112                                                  GValue *value, 
113                                                  GParamSpec *pspec);
114
115 static gboolean
116 sound_handling                                  (GtkWidget *widget, 
117                                                  GdkEventExpose *event, 
118                                                  gpointer data);
119
120 enum 
121 {
122     PROP_0,
123     PROP_HILDON_NOTE_TYPE,
124     PROP_HILDON_NOTE_DESCRIPTION,
125     PROP_HILDON_NOTE_ICON,
126     PROP_HILDON_NOTE_PROGRESSBAR,
127     PROP_HILDON_NOTE_STOCK_ICON
128 };
129
130 static GtkDialogClass*                          parent_class;
131
132
133 static void
134 hildon_note_set_property                        (GObject *object,
135                                                  guint prop_id,
136                                                  const GValue *value, 
137                                                  GParamSpec * pspec)
138 {
139     HildonNote *note = HILDON_NOTE (object);
140     HildonNotePrivate *priv;
141     GtkWidget *widget;
142
143     priv = HILDON_NOTE_GET_PRIVATE (note);
144     g_assert (priv);
145
146     switch (prop_id) {
147
148         case PROP_HILDON_NOTE_TYPE:
149             priv->note_n = g_value_get_enum (value);
150             hildon_note_rebuild (note);
151             break;
152
153         case PROP_HILDON_NOTE_DESCRIPTION:
154             if (priv->original_description) 
155                     g_free (priv->original_description);
156             priv->original_description = g_value_dup_string (value);
157
158             gtk_label_set_text (GTK_LABEL (priv->label), priv->original_description);
159             /* FIXME Is the "original_description" used anywhere? */
160             
161             break;
162
163         case PROP_HILDON_NOTE_ICON:
164             if (priv->icon) {
165               g_free (priv->icon);
166             }
167             priv->icon = g_value_dup_string (value);
168             break;
169
170         case PROP_HILDON_NOTE_STOCK_ICON:
171             if (priv->stock_icon) {
172               g_free (priv->stock_icon);
173             }
174             priv->stock_icon = g_value_dup_string (value);
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_value_set_string (value, priv->icon);
225             break;
226
227         case PROP_HILDON_NOTE_STOCK_ICON:
228             g_value_set_string (value, priv->stock_icon);
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      * Deprecated: Since 2.2
316      */
317     g_object_class_install_property (object_class,
318             PROP_HILDON_NOTE_ICON,
319             g_param_spec_string ("icon",
320                 "note icon",
321                 "The name of the icon that appears in the note dialog",
322                 "",
323                 G_PARAM_READWRITE));
324
325     /**
326      * HildonNote:stock-icon:
327      *
328      * Stock icon name for the note.
329      *
330      * Deprecated: Since 2.2
331      */
332     g_object_class_install_property (object_class,
333             PROP_HILDON_NOTE_STOCK_ICON,
334             g_param_spec_string ("stock-icon",
335                 "Stock note icon",
336                 "The stock name of the icon that appears in the note dialog",
337                 "",
338                 G_PARAM_READWRITE));
339
340     /**
341      * HildonNote:progressbar:
342      *
343      * Progressbar for the note (if any).
344      */
345     g_object_class_install_property (object_class,
346             PROP_HILDON_NOTE_PROGRESSBAR,
347             g_param_spec_object ("progressbar",
348                 "Progressbar widget",
349                 "The progressbar that appears in the note dialog",
350                 GTK_TYPE_PROGRESS_BAR,
351                 G_PARAM_READWRITE));
352 }
353
354 static void 
355 hildon_note_init                                (HildonNote *dialog)
356 {
357     HildonNotePrivate *priv = HILDON_NOTE_GET_PRIVATE (dialog);
358     g_assert (priv);
359
360     priv->label = gtk_label_new (NULL);
361     gtk_label_set_line_wrap (GTK_LABEL (priv->label), TRUE);
362
363     priv->icon = NULL;
364     priv->stock_icon = NULL;
365
366     /* Acquire real references to our internal children, since
367        they are not nessecarily packed into container in each
368        layout */
369     g_object_ref_sink (priv->label);
370
371     gtk_dialog_set_has_separator (GTK_DIALOG (dialog), FALSE);
372     gtk_window_set_modal (GTK_WINDOW (dialog), TRUE);
373
374     /* We use special hint to turn the note into information notification. */
375     gtk_window_set_type_hint (GTK_WINDOW (dialog), GDK_WINDOW_TYPE_HINT_NOTIFICATION);
376 }
377
378
379 static void 
380 hildon_note_finalize                            (GObject *obj_self)
381 {
382     HildonNotePrivate *priv = HILDON_NOTE_GET_PRIVATE (obj_self);
383     g_assert (priv);
384
385     /* FIXME Some of this stuff should be moved to dispose */
386
387     /* Free internal data */
388     if (priv->label)
389         g_object_unref (priv->label);
390
391     if (priv->icon) {
392         g_free (priv->icon);
393         priv->icon = NULL;
394     }
395     if (priv->stock_icon) {
396         g_free (priv->stock_icon);
397         priv->stock_icon = NULL;
398     }
399
400     if (priv->progressbar)
401         g_object_unref (priv->progressbar);
402
403     if (priv->original_description)
404         g_free (priv->original_description);
405
406     G_OBJECT_CLASS (parent_class)->finalize (obj_self);
407 }
408
409
410 static void
411 hildon_note_realize                             (GtkWidget *widget)
412 {
413     GdkDisplay *display;
414     Atom atom;
415     const gchar *notification_type;
416     HildonNotePrivate *priv = HILDON_NOTE_GET_PRIVATE (widget);
417     g_assert (priv);
418
419     /* Make widget->window accessible */
420     GTK_WIDGET_CLASS (parent_class)->realize (widget);
421
422     /* Border only, no titlebar */
423     gdk_window_set_decorations (widget->window, GDK_DECOR_BORDER);
424
425     /* Because ESD is synchronous, we wish to play sound after the
426        note is already on screen to avoid blocking its appearance */
427     if (priv->sound_signal_handler == 0)
428         priv->sound_signal_handler = g_signal_connect_after(widget, 
429                 "expose-event", G_CALLBACK (sound_handling), NULL);
430
431     /* Set the _HILDON_NOTIFICATION_TYPE property so Matchbox places the window correctly */
432     display = gdk_drawable_get_display (widget->window);
433     atom = gdk_x11_get_xatom_by_name_for_display (display, "_HILDON_NOTIFICATION_TYPE");
434
435     if (priv->note_n == HILDON_NOTE_TYPE_INFORMATION ||
436         priv->note_n == HILDON_NOTE_TYPE_INFORMATION_THEME) {
437         notification_type = "_HILDON_NOTIFICATION_TYPE_INFO";
438     } else {
439         notification_type = "_HILDON_NOTIFICATION_TYPE_CONFIRMATION";
440     }
441
442     XChangeProperty (GDK_WINDOW_XDISPLAY (widget->window), GDK_WINDOW_XID (widget->window),
443                      atom, XA_STRING, 8, PropModeReplace, (guchar *) notification_type,
444                      strlen (notification_type));
445 }
446
447 /* Helper function for removing a widget from it's container.
448    we own a separate reference to each object we try to unpack,
449    so extra referencing is not needed. */
450 static void 
451 unpack_widget                                   (GtkWidget *widget)
452 {
453     g_assert (widget == NULL || GTK_IS_WIDGET (widget));
454
455     if (widget && widget->parent)
456         gtk_container_remove (GTK_CONTAINER (widget->parent), widget);
457 }
458
459 static void
460 hildon_note_rebuild                             (HildonNote *note)
461 {
462     GtkDialog *dialog;
463     HildonNotePrivate *priv;
464     gboolean IsHorizontal = TRUE;
465
466     g_assert (HILDON_IS_NOTE (note));
467
468     priv = HILDON_NOTE_GET_PRIVATE (note);
469     g_assert (priv);
470
471     dialog = GTK_DIALOG (note);
472
473     /* Reuse exiting content widgets for new layout */
474     unpack_widget (priv->label);
475     unpack_widget (priv->progressbar);
476
477     /* Destroy old layout and buttons */
478     if (priv->box) {
479         gtk_widget_destroy (priv->box);
480         priv->box = NULL;
481     }
482     if (priv->okButton) {
483         gtk_widget_destroy (priv->okButton);
484         priv->okButton = NULL;
485     }
486     if (priv->cancelButton) {
487         gtk_widget_destroy (priv->cancelButton);
488         priv->cancelButton = NULL;
489     }
490
491     /* Add needed buttons and images for each note type */
492     switch (priv->note_n)
493     {
494         case HILDON_NOTE_TYPE_CONFIRMATION:
495             priv->okButton = gtk_dialog_add_button (dialog,
496                     _("wdgt_bd_yes"), GTK_RESPONSE_OK);
497             priv->cancelButton = gtk_dialog_add_button (dialog,
498                     _("wdgt_bd_no"), GTK_RESPONSE_CANCEL);
499             gtk_widget_show (priv->cancelButton);
500             gtk_widget_set_no_show_all (priv->cancelButton, FALSE);
501             break;
502
503         case HILDON_NOTE_TYPE_PROGRESSBAR:
504             priv->cancelButton = gtk_dialog_add_button (dialog,
505                     _("wdgt_bd_stop"), GTK_RESPONSE_CANCEL);
506             gtk_widget_show (priv->cancelButton);
507             gtk_widget_set_no_show_all (priv->cancelButton, FALSE);
508             IsHorizontal = FALSE;
509             break;
510
511         case HILDON_NOTE_TYPE_CONFIRMATION_BUTTON:
512         case HILDON_NOTE_TYPE_INFORMATION_THEME:
513         case HILDON_NOTE_TYPE_INFORMATION:
514         default:
515             break;
516     }
517
518     if (IsHorizontal) {
519         /* Pack item with label horizontally */
520         priv->box = gtk_hbox_new (FALSE, HILDON_MARGIN_DEFAULT);
521         gtk_container_add (GTK_CONTAINER (dialog->vbox), priv->box);
522
523         gtk_box_pack_start (GTK_BOX (priv->box), priv->label, TRUE, TRUE, 0);
524
525     } else {
526         /* Pack item with label vertically */
527         priv->box = gtk_vbox_new (FALSE, HILDON_MARGIN_DOUBLE);
528         gtk_container_add (GTK_CONTAINER (dialog->vbox), priv->box);
529         gtk_box_pack_start (GTK_BOX (priv->box), priv->label, TRUE, TRUE, 0);
530
531         if (priv->progressbar)
532             gtk_box_pack_start (GTK_BOX (priv->box), priv->progressbar, FALSE, FALSE, 0);
533     }
534
535     gtk_widget_show_all (priv->box);
536 }
537
538 /**
539  * hildon_note_new_confirmation_add_buttons:
540  * @parent: the parent window. The X window ID of the parent window
541  *   has to be the same as the X window ID of the application. This is
542  *   important so that the window manager could handle the windows
543  *   correctly.
544  *   In GTK the X window ID can be checked using
545  *   GDK_WINDOW_XID(GTK_WIDGET(parent)->window).
546  * @description: the message to confirm
547  * @Varargs: arguments pairs for new buttons(label and return value). 
548  *   Terminate the list with %NULL value.
549  * 
550  * Create a new confirmation note with custom buttons. Confirmation
551  * note has a text and any number of buttons. It's important to note
552  * that even though the name of the function might suggest, the
553  * default ok/cancel buttons are not appended but you have to provide
554  * all of the buttons.
555  *
556  * FIXME: This doc seems to be wrong, the two buttons aren't added so
557  * it would only contain the "additional" buttons? However, changing
558  * this would break those applications that rely on current behaviour.
559  *
560  * Returns: A #GtkWidget pointer of the note
561  */
562 GtkWidget*
563 hildon_note_new_confirmation_add_buttons        (GtkWindow *parent,
564                                                  const gchar *description,
565                                                  ...)
566 {
567     va_list args;
568     char *message;
569     int value;
570     GtkWidget *button;
571
572     g_return_val_if_fail (description != NULL, NULL);
573
574     GtkWidget *conf_note =
575         g_object_new (HILDON_TYPE_NOTE,
576                 "note-type", HILDON_NOTE_TYPE_CONFIRMATION_BUTTON,
577                 "description", description,
578                 NULL);
579
580     if (parent != NULL)
581         gtk_window_set_transient_for (GTK_WINDOW (conf_note), parent);
582
583     /* Add the buttons from varargs */
584     va_start(args, description);
585
586     while (TRUE) {
587         message = va_arg (args, char *);
588
589         if (! message) {
590             break;
591         }
592         value = va_arg (args, int);
593
594         button = gtk_dialog_add_button (GTK_DIALOG (conf_note), message, value);
595         /* maemo-gtk is going to set the "no-show-all" property all
596            cancel/close-like buttons to TRUE, so that they are not shown. On
597            the other hand, this confirmation note with custom buttons should
598            not obey this rule, so we need to make sure they are shown. */
599         gtk_widget_show (button);
600         gtk_widget_set_no_show_all (button, FALSE);
601     }
602
603     va_end (args);
604
605     return conf_note;
606 }
607
608
609 /**
610  * hildon_note_new_confirmation:
611  * @parent: the parent window. The X window ID of the parent window
612  *   has to be the same as the X window ID of the application. This is
613  *   important so that the window manager could handle the windows
614  *   correctly. In GTK the X window ID can be checked using
615  *   GDK_WINDOW_XID(GTK_WIDGET(parent)->window).
616  * @description: the message to confirm
617  *
618  * Create a new confirmation note. Confirmation note has a text (description)
619  * that you specify and two buttons.
620  *
621  * Returns: a #GtkWidget pointer of the note
622  */
623 GtkWidget*
624 hildon_note_new_confirmation                    (GtkWindow *parent,
625                                                  const gchar *description)
626 {
627     GtkWidget *dialog = NULL;
628
629     g_return_val_if_fail (description != NULL, NULL);
630
631     dialog = g_object_new (HILDON_TYPE_NOTE,
632             "note-type",
633             HILDON_NOTE_TYPE_CONFIRMATION,
634             "description", description, NULL);
635
636     if (parent != NULL)
637         gtk_window_set_transient_for (GTK_WINDOW (dialog), parent);
638
639     return dialog;
640 }
641
642 /**
643  * hildon_note_new_confirmation_with_icon_name:
644  * @parent: the parent window. The X window ID of the parent window
645  *   has to be the same as the X window ID of the application. This is
646  *   important so that the window manager could handle the windows
647  *   correctly. In GTK the X window ID can be checked using
648  *   GDK_WINDOW_XID(GTK_WIDGET(parent)->window).
649  * @description: the message to confirm
650  * @icon_name: icon to be displayed. If NULL, default icon is used.
651  * 
652  * Create a new confirmation note. Confirmation note has a text (description) 
653  * that you specify and two buttons.
654  *
655  * Deprecated: Since 2.2, icons are not shown in confirmation notes. Icons set
656  * with this function will be ignored. Use hildon_note_new_confirmation() instead.
657  *
658  * Returns: a #GtkWidget pointer of the note
659  */
660 GtkWidget*
661 hildon_note_new_confirmation_with_icon_name     (GtkWindow *parent,
662                                                  const gchar *description,
663                                                  const gchar *icon_name)
664 {
665   return hildon_note_new_confirmation (parent, description);
666 }
667
668 /**
669  * hildon_note_new_information:
670  * @parent: the parent window. The X window ID of the parent window
671  *   has to be the same as the X window ID of the application. This is
672  *   important so that the window manager could handle the windows
673  *   correctly. In GTK the X window ID can be checked using
674  *   GDK_WINDOW_XID(GTK_WIDGET(parent)->window).
675  * @description: the message to confirm
676  * 
677  * Create a new information note. Information note has a text (description)
678  * that you specify and an OK button.
679  * 
680  * Returns: a #GtkWidget pointer of the note
681  */
682 GtkWidget*
683 hildon_note_new_information                     (GtkWindow *parent,
684                                                  const gchar *description)
685 {
686     GtkWidget *dialog = NULL;
687
688     g_return_val_if_fail (description != NULL, NULL);
689
690     dialog = g_object_new (HILDON_TYPE_NOTE,
691             "note-type",
692             HILDON_NOTE_TYPE_INFORMATION_THEME,
693             "description", description, NULL);
694
695     if (parent != NULL)
696         gtk_window_set_transient_for (GTK_WINDOW (dialog), parent);
697
698     return dialog;
699 }
700
701 /**
702  * hildon_note_new_information_with_icon_name:
703  * @parent: the parent window. The X window ID of the parent window
704  *   has to be the same as the X window ID of the application. This is
705  *   important so that the window manager could handle the windows
706  *   correctly. In GTK the X window ID can be checked using
707  *   GDK_WINDOW_XID(GTK_WIDGET(parent)->window).
708  * @description: the message to confirm
709  * @icon_name: icon to be displayed. If NULL, default icon is used.
710  * 
711  * Create a new information note. Information note has text(description) 
712  * that you specify, an OK button and an icon.
713  * 
714  * Deprecated: Since 2.2, icons are not shown in confirmation notes. Icons set
715  * with this function will be ignored. Use hildon_note_new_information() instead.
716  *
717  * Returns: a #GtkWidget pointer of the note
718  */
719 GtkWidget*
720 hildon_note_new_information_with_icon_name      (GtkWindow * parent,
721                                                  const gchar *description,
722                                                  const gchar *icon_name)
723 {
724     return hildon_note_new_information (parent, description);
725 }
726
727 /* FIXME This documentation string LIES! */
728
729 /**
730  * hildon_note_new_cancel_with_progress_bar:
731  * @parent: the parent window. The X window ID of the parent window
732  *   has to be the same as the X window ID of the application. This is
733  *   important so that the window manager could handle the windows
734  *   correctly. In GTK the X window ID can be checked using
735  *   GDK_WINDOW_XID(GTK_WIDGET(parent)->window).
736  * @description: the action to cancel
737  * @progressbar: a pointer to #GtkProgressBar to be filled with the
738  *   progressbar assigned to this note. Use this to set the fraction of
739  *   progressbar done. This parameter can be %NULL as well, in which
740  *   case plain text cancel note appears.
741  *
742  * Create a new cancel note with a progress bar. Cancel note has 
743  * text(description) that you specify, a Cancel button and a progress bar.
744  *
745  * Returns: a #GtkDialog. Use this to get rid of this note when you
746  *   no longer need it.
747  */
748 GtkWidget*
749 hildon_note_new_cancel_with_progress_bar        (GtkWindow *parent,
750                                                  const gchar *description,
751                                                  GtkProgressBar *progressbar)
752 {
753     GtkWidget *dialog = NULL;
754
755     g_return_val_if_fail (description != NULL, NULL);
756
757     dialog = g_object_new (HILDON_TYPE_NOTE,
758             "note-type",
759             HILDON_NOTE_TYPE_PROGRESSBAR,
760             "description", description,
761             "progressbar",
762             progressbar, NULL);
763
764     if (parent != NULL)
765         gtk_window_set_transient_for (GTK_WINDOW (dialog), parent);
766
767     return dialog;
768 }
769
770
771 /**
772  * hildon_note_set_button_text:
773  * @note: a #HildonNote
774  * @text: sets the button text and if there is two buttons in dialog, 
775  *   the button texts will be &lt;text&gt;, "Cancel".  
776  *
777  * Sets the button text to be used by the hildon_note widget.
778  */
779 void 
780 hildon_note_set_button_text                     (HildonNote *note, 
781                                                  const gchar *text)
782 {
783     HildonNotePrivate *priv;
784
785     g_return_if_fail (HILDON_IS_NOTE (note));
786
787     priv = HILDON_NOTE_GET_PRIVATE (HILDON_NOTE (note));
788     g_assert (priv);
789
790     if (priv->okButton) {
791         gtk_button_set_label (GTK_BUTTON (priv->okButton), text);
792         gtk_button_set_label (GTK_BUTTON (priv->cancelButton),
793                 _("wdgt_bd_no"));
794     } else {
795         gtk_button_set_label (GTK_BUTTON (priv->cancelButton), text);
796     }
797 }
798
799 /**
800  * hildon_note_set_button_texts:
801  * @note: a #HildonNote
802  * @text_ok: the new text of the default OK button
803  * @text_cancel: the new text of the default cancel button 
804  *
805  * Sets the button texts to be used by this hildon_note widget.
806  */
807 void 
808 hildon_note_set_button_texts                    (HildonNote *note,
809                                                  const gchar *text_ok,
810                                                  const gchar *text_cancel)
811 {
812     HildonNotePrivate *priv;
813
814     g_return_if_fail (HILDON_IS_NOTE (note));
815
816     priv = HILDON_NOTE_GET_PRIVATE (HILDON_NOTE (note));
817     g_assert (priv);
818
819     if (priv->okButton) {
820         gtk_button_set_label (GTK_BUTTON (priv->okButton), text_ok);
821         gtk_button_set_label (GTK_BUTTON (priv->cancelButton), text_cancel);
822     } else {
823         gtk_button_set_label (GTK_BUTTON (priv->cancelButton), text_cancel);
824     }
825 }
826
827 /* We play a system sound when the note comes visible */
828 static gboolean
829 sound_handling                                  (GtkWidget *widget, 
830                                                  GdkEventExpose *event, 
831                                                  gpointer data)
832 {
833     HildonNotePrivate *priv = HILDON_NOTE_GET_PRIVATE (widget);
834     g_assert (priv);
835
836     g_signal_handler_disconnect (widget, priv->sound_signal_handler);
837
838     priv->sound_signal_handler = 0;
839
840     switch (priv->note_n)
841     {
842         case HILDON_NOTE_TYPE_INFORMATION:
843         case HILDON_NOTE_TYPE_INFORMATION_THEME:
844             hildon_play_system_sound (INFORMATION_SOUND_PATH);
845             break;
846
847         case HILDON_NOTE_TYPE_CONFIRMATION:
848         case HILDON_NOTE_TYPE_CONFIRMATION_BUTTON:
849             hildon_play_system_sound (CONFIRMATION_SOUND_PATH);
850             break;
851
852         default:
853             break;
854     };
855
856     return FALSE;
857 }