2 * This file is part of hildon-libs
4 * Copyright (C) 2005 Nokia Corporation.
6 * Contact: Luc Pionchon <luc.pionchon@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; either 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
28 * This file contains API for conformation, information
31 * 9/2004 Removed animation type of cancel note as separate task.
38 #include "hildon-note.h"
39 #include <gtk/gtklabel.h>
40 #include <gtk/gtkimage.h>
41 #include <gtk/gtkhbox.h>
42 #include <gtk/gtkalignment.h>
43 #include <gtk/gtkvbox.h>
44 #include <gtk/gtkbutton.h>
46 #include <hildon-widgets/hildon-defines.h>
55 /* Can these be included from somewhere? */
57 #define OSSO_MEDIA_SERVICE "com.nokia.osso_media_server"
58 #define OSSO_MEDIA_PATH "/com/nokia/osso_media_server"
59 #define OSSO_MEDIA_INTERFACE "com.nokia.osso_media_server.sound"
60 #define OSSO_MEDIA_PLAY_METHOD "play_sound"
62 #define CONFIRMATION_SOUND_URI "file:///usr/share/sounds/"\
63 "ui-confirmation_note.wav"
64 #define CONFIRMATION_SOUND_PATH "/usr/share/sounds/ui-confirmation_note.wav"
66 #define INFORMATION_SOUND_URI "file:///usr/share/sounds/"\
67 "ui-information_note.wav"
68 #define INFORMATION_SOUND_PATH "/usr/share/sounds/ui-information_note.wav"
70 #define HILDON_NOTE_CONFIRMATION_ICON "qgn_note_confirm"
71 #define HILDON_NOTE_INFORMATION_ICON "qgn_note_info"
73 #define ELLIPSATION_STRING "\342\200\246"
74 #define BOX_SPACING 10
76 /* Not exactly sure what this actually _should_ be, because there is
77 practically no documentation for the ESD... */
79 #define ESD_NAME "hildon-note-instance"
81 #define _(String) dgettext(PACKAGE, String)
83 static GtkDialogClass *parent_class;
85 #define HILDON_NOTE_GET_PRIVATE(obj)\
86 (G_TYPE_INSTANCE_GET_PRIVATE ((obj), \
87 HILDON_TYPE_NOTE, HildonNotePrivate));
89 typedef struct _HildonNotePrivate HildonNotePrivate;
91 static void hildon_note_class_init(HildonNoteClass * class);
92 static void hildon_note_init(HildonNote * dialog);
94 static void hildon_note_create (HildonNote *note);
95 static void hildon_note_create_form(GtkDialog * dialog, GtkWidget * item,
96 gboolean IsHorizontal);
97 static void hildon_note_finalize(GObject * obj_self);
98 static void hildon_note_realize (GtkWidget *widget);
100 static GObject *hildon_note_constructor(GType type,
101 guint n_construct_properties,
102 GObjectConstructParam
103 * construct_properties);
104 static void hildon_note_set_property(GObject * object,
106 const GValue * value,
108 static void hildon_note_get_property(GObject * object,
110 GValue * value, GParamSpec * pspec);
113 sound_handling(GtkWidget * widget, gpointer data);
115 /* common measurement */
116 const int _HILDON_NOTE_CONFIRMATION_TEXT_MAX_WIDTH = 319;
118 struct _HildonNotePrivate {
120 GtkWidget *cancelButton;
124 HildonNoteType note_n;
125 GtkWidget *progressbar;
128 gchar *original_description;
130 gboolean constructed;
135 PROP_HILDON_NOTE_TYPE,
136 PROP_HILDON_NOTE_DESCRIPTION,
137 PROP_HILDON_NOTE_ICON,
138 PROP_HILDON_NOTE_PROGRESSBAR
141 gulong sound_signal_handler = 0;
143 /* This function is just a modified version of two_lines_truncate
144 * in gtk-infoprint.c */
146 hildon_note_five_line_truncate(const HildonNote * note, const gchar * text)
148 gchar *result = NULL;
150 PangoContext *context;
152 int max_width = _HILDON_NOTE_CONFIRMATION_TEXT_MAX_WIDTH;
153 HildonNotePrivate *priv;
155 priv = HILDON_NOTE_GET_PRIVATE(note);
157 if (priv->original_description != NULL)
158 g_free(priv->original_description);
160 priv->original_description = g_strdup(text);
165 str = g_strdup(text);
168 context = gtk_widget_get_pango_context(GTK_WIDGET(note));
171 gchar *lines[5] = { NULL, NULL, NULL, NULL, NULL };
172 guint current_line = 0;
175 layout = pango_layout_new(context);
176 pango_layout_set_text(layout, str, -1);
177 pango_layout_set_width(layout, max_width * PANGO_SCALE);
178 pango_layout_set_wrap(layout, PANGO_WRAP_WORD_CHAR);
179 last_line = MIN(4, pango_layout_get_line_count(layout) - 1);
181 for (current_line = 0;
182 current_line <= last_line;
184 PangoLayoutLine *line = pango_layout_get_line(layout,
187 if (current_line == last_line)
188 lines[current_line] = g_strdup(str + line->start_index);
190 lines[current_line] = g_strndup(str + line->start_index,
193 pango_layout_line_ref(line);
194 pango_layout_line_unref(line);
197 g_object_unref(layout);
199 layout = pango_layout_new(context);
200 pango_layout_set_text(layout, lines[last_line], -1);
203 PangoLayoutLine *line;
206 /* Here we ellipsize the last line... */
207 if (pango_layout_get_line_count(layout) > 1) {
208 gchar *templine = NULL;
210 line = pango_layout_get_line(layout, 0);
211 templine = g_strndup(lines[last_line], line->length);
212 g_free(lines[last_line]);
213 lines[last_line] = g_strconcat(templine, ELLIPSATION_STRING, NULL);
217 if (pango_layout_xy_to_index(layout,
218 max_width * PANGO_SCALE, 0,
219 &index, NULL) == TRUE) {
222 PangoLayout *ellipsis = pango_layout_new(context);
224 pango_layout_set_text(ellipsis, ELLIPSATION_STRING, -1);
225 pango_layout_get_size(ellipsis, &ellipsiswidth, NULL);
226 pango_layout_xy_to_index(layout,
227 max_width * PANGO_SCALE -
228 ellipsiswidth, 0, &index,
230 g_object_unref(G_OBJECT(ellipsis));
231 tempresult = g_strndup(lines[last_line], index);
232 lines[last_line] = g_strconcat(tempresult,
239 for (current_line = 0; current_line <= last_line; current_line++)
240 g_strchomp(lines[current_line]);
242 result = g_strconcat(lines[0], "\n",
246 lines[4], "\n", NULL);
248 for (current_line = 0; current_line <= last_line; current_line++)
249 g_free(lines[current_line]);
251 g_object_unref(layout);
256 result = g_strdup(str);
258 gtk_label_set_text(GTK_LABEL(priv->label), result);
266 hildon_note_one_line_truncate(const HildonNote * note, const gchar * text)
269 PangoContext *context;
271 int max_width = _HILDON_NOTE_CONFIRMATION_TEXT_MAX_WIDTH;
272 HildonNotePrivate *priv;
273 PangoLayoutLine *line;
276 priv = HILDON_NOTE_GET_PRIVATE(note);
278 if (priv->original_description != NULL)
279 g_free(priv->original_description);
281 priv->original_description = g_strdup(text);
283 str = g_strdup(text == NULL ? "" : text);
284 context = gtk_widget_get_pango_context(GTK_WIDGET(note));
286 layout = pango_layout_new(context);
287 pango_layout_set_text(layout, str, -1);
288 pango_layout_set_width(layout, max_width * PANGO_SCALE);
289 pango_layout_set_wrap(layout, PANGO_WRAP_WORD_CHAR);
291 if (pango_layout_get_line_count(layout) > 1) {
292 gchar *templine = NULL;
294 line = pango_layout_get_line(layout, 0);
295 templine = g_strndup(str, line->length);
297 str = g_strconcat(templine, ELLIPSATION_STRING, NULL);
301 if (pango_layout_xy_to_index(layout,
302 max_width * PANGO_SCALE, 0,
303 &index, NULL) == TRUE) {
306 PangoLayout *ellipsis = pango_layout_new(context);
308 pango_layout_set_text(ellipsis, ELLIPSATION_STRING, -1);
309 pango_layout_get_size(ellipsis, &ellipsiswidth, NULL);
310 pango_layout_xy_to_index(layout,
311 max_width * PANGO_SCALE -
312 ellipsiswidth, 0, &index,
314 g_object_unref(G_OBJECT(ellipsis));
315 tempresult = g_strndup(str, index);
316 str = g_strconcat(tempresult,
322 g_object_unref(layout);
323 gtk_label_set_text(GTK_LABEL(priv->label), str);
328 hildon_note_set_property(GObject * object,
330 const GValue * value, GParamSpec * pspec)
332 HildonNote *note = HILDON_NOTE(object);
333 HildonNotePrivate *priv;
335 priv = HILDON_NOTE_GET_PRIVATE(note);
338 case PROP_HILDON_NOTE_TYPE:
339 priv->note_n = g_value_get_enum(value);
340 if (priv->constructed) {
341 hildon_note_create (note);
345 case PROP_HILDON_NOTE_DESCRIPTION:
346 if (priv->note_n == HILDON_NOTE_PROGRESSBAR_TYPE)
347 hildon_note_one_line_truncate(note, g_value_get_string(value));
349 hildon_note_five_line_truncate(note, g_value_get_string(value));
352 case PROP_HILDON_NOTE_ICON:
355 priv->icon = g_value_dup_string(value);
356 if (priv->constructed) {
357 hildon_note_create (note);
361 case PROP_HILDON_NOTE_PROGRESSBAR:
362 priv->progressbar = g_value_get_object(value);
363 if (priv->constructed) {
364 hildon_note_create (note);
369 G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
375 hildon_note_get_property(GObject * object,
376 guint prop_id, GValue * value, GParamSpec * pspec)
378 HildonNote *note = HILDON_NOTE(object);
379 HildonNotePrivate *priv;
381 priv = HILDON_NOTE_GET_PRIVATE(note);
384 case PROP_HILDON_NOTE_TYPE:
385 g_value_set_enum(value, priv->note_n);
388 case PROP_HILDON_NOTE_DESCRIPTION:
389 if (priv->original_description != NULL) {
390 g_value_set_string(value, priv->original_description);
392 g_value_set_string(value, "");
396 case PROP_HILDON_NOTE_ICON:
397 g_value_set_string(value, priv->icon);
400 case PROP_HILDON_NOTE_PROGRESSBAR:
401 g_value_set_object(value, priv->progressbar);
405 G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
410 GType hildon_note_type_get_type (void)
412 static GType notetype = 0;
414 static const GEnumValue values[] = {
415 { HILDON_NOTE_CONFIRMATION_TYPE,
416 "HILDON_NOTE_CONFIRMATION_TYPE",
418 { HILDON_NOTE_CONFIRMATION_BUTTON_TYPE,
419 "HILDON_NOTE_CONFIRMATION_BUTTON_TYPE",
420 "confirmation-button" },
421 { HILDON_NOTE_INFORMATION_TYPE,
422 "HILDON_NOTE_INFORMATION_TYPE",
423 "note-information" },
424 { HILDON_NOTE_INFORMATION_THEME_TYPE,
425 "HILDON_NOTE_INFORMATION_THEME_TYPE",
426 "note-information-theme" },
427 { HILDON_NOTE_PROGRESSBAR_TYPE,
428 "HILDON_NOTE_PROGRESSBAR_TYPE",
429 "note-progressbar" },
432 notetype = g_enum_register_static ("HildonNoteType", values);
438 GType hildon_note_get_type()
440 static GType dialog_type = 0;
443 static const GTypeInfo dialog_info = {
444 sizeof(HildonNoteClass),
445 NULL, /* base_init */
446 NULL, /* base_finalize */
447 (GClassInitFunc) hildon_note_class_init,
448 NULL, /* class_finalize */
449 NULL, /* class_data */
452 (GInstanceInitFunc) hildon_note_init
454 dialog_type = g_type_register_static(GTK_TYPE_DIALOG,
461 static GObject *hildon_note_constructor(GType type,
462 guint n_construct_properties,
463 GObjectConstructParam *
464 construct_properties)
467 HildonNotePrivate *priv;
469 dialog = G_OBJECT_CLASS(parent_class)->constructor
470 (type, n_construct_properties, construct_properties);
471 priv = HILDON_NOTE_GET_PRIVATE(dialog);
473 hildon_note_create (HILDON_NOTE (dialog));
475 priv->constructed = TRUE;
480 static void hildon_note_class_init(HildonNoteClass * class)
482 GObjectClass *object_class = G_OBJECT_CLASS(class);
483 GtkWidgetClass *widget_class = GTK_WIDGET_CLASS(class);
485 /* set the global parent_class */
486 parent_class = g_type_class_peek_parent(class);
488 g_type_class_add_private(class, sizeof(HildonNotePrivate));
490 object_class->finalize = hildon_note_finalize;
492 object_class->set_property = hildon_note_set_property;
493 object_class->get_property = hildon_note_get_property;
494 object_class->constructor = hildon_note_constructor;
496 widget_class->realize = hildon_note_realize;
498 g_object_class_install_property(object_class,
499 PROP_HILDON_NOTE_TYPE,
500 g_param_spec_enum("note_type",
502 "The type of the note dialog",
503 hildon_note_type_get_type(),
504 HILDON_NOTE_CONFIRMATION_TYPE,
508 * HildonNote:description:
510 * Description for note.
512 g_object_class_install_property(object_class,
513 PROP_HILDON_NOTE_DESCRIPTION,
514 g_param_spec_string("description",
516 "The text that appears in the note dialog",
525 g_object_class_install_property(object_class,
526 PROP_HILDON_NOTE_ICON,
527 g_param_spec_string("icon",
529 "The name of the icon that appears in the note dialog",
534 * HildonNote:progressbar:
536 * Progresbar for note.
538 g_object_class_install_property(object_class,
539 PROP_HILDON_NOTE_PROGRESSBAR,
540 g_param_spec_object("progressbar",
541 "Progressbar widget",
542 "The progressbar that appear in the note dialog",
543 GTK_TYPE_PROGRESS_BAR,
547 static void hildon_note_init(HildonNote * dialog)
549 HildonNotePrivate *priv = HILDON_NOTE_GET_PRIVATE(dialog);
551 priv->label = gtk_label_new(NULL);
552 priv->original_description = NULL;
555 gtk_dialog_set_has_separator(GTK_DIALOG(dialog), FALSE);
556 gtk_window_set_modal(GTK_WINDOW(dialog), TRUE);
558 /* Because ESD is synchronous, we wish to play sound after the
559 note is already on screen to avoid blocking its appearance */
560 sound_signal_handler =
561 g_signal_connect_after(G_OBJECT(dialog), "expose-event",
562 G_CALLBACK(sound_handling), dialog);
566 static void hildon_note_finalize(GObject * obj_self)
568 HildonNotePrivate *priv = HILDON_NOTE_GET_PRIVATE(obj_self);
573 if (priv->original_description != NULL)
574 g_free(priv->original_description);
576 G_OBJECT_CLASS(parent_class)->finalize(obj_self);
580 hildon_note_realize (GtkWidget *widget)
582 GTK_WIDGET_CLASS (parent_class)->realize (widget);
584 gdk_window_set_decorations (widget->window, GDK_DECOR_BORDER);
588 hildon_note_create (HildonNote *note)
590 HildonNotePrivate *priv;
591 GtkWidget *item = NULL;
592 gboolean IsHorizontal = TRUE;
594 priv = HILDON_NOTE_GET_PRIVATE (note);
596 if (priv->okButton) {
597 gtk_container_remove (GTK_CONTAINER (priv->okButton->parent),
599 priv->okButton = NULL;
602 if (priv->cancelButton) {
603 gtk_container_remove (GTK_CONTAINER (priv->cancelButton->parent),
605 priv->cancelButton = NULL;
608 if (priv->progressbar && priv->progressbar->parent) {
609 gtk_container_remove (GTK_CONTAINER (priv->progressbar->parent),
611 priv->progressbar = NULL;
614 if (priv->note_n == HILDON_NOTE_CONFIRMATION_TYPE ||
615 priv->note_n == HILDON_NOTE_CONFIRMATION_BUTTON_TYPE ||
616 priv->note_n == HILDON_NOTE_INFORMATION_THEME_TYPE ||
617 priv->note_n == HILDON_NOTE_INFORMATION_TYPE) {
619 if (priv->note_n == HILDON_NOTE_CONFIRMATION_TYPE) {
620 /* ok button clickable with mouse or whatever */
622 gtk_dialog_add_button(GTK_DIALOG(note),
623 _("Ecdg_bd_confirmation_note_ok"),
625 /* cancel button clickable with mouse or whatever */
627 gtk_dialog_add_button(GTK_DIALOG(note),
628 _("Ecdg_bd_confirmation_note_cancel"),
629 GTK_RESPONSE_CANCEL);
631 } else if (priv->note_n == HILDON_NOTE_INFORMATION_TYPE ||
632 priv->note_n == HILDON_NOTE_INFORMATION_THEME_TYPE ) {
633 priv->okButton = NULL;
634 /* cancel button clickable with mouse or whatever */
636 gtk_dialog_add_button(GTK_DIALOG(note),
637 _("Ecdg_bd_information_note_ok"),
638 GTK_RESPONSE_CANCEL);
641 if ((priv->note_n == HILDON_NOTE_INFORMATION_TYPE ||
642 priv->note_n == HILDON_NOTE_INFORMATION_THEME_TYPE) &&
645 item = gtk_image_new_from_icon_name(priv->icon,
646 HILDON_ICON_SIZE_BIG_NOTE);
649 if (priv->note_n == HILDON_NOTE_CONFIRMATION_TYPE ||
650 priv->note_n == HILDON_NOTE_CONFIRMATION_BUTTON_TYPE)
652 item = gtk_image_new_from_icon_name(HILDON_NOTE_CONFIRMATION_ICON,
653 HILDON_ICON_SIZE_BIG_NOTE);
655 item = gtk_image_new_from_icon_name(HILDON_NOTE_INFORMATION_ICON,
656 HILDON_ICON_SIZE_BIG_NOTE);
662 gtk_dialog_add_button(GTK_DIALOG(note),
663 _("Ecdg_bd_cancel_note_cancel"),
664 GTK_RESPONSE_CANCEL);
665 IsHorizontal = FALSE;
667 item = priv->progressbar;
670 hildon_note_create_form(GTK_DIALOG(note), item, IsHorizontal);
674 hildon_note_create_form(GtkDialog * dialog, GtkWidget * item,
675 gboolean IsHorizontal)
677 HildonNotePrivate *priv = HILDON_NOTE_GET_PRIVATE(dialog);
679 g_object_ref (priv->label);
681 if (priv->label->parent) {
682 gtk_container_remove (GTK_CONTAINER (priv->label->parent), priv->label);
686 gtk_container_remove (GTK_CONTAINER (priv->box->parent), priv->box);
691 priv->box = gtk_hbox_new(FALSE, BOX_SPACING);
692 gtk_container_add(GTK_CONTAINER(dialog->vbox), priv->box);
695 GtkWidget *alignment = gtk_alignment_new(0, 0, 0, 0);
697 gtk_box_pack_start(GTK_BOX(priv->box), alignment, FALSE, FALSE, 0);
698 gtk_container_add(GTK_CONTAINER(alignment), item);
700 gtk_box_pack_start(GTK_BOX(priv->box), priv->label, FALSE, FALSE, 0);
703 priv->box = gtk_vbox_new(FALSE, BOX_SPACING);
704 gtk_container_add(GTK_CONTAINER(dialog->vbox), priv->box);
705 gtk_box_pack_start(GTK_BOX(priv->box), priv->label, FALSE, FALSE, 0);
708 gtk_box_pack_start(GTK_BOX(priv->box), item, FALSE, FALSE, 0);
712 gtk_widget_show_all(priv->box);
714 g_object_unref (priv->label);
718 * hildon_note_new_confirmation_add_buttons:
719 * @parent: The parent window. The X window ID of the parent window
720 * has to be the same as the X window ID of the application. This is
721 * important so that the window manager could handle the windows
723 * In GTK the X window ID can be checked with
724 * GDK_WINDOW_XID(GTK_WIDGET(parent)->window).
725 * @description: The message to confirm.
726 * @Varargs: Arguments pairs for new buttons(label and return value)
728 * Create a new confirmation note. Confirmation note has a text,
729 * two buttons and infinite number of additional buttons and an icon.
731 * Return value: A #GtkWidget pointer of the note.
733 GtkWidget *hildon_note_new_confirmation_add_buttons(GtkWindow * parent,
741 GtkWidget *conf_note =
742 g_object_new(HILDON_TYPE_NOTE,
743 "note_type", HILDON_NOTE_CONFIRMATION_BUTTON_TYPE,
744 "description", description,
745 "icon", HILDON_NOTE_CONFIRMATION_ICON,
748 g_return_val_if_fail(conf_note, FALSE);
751 gtk_window_set_transient_for(GTK_WINDOW(conf_note), parent);
753 va_start(args, description);
756 message = va_arg(args, char *);
761 value = va_arg(args, int);
763 gtk_dialog_add_button(GTK_DIALOG(conf_note), message, value);
773 * hildon_note_new_confirmation:
774 * @parent: The parent window. The X window ID of the parent window
775 * has to be the same as the X window ID of the application. This is
776 * important so that the window manager could handle the windows
777 * correctly. In GTK the X window ID can be checked with
778 * GDK_WINDOW_XID(GTK_WIDGET(parent)->window).
779 * @description: The message to confirm.
781 * Create a new confirmation note. Confirmation note has a text,
782 * two buttons and an default confirmation stock icon.
784 * Return value: A #GtkWidget pointer of the note.
786 GtkWidget *hildon_note_new_confirmation(GtkWindow * parent,
787 const gchar * description)
789 return hildon_note_new_confirmation_with_icon_name
790 (parent, description, HILDON_NOTE_CONFIRMATION_ICON);
795 * hildon_note_new_confirmation_with_icon_stock:
796 * @parent: The parent window. The X window ID of the parent window
797 * has to be the same as the X window ID of the application. This is
798 * important so that the window manager could handle the windows
799 * correctly. In GTK the X window ID can be checked with
800 * GDK_WINDOW_XID(GTK_WIDGET(parent)->window).
801 * @description: The message to confirm.
802 * @stock_id: Icon to be displayed. If NULL, default icon is used.
804 * Create a new confirmation note. Confirmation note has a text,
805 * two buttons and an icon.
807 * Return value: A #GtkWidget pointer of the note.
809 GtkWidget *hildon_note_new_confirmation_with_icon_stock(GtkWindow * parent,
815 GtkWidget *dialog = g_object_new(HILDON_TYPE_NOTE,
817 HILDON_NOTE_CONFIRMATION_TYPE,
818 "description", description, "icon",
822 gtk_window_set_transient_for(GTK_WINDOW(dialog), parent);
828 * hildon_note_new_confirmation_with_icon_name:
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
832 * correctly. In GTK the X window ID can be checked with
833 * GDK_WINDOW_XID(GTK_WIDGET(parent)->window).
834 * @description: The message to confirm.
835 * @icon_name: Icon to be displayed. If NULL, default icon is used.
837 * Create a new confirmation note. Confirmation note has a text,
838 * two buttons and an icon.
840 * Return value: A #GtkWidget pointer of the note.
842 GtkWidget *hildon_note_new_confirmation_with_icon_name(GtkWindow * parent,
848 GtkWidget *dialog = g_object_new(HILDON_TYPE_NOTE,
850 HILDON_NOTE_CONFIRMATION_TYPE,
851 "description", description, "icon",
855 gtk_window_set_transient_for(GTK_WINDOW(dialog), parent);
861 * hildon_note_new_information:
862 * @parent: The parent window. The X window ID of the parent window
863 * has to be the same as the X window ID of the application. This is
864 * important so that the window manager could handle the windows
865 * correctly. In GTK the X window ID can be checked with
866 * GDK_WINDOW_XID(GTK_WIDGET(parent)->window).
867 * @description: The message to confirm.
869 * Create a new information note. Information note has a text,
870 * 'OK' labeled button and an icon.
872 * Return value: A #GtkWidget pointer of the note.
874 GtkWidget *hildon_note_new_information(GtkWindow * parent,
875 const gchar * description)
877 return hildon_note_new_information_with_icon_stock
878 (parent, description, "qgn_note_info");
882 * hildon_note_new_information_with_icon_stock:
883 * @parent: The parent window. The X window ID of the parent window
884 * has to be the same as the X window ID of the application. This is
885 * important so that the window manager could handle the windows
886 * correctly. In GTK the X window ID can be checked with
887 * GDK_WINDOW_XID(GTK_WIDGET(parent)->window).
888 * @description: The message to confirm.
889 * @stock_id: Icon to be displayed. If NULL, default icon is used.
891 * Create a new information note. Information note has a text,
892 * 'OK' labeled button and an icon.
894 * Return value: A #GtkWidget pointer of the note.
896 GtkWidget *hildon_note_new_information_with_icon_stock(GtkWindow * parent,
902 GtkWidget *dialog = g_object_new(HILDON_TYPE_NOTE,
904 HILDON_NOTE_INFORMATION_TYPE,
905 "description", description,
906 "icon", stock_id, NULL);
909 gtk_window_set_transient_for(GTK_WINDOW(dialog), parent);
915 * hildon_note_new_information_with_icon_name:
916 * @parent: The parent window. The X window ID of the parent window
917 * has to be the same as the X window ID of the application. This is
918 * important so that the window manager could handle the windows
919 * correctly. In GTK the X window ID can be checked with
920 * GDK_WINDOW_XID(GTK_WIDGET(parent)->window).
921 * @description: The message to confirm.
922 * @icon_name: Icon to be displayed. If NULL, default icon is used.
924 * Create a new information note. Information note has a text,
925 * 'OK' labeled button and an icon.
927 * Return value: A #GtkWidget pointer of the note.
929 GtkWidget *hildon_note_new_information_with_icon_name(GtkWindow * parent,
935 GtkWidget *dialog = g_object_new(HILDON_TYPE_NOTE,
937 HILDON_NOTE_INFORMATION_THEME_TYPE,
938 "description", description,
939 "icon", icon_name, NULL);
942 gtk_window_set_transient_for(GTK_WINDOW(dialog), parent);
948 * hildon_note_new_information_with_icon_theme:
949 * @parent: The parent window. The X window ID of the parent window
950 * has to be the same as the X window ID of the application. This is
951 * important so that the window manager could handle the windows
952 * correctly. In GTK the X window ID can be checked with
953 * GDK_WINDOW_XID(GTK_WIDGET(parent)->window).
954 * @description: The message to confirm.
955 * @icon: #GtkIconTheme icon to be displayed.
957 * Create a new information note. Information note has a text,
958 * 'OK' labeled button and an icon.
960 * Return value: A #GtkWidget pointer of the note.
961 * If NULL, default icon is used.
963 GtkWidget *hildon_note_new_information_with_icon_theme(GtkWindow *parent,
964 const gchar *description,
967 GtkWidget *dialog = g_object_new(HILDON_TYPE_NOTE,
969 HILDON_NOTE_INFORMATION_THEME_TYPE,
970 "description", description,
974 gtk_window_set_transient_for(GTK_WINDOW(dialog), parent);
980 * hildon_note_new_cancel_with_progress_bar:
981 * @parent: The parent window. The X window ID of the parent window
982 * has to be the same as the X window ID of the application. This is
983 * important so that the window manager could handle the windows
984 * correctly. In GTK the X window ID can be checked with
985 * GDK_WINDOW_XID(GTK_WIDGET(parent)->window).
986 * @description: The action to cancel.
987 * @progressbar: A pointer to #GtkProgressBar to be filled with the
988 * progressbar assigned to this note. Use this to set the fraction of
991 * Create a new cancel note with a progress bar. The note has a text,
992 * 'Cancel' labeled button and a progress bar.
994 * Return value: A #GtkDialog. Use this to get rid of this note when you
997 GtkWidget *hildon_note_new_cancel_with_progress_bar(GtkWindow * parent,
1003 GtkWidget *dialog = g_object_new(HILDON_TYPE_NOTE,
1005 HILDON_NOTE_PROGRESSBAR_TYPE,
1006 "description", description,
1011 gtk_window_set_transient_for(GTK_WINDOW(dialog), parent);
1018 * hildon_note_set_button_text:
1019 * @note: A #HildonNote
1020 * @text: Sets the button text and if there is two buttons in dialog,
1021 * the button texts will be <text>, "Cancel".
1023 * Sets the button text to be used by this hildon_note widget.
1025 void hildon_note_set_button_text(HildonNote * note, const gchar * text)
1027 HildonNotePrivate *priv;
1029 priv = HILDON_NOTE_GET_PRIVATE(HILDON_NOTE(note));
1030 if (priv->okButton) {
1031 gtk_button_set_label(GTK_BUTTON(priv->okButton), text);
1032 gtk_button_set_label(GTK_BUTTON(priv->cancelButton),
1033 _("Ecdg_bd_confirmation_note_cancel"));
1035 gtk_button_set_label(GTK_BUTTON(priv->cancelButton), text);
1040 * hildon_note_set_button_texts:
1041 * @note: A #HildonNote
1042 * @text: Sets the button text and if there is two buttons in dialog,
1043 * the button texts will be <textOk>, <textCancel>.
1045 * Sets the button texts to be used by this hildon_note widget.
1047 void hildon_note_set_button_texts(HildonNote * note, const gchar * textOk,
1048 const gchar * textCancel)
1050 HildonNotePrivate *priv;
1052 priv = HILDON_NOTE_GET_PRIVATE(HILDON_NOTE(note));
1053 if (priv->okButton) {
1054 gtk_button_set_label(GTK_BUTTON(priv->okButton), textOk);
1055 gtk_button_set_label(GTK_BUTTON(priv->cancelButton),
1058 gtk_button_set_label(GTK_BUTTON(priv->cancelButton), textCancel);
1065 sound_handling(GtkWidget * widget, gpointer data)
1068 HildonNotePrivate *priv = HILDON_NOTE_GET_PRIVATE(HILDON_NOTE(widget));
1070 if (priv->note_n != HILDON_NOTE_INFORMATION_TYPE &&
1071 priv->note_n != HILDON_NOTE_INFORMATION_THEME_TYPE &&
1072 priv->note_n != HILDON_NOTE_CONFIRMATION_TYPE &&
1073 priv->note_n != HILDON_NOTE_CONFIRMATION_BUTTON_TYPE)
1075 g_signal_handler_disconnect(G_OBJECT(widget),
1076 sound_signal_handler);
1080 if (priv->note_n == HILDON_NOTE_INFORMATION_TYPE ||
1081 priv->note_n == HILDON_NOTE_INFORMATION_THEME_TYPE)
1083 esd_play_file(ESD_NAME, INFORMATION_SOUND_PATH, 1);
1085 g_signal_handler_disconnect(G_OBJECT(widget), sound_signal_handler);
1089 else if (priv->note_n == HILDON_NOTE_CONFIRMATION_TYPE ||
1090 priv->note_n == HILDON_NOTE_CONFIRMATION_BUTTON_TYPE)
1092 esd_play_file(ESD_NAME, CONFIRMATION_SOUND_PATH, 1);
1094 g_signal_handler_disconnect(G_OBJECT(widget), sound_signal_handler);
1097 g_signal_handler_disconnect(G_OBJECT(widget), sound_signal_handler);