X-Git-Url: https://gitweb.stoutner.com/?p=PrivacyBrowserPC.git;a=blobdiff_plain;f=src%2Fmainview.cpp;h=3ebee4c4d02199ba260e47af8fb0262192b31b78;hp=25f3b4c5ea0d1b6f39de2439abea2bff200d58f3;hb=1cbda7a594e97dd3ba6e1c0675be6ec9f6a424b2;hpb=196ae0c95c22cf78557d4f11be317aa7181c9af0 diff --git a/src/mainview.cpp b/src/mainview.cpp index 25f3b4c..3ebee4c 100644 --- a/src/mainview.cpp +++ b/src/mainview.cpp @@ -28,6 +28,7 @@ // Qt headers. #include +#include #include MainView::MainView(QWidget *parent) : QWidget(parent) @@ -43,11 +44,13 @@ MainView::MainView(QWidget *parent) : QWidget(parent) forwardButtonPointer = mainViewUi.forwardButton; QPushButton *homeButtonPointer = mainViewUi.homeButton; urlLineEditPointer = mainViewUi.urlLineEdit; + javaScriptButtonPointer = mainViewUi.javaScript; webEngineViewPointer = mainViewUi.webEngineView; - // Get handles for the webpage and history. + // Get handles for the aspects of the WebEngine. QWebEnginePage *webEnginePagePointer = webEngineViewPointer->page(); webEngineHistoryPointer = webEnginePagePointer->history(); + webEngineSettingsPointer = webEngineViewPointer->settings(); // Update the webengine view from the URL line edit. connect(urlLineEditPointer, SIGNAL(returnKeyPressed(const QString)), this, SLOT(loadUrl(const QString))); @@ -61,6 +64,7 @@ MainView::MainView(QWidget *parent) : QWidget(parent) connect(backButtonPointer, SIGNAL(clicked()), webEngineViewPointer, SLOT(back())); connect(forwardButtonPointer, SIGNAL(clicked()), webEngineViewPointer, SLOT(forward())); connect(homeButtonPointer, SIGNAL(clicked()), this, SLOT(goHome())); + connect(javaScriptButtonPointer, SIGNAL(clicked()), this, SLOT(toggleJavaScript())); // Instantiate the mouse event pointer. MouseEventFilter *mouseEventFilterPointer = new MouseEventFilter(webEngineViewPointer); @@ -71,9 +75,18 @@ MainView::MainView(QWidget *parent) : QWidget(parent) // Listen for hovered link URLs. connect(webEnginePagePointer, SIGNAL(linkHovered(QString)), this, SLOT(pageLinkHovered(QString))); + // Don't allow JavaScript to open windows. + webEngineSettingsPointer->setAttribute(QWebEngineSettings::JavascriptCanOpenWindows, false); + // Set the zoom factor. webEngineViewPointer->setZoomFactor(Settings::zoomFactor()); + // Apply the application settings. + applyApplicationSettings(); + + // Apply the domain settings. + applyDomainSettings(); + // Set the focus on the WebEngine view. webEngineViewPointer->setFocus(); @@ -81,6 +94,30 @@ MainView::MainView(QWidget *parent) : QWidget(parent) goHome(); } +void MainView::applyApplicationSettings() +{ + // TODO. +} + +void MainView::applyDomainSettings() +{ + // Set the JavaScript status. + webEngineSettingsPointer->setAttribute(QWebEngineSettings::JavascriptEnabled, Settings::javaScript()); + + // Update the JavaScript button. + if (Settings::javaScript()) + { + javaScriptButtonPointer->setIcon(QIcon(":/icons/javascript-warning")); + } + else + { + javaScriptButtonPointer->setIcon(QIcon(":/icons/privacy-mode")); + } + + // Reload the website. + webEngineViewPointer->reload(); +} + void MainView::goHome() { // Load the homepage. TODO. Consider sanitizing the homepage input and adding things like protocols if they are missing. @@ -102,6 +139,25 @@ void MainView::pageLinkHovered(const QString &linkUrl) emit linkHovered(linkUrl); } +void MainView::toggleJavaScript() +{ + // Toggle JavaScript. + webEngineSettingsPointer->setAttribute(QWebEngineSettings::JavascriptEnabled, !webEngineSettingsPointer->testAttribute(QWebEngineSettings::JavascriptEnabled)); + + // Update the JavaScript button. + if (webEngineSettingsPointer->testAttribute(QWebEngineSettings::JavascriptEnabled)) + { + javaScriptButtonPointer->setIcon(QIcon(":/icons/javascript-warning")); + } + else + { + javaScriptButtonPointer->setIcon(QIcon(":/icons/privacy-mode")); + } + + // Reload the website. + webEngineViewPointer->reload(); +} + void MainView::updateInterface() { // Update the URL line edit if it does not have focus.