diff --git a/src/filter_results_window.cpp b/src/filter_results_window.cpp index 2710bfd..91b694d 100644 --- a/src/filter_results_window.cpp +++ b/src/filter_results_window.cpp @@ -1,4 +1,4 @@ -/* Copyright (C) 2011 Daniel Verite +/* Copyright (C) 2011-2018 Daniel Verite This file is part of Manitou-Mail (see http://www.manitou-mail.org) @@ -224,7 +224,7 @@ filter_result_message_view::set_headers_visibility(int level) if (level>2) level=2; prefs.m_show_headers_level = level; - m_msg_view->display_body(prefs, 0); + m_msg_view->display_body(prefs, message_view::default_conf); } void @@ -233,7 +233,7 @@ filter_result_message_view::set_message(mail_msg* msg) m_msg_view->set_mail_item(msg); display_prefs prefs; prefs.init(); - m_msg_view->display_body(prefs, 0); + m_msg_view->display_body(prefs, message_view::default_conf); // display attachments m_attch_listview->clear(); diff --git a/src/message_view.cpp b/src/message_view.cpp index 4155cb0..5ebd016 100644 --- a/src/message_view.cpp +++ b/src/message_view.cpp @@ -1,4 +1,4 @@ -/* Copyright (C) 2004-2017 Daniel Verite +/* Copyright (C) 2004-2018 Daniel Verite This file is part of Manitou-Mail (see http://www.manitou-mail.org) @@ -262,7 +262,7 @@ message_view::set_show_on_demand(bool b) } else { if (m_parent) - display_body(m_parent->get_display_prefs(), 0); + display_body(m_parent->get_display_prefs(), default_conf); } } @@ -314,17 +314,14 @@ message_view::ask_for_external_contents() enable_command("fetch", true); } -/* - preferred_format: 0=from config, 1=text, 2=html -*/ void -message_view::display_body(const display_prefs& prefs, int preferred_format) +message_view::display_body(const display_prefs& prefs, display_part preferred_part) { if (!m_pmsg) return; - if (preferred_format==0) { - preferred_format = get_config().get_string("display/body/preferred_format").toLower()=="text" ? 1: 2; + if (preferred_part == default_conf) { + preferred_part = get_config().get_string("display/body/preferred_format").toLower()=="text" ? text_part: html_part; } reset_state(); @@ -346,7 +343,7 @@ message_view::display_body(const display_prefs& prefs, int preferred_format) attchs.fetch(); } - if (preferred_format==1) { + if (preferred_part == text_part) { if (body_text.isEmpty()) { if (attchs.size() > 0) { attachments_list::iterator iter; @@ -375,7 +372,7 @@ message_view::display_body(const display_prefs& prefs, int preferred_format) m_has_text_part = !body_text.isEmpty(); m_has_html_part = (html_attachment!=NULL || !body_html.isEmpty()); - if (preferred_format==1 || body_html.isEmpty()) { + if (preferred_part==text_part || body_html.isEmpty()) { QString b2 = ""; b2.append(h); b2.append("
"); @@ -508,9 +505,10 @@ void message_view::show_text_part() { if (m_parent) - display_body(m_parent->get_display_prefs(), 1); + display_body(m_parent->get_display_prefs(), text_part); enable_command("to_html", m_has_html_part); enable_command("to_text", false); + m_displayed_part = message_view::text_part; display_commands(); } @@ -518,9 +516,10 @@ void message_view::show_html_part() { if (m_parent) - display_body(m_parent->get_display_prefs(), 2); + display_body(m_parent->get_display_prefs(), html_part); enable_command("to_text", m_has_text_part); enable_command("to_html", false); + m_displayed_part = message_view::html_part; display_commands(); } diff --git a/src/message_view.h b/src/message_view.h index 7449b33..14c9908 100644 --- a/src/message_view.h +++ b/src/message_view.h @@ -1,4 +1,4 @@ -/* Copyright (C) 2004-2017 Daniel Verite +/* Copyright (C) 2004-2018 Daniel Verite This file is part of Manitou-Mail (see http://www.manitou-mail.org) @@ -51,7 +51,14 @@ class message_view : public QWidget void highlight_terms(const std::list&); QSize sizeHint() const; - void display_body(const display_prefs& prefs, int preferred_format=0); + /* which part should be displayed */ + enum display_part { + default_conf = 0, // text or html, as decided by the configuration + text_part, // choose text + html_part // choose html + }; + void display_body(const display_prefs& prefs, + display_part preferred_format = default_conf); void set_html_contents(const QString& body, int type); QString selected_text() const; int content_type_shown() const; @@ -61,6 +68,9 @@ class message_view : public QWidget QString hovered_link() const { return m_hovered_link; } + display_part displayed_part() const { + return m_displayed_part; + } protected: void keyPressEvent(QKeyEvent*); public slots: @@ -95,6 +105,7 @@ private slots: bool m_ext_contents; bool m_has_text_part; bool m_has_html_part; + display_part m_displayed_part = default_conf; QString m_hovered_link; qreal m_zoom_factor; std::list m_highlight_words; diff --git a/src/msg_list_window.cpp b/src/msg_list_window.cpp index 0a855c1..14b3f54 100644 --- a/src/msg_list_window.cpp +++ b/src/msg_list_window.cpp @@ -121,7 +121,7 @@ msg_list_window::search_text_changed(const QString& newtext) m_highlighted_text.clear(); if (!m_fetch_on_demand) { m_msgview->clear(); - display_body(); + display_body(true); } } } @@ -378,7 +378,7 @@ msg_list_window::tag_toggled(int tag_id, bool checked) } if (m_pCurrentItem) { // redisplay the body - display_body(); + display_body(true); } QString msg_result = checked ? tr("%1 message(s) tagged.") : tr("%1 message(s) untagged."); statusBar()->showMessage(msg_result.arg(idx), 3000); @@ -915,7 +915,7 @@ msg_list_window::toggle_include_tags_in_headers(bool include) { display_vars.m_show_tags_in_headers = include; if (!m_fetch_on_demand) - display_body(); + display_body(true); } void @@ -923,7 +923,7 @@ msg_list_window::toggle_hide_quoted(bool hide) { display_vars.m_hide_quoted = hide; if (!m_fetch_on_demand) - display_body(); + display_body(true); } void @@ -931,7 +931,7 @@ msg_list_window::toggle_show_filters_log(bool show) { display_vars.m_show_filters_trace = show; if (!m_fetch_on_demand) - display_body(); + display_body(true); } void @@ -2613,7 +2613,7 @@ msg_list_window::search_finished() m_highlighted_text.clear(); if (!m_fetch_on_demand) { m_msgview->clear(); - display_body(); + display_body(true); } } @@ -3544,11 +3544,17 @@ msg_list_window::apply_conf(app_config& conf) } } +/* + keep_part: when true, keep the previous text/html choice. + otherwise, choose text or html per configuration +*/ void -msg_list_window::display_body() +msg_list_window::display_body(bool keep_part) { if (m_pCurrentItem) { - m_msgview->display_body(display_vars, 0); + m_msgview->display_body(display_vars, + keep_part ? m_msgview->displayed_part() : + message_view::default_conf); m_msgview->highlight_terms(m_highlighted_text); } } diff --git a/src/msg_list_window.h b/src/msg_list_window.h index 0154398..ff3cdb3 100644 --- a/src/msg_list_window.h +++ b/src/msg_list_window.h @@ -1,4 +1,4 @@ -/* Copyright (C) 2004-2017 Daniel Verite +/* Copyright (C) 2004-2018 Daniel Verite This file is part of Manitou-Mail (see http://www.manitou-mail.org) @@ -287,7 +287,7 @@ public slots: QString sprint_headers(mail_msg*); void display_msg_note(); - void display_body(); + void display_body(bool keep_part=false); // menu entries enum {