N#27000 (additional fixes to patch from 2006-05-01)
[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  * @description: the message to confirm
463  * @Varargs: arguments pairs for new buttons(label and return value). 
464  *   Terminate the list with %NULL value.
465  * 
466  * Create a new confirmation note with custom buttons. Confirmation
467  * note has a text and any number of buttons. It's important to note
468  * that even though the name of the function might suggest, the
469  * default ok/cancel buttons are not appended but you have to provide
470  * all of the buttons.
471  *
472  * FIXME: This doc seems to be wrong, the two buttons aren't added so
473  * it would only contain the "additional" buttons? However, changing
474  * this would break those applications that rely on current behaviour.
475  *
476  * Returns: A #GtkWidget pointer of the note
477  */
478 GtkWidget *hildon_note_new_confirmation_add_buttons(GtkWindow   *parent,
479                                                     const gchar *description,
480                                                     ...)
481 {
482     va_list args;
483     char *message;
484     int value;
485
486     g_return_val_if_fail(parent == NULL || GTK_IS_WINDOW(parent), NULL);
487
488     GtkWidget *conf_note =
489         g_object_new(HILDON_TYPE_NOTE,
490                      "note_type", HILDON_NOTE_CONFIRMATION_BUTTON_TYPE,
491                      "description", description,
492                      "icon", HILDON_NOTE_CONFIRMATION_ICON, 
493                      NULL);
494
495     if (parent != NULL)
496         gtk_window_set_transient_for(GTK_WINDOW(conf_note), parent);
497
498     /* Add the buttons from varargs */
499     va_start(args, description);
500
501     while (TRUE) {
502         message = va_arg(args, char *);
503
504         if (!message) {
505             break;
506         }
507         value = va_arg(args, int);
508
509         gtk_dialog_add_button(GTK_DIALOG(conf_note), message, value);
510     }
511
512     va_end(args);
513
514     return conf_note;
515 }
516
517
518 /**
519  * hildon_note_new_confirmation:
520  * @parent: the parent window. The X window ID of the parent window
521  *   has to be the same as the X window ID of the application. This is
522  *   important so that the window manager could handle the windows
523  *   correctly. In GTK the X window ID can be checked using
524  *   GDK_WINDOW_XID(GTK_WIDGET(parent)->window).
525  * @description: the message to confirm
526  * 
527  * Create a new confirmation note. Confirmation note has text (description)
528  * that you specify, two buttons and a default confirmation stock icon.
529  *
530  * Returns: a #GtkWidget pointer of the note
531  */
532 GtkWidget *hildon_note_new_confirmation(GtkWindow * parent,
533                                         const gchar * description)
534 {
535     return hildon_note_new_confirmation_with_icon_name
536         (parent, description, HILDON_NOTE_CONFIRMATION_ICON);
537 }
538
539
540 /**
541  * hildon_note_new_confirmation_with_icon_stock:
542  * @parent: the parent window. The X window ID of the parent window
543  *   has to be the same as the X window ID of the application. This is
544  *   important so that the window manager could handle the windows
545  *   correctly. In GTK the X window ID can be checked using
546  *   GDK_WINDOW_XID(GTK_WIDGET(parent)->window).
547  * @description: the message to confirm
548  * @stock_id: icon to be displayed. If NULL, default icon is used.
549  * 
550  * Create a new confirmation note. Confirmation note has text (description) 
551  * that you specify, two buttons and an icon.
552  *
553  * Note! This function is deprecated and broken, and really should not
554  *       be used by anyone!
555  *
556  * Returns: a #GtkWidget pointer of the note
557  */
558 GtkWidget *hildon_note_new_confirmation_with_icon_stock(GtkWindow * parent,
559                                                         const gchar *
560                                                         description,
561                                                         const gchar *
562                                                         stock_id)
563 {
564     /* FIXME: This function is broken. We cannot detect if the "icon"
565               means icon name or stock-id, since the type is the same
566               as in the following function. Anyway, since we really
567               do not support stock icons properly, this is a minor issue. */
568     GtkWidget *dialog = g_object_new(HILDON_TYPE_NOTE,
569                                      "note_type",
570                                      HILDON_NOTE_CONFIRMATION_TYPE,
571                                      "description", description, "icon",
572                                      stock_id, NULL);
573
574     if (parent != NULL)
575         gtk_window_set_transient_for(GTK_WINDOW(dialog), parent);
576
577     return dialog;
578 }
579
580 /**
581  * hildon_note_new_confirmation_with_icon_name:
582  * @parent: the parent window. The X window ID of the parent window
583  *   has to be the same as the X window ID of the application. This is
584  *   important so that the window manager could handle the windows
585  *   correctly. In GTK the X window ID can be checked using
586  *   GDK_WINDOW_XID(GTK_WIDGET(parent)->window).
587  * @description: the message to confirm
588  * @icon_name: icon to be displayed. If NULL, default icon is used.
589  * 
590  * Create a new confirmation note. Confirmation note has text(description) 
591  * that you specify, two buttons and an icon.
592  *
593  * Returns: a #GtkWidget pointer of the note
594  */
595 GtkWidget *hildon_note_new_confirmation_with_icon_name(GtkWindow * parent,
596                                                         const gchar *
597                                                         description,
598                                                         const gchar *
599                                                         icon_name)
600 {
601     GtkWidget *dialog = NULL;
602
603     g_return_val_if_fail(parent == NULL || GTK_IS_WINDOW(parent), NULL);
604
605     dialog = g_object_new(HILDON_TYPE_NOTE,
606                                      "note_type",
607                                      HILDON_NOTE_CONFIRMATION_TYPE,
608                                      "description", description, "icon",
609                                      icon_name, NULL);
610     if (parent != NULL)
611         gtk_window_set_transient_for(GTK_WINDOW(dialog), parent);
612
613     return dialog;
614 }
615
616 /**
617  * hildon_note_new_information:
618  * @parent: the parent window. The X window ID of the parent window
619  *   has to be the same as the X window ID of the application. This is
620  *   important so that the window manager could handle the windows
621  *   correctly. In GTK the X window ID can be checked using
622  *   GDK_WINDOW_XID(GTK_WIDGET(parent)->window).
623  * @description: the message to confirm
624  * 
625  * Create a new information note. Information note has a text(description) 
626  * that you specify, an OK button and an icon.
627  * 
628  * Returns: a #GtkWidget pointer of the note
629  */
630 GtkWidget *hildon_note_new_information(GtkWindow * parent,
631                                        const gchar * description)
632 {
633     return hildon_note_new_information_with_icon_name
634         (parent, description, HILDON_NOTE_INFORMATION_ICON);
635 }
636
637 /**
638  * hildon_note_new_information_with_icon_stock:
639  * @parent: the parent window. The X window ID of the parent window
640  *   has to be the same as the X window ID of the application. This is
641  *   important so that the window manager could handle the windows
642  *   correctly. In GTK the X window ID can be checked using
643  *   GDK_WINDOW_XID(GTK_WIDGET(parent)->window).
644  * @description: the message to confirm
645  * @stock_id: icon to be displayed. If NULL, default icon is used.
646  * 
647  * Create a new information note. Information note has text(description) 
648  * that you specify, an OK button and a default stock note icon.
649  * 
650  * Note! This function is broken and deprecated and should not be
651  *       used by anybody. Since the platform doesn't use stock icons, 
652  *       use #hildon_note_new_information_with_icon_name instead.
653  *
654  * Returns: a #GtkWidget pointer of the note
655  */
656 GtkWidget *hildon_note_new_information_with_icon_stock(GtkWindow * parent,
657                                                        const gchar *
658                                                        description,
659                                                        const gchar *
660                                                        stock_id)
661 {
662     GtkWidget *dialog = NULL;
663
664     g_return_val_if_fail(parent == NULL || GTK_IS_WINDOW(parent), NULL);
665
666     dialog = g_object_new(HILDON_TYPE_NOTE,
667                                      "note_type",
668                                      HILDON_NOTE_INFORMATION_TYPE,
669                                      "description", description,
670                                      "icon", stock_id, NULL);
671     if (parent != NULL)
672         gtk_window_set_transient_for(GTK_WINDOW(dialog), parent);
673
674     return dialog;
675 }
676
677 /**
678  * hildon_note_new_information_with_icon_name:
679  * @parent: the parent window. The X window ID of the parent window
680  *   has to be the same as the X window ID of the application. This is
681  *   important so that the window manager could handle the windows
682  *   correctly. In GTK the X window ID can be checked using
683  *   GDK_WINDOW_XID(GTK_WIDGET(parent)->window).
684  * @description: the message to confirm
685  * @icon_name: icon to be displayed. If NULL, default icon is used.
686  * 
687  * Create a new information note. Information note has text(description) 
688  * that you specify, an OK button and an icon.
689  * 
690  * Returns: a #GtkWidget pointer of the note
691  */
692 GtkWidget *hildon_note_new_information_with_icon_name(GtkWindow * parent,
693                                                        const gchar *
694                                                        description,
695                                                        const gchar *
696                                                        icon_name)
697 {
698     GtkWidget *dialog = NULL;
699
700     g_return_val_if_fail(parent == NULL || GTK_IS_WINDOW(parent), NULL);
701
702     dialog = g_object_new(HILDON_TYPE_NOTE,
703                                      "note_type",
704                                      HILDON_NOTE_INFORMATION_THEME_TYPE,
705                                      "description", description,
706                                      "icon", icon_name, NULL);
707     if (parent != NULL)
708         gtk_window_set_transient_for(GTK_WINDOW(dialog), parent);
709
710     return dialog;
711 }
712
713 /**
714  * hildon_note_new_information_with_icon_theme:
715  * @parent: the parent window. The X window ID of the parent window
716  *   has to be the same as the X window ID of the application. This is
717  *   important so that the window manager could handle the windows
718  *   correctly. In GTK the X window ID can be checked using
719  *   GDK_WINDOW_XID(GTK_WIDGET(parent)->window).
720  * @description: the message to confirm
721  * @icon: #GtkIconTheme icon to be displayed
722  * 
723  * This function is deprecated. Use 
724  * #hildon_note_new_information_with_icon_name instead.
725  *
726  * Create a new information note. Information note has text(description) 
727  * that you specify, an OK button and an icon.
728  *
729  * Returns: a #GtkWidget pointer of the note. 
730  */
731 GtkWidget *hildon_note_new_information_with_icon_theme(GtkWindow *parent,
732                                                        const gchar *description,
733                                                        const gchar *icon)
734 {
735     return hildon_note_new_information_with_icon_name(parent, description, icon);
736 }
737
738 /**
739  * hildon_note_new_cancel_with_progress_bar:
740  * @parent: the parent window. The X window ID of the parent window
741  *   has to be the same as the X window ID of the application. This is
742  *   important so that the window manager could handle the windows
743  *   correctly. In GTK the X window ID can be checked using
744  *   GDK_WINDOW_XID(GTK_WIDGET(parent)->window).
745  * @description: the action to cancel
746  * @progressbar: a pointer to #GtkProgressBar to be filled with the
747  *   progressbar assigned to this note. Use this to set the fraction of
748  *   progressbar done. This parameter can be %NULL as well, in which
749  *   case plain text cancel note appears.
750  *
751  * Create a new cancel note with a progress bar. Cancel note has 
752  * text(description) that you specify, a Cancel button and a progress bar.
753  *
754  * Returns: a #GtkDialog. Use this to get rid of this note when you
755  *   no longer need it.
756  */
757 GtkWidget *hildon_note_new_cancel_with_progress_bar(GtkWindow * parent,
758                                                     const gchar *
759                                                     description,
760                                                     GtkProgressBar *
761                                                     progressbar)
762 {
763     GtkWidget *dialog = NULL;
764
765     g_return_val_if_fail(parent == NULL || GTK_IS_WINDOW(parent), NULL);
766
767     dialog = g_object_new(HILDON_TYPE_NOTE,
768                                      "note_type",
769                                      HILDON_NOTE_PROGRESSBAR_TYPE,
770                                      "description", description,
771                                      "progressbar",
772                                      progressbar, NULL);
773     if (parent != NULL)
774         gtk_window_set_transient_for(GTK_WINDOW(dialog), parent);
775
776     return dialog;
777 }
778
779
780 /**
781  * hildon_note_set_button_text:
782  * @note: a #HildonNote
783  * @text: sets the button text and if there is two buttons in dialog, 
784  *   the button texts will be &lt;text&gt;, "Cancel".  
785  *
786  * Sets the button text to be used by the hildon_note widget.
787  */
788 void hildon_note_set_button_text(HildonNote * note, const gchar * text)
789 {
790     HildonNotePrivate *priv;
791
792     g_return_if_fail(HILDON_IS_NOTE(note));
793
794     priv = HILDON_NOTE_GET_PRIVATE(HILDON_NOTE(note));
795     if (priv->okButton) {
796         gtk_button_set_label(GTK_BUTTON(priv->okButton), text);
797         gtk_button_set_label(GTK_BUTTON(priv->cancelButton),
798                              _("ecdg_bd_confirmation_note_cancel"));
799     } else {
800         gtk_button_set_label(GTK_BUTTON(priv->cancelButton), text);
801     }
802 }
803
804 /**
805  * hildon_note_set_button_texts:
806  * @note: a #HildonNote
807  * @textOk: the new text of the default OK button
808  * @textCancel: the new text of the default cancel button 
809  *
810  * Sets the button texts to be used by this hildon_note widget.
811  */
812 void hildon_note_set_button_texts(HildonNote * note,
813                                   const gchar * textOk,
814                                   const gchar * textCancel)
815 {
816     HildonNotePrivate *priv;
817
818     g_return_if_fail(HILDON_IS_NOTE(note));
819
820     priv = HILDON_NOTE_GET_PRIVATE(HILDON_NOTE(note));
821     if (priv->okButton) {
822       gtk_button_set_label(GTK_BUTTON(priv->okButton), textOk);
823       gtk_button_set_label(GTK_BUTTON(priv->cancelButton),
824                            textCancel);
825     } else {
826       gtk_button_set_label(GTK_BUTTON(priv->cancelButton), textCancel);
827     }
828 }
829
830 /* We play a system sound when the note comes visible */
831 static gboolean
832 sound_handling(GtkWidget * widget, GdkEventExpose *event, gpointer data)
833 {
834   HildonNotePrivate *priv = HILDON_NOTE_GET_PRIVATE(widget);
835   g_signal_handler_disconnect(widget, priv->sound_signal_handler);
836   priv->sound_signal_handler = 0;
837
838   switch (priv->note_n)
839   {
840     case HILDON_NOTE_INFORMATION_TYPE:
841     case HILDON_NOTE_INFORMATION_THEME_TYPE:
842       hildon_play_system_sound(INFORMATION_SOUND_PATH);
843       break;
844     case HILDON_NOTE_CONFIRMATION_TYPE:
845     case HILDON_NOTE_CONFIRMATION_BUTTON_TYPE:
846       hildon_play_system_sound(CONFIRMATION_SOUND_PATH);
847       break;
848     default:
849       break;
850   };
851
852   return FALSE;
853 }