+
+ sort_key = hildon_sort_dialog_add_sort_key (dialog, _("mcen_li_sort_date"));
+ 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 = hildon_sort_dialog_add_sort_key (dialog, _("mcen_li_sort_subject"));
+ 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 = hildon_sort_dialog_add_sort_key (dialog, _("mcen_li_sort_attachment"));
+ 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 = hildon_sort_dialog_add_sort_key (dialog, _("mcen_li_sort_size"));
+ sort_model_ids[sort_key] = TNY_GTK_HEADER_LIST_MODEL_MESSAGE_SIZE_COLUMN;
+ sort_ids[sort_key] = 0;
+
+ sort_key = hildon_sort_dialog_add_sort_key (dialog, _("mcen_li_sort_priority"));
+ sort_model_ids[sort_key] = TNY_GTK_HEADER_LIST_MODEL_FLAGS_COLUMN;
+ sort_ids[sort_key] = TNY_HEADER_FLAG_PRIORITY;
+ 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)
+ 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);
+ 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);
+
+/* while (gtk_events_pending ()) */
+/* gtk_main_iteration (); */
+
+ /* free */
+ g_list_free(cols);