[evolution] Bug 788934 - Add option to have Subject above Sender in Wide view



commit 1ad381e414f61f83ad66ba3e9fadcdd715b6e992
Author: Milan Crha <mcrha redhat com>
Date:   Tue Oct 17 18:46:16 2017 +0200

    Bug 788934 - Add option to have Subject above Sender in Wide view

 data/org.gnome.evolution.mail.gschema.xml.in   |    5 +
 src/e-util/e-cell-tree.c                       |   38 ++++++-
 src/e-util/e-cell-tree.h                       |    6 +
 src/e-util/e-table-extras.c                    |    2 +-
 src/mail/message-list.c                        |  144 +++++++++++++++++++++---
 src/mail/message-list.h                        |    5 +
 src/modules/settings/e-settings-message-list.c |    5 +
 7 files changed, 182 insertions(+), 23 deletions(-)
---
diff --git a/data/org.gnome.evolution.mail.gschema.xml.in b/data/org.gnome.evolution.mail.gschema.xml.in
index 897c264..f97ab66 100644
--- a/data/org.gnome.evolution.mail.gschema.xml.in
+++ b/data/org.gnome.evolution.mail.gschema.xml.in
@@ -713,6 +713,11 @@
       <_summary>Whether go to the previous message after message deletion</_summary>
       <_description>If set to true, goes to the previous message when the selected is deleted; or to the 
next message, when it's set to false.</_description>
     </key>
+    <key name="show-subject-above-sender" type="b">
+      <default>false</default>
+      <_summary>Show Subject above Sender in Messages column</_summary>
+      <_description>Whether to show Subject above Sender (From/To) in the Messages column, usually shown in 
the Vertical/Wide view of the message list</_description>
+    </key>
 
     <!-- The following keys are deprecated. -->
 
diff --git a/src/e-util/e-cell-tree.c b/src/e-util/e-cell-tree.c
index 14e78b2..73de283 100644
--- a/src/e-util/e-cell-tree.c
+++ b/src/e-util/e-cell-tree.c
@@ -211,6 +211,9 @@ draw_expander (ECellTreeView *ectv,
        GtkStateFlags flags = 0;
        gint exp_size;
 
+       if (!E_CELL_TREE (ectv->cell_view.ecell)->show_expander)
+               return;
+
        tree = gtk_widget_get_parent (GTK_WIDGET (ectv->canvas));
        style_context = gtk_widget_get_style_context (tree);
 
@@ -296,7 +299,8 @@ ect_draw (ECellView *ecell_view,
                rect.height = y2 - y1;
 
                /* now draw our icon if we're expandable */
-               if (e_tree_model_node_is_expandable (tree_model, node)) {
+               if (E_CELL_TREE (tree_view->cell_view.ecell)->show_expander &&
+                   e_tree_model_node_is_expandable (tree_model, node)) {
                        gboolean expanded = e_tree_table_adapter_node_is_expanded (tree_table_adapter, node);
                        GdkRectangle r;
 
@@ -437,7 +441,8 @@ ect_event (ECellView *ecell_view,
        switch (event->type) {
        case GDK_BUTTON_PRESS:
 
-               if (event_in_expander (event, offset, 0)) {
+               if (E_CELL_TREE (tree_view->cell_view.ecell)->show_expander &&
+                   event_in_expander (event, offset, 0)) {
                        if (e_tree_model_node_is_expandable (tree_model, node)) {
                                gboolean expanded = e_tree_table_adapter_node_is_expanded (etta, node);
                                gint tmp_row = row;
@@ -480,7 +485,8 @@ ect_event (ECellView *ecell_view,
 
        case GDK_MOTION_NOTIFY:
 
-               if (e_tree_model_node_is_expandable (tree_model, node)) {
+               if (E_CELL_TREE (tree_view->cell_view.ecell)->show_expander &&
+                   e_tree_model_node_is_expandable (tree_model, node)) {
                        gint height = ect_height (ecell_view, model_col, view_col, row);
                        GdkRectangle area;
                        gboolean in_expander = event_in_expander (event, offset, height);
@@ -720,7 +726,7 @@ ect_print (ECellView *ecell_view,
                }
 
                /* now draw our icon if we're expandable */
-               if (expandable) {
+               if (expandable && E_CELL_TREE (tree_view->cell_view.ecell)->show_expander) {
                        gboolean expanded;
                        GdkRectangle r;
                        gint exp_size = 0;
@@ -811,6 +817,7 @@ e_cell_tree_init (ECellTree *ect)
  * e_cell_tree_construct:
  * @ect: the ECellTree we're constructing.
  * @draw_lines: whether or not to draw the lines between parents/children/siblings.
+ * @show_expander: whether to show expander
  * @subcell: the ECell to render to the right of the tree effects.
  *
  * Constructs an ECellTree.  used by subclasses that need to
@@ -820,6 +827,7 @@ e_cell_tree_init (ECellTree *ect)
 void
 e_cell_tree_construct (ECellTree *ect,
                        gboolean draw_lines,
+                      gboolean show_expander,
                        ECell *subcell)
 {
        ect->subcell = subcell;
@@ -827,12 +835,14 @@ e_cell_tree_construct (ECellTree *ect,
                g_object_ref_sink (subcell);
 
        ect->draw_lines = draw_lines;
+       ect->show_expander = show_expander;
        ect->grouped_view = TRUE;
 }
 
 /**
  * e_cell_tree_new:
  * @draw_lines: whether or not to draw the lines between parents/children/siblings.
+ * @show_expander: whether to show expander
  * @subcell: the ECell to render to the right of the tree effects.
  *
  * Creates a new ECell renderer that can be used to render tree
@@ -846,11 +856,12 @@ e_cell_tree_construct (ECellTree *ect,
  **/
 ECell *
 e_cell_tree_new (gboolean draw_lines,
+                gboolean show_expander,
                  ECell *subcell)
 {
        ECellTree *ect = g_object_new (E_TYPE_CELL_TREE, NULL);
 
-       e_cell_tree_construct (ect, draw_lines, subcell);
+       e_cell_tree_construct (ect, draw_lines, show_expander, subcell);
 
        return (ECell *) ect;
 }
@@ -871,3 +882,20 @@ e_cell_tree_set_grouped_view (ECellTree *cell_tree,
 
        cell_tree->grouped_view = grouped_view;
 }
+
+gboolean
+e_cell_tree_get_show_expander (ECellTree *cell_tree)
+{
+       g_return_val_if_fail (E_IS_CELL_TREE (cell_tree), FALSE);
+
+       return cell_tree->show_expander;
+}
+
+void
+e_cell_tree_set_show_expander (ECellTree *cell_tree,
+                              gboolean show_expander)
+{
+       g_return_if_fail (E_IS_CELL_TREE (cell_tree));
+
+       cell_tree->show_expander = show_expander;
+}
diff --git a/src/e-util/e-cell-tree.h b/src/e-util/e-cell-tree.h
index 14490a2..f53dde1 100644
--- a/src/e-util/e-cell-tree.h
+++ b/src/e-util/e-cell-tree.h
@@ -67,6 +67,7 @@ struct _ECellTree {
 
        gboolean draw_lines;
        gboolean grouped_view;
+       gboolean show_expander;
 
        ECell *subcell;
 };
@@ -77,15 +78,20 @@ struct _ECellTreeClass {
 
 GType          e_cell_tree_get_type            (void) G_GNUC_CONST;
 ECell *                e_cell_tree_new                 (gboolean draw_lines,
+                                                gboolean show_expander,
                                                 ECell *subcell);
 void           e_cell_tree_construct           (ECellTree *ect,
                                                 gboolean draw_lines,
+                                                gboolean show_expander,
                                                 ECell *subcell);
 ECellView *    e_cell_tree_view_get_subcell_view
                                                (ECellView *ect);
 gboolean       e_cell_tree_get_grouped_view    (ECellTree *cell_tree);
 void           e_cell_tree_set_grouped_view    (ECellTree *cell_tree,
                                                 gboolean grouped_view);
+gboolean       e_cell_tree_get_show_expander   (ECellTree *cell_tree);
+void           e_cell_tree_set_show_expander   (ECellTree *cell_tree,
+                                                gboolean show_expander);
 
 G_END_DECLS
 
diff --git a/src/e-util/e-table-extras.c b/src/e-util/e-table-extras.c
index 71f2797..c043bfb 100644
--- a/src/e-util/e-table-extras.c
+++ b/src/e-util/e-table-extras.c
@@ -323,7 +323,7 @@ e_table_extras_init (ETableExtras *extras)
        g_object_unref (cell);
 
        sub_cell = e_cell_text_new (NULL, GTK_JUSTIFY_LEFT);
-       cell = e_cell_tree_new (TRUE, sub_cell);
+       cell = e_cell_tree_new (TRUE, TRUE, sub_cell);
        e_table_extras_add_cell (extras, "tree-string", cell);
        g_object_unref (sub_cell);
        g_object_unref (cell);
diff --git a/src/mail/message-list.c b/src/mail/message-list.c
index da715fb..2c2ffab 100644
--- a/src/mail/message-list.c
+++ b/src/mail/message-list.c
@@ -107,6 +107,7 @@ struct _MessageListPrivate {
        gboolean thread_latest;
        gboolean thread_subject;
        gboolean any_row_changed; /* save state before regen list when this is set to true */
+       gboolean show_subject_above_sender;
 
        GtkTargetList *copy_target_list;
        GtkTargetList *paste_target_list;
@@ -181,6 +182,7 @@ enum {
        PROP_SESSION,
        PROP_SHOW_DELETED,
        PROP_SHOW_JUNK,
+       PROP_SHOW_SUBJECT_ABOVE_SENDER,
        PROP_THREAD_LATEST,
        PROP_THREAD_SUBJECT
 };
@@ -2110,16 +2112,19 @@ filter_date (const gint64 *pdate)
        return g_strdup (buf);
 }
 
-static ECell * create_composite_cell (gint col)
+static ECell *
+create_composite_cell (GSettings *mail_settings,
+                      gint col)
 {
-       ECell *cell_vbox, *cell_hbox, *cell_sub, *cell_date, *cell_from, *cell_tree, *cell_attach;
-       GSettings *settings;
+       ECell *cell_vbox, *cell_hbox, *cell_sub, *cell_date, *cell_from, *top_cell_tree, *bottom_cell_tree, 
*cell_attach;
        gboolean show_email;
-       gint alt_col = (col == COL_FROM) ? COL_SENDER : COL_RECIPIENTS;
+       gboolean show_subject_above_sender;
 
-       settings = e_util_ref_settings ("org.gnome.evolution.mail");
-       show_email = g_settings_get_boolean (settings, "show-email");
-       g_object_unref (settings);
+       show_email = g_settings_get_boolean (mail_settings, "show-email");
+       show_subject_above_sender = g_settings_get_boolean (mail_settings, "show-subject-above-sender");
+
+       if (!show_email)
+               col = (col == COL_FROM) ? COL_SENDER : COL_RECIPIENTS;
 
        cell_vbox = e_cell_vbox_new ();
 
@@ -2145,7 +2150,7 @@ static ECell * create_composite_cell (gint col)
                "color_column", COL_COLOUR,
                NULL);
 
-       e_cell_hbox_append (E_CELL_HBOX (cell_hbox), cell_from, show_email ? col : alt_col, 68);
+       e_cell_hbox_append (E_CELL_HBOX (cell_hbox), cell_from, show_subject_above_sender ? COL_SUBJECT : 
col, 68);
        e_cell_hbox_append (E_CELL_HBOX (cell_hbox), cell_attach, COL_ATTACHMENT, 5);
        e_cell_hbox_append (E_CELL_HBOX (cell_hbox), cell_date, COL_SENT, 27);
        g_object_unref (cell_from);
@@ -2157,21 +2162,62 @@ static ECell * create_composite_cell (gint col)
                cell_sub,
                "color_column", COL_COLOUR,
                NULL);
-       cell_tree = e_cell_tree_new (TRUE, cell_sub);
-       e_cell_vbox_append (E_CELL_VBOX (cell_vbox), cell_hbox, COL_FROM);
-       e_cell_vbox_append (E_CELL_VBOX (cell_vbox), cell_tree, COL_SUBJECT);
+       top_cell_tree = e_cell_tree_new (TRUE, FALSE, cell_hbox);
+       bottom_cell_tree = e_cell_tree_new (TRUE, TRUE, cell_sub);
+       e_cell_vbox_append (E_CELL_VBOX (cell_vbox), top_cell_tree, show_subject_above_sender ? COL_SUBJECT : 
col);
+       e_cell_vbox_append (E_CELL_VBOX (cell_vbox), bottom_cell_tree, show_subject_above_sender ? col : 
COL_SUBJECT);
        g_object_unref (cell_sub);
        g_object_unref (cell_hbox);
-       g_object_unref (cell_tree);
+       g_object_unref (top_cell_tree);
+       g_object_unref (bottom_cell_tree);
 
        g_object_set_data (G_OBJECT (cell_vbox), "cell_date", cell_date);
        g_object_set_data (G_OBJECT (cell_vbox), "cell_sub", cell_sub);
        g_object_set_data (G_OBJECT (cell_vbox), "cell_from", cell_from);
+       g_object_set_data (G_OBJECT (cell_vbox), "cell_hbox", cell_hbox);
+       g_object_set_data (G_OBJECT (cell_vbox), "address_model_col", GINT_TO_POINTER (col));
 
        return cell_vbox;
 }
 
 static void
+composite_cell_set_show_subject_above_sender (ECell *cell,
+                                             gboolean show_subject_above_sender)
+{
+       ECellVbox *cell_vbox;
+       ECellHbox *cell_hbox;
+       ECell *cell_from;
+       GObject *cell_obj;
+       gint address_model_col, cell_from_index;
+
+       g_return_if_fail (E_IS_CELL_VBOX (cell));
+
+       cell_obj = G_OBJECT (cell);
+       address_model_col = GPOINTER_TO_INT (g_object_get_data (cell_obj, "address_model_col"));
+
+       cell_vbox = E_CELL_VBOX (cell);
+       g_return_if_fail (cell_vbox->subcell_count == 2);
+       g_return_if_fail (cell_vbox->model_cols != NULL);
+
+       cell_from = g_object_get_data (cell_obj, "cell_from");
+       g_return_if_fail (E_IS_CELL (cell_from));
+
+       cell_hbox = g_object_get_data (cell_obj, "cell_hbox");
+       g_return_if_fail (E_IS_CELL_HBOX (cell_hbox));
+
+       for (cell_from_index = 0; cell_from_index < cell_hbox->subcell_count; cell_from_index++) {
+               if (cell_hbox->subcells[cell_from_index] == cell_from)
+                       break;
+       }
+
+       g_return_if_fail (cell_from_index < cell_hbox->subcell_count);
+
+       cell_hbox->model_cols[cell_from_index] = show_subject_above_sender ? COL_SUBJECT : address_model_col;
+       cell_vbox->model_cols[0] = show_subject_above_sender ? COL_SUBJECT : address_model_col;
+       cell_vbox->model_cols[1] = show_subject_above_sender ? address_model_col : COL_SUBJECT;
+}
+
+static void
 composite_cell_set_strike_col (ECell *cell,
                                gint strikeout_col,
                               gint strikeout_color_col)
@@ -2188,7 +2234,7 @@ composite_cell_set_strike_col (ECell *cell,
 }
 
 static ETableExtras *
-message_list_create_extras (void)
+message_list_create_extras (GSettings *mail_settings)
 {
        ETableExtras *extras;
        ECell *cell;
@@ -2250,7 +2296,7 @@ message_list_create_extras (void)
        e_table_extras_add_cell (extras, "render_text", cell);
        g_object_unref (cell);
 
-       cell = e_cell_tree_new (TRUE, cell);
+       cell = e_cell_tree_new (TRUE, TRUE, cell);
        e_table_extras_add_cell (extras, "render_tree", cell);
        g_object_unref (cell);
 
@@ -2266,11 +2312,11 @@ message_list_create_extras (void)
        g_object_unref (cell);
 
        /* Composite cell for wide view */
-       cell = create_composite_cell (COL_FROM);
+       cell = create_composite_cell (mail_settings, COL_FROM);
        e_table_extras_add_cell (extras, "render_composite_from", cell);
        g_object_unref (cell);
 
-       cell = create_composite_cell (COL_TO);
+       cell = create_composite_cell (mail_settings, COL_TO);
        e_table_extras_add_cell (extras, "render_composite_to", cell);
        g_object_unref (cell);
 
@@ -2853,6 +2899,12 @@ message_list_set_property (GObject *object,
                                g_value_get_boolean (value));
                        return;
 
+               case PROP_SHOW_SUBJECT_ABOVE_SENDER:
+                       message_list_set_show_subject_above_sender (
+                               MESSAGE_LIST (object),
+                               g_value_get_boolean (value));
+                       return;
+
                case PROP_THREAD_LATEST:
                        message_list_set_thread_latest (
                                MESSAGE_LIST (object),
@@ -2925,6 +2977,13 @@ message_list_get_property (GObject *object,
                                MESSAGE_LIST (object)));
                        return;
 
+               case PROP_SHOW_SUBJECT_ABOVE_SENDER:
+                       g_value_set_boolean (
+                               value,
+                               message_list_get_show_subject_above_sender (
+                               MESSAGE_LIST (object)));
+                       return;
+
                case PROP_THREAD_LATEST:
                        g_value_set_boolean (
                                value,
@@ -3594,6 +3653,18 @@ message_list_class_init (MessageListClass *class)
 
        g_object_class_install_property (
                object_class,
+               PROP_SHOW_SUBJECT_ABOVE_SENDER,
+               g_param_spec_boolean (
+                       "show-subject-above-sender",
+                       "Show Subject Above Sender",
+                       NULL,
+                       FALSE,
+                       G_PARAM_READWRITE |
+                       G_PARAM_CONSTRUCT |
+                       G_PARAM_STATIC_STRINGS));
+
+       g_object_class_install_property (
+               object_class,
                PROP_THREAD_LATEST,
                g_param_spec_boolean (
                        "thread-latest",
@@ -3752,7 +3823,7 @@ message_list_construct (MessageList *message_list)
        /*
         * The etree
         */
-       message_list->extras = message_list_create_extras ();
+       message_list->extras = message_list_create_extras (message_list->priv->mail_settings);
 
        etspecfile = g_build_filename (
                EVOLUTION_ETSPECDIR, "message-list.etspec", NULL);
@@ -5009,6 +5080,45 @@ message_list_set_show_junk (MessageList *message_list,
 }
 
 gboolean
+message_list_get_show_subject_above_sender (MessageList *message_list)
+{
+       g_return_val_if_fail (IS_MESSAGE_LIST (message_list), FALSE);
+
+       return message_list->priv->show_subject_above_sender;
+}
+
+void
+message_list_set_show_subject_above_sender (MessageList *message_list,
+                                           gboolean show_subject_above_sender)
+{
+       g_return_if_fail (IS_MESSAGE_LIST (message_list));
+
+       if (show_subject_above_sender == message_list->priv->show_subject_above_sender)
+               return;
+
+       message_list->priv->show_subject_above_sender = show_subject_above_sender;
+
+       if (message_list->extras) {
+               ECell *cell;
+
+               cell = e_table_extras_get_cell (message_list->extras, "render_composite_from");
+               if (cell)
+                       composite_cell_set_show_subject_above_sender (cell, show_subject_above_sender);
+
+               cell = e_table_extras_get_cell (message_list->extras, "render_composite_to");
+               if (cell)
+                       composite_cell_set_show_subject_above_sender (cell, show_subject_above_sender);
+
+               if (message_list->priv->folder &&
+                   gtk_widget_get_realized (GTK_WIDGET (message_list)) &&
+                   gtk_widget_get_visible (GTK_WIDGET (message_list)))
+                       mail_regen_list (message_list, NULL, FALSE);
+       }
+
+       g_object_notify (G_OBJECT (message_list), "show-subject-above-sender");
+}
+
+gboolean
 message_list_get_thread_latest (MessageList *message_list)
 {
        g_return_val_if_fail (IS_MESSAGE_LIST (message_list), FALSE);
diff --git a/src/mail/message-list.h b/src/mail/message-list.h
index bf3e3d4..801e88d 100644
--- a/src/mail/message-list.h
+++ b/src/mail/message-list.h
@@ -177,6 +177,11 @@ void               message_list_set_show_deleted   (MessageList *message_list,
 gboolean       message_list_get_show_junk      (MessageList *message_list);
 void           message_list_set_show_junk      (MessageList *message_list,
                                                 gboolean show_junk);
+gboolean       message_list_get_show_subject_above_sender
+                                               (MessageList *message_list);
+void           message_list_set_show_subject_above_sender
+                                               (MessageList *message_list,
+                                                gboolean show_subject_above_sender);
 gboolean       message_list_get_thread_latest  (MessageList *message_list);
 void           message_list_set_thread_latest  (MessageList *message_list,
                                                 gboolean thread_latest);
diff --git a/src/modules/settings/e-settings-message-list.c b/src/modules/settings/e-settings-message-list.c
index 019f45d..22018c7 100644
--- a/src/modules/settings/e-settings-message-list.c
+++ b/src/modules/settings/e-settings-message-list.c
@@ -57,6 +57,11 @@ settings_message_list_constructed (GObject *object)
                G_SETTINGS_BIND_GET);
 
        g_settings_bind (
+               settings, "show-subject-above-sender",
+               message_list, "show-subject-above-sender",
+               G_SETTINGS_BIND_GET);
+
+       g_settings_bind (
                settings, "thread-latest",
                message_list, "thread-latest",
                G_SETTINGS_BIND_GET);


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]