]> gitweb.stoutner.com Git - PrivacyBrowserPC.git/commitdiff
Add "open in browser" entries to the context menus. https://redmine.stoutner.com...
authorSoren Stoutner <soren@stoutner.com>
Wed, 25 Sep 2024 18:00:23 +0000 (11:00 -0700)
committerSoren Stoutner <soren@stoutner.com>
Wed, 25 Sep 2024 18:00:23 +0000 (11:00 -0700)
src/GlobalVariables.h
src/dialogs/RequestsDialog.cpp
src/dialogs/SettingsDialog.cpp
src/main.cpp
src/uis/RequestsDialog.ui
src/widgets/PrivacyWebEngineView.cpp
src/widgets/PrivacyWebEngineView.h
src/windows/BrowserWindow.cpp

index da404ffb4942cabdf3a20217eced77bba8a6f3a7..fc5235e3fdf653d83d8120f9ed7b5e236cf7ac8d 100644 (file)
@@ -24,6 +24,8 @@
 #include "helpers/FilterListHelper.h"
 
 // List the global variables, proceeded by `extern`.
+extern bool globalChromiumInstalled;
 extern FilterListHelper *globalFilterListHelperPointer;
+extern bool globalFirefoxInstalled;
 
 #endif
index 2ed1ba43036c097b2a3b35f6c7a53fec925676a8..bfb099e1cdb733e87ddfcafee8e2ee393c817612 100644 (file)
@@ -35,9 +35,6 @@ RequestsDialog::RequestsDialog(QWidget *parentWidgetPointer, QList<RequestStruct
     // Set the window title.
     setWindowTitle(i18nc("The requests dialog window title", "Requests"));
 
-    // Set the window modality.
-    setWindowModality(Qt::WindowModality::ApplicationModal);
-
     // Instantiate the requests dialog UI.
     Ui::RequestsDialog requestsDialogUi;
 
index 1f3fb79441901bae1674222a38743445639c4997..7fc0f54fb57ab31896c1bf63d3a2a578e6e4a880 100644 (file)
@@ -95,7 +95,7 @@ SettingsDialog::SettingsDialog(QWidget *parentWidgetPointer, KCoreConfigSkeleton
     QStringList enabledSpellCheckLanguagesList = Settings::spellCheckLanguages();
 
     // Add each dictionary to the spell check list widget.
-    foreach(QString dictionaryString, dictionariesStringList)
+    foreach (QString dictionaryString, dictionariesStringList)
     {
         // Create a new list widget item pointer.
         QListWidgetItem *listWidgetItemPointer = new QListWidgetItem();
index 4f1c8a4d7a374d954cff480ea0d8b696311a78f2..6887fd1a2a79ed6abaca75dec705c7c12e7d4e6d 100644 (file)
@@ -37,7 +37,9 @@
 #include <QFile>
 
 // Declare the global variables.
+bool globalChromiumInstalled;
 FilterListHelper *globalFilterListHelperPointer;
+bool globalFirefoxInstalled;
 
 int main(int argc, char *argv[])
 {
@@ -97,9 +99,13 @@ int main(int argc, char *argv[])
     CookiesDatabase::addDatabase();
     DomainsDatabase::addDatabase();
 
-    // Populate the filter lists.
+    // Populate the global filter list helper.
     globalFilterListHelperPointer = new FilterListHelper;
 
+    // Check if other browsers are installed and store the result in the global variables
+    globalChromiumInstalled = (system("chromium --version > /dev/null 2> /dev/null") == 0);
+    globalFirefoxInstalled = (system("firefox -v > /dev/null 2> /dev/null") == 0);
+
     // Create the main window.
     BrowserWindow *browserWindowPointer = new BrowserWindow();
 
index 3bbb9d0f3fbaca77b18c1f0e6a4f1df1289a9102..fd935c2ca47786906fb094fa03ff8026fddb6947 100644 (file)
     <class>RequestsDialog</class>
 
     <widget class="QWidget">
+        <property name="windowModality">
+            <enum>Qt::ApplicationModal</enum>
+        </property>
+
         <property name="geometry">
             <rect>
                 <x>0</x>
index 6314f2b2a01fc020f3acb83baaabfefd5fe34dda..ac543fadd9aa0f5924ac5ef5123ceb3a63d08d1f 100644 (file)
@@ -18,6 +18,7 @@
  */
 
 // Application headers.
+#include "GlobalVariables.h"
 #include "PrivacyWebEngineView.h"
 #include "PrivacyWebEnginePage.h"
 #include "Settings.h"
@@ -62,6 +63,9 @@ PrivacyWebEngineView::PrivacyWebEngineView(QWidget *parentWidgetPointer) : QWebE
 
     // Handle HTTP authentication requests.
     connect(privacyWebEnginePagePointer, SIGNAL(authenticationRequired(const QUrl&, QAuthenticator*)), this, SLOT(handleAuthenticationRequest(const QUrl&, QAuthenticator*)));
+
+    // Store the link URL whenever a link is hovered.
+    connect(privacyWebEnginePagePointer, SIGNAL(linkHovered(const QString)), this, SLOT(saveHoveredLink(const QString)));
 }
 
 void PrivacyWebEngineView::addCookieToList(const QNetworkCookie &cookie) const
@@ -247,17 +251,50 @@ void PrivacyWebEngineView::contextMenuEvent(QContextMenuEvent *contextMenuEvent)
     // Add the open link in new background tab action if the context menu already contains the open link in new window action.
     if (contextMenuActionsList.contains(webEnginePagePointer->action(QWebEnginePage::OpenLinkInNewWindow)))
     {
-        // Move the open in new tab action to the top of the list.
+        // Move the open in new tab action above the back action.
         contextMenu->insertAction(webEnginePagePointer->action(QWebEnginePage::Back), webEnginePagePointer->action(QWebEnginePage::OpenLinkInNewTab));
 
-        // Add the open link in background tab action below the open in new tab action.
+        // Add the open link in background tab action above the back action.
         contextMenu->insertAction(webEnginePagePointer->action(QWebEnginePage::Back), webEnginePagePointer->action(QWebEnginePage::OpenLinkInNewBackgroundTab));
 
-        // Move the open in new window action below the open in background tab action.
+        // Move the open in new window action above the back action.
         contextMenu->insertAction(webEnginePagePointer->action(QWebEnginePage::Back), webEnginePagePointer->action(QWebEnginePage::OpenLinkInNewWindow));
 
-        // Add a separator below the open in new window action.
+        // Add a separator above the back action.
         contextMenu->insertSeparator(webEnginePagePointer->action(QWebEnginePage::Back));
+
+        if (globalFirefoxInstalled || globalChromiumInstalled)
+        {
+            // Add the open with Firefox action if Firefox is installed.
+            if (globalFirefoxInstalled)
+            {
+                // Create an open with Firefox action.
+                QAction *openWithFirefoxActionPointer = new QAction(QIcon::fromTheme(QLatin1String("firefox-esr")), i18nc("Open with Firefox context menu action", "Open with Firefox"), contextMenu);
+
+                // Add the open with Firefox action above the back action.
+                contextMenu->insertAction(webEnginePagePointer->action(QWebEnginePage::Back), openWithFirefoxActionPointer);
+
+                // Connect the action.
+                connect(openWithFirefoxActionPointer, SIGNAL(triggered()), this, SLOT(openWithFirefox()));
+            }
+
+            // Add the open with Chromium action if Chromium is installed.
+            if (globalChromiumInstalled)
+            {
+                // Create an open with Chromium action.
+                QAction *openWithChromiumActionPointer = new QAction(QIcon::fromTheme(QLatin1String("chromium")), i18nc("Open with Chromium context menu action", "Open with Chromium"), contextMenu);
+
+                // Add the open with Chromium action above the back action.
+                contextMenu->insertAction(webEnginePagePointer->action(QWebEnginePage::Back), openWithChromiumActionPointer);
+
+                // Connect the action.
+                connect(openWithChromiumActionPointer, SIGNAL(triggered()), this, SLOT(openWithChromium()));
+            }
+
+
+            // Add a separator above the back action.
+            contextMenu->insertSeparator(webEnginePagePointer->action(QWebEnginePage::Back));
+        }
     }
 
     // Display the menu using the location in the context menu event.
@@ -327,6 +364,18 @@ void PrivacyWebEngineView::handleAuthenticationRequest(const QUrl &requestUrl, Q
     }
 }
 
+void PrivacyWebEngineView::openWithChromium() const
+{
+    // Open the current URL in Chromium
+    QProcess::startDetached("chromium", QStringList(hoveredLinkString));
+}
+
+void PrivacyWebEngineView::openWithFirefox() const
+{
+    // Open the current URL in Firefox.
+    QProcess::startDetached("firefox-esr", QStringList(hoveredLinkString));
+}
+
 void PrivacyWebEngineView::removeCookieFromList(const QNetworkCookie &cookie) const
 {
     //qDebug() << "Remove cookie:  " << cookie.toRawForm();
@@ -338,6 +387,12 @@ void PrivacyWebEngineView::removeCookieFromList(const QNetworkCookie &cookie) co
     emit numberOfCookiesChanged(cookieListPointer->size());
 }
 
+void PrivacyWebEngineView::saveHoveredLink(const QString &hoveredLink)
+{
+    // Save the hovered link.
+    hoveredLinkString = hoveredLink;
+}
+
 void PrivacyWebEngineView::storeRequest(RequestStruct *requestStructPointer)
 {
     // Store the request struct in the list.
index f68a7559be60d8d1778c62e0b4d619450f53998a..60121cd75c803dabad4da018ca0d5bac5dd95663 100644 (file)
@@ -91,10 +91,14 @@ private Q_SLOTS:
     void clearRequestsList();
     void displayHttpPingDialog(const QString &httpPingUrl) const;
     void handleAuthenticationRequest(const QUrl &requestUrl, QAuthenticator *authenticatorPointer);
+    void openWithChromium() const;
+    void openWithFirefox() const;
+    void saveHoveredLink(const QString &hoveredLink);
     void storeRequest(RequestStruct *requestStructPointer);
 
 private:
     // The private variables.
+    QString hoveredLinkString;
     KLineEdit *passwordLineEditPointer;
     KLineEdit *usernameLineEditPointer;
     QWebEngineProfile *webEngineProfilePointer;
index 6dded8a6024c150e1b1eb2ddf649240d1b30814c..4e9f3035da4ff1d7c611f8a9ffbeb314f11dd295 100644 (file)
@@ -19,6 +19,7 @@
 
 // Application headers.
 #include "BrowserWindow.h"
+#include "GlobalVariables.h"
 #include "Settings.h"
 #include "databases/BookmarksDatabase.h"
 #include "databases/DomainsDatabase.h"
@@ -368,7 +369,7 @@ BrowserWindow::BrowserWindow(bool firstWindow, QString *initialUrlStringPointer)
     actionCollectionPointer->setDefaultShortcut(domainSettingsActionPointer, ctrlShiftDKeySequence);
     actionCollectionPointer->setDefaultShortcut(cookiesActionPointer, ctrlSemicolonKeySequence);
 
-    // Execute the actions.
+    // Connect the actions.
     connect(newTabActionPointer, SIGNAL(triggered()), tabWidgetPointer, SLOT(addTab()));
     connect(newWindowActionPointer, SIGNAL(triggered()), this, SLOT(newWindow()));
     connect(saveArchiveActionPointer, SIGNAL(triggered()), tabWidgetPointer, SLOT(saveArchive()));
@@ -440,13 +441,9 @@ BrowserWindow::BrowserWindow(bool firstWindow, QString *initialUrlStringPointer)
     // Setup the GUI based on the browserwindowui.rc file.
     setupGUI(StandardWindowOption::Default, ("browserwindowui.rc"));
 
-    // Check if other browsers are installed.
-    int firefoxExitCodeInt = system("firefox -v > /dev/null 2> /dev/null");
-    int chromiumExitCodeInt = system("chromium --version > /dev/null 2> /dev/null");
-
     // Set the open with other browser actions visibility.
-    openWithFirefoxActionPointer->setVisible(firefoxExitCodeInt == 0);
-    openWithChromiumActionPointer->setVisible(chromiumExitCodeInt == 0);
+    openWithFirefoxActionPointer->setVisible(globalFirefoxInstalled);
+    openWithChromiumActionPointer->setVisible(globalChromiumInstalled);
 
     // Get lists of the actions' associated widgets.
     QList<QWidget*> userAgentAssociatedWidgetsPointerList = userAgentPrivacyBrowserActionPointer->associatedWidgets();