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 + 2*HILDON_MARGIN_DOUBLE);
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);
767 gtk_dialog_set_padding (dialog,
768 HILDON_MARGIN_DOUBLE,
769 HILDON_MARGIN_DEFAULT,
770 HILDON_MARGIN_DOUBLE,
771 HILDON_MARGIN_DOUBLE);
772 #endif /* MAEMO_GTK */
775 case HILDON_NOTE_TYPE_PROGRESSBAR:
776 priv->cancelButton = gtk_dialog_add_button (dialog,
777 _("wdgt_bd_stop"), GTK_RESPONSE_CANCEL);
778 gtk_widget_show (priv->cancelButton);
779 gtk_widget_set_no_show_all (priv->cancelButton, FALSE);
782 case HILDON_NOTE_TYPE_INFORMATION_THEME:
783 case HILDON_NOTE_TYPE_INFORMATION:
785 gtk_dialog_set_padding (dialog,
786 HILDON_MARGIN_DOUBLE,
787 HILDON_MARGIN_DOUBLE,
790 #endif /* MAEMO_GTK */
794 case HILDON_NOTE_TYPE_CONFIRMATION_BUTTON:
799 /* Don't display the action area if this is just an information
800 * note. This prevents text from being slightly aligned to the
804 gtk_widget_hide (dialog->action_area);
806 gtk_widget_show (dialog->action_area);
808 gtk_widget_set_no_show_all (dialog->action_area, is_info_note);
810 /* Pack label vertically. Spacing is only necessary for the progressbar note. */
811 priv->box = gtk_vbox_new (FALSE, priv->progressbar ? HILDON_MARGIN_DOUBLE : 0);
812 gtk_container_add (GTK_CONTAINER (priv->event_box), priv->box);
813 gtk_box_pack_start (GTK_BOX (priv->box), priv->label, TRUE, TRUE, 0);
815 if (priv->progressbar)
816 gtk_box_pack_start (GTK_BOX (priv->box), priv->progressbar, FALSE, FALSE, 0);
819 hildon_note_set_padding (note);
820 #endif /* MAEMO_GTK */
822 gtk_container_add (GTK_CONTAINER (dialog->vbox), priv->event_box);
824 gtk_widget_show_all (priv->event_box);
828 * hildon_note_new_confirmation_add_buttons:
829 * @parent: the parent window. The X window ID of the parent window
830 * has to be the same as the X window ID of the application. This is
831 * important so that the window manager could handle the windows
833 * In GTK the X window ID can be checked using
834 * GDK_WINDOW_XID(GTK_WIDGET(parent)->window).
835 * @description: the message to confirm
836 * @Varargs: arguments pairs for new buttons(label and return value).
837 * Terminate the list with %NULL value.
839 * Create a new confirmation note with custom buttons. Confirmation
840 * note has a text and any number of buttons. It's important to note
841 * that even though the name of the function might suggest, the
842 * default ok/cancel buttons are not appended but you have to provide
843 * all of the buttons.
845 * FIXME: This doc seems to be wrong, the two buttons aren't added so
846 * it would only contain the "additional" buttons? However, changing
847 * this would break those applications that rely on current behaviour.
849 * Returns: A new #HildonNote.
852 hildon_note_new_confirmation_add_buttons (GtkWindow *parent,
853 const gchar *description,
861 g_return_val_if_fail (description != NULL, NULL);
863 GtkWidget *conf_note =
864 g_object_new (HILDON_TYPE_NOTE,
865 "note-type", HILDON_NOTE_TYPE_CONFIRMATION_BUTTON,
866 "description", description,
870 gtk_window_set_transient_for (GTK_WINDOW (conf_note), parent);
872 /* Add the buttons from varargs */
873 va_start(args, description);
876 message = va_arg (args, char *);
881 value = va_arg (args, int);
883 button = gtk_dialog_add_button (GTK_DIALOG (conf_note), message, value);
884 /* maemo-gtk is going to set the "no-show-all" property all
885 cancel/close-like buttons to TRUE, so that they are not shown. On
886 the other hand, this confirmation note with custom buttons should
887 not obey this rule, so we need to make sure they are shown. */
888 gtk_widget_show (button);
889 gtk_widget_set_no_show_all (button, FALSE);
899 * hildon_note_new_confirmation:
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.
907 * Create a new confirmation note. Confirmation note has a text (description)
908 * that you specify and two buttons.
910 * Returns: a new #HildonNote.
913 hildon_note_new_confirmation (GtkWindow *parent,
914 const gchar *description)
916 GtkWidget *dialog = NULL;
918 g_return_val_if_fail (description != NULL, NULL);
920 dialog = g_object_new (HILDON_TYPE_NOTE,
922 HILDON_NOTE_TYPE_CONFIRMATION,
923 "description", description, NULL);
926 gtk_window_set_transient_for (GTK_WINDOW (dialog), parent);
932 * hildon_note_new_confirmation_with_icon_name:
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 message to confirm
939 * @icon_name: icon to be displayed. If NULL, default icon is used.
941 * Create a new confirmation note. Confirmation note has a text (description)
942 * that you specify and two buttons.
944 * Deprecated: Since 2.2, icons are not shown in confirmation notes. Icons set
945 * with this function will be ignored. Use hildon_note_new_confirmation() instead.
947 * Returns: a new #HildonNote.
950 hildon_note_new_confirmation_with_icon_name (GtkWindow *parent,
951 const gchar *description,
952 const gchar *icon_name)
956 dialog = hildon_note_new_confirmation (parent, description);
957 g_object_set (dialog, "icon", icon_name, NULL);
963 * hildon_note_new_information:
964 * @parent: the parent window. The X window ID of the parent window
965 * has to be the same as the X window ID of the application. This is
966 * important so that the window manager could handle the windows
967 * correctly. In GTK the X window ID can be checked using
968 * GDK_WINDOW_XID(GTK_WIDGET(parent)->window).
969 * @description: the message to confirm.
971 * Create a new information note. Information note has text (a description)
972 * that you specify and an OK button.
974 * Returns: a new #HildonNote.
977 hildon_note_new_information (GtkWindow *parent,
978 const gchar *description)
980 GtkWidget *dialog = NULL;
982 g_return_val_if_fail (description != NULL, NULL);
984 dialog = g_object_new (HILDON_TYPE_NOTE,
986 HILDON_NOTE_TYPE_INFORMATION_THEME,
987 "description", description, NULL);
990 gtk_window_set_transient_for (GTK_WINDOW (dialog), parent);
996 * hildon_note_new_information_with_icon_name:
997 * @parent: the parent window. The X window ID of the parent window
998 * has to be the same as the X window ID of the application. This is
999 * important so that the window manager could handle the windows
1000 * correctly. In GTK the X window ID can be checked using
1001 * GDK_WINDOW_XID(GTK_WIDGET(parent)->window).
1002 * @description: the message to confirm.
1003 * @icon_name: icon to be displayed. If %NULL, the default icon is used.
1005 * Create a new information note. An information note has text (a description)
1006 * that you specify, an OK button and an icon.
1008 * Deprecated: Since 2.2, icons are not shown in confirmation notes. Icons set
1009 * with this function will be ignored. Use hildon_note_new_information()
1012 * Returns: a new #HildonNote.
1015 hildon_note_new_information_with_icon_name (GtkWindow * parent,
1016 const gchar *description,
1017 const gchar *icon_name)
1021 dialog = hildon_note_new_information (parent, description);
1022 g_object_set (dialog, "icon", icon_name, NULL);
1027 /* FIXME This documentation string LIES! */
1030 * hildon_note_new_cancel_with_progress_bar:
1031 * @parent: the parent window. The X window ID of the parent window
1032 * has to be the same as the X window ID of the application. This is
1033 * important so that the window manager could handle the windows
1034 * correctly. In GTK the X window ID can be checked using
1035 * GDK_WINDOW_XID(GTK_WIDGET(parent)->window).
1036 * @description: the action to cancel.
1037 * @progressbar: a pointer to #GtkProgressBar to be filled with the
1038 * progressbar assigned to this note. Use this to set the fraction of
1039 * progressbar done. This parameter can be %NULL as well, in which
1040 * case plain text cancel note appears.
1042 * Create a new cancel note with a progress bar. Cancel note has
1043 * text(description) that you specify, a Cancel button and a progress bar.
1045 * Returns: a #GtkDialog. Use this to get rid of this note when you
1046 * no longer need it.
1049 hildon_note_new_cancel_with_progress_bar (GtkWindow *parent,
1050 const gchar *description,
1051 GtkProgressBar *progressbar)
1053 GtkWidget *dialog = NULL;
1055 g_return_val_if_fail (description != NULL, NULL);
1057 dialog = g_object_new (HILDON_TYPE_NOTE,
1059 HILDON_NOTE_TYPE_PROGRESSBAR,
1060 "description", description,
1065 gtk_window_set_transient_for (GTK_WINDOW (dialog), parent);
1072 * hildon_note_set_button_text:
1073 * @note: a #HildonNote.
1074 * @text: sets the button text. If there are two buttons in dialog,
1075 * the button texts will be <text>, "Cancel".
1077 * Sets the text of the button in @note.
1080 hildon_note_set_button_text (HildonNote *note,
1083 HildonNotePrivate *priv;
1085 g_return_if_fail (HILDON_IS_NOTE (note));
1087 priv = HILDON_NOTE_GET_PRIVATE (HILDON_NOTE (note));
1090 if (priv->okButton) {
1091 gtk_button_set_label (GTK_BUTTON (priv->okButton), text);
1092 gtk_button_set_label (GTK_BUTTON (priv->cancelButton),
1095 gtk_button_set_label (GTK_BUTTON (priv->cancelButton), text);
1100 * hildon_note_set_button_texts:
1101 * @note: a #HildonNote.
1102 * @text_ok: the new text of the default OK button.
1103 * @text_cancel: the new text of the default cancel button.
1105 * Sets the text for the buttons in @note.
1108 hildon_note_set_button_texts (HildonNote *note,
1109 const gchar *text_ok,
1110 const gchar *text_cancel)
1112 HildonNotePrivate *priv;
1114 g_return_if_fail (HILDON_IS_NOTE (note));
1116 priv = HILDON_NOTE_GET_PRIVATE (HILDON_NOTE (note));
1119 if (priv->okButton) {
1120 gtk_button_set_label (GTK_BUTTON (priv->okButton), text_ok);
1121 gtk_button_set_label (GTK_BUTTON (priv->cancelButton), text_cancel);
1123 gtk_button_set_label (GTK_BUTTON (priv->cancelButton), text_cancel);
1128 on_show_cb (GtkWidget *widget,
1131 HildonNotePrivate *priv;
1133 priv = HILDON_NOTE_GET_PRIVATE (widget);
1134 priv->idle_handler = g_idle_add (sound_handling, widget);
1137 /* We play a system sound when the note comes visible */
1139 sound_handling (gpointer data)
1141 HildonNotePrivate *priv = HILDON_NOTE_GET_PRIVATE (data);
1144 switch (priv->note_n)
1146 case HILDON_NOTE_TYPE_INFORMATION:
1147 case HILDON_NOTE_TYPE_INFORMATION_THEME:
1148 hildon_play_system_sound (INFORMATION_SOUND_PATH);
1151 case HILDON_NOTE_TYPE_CONFIRMATION:
1152 case HILDON_NOTE_TYPE_CONFIRMATION_BUTTON:
1153 hildon_play_system_sound (CONFIRMATION_SOUND_PATH);
1160 priv->idle_handler = 0;