* Add new header settings parameter (sort) to select
authorJavier Fernandez Garcia-Boente <jfernandez@igalia.com>
Thu, 26 Apr 2007 08:54:09 +0000 (08:54 +0000)
committerJavier Fernandez Garcia-Boente <jfernandez@igalia.com>
Thu, 26 Apr 2007 08:54:09 +0000 (08:54 +0000)
columns which can be used to sort headers list.
* Review restore_settings_header to set TreeSortable
sort column id.

pmo-trunk-r1673

src/gnome/modest-main-window.c
src/modest-init.c
src/modest-text-utils.c
src/modest-ui-actions.c
src/modest-widget-memory.c
src/widgets/modest-header-view-render.c
src/widgets/modest-header-view.c
src/widgets/modest-header-view.h
src/widgets/modest-mail-header-view.c
src/widgets/modest-main-window.h

index 97beef2..4b9a3fa 100644 (file)
@@ -698,6 +698,13 @@ modest_main_window_set_style (ModestMainWindow *self,
        /* TODO */
 }
 
+void 
+modest_main_window_set_toolbar_mode (ModestMainWindow *self, 
+                                     ModestToolBarModes mode)
+{
+       /* TODO */
+}
+
 ModestMainWindowStyle
 modest_main_window_get_style (ModestMainWindow *self)
 {
index f4eb930..d8819a6 100644 (file)
@@ -63,42 +63,43 @@ static void     init_device_name (ModestConf *conf);
 typedef struct {
        ModestHeaderViewColumn col;
        guint                  width;
+       gint                  sort;
 } FolderCols;
 
 static const FolderCols INBOX_COLUMNS_DETAILS[] = {
-       {MODEST_HEADER_VIEW_COLUMN_MSGTYPE, 40},
-       {MODEST_HEADER_VIEW_COLUMN_ATTACH,  40},
-       {MODEST_HEADER_VIEW_COLUMN_FROM,    80},
-       {MODEST_HEADER_VIEW_COLUMN_SUBJECT, 80},
-       {MODEST_HEADER_VIEW_COLUMN_RECEIVED_DATE, 60},
-       {MODEST_HEADER_VIEW_COLUMN_SIZE, 50}
+       {MODEST_HEADER_VIEW_COLUMN_MSGTYPE, 40, 0},
+       {MODEST_HEADER_VIEW_COLUMN_ATTACH,  40, 0},
+       {MODEST_HEADER_VIEW_COLUMN_FROM,    80, 0},
+       {MODEST_HEADER_VIEW_COLUMN_SUBJECT, 80, 0},
+       {MODEST_HEADER_VIEW_COLUMN_RECEIVED_DATE, 60, 0},
+       {MODEST_HEADER_VIEW_COLUMN_SIZE, 50, 0}
 };
 
 static const FolderCols INBOX_COLUMNS_TWOLINES[] = {
-       {MODEST_HEADER_VIEW_COLUMN_COMPACT_FLAG, 40},
-       {MODEST_HEADER_VIEW_COLUMN_COMPACT_HEADER_IN, 180},
-       {MODEST_HEADER_VIEW_COLUMN_COMPACT_RECEIVED_DATE, 240}
+       {MODEST_HEADER_VIEW_COLUMN_COMPACT_FLAG, 40, 0},
+       {MODEST_HEADER_VIEW_COLUMN_COMPACT_HEADER_IN, 180, 0},
+       {MODEST_HEADER_VIEW_COLUMN_COMPACT_RECEIVED_DATE, 240, 1}
 };
 
 static const FolderCols OUTBOX_COLUMNS_DETAILS[] = {
-       {MODEST_HEADER_VIEW_COLUMN_MSGTYPE, 40},
-       {MODEST_HEADER_VIEW_COLUMN_ATTACH,  40},
-       {MODEST_HEADER_VIEW_COLUMN_TO,    80},
-       {MODEST_HEADER_VIEW_COLUMN_SUBJECT, 80},
-       {MODEST_HEADER_VIEW_COLUMN_SENT_DATE, 80},
-       {MODEST_HEADER_VIEW_COLUMN_SIZE, 50}
+       {MODEST_HEADER_VIEW_COLUMN_MSGTYPE, 40, 0},
+       {MODEST_HEADER_VIEW_COLUMN_ATTACH,  40, 0},
+       {MODEST_HEADER_VIEW_COLUMN_TO,    80, 0},
+       {MODEST_HEADER_VIEW_COLUMN_SUBJECT, 80, 0},
+       {MODEST_HEADER_VIEW_COLUMN_SENT_DATE, 80, 0},
+       {MODEST_HEADER_VIEW_COLUMN_SIZE, 50, 0}
 };
 
 static const FolderCols OUTBOX_COLUMNS_TWOLINES[] = {
-       {MODEST_HEADER_VIEW_COLUMN_COMPACT_FLAG, 40},
-       {MODEST_HEADER_VIEW_COLUMN_COMPACT_HEADER_OUT,180},
-       {MODEST_HEADER_VIEW_COLUMN_STATUS, 240}
+       {MODEST_HEADER_VIEW_COLUMN_COMPACT_FLAG, 40, 0},
+       {MODEST_HEADER_VIEW_COLUMN_COMPACT_HEADER_OUT,180, 0},
+       {MODEST_HEADER_VIEW_COLUMN_STATUS, 240, 0}
 };
 
 static const FolderCols SENT_COLUMNS_TWOLINES[] = {
-       {MODEST_HEADER_VIEW_COLUMN_COMPACT_FLAG, 40},
-       {MODEST_HEADER_VIEW_COLUMN_COMPACT_HEADER_OUT,180},
-       {MODEST_HEADER_VIEW_COLUMN_COMPACT_SENT_DATE, 240}
+       {MODEST_HEADER_VIEW_COLUMN_COMPACT_FLAG, 40, 0},
+       {MODEST_HEADER_VIEW_COLUMN_COMPACT_HEADER_OUT,180, 0},
+       {MODEST_HEADER_VIEW_COLUMN_COMPACT_SENT_DATE, 240, 1}
 };
 
 #ifdef MODEST_PLATFORM_MAEMO
@@ -237,8 +238,8 @@ save_header_settings (ModestConf *conf, TnyFolderType type,
        /* the format is necessarily the same as the one in modest-widget-memory */
        str = g_string_new (NULL);
        for (i = 0; i != col_num; ++i) 
-               g_string_append_printf (str, "%d:%d ",
-                                       cols[i].col, cols[i].width); 
+               g_string_append_printf (str, "%d:%d:%d ",
+                                       cols[i].col, cols[i].width, cols[i].sort); 
 
        modest_conf_set_string (conf, key, str->str, NULL);
        g_free (key);
index e2dcf79..243ede3 100644 (file)
@@ -857,6 +857,8 @@ modest_text_utils_get_display_date (time_t date)
 
        modest_text_utils_strftime (date_buf, BUF_SIZE, "%d/%m/%Y", date);
        modest_text_utils_strftime (now_buf,  BUF_SIZE, "%d/%m/%Y",  now); /* today */
+/*     modest_text_utils_strftime (date_buf, BUF_SIZE, "%x", date); */
+/*     modest_text_utils_strftime (now_buf,  BUF_SIZE, "%x",  now); /\* today *\/ */
        
        /* if this is today, get the time instead of the date */
        if (strcmp (date_buf, now_buf) == 0)
index 6772fff..0771fd2 100644 (file)
@@ -587,8 +587,13 @@ void
 modest_ui_actions_on_sort (GtkAction *action, 
                           ModestWindow *window)
 {
+       ModestWindowMgr *mgr;
+
        g_return_if_fail (MODEST_IS_WINDOW(window));
-       /* FIXME: unimplemented */
+
+       /* Show sorting dialog */
+       mgr = modest_runtime_get_window_mgr ();
+       
 }
 
 
index 2a05e83..6d0e62d 100644 (file)
@@ -257,6 +257,7 @@ save_settings_header_view (ModestConf *conf, ModestHeaderView *header_view,
        TnyFolder *folder;
        TnyFolderType type;
        ModestHeaderViewStyle style;
+       gint sort_colid;
 
        folder = modest_header_view_get_folder (header_view);
        if (!folder || modest_header_view_is_empty (header_view))
@@ -274,17 +275,21 @@ save_settings_header_view (ModestConf *conf, ModestHeaderView *header_view,
        /* NOTE: the exact details of this format are important, as they
         * are also used in modest-init.
         */
+       sort_colid = modest_header_view_get_sort_column_id (header_view, type); 
        while (cursor) {
 
-               int col_id, width;
+               int col_id, width, sort;
                GtkTreeViewColumn *col;
                
                col    = GTK_TREE_VIEW_COLUMN (cursor->data);
                col_id = GPOINTER_TO_INT(g_object_get_data (G_OBJECT(col),
                                                            MODEST_HEADER_VIEW_COLUMN));
                width = gtk_tree_view_column_get_width (col);
-               
-               g_string_append_printf (str, "%d:%d ", col_id, width);
+               sort = 0;
+               if (sort_colid == gtk_tree_view_column_get_sort_column_id(col))
+                       sort = 1;
+                       
+               g_string_append_printf (str, "%d:%d:%d ", col_id, width, sort);
                cursor = g_list_next (cursor);
        }
 
@@ -303,6 +308,8 @@ static gboolean
 restore_settings_header_view (ModestConf *conf, ModestHeaderView *header_view,
                              const gchar *name)
 {
+       guint col, width;
+       gint sort;
        gchar *key;
        TnyFolder *folder;
        TnyFolderType type;
@@ -320,34 +327,54 @@ restore_settings_header_view (ModestConf *conf, ModestHeaderView *header_view,
        if (modest_conf_key_exists (conf, key, NULL)) {
                
                gchar *data, *cursor;
-               guint col, width;
                GList *cols = NULL;
                GList *colwidths = NULL;
-       
+               GList *colsortables = NULL;
+               GtkTreeModel *sortable;
+
                cursor = data = modest_conf_get_string (conf, key, NULL);
-               while (cursor && sscanf (cursor, "%u:%u ", &col, &width) == 2) {
+               while (cursor && sscanf (cursor, "%u:%u:%u ", &col, &width, &sort) == 3) {
                        cols      = g_list_append (cols, GINT_TO_POINTER(col));
                        colwidths = g_list_append (colwidths, GINT_TO_POINTER(width));
+                       colsortables = g_list_append (colsortables, GINT_TO_POINTER(sort));
                        cursor = strchr (cursor + 1, ' ');
                }
                g_free (data);  
                
                if (cols) {
-                       GList *viewcolumns, *colcursor, *widthcursor;
-                       modest_header_view_set_columns (header_view, cols);
+                       GList *viewcolumns, *colcursor, *widthcursor, *sortablecursor, *colidcursor;
+                       gint sort_colid = -1;
+                       modest_header_view_set_columns (header_view, cols, type);
+                       sortable = gtk_tree_view_get_model (GTK_TREE_VIEW (header_view));
 
+                       colidcursor = cols;
                        widthcursor = colwidths;
+                       sortablecursor = colsortables;
                        colcursor = viewcolumns = gtk_tree_view_get_columns (GTK_TREE_VIEW(header_view));
-                       while (colcursor && widthcursor) {
+                       while (colcursor && widthcursor && sortablecursor && colidcursor) {
                                int width = GPOINTER_TO_INT(widthcursor->data);
+                               int sort = GPOINTER_TO_INT(sortablecursor->data);
+                               int colid = GPOINTER_TO_INT(colidcursor->data);
                                if (width > 0)
                                        gtk_tree_view_column_set_max_width(GTK_TREE_VIEW_COLUMN(colcursor->data),
                                                                           width);
+                               if (sort > 0) {
+                                       sort_colid = gtk_tree_view_column_get_sort_column_id (GTK_TREE_VIEW_COLUMN(colcursor->data));
+                                       modest_header_view_set_sort_column_id (header_view, sort_colid, type);
+                                       gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE(sortable),
+                                                                             colid,
+                                                                             GTK_SORT_DESCENDING);
+                                       gtk_tree_sortable_sort_column_changed (GTK_TREE_SORTABLE(sortable));
+                               }
+                               colidcursor = g_list_next (colidcursor);
                                colcursor = g_list_next (colcursor);
                                widthcursor = g_list_next (widthcursor);
+                               sortablecursor = g_list_next (sortablecursor);
                        }
+
                        g_list_free (cols);
                        g_list_free (colwidths);
+                       g_list_free (colsortables);
                        g_list_free (viewcolumns);
                }
        }
index 8242061..78cd1fc 100644 (file)
@@ -73,9 +73,9 @@ get_pixbuf_for_compact_flag (TnyHeaderFlags flags)
        static GdkPixbuf *low_attachments_pixbuf    = NULL;
        static GdkPixbuf *high_pixbuf               = NULL;
        static GdkPixbuf *low_pixbuf                = NULL;
-       TnyHeaderFlags prior;
+       TnyHeaderPriorityFlags prior;
 
-       prior = flags & TNY_HEADER_FLAG_HIGH_PRIORITY;
+       prior = flags & TNY_HEADER_FLAG_PRIORITY;
        switch (prior) {
        case TNY_HEADER_FLAG_HIGH_PRIORITY:
                if (flags & TNY_HEADER_FLAG_ATTACHMENTS) {
index f4cb26f..ff745ba 100644 (file)
@@ -73,6 +73,7 @@ struct _ModestHeaderViewPrivate {
 
        TnyFolderMonitor     *monitor;
        GMutex               *monitor_lock;
+       gint sort_colid[2][TNY_FOLDER_TYPE_NUM];
 };
 
 #define MODEST_HEADER_VIEW_GET_PRIVATE(o)      (G_TYPE_INSTANCE_GET_PRIVATE((o), \
@@ -216,7 +217,7 @@ remove_all_columns (ModestHeaderView *obj)
 }
 
 gboolean
-modest_header_view_set_columns (ModestHeaderView *self, const GList *columns)
+modest_header_view_set_columns (ModestHeaderView *self, const GList *columns, TnyFolderType type)
 {
        GtkTreeModel *sortable;
        GtkTreeViewColumn *column=NULL;
@@ -353,11 +354,6 @@ modest_header_view_set_columns (ModestHeaderView *self, const GList *columns)
                                                 (GtkTreeCellDataFunc)_modest_header_view_compact_date_cell_data,
                                                 GINT_TO_POINTER(TRUE));
                        gtk_tree_view_column_set_fixed_width (column, 130);
-                       /* FIXME: this value must be stored in configuration */
-                       gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE(sortable), 
-                                                             TNY_GTK_HEADER_LIST_MODEL_DATE_RECEIVED_TIME_T_COLUMN,
-                                                             GTK_SORT_DESCENDING);
-                                                             
                        break;
                        
                case MODEST_HEADER_VIEW_COLUMN_COMPACT_SENT_DATE:                                             
@@ -367,10 +363,6 @@ modest_header_view_set_columns (ModestHeaderView *self, const GList *columns)
                                                 (GtkTreeCellDataFunc)_modest_header_view_compact_date_cell_data,
                                                 GINT_TO_POINTER(FALSE));
                        gtk_tree_view_column_set_fixed_width (column, 130);
-                       /* FIXME: this value must be stored in configuration */
-                       gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE(sortable), 
-                                                             TNY_GTK_HEADER_LIST_MODEL_DATE_SENT_TIME_T_COLUMN,
-                                                             GTK_SORT_DESCENDING);
                        break;
                case MODEST_HEADER_VIEW_COLUMN_SIZE:
                        column = get_new_column (_("Size"), renderer_header, TRUE,
@@ -391,7 +383,7 @@ modest_header_view_set_columns (ModestHeaderView *self, const GList *columns)
                        g_return_val_if_reached(FALSE);
                }
 
-               if (sortable)
+               if (sortable) 
                        gtk_tree_sortable_set_sort_func (GTK_TREE_SORTABLE(sortable),
                                                         col, (GtkTreeIterCompareFunc)cmp_rows,
                                                         column, NULL);
@@ -405,7 +397,8 @@ modest_header_view_set_columns (ModestHeaderView *self, const GList *columns)
                                   self);
                gtk_tree_view_append_column (GTK_TREE_VIEW(self), column);              
        }       
-
+       
+       
        return TRUE;
 }
 
@@ -413,6 +406,7 @@ static void
 modest_header_view_init (ModestHeaderView *obj)
 {
        ModestHeaderViewPrivate *priv;
+       guint i, j;
 
        priv = MODEST_HEADER_VIEW_GET_PRIVATE(obj); 
 
@@ -420,7 +414,9 @@ modest_header_view_init (ModestHeaderView *obj)
 
        priv->monitor        = NULL;
        priv->monitor_lock   = g_mutex_new ();
-
+       for (j=0; j < 2; j++)
+               for (i=0; i < TNY_FOLDER_TYPE_NUM; i++) 
+                       priv->sort_colid[j][i] = -1;
 
        setup_drag_and_drop (GTK_TREE_VIEW (obj));
 }
@@ -815,6 +811,30 @@ modest_header_view_set_folder_intern (ModestHeaderView *self, TnyFolder *folder)
 }
 
 void
+modest_header_view_set_sort_column_id (ModestHeaderView *self, guint sort_colid, TnyFolderType type)
+{
+       ModestHeaderViewPrivate *priv;
+       ModestHeaderViewStyle style;
+
+       style = modest_header_view_get_style   (self);
+       priv = MODEST_HEADER_VIEW_GET_PRIVATE(self);
+
+       priv->sort_colid[style][type] = sort_colid;
+}
+
+gint
+modest_header_view_get_sort_column_id (ModestHeaderView *self, TnyFolderType type)
+{
+       ModestHeaderViewPrivate *priv;
+       ModestHeaderViewStyle style;
+
+       style = modest_header_view_get_style   (self);
+       priv = MODEST_HEADER_VIEW_GET_PRIVATE(self);
+
+       return priv->sort_colid[style][type];
+}
+
+void
 modest_header_view_set_folder (ModestHeaderView *self, TnyFolder *folder)
 {
        ModestHeaderViewPrivate *priv;
@@ -959,9 +979,10 @@ cmp_rows (GtkTreeModel *tree_model, GtkTreeIter *iter1, GtkTreeIter *iter2,
        gint t1, t2;
        gint val1, val2;
        gchar *s1, *s2;
-       gint cmp;
-       
+       gint cmp;       
        static int counter = 0;
+
+       g_return_val_if_fail (G_IS_OBJECT(user_data), 0);
        col_id = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(user_data), MODEST_HEADER_VIEW_COLUMN));
        
        if (!(++counter % 100)) {
index d753de0..072885e 100644 (file)
@@ -170,13 +170,15 @@ TnyFolder *modest_header_view_get_folder (ModestHeaderView *self);
  * modest_header_view_set_columns:
  * @self: a ModestHeaderView instance
  * @columns: a list of ModestHeaderViewColumn
+ * @type: #TnyFolderType type
  * 
  * set the columns for this ModestHeaderView.
  *  
  * Returns: TRUE if it succeeded, FALSE otherwise
  */
 gboolean modest_header_view_set_columns (ModestHeaderView *self,
-                                        const GList *columns);
+                                        const GList *columns,
+                                        TnyFolderType type);
 /**
  * modest_header_view_get_columns:
  * @self: a ModestHeaderView instance
@@ -265,8 +267,32 @@ void
 _modest_header_view_change_selection (GtkTreeSelection *selection,
                                      gpointer user_data);
 
+/**
+ * modest_header_view_get_sort_column_id:
+ * @self: a #ModestHeaderView
+ * @type: #TnyFolderType type
+ * 
+ * Gets the selected logical columnd id for sorting.
+ **/
+gint
+modest_header_view_get_sort_column_id (ModestHeaderView *self, TnyFolderType type);
+
+/**
+ * modest_header_view_get_sort_column_id:
+ * @self: a #ModestHeaderView
+ * @sort_colid: logical column id to sort
+ * @type: #TnyFolderType type
+ * 
+ * Sets the logical columnd id for sorting.
+ **/
+void
+modest_header_view_set_sort_column_id (ModestHeaderView *self, guint sort_colid, TnyFolderType type);
+
+
+
 G_END_DECLS
 
 
+
 #endif /* __MODEST_HEADER_VIEW_H__ */
 
index 5c6ee60..f081503 100644 (file)
@@ -588,7 +588,7 @@ modest_mail_header_view_set_priority (ModestMailHeaderView *headers_view,
        g_return_if_fail (MODEST_IS_MAIL_HEADER_VIEW (headers_view));
        priv = MODEST_MAIL_HEADER_VIEW_GET_PRIVATE (headers_view);
 
-       priv->priority_flags = flags & (TNY_HEADER_FLAG_HIGH_PRIORITY);
+       priv->priority_flags = flags & (TNY_HEADER_FLAG_PRIORITY);
 
        if (priv->priority_flags == 0) {
                if (priv->priority_icon != NULL) {
index dbea5c0..c329ddf 100644 (file)
@@ -79,6 +79,12 @@ typedef enum _ModestMainWindowContentsStyle {
        MODEST_MAIN_WINDOW_CONTENTS_STYLE_DETAILS,
 } ModestMainWindowContentsStyle;
 
+/* toolbar modes  */
+typedef enum _ModestToolBarModes {
+       TOOLBAR_MODE_NORMAL,
+       TOOLBAR_MODE_TRANSFER,  
+} ModestToolBarModes;
+
 /**
  * modest_main_window_get_type:
  * 
@@ -167,6 +173,18 @@ ModestMainWindowStyle       modest_main_window_get_style        (ModestMainWindo
 void       modest_main_window_set_contents_style       (ModestMainWindow *self, 
                                                        ModestMainWindowContentsStyle style);
 
+/**
+ * modest_main_window_set_contents_style:
+ * @self: the #ModestMainWindow
+ * @mode: a #ModestTollbarMode that will be set
+ * 
+ * Shows toolitems associated with toolbar mode (Normal/Transfer), 
+ * defined by @mode argument.
+ * 
+ **/
+void 
+modest_main_window_set_toolbar_mode (ModestMainWindow *self, 
+                                     ModestToolBarModes mode);
 
 G_END_DECLS