mirror of
https://github.com/qbittorrent/qBittorrent
synced 2025-07-06 05:01:25 -07:00
Merge pull request #22761 from Chocobo1/rss_fields
Add 'Open link' to RSS article header
This commit is contained in:
commit
afcfea5b8f
1 changed files with 23 additions and 21 deletions
|
@ -333,7 +333,7 @@ void RSSWidget::on_newFeedButton_clicked()
|
||||||
|
|
||||||
// Ask for feed URL
|
// Ask for feed URL
|
||||||
const QString clipText = qApp->clipboard()->text();
|
const QString clipText = qApp->clipboard()->text();
|
||||||
const QString defaultURL = Net::DownloadManager::hasSupportedScheme(clipText) ? clipText : u"http://"_s;
|
const QString defaultURL = Net::DownloadManager::hasSupportedScheme(clipText) ? clipText : u"https://"_s;
|
||||||
|
|
||||||
RSS::Feed *newFeed = nullptr;
|
RSS::Feed *newFeed = nullptr;
|
||||||
RSSFeedDialog dialog {this};
|
RSSFeedDialog dialog {this};
|
||||||
|
@ -623,58 +623,60 @@ void RSSWidget::renderArticle(const RSS::Article *article) const
|
||||||
{
|
{
|
||||||
Q_ASSERT(article);
|
Q_ASSERT(article);
|
||||||
|
|
||||||
|
const QString articleLink = article->link();
|
||||||
const QString highlightedBaseColor = m_ui->textBrowser->palette().color(QPalette::Active, QPalette::Highlight).name();
|
const QString highlightedBaseColor = m_ui->textBrowser->palette().color(QPalette::Active, QPalette::Highlight).name();
|
||||||
const QString highlightedBaseTextColor = m_ui->textBrowser->palette().color(QPalette::Active, QPalette::HighlightedText).name();
|
const QString highlightedBaseTextColor = m_ui->textBrowser->palette().color(QPalette::Active, QPalette::HighlightedText).name();
|
||||||
const QString alternateBaseColor = m_ui->textBrowser->palette().color(QPalette::Active, QPalette::AlternateBase).name();
|
const QString alternateBaseColor = m_ui->textBrowser->palette().color(QPalette::Active, QPalette::AlternateBase).name();
|
||||||
|
|
||||||
QString html =
|
QString html = u"<div style='border: 2px solid red; margin-left: 5px; margin-right: 5px; margin-bottom: 5px;'>"
|
||||||
u"<div style='border: 2px solid red; margin-left: 5px; margin-right: 5px; margin-bottom: 5px;'>" +
|
+ u"<div style='background-color: \"%1\"; font-weight: bold; color: \"%2\";'>%3</div>"_s.arg(highlightedBaseColor, highlightedBaseTextColor, article->title());
|
||||||
u"<div style='background-color: \"%1\"; font-weight: bold; color: \"%2\";'>%3</div>"_s.arg(highlightedBaseColor, highlightedBaseTextColor, article->title());
|
if (const QDateTime articleDate = article->date(); articleDate.isValid())
|
||||||
if (article->date().isValid())
|
html += u"<div style='background-color: \"%1\";'><b>%2</b>%3</div>"_s.arg(alternateBaseColor, tr("Date: "), QLocale::system().toString(articleDate.toLocalTime(), QLocale::ShortFormat));
|
||||||
html += u"<div style='background-color: \"%1\";'><b>%2</b>%3</div>"_s.arg(alternateBaseColor, tr("Date: "), QLocale::system().toString(article->date().toLocalTime(), QLocale::ShortFormat));
|
|
||||||
if (m_ui->feedListWidget->currentItem() == m_ui->feedListWidget->stickyUnreadItem())
|
if (m_ui->feedListWidget->currentItem() == m_ui->feedListWidget->stickyUnreadItem())
|
||||||
html += u"<div style='background-color: \"%1\";'><b>%2</b>%3</div>"_s.arg(alternateBaseColor, tr("Feed: "), article->feed()->title());
|
html += u"<div style='background-color: \"%1\";'><b>%2</b>%3</div>"_s.arg(alternateBaseColor, tr("Feed: "), article->feed()->title());
|
||||||
if (!article->author().isEmpty())
|
if (const QString articleAuthor = article->author(); !articleAuthor.isEmpty())
|
||||||
html += u"<div style='background-color: \"%1\";'><b>%2</b>%3</div>"_s.arg(alternateBaseColor, tr("Author: "), article->author());
|
html += u"<div style='background-color: \"%1\";'><b>%2</b>%3</div>"_s.arg(alternateBaseColor, tr("Author: "), articleAuthor);
|
||||||
|
if (!articleLink.isEmpty())
|
||||||
|
html += u"<div style='background-color: \"%1\";'><a href='%2' target='_blank'><b>%3</b></a></div>"_s.arg(alternateBaseColor, articleLink, tr("Open link"));
|
||||||
html += u"</div>"
|
html += u"</div>"
|
||||||
u"<div style='margin-left: 5px; margin-right: 5px;'>";
|
u"<div style='margin-left: 5px; margin-right: 5px;'>";
|
||||||
if (Qt::mightBeRichText(article->description()))
|
if (QString description = article->description(); Qt::mightBeRichText(description))
|
||||||
{
|
{
|
||||||
html += article->description();
|
html += description;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
QString description = article->description();
|
|
||||||
QRegularExpression rx;
|
QRegularExpression rx;
|
||||||
// If description is plain text, replace BBCode tags with HTML and wrap everything in <pre></pre> so it looks nice
|
// If description is plain text, replace BBCode tags with HTML and wrap everything in <pre></pre> so it looks nice
|
||||||
rx.setPatternOptions(QRegularExpression::InvertedGreedinessOption
|
rx.setPatternOptions(QRegularExpression::InvertedGreedinessOption
|
||||||
| QRegularExpression::CaseInsensitiveOption);
|
| QRegularExpression::CaseInsensitiveOption);
|
||||||
|
|
||||||
rx.setPattern(u"\\[img\\](.+)\\[/img\\]"_s);
|
rx.setPattern(u"\\[img\\](.+)\\[/img\\]"_s);
|
||||||
description = description.replace(rx, u"<img src=\"\\1\">"_s);
|
description.replace(rx, u"<img src=\"\\1\">"_s);
|
||||||
|
|
||||||
rx.setPattern(u"\\[url=(\")?(.+)\\1\\]"_s);
|
rx.setPattern(u"\\[url=(\")?(.+)\\1\\]"_s);
|
||||||
description = description.replace(rx, u"<a href=\"\\2\">"_s);
|
description.replace(rx, u"<a href=\"\\2\">"_s)
|
||||||
description = description.replace(u"[/url]"_s, u"</a>"_s, Qt::CaseInsensitive);
|
.replace(u"[/url]"_s, u"</a>"_s, Qt::CaseInsensitive);
|
||||||
|
|
||||||
rx.setPattern(u"\\[(/)?([bius])\\]"_s);
|
rx.setPattern(u"\\[(/)?([bius])\\]"_s);
|
||||||
description = description.replace(rx, u"<\\1\\2>"_s);
|
description.replace(rx, u"<\\1\\2>"_s);
|
||||||
|
|
||||||
rx.setPattern(u"\\[color=(\")?(.+)\\1\\]"_s);
|
rx.setPattern(u"\\[color=(\")?(.+)\\1\\]"_s);
|
||||||
description = description.replace(rx, u"<span style=\"color:\\2\">"_s);
|
description.replace(rx, u"<span style=\"color:\\2\">"_s)
|
||||||
description = description.replace(u"[/color]"_s, u"</span>"_s, Qt::CaseInsensitive);
|
.replace(u"[/color]"_s, u"</span>"_s, Qt::CaseInsensitive);
|
||||||
|
|
||||||
rx.setPattern(u"\\[size=(\")?(.+)\\d\\1\\]"_s);
|
rx.setPattern(u"\\[size=(\")?(.+)\\d\\1\\]"_s);
|
||||||
description = description.replace(rx, u"<span style=\"font-size:\\2px\">"_s);
|
description.replace(rx, u"<span style=\"font-size:\\2px\">"_s)
|
||||||
description = description.replace(u"[/size]"_s, u"</span>"_s, Qt::CaseInsensitive);
|
.replace(u"[/size]"_s, u"</span>"_s, Qt::CaseInsensitive);
|
||||||
|
|
||||||
html += u"<pre>" + description + u"</pre>";
|
html += u"<pre>" + description + u"</pre>";
|
||||||
}
|
}
|
||||||
|
html += u"</div>";
|
||||||
|
|
||||||
// Supplement relative URLs to absolute ones
|
// Supplement relative URLs to absolute ones
|
||||||
const QUrl url {article->link()};
|
const QUrl url {articleLink};
|
||||||
const QString baseUrl = url.toString(QUrl::RemovePath | QUrl::RemoveQuery);
|
const QString baseUrl = url.toString(QUrl::RemovePath | QUrl::RemoveQuery);
|
||||||
convertRelativeUrlToAbsolute(html, baseUrl);
|
convertRelativeUrlToAbsolute(html, baseUrl);
|
||||||
html += u"</div>";
|
|
||||||
m_ui->textBrowser->setHtml(html);
|
m_ui->textBrowser->setHtml(html);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue