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:
parent
a3510afd4d
commit
feb4de0833
@ -9,15 +9,16 @@
|
||||
#include "miscellaneous/iconfactory.h"
|
||||
|
||||
#include <QGridLayout>
|
||||
#include <QLabel>
|
||||
#include <QParallelAnimationGroup>
|
||||
#include <QPropertyAnimation>
|
||||
#include <QScrollArea>
|
||||
#include <QTextEdit>
|
||||
#include <QToolButton>
|
||||
|
||||
HelpSpoiler::HelpSpoiler(QWidget* parent) : QWidget(parent),
|
||||
m_btnToggle(new QToolButton(this)), m_content(new QScrollArea(this)), m_animation(new QParallelAnimationGroup(this)),
|
||||
m_layout(new QGridLayout(this)), m_text(new QLabel(this)), m_btnHelp(new PlainToolButton(this)) {
|
||||
HelpSpoiler::HelpSpoiler(QWidget* parent)
|
||||
: QWidget(parent), m_btnToggle(new QToolButton(this)), m_content(new QScrollArea(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->setToolButtonStyle(Qt::ToolButtonStyle::ToolButtonTextBesideIcon);
|
||||
@ -29,7 +30,7 @@ HelpSpoiler::HelpSpoiler(QWidget* parent) : QWidget(parent),
|
||||
m_content->setSizePolicy(QSizePolicy::Policy::Expanding, QSizePolicy::Policy::Fixed);
|
||||
m_content->setMaximumHeight(0);
|
||||
m_content->setMinimumHeight(0);
|
||||
m_content->setContentsMargins({ 0, 0, 0, 0 });
|
||||
m_content->setContentsMargins({0, 0, 0, 0});
|
||||
|
||||
m_animation->addAnimation(new QPropertyAnimation(this, QSL("minimumHeight").toLocal8Bit()));
|
||||
m_animation->addAnimation(new QPropertyAnimation(this, QSL("maximumHeight").toLocal8Bit()));
|
||||
@ -47,12 +48,8 @@ HelpSpoiler::HelpSpoiler(QWidget* parent) : QWidget(parent),
|
||||
m_layout->addWidget(m_content, 1, 0, 1, 2);
|
||||
|
||||
QObject::connect(m_btnToggle, &QToolButton::clicked, [this](const bool checked) {
|
||||
const auto collapsed_height = sizeHint().height() - m_content->maximumHeight();
|
||||
auto content_height = m_text->fontMetrics().boundingRect(QRect(QPoint(0, 0),
|
||||
QPoint(m_text->width(), 1000)),
|
||||
Qt::TextFlag::TextWordWrap,
|
||||
m_text->text()).height() +
|
||||
(2 * m_text->fontMetrics().lineSpacing());
|
||||
const auto collapsed_height = m_btnHelp->height();
|
||||
auto content_height = m_text->document()->size().height() + 22;
|
||||
|
||||
for (int i = 0; i < m_animation->animationCount() - 1; 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);
|
||||
}
|
||||
|
||||
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->setStartValue(0);
|
||||
content_animation->setEndValue(content_height);
|
||||
|
||||
m_btnToggle->setArrowType(checked
|
||||
? Qt::ArrowType::DownArrow
|
||||
: Qt::ArrowType::RightArrow);
|
||||
m_animation->setDirection(checked
|
||||
? QAbstractAnimation::Direction::Forward
|
||||
: QAbstractAnimation::Direction::Backward);
|
||||
m_btnToggle->setArrowType(checked ? Qt::ArrowType::DownArrow : Qt::ArrowType::RightArrow);
|
||||
m_animation->setDirection(checked ? QAbstractAnimation::Direction::Forward
|
||||
: QAbstractAnimation::Direction::Backward);
|
||||
m_animation->start();
|
||||
});
|
||||
|
||||
m_text->setMargin(0);
|
||||
m_text->setWordWrap(true);
|
||||
m_text->viewport()->setAutoFillBackground(false);
|
||||
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);
|
||||
|
||||
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);
|
||||
setHelpText(text, is_warning);
|
||||
}
|
||||
|
||||
void HelpSpoiler::setHelpText(const QString& text, bool is_warning) {
|
||||
m_text->setText(text);
|
||||
m_btnHelp->setIcon(is_warning
|
||||
? qApp->icons()->fromTheme(QSL("dialog-warning"))
|
||||
: qApp->icons()->fromTheme(QSL("dialog-question")));
|
||||
void HelpSpoiler::setHelpText(const QString& text, bool is_warning, bool force_html) {
|
||||
if (force_html) {
|
||||
m_text->setHtml(text);
|
||||
}
|
||||
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);
|
||||
}
|
||||
|
@ -5,7 +5,7 @@
|
||||
|
||||
#include <QWidget>
|
||||
|
||||
class QLabel;
|
||||
class QTextEdit;
|
||||
class QGridLayout;
|
||||
class QToolButton;
|
||||
class QParallelAnimationGroup;
|
||||
@ -13,20 +13,20 @@ class QScrollArea;
|
||||
class PlainToolButton;
|
||||
|
||||
class HelpSpoiler : public QWidget {
|
||||
Q_OBJECT
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit HelpSpoiler(QWidget* parent = nullptr);
|
||||
|
||||
void setHelpText(const QString& title, const QString& text, bool is_warning);
|
||||
void setHelpText(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, bool force_html = false);
|
||||
|
||||
private:
|
||||
QToolButton* m_btnToggle;
|
||||
QScrollArea* m_content;
|
||||
QParallelAnimationGroup* m_animation;
|
||||
QGridLayout* m_layout;
|
||||
QLabel* m_text;
|
||||
QTextEdit* m_text;
|
||||
PlainToolButton* m_btnHelp;
|
||||
};
|
||||
|
||||
|
@ -12,12 +12,16 @@ TtRssAccountDetails::TtRssAccountDetails(QWidget* parent) : QWidget(parent) {
|
||||
m_ui.setupUi(this);
|
||||
|
||||
m_ui.m_lblTestResult->label()->setWordWrap(true);
|
||||
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 "
|
||||
"overall synchronization speed is greatly improved, but "
|
||||
"first feed fetching could be slow anyway if your feed contains "
|
||||
"huge number of articles."),
|
||||
false);
|
||||
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 "
|
||||
"overall synchronization speed is greatly improved, but "
|
||||
"first feed fetching could be slow anyway if your feed contains "
|
||||
"huge number of articles.<br/><br/>"
|
||||
"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
|
||||
->setHelpText(tr("Leaving this option on causes that updates "
|
||||
"of feeds will be probably much slower and may time-out often."),
|
||||
|
@ -4,6 +4,7 @@
|
||||
|
||||
#include "3rd-party/boolinq/boolinq.h"
|
||||
#include "definitions/definitions.h"
|
||||
#include "exceptions/feedfetchexception.h"
|
||||
#include "miscellaneous/application.h"
|
||||
#include "miscellaneous/iconfactory.h"
|
||||
#include "miscellaneous/textfactory.h"
|
||||
@ -23,9 +24,9 @@
|
||||
|
||||
TtRssNetworkFactory::TtRssNetworkFactory()
|
||||
: 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_lastError(QNetworkReply::NoError) {}
|
||||
m_lastError(QNetworkReply::NetworkError::NoError) {}
|
||||
|
||||
QString TtRssNetworkFactory::url() const {
|
||||
return m_bareUrl;
|
||||
@ -143,7 +144,7 @@ TtRssResponse TtRssNetworkFactory::logout(const QNetworkProxy& proxy) {
|
||||
|
||||
m_lastError = network_reply.m_networkError;
|
||||
|
||||
if (m_lastError == QNetworkReply::NoError) {
|
||||
if (m_lastError == QNetworkReply::NetworkError::NoError) {
|
||||
m_sessionId.clear();
|
||||
}
|
||||
else {
|
||||
@ -349,7 +350,12 @@ TtRssGetCompactHeadlinesResponse TtRssNetworkFactory::getCompactHeadlines(int fe
|
||||
proxy);
|
||||
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.
|
||||
login(proxy);
|
||||
json[QSL("sid")] = m_sessionId;
|
||||
@ -373,6 +379,7 @@ TtRssGetCompactHeadlinesResponse TtRssNetworkFactory::getCompactHeadlines(int fe
|
||||
}
|
||||
|
||||
m_lastError = network_reply.m_networkError;
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
@ -817,6 +824,10 @@ bool TtRssResponse::isNotLoggedIn() const {
|
||||
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 {
|
||||
return QJsonDocument(m_rawContent).toJson(QJsonDocument::JsonFormat::Compact);
|
||||
}
|
||||
|
@ -28,6 +28,7 @@ class TtRssResponse {
|
||||
QString error() const;
|
||||
bool hasError() const;
|
||||
bool isNotLoggedIn() const;
|
||||
bool isUnknownMethod() const;
|
||||
QString toString() const;
|
||||
|
||||
protected:
|
||||
|
Loading…
x
Reference in New Issue
Block a user