2 * This file is a part of hildon
4 * Copyright (C) 2005, 2006 Nokia Corporation, all rights reserved.
6 * Contact: Rodrigo Novo <rodrigo.novo@nokia.com>
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 (at your option) any later version.
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.
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
27 * @short_description: A widget to ask confirmation from the user.
29 * #HildonNote is a convenient way to prompt users for a small amount of
30 * input. A simple note contains an information text and, in case of
31 * confirmation notes, it shows buttons to confirm or cancel. It also can
32 * include a progress bar.
34 * This widget provides convenient functions to create either
35 * information notes, confirmation notes or cancel notes, which are
36 * useful to show the progress of a requested task allowing the user
39 * To create information notes you can use
40 * hildon_note_new_information(). hildon_note_new_confirmation()
41 * creates a note with a text and two buttons to confirm or
42 * cancel. Note that it is possible to create a confirmation note with
43 * customized buttons by using
44 * hildon_note_new_confirmation_add_buttons().
46 * To create a note with a text, a progress bar and cancel button,
47 * hildon_note_new_cancel_with_progress_bar() can be used.
50 * <title>HildonNote example</title>
54 * show_confirmation_note (GtkWindow *parent)
58 * note = hildon_note_new_confirmation (parent, "Confirmation message...");
60 * retcode = gtk_dialog_run (GTK_DIALOG (note));
61 * gtk_widget_destroy (note);
63 * if (retcode == GTK_RESPONSE_OK) {
64 * g_debug ("User pressed 'OK' button'");
67 * g_debug ("User pressed 'Cancel' button");
83 #include <X11/Xatom.h>
86 #undef HILDON_DISABLE_DEPRECATED
88 #include "hildon-note.h"
89 #include "hildon-defines.h"
90 #include "hildon-sound.h"
91 #include "hildon-banner.h"
92 #include "hildon-enum-types.h"
93 #include "hildon-note-private.h"
95 #define HILDON_INFORMATION_NOTE_MIN_HEIGHT 140
97 #define HILDON_INFORMATION_NOTE_MARGIN 100
99 #define CONFIRMATION_SOUND_PATH \
100 "/usr/share/sounds/ui-confirmation_note.wav"
102 #define INFORMATION_SOUND_PATH \
103 "/usr/share/sounds/ui-information_note.wav"
105 #define _(String) dgettext("hildon-libs", String)
108 hildon_note_class_init (HildonNoteClass *class);
111 hildon_note_init (HildonNote *dialog);
114 hildon_note_rebuild (HildonNote *note);
117 hildon_note_rename (HildonNote *note);
120 hildon_note_finalize (GObject *obj_self);
123 hildon_note_realize (GtkWidget *widget);
126 hildon_note_unrealize (GtkWidget *widget);
129 label_size_request (GtkWidget *label,
134 hildon_note_set_property (GObject *object,
140 hildon_note_get_property (GObject *object,
146 on_show_cb (GtkWidget *widget,
149 sound_handling (gpointer data);
152 unpack_widget (GtkWidget *widget);
157 PROP_HILDON_NOTE_TYPE,
158 PROP_HILDON_NOTE_DESCRIPTION,
159 PROP_HILDON_NOTE_ICON,
160 PROP_HILDON_NOTE_PROGRESSBAR,
161 PROP_HILDON_NOTE_STOCK_ICON
164 static GtkDialogClass* parent_class;
167 event_box_press_event (GtkEventBox *event_box,
168 GdkEventButton *event,
171 HildonNotePrivate *priv = HILDON_NOTE_GET_PRIVATE (note);
173 if (priv->note_n == HILDON_NOTE_TYPE_INFORMATION ||
174 priv->note_n == HILDON_NOTE_TYPE_INFORMATION_THEME) {
175 gtk_dialog_response (note, GTK_RESPONSE_DELETE_EVENT);
183 hildon_note_set_property (GObject *object,
188 HildonNote *note = HILDON_NOTE (object);
189 HildonNotePrivate *priv;
192 priv = HILDON_NOTE_GET_PRIVATE (note);
197 case PROP_HILDON_NOTE_TYPE:
198 priv->note_n = g_value_get_enum (value);
199 hildon_note_rename (note);
200 hildon_note_rebuild (note);
203 case PROP_HILDON_NOTE_DESCRIPTION:
204 if (priv->original_description)
205 g_free (priv->original_description);
206 priv->original_description = g_value_dup_string (value);
208 gtk_label_set_text (GTK_LABEL (priv->label), priv->original_description);
209 /* FIXME Is the "original_description" used anywhere? */
213 case PROP_HILDON_NOTE_ICON:
217 priv->icon = g_value_dup_string (value);
220 case PROP_HILDON_NOTE_STOCK_ICON:
221 if (priv->stock_icon) {
222 g_free (priv->stock_icon);
224 priv->stock_icon = g_value_dup_string (value);
227 case PROP_HILDON_NOTE_PROGRESSBAR:
228 widget = g_value_get_object (value);
229 if (widget != priv->progressbar)
231 if (priv->progressbar)
232 g_object_unref (priv->progressbar);
234 priv->progressbar = widget;
238 g_object_ref (widget);
239 gtk_object_sink (GTK_OBJECT (widget));
242 hildon_note_rebuild (note);
247 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
253 hildon_note_get_property (GObject *object,
258 HildonNote *note = HILDON_NOTE (object);
259 HildonNotePrivate *priv;
261 priv = HILDON_NOTE_GET_PRIVATE (note);
265 case PROP_HILDON_NOTE_TYPE:
266 g_value_set_enum (value, priv->note_n);
269 case PROP_HILDON_NOTE_DESCRIPTION:
270 g_value_set_string (value, priv->original_description);
273 case PROP_HILDON_NOTE_ICON:
274 g_value_set_string (value, priv->icon);
277 case PROP_HILDON_NOTE_STOCK_ICON:
278 g_value_set_string (value, priv->stock_icon);
281 case PROP_HILDON_NOTE_PROGRESSBAR:
282 g_value_set_object (value, priv->progressbar);
286 G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
292 * hildon_note_get_type:
294 * Returns GType for HildonNote.
296 * Returns: HildonNote type
299 hildon_note_get_type (void)
301 static GType dialog_type = 0;
304 static const GTypeInfo dialog_info = {
305 sizeof(HildonNoteClass),
306 NULL, /* base_init */
307 NULL, /* base_finalize */
308 (GClassInitFunc) hildon_note_class_init,
309 NULL, /* class_finalize */
310 NULL, /* class_data */
313 (GInstanceInitFunc) hildon_note_init
315 dialog_type = g_type_register_static (GTK_TYPE_DIALOG,
323 hildon_note_class_init (HildonNoteClass *class)
325 GObjectClass *object_class = G_OBJECT_CLASS (class);
326 GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (class);
328 /* set the global parent_class */
329 parent_class = g_type_class_peek_parent (class);
331 g_type_class_add_private (class, sizeof (HildonNotePrivate));
333 object_class->finalize = hildon_note_finalize;
334 object_class->set_property = hildon_note_set_property;
335 object_class->get_property = hildon_note_get_property;
336 widget_class->realize = hildon_note_realize;
337 widget_class->unrealize = hildon_note_unrealize;
339 g_object_class_install_property (object_class,
340 PROP_HILDON_NOTE_TYPE,
341 g_param_spec_enum ("note-type",
343 "The type of the note dialog",
344 hildon_note_type_get_type (),
345 HILDON_NOTE_TYPE_CONFIRMATION,
346 G_PARAM_READWRITE | G_PARAM_CONSTRUCT));
349 * HildonNote:description:
351 * Description for the note.
353 g_object_class_install_property (object_class,
354 PROP_HILDON_NOTE_DESCRIPTION,
355 g_param_spec_string ("description",
357 "The text that appears in the note dialog",
366 * Deprecated: Since 2.2
368 g_object_class_install_property (object_class,
369 PROP_HILDON_NOTE_ICON,
370 g_param_spec_string ("icon",
372 "The name of the icon that appears in the note dialog",
377 * HildonNote:stock-icon:
379 * Stock icon name for the note.
381 * Deprecated: Since 2.2
383 g_object_class_install_property (object_class,
384 PROP_HILDON_NOTE_STOCK_ICON,
385 g_param_spec_string ("stock-icon",
387 "The stock name of the icon that appears in the note dialog",
392 * HildonNote:progressbar:
394 * Progressbar for the note (if any).
396 g_object_class_install_property (object_class,
397 PROP_HILDON_NOTE_PROGRESSBAR,
398 g_param_spec_object ("progressbar",
399 "Progressbar widget",
400 "The progressbar that appears in the note dialog",
401 GTK_TYPE_PROGRESS_BAR,
406 hildon_note_init (HildonNote *dialog)
408 HildonNotePrivate *priv = HILDON_NOTE_GET_PRIVATE (dialog);
411 priv->label = gtk_label_new (NULL);
412 gtk_label_set_line_wrap (GTK_LABEL (priv->label), TRUE);
413 gtk_label_set_justify (GTK_LABEL (priv->label), GTK_JUSTIFY_LEFT);
415 priv->event_box = gtk_event_box_new ();
417 priv->stock_icon = NULL;
418 priv->idle_handler = 0;
420 gtk_event_box_set_visible_window (GTK_EVENT_BOX (priv->event_box), FALSE);
421 gtk_event_box_set_above_child (GTK_EVENT_BOX (priv->event_box), TRUE);
422 g_signal_connect (priv->event_box, "button-press-event",
423 G_CALLBACK (event_box_press_event), dialog);
425 /* Because ESD is synchronous, we wish to play sound after the
426 note is already on screen to avoid blocking its appearance */
427 g_signal_connect (GTK_WIDGET (dialog), "show",
428 G_CALLBACK (on_show_cb), NULL);
430 /* Acquire real references to our internal children, since
431 they are not nessecarily packed into container in each
433 g_object_ref_sink (priv->event_box);
434 g_object_ref_sink (priv->label);
436 gtk_dialog_set_has_separator (GTK_DIALOG (dialog), FALSE);
437 gtk_window_set_modal (GTK_WINDOW (dialog), TRUE);
439 /* We use special hint to turn the note into information notification. */
440 gtk_window_set_type_hint (GTK_WINDOW (dialog), GDK_WINDOW_TYPE_HINT_NOTIFICATION);
445 hildon_note_finalize (GObject *obj_self)
447 HildonNotePrivate *priv = HILDON_NOTE_GET_PRIVATE (obj_self);
450 /* FIXME Some of this stuff should be moved to dispose */
452 /* Free internal data */
454 g_object_unref (priv->event_box);
457 g_object_unref (priv->label);
463 if (priv->stock_icon) {
464 g_free (priv->stock_icon);
465 priv->stock_icon = NULL;
467 if (priv->idle_handler) {
468 g_source_remove (priv->idle_handler);
469 priv->idle_handler = 0;
472 if (priv->progressbar)
473 g_object_unref (priv->progressbar);
475 if (priv->original_description)
476 g_free (priv->original_description);
478 G_OBJECT_CLASS (parent_class)->finalize (obj_self);
482 label_size_request (GtkWidget *label,
486 gint note_height = MAX (HILDON_INFORMATION_NOTE_MIN_HEIGHT, req->height);
487 g_object_set (note, "height-request", note_height, NULL);
491 resize_button (GtkWidget *button, gpointer *data)
493 gint width = GPOINTER_TO_INT (data);
494 g_object_set (button, "width-request", width, NULL);
498 hildon_note_orientation_update (HildonNote *note, GdkScreen *screen)
500 GtkDialog *dialog = GTK_DIALOG (note);
501 HildonNotePrivate* priv = HILDON_NOTE_GET_PRIVATE (note);
503 gint button_width, padding;
504 gboolean portrait = gdk_screen_get_width (screen) < gdk_screen_get_height (screen);
506 g_object_ref (dialog->action_area);
507 unpack_widget (dialog->action_area);
510 parent = dialog->vbox;
511 button_width = gdk_screen_get_width (screen) - HILDON_MARGIN_DOUBLE * 2;
512 padding = HILDON_MARGIN_DOUBLE;
514 parent = gtk_widget_get_parent (dialog->vbox);
515 button_width = priv->button_width;
519 gtk_box_pack_end (GTK_BOX (parent), dialog->action_area,
521 gtk_box_reorder_child (GTK_BOX (parent), dialog->action_area, 0);
522 gtk_container_foreach (GTK_CONTAINER (dialog->action_area),
523 (GtkCallback) resize_button,
524 GINT_TO_POINTER (button_width));
525 g_object_unref (dialog->action_area);
526 gtk_container_child_set (GTK_CONTAINER (priv->box), priv->label,
527 "padding", padding, NULL);
531 screen_size_changed (GdkScreen *screen,
534 HildonNotePrivate *priv = HILDON_NOTE_GET_PRIVATE (note);
535 gint screen_width = gdk_screen_get_width (screen);
536 gint text_width = screen_width - HILDON_INFORMATION_NOTE_MARGIN * 2;
538 if (priv->note_n == HILDON_NOTE_TYPE_INFORMATION ||
539 priv->note_n == HILDON_NOTE_TYPE_INFORMATION_THEME) {
540 g_object_set (note, "width-request", screen_width, NULL);
541 g_object_set (priv->label, "width-request", text_width, NULL);
544 } else if (priv->note_n == HILDON_NOTE_TYPE_CONFIRMATION) {
545 hildon_note_orientation_update (HILDON_NOTE (note), screen);
550 hildon_note_realize (GtkWidget *widget)
553 gboolean is_info_note = FALSE;
555 const gchar *notification_type;
556 HildonNotePrivate *priv = HILDON_NOTE_GET_PRIVATE (widget);
559 /* Make widget->window accessible */
560 GTK_WIDGET_CLASS (parent_class)->realize (widget);
562 /* Border only, no titlebar */
563 gdk_window_set_decorations (widget->window, GDK_DECOR_BORDER);
565 /* Set the _HILDON_NOTIFICATION_TYPE property so Matchbox places the window correctly */
566 display = gdk_drawable_get_display (widget->window);
567 atom = gdk_x11_get_xatom_by_name_for_display (display, "_HILDON_NOTIFICATION_TYPE");
569 if (priv->note_n == HILDON_NOTE_TYPE_INFORMATION ||
570 priv->note_n == HILDON_NOTE_TYPE_INFORMATION_THEME) {
571 notification_type = "_HILDON_NOTIFICATION_TYPE_INFO";
574 notification_type = "_HILDON_NOTIFICATION_TYPE_CONFIRMATION";
577 XChangeProperty (GDK_WINDOW_XDISPLAY (widget->window), GDK_WINDOW_XID (widget->window),
578 atom, XA_STRING, 8, PropModeReplace, (guchar *) notification_type,
579 strlen (notification_type));
582 g_signal_connect (priv->label, "size-request", G_CALLBACK (label_size_request), widget);
585 GdkScreen *screen = gtk_widget_get_screen (widget);
586 g_signal_connect (screen, "size-changed", G_CALLBACK (screen_size_changed), widget);
587 screen_size_changed (screen, widget);
591 hildon_note_unrealize (GtkWidget *widget)
593 HildonNotePrivate *priv = HILDON_NOTE_GET_PRIVATE (widget);
594 GdkScreen *screen = gtk_widget_get_screen (widget);
596 g_signal_handlers_disconnect_by_func (screen, G_CALLBACK (screen_size_changed), widget);
597 g_signal_handlers_disconnect_by_func (priv->label, G_CALLBACK (label_size_request), widget);
599 GTK_WIDGET_CLASS (parent_class)->unrealize (widget);
603 /* Helper function for removing a widget from it's container.
604 we own a separate reference to each object we try to unpack,
605 so extra referencing is not needed. */
607 unpack_widget (GtkWidget *widget)
609 g_assert (widget == NULL || GTK_IS_WIDGET (widget));
611 if (widget && widget->parent)
612 gtk_container_remove (GTK_CONTAINER (widget->parent), widget);
616 Name the widget and text label based on the note type. This is used
617 by the theme to give proper backgrounds depending on the note type.
620 hildon_note_rename (HildonNote *note)
623 GEnumClass *enum_class;
626 HildonNotePrivate *priv = HILDON_NOTE_GET_PRIVATE (note);
628 enum_class = g_type_class_ref (HILDON_TYPE_NOTE_TYPE);
629 value = g_enum_get_value (enum_class, priv->note_n);
631 name = g_strconcat ("HildonNote-", value->value_nick, NULL);
632 gtk_widget_set_name (GTK_WIDGET (note), name);
635 name = g_strconcat ("HildonNoteLabel-", value->value_nick, NULL);
636 gtk_widget_set_name (priv->label, name);
639 g_type_class_unref (enum_class);
643 hildon_note_rebuild (HildonNote *note)
646 HildonNotePrivate *priv;
647 gboolean is_info_note = FALSE;
649 g_assert (HILDON_IS_NOTE (note));
651 priv = HILDON_NOTE_GET_PRIVATE (note);
654 dialog = GTK_DIALOG (note);
656 /* Reuse exiting content widgets for new layout */
657 unpack_widget (priv->label);
658 unpack_widget (priv->progressbar);
659 unpack_widget (priv->event_box);
661 /* Destroy old layout and buttons */
663 gtk_widget_destroy (priv->box);
666 if (priv->okButton) {
667 gtk_widget_destroy (priv->okButton);
668 priv->okButton = NULL;
670 if (priv->cancelButton) {
671 gtk_widget_destroy (priv->cancelButton);
672 priv->cancelButton = NULL;
675 /* Add needed buttons and images for each note type */
676 switch (priv->note_n)
678 case HILDON_NOTE_TYPE_CONFIRMATION:
679 priv->okButton = gtk_dialog_add_button (dialog,
680 _("wdgt_bd_yes"), GTK_RESPONSE_OK);
681 priv->cancelButton = gtk_dialog_add_button (dialog,
682 _("wdgt_bd_no"), GTK_RESPONSE_CANCEL);
683 gtk_widget_show (priv->cancelButton);
684 g_object_get (priv->okButton, "width-request",
685 &priv->button_width, NULL);
686 gtk_widget_set_no_show_all (priv->cancelButton, FALSE);
689 case HILDON_NOTE_TYPE_PROGRESSBAR:
690 priv->cancelButton = gtk_dialog_add_button (dialog,
691 _("wdgt_bd_stop"), GTK_RESPONSE_CANCEL);
692 gtk_widget_show (priv->cancelButton);
693 gtk_widget_set_no_show_all (priv->cancelButton, FALSE);
696 case HILDON_NOTE_TYPE_INFORMATION_THEME:
697 case HILDON_NOTE_TYPE_INFORMATION:
701 case HILDON_NOTE_TYPE_CONFIRMATION_BUTTON:
706 /* Don't display the action area if this is just an information
707 * note. This prevents text from being slightly aligned to the
711 gtk_widget_hide (dialog->action_area);
713 gtk_widget_show (dialog->action_area);
715 gtk_widget_set_no_show_all (dialog->action_area, is_info_note);
717 /* Pack label vertically. Spacing is only necessary for the progressbar note. */
718 priv->box = gtk_vbox_new (FALSE, priv->progressbar ? HILDON_MARGIN_DOUBLE : 0);
719 gtk_container_add (GTK_CONTAINER (priv->event_box), priv->box);
720 gtk_box_pack_start (GTK_BOX (priv->box), priv->label, TRUE, TRUE, 0);
722 if (priv->progressbar)
723 gtk_box_pack_start (GTK_BOX (priv->box), priv->progressbar, FALSE, FALSE, 0);
725 gtk_container_add (GTK_CONTAINER (dialog->vbox), priv->event_box);
727 gtk_widget_show_all (priv->event_box);
731 * hildon_note_new_confirmation_add_buttons:
732 * @parent: the parent window. The X window ID of the parent window
733 * has to be the same as the X window ID of the application. This is
734 * important so that the window manager could handle the windows
736 * In GTK the X window ID can be checked using
737 * GDK_WINDOW_XID(GTK_WIDGET(parent)->window).
738 * @description: the message to confirm
739 * @Varargs: arguments pairs for new buttons(label and return value).
740 * Terminate the list with %NULL value.
742 * Create a new confirmation note with custom buttons. Confirmation
743 * note has a text and any number of buttons. It's important to note
744 * that even though the name of the function might suggest, the
745 * default ok/cancel buttons are not appended but you have to provide
746 * all of the buttons.
748 * FIXME: This doc seems to be wrong, the two buttons aren't added so
749 * it would only contain the "additional" buttons? However, changing
750 * this would break those applications that rely on current behaviour.
752 * Returns: A #GtkWidget pointer of the note
755 hildon_note_new_confirmation_add_buttons (GtkWindow *parent,
756 const gchar *description,
764 g_return_val_if_fail (description != NULL, NULL);
766 GtkWidget *conf_note =
767 g_object_new (HILDON_TYPE_NOTE,
768 "note-type", HILDON_NOTE_TYPE_CONFIRMATION_BUTTON,
769 "description", description,
773 gtk_window_set_transient_for (GTK_WINDOW (conf_note), parent);
775 /* Add the buttons from varargs */
776 va_start(args, description);
779 message = va_arg (args, char *);
784 value = va_arg (args, int);
786 button = gtk_dialog_add_button (GTK_DIALOG (conf_note), message, value);
787 /* maemo-gtk is going to set the "no-show-all" property all
788 cancel/close-like buttons to TRUE, so that they are not shown. On
789 the other hand, this confirmation note with custom buttons should
790 not obey this rule, so we need to make sure they are shown. */
791 gtk_widget_show (button);
792 gtk_widget_set_no_show_all (button, FALSE);
802 * hildon_note_new_confirmation:
803 * @parent: the parent window. The X window ID of the parent window
804 * has to be the same as the X window ID of the application. This is
805 * important so that the window manager could handle the windows
806 * correctly. In GTK the X window ID can be checked using
807 * GDK_WINDOW_XID(GTK_WIDGET(parent)->window).
808 * @description: the message to confirm
810 * Create a new confirmation note. Confirmation note has a text (description)
811 * that you specify and two buttons.
813 * Returns: a #GtkWidget pointer of the note
816 hildon_note_new_confirmation (GtkWindow *parent,
817 const gchar *description)
819 GtkWidget *dialog = NULL;
821 g_return_val_if_fail (description != NULL, NULL);
823 dialog = g_object_new (HILDON_TYPE_NOTE,
825 HILDON_NOTE_TYPE_CONFIRMATION,
826 "description", description, NULL);
829 gtk_window_set_transient_for (GTK_WINDOW (dialog), parent);
835 * hildon_note_new_confirmation_with_icon_name:
836 * @parent: the parent window. The X window ID of the parent window
837 * has to be the same as the X window ID of the application. This is
838 * important so that the window manager could handle the windows
839 * correctly. In GTK the X window ID can be checked using
840 * GDK_WINDOW_XID(GTK_WIDGET(parent)->window).
841 * @description: the message to confirm
842 * @icon_name: icon to be displayed. If NULL, default icon is used.
844 * Create a new confirmation note. Confirmation note has a text (description)
845 * that you specify and two buttons.
847 * Deprecated: Since 2.2, icons are not shown in confirmation notes. Icons set
848 * with this function will be ignored. Use hildon_note_new_confirmation() instead.
850 * Returns: a #GtkWidget pointer of the note
853 hildon_note_new_confirmation_with_icon_name (GtkWindow *parent,
854 const gchar *description,
855 const gchar *icon_name)
859 dialog = hildon_note_new_confirmation (parent, description);
860 g_object_set (dialog, "icon", icon_name, NULL);
866 * hildon_note_new_information:
867 * @parent: the parent window. The X window ID of the parent window
868 * has to be the same as the X window ID of the application. This is
869 * important so that the window manager could handle the windows
870 * correctly. In GTK the X window ID can be checked using
871 * GDK_WINDOW_XID(GTK_WIDGET(parent)->window).
872 * @description: the message to confirm
874 * Create a new information note. Information note has a text (description)
875 * that you specify and an OK button.
877 * Returns: a #GtkWidget pointer of the note
880 hildon_note_new_information (GtkWindow *parent,
881 const gchar *description)
883 GtkWidget *dialog = NULL;
885 g_return_val_if_fail (description != NULL, NULL);
887 dialog = g_object_new (HILDON_TYPE_NOTE,
889 HILDON_NOTE_TYPE_INFORMATION_THEME,
890 "description", description, NULL);
893 gtk_window_set_transient_for (GTK_WINDOW (dialog), parent);
899 * hildon_note_new_information_with_icon_name:
900 * @parent: the parent window. The X window ID of the parent window
901 * has to be the same as the X window ID of the application. This is
902 * important so that the window manager could handle the windows
903 * correctly. In GTK the X window ID can be checked using
904 * GDK_WINDOW_XID(GTK_WIDGET(parent)->window).
905 * @description: the message to confirm
906 * @icon_name: icon to be displayed. If NULL, default icon is used.
908 * Create a new information note. Information note has text(description)
909 * that you specify, an OK button and an icon.
911 * Deprecated: Since 2.2, icons are not shown in confirmation notes. Icons set
912 * with this function will be ignored. Use hildon_note_new_information() instead.
914 * Returns: a #GtkWidget pointer of the note
917 hildon_note_new_information_with_icon_name (GtkWindow * parent,
918 const gchar *description,
919 const gchar *icon_name)
923 dialog = hildon_note_new_information (parent, description);
924 g_object_set (dialog, "icon", icon_name, NULL);
929 /* FIXME This documentation string LIES! */
932 * hildon_note_new_cancel_with_progress_bar:
933 * @parent: the parent window. The X window ID of the parent window
934 * has to be the same as the X window ID of the application. This is
935 * important so that the window manager could handle the windows
936 * correctly. In GTK the X window ID can be checked using
937 * GDK_WINDOW_XID(GTK_WIDGET(parent)->window).
938 * @description: the action to cancel
939 * @progressbar: a pointer to #GtkProgressBar to be filled with the
940 * progressbar assigned to this note. Use this to set the fraction of
941 * progressbar done. This parameter can be %NULL as well, in which
942 * case plain text cancel note appears.
944 * Create a new cancel note with a progress bar. Cancel note has
945 * text(description) that you specify, a Cancel button and a progress bar.
947 * Returns: a #GtkDialog. Use this to get rid of this note when you
951 hildon_note_new_cancel_with_progress_bar (GtkWindow *parent,
952 const gchar *description,
953 GtkProgressBar *progressbar)
955 GtkWidget *dialog = NULL;
957 g_return_val_if_fail (description != NULL, NULL);
959 dialog = g_object_new (HILDON_TYPE_NOTE,
961 HILDON_NOTE_TYPE_PROGRESSBAR,
962 "description", description,
967 gtk_window_set_transient_for (GTK_WINDOW (dialog), parent);
974 * hildon_note_set_button_text:
975 * @note: a #HildonNote
976 * @text: sets the button text and if there is two buttons in dialog,
977 * the button texts will be <text>, "Cancel".
979 * Sets the button text to be used by the hildon_note widget.
982 hildon_note_set_button_text (HildonNote *note,
985 HildonNotePrivate *priv;
987 g_return_if_fail (HILDON_IS_NOTE (note));
989 priv = HILDON_NOTE_GET_PRIVATE (HILDON_NOTE (note));
992 if (priv->okButton) {
993 gtk_button_set_label (GTK_BUTTON (priv->okButton), text);
994 gtk_button_set_label (GTK_BUTTON (priv->cancelButton),
997 gtk_button_set_label (GTK_BUTTON (priv->cancelButton), text);
1002 * hildon_note_set_button_texts:
1003 * @note: a #HildonNote
1004 * @text_ok: the new text of the default OK button
1005 * @text_cancel: the new text of the default cancel button
1007 * Sets the button texts to be used by this hildon_note widget.
1010 hildon_note_set_button_texts (HildonNote *note,
1011 const gchar *text_ok,
1012 const gchar *text_cancel)
1014 HildonNotePrivate *priv;
1016 g_return_if_fail (HILDON_IS_NOTE (note));
1018 priv = HILDON_NOTE_GET_PRIVATE (HILDON_NOTE (note));
1021 if (priv->okButton) {
1022 gtk_button_set_label (GTK_BUTTON (priv->okButton), text_ok);
1023 gtk_button_set_label (GTK_BUTTON (priv->cancelButton), text_cancel);
1025 gtk_button_set_label (GTK_BUTTON (priv->cancelButton), text_cancel);
1030 on_show_cb (GtkWidget *widget,
1033 HildonNotePrivate *priv;
1035 priv = HILDON_NOTE_GET_PRIVATE (widget);
1036 priv->idle_handler = g_idle_add (sound_handling, widget);
1039 /* We play a system sound when the note comes visible */
1041 sound_handling (gpointer data)
1043 HildonNotePrivate *priv = HILDON_NOTE_GET_PRIVATE (data);
1046 switch (priv->note_n)
1048 case HILDON_NOTE_TYPE_INFORMATION:
1049 case HILDON_NOTE_TYPE_INFORMATION_THEME:
1050 hildon_play_system_sound (INFORMATION_SOUND_PATH);
1053 case HILDON_NOTE_TYPE_CONFIRMATION:
1054 case HILDON_NOTE_TYPE_CONFIRMATION_BUTTON:
1055 hildon_play_system_sound (CONFIRMATION_SOUND_PATH);
1062 priv->idle_handler = 0;