Work to fix recovering sort status in headers view (fixes NB#58250).
authorJose Dapena Paz <jdapena@igalia.com>
Mon, 18 Jun 2007 16:13:14 +0000 (16:13 +0000)
committerJose Dapena Paz <jdapena@igalia.com>
Mon, 18 Jun 2007 16:13:14 +0000 (16:13 +0000)
* src/maemo/modest-platform.c:
        * Now it retrieves the current header view sort column,
          sort type, and in case of sorting flags, the flag we sort.
          This way, the dialog is prefilled with the current header
          view status.
* src/modest-widget-memory-priv.h:
        * Added the new kind of key "column-sort", that specified the
          model column used to sort in header view.
* src/modest-widget-memory.c:
        * Now save_settings_header_view and restore_settings_header_view
          store a global sort value. This is required for recovering the
          sort status in the compact view.

Other fixes:
* src/modest-ui-dimming-rules.c:
        * Condition for one or more attachments was wrong.

pmo-trunk-r2292

src/maemo/modest-platform.c
src/modest-ui-dimming-rules.c
src/modest-widget-memory-priv.h
src/modest-widget-memory.c

index 192b6c4..f3c3dad 100644 (file)
@@ -596,6 +596,10 @@ launch_sort_headers_dialog (GtkWindow *parent_window,
        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;
        
        /* Get header window */
        if (MODEST_IS_MAIN_WINDOW (parent_window)) {
@@ -610,6 +614,7 @@ launch_sort_headers_dialog (GtkWindow *parent_window,
        int sort_model_ids[6];
        int sort_ids[6];
 
+
        outgoing = (GPOINTER_TO_INT (g_object_get_data(G_OBJECT(cols->data), MODEST_HEADER_VIEW_COLUMN))==
                    MODEST_HEADER_VIEW_COLUMN_COMPACT_HEADER_OUT);
 
@@ -642,6 +647,7 @@ launch_sort_headers_dialog (GtkWindow *parent_window,
        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;
@@ -650,10 +656,33 @@ launch_sort_headers_dialog (GtkWindow *parent_window,
        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;
 
        /* Launch dialogs */
-       hildon_sort_dialog_set_sort_key (dialog, default_key);
-       hildon_sort_dialog_set_sort_order (dialog, GTK_SORT_DESCENDING);
+       if (!gtk_tree_sortable_get_sort_column_id (GTK_TREE_SORTABLE (gtk_tree_view_get_model (GTK_TREE_VIEW (header_view))),
+                                                  &current_sort_colid, &current_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);
index f65cd0e..477707a 100644 (file)
@@ -952,7 +952,7 @@ _invalid_attach_selected (ModestWindow *win,
                        result = n_selected != 1;
                else
                        
-                       result = n_selected == 1;
+                       result = n_selected < 1;
                
                /* Set notifications */
                if (!result && rule != NULL) {
index 2a9f686..6a5a284 100644 (file)
@@ -40,6 +40,7 @@ G_BEGIN_DECLS
 #define MODEST_WIDGET_MEMORY_PARAM_POS           "pos"
 #define MODEST_WIDGET_MEMORY_PARAM_COLUMN_WIDTH  "column-width"
 #define MODEST_WIDGET_MEMORY_PARAM_WINDOW_STYLE  "window-style"
+#define MODEST_WIDGET_MEMORY_PARAM_COLUMN_SORT   "column-sort"
 
 /* private functions, only for use in modest-widget-memory and modest-init */
 gchar* _modest_widget_memory_get_keyname           (const gchar *name, const gchar *param);
index 1920953..22c8da2 100644 (file)
@@ -257,6 +257,8 @@ save_settings_header_view (ModestConf *conf, ModestHeaderView *header_view,
                           const gchar *name)
 {
        gchar *key;
+       gchar *sort_key;
+       gchar *sort_value;
        GString *str;
        GList *cols, *cursor;
        TnyFolder *folder;
@@ -264,6 +266,7 @@ save_settings_header_view (ModestConf *conf, ModestHeaderView *header_view,
        ModestHeaderViewStyle style;
        gint sort_colid;
        GtkSortType sort_type;
+       gint sort_flag_id = 0;
        
        folder = modest_header_view_get_folder (header_view);
        if (!folder || modest_header_view_is_empty (header_view))
@@ -274,6 +277,8 @@ save_settings_header_view (ModestConf *conf, ModestHeaderView *header_view,
        
        key = _modest_widget_memory_get_keyname_with_double_type (name, type, style,
                                                                  MODEST_WIDGET_MEMORY_PARAM_COLUMN_WIDTH);
+       sort_key = _modest_widget_memory_get_keyname_with_double_type (name, type, style,
+                                                                      MODEST_WIDGET_MEMORY_PARAM_COLUMN_SORT);
 
        cursor = cols = modest_header_view_get_columns (header_view);
        if (!cols) {
@@ -288,10 +293,12 @@ save_settings_header_view (ModestConf *conf, ModestHeaderView *header_view,
         */
        sort_colid = modest_header_view_get_sort_column_id (header_view, type); 
        sort_type = modest_header_view_get_sort_type (header_view, type); 
+
        while (cursor) {
 
                int col_id, width, sort;
                GtkTreeViewColumn *col;
+               int column_sort_flag;
                
                col    = GTK_TREE_VIEW_COLUMN (cursor->data);
                col_id = GPOINTER_TO_INT(g_object_get_data (G_OBJECT(col),
@@ -300,6 +307,9 @@ save_settings_header_view (ModestConf *conf, ModestHeaderView *header_view,
                sort = 0;
                if (sort_colid == col_id)
                        sort = (sort_type == GTK_SORT_ASCENDING) ? 1:0;
+               column_sort_flag = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (col), MODEST_HEADER_VIEW_FLAG_SORT));
+               if (column_sort_flag != 0)
+                       sort_flag_id = column_sort_flag;
                
                g_string_append_printf (str, "%d:%d:%d ", col_id, width, sort);
                cursor = g_list_next (cursor);
@@ -313,6 +323,15 @@ save_settings_header_view (ModestConf *conf, ModestHeaderView *header_view,
        else
                modest_conf_set_string (conf, key, str->str, NULL);
 
+       /* store current sort column for compact view */
+       if (sort_colid >= 0) {
+               sort_value = g_strdup_printf("%d:%d:%d", sort_colid, sort_type, sort_flag_id);
+               modest_conf_set_string (conf, sort_key, sort_value, NULL);
+               g_free (sort_value);
+       }
+
+
+
        g_free (key);   
        g_string_free (str, TRUE);
        g_list_free (cols);
@@ -329,9 +348,12 @@ restore_settings_header_view (ModestConf *conf, ModestHeaderView *header_view,
        guint col, width;
        gint sort;
        gchar *key;
+       gchar *sort_key;
        TnyFolder *folder;
        TnyFolderType type;
        ModestHeaderViewStyle style;
+       gint sort_flag_id = 0;
+       gint sort_colid = -1, sort_type;
        
        folder = modest_header_view_get_folder (header_view);
        if (!folder || modest_header_view_is_empty (header_view))
@@ -341,6 +363,14 @@ restore_settings_header_view (ModestConf *conf, ModestHeaderView *header_view,
 
        key = _modest_widget_memory_get_keyname_with_double_type (name, type, style,
                                                                  MODEST_WIDGET_MEMORY_PARAM_COLUMN_WIDTH);
+       sort_key = _modest_widget_memory_get_keyname_with_double_type (name, type, style,
+                                                                 MODEST_WIDGET_MEMORY_PARAM_COLUMN_SORT);
+
+       if (modest_conf_key_exists (conf, sort_key, NULL)) {
+               gchar *value = modest_conf_get_string (conf, sort_key, NULL);
+               sscanf (value, "%d:%d:%d", &sort_colid, &sort_type, &sort_flag_id);
+       }
+
        if (modest_conf_key_exists (conf, key, NULL)) {
                
                gchar *data, *cursor;
@@ -372,31 +402,27 @@ restore_settings_header_view (ModestConf *conf, ModestHeaderView *header_view,
                        cols = modest_init_get_default_header_view_column_ids (type, style);
                
                if (cols) {
-                       GList *viewcolumns, *colcursor, *widthcursor, *sortablecursor;
+                       GList *viewcolumns, *colcursor, *widthcursor;
                        modest_header_view_set_columns (header_view, cols, type);
                        sortable = gtk_tree_view_get_model (GTK_TREE_VIEW (header_view));
 
                        widthcursor = colwidths;
-                       sortablecursor = colsortables;
                        colcursor = viewcolumns = gtk_tree_view_get_columns (GTK_TREE_VIEW(header_view));
-                       while (colcursor && widthcursor && sortablecursor) {
+                       while (colcursor && widthcursor) {
                                int width = GPOINTER_TO_INT(widthcursor->data);
-                               int sort = GPOINTER_TO_INT(sortablecursor->data);
+                               int view_column_id = GPOINTER_TO_INT (g_object_get_data (
+                                                                             G_OBJECT (colcursor->data), 
+                                                                             MODEST_HEADER_VIEW_COLUMN));
                                if (width > 0)
                                        gtk_tree_view_column_set_max_width(GTK_TREE_VIEW_COLUMN(colcursor->data),
                                                                           width);
-                               if (sort != 0) {
-                                       int colid = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(colcursor->data), MODEST_HEADER_VIEW_COLUMN));
-                                       GtkSortType sort_type = (sort == 1) ? GTK_SORT_ASCENDING : GTK_SORT_DESCENDING; 
-                                       modest_header_view_set_sort_params (header_view, colid, sort_type, type);
-                                       gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE(sortable),
-                                                                             colid,
-                                                                             sort_type);
-                                       gtk_tree_sortable_sort_column_changed (GTK_TREE_SORTABLE(sortable));
-                               }
+                               if (((view_column_id == MODEST_HEADER_VIEW_COLUMN_COMPACT_HEADER_IN) ||
+                                    (view_column_id == MODEST_HEADER_VIEW_COLUMN_COMPACT_HEADER_OUT)) &&
+                                   (sort_flag_id != 0))
+                                       g_object_set_data (G_OBJECT (colcursor->data), 
+                                                          MODEST_HEADER_VIEW_FLAG_SORT, GINT_TO_POINTER (sort_flag_id));
                                colcursor = g_list_next (colcursor);
                                widthcursor = g_list_next (widthcursor);
-                               sortablecursor = g_list_next (sortablecursor);
                        }
 
                        g_list_free (cols);
@@ -406,6 +432,17 @@ restore_settings_header_view (ModestConf *conf, ModestHeaderView *header_view,
                }
        }
 
+       if (sort_colid >= 0) {
+               GtkTreeModel *sortable = gtk_tree_view_get_model (GTK_TREE_VIEW (header_view));
+               if (sort_colid == TNY_GTK_HEADER_LIST_MODEL_FLAGS_COLUMN)
+                       modest_header_view_sort_by_column_id (header_view, 0, sort_type);
+               gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE(sortable),
+                                                     sort_colid,
+                                                     sort_type);
+               modest_header_view_sort_by_column_id (header_view, sort_colid, sort_type);
+               gtk_tree_sortable_sort_column_changed (GTK_TREE_SORTABLE(sortable));
+       }
+
        g_free (key);
        g_object_unref (G_OBJECT (folder));