From: Soren Stoutner Date: Wed, 25 Sep 2024 18:00:23 +0000 (-0700) Subject: Add "open in browser" entries to the context menus. https://redmine.stoutner.com... X-Git-Url: https://gitweb.stoutner.com/?a=commitdiff_plain;h=25678d4e4ba496e5f262a29b538ec07bb96c7873;p=PrivacyBrowserPC.git Add "open in browser" entries to the context menus. https://redmine.stoutner.com/issues/1220 --- diff --git a/src/GlobalVariables.h b/src/GlobalVariables.h index da404ff..fc5235e 100644 --- a/src/GlobalVariables.h +++ b/src/GlobalVariables.h @@ -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 diff --git a/src/dialogs/RequestsDialog.cpp b/src/dialogs/RequestsDialog.cpp index 2ed1ba4..bfb099e 100644 --- a/src/dialogs/RequestsDialog.cpp +++ b/src/dialogs/RequestsDialog.cpp @@ -35,9 +35,6 @@ RequestsDialog::RequestsDialog(QWidget *parentWidgetPointer, QList // 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(); diff --git a/src/uis/RequestsDialog.ui b/src/uis/RequestsDialog.ui index 3bbb9d0..fd935c2 100644 --- a/src/uis/RequestsDialog.ui +++ b/src/uis/RequestsDialog.ui @@ -22,6 +22,10 @@ RequestsDialog + + Qt::ApplicationModal + + 0 diff --git a/src/widgets/PrivacyWebEngineView.cpp b/src/widgets/PrivacyWebEngineView.cpp index 6314f2b..ac543fa 100644 --- a/src/widgets/PrivacyWebEngineView.cpp +++ b/src/widgets/PrivacyWebEngineView.cpp @@ -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. diff --git a/src/widgets/PrivacyWebEngineView.h b/src/widgets/PrivacyWebEngineView.h index f68a755..60121cd 100644 --- a/src/widgets/PrivacyWebEngineView.h +++ b/src/widgets/PrivacyWebEngineView.h @@ -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; diff --git a/src/windows/BrowserWindow.cpp b/src/windows/BrowserWindow.cpp index 6dded8a..4e9f303 100644 --- a/src/windows/BrowserWindow.cpp +++ b/src/windows/BrowserWindow.cpp @@ -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 userAgentAssociatedWidgetsPointerList = userAgentPrivacyBrowserActionPointer->associatedWidgets();