fix #1645
This commit is contained in:
parent
fd272ea0aa
commit
c210e5ed1b
7 changed files with 64 additions and 8 deletions
|
@ -9,12 +9,15 @@
|
|||
#include <librssguard/exceptions/networkexception.h>
|
||||
#include <librssguard/exceptions/scriptexception.h>
|
||||
#include <librssguard/miscellaneous/iconfactory.h>
|
||||
#include <librssguard/miscellaneous/settings.h>
|
||||
#include <librssguard/miscellaneous/textfactory.h>
|
||||
#include <librssguard/network-web/networkfactory.h>
|
||||
#include <librssguard/services/abstract/category.h>
|
||||
|
||||
#include <QClipboard>
|
||||
#include <QFileDialog>
|
||||
#include <QImageReader>
|
||||
#include <QInputDialog>
|
||||
#include <QMenu>
|
||||
#include <QMimeData>
|
||||
#include <QTextCodec>
|
||||
|
@ -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<IconLocation> 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());
|
||||
|
|
|
@ -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<Category*>& 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{};
|
||||
};
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -12,7 +12,6 @@
|
|||
#include "network-web/adblock/adblockmanager.h"
|
||||
#include "network-web/webfactory.h"
|
||||
|
||||
#include <QInputDialog>
|
||||
#include <QMenu>
|
||||
#include <QMessageBox>
|
||||
#include <QTimer>
|
||||
|
|
|
@ -210,7 +210,8 @@ QNetworkReply::NetworkError NetworkFactory::downloadIcon(const QList<IconLocatio
|
|||
false,
|
||||
{},
|
||||
{},
|
||||
custom_proxy)
|
||||
custom_proxy,
|
||||
http2_status)
|
||||
.m_networkError;
|
||||
|
||||
if (network_result == QNetworkReply::NetworkError::NoError) {
|
||||
|
@ -225,6 +226,7 @@ QNetworkReply::NetworkError NetworkFactory::downloadIcon(const QList<IconLocatio
|
|||
Qt::AspectRatioMode::KeepAspectRatio,
|
||||
Qt::TransformationMode::SmoothTransformation);
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -258,7 +260,8 @@ QNetworkReply::NetworkError NetworkFactory::downloadIcon(const QList<IconLocatio
|
|||
false,
|
||||
{},
|
||||
{},
|
||||
custom_proxy)
|
||||
custom_proxy,
|
||||
http2_status)
|
||||
.m_networkError;
|
||||
|
||||
if (network_result == QNetworkReply::NetworkError::NoError) {
|
||||
|
@ -274,7 +277,7 @@ QNetworkReply::NetworkError NetworkFactory::downloadIcon(const QList<IconLocatio
|
|||
Qt::TransformationMode::SmoothTransformation);
|
||||
}
|
||||
|
||||
return network_result;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -34,7 +34,6 @@
|
|||
#include <utility>
|
||||
|
||||
#include <QDebug>
|
||||
#include <QInputDialog>
|
||||
#include <QJsonDocument>
|
||||
#include <QJsonObject>
|
||||
#include <QNetworkReply>
|
||||
|
|
|
@ -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]() {
|
||||
|
|
Loading…
Add table
Reference in a new issue