Skip to content

Commit

Permalink
Redisplay the body with the same part as previously displayed.
Browse files Browse the repository at this point in the history
This solves the bug that when clicking on Show text or html part
in the body to toggle between them, and then toggling another
element of the display, such as headers, it went back to
showing text or html according to the configured default rather than
the current choice.
  • Loading branch information
manitou-mail committed Mar 25, 2018
1 parent f97f66d commit 17aebc7
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 27 deletions.
6 changes: 3 additions & 3 deletions 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)
Expand Down Expand Up @@ -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
Expand All @@ -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();
Expand Down
23 changes: 11 additions & 12 deletions 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)
Expand Down Expand Up @@ -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);
}
}

Expand Down Expand Up @@ -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();
Expand All @@ -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;
Expand Down Expand Up @@ -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 = "<html><body>";
b2.append(h);
b2.append("<div id=\"manitou-body\">");
Expand Down Expand Up @@ -508,19 +505,21 @@ 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();
}

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();
}

Expand Down
15 changes: 13 additions & 2 deletions 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)
Expand Down Expand Up @@ -51,7 +51,14 @@ class message_view : public QWidget
void highlight_terms(const std::list<searched_text>&);

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;
Expand All @@ -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:
Expand Down Expand Up @@ -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<searched_text> m_highlight_words;
Expand Down
22 changes: 14 additions & 8 deletions src/msg_list_window.cpp
Expand Up @@ -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);
}
}
}
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -915,23 +915,23 @@ 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
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
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
Expand Down Expand Up @@ -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);
}
}

Expand Down Expand Up @@ -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);
}
}
Expand Down
4 changes: 2 additions & 2 deletions 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)
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit 17aebc7

Please sign in to comment.