X-Git-Url: http://git.maemo.org/git/?p=modest;a=blobdiff_plain;f=src%2Fmaemo%2Fmodest-platform.c;h=a13b8e3b0710f7902da0341891843aafac12ebab;hp=f48d95def9ddbe97129e375bd602b1a221213fb0;hb=092fe34f03c3165f87be7e09877bb614c468590f;hpb=4b665147693d48ea2cc8c4eb5c2fe966c8491415 diff --git a/src/maemo/modest-platform.c b/src/maemo/modest-platform.c index f48d95d..a13b8e3 100644 --- a/src/maemo/modest-platform.c +++ b/src/maemo/modest-platform.c @@ -55,6 +55,7 @@ #include #include #include +#include "modest-hildon-sort-dialog.h" #include #include @@ -586,165 +587,6 @@ entry_changed (GtkEditable *editable, g_free (chars); } -static guint -checked_hildon_sort_dialog_add_sort_key (HildonSortDialog *dialog, const gchar* key, guint max) -{ - gint sort_key; - - g_return_val_if_fail (dialog && HILDON_IS_SORT_DIALOG(dialog), 0); - g_return_val_if_fail (key, 0); - - sort_key = hildon_sort_dialog_add_sort_key (dialog, key); - if (sort_key < 0 || sort_key >= max) { - g_warning ("%s: out of range (%d) for %s", __FUNCTION__, sort_key, key); - return 0; - } else - return (guint)sort_key; -} - - -static void -launch_sort_headers_dialog (GtkWindow *parent_window, - HildonSortDialog *dialog) -{ - ModestHeaderView *header_view = NULL; - GList *cols = NULL; - GtkSortType sort_type; - gint sort_key; - gint default_key = 0; - gint result; - gboolean outgoing = FALSE; - gint current_sort_colid = -1; - GtkSortType current_sort_type; - gint attachments_sort_id; - gint priority_sort_id; - GtkTreeSortable *sortable; - - /* Get header window */ - if (MODEST_IS_MAIN_WINDOW (parent_window)) { - header_view = MODEST_HEADER_VIEW(modest_main_window_get_child_widget (MODEST_MAIN_WINDOW(parent_window), - MODEST_MAIN_WINDOW_WIDGET_TYPE_HEADER_VIEW)); - } - if (!header_view) - return; - - /* Add sorting keys */ - cols = modest_header_view_get_columns (header_view); - if (cols == NULL) - return; -#define SORT_ID_NUM 6 - int sort_model_ids[SORT_ID_NUM]; - int sort_ids[SORT_ID_NUM]; - - outgoing = (GPOINTER_TO_INT (g_object_get_data(G_OBJECT(cols->data), MODEST_HEADER_VIEW_COLUMN))== - MODEST_HEADER_VIEW_COLUMN_COMPACT_HEADER_OUT); - - sort_key = checked_hildon_sort_dialog_add_sort_key (dialog, _("mcen_li_sort_sender_recipient"), - SORT_ID_NUM); - if (outgoing) { - sort_model_ids[sort_key] = TNY_GTK_HEADER_LIST_MODEL_TO_COLUMN; - sort_ids[sort_key] = MODEST_HEADER_VIEW_COLUMN_COMPACT_HEADER_OUT; - } else { - sort_model_ids[sort_key] = TNY_GTK_HEADER_LIST_MODEL_FROM_COLUMN; - sort_ids[sort_key] = MODEST_HEADER_VIEW_COLUMN_COMPACT_HEADER_IN; - } - - sort_key = checked_hildon_sort_dialog_add_sort_key (dialog, _("mcen_li_sort_date"), - SORT_ID_NUM); - if (outgoing) { - sort_model_ids[sort_key] = TNY_GTK_HEADER_LIST_MODEL_DATE_SENT_TIME_T_COLUMN; - sort_ids[sort_key] = MODEST_HEADER_VIEW_COLUMN_COMPACT_SENT_DATE; - } else { - sort_model_ids[sort_key] = TNY_GTK_HEADER_LIST_MODEL_DATE_RECEIVED_TIME_T_COLUMN; - sort_ids[sort_key] = MODEST_HEADER_VIEW_COLUMN_COMPACT_RECEIVED_DATE; - } - default_key = sort_key; - - sort_key = checked_hildon_sort_dialog_add_sort_key (dialog, _("mcen_li_sort_subject"), - SORT_ID_NUM); - sort_model_ids[sort_key] = TNY_GTK_HEADER_LIST_MODEL_SUBJECT_COLUMN; - if (outgoing) - sort_ids[sort_key] = MODEST_HEADER_VIEW_COLUMN_COMPACT_HEADER_OUT; - else - sort_ids[sort_key] = MODEST_HEADER_VIEW_COLUMN_COMPACT_HEADER_IN; - - sort_key = checked_hildon_sort_dialog_add_sort_key (dialog, _("mcen_li_sort_attachment"), - SORT_ID_NUM); - sort_model_ids[sort_key] = TNY_GTK_HEADER_LIST_MODEL_FLAGS_COLUMN; - sort_ids[sort_key] = TNY_HEADER_FLAG_ATTACHMENTS; - attachments_sort_id = sort_key; - - sort_key = checked_hildon_sort_dialog_add_sort_key (dialog, _("mcen_li_sort_size"), - SORT_ID_NUM); - sort_model_ids[sort_key] = TNY_GTK_HEADER_LIST_MODEL_MESSAGE_SIZE_COLUMN; - sort_ids[sort_key] = 0; - - sort_key = checked_hildon_sort_dialog_add_sort_key (dialog, _("mcen_li_sort_priority"), - SORT_ID_NUM); - sort_model_ids[sort_key] = TNY_GTK_HEADER_LIST_MODEL_FLAGS_COLUMN; - sort_ids[sort_key] = TNY_HEADER_FLAG_PRIORITY_MASK; - priority_sort_id = sort_key; - - sortable = GTK_TREE_SORTABLE (gtk_tree_model_filter_get_model - (GTK_TREE_MODEL_FILTER (gtk_tree_view_get_model (GTK_TREE_VIEW (header_view))))); - /* Launch dialogs */ - if (!gtk_tree_sortable_get_sort_column_id (sortable, - ¤t_sort_colid, ¤t_sort_type)) { - hildon_sort_dialog_set_sort_key (dialog, default_key); - hildon_sort_dialog_set_sort_order (dialog, GTK_SORT_DESCENDING); - } else { - hildon_sort_dialog_set_sort_order (dialog, current_sort_type); - if (current_sort_colid == TNY_GTK_HEADER_LIST_MODEL_FLAGS_COLUMN) { - gpointer flags_sort_type_pointer; - flags_sort_type_pointer = g_object_get_data (G_OBJECT (cols->data), MODEST_HEADER_VIEW_FLAG_SORT); - if (GPOINTER_TO_INT (flags_sort_type_pointer) == TNY_HEADER_FLAG_PRIORITY_MASK) - hildon_sort_dialog_set_sort_key (dialog, priority_sort_id); - else - hildon_sort_dialog_set_sort_key (dialog, attachments_sort_id); - } else { - gint current_sort_keyid = 0; - while (current_sort_keyid < 6) { - if (sort_model_ids[current_sort_keyid] == current_sort_colid) - break; - else - current_sort_keyid++; - } - hildon_sort_dialog_set_sort_key (dialog, current_sort_keyid); - } - } - - result = gtk_dialog_run (GTK_DIALOG (dialog)); - if (result == GTK_RESPONSE_OK) { - sort_key = hildon_sort_dialog_get_sort_key (dialog); - if (sort_key < 0 || sort_key > SORT_ID_NUM -1) { - g_warning ("%s: out of range (%d)", __FUNCTION__, sort_key); - sort_key = 0; - } - - sort_type = hildon_sort_dialog_get_sort_order (dialog); - if (sort_model_ids[sort_key] == TNY_GTK_HEADER_LIST_MODEL_FLAGS_COLUMN) { - g_object_set_data (G_OBJECT(cols->data), MODEST_HEADER_VIEW_FLAG_SORT, - GINT_TO_POINTER (sort_ids[sort_key])); - /* This is a hack to make it resort rows always when flag fields are - * selected. If we do not do this, changing sort field from priority to - * attachments does not work */ - modest_header_view_sort_by_column_id (header_view, 0, sort_type); - } else { - gtk_tree_view_column_set_sort_column_id (GTK_TREE_VIEW_COLUMN (cols->data), - sort_model_ids[sort_key]); - } - - modest_header_view_sort_by_column_id (header_view, sort_model_ids[sort_key], sort_type); - gtk_tree_sortable_sort_column_changed (sortable); - } - - modest_widget_memory_save (modest_runtime_get_conf (), - G_OBJECT (header_view), MODEST_CONF_HEADER_VIEW_KEY); - - /* free */ - g_list_free(cols); -} - static void @@ -860,21 +702,22 @@ modest_platform_run_folder_name_dialog (GtkWindow *parent_window, G_CALLBACK (entry_changed), dialog); + + /* Some locales like pt_BR need this to get the full window + title shown */ + gtk_widget_set_size_request (GTK_WIDGET (dialog), 300, -1); + /* Create the hbox */ hbox = gtk_hbox_new (FALSE, 12); - gtk_box_pack_start (GTK_BOX (hbox), label, TRUE, FALSE, 0); + gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, FALSE, 0); gtk_box_pack_start (GTK_BOX (hbox), entry, TRUE, TRUE, 0); /* Add hbox to dialog */ gtk_box_pack_start (GTK_BOX(GTK_DIALOG(dialog)->vbox), hbox, FALSE, FALSE, 0); - - gtk_widget_show_all (GTK_WIDGET(GTK_DIALOG(dialog)->vbox)); - gtk_window_set_transient_for (GTK_WINDOW (dialog), parent_window); - - /* Some locales like pt_BR need this to get the full window - title shown */ - gtk_widget_set_size_request (GTK_WIDGET (dialog), 300, -1); + modest_window_mgr_set_modal (modest_runtime_get_window_mgr (), + GTK_WINDOW (dialog)); + gtk_widget_show_all (GTK_WIDGET(dialog)); result = gtk_dialog_run (GTK_DIALOG(dialog)); if (result == GTK_RESPONSE_ACCEPT) @@ -964,9 +807,16 @@ modest_platform_run_rename_folder_dialog (GtkWindow *parent_window, static void -on_destroy_dialog (GtkDialog *dialog) +on_destroy_dialog (GtkWidget *dialog) { - gtk_widget_destroy (GTK_WIDGET(dialog)); + /* This could happen when the dialogs get programatically + hidden or destroyed (for example when closing the + application while a dialog is being shown) */ + if (!GTK_IS_WIDGET (dialog)) + return; + + gtk_widget_destroy (dialog); + if (gtk_events_pending ()) gtk_main_iteration (); } @@ -984,10 +834,7 @@ modest_platform_run_confirmation_dialog (GtkWindow *parent_window, response = gtk_dialog_run (GTK_DIALOG (dialog)); - on_destroy_dialog (GTK_DIALOG(dialog)); - - while (gtk_events_pending ()) - gtk_main_iteration (); + on_destroy_dialog (dialog); return response; } @@ -1010,10 +857,7 @@ modest_platform_run_confirmation_dialog_with_buttons (GtkWindow *parent_window, response = gtk_dialog_run (GTK_DIALOG (dialog)); - on_destroy_dialog (GTK_DIALOG(dialog)); - - while (gtk_events_pending ()) - gtk_main_iteration (); + on_destroy_dialog (dialog); return response; } @@ -1032,10 +876,7 @@ modest_platform_run_yes_no_dialog (GtkWindow *parent_window, modest_window_mgr_set_modal (modest_runtime_get_window_mgr (), GTK_WINDOW (dialog)); response = gtk_dialog_run (GTK_DIALOG (dialog)); - on_destroy_dialog (GTK_DIALOG(dialog)); - - while (gtk_events_pending ()) - gtk_main_iteration (); + on_destroy_dialog (dialog); return response; } @@ -1050,16 +891,14 @@ modest_platform_run_information_dialog (GtkWindow *parent_window, GtkWidget *note; note = hildon_note_new_information (parent_window, message); - modest_window_mgr_set_modal (modest_runtime_get_window_mgr (), - GTK_WINDOW (note)); + if (block) + modest_window_mgr_set_modal (modest_runtime_get_window_mgr (), + GTK_WINDOW (note)); if (block) { gtk_dialog_run (GTK_DIALOG (note)); - on_destroy_dialog (GTK_DIALOG (note)); - - while (gtk_events_pending ()) - gtk_main_iteration (); + on_destroy_dialog (note); } else { g_signal_connect_swapped (note, "response", @@ -1240,31 +1079,18 @@ modest_platform_connect_and_wait_if_network_folderstore (GtkWindow *parent_windo return result; } -void -modest_platform_run_sort_dialog (GtkWindow *parent_window, - ModestSortDialogType type) +GtkWidget * +modest_platform_create_sort_dialog (GtkWindow *parent_window) { - GtkWidget *dialog = NULL; + GtkWidget *dialog; - /* Build dialog */ - dialog = hildon_sort_dialog_new (parent_window); - modest_window_mgr_set_modal (modest_runtime_get_window_mgr (), - GTK_WINDOW (dialog)); + dialog = modest_hildon_sort_dialog_new (parent_window); hildon_help_dialog_help_enable (GTK_DIALOG(dialog), "applications_email_sort", modest_maemo_utils_get_osso_context()); - /* Fill sort keys */ - switch (type) { - case MODEST_SORT_HEADERS: - launch_sort_headers_dialog (parent_window, - HILDON_SORT_DIALOG(dialog)); - break; - } - - /* Free */ - on_destroy_dialog (GTK_DIALOG(dialog)); + return dialog; } @@ -1658,11 +1484,31 @@ modest_platform_information_banner (GtkWidget *parent, const gchar *icon_name, const gchar *text) { - GtkWidget *banner; - ModestWindowMgr *mgr; + GtkWidget *banner, *banner_parent = NULL; + ModestWindowMgr *mgr = modest_runtime_get_window_mgr (); - mgr = modest_runtime_get_window_mgr (); - banner = hildon_banner_show_information (parent, icon_name, text); + if (modest_window_mgr_num_windows (mgr) == 0) + return; + + if (parent && GTK_IS_WINDOW (parent)) { + /* If the window is the active one then show the + banner on top of this window */ + if (gtk_window_is_active (GTK_WINDOW (parent))) + banner_parent = parent; + /* If the window is not the topmost but it's visible + (it's minimized for example) then show the banner + with no parent */ + else if (GTK_WIDGET_VISIBLE (parent)) + banner_parent = NULL; + /* If the window is hidden (like the main window when + running in the background) then do not show + anything */ + else + return; + } + + + banner = hildon_banner_show_information (banner_parent, icon_name, text); modest_window_mgr_register_banner (mgr); g_object_ref (mgr); @@ -1676,6 +1522,10 @@ modest_platform_information_banner_with_timeout (GtkWidget *parent, gint timeout) { GtkWidget *banner; + + if (modest_window_mgr_num_windows (modest_runtime_get_window_mgr ()) == 0) + return; + banner = hildon_banner_show_information (parent, icon_name, text); hildon_banner_set_timeout(HILDON_BANNER(banner), timeout); } @@ -1689,6 +1539,13 @@ modest_platform_animation_banner (GtkWidget *parent, g_return_val_if_fail (text != NULL, NULL); + if (modest_window_mgr_num_windows (modest_runtime_get_window_mgr ()) == 0) + return NULL; + + /* If the parent is not visible then do not show */ + if (parent && !GTK_WIDGET_VISIBLE (parent)) + return NULL; + inf_note = hildon_banner_show_animation (parent, animation_name, text); return inf_note; @@ -1868,7 +1725,7 @@ modest_platform_run_certificate_confirmation_dialog (const gchar* server_name, GTK_WINDOW (note)); response = gtk_dialog_run(GTK_DIALOG(note)); - on_destroy_dialog (GTK_DIALOG(note)); + on_destroy_dialog (note); g_free (question); return response == GTK_RESPONSE_OK; @@ -1903,7 +1760,7 @@ modest_platform_run_alert_dialog (const gchar* prompt, const int response = gtk_dialog_run (GTK_DIALOG (dialog)); retval = (response == GTK_RESPONSE_YES) || (response == GTK_RESPONSE_OK); - on_destroy_dialog (GTK_DIALOG(dialog)); + on_destroy_dialog (dialog); } else { /* Just show the error text and use the default response: */ modest_platform_run_information_dialog (GTK_WINDOW (main_win), @@ -2217,7 +2074,7 @@ modest_platform_get_account_settings_dialog (ModestAccountSettings *settings) } GtkWidget * -modest_platform_get_account_settings_wizard () +modest_platform_get_account_settings_wizard (void) { ModestEasysetupWizardDialog *dialog = modest_easysetup_wizard_dialog_new (); @@ -2262,30 +2119,23 @@ modest_platform_get_current_connection (void) gboolean -modest_platform_check_memory_low (gboolean showui) +modest_platform_check_memory_low (ModestWindow *win, + gboolean visuals) { gboolean lowmem; - + /* are we in low memory state? */ lowmem = osso_mem_in_lowmem_state () ? TRUE : FALSE; - - - if (showui && lowmem) { - ModestWindowMgr *window_mgr; - ModestWindow *main_win; - - window_mgr = modest_runtime_get_window_mgr(); - main_win = modest_window_mgr_get_main_window ( - window_mgr, FALSE /* don't create */); - - if (!main_win) - return lowmem; /* don't show ui */ - + + if (win && lowmem && visuals) modest_platform_run_information_dialog ( - GTK_WINDOW(main_win), + GTK_WINDOW(win), dgettext("ke-recv","memr_ib_operation_disabled"), TRUE); - } - + + if (lowmem) + g_debug ("%s: low memory reached. disallowing some operations", + __FUNCTION__); + return lowmem; }