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