X-Git-Url: http://git.maemo.org/git/?a=blobdiff_plain;f=src%2Fhildon2%2Fmodest-maemo-utils.c;h=585f35b5d77eee4a5eaf67aa5aab5a627d5d96e0;hb=6e0ed95f0118e1954676abdade7dc00d4b7cb2fd;hp=d1a10c7a41802c75077c2c36cb0831dfeb2b7c1e;hpb=a7be4d9c27d5a6074f3a1701b12bcc2c45887022;p=modest diff --git a/src/hildon2/modest-maemo-utils.c b/src/hildon2/modest-maemo-utils.c index d1a10c7..585f35b 100644 --- a/src/hildon2/modest-maemo-utils.c +++ b/src/hildon2/modest-maemo-utils.c @@ -51,6 +51,7 @@ #include "modest-maemo-utils.h" #include "modest-text-utils.h" #include "modest-platform.h" +#include "modest-ui-constants.h" /* * For getting and tracking the Bluetooth name @@ -67,6 +68,9 @@ #define BTNAME_MATCH_RULE "type='signal',interface='" BTNAME_SIGNAL_IF \ "',member='" BTNAME_SIG_CHANGED "'" +/* Label child of a captioned */ +#define CAPTIONED_LABEL_CHILD "captioned-label" + static osso_context_t *__osso_context = NULL; /* urgh global */ @@ -202,8 +206,7 @@ modest_maemo_utils_setup_images_filechooser (GtkFileChooser *chooser) g_return_if_fail (GTK_IS_FILE_CHOOSER (chooser)); /* Set the default folder to images folder */ - images_folder = g_build_filename (g_get_home_dir (), - MODEST_MAEMO_UTILS_MYDOCS_FOLDER, + images_folder = g_build_filename (g_getenv (MODEST_MAEMO_UTILS_MYDOCS_ENV), MODEST_MAEMO_UTILS_DEFAULT_IMAGE_FOLDER, NULL); gtk_file_chooser_set_current_folder (chooser, images_folder); g_free (images_folder); @@ -288,3 +291,171 @@ modest_maemo_utils_get_manager_menubar_as_menu (GtkUIManager *manager, return new_menu; } + +/** + * modest_maemo_utils_create_captioned: + * @title_size_group: a #GtkSizeGroup + * @value_size_group: a #GtkSizeGroup + * @title: a string + * @control: a #GtkWidget + * + * this creates a widget (a #GtkHBox) with a control, and a label + * (@string) captioning it. It also uses the proper size groups for title + * and control. + * + * Returns: a widget containing the control and a proper label. + */ +GtkWidget * +modest_maemo_utils_create_captioned (GtkSizeGroup *title_size_group, + GtkSizeGroup *value_size_group, + const gchar *title, + gboolean use_markup, + GtkWidget *control) +{ + return modest_maemo_utils_create_captioned_with_size_type (title_size_group, + value_size_group, + title, + use_markup, + control, + HILDON_SIZE_FINGER_HEIGHT | HILDON_SIZE_AUTO_WIDTH); +} + +/** + * modest_maemo_utils_create_captioned_with_size_type: + * @title_size_group: a #GtkSizeGroup + * @value_size_group: a #GtkSizeGroup + * @title: a string + * @control: a #GtkWidget + * @size_type: a #HildonSizeType + * + * this creates a widget (a #GtkHBox) with a control, and a label + * (@string) captioning it. It also uses the proper size groups for title + * and control. + * + * Returns: a widget containing the control and a proper label. + */ +GtkWidget * +modest_maemo_utils_create_captioned_with_size_type (GtkSizeGroup *title_size_group, + GtkSizeGroup *value_size_group, + const gchar *title, + gboolean use_markup, + GtkWidget *control, + HildonSizeType size_type) +{ + GtkWidget *label; + GtkWidget *box; + + if (use_markup) { + label = gtk_label_new (NULL); + gtk_label_set_markup (GTK_LABEL (label), title); + } else { + label = gtk_label_new (title); + } + + gtk_label_set_line_wrap (GTK_LABEL (label), TRUE); + hildon_gtk_widget_set_theme_size (label, HILDON_SIZE_FINGER_HEIGHT); + gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5); + gtk_widget_show (label); + box = gtk_hbox_new (FALSE, MODEST_MARGIN_HALF); + gtk_box_pack_start (GTK_BOX (box), label, FALSE, FALSE, MODEST_MARGIN_HALF); + gtk_box_pack_start (GTK_BOX (box), control, TRUE, TRUE, MODEST_MARGIN_HALF); + if (title_size_group) + gtk_size_group_add_widget (title_size_group, label); + if (value_size_group) + gtk_size_group_add_widget (value_size_group, control); + + hildon_gtk_widget_set_theme_size (control, size_type); + + g_object_set_data (G_OBJECT (box), CAPTIONED_LABEL_CHILD, label); + + return box; +} + +/** + * modest_maemo_utils_captioned_set_label: + * @captioned: a #GtkWidget built as captioned + * @new_label: a string + * @use_markup: a #gboolean + * + * set a new label for the captioned + */ +void +modest_maemo_utils_captioned_set_label (GtkWidget *captioned, + const gchar *new_label, + gboolean use_markup) +{ + GtkWidget *label; + + g_return_if_fail (GTK_IS_WIDGET (captioned)); + + label = g_object_get_data (G_OBJECT (captioned), CAPTIONED_LABEL_CHILD); + g_return_if_fail (GTK_IS_LABEL (label)); + + if (use_markup) { + gtk_label_set_markup (GTK_LABEL (label), new_label); + } else { + gtk_label_set_text (GTK_LABEL (label), new_label); + } +} + +/** + * modest_maemo_utils_set_hbutton_layout: + * @title_sizegroup: a #GtkSizeGroup, or %NULL + * @value_sizegroup: a #GtkSizeGroup, or %NULL + * @title: a string + * @button: a #HildonButton + * + * Configures the alignment and layout of @button. If @title_sizegroup is provided, + * the title will be aligned to the left using it. If @value_sizegroup is provided, + * the value will be aligned to the left using it. It also sets the title + * of the button. + * + * The alignment is left for the title and for the value. + */ +void +modest_maemo_utils_set_hbutton_layout (GtkSizeGroup *title_sizegroup, + GtkSizeGroup *value_sizegroup, + const gchar *title, + GtkWidget *button) +{ + hildon_button_set_title (HILDON_BUTTON (button), title); + if (title_sizegroup) + hildon_button_add_title_size_group (HILDON_BUTTON (button), title_sizegroup); + if (value_sizegroup) + hildon_button_add_value_size_group (HILDON_BUTTON (button), value_sizegroup); + hildon_button_set_alignment (HILDON_BUTTON (button), 0.0, 0.5, 1.0, 0.0); + hildon_button_set_title_alignment (HILDON_BUTTON (button), 0.0, 0.5); + hildon_button_set_value_alignment (HILDON_BUTTON (button), 0.0, 0.5); +} + +void +modest_maemo_utils_set_vbutton_layout (GtkSizeGroup *sizegroup, + const gchar *title, + GtkWidget *button) +{ + hildon_button_set_title (HILDON_BUTTON (button), title); + if (sizegroup) { + hildon_button_add_title_size_group (HILDON_BUTTON (button), sizegroup); + hildon_button_add_value_size_group (HILDON_BUTTON (button), sizegroup); + } + hildon_button_set_alignment (HILDON_BUTTON (button), 0.0, 0.5, 1.0, 0.0); + hildon_button_set_title_alignment (HILDON_BUTTON (button), 0.0, 0.5); + hildon_button_set_value_alignment (HILDON_BUTTON (button), 0.0, 0.5); +} + +GtkWidget * +modest_maemo_utils_create_group_box (const gchar *label_text, GtkWidget *contents) +{ + GtkWidget *label; + GtkWidget *box; + + label = gtk_label_new (label_text); + gtk_widget_show (label); + + box = gtk_vbox_new (FALSE, MODEST_MARGIN_HALF); + gtk_box_pack_start (GTK_BOX (box), label, FALSE, FALSE, 0); + gtk_box_pack_start (GTK_BOX (box), contents, TRUE, TRUE, 0); + gtk_widget_show (box); + + return box; +}