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 can also
32 * include a #GtkProgressBar.
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-gtk.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_set_padding (HildonNote *note);
120 hildon_note_rename (HildonNote *note);
123 hildon_note_finalize (GObject *obj_self);
126 hildon_note_realize (GtkWidget *widget);
129 hildon_note_unrealize (GtkWidget *widget);
132 hildon_note_size_request (GtkWidget *note,
133 GtkRequisition *req);
136 label_size_request (GtkWidget *label,
141 hildon_note_set_property (GObject *object,
147 hildon_note_get_property (GObject *object,
153 on_show_cb (GtkWidget *widget,
156 sound_handling (gpointer data);
159 unpack_widget (GtkWidget *widget);
164 PROP_HILDON_NOTE_TYPE,
165 PROP_HILDON_NOTE_DESCRIPTION,
166 PROP_HILDON_NOTE_ICON,
167 PROP_HILDON_NOTE_PROGRESSBAR,
168 PROP_HILDON_NOTE_STOCK_ICON
171 static GtkDialogClass* parent_class;
174 event_box_press_event (GtkEventBox *event_box,
175 GdkEventButton *event,
178 HildonNotePrivate *priv = HILDON_NOTE_GET_PRIVATE (note);
180 if (priv->note_n == HILDON_NOTE_TYPE_INFORMATION ||
181 priv->note_n == HILDON_NOTE_TYPE_INFORMATION_THEME) {
182 gtk_dialog_response (note, GTK_RESPONSE_DELETE_EVENT);
190 hildon_note_set_property (GObject *object,
195 HildonNote *note = HILDON_NOTE (object);
196 HildonNotePrivate *priv;
199 priv = HILDON_NOTE_GET_PRIVATE (note);
204 case PROP_HILDON_NOTE_TYPE:
205 priv->note_n = g_value_get_enum (value);
206 hildon_note_rename (note);
207 hildon_note_rebuild (note);
210 case PROP_HILDON_NOTE_DESCRIPTION:
211 if (priv->original_description)
212 g_free (priv->original_description);
213 priv->original_description = g_value_dup_string (value);
215 gtk_label_set_text (GTK_LABEL (priv->label), priv->original_description);
216 /* FIXME Is the "original_description" used anywhere? */
220 case PROP_HILDON_NOTE_ICON:
224 priv->icon = g_value_dup_string (value);
227 case PROP_HILDON_NOTE_STOCK_ICON:
228 if (priv->stock_icon) {
229 g_free (priv->stock_icon);
231 priv->stock_icon = g_value_dup_string (value);
234 case PROP_HILDON_NOTE_PROGRESSBAR:
235 widget = g_value_get_object (value);
236 if (widget != priv->progressbar)
238 if (priv->progressbar)
239 g_object_unref (priv->progressbar);
241 priv->progressbar = widget;
245 g_object_ref (widget);
246 gtk_object_sink (GTK_OBJECT (widget));
249 hildon_note_rebuild (note);
254 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
260 hildon_note_get_property (GObject *object,
265 HildonNote *note = HILDON_NOTE (object);
266 HildonNotePrivate *priv;
268 priv = HILDON_NOTE_GET_PRIVATE (note);
272 case PROP_HILDON_NOTE_TYPE:
273 g_value_set_enum (value, priv->note_n);
276 case PROP_HILDON_NOTE_DESCRIPTION:
277 g_value_set_string (value, priv->original_description);
280 case PROP_HILDON_NOTE_ICON:
281 g_value_set_string (value, priv->icon);
284 case PROP_HILDON_NOTE_STOCK_ICON:
285 g_value_set_string (value, priv->stock_icon);
288 case PROP_HILDON_NOTE_PROGRESSBAR:
289 g_value_set_object (value, priv->progressbar);
293 G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
300 hildon_note_constructor (GType type,
301 guint n_construct_properties,
302 GObjectConstructParam *construct_params)
305 object = (* G_OBJECT_CLASS (parent_class)->constructor)
306 (type, n_construct_properties, construct_params);
307 hildon_note_set_padding (HILDON_NOTE (object));
311 #endif /* MAEMO_GTK */
314 * hildon_note_get_type:
316 * Returns GType for HildonNote.
318 * Returns: HildonNote type
321 hildon_note_get_type (void)
323 static GType dialog_type = 0;
326 static const GTypeInfo dialog_info = {
327 sizeof(HildonNoteClass),
328 NULL, /* base_init */
329 NULL, /* base_finalize */
330 (GClassInitFunc) hildon_note_class_init,
331 NULL, /* class_finalize */
332 NULL, /* class_data */
335 (GInstanceInitFunc) hildon_note_init
337 dialog_type = g_type_register_static (GTK_TYPE_DIALOG,
345 hildon_note_class_init (HildonNoteClass *class)
347 GObjectClass *object_class = G_OBJECT_CLASS (class);
348 GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (class);
350 /* set the global parent_class */
351 parent_class = g_type_class_peek_parent (class);
353 g_type_class_add_private (class, sizeof (HildonNotePrivate));
355 object_class->finalize = hildon_note_finalize;
356 object_class->set_property = hildon_note_set_property;
357 object_class->get_property = hildon_note_get_property;
359 object_class->constructor = hildon_note_constructor;
360 #endif /* MAEMO_GTK */
361 widget_class->realize = hildon_note_realize;
362 widget_class->unrealize = hildon_note_unrealize;
363 widget_class->size_request = hildon_note_size_request;
368 * The type of the #HildonNote, defining its contents, behavior, and
371 g_object_class_install_property (object_class,
372 PROP_HILDON_NOTE_TYPE,
373 g_param_spec_enum ("note-type",
375 "The type of the note dialog",
376 hildon_note_type_get_type (),
377 HILDON_NOTE_TYPE_CONFIRMATION,
378 G_PARAM_READWRITE | G_PARAM_CONSTRUCT));
381 * HildonNote:description:
383 * The text that appears in the #HildonNote.
385 g_object_class_install_property (object_class,
386 PROP_HILDON_NOTE_DESCRIPTION,
387 g_param_spec_string ("description",
389 "The text that appears in the note dialog",
398 * Deprecated: Since 2.2
400 g_object_class_install_property (object_class,
401 PROP_HILDON_NOTE_ICON,
402 g_param_spec_string ("icon",
404 "The name of the icon that appears in the note dialog",
409 * HildonNote:stock-icon:
411 * Stock icon name for the note.
413 * Deprecated: Since 2.2
415 g_object_class_install_property (object_class,
416 PROP_HILDON_NOTE_STOCK_ICON,
417 g_param_spec_string ("stock-icon",
419 "The stock name of the icon that appears in the note dialog",
424 * HildonNote:progressbar:
426 * If set, a #GtkProgressBar is displayed in the note.
428 g_object_class_install_property (object_class,
429 PROP_HILDON_NOTE_PROGRESSBAR,
430 g_param_spec_object ("progressbar",
431 "Progressbar widget",
432 "The progressbar that appears in the note dialog",
433 GTK_TYPE_PROGRESS_BAR,
438 hildon_note_init (HildonNote *dialog)
440 HildonNotePrivate *priv = HILDON_NOTE_GET_PRIVATE (dialog);
443 priv->label = gtk_label_new (NULL);
444 gtk_label_set_line_wrap (GTK_LABEL (priv->label), TRUE);
445 gtk_label_set_justify (GTK_LABEL (priv->label), GTK_JUSTIFY_LEFT);
447 priv->event_box = gtk_event_box_new ();
449 priv->stock_icon = NULL;
450 priv->idle_handler = 0;
452 gtk_event_box_set_visible_window (GTK_EVENT_BOX (priv->event_box), FALSE);
453 gtk_event_box_set_above_child (GTK_EVENT_BOX (priv->event_box), TRUE);
454 g_signal_connect (priv->event_box, "button-press-event",
455 G_CALLBACK (event_box_press_event), dialog);
457 /* Because ESD is synchronous, we wish to play sound after the
458 note is already on screen to avoid blocking its appearance */
459 g_signal_connect (GTK_WIDGET (dialog), "show",
460 G_CALLBACK (on_show_cb), NULL);
462 /* Acquire real references to our internal children, since
463 they are not nessecarily packed into container in each
465 g_object_ref_sink (priv->event_box);
466 g_object_ref_sink (priv->label);
468 gtk_dialog_set_has_separator (GTK_DIALOG (dialog), FALSE);
469 gtk_window_set_modal (GTK_WINDOW (dialog), TRUE);
471 /* We use special hint to turn the note into information notification. */
472 gtk_window_set_type_hint (GTK_WINDOW (dialog), GDK_WINDOW_TYPE_HINT_NOTIFICATION);
477 hildon_note_finalize (GObject *obj_self)
479 HildonNotePrivate *priv = HILDON_NOTE_GET_PRIVATE (obj_self);
482 /* FIXME Some of this stuff should be moved to dispose */
484 /* Free internal data */
486 g_object_unref (priv->event_box);
489 g_object_unref (priv->label);
495 if (priv->stock_icon) {
496 g_free (priv->stock_icon);
497 priv->stock_icon = NULL;
499 if (priv->idle_handler) {
500 g_source_remove (priv->idle_handler);
501 priv->idle_handler = 0;
504 if (priv->progressbar)
505 g_object_unref (priv->progressbar);
507 if (priv->original_description)
508 g_free (priv->original_description);
510 G_OBJECT_CLASS (parent_class)->finalize (obj_self);
514 label_size_request (GtkWidget *label,
518 gint note_height = MAX (HILDON_INFORMATION_NOTE_MIN_HEIGHT, req->height);
519 g_object_set (note, "height-request", note_height, NULL);
523 resize_button (GtkWidget *button, gpointer *data)
525 gint width = GPOINTER_TO_INT (data);
526 g_object_set (button, "width-request", width, NULL);
530 hildon_note_orientation_update (HildonNote *note, GdkScreen *screen)
532 GtkDialog *dialog = GTK_DIALOG (note);
533 HildonNotePrivate* priv = HILDON_NOTE_GET_PRIVATE (note);
535 gint button_width, padding;
536 gboolean portrait = gdk_screen_get_width (screen) < gdk_screen_get_height (screen);
538 g_object_ref (dialog->action_area);
539 unpack_widget (dialog->action_area);
542 parent = dialog->vbox;
543 button_width = gdk_screen_get_width (screen) - HILDON_MARGIN_DOUBLE * 2;
544 padding = HILDON_MARGIN_DOUBLE;
546 parent = gtk_widget_get_parent (dialog->vbox);
547 button_width = priv->button_width;
551 gtk_box_pack_end (GTK_BOX (parent), dialog->action_area,
553 gtk_box_reorder_child (GTK_BOX (parent), dialog->action_area, 0);
554 gtk_container_foreach (GTK_CONTAINER (dialog->action_area),
555 (GtkCallback) resize_button,
556 GINT_TO_POINTER (button_width));
557 g_object_unref (dialog->action_area);
558 gtk_container_child_set (GTK_CONTAINER (priv->box), priv->label,
559 "padding", padding, NULL);
563 hildon_note_size_request (GtkWidget *note,
566 GTK_WIDGET_CLASS (parent_class)->size_request (note, req);
567 req->width = gdk_screen_get_width (gtk_widget_get_screen (note));
571 screen_size_changed (GdkScreen *screen,
574 HildonNotePrivate *priv = HILDON_NOTE_GET_PRIVATE (note);
576 hildon_note_rename (HILDON_NOTE (note));
578 if (priv->note_n == HILDON_NOTE_TYPE_INFORMATION ||
579 priv->note_n == HILDON_NOTE_TYPE_INFORMATION_THEME) {
580 gint screen_width = gdk_screen_get_width (screen);
581 gint text_width = screen_width - HILDON_INFORMATION_NOTE_MARGIN * 2;
582 g_object_set (priv->label, "width-request", text_width, NULL);
585 } else if (priv->note_n == HILDON_NOTE_TYPE_CONFIRMATION) {
586 hildon_note_orientation_update (HILDON_NOTE (note), screen);
591 hildon_note_realize (GtkWidget *widget)
594 gboolean is_info_note = FALSE;
596 const gchar *notification_type;
597 HildonNotePrivate *priv = HILDON_NOTE_GET_PRIVATE (widget);
600 /* Make widget->window accessible */
601 GTK_WIDGET_CLASS (parent_class)->realize (widget);
603 /* Border only, no titlebar */
604 gdk_window_set_decorations (widget->window, GDK_DECOR_BORDER);
606 /* Set the _HILDON_NOTIFICATION_TYPE property so Matchbox places the window correctly */
607 display = gdk_drawable_get_display (widget->window);
608 atom = gdk_x11_get_xatom_by_name_for_display (display, "_HILDON_NOTIFICATION_TYPE");
610 if (priv->note_n == HILDON_NOTE_TYPE_INFORMATION ||
611 priv->note_n == HILDON_NOTE_TYPE_INFORMATION_THEME) {
612 notification_type = "_HILDON_NOTIFICATION_TYPE_INFO";
615 notification_type = "_HILDON_NOTIFICATION_TYPE_CONFIRMATION";
618 XChangeProperty (GDK_WINDOW_XDISPLAY (widget->window), GDK_WINDOW_XID (widget->window),
619 atom, XA_STRING, 8, PropModeReplace, (guchar *) notification_type,
620 strlen (notification_type));
623 g_signal_connect (priv->label, "size-request", G_CALLBACK (label_size_request), widget);
626 GdkScreen *screen = gtk_widget_get_screen (widget);
627 g_signal_connect (screen, "size-changed", G_CALLBACK (screen_size_changed), widget);
628 screen_size_changed (screen, widget);
630 hildon_gtk_window_set_portrait_flags (GTK_WINDOW (widget), HILDON_PORTRAIT_MODE_SUPPORT);
634 hildon_note_unrealize (GtkWidget *widget)
636 HildonNotePrivate *priv = HILDON_NOTE_GET_PRIVATE (widget);
637 GdkScreen *screen = gtk_widget_get_screen (widget);
639 g_signal_handlers_disconnect_by_func (screen, G_CALLBACK (screen_size_changed), widget);
640 g_signal_handlers_disconnect_by_func (priv->label, G_CALLBACK (label_size_request), widget);
642 GTK_WIDGET_CLASS (parent_class)->unrealize (widget);
646 /* Helper function for removing a widget from it's container.
647 we own a separate reference to each object we try to unpack,
648 so extra referencing is not needed. */
650 unpack_widget (GtkWidget *widget)
652 g_assert (widget == NULL || GTK_IS_WIDGET (widget));
654 if (widget && widget->parent)
655 gtk_container_remove (GTK_CONTAINER (widget->parent), widget);
659 Name the widget and text label based on the note type. This is used
660 by the theme to give proper backgrounds depending on the note type.
663 hildon_note_rename (HildonNote *note)
666 GEnumClass *enum_class;
668 GdkScreen *screen = gtk_widget_get_screen (GTK_WIDGET (note));
669 gboolean portrait = gdk_screen_get_width (screen) < gdk_screen_get_height (screen);
670 const gchar *portrait_suffix = portrait ? "-portrait" : NULL;
672 HildonNotePrivate *priv = HILDON_NOTE_GET_PRIVATE (note);
674 enum_class = g_type_class_ref (HILDON_TYPE_NOTE_TYPE);
675 value = g_enum_get_value (enum_class, priv->note_n);
677 name = g_strconcat ("HildonNote-", value->value_nick, portrait_suffix, NULL);
678 gtk_widget_set_name (GTK_WIDGET (note), name);
681 name = g_strconcat ("HildonNoteLabel-", value->value_nick, NULL);
682 gtk_widget_set_name (priv->label, name);
685 g_type_class_unref (enum_class);
690 hildon_note_set_padding (HildonNote *note)
692 HildonNotePrivate *priv;
694 priv = HILDON_NOTE_GET_PRIVATE (note);
696 switch (priv->note_n) {
697 case HILDON_NOTE_TYPE_INFORMATION:
698 case HILDON_NOTE_TYPE_INFORMATION_THEME:
699 gtk_dialog_set_padding (GTK_DIALOG (note),
700 HILDON_MARGIN_DOUBLE,
701 HILDON_MARGIN_DOUBLE,
706 case HILDON_NOTE_TYPE_CONFIRMATION:
707 case HILDON_NOTE_TYPE_CONFIRMATION_BUTTON:
708 gtk_dialog_set_padding (GTK_DIALOG (note),
709 HILDON_MARGIN_DOUBLE,
710 HILDON_MARGIN_DEFAULT,
711 HILDON_MARGIN_DOUBLE,
712 HILDON_MARGIN_DOUBLE);
719 #endif /* MAEMO_GTK */
722 hildon_note_rebuild (HildonNote *note)
725 HildonNotePrivate *priv;
726 gboolean is_info_note = FALSE;
728 g_assert (HILDON_IS_NOTE (note));
730 priv = HILDON_NOTE_GET_PRIVATE (note);
733 dialog = GTK_DIALOG (note);
735 /* Reuse exiting content widgets for new layout */
736 unpack_widget (priv->label);
737 unpack_widget (priv->progressbar);
738 unpack_widget (priv->event_box);
740 /* Destroy old layout and buttons */
742 gtk_widget_destroy (priv->box);
745 if (priv->okButton) {
746 gtk_widget_destroy (priv->okButton);
747 priv->okButton = NULL;
749 if (priv->cancelButton) {
750 gtk_widget_destroy (priv->cancelButton);
751 priv->cancelButton = NULL;
754 /* Add needed buttons and images for each note type */
755 switch (priv->note_n)
757 case HILDON_NOTE_TYPE_CONFIRMATION:
758 priv->okButton = gtk_dialog_add_button (dialog,
759 _("wdgt_bd_yes"), GTK_RESPONSE_OK);
760 priv->cancelButton = gtk_dialog_add_button (dialog,
761 _("wdgt_bd_no"), GTK_RESPONSE_CANCEL);
762 gtk_widget_show (priv->cancelButton);
763 g_object_get (priv->okButton, "width-request",
764 &priv->button_width, NULL);
765 gtk_widget_set_no_show_all (priv->cancelButton, FALSE);
768 case HILDON_NOTE_TYPE_PROGRESSBAR:
769 priv->cancelButton = gtk_dialog_add_button (dialog,
770 _("wdgt_bd_stop"), GTK_RESPONSE_CANCEL);
771 gtk_widget_show (priv->cancelButton);
772 gtk_widget_set_no_show_all (priv->cancelButton, FALSE);
775 case HILDON_NOTE_TYPE_INFORMATION_THEME:
776 case HILDON_NOTE_TYPE_INFORMATION:
780 case HILDON_NOTE_TYPE_CONFIRMATION_BUTTON:
785 /* Don't display the action area if this is just an information
786 * note. This prevents text from being slightly aligned to the
790 gtk_widget_hide (dialog->action_area);
792 gtk_widget_show (dialog->action_area);
794 gtk_widget_set_no_show_all (dialog->action_area, is_info_note);
796 /* Pack label vertically. Spacing is only necessary for the progressbar note. */
797 priv->box = gtk_vbox_new (FALSE, priv->progressbar ? HILDON_MARGIN_DOUBLE : 0);
798 gtk_container_add (GTK_CONTAINER (priv->event_box), priv->box);
799 gtk_box_pack_start (GTK_BOX (priv->box), priv->label, TRUE, TRUE, 0);
801 if (priv->progressbar)
802 gtk_box_pack_start (GTK_BOX (priv->box), priv->progressbar, FALSE, FALSE, 0);
805 hildon_note_set_padding (note);
806 #endif /* MAEMO_GTK */
808 gtk_container_add (GTK_CONTAINER (dialog->vbox), priv->event_box);
810 gtk_widget_show_all (priv->event_box);
814 * hildon_note_new_confirmation_add_buttons:
815 * @parent: the parent window. The X window ID of the parent window
816 * has to be the same as the X window ID of the application. This is
817 * important so that the window manager could handle the windows
819 * In GTK the X window ID can be checked using
820 * GDK_WINDOW_XID(GTK_WIDGET(parent)->window).
821 * @description: the message to confirm
822 * @Varargs: arguments pairs for new buttons(label and return value).
823 * Terminate the list with %NULL value.
825 * Create a new confirmation note with custom buttons. Confirmation
826 * note has a text and any number of buttons. It's important to note
827 * that even though the name of the function might suggest, the
828 * default ok/cancel buttons are not appended but you have to provide
829 * all of the buttons.
831 * FIXME: This doc seems to be wrong, the two buttons aren't added so
832 * it would only contain the "additional" buttons? However, changing
833 * this would break those applications that rely on current behaviour.
835 * Returns: A new #HildonNote.
838 hildon_note_new_confirmation_add_buttons (GtkWindow *parent,
839 const gchar *description,
847 g_return_val_if_fail (description != NULL, NULL);
849 GtkWidget *conf_note =
850 g_object_new (HILDON_TYPE_NOTE,
851 "note-type", HILDON_NOTE_TYPE_CONFIRMATION_BUTTON,
852 "description", description,
856 gtk_window_set_transient_for (GTK_WINDOW (conf_note), parent);
858 /* Add the buttons from varargs */
859 va_start(args, description);
862 message = va_arg (args, char *);
867 value = va_arg (args, int);
869 button = gtk_dialog_add_button (GTK_DIALOG (conf_note), message, value);
870 /* maemo-gtk is going to set the "no-show-all" property all
871 cancel/close-like buttons to TRUE, so that they are not shown. On
872 the other hand, this confirmation note with custom buttons should
873 not obey this rule, so we need to make sure they are shown. */
874 gtk_widget_show (button);
875 gtk_widget_set_no_show_all (button, FALSE);
885 * hildon_note_new_confirmation:
886 * @parent: the parent window. The X window ID of the parent window
887 * has to be the same as the X window ID of the application. This is
888 * important so that the window manager could handle the windows
889 * correctly. In GTK the X window ID can be checked using
890 * GDK_WINDOW_XID(GTK_WIDGET(parent)->window).
891 * @description: the message to confirm.
893 * Create a new confirmation note. Confirmation note has a text (description)
894 * that you specify and two buttons.
896 * Returns: a new #HildonNote.
899 hildon_note_new_confirmation (GtkWindow *parent,
900 const gchar *description)
902 GtkWidget *dialog = NULL;
904 g_return_val_if_fail (description != NULL, NULL);
906 dialog = g_object_new (HILDON_TYPE_NOTE,
908 HILDON_NOTE_TYPE_CONFIRMATION,
909 "description", description, NULL);
912 gtk_window_set_transient_for (GTK_WINDOW (dialog), parent);
918 * hildon_note_new_confirmation_with_icon_name:
919 * @parent: the parent window. The X window ID of the parent window
920 * has to be the same as the X window ID of the application. This is
921 * important so that the window manager could handle the windows
922 * correctly. In GTK the X window ID can be checked using
923 * GDK_WINDOW_XID(GTK_WIDGET(parent)->window).
924 * @description: the message to confirm
925 * @icon_name: icon to be displayed. If NULL, default icon is used.
927 * Create a new confirmation note. Confirmation note has a text (description)
928 * that you specify and two buttons.
930 * Deprecated: Since 2.2, icons are not shown in confirmation notes. Icons set
931 * with this function will be ignored. Use hildon_note_new_confirmation() instead.
933 * Returns: a new #HildonNote.
936 hildon_note_new_confirmation_with_icon_name (GtkWindow *parent,
937 const gchar *description,
938 const gchar *icon_name)
942 dialog = hildon_note_new_confirmation (parent, description);
943 g_object_set (dialog, "icon", icon_name, NULL);
949 * hildon_note_new_information:
950 * @parent: the parent window. The X window ID of the parent window
951 * has to be the same as the X window ID of the application. This is
952 * important so that the window manager could handle the windows
953 * correctly. In GTK the X window ID can be checked using
954 * GDK_WINDOW_XID(GTK_WIDGET(parent)->window).
955 * @description: the message to confirm.
957 * Create a new information note. Information note has text (a description)
958 * that you specify and an OK button.
960 * Returns: a new #HildonNote.
963 hildon_note_new_information (GtkWindow *parent,
964 const gchar *description)
966 GtkWidget *dialog = NULL;
968 g_return_val_if_fail (description != NULL, NULL);
970 dialog = g_object_new (HILDON_TYPE_NOTE,
972 HILDON_NOTE_TYPE_INFORMATION_THEME,
973 "description", description, NULL);
976 gtk_window_set_transient_for (GTK_WINDOW (dialog), parent);
982 * hildon_note_new_information_with_icon_name:
983 * @parent: the parent window. The X window ID of the parent window
984 * has to be the same as the X window ID of the application. This is
985 * important so that the window manager could handle the windows
986 * correctly. In GTK the X window ID can be checked using
987 * GDK_WINDOW_XID(GTK_WIDGET(parent)->window).
988 * @description: the message to confirm.
989 * @icon_name: icon to be displayed. If %NULL, the default icon is used.
991 * Create a new information note. An information note has text (a description)
992 * that you specify, an OK button and an icon.
994 * Deprecated: Since 2.2, icons are not shown in confirmation notes. Icons set
995 * with this function will be ignored. Use hildon_note_new_information()
998 * Returns: a new #HildonNote.
1001 hildon_note_new_information_with_icon_name (GtkWindow * parent,
1002 const gchar *description,
1003 const gchar *icon_name)
1007 dialog = hildon_note_new_information (parent, description);
1008 g_object_set (dialog, "icon", icon_name, NULL);
1013 /* FIXME This documentation string LIES! */
1016 * hildon_note_new_cancel_with_progress_bar:
1017 * @parent: the parent window. The X window ID of the parent window
1018 * has to be the same as the X window ID of the application. This is
1019 * important so that the window manager could handle the windows
1020 * correctly. In GTK the X window ID can be checked using
1021 * GDK_WINDOW_XID(GTK_WIDGET(parent)->window).
1022 * @description: the action to cancel.
1023 * @progressbar: a pointer to #GtkProgressBar to be filled with the
1024 * progressbar assigned to this note. Use this to set the fraction of
1025 * progressbar done. This parameter can be %NULL as well, in which
1026 * case plain text cancel note appears.
1028 * Create a new cancel note with a progress bar. Cancel note has
1029 * text(description) that you specify, a Cancel button and a progress bar.
1031 * Returns: a #GtkDialog. Use this to get rid of this note when you
1032 * no longer need it.
1035 hildon_note_new_cancel_with_progress_bar (GtkWindow *parent,
1036 const gchar *description,
1037 GtkProgressBar *progressbar)
1039 GtkWidget *dialog = NULL;
1041 g_return_val_if_fail (description != NULL, NULL);
1043 dialog = g_object_new (HILDON_TYPE_NOTE,
1045 HILDON_NOTE_TYPE_PROGRESSBAR,
1046 "description", description,
1051 gtk_window_set_transient_for (GTK_WINDOW (dialog), parent);
1058 * hildon_note_set_button_text:
1059 * @note: a #HildonNote.
1060 * @text: sets the button text. If there are two buttons in dialog,
1061 * the button texts will be <text>, "Cancel".
1063 * Sets the text of the button in @note.
1066 hildon_note_set_button_text (HildonNote *note,
1069 HildonNotePrivate *priv;
1071 g_return_if_fail (HILDON_IS_NOTE (note));
1073 priv = HILDON_NOTE_GET_PRIVATE (HILDON_NOTE (note));
1076 if (priv->okButton) {
1077 gtk_button_set_label (GTK_BUTTON (priv->okButton), text);
1078 gtk_button_set_label (GTK_BUTTON (priv->cancelButton),
1081 gtk_button_set_label (GTK_BUTTON (priv->cancelButton), text);
1086 * hildon_note_set_button_texts:
1087 * @note: a #HildonNote.
1088 * @text_ok: the new text of the default OK button.
1089 * @text_cancel: the new text of the default cancel button.
1091 * Sets the text for the buttons in @note.
1094 hildon_note_set_button_texts (HildonNote *note,
1095 const gchar *text_ok,
1096 const gchar *text_cancel)
1098 HildonNotePrivate *priv;
1100 g_return_if_fail (HILDON_IS_NOTE (note));
1102 priv = HILDON_NOTE_GET_PRIVATE (HILDON_NOTE (note));
1105 if (priv->okButton) {
1106 gtk_button_set_label (GTK_BUTTON (priv->okButton), text_ok);
1107 gtk_button_set_label (GTK_BUTTON (priv->cancelButton), text_cancel);
1109 gtk_button_set_label (GTK_BUTTON (priv->cancelButton), text_cancel);
1114 on_show_cb (GtkWidget *widget,
1117 HildonNotePrivate *priv;
1119 priv = HILDON_NOTE_GET_PRIVATE (widget);
1120 priv->idle_handler = g_idle_add (sound_handling, widget);
1123 /* We play a system sound when the note comes visible */
1125 sound_handling (gpointer data)
1127 HildonNotePrivate *priv = HILDON_NOTE_GET_PRIVATE (data);
1130 switch (priv->note_n)
1132 case HILDON_NOTE_TYPE_INFORMATION:
1133 case HILDON_NOTE_TYPE_INFORMATION_THEME:
1134 hildon_play_system_sound (INFORMATION_SOUND_PATH);
1137 case HILDON_NOTE_TYPE_CONFIRMATION:
1138 case HILDON_NOTE_TYPE_CONFIRMATION_BUTTON:
1139 hildon_play_system_sound (CONFIRMATION_SOUND_PATH);
1146 priv->idle_handler = 0;