diff --git a/src/librssguard-standard/src/gui/standardfeeddetails.cpp b/src/librssguard-standard/src/gui/standardfeeddetails.cpp index 14ba1035d..37a73a650 100644 --- a/src/librssguard-standard/src/gui/standardfeeddetails.cpp +++ b/src/librssguard-standard/src/gui/standardfeeddetails.cpp @@ -9,12 +9,15 @@ #include #include #include +#include #include #include #include +#include #include #include +#include #include #include #include @@ -79,12 +82,16 @@ StandardFeedDetails::StandardFeedDetails(QWidget* parent) : QWidget(parent) { // Setup menu & actions for icon selection. m_iconMenu = new QMenu(tr("Icon selection"), this); m_actionLoadIconFromFile = - new QAction(qApp->icons()->fromTheme(QSL("image-x-generic")), tr("Load icon from file..."), this); + new QAction(qApp->icons()->fromTheme(QSL("image-x-generic")), tr("Select icon from file..."), this); + m_actionLoadIconFromUrl = new QAction(qApp->icons()->fromTheme(QSL("emblem-downloads"), QSL("download")), + tr("Download icon from URL..."), + this); m_actionUseDefaultIcon = new QAction(qApp->icons()->fromTheme(QSL("application-rss+xml")), tr("Use default icon from icon theme"), this); m_actionFetchIcon = new QAction(qApp->icons()->fromTheme(QSL("emblem-downloads"), QSL("download")), tr("Fetch icon from feed"), this); m_iconMenu->addAction(m_actionFetchIcon); + m_iconMenu->addAction(m_actionLoadIconFromUrl); m_iconMenu->addAction(m_actionLoadIconFromFile); m_iconMenu->addAction(m_actionUseDefaultIcon); m_ui.m_btnIcon->setMenu(m_iconMenu); @@ -112,6 +119,7 @@ StandardFeedDetails::StandardFeedDetails(QWidget* parent) : QWidget(parent) { }); connect(m_actionLoadIconFromFile, &QAction::triggered, this, &StandardFeedDetails::onLoadIconFromFile); connect(m_actionUseDefaultIcon, &QAction::triggered, this, &StandardFeedDetails::onUseDefaultIcon); + connect(m_actionLoadIconFromUrl, &QAction::triggered, this, &StandardFeedDetails::onLoadIconFromUrl); setTabOrder(m_ui.m_cmbParentCategory, m_ui.m_cmbType); setTabOrder(m_ui.m_cmbType, m_ui.m_cmbEncoding); @@ -137,6 +145,43 @@ StandardFeedDetails::StandardFeedDetails(QWidget* parent) : QWidget(parent) { onPostProcessScriptChanged({}); } +void StandardFeedDetails::onLoadIconFromUrl() { + bool ok = false; + QString src = qApp->clipboard()->text().simplified().replace(QRegularExpression("\\r|\\n"), QString()); + + if (src.isEmpty() && + (sourceType() == StandardFeed::SourceType::EmbeddedBrowser || sourceType() == StandardFeed::SourceType::Url)) { + src = m_ui.m_txtSource->textEdit()->toPlainText(); + } + + QString url = QInputDialog::getText(window(), + tr("Enter URL"), + tr("Enter direct URL pointing to the image"), + QLineEdit::EchoMode::Normal, + src, + &ok); + + if (!ok || url.isEmpty()) { + return; + } + + QList icon_loc = {IconLocation(url, true), IconLocation(url, false)}; + int timeout = qApp->settings()->value(GROUP(Feeds), SETTING(Feeds::UpdateTimeout)).toInt(); + QPixmap pixmap; + + if (NetworkFactory::downloadIcon(icon_loc, timeout, pixmap, {}, m_account->networkProxy()) == + QNetworkReply::NetworkError::NoError) { + m_ui.m_btnIcon->setIcon(QIcon(pixmap)); + } + else { + qApp->showGuiMessage(Notification::Event::GeneralEvent, + GuiMessage(tr("Icon not fetched"), + tr("Icon was not fetched due to network error."), + QSystemTrayIcon::MessageIcon::Critical), + GuiMessageDestination(true, true)); + } +} + void StandardFeedDetails::guessIconOnly(StandardFeed::SourceType source_type, const QString& source, const QString& post_process_script, @@ -364,6 +409,8 @@ StandardFeed::SourceType StandardFeedDetails::sourceType() const { } void StandardFeedDetails::prepareForNewFeed(RootItem* parent_to_select, const QString& url) { + m_account = parent_to_select->getParentServiceRoot(); + // Make sure that "default" icon is used as the default option for new // feed. m_actionUseDefaultIcon->trigger(); @@ -400,6 +447,8 @@ void StandardFeedDetails::prepareForNewFeed(RootItem* parent_to_select, const QS } void StandardFeedDetails::setExistingFeed(StandardFeed* feed) { + m_account = feed->getParentServiceRoot(); + m_ui.m_cmbSourceType->setCurrentIndex(m_ui.m_cmbSourceType->findData(QVariant::fromValue(feed->sourceType()))); m_ui.m_cmbParentCategory->setCurrentIndex(m_ui.m_cmbParentCategory->findData(QVariant::fromValue(feed->parent()))); m_ui.m_txtTitle->lineEdit()->setText(feed->title()); diff --git a/src/librssguard-standard/src/gui/standardfeeddetails.h b/src/librssguard-standard/src/gui/standardfeeddetails.h index ad89166dd..22456f8f2 100644 --- a/src/librssguard-standard/src/gui/standardfeeddetails.h +++ b/src/librssguard-standard/src/gui/standardfeeddetails.h @@ -49,6 +49,7 @@ class StandardFeedDetails : public QWidget { void onUrlChanged(const QString& new_url); void onPostProcessScriptChanged(const QString& new_pp); void onLoadIconFromFile(); + void onLoadIconFromUrl(); void onUseDefaultIcon(); private: @@ -57,9 +58,11 @@ class StandardFeedDetails : public QWidget { void loadCategories(const QList& categories, RootItem* root_item); private: + ServiceRoot* m_account; Ui::StandardFeedDetails m_ui; QMenu* m_iconMenu{}; QAction* m_actionLoadIconFromFile{}; + QAction* m_actionLoadIconFromUrl{}; QAction* m_actionUseDefaultIcon{}; QAction* m_actionFetchIcon{}; }; diff --git a/src/librssguard/definitions/typedefs.h b/src/librssguard/definitions/typedefs.h index 48bc12e09..59c4ba8b0 100644 --- a/src/librssguard/definitions/typedefs.h +++ b/src/librssguard/definitions/typedefs.h @@ -30,6 +30,8 @@ struct IconLocation { // The "bool" if true means that the URL is direct and download directly, if false then // only use its domain and download via 3rd-party service. bool m_isDirect; + + IconLocation(const QString& url, bool is_direct) : m_url(url), m_isDirect(is_direct) {} }; #endif // TYPEDEFS_H diff --git a/src/librssguard/network-web/adblock/adblockdialog.cpp b/src/librssguard/network-web/adblock/adblockdialog.cpp index 937d926a2..8d227efd1 100644 --- a/src/librssguard/network-web/adblock/adblockdialog.cpp +++ b/src/librssguard/network-web/adblock/adblockdialog.cpp @@ -12,7 +12,6 @@ #include "network-web/adblock/adblockmanager.h" #include "network-web/webfactory.h" -#include #include #include #include diff --git a/src/librssguard/network-web/networkfactory.cpp b/src/librssguard/network-web/networkfactory.cpp index da7a7daa8..ef92b567f 100644 --- a/src/librssguard/network-web/networkfactory.cpp +++ b/src/librssguard/network-web/networkfactory.cpp @@ -210,7 +210,8 @@ QNetworkReply::NetworkError NetworkFactory::downloadIcon(const QList #include -#include #include #include #include diff --git a/src/librssguard/network-web/webfactory.cpp b/src/librssguard/network-web/webfactory.cpp index be6e3c53b..994cce828 100644 --- a/src/librssguard/network-web/webfactory.cpp +++ b/src/librssguard/network-web/webfactory.cpp @@ -461,8 +461,9 @@ QWebEngineProfile* WebFactory::engineProfile() const { QAction* WebFactory::engineSettingsAction() { if (m_engineSettings == nullptr) { - m_engineSettings = - new QAction(qApp->icons()->fromTheme(QSL("applications-internet")), tr("Web engine settings"), this); + m_engineSettings = new QAction(qApp->icons()->fromTheme(QSL("applications-internet"), QSL("internet-services")), + tr("Web engine settings"), + this); m_engineSettings->setMenu(new QMenu()); createMenu(m_engineSettings->menu()); connect(m_engineSettings->menu(), &QMenu::aboutToShow, this, [this]() {