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