2006-11-16 Michael Dominic Kostrzewa <michael.kostrzewa@nokia.com>
[hildon] / src / 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.
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_get_type()
200 {
201     static GType dialog_type = 0;
202
203     if (!dialog_type) {
204         static const GTypeInfo dialog_info = {
205             sizeof(HildonNoteClass),
206             NULL,       /* base_init */
207             NULL,       /* base_finalize */
208             (GClassInitFunc) hildon_note_class_init,
209             NULL,       /* class_finalize */
210             NULL,       /* class_data */
211             sizeof(HildonNote),
212             0,  /* n_preallocs */
213             (GInstanceInitFunc) hildon_note_init
214         };
215         dialog_type = g_type_register_static(GTK_TYPE_DIALOG,
216                                              "HildonNote",
217                                              &dialog_info, 0);
218     }
219     return dialog_type;
220 }
221
222 static void hildon_note_class_init(HildonNoteClass * class)
223 {
224     GObjectClass *object_class = G_OBJECT_CLASS(class);
225     GtkWidgetClass *widget_class = GTK_WIDGET_CLASS(class);
226
227     /* set the global parent_class */
228     parent_class = g_type_class_peek_parent(class);
229
230     g_type_class_add_private(class, sizeof(HildonNotePrivate));
231
232     object_class->finalize = hildon_note_finalize;
233     object_class->set_property = hildon_note_set_property;
234     object_class->get_property = hildon_note_get_property;
235     widget_class->realize = hildon_note_realize;
236
237     g_object_class_install_property(object_class,
238         PROP_HILDON_NOTE_TYPE,
239         g_param_spec_enum("note_type",
240                           "note type",
241                           "The type of the note dialog",
242                           hildon_note_type_get_type(),
243                           HILDON_NOTE_CONFIRMATION_TYPE,
244                           G_PARAM_READWRITE | G_PARAM_CONSTRUCT));
245
246   /**
247    * HildonNote:description:
248    *
249    * Description for note.
250    */
251     g_object_class_install_property(object_class,
252         PROP_HILDON_NOTE_DESCRIPTION,
253         g_param_spec_string("description",
254                             "note description",
255                             "The text that appears in the note dialog",
256                             "",
257                             G_PARAM_READWRITE));
258
259   /**
260    * HildonNote:icon:
261    *
262    * Icon for note.
263    */
264     g_object_class_install_property(object_class,
265         PROP_HILDON_NOTE_ICON,
266         g_param_spec_string("icon",
267                             "note icon",
268                             "The name of the icon that appears in the note dialog",
269                             "",
270                             G_PARAM_READWRITE));
271
272    /**
273    * HildonNote:stock-icon:
274    *
275    * Stock icon for note.
276    */
277     g_object_class_install_property(object_class,
278         PROP_HILDON_NOTE_STOCK_ICON,
279         g_param_spec_string("stock-icon",
280                             "Stock note icon",
281                             "The stock name of the icon that appears in the note dialog",
282                             "",
283                             G_PARAM_READWRITE));
284
285   /**
286    * HildonNote:progressbar:
287    *
288    * Progressbar for note.
289    */
290     g_object_class_install_property(object_class,
291         PROP_HILDON_NOTE_PROGRESSBAR,
292         g_param_spec_object("progressbar",
293                             "Progressbar widget",
294                             "The progressbar that appears in the note dialog",
295                             GTK_TYPE_PROGRESS_BAR,
296                             G_PARAM_READWRITE));
297 }
298
299 static void hildon_note_init(HildonNote * dialog)
300 {
301     HildonNotePrivate *priv = HILDON_NOTE_GET_PRIVATE(dialog);
302
303     priv->label = gtk_label_new(NULL);
304     priv->icon  = gtk_image_new();
305
306     /* Acquire real references to our internal children, since
307        they are not nessecarily packed into container in each
308        layout */
309     g_object_ref(priv->label);
310     g_object_ref(priv->icon);
311     gtk_object_sink(GTK_OBJECT(priv->label));
312     gtk_object_sink(GTK_OBJECT(priv->icon));
313     
314     gtk_dialog_set_has_separator(GTK_DIALOG(dialog), FALSE);
315     gtk_window_set_modal(GTK_WINDOW(dialog), TRUE);
316 }
317
318
319 static void hildon_note_finalize(GObject * obj_self)
320 {
321     HildonNotePrivate *priv = HILDON_NOTE_GET_PRIVATE(obj_self);
322     
323     /* Free internal data */
324     g_object_unref(priv->label);
325     g_object_unref(priv->icon);
326     if (priv->progressbar)
327         g_object_unref(priv->progressbar);
328
329     g_free(priv->original_description);
330
331     G_OBJECT_CLASS(parent_class)->finalize(obj_self);
332 }
333
334 static void
335 hildon_note_realize (GtkWidget *widget)
336 {
337     HildonNotePrivate *priv = HILDON_NOTE_GET_PRIVATE(widget);
338
339     /* Make widget->window accessible */
340     GTK_WIDGET_CLASS (parent_class)->realize (widget);
341
342     /* Border only, no titlebar */
343     gdk_window_set_decorations (widget->window, GDK_DECOR_BORDER);
344
345     /* Because ESD is synchronous, we wish to play sound after the
346        note is already on screen to avoid blocking its appearance */
347     if (priv->sound_signal_handler == 0)
348         priv->sound_signal_handler = g_signal_connect_after(widget, 
349                 "expose-event", G_CALLBACK(sound_handling), NULL);
350 }
351
352 /* Helper function for removing a widget from it's container.
353    we own a separate reference to each object we try to unpack,
354    so extra referencing is not needed. */
355 static void unpack_widget(GtkWidget *widget)
356 {
357     g_assert(widget == NULL || GTK_IS_WIDGET(widget));
358
359     if (widget && widget->parent)
360         gtk_container_remove(GTK_CONTAINER(widget->parent), widget);
361 }
362
363 static void
364 hildon_note_rebuild(HildonNote *note)
365 {
366     GtkDialog *dialog;
367     HildonNotePrivate *priv;
368     gboolean IsHorizontal = TRUE;
369
370     g_assert(HILDON_IS_NOTE(note));
371
372     priv = HILDON_NOTE_GET_PRIVATE (note);
373     dialog = GTK_DIALOG(note);
374
375     /* Reuse exiting content widgets for new layout */
376     unpack_widget(priv->label);
377     unpack_widget(priv->icon);
378     unpack_widget(priv->progressbar);
379
380     /* Destroy old layout and buttons */
381     if (priv->box) {
382         gtk_widget_destroy(priv->box);
383         priv->box = NULL;
384     }
385     if (priv->okButton) {
386         gtk_widget_destroy(priv->okButton);
387         priv->okButton = NULL;
388     }
389     if (priv->cancelButton) {
390         gtk_widget_destroy(priv->cancelButton);
391         priv->cancelButton = NULL;
392     }
393
394     /* Add needed buttons and images for each note type */
395     switch (priv->note_n)
396     {
397         case HILDON_NOTE_CONFIRMATION_TYPE:
398             priv->okButton = gtk_dialog_add_button(dialog,
399                     _("ecdg_bd_confirmation_note_ok"), GTK_RESPONSE_OK);
400             priv->cancelButton = gtk_dialog_add_button(dialog,
401                     _("ecdg_bd_confirmation_note_cancel"), GTK_RESPONSE_CANCEL);
402
403             /* Fall through */
404         case HILDON_NOTE_CONFIRMATION_BUTTON_TYPE:
405             gtk_image_set_from_icon_name(GTK_IMAGE(priv->icon),
406                HILDON_NOTE_CONFIRMATION_ICON, 
407                HILDON_ICON_SIZE_BIG_NOTE);
408             break;
409
410         case HILDON_NOTE_INFORMATION_THEME_TYPE:
411         case HILDON_NOTE_INFORMATION_TYPE:
412             /* Add clickable OK button (cancel really,
413                but doesn't matter since this is info) */
414             priv->cancelButton = gtk_dialog_add_button(dialog,
415                     _("ecdg_bd_information_note_ok"), GTK_RESPONSE_CANCEL);
416             gtk_image_set_from_icon_name(GTK_IMAGE(priv->icon),
417                 HILDON_NOTE_INFORMATION_ICON,
418                 HILDON_ICON_SIZE_BIG_NOTE);
419             break;
420
421         case HILDON_NOTE_PROGRESSBAR_TYPE:
422             priv->cancelButton = gtk_dialog_add_button(dialog,
423                     _("ecdg_bd_cancel_note_cancel"), GTK_RESPONSE_CANCEL);
424             IsHorizontal = FALSE;
425             break;
426
427         default:
428             break;
429     }
430
431     if (IsHorizontal) {
432         /* Pack item with label horizontally */
433         priv->box = gtk_hbox_new(FALSE, HILDON_MARGIN_DEFAULT);
434         gtk_container_add(GTK_CONTAINER(dialog->vbox), priv->box);
435
436         if (priv->icon) {
437             GtkWidget *alignment = gtk_alignment_new(0, 0, 0, 0);
438
439             gtk_box_pack_start(GTK_BOX(priv->box), alignment, FALSE, FALSE, 0);
440             gtk_container_add(GTK_CONTAINER(alignment), priv->icon);
441         }
442         gtk_box_pack_start(GTK_BOX(priv->box), priv->label, TRUE, TRUE, 0);
443
444     } else {
445         /* Pack item with label vertically */
446         priv->box = gtk_vbox_new(FALSE, HILDON_MARGIN_DOUBLE);
447         gtk_container_add(GTK_CONTAINER(dialog->vbox), priv->box);
448         gtk_box_pack_start(GTK_BOX(priv->box), priv->label, TRUE, TRUE, 0);
449
450         if (priv->progressbar)
451             gtk_box_pack_start(GTK_BOX(priv->box), priv->progressbar, FALSE, FALSE, 0);
452     }
453     
454     gtk_widget_show_all(priv->box);
455 }
456
457 /**
458  * hildon_note_new_confirmation_add_buttons:
459  * @parent: the parent window. The X window ID of the parent window
460  *   has to be the same as the X window ID of the application. This is
461  *   important so that the window manager could handle the windows
462  *   correctly.
463  *   In GTK the X window ID can be checked using
464  *   GDK_WINDOW_XID(GTK_WIDGET(parent)->window).
465  * @description: the message to confirm
466  * @Varargs: arguments pairs for new buttons(label and return value). 
467  *   Terminate the list with %NULL value.
468  * 
469  * Create a new confirmation note with custom buttons. Confirmation
470  * note has a text and any number of buttons. It's important to note
471  * that even though the name of the function might suggest, the
472  * default ok/cancel buttons are not appended but you have to provide
473  * all of the buttons.
474  *
475  * FIXME: This doc seems to be wrong, the two buttons aren't added so
476  * it would only contain the "additional" buttons? However, changing
477  * this would break those applications that rely on current behaviour.
478  *
479  * Returns: A #GtkWidget pointer of the note
480  */
481 GtkWidget *hildon_note_new_confirmation_add_buttons(GtkWindow   *parent,
482                                                     const gchar *description,
483                                                     ...)
484 {
485     va_list args;
486     char *message;
487     int value;
488
489     g_return_val_if_fail(parent == NULL || GTK_IS_WINDOW(parent), NULL);
490
491     GtkWidget *conf_note =
492         g_object_new(HILDON_TYPE_NOTE,
493                      "note_type", HILDON_NOTE_CONFIRMATION_BUTTON_TYPE,
494                      "description", description,
495                      "icon", HILDON_NOTE_CONFIRMATION_ICON, 
496                      NULL);
497
498     if (parent != NULL)
499         gtk_window_set_transient_for(GTK_WINDOW(conf_note), parent);
500
501     /* Add the buttons from varargs */
502     va_start(args, description);
503
504     while (TRUE) {
505         message = va_arg(args, char *);
506
507         if (!message) {
508             break;
509         }
510         value = va_arg(args, int);
511
512         gtk_dialog_add_button(GTK_DIALOG(conf_note), message, value);
513     }
514
515     va_end(args);
516
517     return conf_note;
518 }
519
520
521 /**
522  * hildon_note_new_confirmation:
523  * @parent: the parent window. The X window ID of the parent window
524  *   has to be the same as the X window ID of the application. This is
525  *   important so that the window manager could handle the windows
526  *   correctly. In GTK the X window ID can be checked using
527  *   GDK_WINDOW_XID(GTK_WIDGET(parent)->window).
528  * @description: the message to confirm
529  * 
530  * Create a new confirmation note. Confirmation note has text (description)
531  * that you specify, two buttons and a default confirmation stock icon.
532  *
533  * Returns: a #GtkWidget pointer of the note
534  */
535 GtkWidget *hildon_note_new_confirmation(GtkWindow * parent,
536                                         const gchar * description)
537 {
538     return hildon_note_new_confirmation_with_icon_name
539         (parent, description, HILDON_NOTE_CONFIRMATION_ICON);
540 }
541
542 /**
543  * hildon_note_new_confirmation_with_icon_name:
544  * @parent: the parent window. The X window ID of the parent window
545  *   has to be the same as the X window ID of the application. This is
546  *   important so that the window manager could handle the windows
547  *   correctly. In GTK the X window ID can be checked using
548  *   GDK_WINDOW_XID(GTK_WIDGET(parent)->window).
549  * @description: the message to confirm
550  * @icon_name: icon to be displayed. If NULL, default icon is used.
551  * 
552  * Create a new confirmation note. Confirmation note has text(description) 
553  * that you specify, two buttons and an icon.
554  *
555  * Returns: a #GtkWidget pointer of the note
556  */
557 GtkWidget *hildon_note_new_confirmation_with_icon_name(GtkWindow * parent,
558                                                         const gchar *
559                                                         description,
560                                                         const gchar *
561                                                         icon_name)
562 {
563     GtkWidget *dialog = NULL;
564
565     g_return_val_if_fail(parent == NULL || GTK_IS_WINDOW(parent), NULL);
566
567     dialog = g_object_new(HILDON_TYPE_NOTE,
568                                      "note_type",
569                                      HILDON_NOTE_CONFIRMATION_TYPE,
570                                      "description", description, "icon",
571                                      icon_name, NULL);
572     if (parent != NULL)
573         gtk_window_set_transient_for(GTK_WINDOW(dialog), parent);
574
575     return dialog;
576 }
577
578 /**
579  * hildon_note_new_information:
580  * @parent: the parent window. The X window ID of the parent window
581  *   has to be the same as the X window ID of the application. This is
582  *   important so that the window manager could handle the windows
583  *   correctly. In GTK the X window ID can be checked using
584  *   GDK_WINDOW_XID(GTK_WIDGET(parent)->window).
585  * @description: the message to confirm
586  * 
587  * Create a new information note. Information note has a text(description) 
588  * that you specify, an OK button and an icon.
589  * 
590  * Returns: a #GtkWidget pointer of the note
591  */
592 GtkWidget *hildon_note_new_information(GtkWindow * parent,
593                                        const gchar * description)
594 {
595     return hildon_note_new_information_with_icon_name
596         (parent, description, HILDON_NOTE_INFORMATION_ICON);
597 }
598
599 /**
600  * hildon_note_new_information_with_icon_name:
601  * @parent: the parent window. The X window ID of the parent window
602  *   has to be the same as the X window ID of the application. This is
603  *   important so that the window manager could handle the windows
604  *   correctly. In GTK the X window ID can be checked using
605  *   GDK_WINDOW_XID(GTK_WIDGET(parent)->window).
606  * @description: the message to confirm
607  * @icon_name: icon to be displayed. If NULL, default icon is used.
608  * 
609  * Create a new information note. Information note has text(description) 
610  * that you specify, an OK button and an icon.
611  * 
612  * Returns: a #GtkWidget pointer of the note
613  */
614 GtkWidget *hildon_note_new_information_with_icon_name(GtkWindow * parent,
615                                                        const gchar *
616                                                        description,
617                                                        const gchar *
618                                                        icon_name)
619 {
620     GtkWidget *dialog = NULL;
621
622     g_return_val_if_fail(parent == NULL || GTK_IS_WINDOW(parent), NULL);
623
624     dialog = g_object_new(HILDON_TYPE_NOTE,
625                                      "note_type",
626                                      HILDON_NOTE_INFORMATION_THEME_TYPE,
627                                      "description", description,
628                                      "icon", icon_name, NULL);
629     if (parent != NULL)
630         gtk_window_set_transient_for(GTK_WINDOW(dialog), parent);
631
632     return dialog;
633 }
634
635 /**
636  * hildon_note_new_cancel_with_progress_bar:
637  * @parent: the parent window. The X window ID of the parent window
638  *   has to be the same as the X window ID of the application. This is
639  *   important so that the window manager could handle the windows
640  *   correctly. In GTK the X window ID can be checked using
641  *   GDK_WINDOW_XID(GTK_WIDGET(parent)->window).
642  * @description: the action to cancel
643  * @progressbar: a pointer to #GtkProgressBar to be filled with the
644  *   progressbar assigned to this note. Use this to set the fraction of
645  *   progressbar done. This parameter can be %NULL as well, in which
646  *   case plain text cancel note appears.
647  *
648  * Create a new cancel note with a progress bar. Cancel note has 
649  * text(description) that you specify, a Cancel button and a progress bar.
650  *
651  * Returns: a #GtkDialog. Use this to get rid of this note when you
652  *   no longer need it.
653  */
654 GtkWidget *hildon_note_new_cancel_with_progress_bar(GtkWindow * parent,
655                                                     const gchar *
656                                                     description,
657                                                     GtkProgressBar *
658                                                     progressbar)
659 {
660     GtkWidget *dialog = NULL;
661
662     g_return_val_if_fail(parent == NULL || GTK_IS_WINDOW(parent), NULL);
663
664     dialog = g_object_new(HILDON_TYPE_NOTE,
665                                      "note_type",
666                                      HILDON_NOTE_PROGRESSBAR_TYPE,
667                                      "description", description,
668                                      "progressbar",
669                                      progressbar, NULL);
670     if (parent != NULL)
671         gtk_window_set_transient_for(GTK_WINDOW(dialog), parent);
672
673     return dialog;
674 }
675
676
677 /**
678  * hildon_note_set_button_text:
679  * @note: a #HildonNote
680  * @text: sets the button text and if there is two buttons in dialog, 
681  *   the button texts will be &lt;text&gt;, "Cancel".  
682  *
683  * Sets the button text to be used by the hildon_note widget.
684  */
685 void hildon_note_set_button_text(HildonNote * note, const gchar * text)
686 {
687     HildonNotePrivate *priv;
688
689     g_return_if_fail(HILDON_IS_NOTE(note));
690
691     priv = HILDON_NOTE_GET_PRIVATE(HILDON_NOTE(note));
692     if (priv->okButton) {
693         gtk_button_set_label(GTK_BUTTON(priv->okButton), text);
694         gtk_button_set_label(GTK_BUTTON(priv->cancelButton),
695                              _("ecdg_bd_confirmation_note_cancel"));
696     } else {
697         gtk_button_set_label(GTK_BUTTON(priv->cancelButton), text);
698     }
699 }
700
701 /**
702  * hildon_note_set_button_texts:
703  * @note: a #HildonNote
704  * @textOk: the new text of the default OK button
705  * @textCancel: the new text of the default cancel button 
706  *
707  * Sets the button texts to be used by this hildon_note widget.
708  */
709 void hildon_note_set_button_texts(HildonNote * note,
710                                   const gchar * textOk,
711                                   const gchar * textCancel)
712 {
713     HildonNotePrivate *priv;
714
715     g_return_if_fail(HILDON_IS_NOTE(note));
716
717     priv = HILDON_NOTE_GET_PRIVATE(HILDON_NOTE(note));
718     if (priv->okButton) {
719       gtk_button_set_label(GTK_BUTTON(priv->okButton), textOk);
720       gtk_button_set_label(GTK_BUTTON(priv->cancelButton),
721                            textCancel);
722     } else {
723       gtk_button_set_label(GTK_BUTTON(priv->cancelButton), textCancel);
724     }
725 }
726
727 /* We play a system sound when the note comes visible */
728 static gboolean
729 sound_handling(GtkWidget * widget, GdkEventExpose *event, gpointer data)
730 {
731   HildonNotePrivate *priv = HILDON_NOTE_GET_PRIVATE(widget);
732   g_signal_handler_disconnect(widget, priv->sound_signal_handler);
733   priv->sound_signal_handler = 0;
734
735   switch (priv->note_n)
736   {
737     case HILDON_NOTE_INFORMATION_TYPE:
738     case HILDON_NOTE_INFORMATION_THEME_TYPE:
739       hildon_play_system_sound(INFORMATION_SOUND_PATH);
740       break;
741     case HILDON_NOTE_CONFIRMATION_TYPE:
742     case HILDON_NOTE_CONFIRMATION_BUTTON_TYPE:
743       hildon_play_system_sound(CONFIRMATION_SOUND_PATH);
744       break;
745     default:
746       break;
747   };
748
749   return FALSE;
750 }