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                     _("wdgt_bd_yes"), GTK_RESPONSE_OK);
488             priv->cancelButton = gtk_dialog_add_button (dialog,
489                     _("wdgt_bd_no"), GTK_RESPONSE_CANCEL);
490             gtk_widget_set_no_show_all (priv->cancelButton, FALSE);
491             break;
492
493         case HILDON_NOTE_TYPE_CONFIRMATION_BUTTON:
494             gtk_image_set_from_icon_name (GTK_IMAGE (priv->icon),
495                     HILDON_NOTE_CONFIRMATION_ICON, 
496                     HILDON_ICON_SIZE_BIG_NOTE);
497             break;
498
499         case HILDON_NOTE_TYPE_INFORMATION_THEME:
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_INFORMATION:
506             break;
507
508         case HILDON_NOTE_TYPE_PROGRESSBAR:
509             priv->cancelButton = gtk_dialog_add_button (dialog,
510                     _("wdgt_bd_stop"), GTK_RESPONSE_CANCEL);
511             IsHorizontal = FALSE;
512             break;
513
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         if (priv->icon) {
524             GtkWidget *alignment = gtk_alignment_new (0, 0, 0, 0);
525
526             gtk_box_pack_start (GTK_BOX (priv->box), alignment, FALSE, FALSE, 0);
527             gtk_container_add (GTK_CONTAINER (alignment), priv->icon);
528         }
529         gtk_box_pack_start (GTK_BOX (priv->box), priv->label, TRUE, TRUE, 0);
530
531     } else {
532         /* Pack item with label vertically */
533         priv->box = gtk_vbox_new (FALSE, HILDON_MARGIN_DOUBLE);
534         gtk_container_add (GTK_CONTAINER (dialog->vbox), priv->box);
535         gtk_box_pack_start (GTK_BOX (priv->box), priv->label, TRUE, TRUE, 0);
536
537         if (priv->progressbar)
538             gtk_box_pack_start (GTK_BOX (priv->box), priv->progressbar, FALSE, FALSE, 0);
539     }
540
541     gtk_widget_show_all (priv->box);
542 }
543
544 /**
545  * hildon_note_new_confirmation_add_buttons:
546  * @parent: the parent window. The X window ID of the parent window
547  *   has to be the same as the X window ID of the application. This is
548  *   important so that the window manager could handle the windows
549  *   correctly.
550  *   In GTK the X window ID can be checked using
551  *   GDK_WINDOW_XID(GTK_WIDGET(parent)->window).
552  * @description: the message to confirm
553  * @Varargs: arguments pairs for new buttons(label and return value). 
554  *   Terminate the list with %NULL value.
555  * 
556  * Create a new confirmation note with custom buttons. Confirmation
557  * note has a text and any number of buttons. It's important to note
558  * that even though the name of the function might suggest, the
559  * default ok/cancel buttons are not appended but you have to provide
560  * all of the buttons.
561  *
562  * FIXME: This doc seems to be wrong, the two buttons aren't added so
563  * it would only contain the "additional" buttons? However, changing
564  * this would break those applications that rely on current behaviour.
565  *
566  * Returns: A #GtkWidget pointer of the note
567  */
568 GtkWidget*
569 hildon_note_new_confirmation_add_buttons        (GtkWindow *parent,
570                                                  const gchar *description,
571                                                  ...)
572 {
573     va_list args;
574     char *message;
575     int value;
576
577     g_return_val_if_fail (description != NULL, NULL);
578
579     GtkWidget *conf_note =
580         g_object_new (HILDON_TYPE_NOTE,
581                 "note-type", HILDON_NOTE_TYPE_CONFIRMATION_BUTTON,
582                 "description", description,
583                 "icon", HILDON_NOTE_CONFIRMATION_ICON, 
584                 NULL);
585
586     if (parent != NULL)
587         gtk_window_set_transient_for (GTK_WINDOW (conf_note), parent);
588
589     /* Add the buttons from varargs */
590     va_start(args, description);
591
592     while (TRUE) {
593         message = va_arg (args, char *);
594
595         if (! message) {
596             break;
597         }
598         value = va_arg (args, int);
599
600         gtk_dialog_add_button (GTK_DIALOG (conf_note), message, value);
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 text (description)
619  * that you specify, two buttons and a default confirmation stock icon.
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     return hildon_note_new_confirmation_with_icon_name
628         (parent, description, HILDON_NOTE_CONFIRMATION_ICON);
629 }
630
631 /**
632  * hildon_note_new_confirmation_with_icon_name:
633  * @parent: the parent window. The X window ID of the parent window
634  *   has to be the same as the X window ID of the application. This is
635  *   important so that the window manager could handle the windows
636  *   correctly. In GTK the X window ID can be checked using
637  *   GDK_WINDOW_XID(GTK_WIDGET(parent)->window).
638  * @description: the message to confirm
639  * @icon_name: icon to be displayed. If NULL, default icon is used.
640  * 
641  * Create a new confirmation note. Confirmation note has text(description) 
642  * that you specify, two buttons and an icon.
643  *
644  * Returns: a #GtkWidget pointer of the note
645  */
646 GtkWidget*
647 hildon_note_new_confirmation_with_icon_name     (GtkWindow *parent,
648                                                  const gchar *description,
649                                                  const gchar *icon_name)
650 {
651     GtkWidget *dialog = NULL;
652
653     g_return_val_if_fail (description != NULL, NULL);
654
655     dialog = g_object_new (HILDON_TYPE_NOTE,
656             "note-type",
657             HILDON_NOTE_TYPE_CONFIRMATION,
658             "description", description, "icon",
659             icon_name, NULL);
660
661     if (parent != NULL)
662         gtk_window_set_transient_for (GTK_WINDOW (dialog), parent);
663
664     return dialog;
665 }
666
667 /**
668  * hildon_note_new_information:
669  * @parent: the parent window. The X window ID of the parent window
670  *   has to be the same as the X window ID of the application. This is
671  *   important so that the window manager could handle the windows
672  *   correctly. In GTK the X window ID can be checked using
673  *   GDK_WINDOW_XID(GTK_WIDGET(parent)->window).
674  * @description: the message to confirm
675  * 
676  * Create a new information note. Information note has a text(description) 
677  * that you specify, an OK button and an icon.
678  * 
679  * Returns: a #GtkWidget pointer of the note
680  */
681 GtkWidget*
682 hildon_note_new_information                     (GtkWindow *parent,
683                                                  const gchar *description)
684 {
685     return hildon_note_new_information_with_icon_name
686         (parent, description, HILDON_NOTE_INFORMATION_ICON);
687 }
688
689 /**
690  * hildon_note_new_information_with_icon_name:
691  * @parent: the parent window. The X window ID of the parent window
692  *   has to be the same as the X window ID of the application. This is
693  *   important so that the window manager could handle the windows
694  *   correctly. In GTK the X window ID can be checked using
695  *   GDK_WINDOW_XID(GTK_WIDGET(parent)->window).
696  * @description: the message to confirm
697  * @icon_name: icon to be displayed. If NULL, default icon is used.
698  * 
699  * Create a new information note. Information note has text(description) 
700  * that you specify, an OK button and an icon.
701  * 
702  * Returns: a #GtkWidget pointer of the note
703  */
704 GtkWidget*
705 hildon_note_new_information_with_icon_name      (GtkWindow * parent,
706                                                  const gchar *description,
707                                                  const gchar *icon_name)
708 {
709     GtkWidget *dialog = NULL;
710
711     g_return_val_if_fail (description != NULL, NULL);
712     g_return_val_if_fail (icon_name != NULL, NULL);
713
714     dialog = g_object_new (HILDON_TYPE_NOTE,
715             "note-type",
716             HILDON_NOTE_TYPE_INFORMATION_THEME,
717             "description", description,
718             "icon", icon_name, NULL);
719
720     if (parent != NULL)
721         gtk_window_set_transient_for (GTK_WINDOW (dialog), parent);
722
723     return dialog;
724 }
725
726 /* FIXME This documentation string LIES! */
727
728 /**
729  * hildon_note_new_cancel_with_progress_bar:
730  * @parent: the parent window. The X window ID of the parent window
731  *   has to be the same as the X window ID of the application. This is
732  *   important so that the window manager could handle the windows
733  *   correctly. In GTK the X window ID can be checked using
734  *   GDK_WINDOW_XID(GTK_WIDGET(parent)->window).
735  * @description: the action to cancel
736  * @progressbar: a pointer to #GtkProgressBar to be filled with the
737  *   progressbar assigned to this note. Use this to set the fraction of
738  *   progressbar done. This parameter can be %NULL as well, in which
739  *   case plain text cancel note appears.
740  *
741  * Create a new cancel note with a progress bar. Cancel note has 
742  * text(description) that you specify, a Cancel button and a progress bar.
743  *
744  * Returns: a #GtkDialog. Use this to get rid of this note when you
745  *   no longer need it.
746  */
747 GtkWidget*
748 hildon_note_new_cancel_with_progress_bar        (GtkWindow *parent,
749                                                  const gchar *description,
750                                                  GtkProgressBar *progressbar)
751 {
752     GtkWidget *dialog = NULL;
753
754     g_return_val_if_fail (description != NULL, NULL);
755
756     dialog = g_object_new (HILDON_TYPE_NOTE,
757             "note-type",
758             HILDON_NOTE_TYPE_PROGRESSBAR,
759             "description", description,
760             "progressbar",
761             progressbar, NULL);
762
763     if (parent != NULL)
764         gtk_window_set_transient_for (GTK_WINDOW (dialog), parent);
765
766     return dialog;
767 }
768
769
770 /**
771  * hildon_note_set_button_text:
772  * @note: a #HildonNote
773  * @text: sets the button text and if there is two buttons in dialog, 
774  *   the button texts will be &lt;text&gt;, "Cancel".  
775  *
776  * Sets the button text to be used by the hildon_note widget.
777  */
778 void 
779 hildon_note_set_button_text                     (HildonNote *note, 
780                                                  const gchar *text)
781 {
782     HildonNotePrivate *priv;
783
784     g_return_if_fail (HILDON_IS_NOTE (note));
785
786     priv = HILDON_NOTE_GET_PRIVATE (HILDON_NOTE (note));
787     g_assert (priv);
788
789     if (priv->okButton) {
790         gtk_button_set_label (GTK_BUTTON (priv->okButton), text);
791         gtk_button_set_label (GTK_BUTTON (priv->cancelButton),
792                 _("wdgt_bd_no"));
793     } else {
794         gtk_button_set_label (GTK_BUTTON (priv->cancelButton), text);
795     }
796 }
797
798 /**
799  * hildon_note_set_button_texts:
800  * @note: a #HildonNote
801  * @text_ok: the new text of the default OK button
802  * @text_cancel: the new text of the default cancel button 
803  *
804  * Sets the button texts to be used by this hildon_note widget.
805  */
806 void 
807 hildon_note_set_button_texts                    (HildonNote *note,
808                                                  const gchar *text_ok,
809                                                  const gchar *text_cancel)
810 {
811     HildonNotePrivate *priv;
812
813     g_return_if_fail (HILDON_IS_NOTE (note));
814
815     priv = HILDON_NOTE_GET_PRIVATE (HILDON_NOTE (note));
816     g_assert (priv);
817
818     if (priv->okButton) {
819         gtk_button_set_label (GTK_BUTTON (priv->okButton), text_ok);
820         gtk_button_set_label (GTK_BUTTON (priv->cancelButton), text_cancel);
821     } else {
822         gtk_button_set_label (GTK_BUTTON (priv->cancelButton), text_cancel);
823     }
824 }
825
826 /* We play a system sound when the note comes visible */
827 static gboolean
828 sound_handling                                  (GtkWidget *widget, 
829                                                  GdkEventExpose *event, 
830                                                  gpointer data)
831 {
832     HildonNotePrivate *priv = HILDON_NOTE_GET_PRIVATE (widget);
833     g_assert (priv);
834
835     g_signal_handler_disconnect (widget, priv->sound_signal_handler);
836
837     priv->sound_signal_handler = 0;
838
839     switch (priv->note_n)
840     {
841         case HILDON_NOTE_TYPE_INFORMATION:
842         case HILDON_NOTE_TYPE_INFORMATION_THEME:
843             hildon_play_system_sound (INFORMATION_SOUND_PATH);
844             break;
845
846         case HILDON_NOTE_TYPE_CONFIRMATION:
847         case HILDON_NOTE_TYPE_CONFIRMATION_BUTTON:
848             hildon_play_system_sound (CONFIRMATION_SOUND_PATH);
849             break;
850
851         default:
852             break;
853     };
854
855     return FALSE;
856 }