1
mirror of https://invent.kde.org/network/falkon.git synced 2024-12-20 18:56:34 +01:00

[SBI_JsIcon] Fix after 36724df3a6

Closes #1174
This commit is contained in:
nowrep 2014-01-25 17:48:30 +01:00
parent 5230554943
commit d5ea5342cf
4 changed files with 26 additions and 3 deletions

View File

@ -77,6 +77,8 @@ WebPage::WebPage(QObject* parent)
, m_secureStatus(false) , m_secureStatus(false)
, m_adjustingScheduled(false) , m_adjustingScheduled(false)
{ {
m_javaScriptEnabled = mApp->webSettings()->testAttribute(QWebSettings::JavascriptEnabled);
m_networkProxy = new NetworkManagerProxy(this); m_networkProxy = new NetworkManagerProxy(this);
m_networkProxy->setPrimaryNetworkAccessManager(mApp->networkManager()); m_networkProxy->setPrimaryNetworkAccessManager(mApp->networkManager());
m_networkProxy->setPage(this); m_networkProxy->setPage(this);
@ -286,7 +288,7 @@ void WebPage::addJavaScriptObject()
// Make sure all other sites have JavaScript set by user preferences // Make sure all other sites have JavaScript set by user preferences
// (JavaScript is enabled in WebPage::urlChanged) // (JavaScript is enabled in WebPage::urlChanged)
if (url().scheme() != QLatin1String("qupzilla")) { if (url().scheme() != QLatin1String("qupzilla")) {
settings()->setAttribute(QWebSettings::JavascriptEnabled, mApp->webSettings()->testAttribute(QWebSettings::JavascriptEnabled)); settings()->setAttribute(QWebSettings::JavascriptEnabled, m_javaScriptEnabled);
} }
if (url().toString() != QLatin1String("qupzilla:speeddial")) { if (url().toString() != QLatin1String("qupzilla:speeddial")) {
@ -996,6 +998,12 @@ void WebPage::javaScriptAlert(QWebFrame* originatingFrame, const QString &msg)
#endif #endif
} }
void WebPage::setJavaScriptEnabled(bool enabled)
{
settings()->setAttribute(QWebSettings::JavascriptEnabled, enabled);
m_javaScriptEnabled = enabled;
}
QString WebPage::chooseFile(QWebFrame* originatingFrame, const QString &oldFile) QString WebPage::chooseFile(QWebFrame* originatingFrame, const QString &oldFile)
{ {
QString suggFileName; QString suggFileName;

View File

@ -63,6 +63,8 @@ public:
bool javaScriptConfirm(QWebFrame* originatingFrame, const QString &msg); bool javaScriptConfirm(QWebFrame* originatingFrame, const QString &msg);
void javaScriptAlert(QWebFrame* originatingFrame, const QString &msg); void javaScriptAlert(QWebFrame* originatingFrame, const QString &msg);
void setJavaScriptEnabled(bool enabled);
void addAdBlockRule(const AdBlockRule* rule, const QUrl &url); void addAdBlockRule(const AdBlockRule* rule, const QUrl &url);
QVector<AdBlockedEntry> adBlockedEntries() const; QVector<AdBlockedEntry> adBlockedEntries() const;
@ -146,6 +148,7 @@ private:
int m_loadProgress; int m_loadProgress;
bool m_blockAlerts; bool m_blockAlerts;
bool m_secureStatus; bool m_secureStatus;
bool m_javaScriptEnabled;
bool m_adjustingScheduled; bool m_adjustingScheduled;
}; };

View File

@ -55,6 +55,11 @@ void SBI_JavaScriptIcon::showMenu(const QPoint &point)
menu.addAction(tr("Enable JavaScript (temporarily)"), this, SLOT(toggleJavaScript())); menu.addAction(tr("Enable JavaScript (temporarily)"), this, SLOT(toggleJavaScript()));
} }
// JavaScript needs to be always enabled for qupzilla: sites
if (currentPage()->url().scheme() == QLatin1String("qupzilla")) {
menu.actions().at(1)->setEnabled(false);
}
menu.addSeparator(); menu.addSeparator();
menu.addAction(m_icon, tr("Global settings"))->setFont(boldFont); menu.addAction(m_icon, tr("Global settings"))->setFont(boldFont);
menu.addAction(tr("Manage JavaScript settings"), this, SLOT(openJavaScriptSettings())); menu.addAction(tr("Manage JavaScript settings"), this, SLOT(openJavaScriptSettings()));
@ -76,7 +81,7 @@ void SBI_JavaScriptIcon::updateIcon()
void SBI_JavaScriptIcon::toggleJavaScript() void SBI_JavaScriptIcon::toggleJavaScript()
{ {
bool current = currentPageSettings()->testAttribute(QWebSettings::JavascriptEnabled); bool current = currentPageSettings()->testAttribute(QWebSettings::JavascriptEnabled);
currentPageSettings()->setAttribute(QWebSettings::JavascriptEnabled, !current); currentPage()->setJavaScriptEnabled(!current);
p_QupZilla->weView()->reload(); p_QupZilla->weView()->reload();
@ -89,7 +94,12 @@ void SBI_JavaScriptIcon::openJavaScriptSettings()
dialog.exec(); dialog.exec();
} }
WebPage* SBI_JavaScriptIcon::currentPage()
{
return p_QupZilla->weView()->page();
}
QWebSettings* SBI_JavaScriptIcon::currentPageSettings() QWebSettings* SBI_JavaScriptIcon::currentPageSettings()
{ {
return p_QupZilla->weView()->page()->settings(); return currentPage()->settings();
} }

View File

@ -25,6 +25,7 @@
class QWebSettings; class QWebSettings;
class QupZilla; class QupZilla;
class WebPage;
class SBI_JavaScriptIcon : public ClickableLabel class SBI_JavaScriptIcon : public ClickableLabel
{ {
@ -41,6 +42,7 @@ private slots:
void openJavaScriptSettings(); void openJavaScriptSettings();
private: private:
WebPage* currentPage();
QWebSettings* currentPageSettings(); QWebSettings* currentPageSettings();
QupZilla* p_QupZilla; QupZilla* p_QupZilla;