fix resolving of URLs for external browser and downloading

This commit is contained in:
Martin Rotter 2022-05-02 14:55:44 +02:00
parent d9a651490a
commit 4348a51d67
4 changed files with 18 additions and 21 deletions

View file

@ -386,10 +386,12 @@ void TextBrowserViewer::enableResources(bool enable) {
} }
void TextBrowserViewer::openLinkInExternalBrowser() { void TextBrowserViewer::openLinkInExternalBrowser() {
auto link = anchorAt(m_lastContextMenuPos); auto url = QUrl(anchorAt(m_lastContextMenuPos));
if (!link.isEmpty()) { if (url.isValid()) {
qApp->web()->openUrlInExternalBrowser(link); const QUrl resolved_url = (m_currentUrl.isValid() && url.isRelative()) ? m_currentUrl.resolved(url) : url;
qApp->web()->openUrlInExternalBrowser(resolved_url.toString());
if (qApp->settings() if (qApp->settings()
->value(GROUP(Messages), SETTING(Messages::BringAppToFrontAfterMessageOpenedExternally)) ->value(GROUP(Messages), SETTING(Messages::BringAppToFrontAfterMessageOpenedExternally))
@ -402,10 +404,12 @@ void TextBrowserViewer::openLinkInExternalBrowser() {
} }
void TextBrowserViewer::downloadLink() { void TextBrowserViewer::downloadLink() {
auto link = anchorAt(m_lastContextMenuPos); auto url = QUrl(anchorAt(m_lastContextMenuPos));
if (!link.isEmpty()) { if (url.isValid()) {
qApp->downloadManager()->download(link); const QUrl resolved_url = (m_currentUrl.isValid() && url.isRelative()) ? m_currentUrl.resolved(url) : url;
qApp->downloadManager()->download(resolved_url);
} }
} }

View file

@ -41,8 +41,12 @@ DVALUE(QString) Node::PackageFolderDef = QSL(USER_DATA_PLACEHOLDER) + "/node-pac
// Cookies. // Cookies.
DKEY Cookies::ID = "cookies"; DKEY Cookies::ID = "cookies";
// Network.
DKEY Network::ID = "network"; DKEY Network::ID = "network";
DKEY Network::SendDNT = "send_dnt";
VALUE(bool) Network::SendDNTDef = false;
DKEY Network::IgnoreAllCookies = "ignore_all_cookies"; DKEY Network::IgnoreAllCookies = "ignore_all_cookies";
DVALUE(bool) Network::IgnoreAllCookiesDef = false; DVALUE(bool) Network::IgnoreAllCookiesDef = false;
@ -400,9 +404,6 @@ DKEY Notifications::ID = "notifications";
// Web browser. // Web browser.
DKEY Browser::ID = "browser"; DKEY Browser::ID = "browser";
DKEY Browser::SendDNT = "send_dnt";
VALUE(bool) Browser::SendDNTDef = false;
DKEY Browser::OpenLinksInExternalBrowserRightAway = "open_link_externally_wo_confirmation"; DKEY Browser::OpenLinksInExternalBrowserRightAway = "open_link_externally_wo_confirmation";
DVALUE(bool) Browser::OpenLinksInExternalBrowserRightAwayDef = false; DVALUE(bool) Browser::OpenLinksInExternalBrowserRightAwayDef = false;

View file

@ -320,6 +320,9 @@ namespace GUI {
namespace Network { namespace Network {
KEY ID; KEY ID;
KEY SendDNT;
VALUE(bool) SendDNTDef;
KEY IgnoreAllCookies; KEY IgnoreAllCookies;
VALUE(bool) IgnoreAllCookiesDef; VALUE(bool) IgnoreAllCookiesDef;
} // namespace Network } // namespace Network
@ -439,40 +442,29 @@ namespace Notifications {
// Web browser. // Web browser.
namespace Browser { namespace Browser {
KEY ID; KEY ID;
KEY SendDNT;
VALUE(bool) SendDNTDef;
KEY OpenLinksInExternalBrowserRightAway; KEY OpenLinksInExternalBrowserRightAway;
VALUE(bool) OpenLinksInExternalBrowserRightAwayDef; VALUE(bool) OpenLinksInExternalBrowserRightAwayDef;
KEY CustomExternalBrowserEnabled; KEY CustomExternalBrowserEnabled;
VALUE(bool) CustomExternalBrowserEnabledDef; VALUE(bool) CustomExternalBrowserEnabledDef;
KEY CustomExternalBrowserExecutable; KEY CustomExternalBrowserExecutable;
VALUE(QString) CustomExternalBrowserExecutableDef; VALUE(QString) CustomExternalBrowserExecutableDef;
KEY CustomExternalBrowserArguments; KEY CustomExternalBrowserArguments;
VALUE(char*) CustomExternalBrowserArgumentsDef; VALUE(char*) CustomExternalBrowserArgumentsDef;
KEY CustomExternalEmailEnabled; KEY CustomExternalEmailEnabled;
VALUE(bool) CustomExternalEmailEnabledDef; VALUE(bool) CustomExternalEmailEnabledDef;
KEY CustomExternalEmailExecutable; KEY CustomExternalEmailExecutable;
VALUE(QString) CustomExternalEmailExecutableDef; VALUE(QString) CustomExternalEmailExecutableDef;
KEY ExternalTools; KEY ExternalTools;
VALUE(QStringList) ExternalToolsDef; VALUE(QStringList) ExternalToolsDef;
KEY CustomExternalEmailArguments; KEY CustomExternalEmailArguments;
VALUE(char*) CustomExternalEmailArgumentsDef; VALUE(char*) CustomExternalEmailArgumentsDef;
} // namespace Browser } // namespace Browser

View file

@ -51,5 +51,5 @@ void NetworkUrlInterceptor::removeUrlInterceptor(UrlInterceptor* interceptor) {
} }
void NetworkUrlInterceptor::load() { void NetworkUrlInterceptor::load() {
m_sendDnt = qApp->settings()->value(GROUP(Browser), SETTING(Browser::SendDNT)).toBool(); m_sendDnt = qApp->settings()->value(GROUP(Network), SETTING(Network::SendDNT)).toBool();
} }