add a switch to turn off raw XML saving

This commit is contained in:
Martin Rotter 2024-08-01 10:51:32 +02:00
parent c8bfcf6ffe
commit 3a948c6825
14 changed files with 187 additions and 45 deletions

View File

@ -15,6 +15,8 @@ set(SOURCES
src/gui/standardaccountdetails.h
src/gui/standardfeeddetails.cpp
src/gui/standardfeeddetails.h
src/gui/standardfeedexpdetails.cpp
src/gui/standardfeedexpdetails.h
src/parsers/atomparser.cpp
src/parsers/atomparser.h
src/parsers/feedparser.cpp
@ -46,6 +48,7 @@ set(UI_FILES
src/gui/formstandardimportexport.ui
src/gui/standardaccountdetails.ui
src/gui/standardfeeddetails.ui
src/gui/standardfeedexpdetails.ui
)
# Add ZLIB.

View File

@ -3,6 +3,7 @@
#include "src/gui/formstandardfeeddetails.h"
#include "src/gui/standardfeeddetails.h"
#include "src/gui/standardfeedexpdetails.h"
#include "src/standardfeed.h"
#include <librssguard/database/databasequeries.h>
@ -25,9 +26,11 @@ FormStandardFeedDetails::FormStandardFeedDetails(ServiceRoot* service_root,
const QString& url,
QWidget* parent)
: FormFeedDetails(service_root, parent), m_standardFeedDetails(new StandardFeedDetails(this)),
m_authDetails(new AuthenticationDetails(false, this)), m_parentToSelect(parent_to_select), m_urlToProcess(url) {
m_standardFeedExpDetails(new StandardFeedExpDetails(this)), m_authDetails(new AuthenticationDetails(false, this)),
m_parentToSelect(parent_to_select), m_urlToProcess(url) {
insertCustomTab(m_standardFeedDetails, tr("General"), 0);
insertCustomTab(m_authDetails, tr("Network"), 2);
insertCustomTab(m_standardFeedExpDetails, tr("Experimental"));
activateTab(0);
connect(m_standardFeedDetails->m_ui.m_btnFetchMetadata,
@ -117,6 +120,10 @@ void FormStandardFeedDetails::apply() {
std_feed->setProtection(m_authDetails->authenticationType());
}
if (isChangeAllowed(m_standardFeedExpDetails->m_ui.m_mcbDontUseRawXml)) {
std_feed->setDontUseRawXmlSaving(m_standardFeedExpDetails->m_ui.m_cbDontUseRawXml->isChecked());
}
if (isChangeAllowed(m_authDetails->findChild<MultiFeedEditCheckBox*>(QSL("m_mcbAuthentication")))) {
std_feed->setUsername(m_authDetails->username());
std_feed->setPassword(m_authDetails->password());
@ -171,6 +178,9 @@ void FormStandardFeedDetails::loadFeedData() {
->addActionWidget(m_authDetails->findChild<QGroupBox*>(QSL("m_gbAuthentication")));
m_standardFeedDetails->m_ui.m_btnFetchMetadata->setEnabled(false);
m_standardFeedExpDetails->m_ui.m_mcbDontUseRawXml
->addActionWidget(m_standardFeedExpDetails->m_ui.m_cbDontUseRawXml);
}
else {
// We hide batch selectors.
@ -195,5 +205,7 @@ void FormStandardFeedDetails::loadFeedData() {
}
else {
m_standardFeedDetails->setExistingFeed(std_feed);
m_standardFeedExpDetails->m_ui.m_cbDontUseRawXml->setChecked(std_feed->dontUseRawXmlSaving());
}
}

View File

@ -6,6 +6,7 @@
#include <librssguard/services/abstract/gui/formfeeddetails.h>
class StandardFeedDetails;
class StandardFeedExpDetails;
class StandardServiceRoot;
class AuthenticationDetails;
class StandardFeed;
@ -31,6 +32,7 @@ class FormStandardFeedDetails : public FormFeedDetails {
private:
StandardFeedDetails* m_standardFeedDetails;
StandardFeedExpDetails* m_standardFeedExpDetails;
AuthenticationDetails* m_authDetails;
RootItem* m_parentToSelect;
QString m_urlToProcess;

View File

@ -0,0 +1,25 @@
// For license of this file, see <project-root-folder>/LICENSE.md.
#include "src/gui/standardfeedexpdetails.h"
#include "src/definitions.h"
#include <librssguard/3rd-party/boolinq/boolinq.h>
#include <librssguard/exceptions/applicationexception.h>
#include <librssguard/exceptions/networkexception.h>
#include <librssguard/exceptions/scriptexception.h>
#include <librssguard/miscellaneous/iconfactory.h>
#include <librssguard/miscellaneous/textfactory.h>
#include <librssguard/network-web/networkfactory.h>
#include <librssguard/services/abstract/category.h>
#include <QFileDialog>
#include <QImageReader>
#include <QMenu>
#include <QMimeData>
#include <QTextCodec>
#include <QtGlobal>
StandardFeedExpDetails::StandardFeedExpDetails(QWidget* parent) : QWidget(parent) {
m_ui.setupUi(this);
}

View File

@ -0,0 +1,28 @@
// For license of this file, see <project-root-folder>/LICENSE.md.
#ifndef STANDARDFEEDEXPDETAILS_H
#define STANDARDFEEDEXPDETAILS_H
#include "src/standardfeed.h"
#include "ui_standardfeedexpdetails.h"
#include <QNetworkProxy>
#include <QWidget>
class Category;
class RootItem;
class StandardFeedExpDetails : public QWidget {
Q_OBJECT
friend class FormStandardFeedDetails;
public:
explicit StandardFeedExpDetails(QWidget* parent = nullptr);
private:
Ui::StandardFeedExpDetails m_ui;
};
#endif // STANDARDFEEDEXPDETAILS_H

View File

@ -0,0 +1,38 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>StandardFeedExpDetails</class>
<widget class="QWidget" name="StandardFeedExpDetails">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>360</width>
<height>197</height>
</rect>
</property>
<property name="windowTitle">
<string>Form</string>
</property>
<layout class="QFormLayout" name="formLayout">
<item row="0" column="1">
<widget class="QCheckBox" name="m_cbDontUseRawXml">
<property name="text">
<string>Use older mechanism for extracting raw XML data</string>
</property>
</widget>
</item>
<item row="0" column="0">
<widget class="MultiFeedEditCheckBox" name="m_mcbDontUseRawXml"/>
</item>
</layout>
</widget>
<customwidgets>
<customwidget>
<class>MultiFeedEditCheckBox</class>
<extends>QCheckBox</extends>
<header>multifeededitcheckbox.h</header>
</customwidget>
</customwidgets>
<resources/>
<connections/>
</ui>

View File

@ -79,17 +79,16 @@ QPair<StandardFeed*, QList<IconLocation>> FeedParser::guessFeed(const QByteArray
}
QString FeedParser::xmlMessageRawContents(const QDomElement& msg_element) const {
QString raw_contents;
QTextStream str(&raw_contents);
if (dontUseRawXmlSaving()) {
return msg_element.text();
}
else {
QString raw_contents;
QTextStream str(&raw_contents);
msg_element.save(str, 0, QDomNode::EncodingPolicy::EncodingFromTextStream);
return raw_contents;
/*
qDebugNN << msg_element.text();
return msg_element.text();
*/
msg_element.save(str, 0, QDomNode::EncodingPolicy::EncodingFromTextStream);
return raw_contents;
}
}
QJsonArray FeedParser::jsonMessageElements() {
@ -345,25 +344,30 @@ QString FeedParser::xmlMrssTextFromPath(const QDomElement& msg_element, const QS
}
QString FeedParser::xmlRawChild(const QDomElement& container) const {
QString raw;
auto children = container.childNodes();
for (int i = 0; i < children.size(); i++) {
auto child = children.at(i);
if (child.isCDATASection()) {
raw += child.toCDATASection().data();
}
else {
QString raw_ch;
QTextStream str(&raw_ch);
child.save(str, 0);
raw += WebFactory::unescapeHtml(raw_ch);
}
if (dontUseRawXmlSaving()) {
return container.text();
}
else {
QString raw;
auto children = container.childNodes();
return raw;
for (int i = 0; i < children.size(); i++) {
auto child = children.at(i);
if (child.isCDATASection()) {
raw += child.toCDATASection().data();
}
else {
QString raw_ch;
QTextStream str(&raw_ch);
child.save(str, 0);
raw += WebFactory::unescapeHtml(raw_ch);
}
}
return raw;
}
}
QStringList FeedParser::xmlTextsFromPath(const QDomElement& element,
@ -408,6 +412,14 @@ QStringList FeedParser::xmlTextsFromPath(const QDomElement& element,
return result;
}
bool FeedParser::dontUseRawXmlSaving() const {
return m_dontUseRawXmlSaving;
}
void FeedParser::setDontUseRawXmlSaving(bool no_raw_xml_saving) {
m_dontUseRawXmlSaving = no_raw_xml_saving;
}
QString FeedParser::dateTimeFormat() const {
return m_dateTimeFormat;
}

View File

@ -40,6 +40,9 @@ class FeedParser {
QString dateTimeFormat() const;
void setDateTimeFormat(const QString& dt_format);
bool dontUseRawXmlSaving() const;
void setDontUseRawXmlSaving(bool no_raw_xml_saving);
protected:
virtual QString feedAuthor() const;
@ -61,7 +64,7 @@ class FeedParser {
virtual QString jsonMessageUrl(const QJsonObject& msg_element) const;
virtual QString jsonMessageDescription(const QJsonObject& msg_element) const;
virtual QString jsonMessageAuthor(const QJsonObject& msg_element) const;
virtual QDateTime jsonMessageDateCreated(const QJsonObject& msg_element) ;
virtual QDateTime jsonMessageDateCreated(const QJsonObject& msg_element);
virtual QString jsonMessageId(const QJsonObject& msg_element) const;
virtual QList<Enclosure> jsonMessageEnclosures(const QJsonObject& msg_element) const;
virtual QList<MessageCategory> jsonMessageCategories(const QJsonObject& msg_element) const;
@ -71,9 +74,9 @@ class FeedParser {
virtual QVariantList objMessageElements();
virtual QString objMessageTitle(const QVariant& msg_element) const;
virtual QString objMessageUrl(const QVariant& msg_element) const;
virtual QString objMessageDescription(const QVariant& msg_element) ;
virtual QString objMessageDescription(const QVariant& msg_element);
virtual QString objMessageAuthor(const QVariant& msg_element) const;
virtual QDateTime objMessageDateCreated(const QVariant& msg_element) ;
virtual QDateTime objMessageDateCreated(const QVariant& msg_element);
virtual QString objMessageId(const QVariant& msg_element) const;
virtual QList<Enclosure> objMessageEnclosures(const QVariant& msg_element) const;
virtual QList<MessageCategory> objMessageCategories(const QVariant& msg_element) const;
@ -95,6 +98,7 @@ class FeedParser {
QDomDocument m_xml;
QJsonDocument m_json;
QString m_mrssNamespace;
bool m_dontUseRawXmlSaving;
};
#endif // FEEDPARSER_H

View File

@ -268,16 +268,6 @@ QString RssParser::xmlMessageDescription(const QDomElement& msg_element) const {
}
return description;
/*
QString description = msg_element.elementsByTagName(QSL("encoded")).at(0).toElement().text();
if (description.isEmpty()) {
description = msg_element.elementsByTagName(QSL("description")).at(0).toElement().text();
}
return description;
*/
}
QString RssParser::xmlMessageAuthor(const QDomElement& msg_element) const {

View File

@ -52,6 +52,7 @@ StandardFeed::StandardFeed(RootItem* parent_item) : Feed(parent_item) {
m_protection = NetworkFactory::NetworkAuthentication::NoAuthentication;
m_username = QString();
m_password = QString();
m_dontUseRawXmlSaving = false;
}
StandardFeed::StandardFeed(const StandardFeed& other) : Feed(other) {
@ -62,6 +63,7 @@ StandardFeed::StandardFeed(const StandardFeed& other) : Feed(other) {
m_protection = other.protection();
m_username = other.username();
m_password = other.password();
m_dontUseRawXmlSaving = other.dontUseRawXmlSaving();
}
QList<QAction*> StandardFeed::contextMenuFeedsList() {
@ -84,6 +86,7 @@ QString StandardFeed::additionalTooltip() const {
.toStdList();
QStringList fltrs = FROM_STD_LIST(QStringList, std_fltrs);
// TODO: toto je v podstatě zkopirovane z Feed...
QString base_tooltip =
tr("Auto-update status: %1\n"
"Active message filters: %2\n"
@ -100,10 +103,12 @@ QString StandardFeed::additionalTooltip() const {
return base_tooltip + tr("Encoding: %1\n"
"Type: %2\n"
"Post-processing script: %3")
"Post-processing script: %3\n"
"Do not use raw XML saving: %4")
.arg(encoding(),
StandardFeed::typeToString(type()),
m_postProcessScript.isEmpty() ? QSL("-") : m_postProcessScript);
m_postProcessScript.isEmpty() ? QSL("-") : m_postProcessScript,
dontUseRawXmlSaving() ? tr("yes") : tr("no"));
}
bool StandardFeed::canBeDeleted() const {
@ -158,6 +163,7 @@ QVariantHash StandardFeed::customDatabaseData() const {
data[QSL("protected")] = int(protection());
data[QSL("username")] = username();
data[QSL("password")] = TextFactory::encrypt(password());
data[QSL("dont_use_raw_xml_saving")] = dontUseRawXmlSaving();
return data;
}
@ -170,6 +176,7 @@ void StandardFeed::setCustomDatabaseData(const QVariantHash& data) {
setProtection(NetworkFactory::NetworkAuthentication(data[QSL("protected")].toInt()));
setUsername(data[QSL("username")].toString());
setPassword(TextFactory::decrypt(data[QSL("password")].toString()));
setDontUseRawXmlSaving(data[QSL("dont_use_raw_xml_saving")].toBool());
}
QString StandardFeed::typeToString(StandardFeed::Type type) {
@ -426,6 +433,14 @@ bool StandardFeed::removeItself() {
return DatabaseQueries::deleteFeed(database, this, getParentServiceRoot()->accountId());
}
bool StandardFeed::dontUseRawXmlSaving() const {
return m_dontUseRawXmlSaving;
}
void StandardFeed::setDontUseRawXmlSaving(bool no_raw_xml_saving) {
m_dontUseRawXmlSaving = no_raw_xml_saving;
}
QString StandardFeed::dateTimeFormat() const {
return m_dateTimeFormat;
}

View File

@ -110,6 +110,9 @@ class StandardFeed : public Feed {
QString dateTimeFormat() const;
void setDateTimeFormat(const QString& dt_format);
bool dontUseRawXmlSaving() const;
void setDontUseRawXmlSaving(bool no_raw_xml_saving);
public slots:
void fetchMetadataForItself();
@ -127,6 +130,7 @@ class StandardFeed : public Feed {
QString m_username;
QString m_password;
QString m_lastEtag;
bool m_dontUseRawXmlSaving;
};
Q_DECLARE_METATYPE(StandardFeed::SourceType)

View File

@ -358,6 +358,7 @@ QList<Message> StandardServiceRoot::obtainNewMessages(Feed* feed,
parser->setDateTimeFormat(f->dateTimeFormat());
}
parser->setDontUseRawXmlSaving(f->dontUseRawXmlSaving());
messages = parser->messages();
if (!parser->dateTimeFormat().isEmpty()) {

View File

@ -36,7 +36,12 @@ void FormFeedDetails::clearTabs() {
}
void FormFeedDetails::insertCustomTab(QWidget* custom_tab, const QString& title, int index) {
m_ui->m_tabWidget->insertTab(index, custom_tab, title);
if (index < 0) {
m_ui->m_tabWidget->addTab(custom_tab, title);
}
else {
m_ui->m_tabWidget->insertTab(index, custom_tab, title);
}
}
void FormFeedDetails::apply() {

View File

@ -50,7 +50,10 @@ class RSSGUARD_DLLSPEC FormFeedDetails : public QDialog {
QDialogButtonBox* buttonBox() const;
bool isChangeAllowed(MultiFeedEditCheckBox* mcb) const;
void insertCustomTab(QWidget* custom_tab, const QString& title, int index);
// Inserts custom tab made by plugin into its editing form. When index is less
// than zero, tab is inserted to the last position.
void insertCustomTab(QWidget* custom_tab, const QString& title, int index = -1);
// Sets the feed which will be edited.
// NOTE: This must be reimplemented in subclasses. Also this