From 52798f9ed2502985099f45655aab2623cf88da2d Mon Sep 17 00:00:00 2001 From: Martin Rotter Date: Sat, 9 Apr 2022 18:44:32 +0200 Subject: [PATCH] fix #685 --- .clang-format | 2 +- .../network-web/webengine/webenginepage.cpp | 13 +-- .../standard/gui/formstandardimportexport.cpp | 92 ++++++++++++------- .../standard/gui/formstandardimportexport.ui | 36 +++++--- .../standardfeedsimportexportmodel.cpp | 59 +++++------- .../standard/standardfeedsimportexportmodel.h | 9 +- 6 files changed, 111 insertions(+), 100 deletions(-) diff --git a/.clang-format b/.clang-format index 74221c77a..a8cbff089 100644 --- a/.clang-format +++ b/.clang-format @@ -39,7 +39,7 @@ BraceWrapping: AfterStruct: false AfterUnion: false AfterExternBlock: false - BeforeCatch: false + BeforeCatch: true BeforeElse: true BeforeLambdaBody: false BeforeWhile: true diff --git a/src/librssguard/network-web/webengine/webenginepage.cpp b/src/librssguard/network-web/webengine/webenginepage.cpp index 6dc6716a5..249bb29a1 100644 --- a/src/librssguard/network-web/webengine/webenginepage.cpp +++ b/src/librssguard/network-web/webengine/webenginepage.cpp @@ -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)); diff --git a/src/librssguard/services/standard/gui/formstandardimportexport.cpp b/src/librssguard/services/standard/gui/formstandardimportexport.cpp index 665e90210..08bf687c0 100644 --- a/src/librssguard/services/standard/gui/formstandardimportexport.cpp +++ b/src/librssguard/services/standard/gui/formstandardimportexport.cpp @@ -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(m_ui->m_cmbRootNode->itemData(m_ui->m_cmbRootNode->currentIndex()).value()); + RootItem* parent = + static_cast(m_ui->m_cmbRootNode->itemData(m_ui->m_cmbRootNode->currentIndex()).value()); 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& 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)); } } diff --git a/src/librssguard/services/standard/gui/formstandardimportexport.ui b/src/librssguard/services/standard/gui/formstandardimportexport.ui index 68242b39a..72263f516 100644 --- a/src/librssguard/services/standard/gui/formstandardimportexport.ui +++ b/src/librssguard/services/standard/gui/formstandardimportexport.ui @@ -79,6 +79,13 @@ + + + + Export icons + + + @@ -97,20 +104,6 @@ 3 - - - - &Check all feeds - - - - - - - &Uncheck all feeds - - - @@ -152,6 +145,20 @@ + + + + &Check all feeds + + + + + + + &Uncheck all feeds + + + @@ -226,6 +233,7 @@ m_btnSelectFile m_cmbRootNode + m_cbExportIcons m_btnCheckAllItems m_btnUncheckAllItems m_treeFeeds diff --git a/src/librssguard/services/standard/standardfeedsimportexportmodel.cpp b/src/librssguard/services/standard/standardfeedsimportexportmodel.cpp index 7c53a7492..5e06236c0 100644 --- a/src/librssguard/services/standard/standardfeedsimportexportmodel.cpp +++ b/src/librssguard/services/standard/standardfeedsimportexportmodel.cpp @@ -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 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) { diff --git a/src/librssguard/services/standard/standardfeedsimportexportmodel.h b/src/librssguard/services/standard/standardfeedsimportexportmodel.h index 8410194ad..da5f8901d 100644 --- a/src/librssguard/services/standard/standardfeedsimportexportmodel.h +++ b/src/librssguard/services/standard/standardfeedsimportexportmodel.h @@ -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