update helpspoiler to display HTML, properly show TT-RSS error when method not found, disable intelligent sync by default in tt-rss, update warning regarding 3rd party plugin

This commit is contained in:
Martin Rotter 2023-01-30 09:30:11 +01:00
parent a3510afd4d
commit feb4de0833
5 changed files with 63 additions and 41 deletions

View file

@ -9,15 +9,16 @@
#include "miscellaneous/iconfactory.h" #include "miscellaneous/iconfactory.h"
#include <QGridLayout> #include <QGridLayout>
#include <QLabel>
#include <QParallelAnimationGroup> #include <QParallelAnimationGroup>
#include <QPropertyAnimation> #include <QPropertyAnimation>
#include <QScrollArea> #include <QScrollArea>
#include <QTextEdit>
#include <QToolButton> #include <QToolButton>
HelpSpoiler::HelpSpoiler(QWidget* parent) : QWidget(parent), HelpSpoiler::HelpSpoiler(QWidget* parent)
m_btnToggle(new QToolButton(this)), m_content(new QScrollArea(this)), m_animation(new QParallelAnimationGroup(this)), : QWidget(parent), m_btnToggle(new QToolButton(this)), m_content(new QScrollArea(this)),
m_layout(new QGridLayout(this)), m_text(new QLabel(this)), m_btnHelp(new PlainToolButton(this)) { m_animation(new QParallelAnimationGroup(this)), m_layout(new QGridLayout(this)), m_text(new QTextEdit(this)),
m_btnHelp(new PlainToolButton(this)) {
m_btnToggle->setStyleSheet(QSL("QToolButton { border: none; }")); m_btnToggle->setStyleSheet(QSL("QToolButton { border: none; }"));
m_btnToggle->setToolButtonStyle(Qt::ToolButtonStyle::ToolButtonTextBesideIcon); m_btnToggle->setToolButtonStyle(Qt::ToolButtonStyle::ToolButtonTextBesideIcon);
@ -47,12 +48,8 @@ HelpSpoiler::HelpSpoiler(QWidget* parent) : QWidget(parent),
m_layout->addWidget(m_content, 1, 0, 1, 2); m_layout->addWidget(m_content, 1, 0, 1, 2);
QObject::connect(m_btnToggle, &QToolButton::clicked, [this](const bool checked) { QObject::connect(m_btnToggle, &QToolButton::clicked, [this](const bool checked) {
const auto collapsed_height = sizeHint().height() - m_content->maximumHeight(); const auto collapsed_height = m_btnHelp->height();
auto content_height = m_text->fontMetrics().boundingRect(QRect(QPoint(0, 0), auto content_height = m_text->document()->size().height() + 22;
QPoint(m_text->width(), 1000)),
Qt::TextFlag::TextWordWrap,
m_text->text()).height() +
(2 * m_text->fontMetrics().lineSpacing());
for (int i = 0; i < m_animation->animationCount() - 1; i++) { for (int i = 0; i < m_animation->animationCount() - 1; i++) {
QPropertyAnimation* spoiler_animation = static_cast<QPropertyAnimation*>(m_animation->animationAt(i)); QPropertyAnimation* spoiler_animation = static_cast<QPropertyAnimation*>(m_animation->animationAt(i));
@ -62,37 +59,46 @@ HelpSpoiler::HelpSpoiler(QWidget* parent) : QWidget(parent),
spoiler_animation->setEndValue(collapsed_height + content_height); spoiler_animation->setEndValue(collapsed_height + content_height);
} }
QPropertyAnimation* content_animation = static_cast<QPropertyAnimation*>(m_animation->animationAt(m_animation->animationCount() - 1)); QPropertyAnimation* content_animation =
static_cast<QPropertyAnimation*>(m_animation->animationAt(m_animation->animationCount() - 1));
content_animation->setDuration(100); content_animation->setDuration(100);
content_animation->setStartValue(0); content_animation->setStartValue(0);
content_animation->setEndValue(content_height); content_animation->setEndValue(content_height);
m_btnToggle->setArrowType(checked m_btnToggle->setArrowType(checked ? Qt::ArrowType::DownArrow : Qt::ArrowType::RightArrow);
? Qt::ArrowType::DownArrow m_animation->setDirection(checked ? QAbstractAnimation::Direction::Forward
: Qt::ArrowType::RightArrow);
m_animation->setDirection(checked
? QAbstractAnimation::Direction::Forward
: QAbstractAnimation::Direction::Backward); : QAbstractAnimation::Direction::Backward);
m_animation->start(); m_animation->start();
}); });
m_text->setMargin(0); m_text->viewport()->setAutoFillBackground(false);
m_text->setWordWrap(true); m_text->setFrameShape(QFrame::Shape::NoFrame);
m_text->setTextInteractionFlags(Qt::TextInteractionFlag::TextBrowserInteraction);
m_text->setVerticalScrollBarPolicy(Qt::ScrollBarPolicy::ScrollBarAlwaysOff);
m_text->setHorizontalScrollBarPolicy(Qt::ScrollBarPolicy::ScrollBarAlwaysOff);
m_text->setWordWrapMode(QTextOption::WrapMode::WordWrap);
auto* content_layout = new QVBoxLayout(m_content); auto* content_layout = new QVBoxLayout(m_content);
content_layout->addWidget(m_text, 1); content_layout->addWidget(m_text, 1);
} }
void HelpSpoiler::setHelpText(const QString& title, const QString& text, bool is_warning) { void HelpSpoiler::setHelpText(const QString& title, const QString& text, bool is_warning, bool force_html) {
m_btnToggle->setText(title); m_btnToggle->setText(title);
setHelpText(text, is_warning); setHelpText(text, is_warning);
} }
void HelpSpoiler::setHelpText(const QString& text, bool is_warning) { void HelpSpoiler::setHelpText(const QString& text, bool is_warning, bool force_html) {
m_text->setText(text); if (force_html) {
m_btnHelp->setIcon(is_warning m_text->setHtml(text);
? qApp->icons()->fromTheme(QSL("dialog-warning")) }
: qApp->icons()->fromTheme(QSL("dialog-question"))); else {
m_text->setText(text);
}
m_btnHelp->setIcon(is_warning ? qApp->icons()->fromTheme(QSL("dialog-warning"))
: qApp->icons()->fromTheme(QSL("dialog-question")));
m_text->document()->setDocumentMargin(0);
} }

View file

@ -5,7 +5,7 @@
#include <QWidget> #include <QWidget>
class QLabel; class QTextEdit;
class QGridLayout; class QGridLayout;
class QToolButton; class QToolButton;
class QParallelAnimationGroup; class QParallelAnimationGroup;
@ -18,15 +18,15 @@ class HelpSpoiler : public QWidget {
public: public:
explicit HelpSpoiler(QWidget* parent = nullptr); explicit HelpSpoiler(QWidget* parent = nullptr);
void setHelpText(const QString& title, const QString& text, bool is_warning); void setHelpText(const QString& title, const QString& text, bool is_warning, bool force_html = false);
void setHelpText(const QString& text, bool is_warning); void setHelpText(const QString& text, bool is_warning, bool force_html = false);
private: private:
QToolButton* m_btnToggle; QToolButton* m_btnToggle;
QScrollArea* m_content; QScrollArea* m_content;
QParallelAnimationGroup* m_animation; QParallelAnimationGroup* m_animation;
QGridLayout* m_layout; QGridLayout* m_layout;
QLabel* m_text; QTextEdit* m_text;
PlainToolButton* m_btnHelp; PlainToolButton* m_btnHelp;
}; };

View file

@ -12,12 +12,16 @@ TtRssAccountDetails::TtRssAccountDetails(QWidget* parent) : QWidget(parent) {
m_ui.setupUi(this); m_ui.setupUi(this);
m_ui.m_lblTestResult->label()->setWordWrap(true); m_ui.m_lblTestResult->label()->setWordWrap(true);
m_ui.m_lblNewAlgorithm->setHelpText(tr("If you select intelligent synchronization, then only not-yet-fetched " m_ui.m_lblNewAlgorithm
->setHelpText(tr("If you select intelligent synchronization, then only not-yet-fetched "
"or updated articles are downloaded. Network usage is greatly reduced and " "or updated articles are downloaded. Network usage is greatly reduced and "
"overall synchronization speed is greatly improved, but " "overall synchronization speed is greatly improved, but "
"first feed fetching could be slow anyway if your feed contains " "first feed fetching could be slow anyway if your feed contains "
"huge number of articles."), "huge number of articles.<br/><br/>"
false); "Also, make sure to install <a href=\"https://www.google.com\">api_newsplus</a> TT-RSS "
"plugin to your server instance."),
true,
true);
m_ui.m_lblServerSideUpdateInformation m_ui.m_lblServerSideUpdateInformation
->setHelpText(tr("Leaving this option on causes that updates " ->setHelpText(tr("Leaving this option on causes that updates "
"of feeds will be probably much slower and may time-out often."), "of feeds will be probably much slower and may time-out often."),

View file

@ -4,6 +4,7 @@
#include "3rd-party/boolinq/boolinq.h" #include "3rd-party/boolinq/boolinq.h"
#include "definitions/definitions.h" #include "definitions/definitions.h"
#include "exceptions/feedfetchexception.h"
#include "miscellaneous/application.h" #include "miscellaneous/application.h"
#include "miscellaneous/iconfactory.h" #include "miscellaneous/iconfactory.h"
#include "miscellaneous/textfactory.h" #include "miscellaneous/textfactory.h"
@ -23,9 +24,9 @@
TtRssNetworkFactory::TtRssNetworkFactory() TtRssNetworkFactory::TtRssNetworkFactory()
: m_bareUrl(QString()), m_fullUrl(QString()), m_username(QString()), m_password(QString()), : m_bareUrl(QString()), m_fullUrl(QString()), m_username(QString()), m_password(QString()),
m_batchSize(TTRSS_DEFAULT_MESSAGES), m_forceServerSideUpdate(false), m_intelligentSynchronization(true), m_batchSize(TTRSS_DEFAULT_MESSAGES), m_forceServerSideUpdate(false), m_intelligentSynchronization(false),
m_authIsUsed(false), m_authUsername(QString()), m_authPassword(QString()), m_sessionId(QString()), m_authIsUsed(false), m_authUsername(QString()), m_authPassword(QString()), m_sessionId(QString()),
m_lastError(QNetworkReply::NoError) {} m_lastError(QNetworkReply::NetworkError::NoError) {}
QString TtRssNetworkFactory::url() const { QString TtRssNetworkFactory::url() const {
return m_bareUrl; return m_bareUrl;
@ -143,7 +144,7 @@ TtRssResponse TtRssNetworkFactory::logout(const QNetworkProxy& proxy) {
m_lastError = network_reply.m_networkError; m_lastError = network_reply.m_networkError;
if (m_lastError == QNetworkReply::NoError) { if (m_lastError == QNetworkReply::NetworkError::NoError) {
m_sessionId.clear(); m_sessionId.clear();
} }
else { else {
@ -349,7 +350,12 @@ TtRssGetCompactHeadlinesResponse TtRssNetworkFactory::getCompactHeadlines(int fe
proxy); proxy);
TtRssGetCompactHeadlinesResponse result(QString::fromUtf8(result_raw)); TtRssGetCompactHeadlinesResponse result(QString::fromUtf8(result_raw));
if (result.isNotLoggedIn()) { if (result.isUnknownMethod()) {
qCriticalNN << LOGSEC_TTRSS << "'getCompactHeadlines' method is not installed.";
throw FeedFetchException(Feed::Status::OtherError, QSL("'getCompactHeadlines' method is not installed."));
}
else if (result.isNotLoggedIn()) {
// We are not logged in. // We are not logged in.
login(proxy); login(proxy);
json[QSL("sid")] = m_sessionId; json[QSL("sid")] = m_sessionId;
@ -373,6 +379,7 @@ TtRssGetCompactHeadlinesResponse TtRssNetworkFactory::getCompactHeadlines(int fe
} }
m_lastError = network_reply.m_networkError; m_lastError = network_reply.m_networkError;
return result; return result;
} }
@ -817,6 +824,10 @@ bool TtRssResponse::isNotLoggedIn() const {
return status() == TTRSS_API_STATUS_ERR && hasError() && error() == QSL(TTRSS_NOT_LOGGED_IN); return status() == TTRSS_API_STATUS_ERR && hasError() && error() == QSL(TTRSS_NOT_LOGGED_IN);
} }
bool TtRssResponse::isUnknownMethod() const {
return status() == TTRSS_API_STATUS_ERR && hasError() && error() == QSL(TTRSS_UNKNOWN_METHOD);
}
QString TtRssResponse::toString() const { QString TtRssResponse::toString() const {
return QJsonDocument(m_rawContent).toJson(QJsonDocument::JsonFormat::Compact); return QJsonDocument(m_rawContent).toJson(QJsonDocument::JsonFormat::Compact);
} }

View file

@ -28,6 +28,7 @@ class TtRssResponse {
QString error() const; QString error() const;
bool hasError() const; bool hasError() const;
bool isNotLoggedIn() const; bool isNotLoggedIn() const;
bool isUnknownMethod() const;
QString toString() const; QString toString() const;
protected: protected: