add ability to display attachments directly in text-based previewer + enhance feed download logic to allow proper exceptions catching and feed error propagation!
This commit is contained in:
parent
e142522af7
commit
11b99604ac
@ -26,7 +26,7 @@
|
||||
<url type="donation">https://github.com/sponsors/martinrotter</url>
|
||||
<content_rating type="oars-1.1" />
|
||||
<releases>
|
||||
<release version="4.2.3" date="2022-08-27"/>
|
||||
<release version="4.2.3" date="2022-08-29"/>
|
||||
</releases>
|
||||
<content_rating type="oars-1.0">
|
||||
<content_attribute id="violence-cartoon">none</content_attribute>
|
||||
|
@ -88,6 +88,9 @@ PreparedHtml TextBrowserViewer::prepareHtmlForMessage(const QList<Message>& mess
|
||||
PreparedHtml html;
|
||||
|
||||
for (const Message& message : messages) {
|
||||
bool is_plain = !Qt::mightBeRichText(message.m_contents.simplified());
|
||||
|
||||
// Add title.
|
||||
if (!message.m_url.isEmpty()) {
|
||||
html.m_html += QSL("<h2 align=\"center\"><a href=\"%2\">%1</a></h2>").arg(message.m_title, message.m_url);
|
||||
}
|
||||
@ -95,36 +98,61 @@ PreparedHtml TextBrowserViewer::prepareHtmlForMessage(const QList<Message>& mess
|
||||
html.m_html += QSL("<h2 align=\"center\">%1</h2>").arg(message.m_title);
|
||||
}
|
||||
|
||||
// Start contents.
|
||||
html.m_html += QSL("<div>");
|
||||
|
||||
// Add links to enclosures.
|
||||
for (const Enclosure& enc : message.m_enclosures) {
|
||||
html.m_html += QString("[%2] <a href=\"%1\">%1</a><br/>").arg(enc.m_url, enc.m_mimeType);
|
||||
html.m_html += QSL("[%2] <a href=\"%1\">%1</a><br/>").arg(enc.m_url, enc.m_mimeType);
|
||||
}
|
||||
|
||||
// Display enclosures which are pictures if user has it enabled.
|
||||
auto first_enc_break_added = false;
|
||||
|
||||
if (qApp->settings()->value(GROUP(Messages), SETTING(Messages::DisplayEnclosuresInMessage)).toBool()) {
|
||||
for (const Enclosure& enc : message.m_enclosures) {
|
||||
if (enc.m_mimeType.startsWith(QSL("image/"))) {
|
||||
if (!first_enc_break_added) {
|
||||
html.m_html += QSL("<br/>");
|
||||
first_enc_break_added = true;
|
||||
}
|
||||
|
||||
html.m_html += QSL("<img src=\"%1\" /><br/>").arg(enc.m_url);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Append actual contents of article and convert to HTML if needed.
|
||||
html.m_html += is_plain ? Qt::convertFromPlainText(message.m_contents) : message.m_contents;
|
||||
|
||||
static QRegularExpression img_tag_rgx("\\<img[^\\>]*src\\s*=\\s*[\"\']([^\"\']*)[\"\'][^\\>]*\\>",
|
||||
QRegularExpression::PatternOption::CaseInsensitiveOption |
|
||||
QRegularExpression::PatternOption::InvertedGreedinessOption);
|
||||
QRegularExpressionMatchIterator i = img_tag_rgx.globalMatch(message.m_contents);
|
||||
|
||||
// Extract all images links from article to be appended to end of article.
|
||||
QRegularExpressionMatchIterator i = img_tag_rgx.globalMatch(html.m_html);
|
||||
QString pictures_html;
|
||||
|
||||
while (i.hasNext()) {
|
||||
QRegularExpressionMatch match = i.next();
|
||||
auto captured_url = match.captured(1);
|
||||
|
||||
pictures_html += QString("<br/>[%1] <a href=\"%2\">%2</a>").arg(tr("image"), captured_url);
|
||||
pictures_html += QSL("<br/>[%1] <a href=\"%2\">%2</a>").arg(tr("image"), captured_url);
|
||||
}
|
||||
|
||||
QString cnts = message.m_contents;
|
||||
|
||||
// Make alla images clickable as links and also resize them if user has it setup.
|
||||
auto forced_img_size = qApp->settings()->value(GROUP(Messages), SETTING(Messages::MessageHeadImageHeight)).toInt();
|
||||
|
||||
// Fixup all "img" tags.
|
||||
html.m_html += cnts.replace(img_tag_rgx,
|
||||
QSL("<a href=\"\\1\"><img height=\"%1\" src=\"\\1\" /></a>")
|
||||
.arg(forced_img_size <= 0 ? QString() : QString::number(forced_img_size)));
|
||||
html.m_html = html.m_html.replace(img_tag_rgx,
|
||||
QSL("<a href=\"\\1\"><img height=\"%1\" src=\"\\1\" /></a>")
|
||||
.arg(forced_img_size <= 0 ? QString() : QString::number(forced_img_size)));
|
||||
|
||||
// Append generated list of images.
|
||||
html.m_html += pictures_html;
|
||||
}
|
||||
|
||||
// Close contents.
|
||||
html.m_html += QSL("</div>");
|
||||
|
||||
QString base_url;
|
||||
|
Loading…
x
Reference in New Issue
Block a user