]> gitweb.stoutner.com Git - PrivacyBrowserPC.git/commitdiff
Enable opening links in new windows.
authorSoren Stoutner <soren@stoutner.com>
Mon, 15 Aug 2022 21:35:20 +0000 (14:35 -0700)
committerSoren Stoutner <soren@stoutner.com>
Mon, 15 Aug 2022 21:35:20 +0000 (14:35 -0700)
src/widgets/PrivacyWebEngineView.cpp
src/widgets/PrivacyWebEngineView.h
src/widgets/TabWidget.cpp
src/widgets/TabWidget.h
src/windows/BrowserWindow.cpp
src/windows/BrowserWindow.h

index ba56d31d76c6827f9b3e1e60927c756f9ed4e896..10a3a47fcf3f7124a194ce4c62f31b273c5eeaac 100644 (file)
@@ -41,8 +41,6 @@ void PrivacyWebEngineView::addCookieToList(const QNetworkCookie &cookie) const
 }
 
 QWebEngineView* PrivacyWebEngineView::createWindow(QWebEnginePage::WebWindowType webWindowType) {
-    qDebug().noquote().nospace() << "Web window type:  " << webWindowType;
-
     // Get a handle for the browser window.
     BrowserWindow *browserWindowPointer = qobject_cast<BrowserWindow*>(window());
 
@@ -54,8 +52,19 @@ QWebEngineView* PrivacyWebEngineView::createWindow(QWebEnginePage::WebWindowType
             return browserWindowPointer->tabWidgetPointer->addTab(true);
         }
 
+        case QWebEnginePage::WebBrowserWindow: {
+            // Create a new browser window.
+            BrowserWindow *newBrowserWindowPointer = new BrowserWindow();
+
+            // Show the new browser window.
+            newBrowserWindowPointer->show();
+
+            // The new privacy WebEngine view pointer is returned so it can be populated with the link from the context menu.
+            return newBrowserWindowPointer->tabWidgetPointer->loadBlankInitialWebsite();
+        }
+
         default: {
-            // Return an null pointer.
+            // Return an null pointer for opening a background tab and opening a web dialog.
             return nullptr;
         }
     }
index 8a049576438953b23d72852889b97354c17d17b5..863cf5d4429ce1bc9af8b14c9acbc4deb1445c1b 100644 (file)
@@ -36,6 +36,7 @@ public:
     // The public variables.
     std::list<QNetworkCookie> *cookieListPointer = new std::list<QNetworkCookie>;
     QString domainSettingsName = QStringLiteral("");
+    int loadProgressInt = -1;
     bool localStorageEnabled = false;
 
 signals:
index 9e843ef306da564f362d7c5e434a0589b7dda21d..eb82f23d2fed09c49c4739479963ff2aba519fc5 100644 (file)
@@ -166,12 +166,55 @@ PrivacyWebEngineView* TabWidget::addTab(const bool focusNewWebEngineView)
     QWebEngineSettings *webEngineSettingsPointer = webEnginePagePointer->settings();
 
     // Update the URL line edit when the URL changes.
-    connect(privacyWebEngineViewPointer, SIGNAL(urlChanged(const QUrl)), this, SLOT(updateUrl(const QUrl)));
+    connect(privacyWebEngineViewPointer, &PrivacyWebEngineView::urlChanged, [privacyWebEngineViewPointer, this] (const QUrl &newUrl)
+    {
+        // Only update the UI if this is the current tab.
+        if (privacyWebEngineViewPointer == currentPrivacyWebEngineViewPointer)
+        {
+            // Update the URL line edit.
+            emit updateUrlLineEdit(newUrl);
 
-    // Update the progress bar.
-    connect(privacyWebEngineViewPointer, SIGNAL(loadStarted()), this, SLOT(loadStarted()));
-    connect(privacyWebEngineViewPointer, SIGNAL(loadProgress(const int)), this, SLOT(loadProgress(const int)));
-    connect(privacyWebEngineViewPointer, SIGNAL(loadFinished(const bool)), this, SLOT(loadFinished()));
+            // Update the status of the forward and back buttons.
+            emit updateBackAction(currentWebEngineHistoryPointer->canGoBack());
+            emit updateForwardAction(currentWebEngineHistoryPointer->canGoForward());
+        }
+
+        // Reapply the zoom factor.  This is a bug in QWebEngineView that resets the zoom with every load.  It can be removed once <https://redmine.stoutner.com/issues/799> is fixed.
+        privacyWebEngineViewPointer->setZoomFactor(currentZoomFactor);
+    });
+
+    // Update the progress bar when a load is started.
+    connect(privacyWebEngineViewPointer, &PrivacyWebEngineView::loadStarted, [privacyWebEngineViewPointer, this] ()
+    {
+        // Store the load progress.
+        privacyWebEngineViewPointer->loadProgressInt = 0;
+
+        // Show the progress bar if this is the current tab.
+        if (privacyWebEngineViewPointer == currentPrivacyWebEngineViewPointer)
+            emit showProgressBar(0);
+    });
+
+    // Update the progress bar when a load progresses.
+    connect(privacyWebEngineViewPointer, &PrivacyWebEngineView::loadProgress, [privacyWebEngineViewPointer, this] (const int progress)
+    {
+        // Store the load progress.
+        privacyWebEngineViewPointer->loadProgressInt = progress;
+
+        // Update the progress bar if this is the current tab.
+        if (privacyWebEngineViewPointer == currentPrivacyWebEngineViewPointer)
+            emit showProgressBar(progress);
+    });
+
+    // Update the progress bar when a load finishes.
+    connect(privacyWebEngineViewPointer, &PrivacyWebEngineView::loadFinished, [privacyWebEngineViewPointer, this] ()
+    {
+        // Store the load progress.
+        privacyWebEngineViewPointer->loadProgressInt = -1;
+
+        // Hide the progress bar if this is the current tab.
+        if (privacyWebEngineViewPointer == currentPrivacyWebEngineViewPointer)
+            emit hideProgressBar();
+    });
 
     // Handle full screen requests.
     connect(webEnginePagePointer, SIGNAL(fullScreenRequested(QWebEngineFullScreenRequest)), this, SLOT(fullScreenRequested(QWebEngineFullScreenRequest)));
@@ -236,16 +279,13 @@ PrivacyWebEngineView* TabWidget::addTab(const bool focusNewWebEngineView)
     // Limit WebRTC to public IP addresses.
     webEngineSettingsPointer->setAttribute(QWebEngineSettings::WebRTCPublicInterfacesOnly, true);
 
-    // Define an update cookie count lambda.
-    auto updateCookieCount = [privacyWebEngineViewPointer, this] (const int numberOfCookies)
+    // Update the cookies action.
+    connect(privacyWebEngineViewPointer, &PrivacyWebEngineView::updateCookiesAction, [privacyWebEngineViewPointer, this] (const int numberOfCookies)
     {
         // Update the cookie action if the specified privacy WebEngine view is the current privacy WebEngine view.
         if (privacyWebEngineViewPointer == currentPrivacyWebEngineViewPointer)
             emit updateCookiesAction(numberOfCookies);
-    };
-
-    // Update the cookies action.
-    connect(privacyWebEngineViewPointer, &PrivacyWebEngineView::updateCookiesAction, this, updateCookieCount);
+    });
 
     // Process cookie changes.
     connect(webEngineCookieStorePointer, SIGNAL(cookieAdded(QNetworkCookie)), privacyWebEngineViewPointer, SLOT(addCookieToList(QNetworkCookie)));
@@ -258,21 +298,22 @@ PrivacyWebEngineView* TabWidget::addTab(const bool focusNewWebEngineView)
     for (QNetworkCookie *cookiePointer : *durableCookiesListPointer)
         addCookieToStore(*cookiePointer, webEngineCookieStorePointer);
 
-    // Define an update tab title lambda.
-    auto updateTabTitle = [privacyWebEngineViewPointer, this] (const QString &title)
+    // Update the title when it changes.
+    connect(privacyWebEngineViewPointer, &PrivacyWebEngineView::titleChanged, [this, privacyWebEngineViewPointer] (const QString &title)
     {
         // Get the index for this tab.
         int tabIndex = tabWidgetPointer->indexOf(privacyWebEngineViewPointer);
 
         // Update the title for this tab.
         tabWidgetPointer->setTabText(tabIndex, title);
-    };
 
-    // Update the title when it changes.
-    connect(privacyWebEngineViewPointer, &PrivacyWebEngineView::titleChanged, this, updateTabTitle);
+        // Update the window title if this is the current tab.
+        if (tabIndex == tabWidgetPointer->currentIndex())
+            emit updateWindowTitle(title);
+    });
 
-    // Define an update tab icon lambda.
-    auto updateTabIcon = [privacyWebEngineViewPointer, this] (const QIcon &icon)
+    // Update the icon when it changes.
+    connect(privacyWebEngineViewPointer, &PrivacyWebEngineView::iconChanged, [privacyWebEngineViewPointer, this] (const QIcon &icon)
     {
         // Get the index for this tab.
         int tabIndex = tabWidgetPointer->indexOf(privacyWebEngineViewPointer);
@@ -282,10 +323,7 @@ PrivacyWebEngineView* TabWidget::addTab(const bool focusNewWebEngineView)
             tabWidgetPointer->setTabIcon(tabIndex, defaultTabIcon);
         else
             tabWidgetPointer->setTabIcon(tabIndex, icon);
-    };
-
-    // Update the icon when it changes.
-    connect(privacyWebEngineViewPointer, &PrivacyWebEngineView::iconChanged, this, updateTabIcon);
+    });
 
     // Move to the new tab.
     tabWidgetPointer->setCurrentIndex(newTabIndex);
@@ -601,10 +639,13 @@ void TabWidget::home() const
     currentPrivacyWebEngineViewPointer->load(QUrl::fromUserInput(Settings::homepage()));
 }
 
-void TabWidget::loadFinished() const
+PrivacyWebEngineView* TabWidget::loadBlankInitialWebsite()
 {
-    // Hide the progress bar.
-    emit hideProgressBar();
+    // Apply the application settings.
+    applyApplicationSettings();
+
+    // Return the current privacy WebEngine view pointer.
+    return currentPrivacyWebEngineViewPointer;
 }
 
 void TabWidget::loadInitialWebsite()
@@ -628,18 +669,6 @@ void TabWidget::loadInitialWebsite()
     }
 }
 
-void TabWidget::loadProgress(const int &progress) const
-{
-    // Show the progress bar.
-    emit showProgressBar(progress);
-}
-
-void TabWidget::loadStarted() const
-{
-    // Show the progress bar.
-    emit showProgressBar(0);
-}
-
 void TabWidget::loadUrlFromLineEdit(QString url) const
 {
     // Decide if the text is more likely to be a URL or a search.
@@ -870,25 +899,21 @@ void TabWidget::updateUiWithTabSettings()
     emit clearUrlLineEditFocus();
 
     // Update the UI.
+    emit updateBackAction(currentWebEngineHistoryPointer->canGoBack());
+    emit updateCookiesAction(currentPrivacyWebEngineViewPointer->cookieListPointer->size());
     emit updateDomainSettingsIndicator(currentPrivacyWebEngineViewPointer->domainSettingsName != QStringLiteral(""));
+    emit updateDomStorageAction(currentWebEngineSettingsPointer->testAttribute(QWebEngineSettings::LocalStorageEnabled));
+    emit updateForwardAction(currentWebEngineHistoryPointer->canGoForward());
     emit updateJavaScriptAction(currentWebEngineSettingsPointer->testAttribute(QWebEngineSettings::JavascriptEnabled));
     emit updateLocalStorageAction(currentPrivacyWebEngineViewPointer->localStorageEnabled);
-    emit updateDomStorageAction(currentWebEngineSettingsPointer->testAttribute(QWebEngineSettings::LocalStorageEnabled));
+    emit updateWindowTitle(currentPrivacyWebEngineViewPointer->title());
+    emit updateUrlLineEdit(currentPrivacyWebEngineViewPointer->url());
     emit updateUserAgentActions(currentWebEngineProfilePointer->httpUserAgent(), true);
     emit updateZoomFactorAction(currentPrivacyWebEngineViewPointer->zoomFactor());
-    emit updateUrlLineEdit(currentPrivacyWebEngineViewPointer->url());
-    emit updateCookiesAction(currentPrivacyWebEngineViewPointer->cookieListPointer->size());
-}
 
-void TabWidget::updateUrl(const QUrl &url) const
-{
-    // Update the URL line edit.
-    emit updateUrlLineEdit(url);
-
-    // Update the status of the forward and back buttons.
-    emit updateBackAction(currentWebEngineHistoryPointer->canGoBack());
-    emit updateForwardAction(currentWebEngineHistoryPointer->canGoForward());
-
-    // Reapply the zoom factor.  This is a bug in QWebEngineView that resets the zoom with every load.  <https://redmine.stoutner.com/issues/799>
-    currentPrivacyWebEngineViewPointer->setZoomFactor(currentZoomFactor);
+    // Update the progress bar.
+    if (currentPrivacyWebEngineViewPointer->loadProgressInt >= 0)
+        emit showProgressBar(currentPrivacyWebEngineViewPointer->loadProgressInt);
+    else
+        emit hideProgressBar();
 }
index 6a24313b74561389ab87b35f1b1478554a7802e7..ed9ad03b002e314227c792d6a501d86f7533cd2c 100644 (file)
@@ -50,6 +50,7 @@ public:
 
     // The public functions.
     void applyOnTheFlyZoomFactor(const double &zoomFactor);
+    PrivacyWebEngineView* loadBlankInitialWebsite();
     void loadInitialWebsite();
     std::list<QNetworkCookie>* getCookieList() const;
     QString& getDomainSettingsName() const;
@@ -80,6 +81,7 @@ signals:
     void updateSearchEngineActions(const QString &searchEngine, const bool &updateCustomSearchEngineStatus) const;
     void updateUrlLineEdit(const QUrl &newUrl) const;
     void updateUserAgentActions(const QString &userAgent, const bool &updateCustomUserAgentStatus) const;
+    void updateWindowTitle(const QString &title) const;
     void updateZoomFactorAction(const double &zoomFactor) const;
 
 public Q_SLOTS:
@@ -108,15 +110,11 @@ private Q_SLOTS:
     void addFirstTab();
     void deleteTab(const int tabIndex);
     void fullScreenRequested(QWebEngineFullScreenRequest fullScreenRequest) const;
-    void loadFinished() const;
-    void loadProgress(const int &progress) const;
-    void loadStarted() const;
     void pageLinkHovered(const QString &linkUrl) const;
     void printWebpage(QPrinter *printerPointer) const;
     void showSaveDialog(QWebEngineDownloadItem *downloadItemPointer) const;
     void showSaveFilePickerDialog(QUrl &downloadUrl, QString &suggestedFileName);
     void updateUiWithTabSettings();
-    void updateUrl(const QUrl &url) const;
 
 private:
     // The private variables.
index acf72db504019702db450969a89e17523b0a0681..064c7eda22b7a70c4152306250e4fcd257f8bb30 100644 (file)
@@ -40,7 +40,7 @@
 #include <QStatusBar>
 
 // Construct the class.
-BrowserWindow::BrowserWindow() : KXmlGuiWindow()
+BrowserWindow::BrowserWindow(bool firstWindow) : KXmlGuiWindow()
 {
     // Initialize the variables.
     javaScriptEnabled = false;
@@ -247,6 +247,9 @@ BrowserWindow::BrowserWindow() : KXmlGuiWindow()
     // Update the URL line edit on page loads.
     connect(tabWidgetPointer, SIGNAL(updateUrlLineEdit(QUrl)), this, SLOT(updateUrlLineEdit(QUrl)));
 
+    // Update the window title.
+    connect(tabWidgetPointer, SIGNAL(updateWindowTitle(const QString)), this, SLOT(updateWindowTitle(const QString)));
+
     // Get a handle for the status bar.
     QStatusBar *statusBarPointer = statusBar();
 
@@ -289,8 +292,9 @@ BrowserWindow::BrowserWindow() : KXmlGuiWindow()
     connect(f11ShortcutPointer, SIGNAL(activated()), fullScreenActionPointer, SLOT(trigger()));
     connect(escapeShortcutPointer, SIGNAL(activated()), this, SLOT(escape()));
 
-    // Load the initial website.
-    tabWidgetPointer->loadInitialWebsite();
+    // Load the initial website if this is the first window.
+    if (firstWindow)
+        tabWidgetPointer->loadInitialWebsite();
 }
 
 void BrowserWindow::addOrEditDomainSettings() const
@@ -943,3 +947,9 @@ void BrowserWindow::updateUserAgentLabel(const QString &userAgentDatabaseName) c
     // Update the user agent label.
     userAgentLabelPointer->setText(UserAgentHelper::getUserAgentFromDatabaseName(userAgentDatabaseName));
 }
+
+void BrowserWindow::updateWindowTitle(const QString &title)
+{
+    // Update the window title.
+    setWindowTitle(title);
+}
index f880cc8f4903b2b63beea736f7614dc4fb3e4fb4..a131a4484e02f52d5d20e0669e7780b01e212124 100644 (file)
@@ -40,7 +40,7 @@ class BrowserWindow : public KXmlGuiWindow
 
 public:
     // The default constructor.
-    BrowserWindow();
+    BrowserWindow(bool firstWindow=true);
 
     // The public functions.
     QSize sizeHint() const override;
@@ -81,6 +81,7 @@ private Q_SLOTS:
     void updateSearchEngineLabel(const QString &searchEngineString) const;
     void updateUrlLineEdit(const QUrl &newUrl);
     void updateUserAgentLabel(const QString &userAgentDatabaseName) const;
+    void updateWindowTitle(const QString &title);
 
 private:
     // The private variables.