#include "modest-platform.h"
#include "modest-ui-constants.h"
#include <hildon/hildon-picker-dialog.h>
+#ifdef MODEST_USE_IPHB
+#include <iphbd/libiphb.h>
+#endif
/* Label child of a captioned */
#define CAPTIONED_LABEL_CHILD "captioned-label"
/* Set the images mime filter */
file_filter = gtk_file_filter_new ();
-#ifdef MODEST_HAVE_HILDON0_WIDGETS
- image_mimetypes_list = osso_mime_get_mime_types_for_category (OSSO_MIME_CATEGORY_IMAGES);
-#else
image_mimetypes_list = hildon_mime_get_mime_types_for_category (HILDON_MIME_CATEGORY_IMAGES);
-#endif
for (node = image_mimetypes_list; node != NULL; node = g_list_next (node)) {
gtk_file_filter_add_mime_type (file_filter, node->data);
}
gtk_file_chooser_set_filter (chooser, file_filter);
-#ifdef MODEST_HAVE_HILDON0_WIDGETS
- osso_mime_types_list_free (image_mimetypes_list);
-#else
hildon_mime_types_list_free (image_mimetypes_list);
-#endif
}
-void
-modest_maemo_set_thumbable_scrollbar (GtkScrolledWindow *win,
- gboolean thumbable)
+#ifdef MODEST_PLATFORM_MAEMO
+gboolean
+modest_maemo_utils_in_usb_mode ()
{
- g_return_if_fail (GTK_IS_SCROLLED_WINDOW(win));
-#ifdef MODEST_HAVE_HILDON1_WIDGETS
- hildon_helper_set_thumb_scrollbar (win, thumbable);
-#endif /* MODEST_HAVE_HILDON1_WIDGETS */
+ return modest_conf_get_bool (modest_runtime_get_conf (), INTERNAL_MMC_USB_MODE, NULL);
}
+#endif
-GtkWidget *
-modest_maemo_utils_get_manager_menubar_as_menu (GtkUIManager *manager,
- const gchar *item_name)
-{
- GtkWidget *new_menu;
- GtkWidget *menubar;
- GList *children, *iter;
-
- menubar = gtk_ui_manager_get_widget (manager, item_name);
- new_menu = gtk_menu_new ();
-
- children = gtk_container_get_children (GTK_CONTAINER (menubar));
- for (iter = children; iter != NULL; iter = g_list_next (iter)) {
- GtkWidget *menu;
-
- menu = GTK_WIDGET (iter->data);
- gtk_widget_reparent (menu, new_menu);
- }
-
- g_list_free (children);
+#ifdef MODEST_USE_IPHB
- return new_menu;
-}
+typedef struct _ModestHeartbeatSource {
+ GSource source;
+ iphb_t iphb;
+ GPollFD poll;
+ gint interval;
+} ModestHeartbeatSource;
-/**
- * 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)
+static gboolean modest_heartbeat_prepare (GSource* source, gint *timeout)
{
- return modest_maemo_utils_create_captioned_with_size_type (title_size_group,
- value_size_group,
- title,
- use_markup,
- control,
- 0);
+ *timeout = -1;
+ return FALSE;
}
-/**
- * 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)
+static gboolean
+modest_heartbeat_check(GSource* source)
{
- GtkWidget *label;
- GtkWidget *align;
- GtkWidget *box;
-
- if (use_markup) {
- label = gtk_label_new (NULL);
- gtk_label_set_markup (GTK_LABEL (label), title);
- } else {
- label = gtk_label_new (title);
- }
- align = gtk_alignment_new (0.0, 0.0, 1.0, 1.0);
- gtk_alignment_set_padding (GTK_ALIGNMENT (align), 0, 0, MODEST_MARGIN_DOUBLE, MODEST_MARGIN_DOUBLE);
-
- 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);
- gtk_widget_show (align);
- box = gtk_hbox_new (FALSE, 0);
- gtk_container_add (GTK_CONTAINER (align), label);
- gtk_box_pack_start (GTK_BOX (box), align, FALSE, FALSE, 0);
- gtk_box_pack_start (GTK_BOX (box), control, TRUE, TRUE, 0);
- 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;
+ return ((ModestHeartbeatSource *) source)->poll.revents != 0;
}
-/**
- * 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)
+static gboolean modest_heartbeat_dispatch (GSource *source, GSourceFunc callback, gpointer userdata)
{
- 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);
- }
-}
+ if (callback(userdata))
+ {
+ ModestHeartbeatSource *hb_source = (ModestHeartbeatSource *) source;
-/**
- * modest_maemo_utils_captioned_get_label_widget:
- * @captioned: a #GtkWidget built as captioned
- *
- * obtains the label widget for the captioned
- *
- * Returns: a #GtkLabel
- */
-GtkWidget *
-modest_maemo_utils_captioned_get_label_widget (GtkWidget *captioned)
-{
- GtkWidget *label;
+ g_source_remove_poll (source, &(hb_source->poll));
- g_return_val_if_fail (GTK_IS_WIDGET (captioned), NULL);
+ int min = MAX(hb_source->interval - 30, 5);
+ iphb_wait(hb_source->iphb, min, min + 60, 0);
- label = g_object_get_data (G_OBJECT (captioned), CAPTIONED_LABEL_CHILD);
- g_return_val_if_fail (GTK_IS_LABEL (label), NULL);
+ hb_source->poll.fd = iphb_get_fd(hb_source->iphb);
+ hb_source->poll.events = G_IO_IN;
+ hb_source->poll.revents = 0;
- return label;
+ g_source_add_poll(source, &(hb_source->poll));
+ return TRUE;
+ } else {
+ return FALSE;
+ }
}
-/**
- * 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)
+static void
+modest_heartbeat_finalize (GSource* source)
{
- 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);
+ ModestHeartbeatSource* hb_source = (ModestHeartbeatSource *) source;
+ hb_source->iphb = iphb_close(hb_source->iphb);
}
-void
-modest_maemo_utils_set_vbutton_layout (GtkSizeGroup *sizegroup,
- const gchar *title,
- GtkWidget *button)
+GSourceFuncs modest_heartbeat_funcs =
{
- 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)
+ modest_heartbeat_prepare,
+ modest_heartbeat_check,
+ modest_heartbeat_dispatch,
+ modest_heartbeat_finalize,
+ NULL,
+ NULL
+};
+
+static GSource *
+modest_heartbeat_source_new (void)
{
- GtkWidget *label;
- GtkWidget *box;
+ GSource *source;
+ ModestHeartbeatSource *hb_source;
+ iphb_t iphb;
+ int hb_interval;
- label = gtk_label_new (label_text);
- gtk_widget_show (label);
+ source = NULL;
+ hb_interval = 0;
- 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);
+ iphb = iphb_open (&hb_interval);
- return box;
-}
+ if (iphb != 0) {
+ int min;
+ source = g_source_new (&modest_heartbeat_funcs, sizeof (ModestHeartbeatSource));
+ hb_source = (ModestHeartbeatSource *) source;
+ g_source_set_priority (source, G_PRIORITY_DEFAULT_IDLE);
+ hb_source->iphb = iphb;
+ hb_source->interval = hb_interval;
-static gboolean match_all (TnyList *list, GObject *item, gpointer match_data)
-{
- return TRUE;
-}
+ min = MAX(hb_interval - 30, 5);
+ iphb_wait(hb_source->iphb, min, min + 60, 0);
-gboolean
-modest_maemo_utils_select_attachments (GtkWindow *window, TnyList *att_list, gboolean include_msgs)
-{
- GtkTreeModel *model;
- TnyIterator *iterator;
- GtkWidget *selector;
- GtkCellRenderer *renderer;
- GtkWidget *dialog;
- gint response;
- gboolean result = TRUE;
- gint attachments_added = 0;
-
- model = GTK_TREE_MODEL (gtk_list_store_new (2, G_TYPE_STRING, G_TYPE_OBJECT));
- for (iterator = tny_list_create_iterator (att_list);
- !tny_iterator_is_done (iterator);
- tny_iterator_next (iterator)) {
- GtkTreeIter iter;
- TnyMimePart *part;
- gchar *filename = NULL;
-
- part = (TnyMimePart *) tny_iterator_get_current (iterator);
-
- /* Ignore purged attachments and messages if ignore is
- set to TRUE */
- if (!(tny_mime_part_is_purged (part) ||
- (TNY_IS_MSG (part) && !include_msgs))) {
-
- if (TNY_IS_MSG (part)) {
- TnyHeader *header = tny_msg_get_header (TNY_MSG (part));
- filename = tny_header_dup_subject (header);
- g_object_unref (header);
- } else {
- filename = g_strdup (tny_mime_part_get_filename (part));
- }
- if ((filename == NULL) || (filename[0] == '\0')) {
- g_free (filename);
- filename = g_strdup (_("mail_va_no_subject"));
- }
- gtk_list_store_append (GTK_LIST_STORE (model), &iter);
- gtk_list_store_set (GTK_LIST_STORE (model), &iter, 0, filename, 1, part, -1);
- attachments_added ++;
- g_free (filename);
- }
- g_object_unref (part);
- }
- g_object_unref (iterator);
-
- selector = GTK_WIDGET (hildon_touch_selector_new ());
- renderer = gtk_cell_renderer_text_new ();
- hildon_touch_selector_append_column (HILDON_TOUCH_SELECTOR (selector), model, renderer,
- "text", 0, NULL);
- hildon_touch_selector_set_column_selection_mode (HILDON_TOUCH_SELECTOR (selector),
- HILDON_TOUCH_SELECTOR_SELECTION_MODE_MULTIPLE);
-
- dialog = hildon_picker_dialog_new (window);
- gtk_window_set_title (GTK_WINDOW (dialog), (attachments_added > 1)?
- _("mcen_ti_select_attachments_title"):_("mcen_ti_select_attachment_title"));
- hildon_picker_dialog_set_selector (HILDON_PICKER_DIALOG (dialog), HILDON_TOUCH_SELECTOR (selector));
- hildon_picker_dialog_set_done_label (HILDON_PICKER_DIALOG (dialog), _HL("wdgt_bd_done"));
-
- response = gtk_dialog_run (GTK_DIALOG (dialog));
-
- if (response == GTK_RESPONSE_OK) {
- GList *selected_rows, *node;
-
- tny_list_remove_matches (att_list, match_all, NULL);
- selected_rows = hildon_touch_selector_get_selected_rows (HILDON_TOUCH_SELECTOR (selector), 0);
- for (node = selected_rows; node != NULL; node = g_list_next (node)) {
- GtkTreePath *path;
- GObject *selected;
- GtkTreeIter iter;
-
- path = (GtkTreePath *) node->data;
- gtk_tree_model_get_iter (model, &iter, path);
- gtk_tree_model_get (model, &iter, 1, &selected, -1);
- tny_list_append (att_list, selected);
- }
- if (tny_list_get_length (att_list) == 0)
- result = FALSE;
+ hb_source->poll.fd = iphb_get_fd(hb_source->iphb);
+ hb_source->poll.events = G_IO_IN;
+ hb_source->poll.revents = 0;
- g_list_foreach (selected_rows, (GFunc) gtk_tree_path_free, NULL);
- g_list_free (selected_rows);
+ g_source_add_poll(source, &(hb_source->poll));
} else {
- result = FALSE;
+ source = g_idle_source_new ();
}
- gtk_widget_destroy (dialog);
+ return source;
+}
+
+guint
+modest_heartbeat_add (GSourceFunc function,
+ gpointer userdata)
+{
+ GSource *source;
+ guint id;
- g_object_unref (model);
+ source = modest_heartbeat_source_new ();
+ g_source_set_callback (source, function, userdata, NULL);
+ id = g_source_attach (source, NULL);
+ g_source_unref (source);
- return result;
+ return id;
}
-#ifdef MODEST_PLATFORM_MAEMO
-gboolean
-modest_maemo_utils_in_usb_mode ()
+#else
+guint
+modest_heartbeat_add (GSourceFunc function,
+ gpointer userdata)
{
- return modest_conf_get_bool (modest_runtime_get_conf (), INTERNAL_MMC_USB_MODE, NULL);
+ return g_idle_add (function, userdata);
}
#endif