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