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