From 6bf30e844110ee9a4eeaa1b814d22cee490f8414 Mon Sep 17 00:00:00 2001 From: Soren Stoutner Date: Thu, 29 Aug 2024 12:33:06 -0700 Subject: [PATCH] Implement opening web pages in other browsers. https://redmine.stoutner.com/issues/1216 --- doc/index.docbook | 4 ++-- src/ui.rcs/browserwindowui.rc | 3 +++ src/windows/BrowserWindow.cpp | 32 ++++++++++++++++++++++++++++++++ src/windows/BrowserWindow.h | 2 ++ 4 files changed, 39 insertions(+), 2 deletions(-) diff --git a/doc/index.docbook b/doc/index.docbook index 7282b39..3a9905e 100644 --- a/doc/index.docbook +++ b/doc/index.docbook @@ -1793,10 +1793,10 @@ Changelog - + <ulink url="https://www.stoutner.com/privacy-browser-pc-0-6-1/">0.6.1</ulink> - - 21 August 2024 + 21 August 2024 Fix the domain settings dialog not fitting on small screens. diff --git a/src/ui.rcs/browserwindowui.rc b/src/ui.rcs/browserwindowui.rc index 0deed07..d0c931e 100644 --- a/src/ui.rcs/browserwindowui.rc +++ b/src/ui.rcs/browserwindowui.rc @@ -36,6 +36,9 @@ + + + diff --git a/src/windows/BrowserWindow.cpp b/src/windows/BrowserWindow.cpp index 9177b26..6dded8a 100644 --- a/src/windows/BrowserWindow.cpp +++ b/src/windows/BrowserWindow.cpp @@ -95,6 +95,8 @@ BrowserWindow::BrowserWindow(bool firstWindow, QString *initialUrlStringPointer) QAction *newTabActionPointer = actionCollectionPointer->addAction(QLatin1String("new_tab")); QAction *newWindowActionPointer = actionCollectionPointer->addAction(QLatin1String("new_window")); QAction *saveArchiveActionPointer = actionCollectionPointer->addAction(QLatin1String("save_archive")); + QAction *openWithFirefoxActionPointer = actionCollectionPointer->addAction(QLatin1String("open_with_firefox")); + QAction *openWithChromiumActionPointer = actionCollectionPointer->addAction(QLatin1String("open_with_chromium")); zoomDefaultActionPointer = actionCollectionPointer->addAction(QLatin1String("zoom_default")); QAction *reloadAndBypassCacheActionPointer = actionCollectionPointer->addAction(QLatin1String("reload_and_bypass_cache")); stopActionPointer = actionCollectionPointer->addAction(QLatin1String("stop")); @@ -194,6 +196,8 @@ BrowserWindow::BrowserWindow(bool firstWindow, QString *initialUrlStringPointer) newTabActionPointer->setText(i18nc("New tab action", "New Tab")); newWindowActionPointer->setText(i18nc("New window action", "New Window")); saveArchiveActionPointer->setText(i18nc("Save archive action", "Save Archive")); + openWithFirefoxActionPointer->setText(i18nc("Open with Firefox action", "Open With Firefox")); + openWithChromiumActionPointer->setText(i18nc("Open with Chromium action", "Open With Chromium")); zoomDefaultActionPointer->setText(i18nc("Zoom default action", "Zoom Default")); reloadAndBypassCacheActionPointer->setText(i18nc("Reload and bypass cache action", "Reload and Bypass Cache")); stopActionPointer->setText(i18nc("Stop action", "Stop")); @@ -239,6 +243,8 @@ BrowserWindow::BrowserWindow(bool firstWindow, QString *initialUrlStringPointer) newTabActionPointer->setIcon(QIcon::fromTheme(QLatin1String("tab-new"))); newWindowActionPointer->setIcon(QIcon::fromTheme(QLatin1String("window-new"))); saveArchiveActionPointer->setIcon(QIcon::fromTheme(QLatin1String("document-save"))); + openWithFirefoxActionPointer->setIcon(QIcon::fromTheme(QLatin1String("firefox-esr"))); + openWithChromiumActionPointer->setIcon(QIcon::fromTheme(QLatin1String("chromium"))); zoomDefaultActionPointer->setIcon(QIcon::fromTheme(QLatin1String("zoom-fit-best"))); reloadAndBypassCacheActionPointer->setIcon(QIcon::fromTheme(QLatin1String("view-refresh"))); stopActionPointer->setIcon(QIcon::fromTheme(QLatin1String("process-stop"))); @@ -284,6 +290,8 @@ BrowserWindow::BrowserWindow(bool firstWindow, QString *initialUrlStringPointer) QKeySequence ctrlTKeySequence = QKeySequence(i18nc("The open new tab key sequence.", "Ctrl+T")); QKeySequence ctrlNKeySequence = QKeySequence(i18nc("The open new window key sequence.", "Ctrl+N")); QKeySequence ctrlAKeySequence = QKeySequence(i18nc("The save archive key sequence.", "Ctrl+A")); + QKeySequence altFKeySequence = QKeySequence(i18nc("The open with Firefox key sequence.", "Alt+F")); + QKeySequence altCKeySequence = QKeySequence(i18nc("The open with Chromium key sequence.", "Alt+C")); QKeySequence ctrl0KeySequence = QKeySequence(i18nc("The zoom default key sequence.", "Ctrl+0")); QKeySequence ctrlF5KeySequence = QKeySequence(i18nc("The reload and bypass cache key sequence.", "Ctrl+F5")); QKeySequence ctrlShiftXKeySequence = QKeySequence(i18nc("The stop key sequence.", "Ctrl+Shift+X")); @@ -323,6 +331,8 @@ BrowserWindow::BrowserWindow(bool firstWindow, QString *initialUrlStringPointer) actionCollectionPointer->setDefaultShortcut(newTabActionPointer, ctrlTKeySequence); actionCollectionPointer->setDefaultShortcut(newWindowActionPointer, ctrlNKeySequence); actionCollectionPointer->setDefaultShortcut(saveArchiveActionPointer, ctrlAKeySequence); + actionCollectionPointer->setDefaultShortcut(openWithFirefoxActionPointer, altFKeySequence); + actionCollectionPointer->setDefaultShortcut(openWithChromiumActionPointer, altCKeySequence); actionCollectionPointer->setDefaultShortcut(zoomDefaultActionPointer, ctrl0KeySequence); actionCollectionPointer->setDefaultShortcut(reloadAndBypassCacheActionPointer, ctrlF5KeySequence); actionCollectionPointer->setDefaultShortcut(stopActionPointer, ctrlShiftXKeySequence); @@ -362,6 +372,8 @@ BrowserWindow::BrowserWindow(bool firstWindow, QString *initialUrlStringPointer) connect(newTabActionPointer, SIGNAL(triggered()), tabWidgetPointer, SLOT(addTab())); connect(newWindowActionPointer, SIGNAL(triggered()), this, SLOT(newWindow())); connect(saveArchiveActionPointer, SIGNAL(triggered()), tabWidgetPointer, SLOT(saveArchive())); + connect(openWithFirefoxActionPointer, SIGNAL(triggered()), this, SLOT(openWithFirefox())); + connect(openWithChromiumActionPointer, SIGNAL(triggered()), this, SLOT(openWithChromium())); connect(zoomDefaultActionPointer, SIGNAL(triggered()), this, SLOT(zoomDefault())); connect(reloadAndBypassCacheActionPointer, SIGNAL(triggered()), this, SLOT(reloadAndBypassCache())); connect(stopActionPointer, SIGNAL(triggered()), tabWidgetPointer, SLOT(stop())); @@ -428,6 +440,14 @@ 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); + // Get lists of the actions' associated widgets. QList userAgentAssociatedWidgetsPointerList = userAgentPrivacyBrowserActionPointer->associatedWidgets(); QList searchEngineAssociatedWidgetsPointerList = searchEngineMojeekActionPointer->associatedWidgets(); @@ -1134,6 +1154,18 @@ void BrowserWindow::newWindow() const browserWindowPointer->show(); } +void BrowserWindow::openWithChromium() const +{ + // Open the current URL in Chromium + QProcess::startDetached("chromium", QStringList(urlLineEditPointer->text())); +} + +void BrowserWindow::openWithFirefox() const +{ + // Open the current URL in Firefox. + QProcess::startDetached("firefox-esr", QStringList(urlLineEditPointer->text())); +} + void BrowserWindow::populateBookmarksInAllWindows() const { // Get a list of all the registered service names. diff --git a/src/windows/BrowserWindow.h b/src/windows/BrowserWindow.h index 8ee94b8..7564567 100644 --- a/src/windows/BrowserWindow.h +++ b/src/windows/BrowserWindow.h @@ -73,6 +73,8 @@ private Q_SLOTS: void incrementZoom(); void loadUrlFromLineEdit(const QString &url) const; void newWindow() const; + void openWithChromium() const; + void openWithFirefox() const; void populateBookmarksInAllWindows() const; void refresh() const; void reloadAndBypassCache() const; -- 2.45.2