fix #1268
This commit is contained in:
parent
48e31b900c
commit
c2f767ea55
@ -104,6 +104,7 @@ SettingsFeedsMessages::SettingsFeedsMessages(Settings* settings, QWidget* parent
|
||||
this,
|
||||
&SettingsFeedsMessages::dirtifySettings);
|
||||
connect(m_ui->m_checkUpdateAllFeedsOnStartup, &QCheckBox::toggled, this, &SettingsFeedsMessages::dirtifySettings);
|
||||
connect(m_ui->m_cbLegacyArticleFormatting, &QCheckBox::toggled, this, &SettingsFeedsMessages::dirtifySettings);
|
||||
connect(m_ui->m_spinAutoUpdateInterval,
|
||||
static_cast<void (QDoubleSpinBox::*)(double)>(&QDoubleSpinBox::valueChanged),
|
||||
this,
|
||||
@ -252,6 +253,10 @@ void SettingsFeedsMessages::changeFont(QLabel& lbl) {
|
||||
void SettingsFeedsMessages::loadSettings() {
|
||||
onBeginLoadSettings();
|
||||
|
||||
if (!qApp->usingLite()) {
|
||||
m_ui->m_cbLegacyArticleFormatting->setVisible(false);
|
||||
}
|
||||
|
||||
m_ui->m_spinRelativeArticleTime
|
||||
->setValue(settings()->value(GROUP(Messages), SETTING(Messages::RelativeTimeForNewerArticles)).toInt());
|
||||
m_ui->m_spinPaddingRowsMessages
|
||||
@ -282,6 +287,11 @@ void SettingsFeedsMessages::loadSettings() {
|
||||
m_ui->m_spinAutoUpdateInterval->setValue(settings()->value(GROUP(Feeds), SETTING(Feeds::AutoUpdateInterval)).toInt());
|
||||
m_ui->m_spinFeedUpdateTimeout->setValue(settings()->value(GROUP(Feeds), SETTING(Feeds::UpdateTimeout)).toInt());
|
||||
|
||||
if (qApp->usingLite()) {
|
||||
m_ui->m_cbLegacyArticleFormatting
|
||||
->setChecked(settings()->value(GROUP(Messages), SETTING(Messages::UseLegacyArticleFormat)).toBool());
|
||||
}
|
||||
|
||||
m_ui->m_dtDateTimeToAvoid->setEnabled(false);
|
||||
m_ui->m_spinHoursAvoid->setEnabled(false);
|
||||
|
||||
@ -413,6 +423,12 @@ void SettingsFeedsMessages::saveSettings() {
|
||||
|
||||
settings()->setValue(GROUP(Messages), Messages::AvoidOldArticles, m_ui->m_gbAvoidOldArticles->isChecked());
|
||||
|
||||
if (qApp->usingLite()) {
|
||||
settings()->setValue(GROUP(Messages),
|
||||
Messages::UseLegacyArticleFormat,
|
||||
m_ui->m_cbLegacyArticleFormatting->isChecked());
|
||||
}
|
||||
|
||||
if (m_ui->m_rbAvoidAbsolute->isChecked()) {
|
||||
settings()->setValue(GROUP(Messages), Messages::DateTimeToAvoidArticle, m_ui->m_dtDateTimeToAvoid->dateTime());
|
||||
settings()->setValue(GROUP(Messages), Messages::HoursToAvoidArticle, 0);
|
||||
|
@ -386,14 +386,14 @@
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="4" column="0">
|
||||
<item row="5" column="0">
|
||||
<widget class="QCheckBox" name="m_checkBringToForegroundAfterMsgOpened">
|
||||
<property name="text">
|
||||
<string>Bring application window to front once article is opened in external web browser</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="5" column="0" colspan="2">
|
||||
<item row="6" column="0" colspan="2">
|
||||
<widget class="QGroupBox" name="groupBox">
|
||||
<property name="title">
|
||||
<string>Internal article viewer</string>
|
||||
@ -499,6 +499,13 @@
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="4" column="0" colspan="2">
|
||||
<widget class="QCheckBox" name="m_cbLegacyArticleFormatting">
|
||||
<property name="text">
|
||||
<string>Use legacy article formatting</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<widget class="QWidget" name="m_tabArticlesList">
|
||||
|
@ -250,7 +250,9 @@ void TextBrowserViewer::loadMessages(const QList<Message>& messages, RootItem* r
|
||||
m_root = root;
|
||||
|
||||
auto html_messages =
|
||||
qApp->skins()->generateHtmlOfArticles(messages, root, width() * ACCEPTABLE_IMAGE_PERCENTUAL_WIDTH);
|
||||
qApp->settings()->value(GROUP(Messages), SETTING(Messages::UseLegacyArticleFormat)).toBool()
|
||||
? prepareLegacyHtmlForMessage(messages, root)
|
||||
: qApp->skins()->generateHtmlOfArticles(messages, root, width() * ACCEPTABLE_IMAGE_PERCENTUAL_WIDTH);
|
||||
|
||||
// Remove other characters which cannot be displayed properly.
|
||||
static QRegularExpression exp_symbols("[0-9A-F]{3};");
|
||||
@ -535,6 +537,104 @@ void TextBrowserViewer::resourceDownloaded(const QUrl& url,
|
||||
downloadNextNeededResource();
|
||||
}
|
||||
|
||||
PreparedHtml TextBrowserViewer::prepareLegacyHtmlForMessage(const QList<Message>& messages, RootItem* selected_item) const {
|
||||
PreparedHtml html;
|
||||
bool acc_displays_enclosures =
|
||||
selected_item == nullptr || selected_item->getParentServiceRoot()->displaysEnclosures();
|
||||
|
||||
for (const Message& message : messages) {
|
||||
bool is_plain = !TextFactory::couldBeHtml(message.m_contents);
|
||||
|
||||
// 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);
|
||||
}
|
||||
else {
|
||||
html.m_html += QSL("<h2 align=\"center\">%1</h2>").arg(message.m_title);
|
||||
}
|
||||
|
||||
// Start contents.
|
||||
html.m_html += QSL("<div>");
|
||||
|
||||
// Add links to enclosures.
|
||||
if (acc_displays_enclosures) {
|
||||
for (const Enclosure& enc : message.m_enclosures) {
|
||||
html.m_html += QSL("[<a href=\"%1\">%2</a>]").arg(enc.m_url, enc.m_mimeType);
|
||||
}
|
||||
}
|
||||
|
||||
// Display enclosures which are pictures if user has it enabled.
|
||||
auto first_enc_break_added = false;
|
||||
|
||||
if (acc_displays_enclosures &&
|
||||
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, Qt::WhiteSpaceMode::WhiteSpaceNormal)
|
||||
: message.m_contents;
|
||||
|
||||
static QRegularExpression img_tag_rgx(QSL("\\<img[^\\>]*src\\s*=\\s*[\"\']([^\"\']*)[\"\'][^\\>]*\\>"),
|
||||
QRegularExpression::PatternOption::CaseInsensitiveOption |
|
||||
QRegularExpression::PatternOption::InvertedGreedinessOption);
|
||||
|
||||
// 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 += QSL("<br/>[%1] <a href=\"%2\">%2</a>").arg(tr("image"), captured_url);
|
||||
}
|
||||
|
||||
// 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::LimitArticleImagesHeight)).toInt();
|
||||
|
||||
// Fixup all "img" tags.
|
||||
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;
|
||||
auto* feed = selected_item->getParentServiceRoot()
|
||||
->getItemFromSubTree([messages](const RootItem* it) {
|
||||
return it->kind() == RootItem::Kind::Feed && it->customId() == messages.at(0).m_feedId;
|
||||
})
|
||||
->toFeed();
|
||||
|
||||
if (feed != nullptr) {
|
||||
QUrl url(NetworkFactory::sanitizeUrl(feed->source()));
|
||||
|
||||
if (url.isValid()) {
|
||||
base_url = url.scheme() + QSL("://") + url.host();
|
||||
}
|
||||
}
|
||||
|
||||
html.m_baseUrl = base_url;
|
||||
|
||||
return html;
|
||||
}
|
||||
|
||||
bool TextBrowserViewer::resourcesEnabled() const {
|
||||
return m_resourcesEnabled;
|
||||
}
|
||||
|
@ -94,6 +94,8 @@ class TextBrowserViewer : public QTextBrowser, public WebViewer {
|
||||
void closeWindowRequested();
|
||||
|
||||
private:
|
||||
PreparedHtml prepareLegacyHtmlForMessage(const QList<Message>& messages, RootItem* selected_item) const;
|
||||
|
||||
void setHtmlPrivate(const QString& html, const QUrl& base_url);
|
||||
BlockingResult blockedWithAdblock(const QUrl& url);
|
||||
|
||||
|
@ -143,6 +143,9 @@ DKEY Messages::ID = "messages";
|
||||
DKEY Messages::LimitArticleImagesHeight = "message_head_image_height";
|
||||
DVALUE(int) Messages::LimitArticleImagesHeightDef = 72;
|
||||
|
||||
DKEY Messages::UseLegacyArticleFormat = "legacy_article_format";
|
||||
DVALUE(bool) Messages::UseLegacyArticleFormatDef = false;
|
||||
|
||||
DKEY Messages::DisplayEnclosuresInMessage = "show_enclosures_in_message";
|
||||
DVALUE(bool) Messages::DisplayEnclosuresInMessageDef = false;
|
||||
|
||||
|
@ -140,6 +140,9 @@ namespace Messages {
|
||||
KEY LimitArticleImagesHeight;
|
||||
VALUE(int) LimitArticleImagesHeightDef;
|
||||
|
||||
KEY UseLegacyArticleFormat;
|
||||
VALUE(bool) UseLegacyArticleFormatDef;
|
||||
|
||||
KEY DisplayEnclosuresInMessage;
|
||||
VALUE(bool) DisplayEnclosuresInMessageDef;
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user