[balsa/75-peter] body: Restore mp_alt_selection member



commit fb518bbd67b6f4166a7f6ea1b466f8205bb6195d
Author: Peter Bloomfield <PeterBloomfield bellsouth net>
Date:   Thu May 12 13:56:20 2022 -0400

    body: Restore mp_alt_selection member
    
    Restore the `LibBalsaMpAltSelection mp_alt_selection;` member in the
    `LibBalsaMessageBody` structure, and use it to remember the most recent
    `HTML vs text/plain` selection for this part.

 libbalsa/body.c | 21 ++++++++++++++++++---
 libbalsa/body.h |  5 ++++-
 2 files changed, 22 insertions(+), 4 deletions(-)
---
diff --git a/libbalsa/body.c b/libbalsa/body.c
index aa6b614ea..e300ae969 100644
--- a/libbalsa/body.c
+++ b/libbalsa/body.c
@@ -1035,9 +1035,13 @@ libbalsa_message_body_set_mp_alt_selection(LibBalsaMessageBody *body, gpointer k
                        }
                        g_free(conttype);
 
+                        /* Remember the most recent selection: */
+                        mp_alt_body->mp_alt_selection = selection;
+
                         if (mp_alt_body->selection_table == NULL)
                             mp_alt_body->selection_table = g_hash_table_new(NULL, NULL);
 
+                        /* Remember the most recent selection for this key: */
                         if (g_hash_table_insert(mp_alt_body->selection_table, key,
                                                 GINT_TO_POINTER(selection))) {
                             g_object_weak_ref(key, body_weak_notify, mp_alt_body);
@@ -1060,15 +1064,26 @@ static inline gboolean body_is_type(const LibBalsaMessageBody *body,
 LibBalsaMpAltSelection
 libbalsa_message_body_get_mp_alt_selection(LibBalsaMessageBody *body, gpointer key)
 {
-       LibBalsaMpAltSelection selection = LIBBALSA_MP_ALT_AUTO;
+       LibBalsaMpAltSelection selection;
 
-       g_return_val_if_fail(body != NULL, FALSE);
+       g_return_val_if_fail(body != NULL, LIBBALSA_MP_ALT_AUTO);
 
        if (!body_is_type(body, "multipart", "alternative"))
             body = find_mp_alt_parent(body);
 
-       if (body != NULL && body->selection_table != NULL)
+       if (body == NULL) {
+            selection = LIBBALSA_MP_ALT_AUTO;
+        } else {
+            if (body->selection_table != NULL && g_hash_table_contains(body->selection_table, key)) {
+                /* The part is currently being viewed, so return the
+                 * selection that was used to view it: */
                selection = GPOINTER_TO_INT(g_hash_table_lookup(body->selection_table, key));
+            } else {
+                /* The part is not currently being viewed, so return the
+                 * most recent selection: */
+                selection = body->mp_alt_selection;
+            }
+        }
 
        return selection;
 }
diff --git a/libbalsa/body.h b/libbalsa/body.h
index 5affc4c8f..2650df728 100644
--- a/libbalsa/body.h
+++ b/libbalsa/body.h
@@ -93,7 +93,10 @@ struct _LibBalsaMessageBody {
 
 #ifdef HAVE_HTML_WIDGET
     gboolean html_ext_loaded;  /* if external HTML content was loaded */
-    GHashTable *selection_table; /* which part of a multipart/alternative is selected for a given key*/
+    LibBalsaMpAltSelection mp_alt_selection; /* which part of a multipart/alternative
+                                                was most recently selected */
+    GHashTable *selection_table;             /* which part of a multipart/alternative
+                                                was most recently selected for a given key */
 #endif /* HAVE_HTML_WIDGET */
 
     LibBalsaMessageBody *parent;       /* Parent part in the message */


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