This commit is contained in:
Martin Rotter 2022-04-09 18:44:32 +02:00
parent 9fb922f785
commit 52798f9ed2
6 changed files with 111 additions and 100 deletions

View file

@ -39,7 +39,7 @@ BraceWrapping:
AfterStruct: false
AfterUnion: false
AfterExternBlock: false
BeforeCatch: false
BeforeCatch: true
BeforeElse: true
BeforeLambdaBody: false
BeforeWhile: true

View file

@ -60,18 +60,13 @@ bool WebEnginePage::acceptNavigationRequest(const QUrl& url, NavigationType type
}
}
/*if (url.host() == INTERNAL_URL_MESSAGE_HOST) {
setHtml(view()->messageContents(), QUrl(INTERNAL_URL_MESSAGE));
return true;
}
else {*/
return QWebEnginePage::acceptNavigationRequest(url, type, is_main_frame);
//}
}
void WebEnginePage::javaScriptConsoleMessage(JavaScriptConsoleMessageLevel level, const QString& message,
int line_number, const QString& source_id) {
void WebEnginePage::javaScriptConsoleMessage(JavaScriptConsoleMessageLevel level,
const QString& message,
int line_number,
const QString& source_id) {
Q_UNUSED(level)
qWarningNN << LOGSEC_JS << message << QSL(" (source: %1:%2)").arg(source_id, QString::number(line_number));

View file

@ -27,11 +27,18 @@ FormStandardImportExport::FormStandardImportExport(StandardServiceRoot* service_
GuiUtilities::applyDialogProperties(*this, qApp->icons()->fromTheme(QSL("document-export")));
m_ui->m_lblSelectFile->setStatus(WidgetWithStatus::StatusType::Error, tr("No file is selected."), tr("No file is selected."));
m_ui->m_lblSelectFile->setStatus(WidgetWithStatus::StatusType::Error,
tr("No file is selected."),
tr("No file is selected."));
m_ui->m_buttonBox->button(QDialogButtonBox::StandardButton::Ok)->disconnect();
m_ui->m_lblResult->setStatus(WidgetWithStatus::StatusType::Warning, tr("No operation executed yet."), tr("No operation executed yet."));
m_ui->m_lblResult->setStatus(WidgetWithStatus::StatusType::Warning,
tr("No operation executed yet."),
tr("No operation executed yet."));
connect(m_ui->m_buttonBox->button(QDialogButtonBox::StandardButton::Ok), &QPushButton::clicked, this, &FormStandardImportExport::performAction);
connect(m_ui->m_buttonBox->button(QDialogButtonBox::StandardButton::Ok),
&QPushButton::clicked,
this,
&FormStandardImportExport::performAction);
connect(m_ui->m_btnSelectFile, &QPushButton::clicked, this, &FormStandardImportExport::selectFile);
connect(m_ui->m_btnCheckAllItems, &QPushButton::clicked, m_model, &FeedsImportExportModel::checkAllItems);
connect(m_ui->m_btnUncheckAllItems, &QPushButton::clicked, m_model, &FeedsImportExportModel::uncheckAllItems);
@ -61,10 +68,12 @@ void FormStandardImportExport::setMode(FeedsImportExportModel::Mode mode) {
}
case FeedsImportExportModel::Mode::Import: {
m_ui->m_cbExportIcons->setVisible(false);
m_ui->m_groupFile->setTitle(tr("Source file"));
m_ui->m_groupFeeds->setTitle(tr("Target feeds && categories"));
m_ui->m_groupFeeds->setDisabled(true);
m_ui->m_buttonBox->button(QDialogButtonBox::StandardButton::Ok)->setText(tr("&Import from file"));
m_ui->m_buttonBox->button(QDialogButtonBox::StandardButton::Ok)->setEnabled(false);
// Load categories.
loadCategories(m_serviceRoot->getSubTreeCategories(), m_serviceRoot);
@ -76,8 +85,6 @@ void FormStandardImportExport::setMode(FeedsImportExportModel::Mode mode) {
default:
break;
}
m_ui->m_buttonBox->button(QDialogButtonBox::StandardButton::Ok)->setEnabled(false);
}
void FormStandardImportExport::selectFile() {
@ -122,7 +129,8 @@ void FormStandardImportExport::onParsingFinished(int count_failed, int count_suc
}
else {
m_ui->m_groupFeeds->setEnabled(false);
m_ui->m_lblResult->setStatus(WidgetWithStatus::StatusType::Error, tr("Error, file is not well-formed. Select another file."),
m_ui->m_lblResult->setStatus(WidgetWithStatus::StatusType::Error,
tr("Error, file is not well-formed. Select another file."),
tr("Error occurred. File is not well-formed. Select another file."));
}
@ -135,8 +143,7 @@ void FormStandardImportExport::onParsingProgress(int completed, int total) {
}
void FormStandardImportExport::selectExportFile(bool without_dialog) {
const QString the_file = qApp->homeFolder() +
QDir::separator() +
const QString the_file = qApp->homeFolder() + QDir::separator() +
QSL("rssguard_feeds_%1.opml").arg(QDate::currentDate().toString(Qt::DateFormat::ISODate));
QString selected_file;
QString selected_filter;
@ -150,10 +157,8 @@ void FormStandardImportExport::selectExportFile(bool without_dialog) {
filter += filter_opml20;
filter += QSL(";;");
filter += filter_txt_url_per_line;
selected_file = QFileDialog::getSaveFileName(this, tr("Select file for feeds export"),
the_file,
filter,
&selected_filter);
selected_file =
QFileDialog::getSaveFileName(this, tr("Select file for feeds export"), the_file, filter, &selected_filter);
}
else {
selected_file = the_file;
@ -176,10 +181,14 @@ void FormStandardImportExport::selectExportFile(bool without_dialog) {
}
}
m_ui->m_lblSelectFile->setStatus(WidgetWithStatus::StatusType::Ok, QDir::toNativeSeparators(selected_file), tr("File is selected."));
m_ui->m_lblSelectFile->setStatus(WidgetWithStatus::StatusType::Ok,
QDir::toNativeSeparators(selected_file),
tr("File is selected."));
}
m_ui->m_buttonBox->button(QDialogButtonBox::StandardButton::Ok)->setEnabled(m_ui->m_lblSelectFile->status() == WidgetWithStatus::StatusType::Ok);
const auto is_ok = m_ui->m_lblSelectFile->status() == WidgetWithStatus::StatusType::Ok;
m_ui->m_buttonBox->button(QDialogButtonBox::StandardButton::Ok)->setEnabled(is_ok);
}
void FormStandardImportExport::selectImportFile() {
@ -192,8 +201,11 @@ void FormStandardImportExport::selectImportFile() {
filter += filter_opml20;
filter += QSL(";;");
filter += filter_txt_url_per_line;
const QString selected_file = QFileDialog::getOpenFileName(this, tr("Select file for feeds import"), qApp->homeFolder(),
filter, &selected_filter);
const QString selected_file = QFileDialog::getOpenFileName(this,
tr("Select file for feeds import"),
qApp->homeFolder(),
filter,
&selected_filter);
if (!selected_file.isEmpty()) {
if (selected_filter == filter_opml20) {
@ -203,17 +215,19 @@ void FormStandardImportExport::selectImportFile() {
m_conversionType = ConversionType::TxtUrlPerLine;
}
m_ui->m_lblSelectFile->setStatus(WidgetWithStatus::StatusType::Ok, QDir::toNativeSeparators(selected_file), tr("File is selected."));
QMessageBox::StandardButton answer = MsgBox::show(this,
QMessageBox::Icon::Warning,
tr("Get online metadata"),
tr("Metadata for your feeds can be fetched online. Note that the action "
"could take several minutes, depending on number of feeds."),
tr("Do you want to fetch feed metadata online?"),
QString(),
QMessageBox::StandardButton::Yes |
QMessageBox::StandardButton::No,
QMessageBox::StandardButton::Yes);
m_ui->m_lblSelectFile->setStatus(WidgetWithStatus::StatusType::Ok,
QDir::toNativeSeparators(selected_file),
tr("File is selected."));
QMessageBox::StandardButton answer =
MsgBox::show(this,
QMessageBox::Icon::Warning,
tr("Get online metadata"),
tr("Metadata for your feeds can be fetched online. Note that the action "
"could take several minutes, depending on number of feeds."),
tr("Do you want to fetch feed metadata online?"),
QString(),
QMessageBox::StandardButton::Yes | QMessageBox::StandardButton::No,
QMessageBox::StandardButton::Yes);
parseImportFile(selected_file, answer == QMessageBox::StandardButton::Yes);
}
@ -228,7 +242,9 @@ void FormStandardImportExport::parseImportFile(const QString& file_name, bool fe
input_file.close();
}
else {
m_ui->m_lblResult->setStatus(WidgetWithStatus::StatusType::Error, tr("Cannot open source file."), tr("Cannot open source file."));
m_ui->m_lblResult->setStatus(WidgetWithStatus::StatusType::Error,
tr("Cannot open source file."),
tr("Cannot open source file."));
return;
}
@ -267,7 +283,7 @@ void FormStandardImportExport::exportFeeds() {
switch (m_conversionType) {
case ConversionType::OPML20:
result_export = m_model->exportToOMPL20(result_data);
result_export = m_model->exportToOMPL20(result_data, m_ui->m_cbExportIcons->isChecked());
break;
case ConversionType::TxtUrlPerLine:
@ -281,21 +297,27 @@ void FormStandardImportExport::exportFeeds() {
if (result_export) {
try {
IOFactory::writeFile(m_ui->m_lblSelectFile->label()->text(), result_data);
m_ui->m_lblResult->setStatus(WidgetWithStatus::StatusType::Ok, tr("Feeds were exported successfully."),
m_ui->m_lblResult->setStatus(WidgetWithStatus::StatusType::Ok,
tr("Feeds were exported successfully."),
tr("Feeds were exported successfully."));
}
catch (IOException& ex) {
m_ui->m_lblResult->setStatus(WidgetWithStatus::StatusType::Error, tr("Cannot write into destination file: '%1'."), ex.message());
m_ui->m_lblResult->setStatus(WidgetWithStatus::StatusType::Error,
tr("Cannot write into destination file: '%1'."),
ex.message());
}
}
else {
m_ui->m_lblResult->setStatus(WidgetWithStatus::StatusType::Error, tr("Critical error occurred."), tr("Critical error occurred."));
m_ui->m_lblResult->setStatus(WidgetWithStatus::StatusType::Error,
tr("Critical error occurred."),
tr("Critical error occurred."));
}
}
void FormStandardImportExport::importFeeds() {
QString output_message;
RootItem* parent = static_cast<RootItem*>(m_ui->m_cmbRootNode->itemData(m_ui->m_cmbRootNode->currentIndex()).value<void*>());
RootItem* parent =
static_cast<RootItem*>(m_ui->m_cmbRootNode->itemData(m_ui->m_cmbRootNode->currentIndex()).value<void*>());
if (m_serviceRoot->mergeImportExportModel(m_model, parent, output_message)) {
m_serviceRoot->requestItemExpand(parent->getSubTree(), true);
@ -307,9 +329,9 @@ void FormStandardImportExport::importFeeds() {
}
void FormStandardImportExport::loadCategories(const QList<Category*>& categories, RootItem* root_item) {
m_ui->m_cmbRootNode->addItem(root_item->icon(), root_item->title(), QVariant::fromValue((void*) root_item));
m_ui->m_cmbRootNode->addItem(root_item->icon(), root_item->title(), QVariant::fromValue((void*)root_item));
for (Category* category : categories) {
m_ui->m_cmbRootNode->addItem(category->icon(), category->title(), QVariant::fromValue((void*) category));
m_ui->m_cmbRootNode->addItem(category->icon(), category->title(), QVariant::fromValue((void*)category));
}
}

View file

@ -79,6 +79,13 @@
</item>
</layout>
</item>
<item>
<widget class="QCheckBox" name="m_cbExportIcons">
<property name="text">
<string>Export icons</string>
</property>
</widget>
</item>
<item>
<widget class="QGroupBox" name="m_groupFeeds">
<property name="title">
@ -97,20 +104,6 @@
<property name="bottomMargin">
<number>3</number>
</property>
<item row="1" column="1">
<widget class="QPushButton" name="m_btnCheckAllItems">
<property name="text">
<string>&amp;Check all feeds</string>
</property>
</widget>
</item>
<item row="1" column="2">
<widget class="QPushButton" name="m_btnUncheckAllItems">
<property name="text">
<string>&amp;Uncheck all feeds</string>
</property>
</widget>
</item>
<item row="1" column="3">
<spacer name="horizontalSpacer">
<property name="orientation">
@ -152,6 +145,20 @@
</attribute>
</widget>
</item>
<item row="1" column="1">
<widget class="QPushButton" name="m_btnCheckAllItems">
<property name="text">
<string>&amp;Check all feeds</string>
</property>
</widget>
</item>
<item row="1" column="2">
<widget class="QPushButton" name="m_btnUncheckAllItems">
<property name="text">
<string>&amp;Uncheck all feeds</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
@ -226,6 +233,7 @@
<tabstops>
<tabstop>m_btnSelectFile</tabstop>
<tabstop>m_cmbRootNode</tabstop>
<tabstop>m_cbExportIcons</tabstop>
<tabstop>m_btnCheckAllItems</tabstop>
<tabstop>m_btnUncheckAllItems</tabstop>
<tabstop>m_treeFeeds</tabstop>

View file

@ -28,11 +28,10 @@ FeedsImportExportModel::~FeedsImportExportModel() {
}
}
bool FeedsImportExportModel::exportToOMPL20(QByteArray& result) {
bool FeedsImportExportModel::exportToOMPL20(QByteArray& result, bool export_icons) {
QDomDocument opml_document;
QDomProcessingInstruction xml_declaration = opml_document.createProcessingInstruction(QSL("xml"),
QSL(
"version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\""));
QDomProcessingInstruction xml_declaration =
opml_document.createProcessingInstruction(QSL("xml"), QSL("version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\""));
opml_document.appendChild(xml_declaration);
@ -80,8 +79,9 @@ bool FeedsImportExportModel::exportToOMPL20(QByteArray& result) {
outline_category.setAttribute(QSL("text"), child_item->title());
outline_category.setAttribute(QSL("description"), child_item->description());
if (!child_item->icon().isNull()) {
outline_category.setAttribute(QSL("rssguard:icon"), QString(qApp->icons()->toByteArray(child_item->icon())));
if (export_icons && !child_item->icon().isNull()) {
outline_category.setAttribute(QSL("rssguard:icon"),
QString(qApp->icons()->toByteArray(child_item->icon())));
}
active_element.appendChild(outline_category);
@ -104,7 +104,7 @@ bool FeedsImportExportModel::exportToOMPL20(QByteArray& result) {
outline_feed.setAttribute(QSL("rssguard:xmlUrlType"), QString::number(int(child_feed->sourceType())));
outline_feed.setAttribute(QSL("rssguard:postProcess"), child_feed->postProcessScript());
if (!child_feed->icon().isNull()) {
if (export_icons && !child_feed->icon().isNull()) {
outline_feed.setAttribute(QSL("rssguard:icon"), QString(qApp->icons()->toByteArray(child_feed->icon())));
}
@ -168,8 +168,7 @@ void FeedsImportExportModel::importAsOPML20(const QByteArray& data, bool fetch_m
QStack<RootItem*> model_items;
QNetworkProxy custom_proxy;
if (sourceModel()->rootItem() != nullptr &&
sourceModel()->rootItem()->getParentServiceRoot() != nullptr) {
if (sourceModel()->rootItem() != nullptr && sourceModel()->rootItem()->getParentServiceRoot() != nullptr) {
custom_proxy = sourceModel()->rootItem()->getParentServiceRoot()->networkProxy();
}
@ -201,23 +200,17 @@ void FeedsImportExportModel::importAsOPML20(const QByteArray& data, bool fetch_m
if (!feed_url.isEmpty()) {
try {
if (fetch_metadata_online) {
StandardFeed* guessed = StandardFeed::guessFeed(StandardFeed::SourceType::Url,
feed_url,
{}, {}, {},
custom_proxy);
StandardFeed* guessed =
StandardFeed::guessFeed(StandardFeed::SourceType::Url, feed_url, {}, {}, {}, custom_proxy);
guessed->setSource(feed_url);
active_model_item->appendChild(guessed);
succeded++;
add_offline_anyway = false;
}
}
catch (const ApplicationException& ex) {
qCriticalNN << LOGSEC_CORE
<< "Cannot fetch medatada for feed:"
<< QUOTE_W_SPACE(feed_url)
<< "with error:"
<< QUOTE_W_SPACE_DOT(ex.message());
} catch (const ApplicationException& ex) {
qCriticalNN << LOGSEC_CORE << "Cannot fetch medatada for feed:" << QUOTE_W_SPACE(feed_url)
<< "with error:" << QUOTE_W_SPACE_DOT(ex.message());
}
if (add_offline_anyway) {
@ -225,8 +218,10 @@ void FeedsImportExportModel::importAsOPML20(const QByteArray& data, bool fetch_m
QString feed_encoding = child_element.attribute(QSL("encoding"), QSL(DEFAULT_FEED_ENCODING));
QString feed_type = child_element.attribute(QSL("version"), QSL(DEFAULT_FEED_TYPE)).toUpper();
QString feed_description = child_element.attribute(QSL("description"));
QIcon feed_icon = qApp->icons()->fromByteArray(child_element.attribute(QSL("rssguard:icon")).toLocal8Bit());
StandardFeed::SourceType source_type = StandardFeed::SourceType(child_element.attribute(QSL("rssguard:xmlUrlType")).toInt());
QIcon feed_icon =
qApp->icons()->fromByteArray(child_element.attribute(QSL("rssguard:icon")).toLocal8Bit());
StandardFeed::SourceType source_type =
StandardFeed::SourceType(child_element.attribute(QSL("rssguard:xmlUrlType")).toInt());
QString post_process = child_element.attribute(QSL("rssguard:postProcess"));
auto* new_feed = new StandardFeed(active_model_item);
@ -270,7 +265,8 @@ void FeedsImportExportModel::importAsOPML20(const QByteArray& data, bool fetch_m
// Add category and continue.
QString category_title = child_element.attribute(QSL("text"));
QString category_description = child_element.attribute(QSL("description"));
QIcon category_icon = qApp->icons()->fromByteArray(child_element.attribute(QSL("rssguard:icon")).toLocal8Bit());
QIcon category_icon =
qApp->icons()->fromByteArray(child_element.attribute(QSL("rssguard:icon")).toLocal8Bit());
if (category_title.isEmpty()) {
qWarningNN << LOGSEC_CORE
@ -332,8 +328,7 @@ void FeedsImportExportModel::importAsTxtURLPerLine(const QByteArray& data, bool
auto* root_item = new StandardServiceRoot();
QNetworkProxy custom_proxy;
if (sourceModel()->rootItem() != nullptr &&
sourceModel()->rootItem()->getParentServiceRoot() != nullptr) {
if (sourceModel()->rootItem() != nullptr && sourceModel()->rootItem()->getParentServiceRoot() != nullptr) {
custom_proxy = sourceModel()->rootItem()->getParentServiceRoot()->networkProxy();
}
@ -345,22 +340,16 @@ void FeedsImportExportModel::importAsTxtURLPerLine(const QByteArray& data, bool
try {
if (fetch_metadata_online) {
StandardFeed* guessed = StandardFeed::guessFeed(StandardFeed::SourceType::Url,
url, {}, {}, {},
custom_proxy);
StandardFeed* guessed = StandardFeed::guessFeed(StandardFeed::SourceType::Url, url, {}, {}, {}, custom_proxy);
guessed->setSource(url);
root_item->appendChild(guessed);
succeded++;
add_offline_anyway = false;
}
}
catch (const ApplicationException& ex) {
qCriticalNN << LOGSEC_CORE
<< "Cannot fetch medatada for feed:"
<< QUOTE_W_SPACE(url)
<< "with error:"
<< QUOTE_W_SPACE_DOT(ex.message());
} catch (const ApplicationException& ex) {
qCriticalNN << LOGSEC_CORE << "Cannot fetch medatada for feed:" << QUOTE_W_SPACE(url)
<< "with error:" << QUOTE_W_SPACE_DOT(ex.message());
}
if (add_offline_anyway) {

View file

@ -6,20 +6,17 @@
#include "services/abstract/accountcheckmodel.h"
class FeedsImportExportModel : public AccountCheckSortedModel {
Q_OBJECT
Q_OBJECT
public:
enum class Mode {
Import,
Export
};
enum class Mode { Import, Export };
explicit FeedsImportExportModel(QObject* parent = nullptr);
virtual ~FeedsImportExportModel();
// Exports to OPML 2.0
// NOTE: http://dev.opml.org/spec2.html
bool exportToOMPL20(QByteArray& result);
bool exportToOMPL20(QByteArray& result, bool export_icons);
void importAsOPML20(const QByteArray& data, bool fetch_metadata_online);
// Exports to plain text format