From 4cc8dc9f33a42f36b049248acff0be5bb01d3090 Mon Sep 17 00:00:00 2001 From: Soren Stoutner Date: Tue, 30 Jun 2026 14:51:27 -0700 Subject: [PATCH] Add a forward and back history. https://redmine.stoutner.com/issues/1098 --- src/widgets/PrivacyWebEnginePage.cpp | 28 +++---- src/widgets/PrivacyWebEnginePage.h | 28 ++++--- src/widgets/PrivacyWebEngineView.cpp | 42 +++++++++- src/widgets/PrivacyWebEngineView.h | 11 ++- src/widgets/TabWidget.cpp | 30 +++----- src/widgets/TabWidget.h | 9 +-- src/windows/BrowserWindow.cpp | 110 +++++++++++++++++++++++---- src/windows/BrowserWindow.h | 7 +- 8 files changed, 191 insertions(+), 74 deletions(-) diff --git a/src/widgets/PrivacyWebEnginePage.cpp b/src/widgets/PrivacyWebEnginePage.cpp index b2fec02..e89ecdb 100644 --- a/src/widgets/PrivacyWebEnginePage.cpp +++ b/src/widgets/PrivacyWebEnginePage.cpp @@ -1,25 +1,25 @@ -/* - * Copyright 2024 Soren Stoutner . +/* SPDX-License-Identifier: GPL-3.0-or-later + * SPDX-FileCopyrightText: 2024, 2026 Soren Stoutner * * This file is part of Privacy Browser PC . * - * Privacy Browser PC is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. + * This program is free software: you can redistribute it and/or modify it under + * the terms of the GNU General Public License as published by the Free Software + * Foundation, either version 3 of the License, or (at your option) any later + * version. * - * Privacy Browser PC is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more + * details. * - * You should have received a copy of the GNU General Public License - * along with Privacy Browser PC. If not, see . + * You should have received a copy of the GNU General Public License along with + * this program. If not, see . */ // Application headers. #include "PrivacyWebEnginePage.h" // Construct the class. -PrivacyWebEnginePage::PrivacyWebEnginePage(QWebEngineProfile *webEngineProfilePointer, QObject *parentObjectPointer) : QWebEnginePage(webEngineProfilePointer, parentObjectPointer) {} - +PrivacyWebEnginePage::PrivacyWebEnginePage(QWebEngineProfile *webEngineProfilePointer, QObject *parentObjectPointer) : + QWebEnginePage(webEngineProfilePointer, parentObjectPointer) {} diff --git a/src/widgets/PrivacyWebEnginePage.h b/src/widgets/PrivacyWebEnginePage.h index 9880b0b..07a300f 100644 --- a/src/widgets/PrivacyWebEnginePage.h +++ b/src/widgets/PrivacyWebEnginePage.h @@ -1,20 +1,20 @@ -/* - * Copyright 2024 Soren Stoutner . +/* SPDX-License-Identifier: GPL-3.0-or-later + * SPDX-FileCopyrightText: 2024, 2026 Soren Stoutner * * This file is part of Privacy Browser PC . * - * Privacy Browser PC is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. + * This program is free software: you can redistribute it and/or modify it under + * the terms of the GNU General Public License as published by the Free Software + * Foundation, either version 3 of the License, or (at your option) any later + * version. * - * Privacy Browser PC is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more + * details. * - * You should have received a copy of the GNU General Public License - * along with Privacy Browser PC. If not, see . + * You should have received a copy of the GNU General Public License along with + * this program. If not, see . */ #ifndef PRIVACY_WEBENGINE_PAGE_H @@ -29,9 +29,7 @@ class PrivacyWebEnginePage : public QWebEnginePage Q_OBJECT public: - // The default constructor. + // The primary constructor. explicit PrivacyWebEnginePage(QWebEngineProfile *webEngineProfilePointer, QObject *parentObjectPointer = nullptr); - -//protected: }; #endif diff --git a/src/widgets/PrivacyWebEngineView.cpp b/src/widgets/PrivacyWebEngineView.cpp index 298cdb9..3ad936b 100644 --- a/src/widgets/PrivacyWebEngineView.cpp +++ b/src/widgets/PrivacyWebEngineView.cpp @@ -1,5 +1,5 @@ /* SPDX-License-Identifier: GPL-3.0-or-later - * SPDX-FileCopyrightText: 2022-2025 Soren Stoutner + * SPDX-FileCopyrightText: 2022-2026 Soren Stoutner * * This file is part of Privacy Browser PC . * @@ -73,6 +73,9 @@ PrivacyWebEngineView::PrivacyWebEngineView(QWidget *parentWidgetPointer) : QWebE // Store the URL when it changes. connect(this, SIGNAL(urlChanged(const QUrl&)), this, SLOT(storeUpdatedUrl(const QUrl&))); + + // Update the favorite icon when it is received. + connect(this, SIGNAL(iconChanged(const QIcon&)), this, SLOT(processFavoriteIcon(const QIcon&))); } void PrivacyWebEngineView::addCookieToList(const QNetworkCookie &cookie) const @@ -238,7 +241,8 @@ void PrivacyWebEngineView::applyDomainSettings(const QUrl &newUrl, const bool na Q_EMIT updateUi(this); // Reload the URL. - // This works around a bug in Qt WebEngine that causes massive problems when the user agent is changed after the page has started pre-rendering. + // This works around a bug in Qt WebEngine that causes massive problems when the user agent is changed after the page has started pre-rendering. + // if (navigatingHistory) { // Get a handle for the WebEngine history. @@ -436,6 +440,21 @@ void PrivacyWebEngineView::displayHttpPingDialog(const QString &httpPingUrl) con Q_EMIT displayHttpPingBlockedDialog(httpPingUrl); } +QIcon PrivacyWebEngineView::getFavoriteIcon(const QString &favoriteIconUrlString) +{ + // Check if the favorite icons map already contains the favorite icon. + if (favoriteIconsMap.contains(favoriteIconUrlString)) // The favorite icons map already contains the icon. + { + // Return the favorite icon. + return favoriteIconsMap.value(favoriteIconUrlString); + } + else // The favorite icons map does not contain the icon. + { + // Return the default favorite icon. + return defaultFavoriteIcon; + } +} + void PrivacyWebEngineView::handleAuthenticationRequest(const QUrl &requestUrl, QAuthenticator *authenticatorPointer) { // Only display the HTTP authentication dialog if it hasn't already been displayed three times for this URL. @@ -472,6 +491,21 @@ void PrivacyWebEngineView::openWithFirefox() const QProcess::startDetached(QLatin1String("firefox-esr"), QStringList(hoveredLinkString)); } +void PrivacyWebEngineView::processFavoriteIcon(const QIcon &newFavoriteIcon) +{ + // Store the favorite icon in the privacy WebEngine view. It is used when creating bookmarks. + if (newFavoriteIcon.isNull()) + favoriteIcon = defaultFavoriteIcon; + else + favoriteIcon = newFavoriteIcon; + + // Add the icon to the favorite icons map if it doesn't already exist. These are used for populating the forward and back icons. + if (!favoriteIconsMap.contains(currentUrlString)) + favoriteIconsMap.insert(currentUrlString, favoriteIcon); + + Q_EMIT favoriteIconChanged(favoriteIcon); +} + void PrivacyWebEngineView::removeCookieFromList(const QNetworkCookie &cookie) const { //qDebug() << "Remove cookie: " << cookie.toRawForm(); @@ -519,7 +553,7 @@ void PrivacyWebEngineView::storeRequest(RequestStruct *requestStructPointer) void PrivacyWebEngineView::storeUpdatedUrl(const QUrl &newUrl) { - // Store the new URL string (which changes when a new page is loaded as the current URL text. This is important when loading a new tab from a link. - currentUrlText = newUrl.toString(); + // Store the new URL string. This is important when loading a new tab from a link. + currentUrlString = newUrl.toString(); } diff --git a/src/widgets/PrivacyWebEngineView.h b/src/widgets/PrivacyWebEngineView.h index 984d972..e3c2b26 100644 --- a/src/widgets/PrivacyWebEngineView.h +++ b/src/widgets/PrivacyWebEngineView.h @@ -1,5 +1,5 @@ /* SPDX-License-Identifier: GPL-3.0-or-later - * SPDX-FileCopyrightText: 2022-2025 Soren Stoutner + * SPDX-FileCopyrightText: 2022-2026 Soren Stoutner * * This file is part of Privacy Browser PC . * @@ -42,6 +42,9 @@ public: // The default constructor. explicit PrivacyWebEngineView(QWidget *parentWidgetPointer = nullptr); + // The public functions. + QIcon getFavoriteIcon(const QString &favoriteIconUrlString); + // The public static constants. static const int ULTRAPRIVACY = 0; static const int ULTRALIST = 1; @@ -54,7 +57,7 @@ public: QVector blockedRequestsVector = {0, 0, 0, 0, 0, 0}; std::list *cookieListPointer = new std::list; QString currentHost = QLatin1String(""); - QString currentUrlText = QLatin1String(""); + QString currentUrlString = QLatin1String(""); double defaultZoomFactor = 1.00; QString domainSettingsName = QLatin1String(""); bool easyListEnabled = true; @@ -76,6 +79,7 @@ Q_SIGNALS: // The signals. void numberOfCookiesChanged(const int numberOfCookies) const; void displayHttpPingBlockedDialog(const QString &httpPingUrl) const; + void favoriteIconChanged(const QIcon &newFavoriteIcon) const; void requestBlocked(const QVector blockedRequestsVector) const; void updateUi(const PrivacyWebEngineView *privacyWebEngineViewPointer) const; @@ -93,12 +97,15 @@ private Q_SLOTS: void manualOpenInNewTab(); void openWithChromium() const; void openWithFirefox() const; + void processFavoriteIcon(const QIcon&); void saveHoveredLink(const QString &hoveredLink); void storeRequest(RequestStruct *requestStructPointer); void storeUpdatedUrl(const QUrl &newUrl); private: // The private variables. + QIcon defaultFavoriteIcon = QIcon::fromTheme(QLatin1String("globe"), QIcon::fromTheme(QLatin1String("applications-internet"))); + QMap favoriteIconsMap; QString hoveredLinkString; bool manuallyOpeninginNewTab = false; KLineEdit *passwordLineEditPointer; diff --git a/src/widgets/TabWidget.cpp b/src/widgets/TabWidget.cpp index f3a08fe..bc1f4a0 100644 --- a/src/widgets/TabWidget.cpp +++ b/src/widgets/TabWidget.cpp @@ -236,8 +236,7 @@ PrivacyWebEngineView* TabWidget::addTab(const bool removeUrlLineEditFocus, const Q_EMIT updateUrlLineEdit(newUrl); // Update the status of the forward and back buttons. - Q_EMIT updateBackAction(currentWebEngineHistoryPointer->canGoBack()); - Q_EMIT updateForwardAction(currentWebEngineHistoryPointer->canGoForward()); + Q_EMIT forwardAndBackChanged(currentWebEngineHistoryPointer); } }); @@ -267,22 +266,16 @@ PrivacyWebEngineView* TabWidget::addTab(const bool removeUrlLineEditFocus, const }); // Update the icon when it changes. - connect(privacyWebEngineViewPointer, &PrivacyWebEngineView::iconChanged, [this, splitterPointer, privacyWebEngineViewPointer] (const QIcon &newFavoriteIcon) + connect(privacyWebEngineViewPointer, &PrivacyWebEngineView::favoriteIconChanged, [this, splitterPointer, privacyWebEngineViewPointer] (const QIcon &newFavoriteIcon) { - // Store the favorite icon in the privacy web engine view. - if (newFavoriteIcon.isNull()) - privacyWebEngineViewPointer->favoriteIcon = defaultFavoriteIcon; - else - privacyWebEngineViewPointer->favoriteIcon = newFavoriteIcon; - // Get the index for this tab. int tabIndex = qTabWidgetPointer->indexOf(splitterPointer); // Update the icon for this tab. - if (newFavoriteIcon.isNull()) - qTabWidgetPointer->setTabIcon(tabIndex, defaultFavoriteIcon); - else - qTabWidgetPointer->setTabIcon(tabIndex, newFavoriteIcon); + qTabWidgetPointer->setTabIcon(tabIndex, newFavoriteIcon); + + // Update the forward and back history. + Q_EMIT forwardAndBackChanged(currentWebEngineHistoryPointer); }); // Update the progress bar and the favorite icon when a load is started. @@ -730,7 +723,7 @@ std::list* TabWidget::getCookieList() const return currentPrivacyWebEngineViewPointer->cookieListPointer; } -QIcon TabWidget::getCurrentTabFavoritIcon() const +QIcon TabWidget::getCurrentTabFavoriteIcon() const { // Return the current Privacy WebEngine favorite icon. return currentPrivacyWebEngineViewPointer->favoriteIcon; @@ -1143,10 +1136,10 @@ void TabWidget::stop() const currentPrivacyWebEngineViewPointer->stop(); } -void TabWidget::storeCurrentUrlText(const QString &urlText) const +void TabWidget::storeCurrentUrlString(const QString &urlString) const { // Store the current URL text in the privacy WebEngine view. - currentPrivacyWebEngineViewPointer->currentUrlText = urlText; + currentPrivacyWebEngineViewPointer->currentUrlString = urlString; } void TabWidget::toggleDeveloperTools(const bool enabled) const @@ -1341,11 +1334,10 @@ void TabWidget::updateUiWithTabSettings() Q_EMIT ultraPrivacyStatusChanged(currentPrivacyWebEngineViewPointer->ultraPrivacyEnabled); Q_EMIT blockedRequestsUpdated(currentPrivacyWebEngineViewPointer->blockedRequestsVector); Q_EMIT cookiesChanged(currentPrivacyWebEngineViewPointer->cookieListPointer->size()); - Q_EMIT updateBackAction(currentWebEngineHistoryPointer->canGoBack()); + Q_EMIT forwardAndBackChanged(currentWebEngineHistoryPointer); Q_EMIT updateDefaultZoomFactor(currentPrivacyWebEngineViewPointer->defaultZoomFactor); Q_EMIT updateDeveloperToolsAction(devToolsWebEngineViewPointer->isVisible()); Q_EMIT updateDomStorageAction(currentWebEngineSettingsPointer->testAttribute(QWebEngineSettings::LocalStorageEnabled)); - Q_EMIT updateForwardAction(currentWebEngineHistoryPointer->canGoForward()); Q_EMIT updateJavaScriptAction(currentWebEngineSettingsPointer->testAttribute(QWebEngineSettings::JavascriptEnabled)); Q_EMIT updateLocalStorageAction(currentPrivacyWebEngineViewPointer->localStorageEnabled); Q_EMIT updateUserAgentActions(currentWebEngineProfilePointer->httpUserAgent(), true); @@ -1364,7 +1356,7 @@ void TabWidget::updateUiWithTabSettings() // Update the URL. Q_EMIT updateWindowTitle(currentPrivacyWebEngineViewPointer->title()); Q_EMIT updateDomainSettingsIndicator(currentPrivacyWebEngineViewPointer->domainSettingsName != QLatin1String("")); - Q_EMIT updateUrlLineEdit(QUrl(currentPrivacyWebEngineViewPointer->currentUrlText)); + Q_EMIT updateUrlLineEdit(QUrl(currentPrivacyWebEngineViewPointer->currentUrlString)); } void TabWidget::useNativeKdeDownloader(QUrl &downloadUrl, QString &suggestedFileName) diff --git a/src/widgets/TabWidget.h b/src/widgets/TabWidget.h index 86ba40b..c1ed9ac 100644 --- a/src/widgets/TabWidget.h +++ b/src/widgets/TabWidget.h @@ -1,5 +1,5 @@ /* SPDX-License-Identifier: GPL-3.0-or-later - * SPDX-FileCopyrightText: 2022-2025 Soren Stoutner + * SPDX-FileCopyrightText: 2022-2026 Soren Stoutner * * This file is part of Privacy Browser PC . * @@ -60,7 +60,7 @@ public: void loadInitialWebsite(); void findPrevious(const QString &text) const; std::list* getCookieList() const; - QIcon getCurrentTabFavoritIcon() const; + QIcon getCurrentTabFavoriteIcon() const; QString getCurrentTabTitle() const; QString getCurrentTabUrl() const; QString getCurrentUserAgent() const; @@ -85,20 +85,19 @@ Q_SIGNALS: void fanboysAnnoyanceListStatusChanged(const bool isEnabled) const; void removeCookie(const QNetworkCookie &cookie) const; void clearUrlLineEditFocus() const; + void forwardAndBackChanged(QWebEngineHistory *webEngineHistoryPointer) const; void fullScreenRequested(const bool toggleOn) const; void hideProgressBar() const; void linkHovered(const QString &linkUrl) const; void showProgressBar(const int &progress) const; void ultraListStatusChanged(const bool) const; void ultraPrivacyStatusChanged(const bool) const; - void updateBackAction(const bool isEnabled) const; void updateDefaultZoomFactor(const double newDefaultZoomFactorDouble) const; void updateDeveloperToolsAction(const bool isEnabled) const; void updateDomStorageAction(const bool isEnabled) const; void updateDomainSettingsIndicator(const bool status) const; void updateFindText(const QString &text, const bool findCaseSensitive) const; void updateFindTextResults(const QWebEngineFindTextResult &findTextResult) const; - void updateForwardAction(const bool isEnabled) const; void updateJavaScriptAction(const bool isEnabled) const; void updateLocalStorageAction(const bool isEnabled) const; void updateSearchEngineActions(const QString &searchEngine, const bool &updateCustomSearchEngineStatus) const; @@ -131,7 +130,7 @@ public Q_SLOTS: void reloadAndBypassCache() const; void saveArchive(); void stop() const; - void storeCurrentUrlText(const QString &urlText) const; + void storeCurrentUrlString(const QString &urlString) const; void toggleEasyList() const; void toggleEasyPrivacy() const; void toggleFanboysAnnoyanceList() const; diff --git a/src/windows/BrowserWindow.cpp b/src/windows/BrowserWindow.cpp index 2ff9a11..40b3885 100644 --- a/src/windows/BrowserWindow.cpp +++ b/src/windows/BrowserWindow.cpp @@ -1,5 +1,5 @@ /* SPDX-License-Identifier: GPL-3.0-or-later - * SPDX-FileCopyrightText: 2022-2025 Soren Stoutner + * SPDX-FileCopyrightText: 2022-2026 Soren Stoutner * * This file is part of Privacy Browser PC . * @@ -84,8 +84,8 @@ BrowserWindow::BrowserWindow(bool firstWindow, QString *initialUrlStringPointer) zoomOutActionPointer = KStandardAction::zoomOut(this, SLOT(decrementZoom()), actionCollectionPointer); refreshActionPointer = KStandardAction::redisplay(this, SLOT(refresh()), actionCollectionPointer); fullScreenActionPointer = KStandardAction::fullScreen(this, SLOT(toggleFullScreen()), this, actionCollectionPointer); - QAction *backActionPointer = KStandardAction::back(this, SLOT(back()), actionCollectionPointer); - QAction *forwardActionPointer = KStandardAction::forward(this, SLOT(forward()), actionCollectionPointer); + backActionPointer = KStandardAction::back(this, SLOT(back()), actionCollectionPointer); + forwardActionPointer = KStandardAction::forward(this, SLOT(forward()), actionCollectionPointer); KStandardAction::home(this, SLOT(home()), actionCollectionPointer); QAction *editBookmarksActionPointer = KStandardAction::editBookmarks(this, SLOT(editBookmarks()), actionCollectionPointer); KStandardAction::preferences(this, SLOT(showSettingsDialog()), actionCollectionPointer); @@ -139,6 +139,14 @@ BrowserWindow::BrowserWindow(bool firstWindow, QString *initialUrlStringPointer) findCaseSensitiveActionPointer = actionCollectionPointer->addAction(QLatin1String("find_case_sensitive")); hideFindTextActionPointer = actionCollectionPointer->addAction(QLatin1String("hide_find_actions")); + // Create the forward and back menus. + backMenuPointer = new QMenu(); + forwardMenuPointer = new QMenu(); + + // Set the forward and back menus. + backActionPointer->setMenu(backMenuPointer); + forwardActionPointer->setMenu(forwardMenuPointer); + // Create the action groups QActionGroup *userAgentActionGroupPointer = new QActionGroup(this); QActionGroup *searchEngineActionGroupPointer = new QActionGroup(this); @@ -426,9 +434,8 @@ BrowserWindow::BrowserWindow(bool firstWindow, QString *initialUrlStringPointer) connect(tabWidgetPointer, SIGNAL(fanboysAnnoyanceListStatusChanged(bool)), fanboysAnnoyanceListPointer, SLOT(setChecked(bool))); connect(tabWidgetPointer, SIGNAL(ultraListStatusChanged(bool)), ultraListActionPointer, SLOT(setChecked(bool))); connect(tabWidgetPointer, SIGNAL(ultraPrivacyStatusChanged(bool)), ultraPrivacyActionPointer, SLOT(setChecked(bool))); + connect(tabWidgetPointer, SIGNAL(forwardAndBackChanged(QWebEngineHistory *)), this, SLOT(updateForwardAndBackActions(QWebEngineHistory *))); connect(tabWidgetPointer, SIGNAL(updateDeveloperToolsAction(bool)), developerToolsActionPointer, SLOT(setChecked(bool))); - connect(tabWidgetPointer, SIGNAL(updateBackAction(bool)), backActionPointer, SLOT(setEnabled(bool))); - connect(tabWidgetPointer, SIGNAL(updateForwardAction(bool)), forwardActionPointer, SLOT(setEnabled(bool))); connect(tabWidgetPointer, SIGNAL(updateJavaScriptAction(bool)), this, SLOT(updateJavaScriptAction(bool))); connect(tabWidgetPointer, SIGNAL(updateLocalStorageAction(bool)), this, SLOT(updateLocalStorageAction(bool))); connect(tabWidgetPointer, SIGNAL(updateDomStorageAction(bool)), this, SLOT(updateDomStorageAction(bool))); @@ -690,7 +697,7 @@ void BrowserWindow::addBookmarkFolderFinalActions(QMenu *menuPointer, const doub { // Instantiate an add bookmark dialog. AddBookmarkDialog *addBookmarkDialogPointer = new AddBookmarkDialog(this, tabWidgetPointer->getCurrentTabTitle(), tabWidgetPointer->getCurrentTabUrl(), - tabWidgetPointer->getCurrentTabFavoritIcon(), folderId); + tabWidgetPointer->getCurrentTabFavoriteIcon(), folderId); // Update the displayed bookmarks when a new one is added. connect(addBookmarkDialogPointer, SIGNAL(bookmarkAdded()), this, SLOT(populateBookmarksInAllWindows())); @@ -704,7 +711,7 @@ void BrowserWindow::addBookmarkFolderFinalActions(QMenu *menuPointer, const doub QAction *addFolderActionPointer = menuPointer->addAction(QIcon::fromTheme(QLatin1String("folder-add")), i18nc("The add folder action", "Add Folder"), [=] { // Instantiate an add folder dialog. - AddFolderDialog *addFolderDialogPointer = new AddFolderDialog(this, tabWidgetPointer->getCurrentTabFavoritIcon(), folderId); + AddFolderDialog *addFolderDialogPointer = new AddFolderDialog(this, tabWidgetPointer->getCurrentTabFavoriteIcon(), folderId); // Update the displayed bookmarks when a folder is added. connect(addFolderDialogPointer, SIGNAL(folderAdded()), this, SLOT(populateBookmarksInAllWindows())); @@ -772,7 +779,7 @@ void BrowserWindow::addBookmarkFolderFinalActions(QMenu *menuPointer, const doub QAction *editFolderActionPointer = menuPointer->addAction(QIcon::fromTheme(QLatin1String("document-edit")), i18nc("The edit folder action", "Edit Folder"), [=] { // Get the current tab favorite icon. - QIcon currentTabFavoriteIcon = tabWidgetPointer->getCurrentTabFavoritIcon(); + QIcon currentTabFavoriteIcon = tabWidgetPointer->getCurrentTabFavoriteIcon(); // Instantiate an edit folder dialog. QDialog *editFolderDialogPointer = new EditFolderDialog(this, folderDatabaseId, currentTabFavoriteIcon); @@ -985,7 +992,7 @@ void BrowserWindow::decrementZoom() void BrowserWindow::editBookmarks() { // Instantiate an edit bookmarks dialog. - BookmarksDialog *bookmarksDialogPointer = new BookmarksDialog(this, tabWidgetPointer->getCurrentTabFavoritIcon(), tabWidgetPointer->getCurrentTabTitle(), tabWidgetPointer->getCurrentTabUrl()); + BookmarksDialog *bookmarksDialogPointer = new BookmarksDialog(this, tabWidgetPointer->getCurrentTabFavoriteIcon(), tabWidgetPointer->getCurrentTabTitle(), tabWidgetPointer->getCurrentTabUrl()); // Update the displayed bookmarks when edited. connect(bookmarksDialogPointer, SIGNAL(bookmarkUpdated()), this, SLOT(populateBookmarksInAllWindows())); @@ -1424,13 +1431,13 @@ void BrowserWindow::populateBookmarksToolBarSubfolders(const double folderId, QM } } -void BrowserWindow::processUrlTextChanges(const QString &newUrlText) const +void BrowserWindow::processUrlTextChanges(const QString &newUrlString) const { // Update the visibility of the restore URL text action pointer. - restoreUrlTextActionPointer->setVisible(newUrlText != tabWidgetPointer->getCurrentTabUrl()); + restoreUrlTextActionPointer->setVisible(newUrlString != tabWidgetPointer->getCurrentTabUrl()); // Store the new URL text in the WebEngine View. - tabWidgetPointer->storeCurrentUrlText(newUrlText); + tabWidgetPointer->storeCurrentUrlString(newUrlString); } void BrowserWindow::refresh() const @@ -1542,7 +1549,7 @@ void BrowserWindow::showBookmarkContextMenu(const QPoint &point) bookmarkContextMenuPointer->addAction(QIcon::fromTheme(QLatin1String("document-edit")), i18nc("Edit bookmark context menu entry", "Edit"), [=] { // Get the current tab favorite icon. - QIcon currentTabFavoriteIcon = tabWidgetPointer->getCurrentTabFavoritIcon(); + QIcon currentTabFavoriteIcon = tabWidgetPointer->getCurrentTabFavoriteIcon(); // Instantiate an edit bookmark dialog. QDialog *editBookmarkDialogPointer = new EditBookmarkDialog(this, databaseId, currentTabFavoriteIcon); @@ -1745,7 +1752,7 @@ void BrowserWindow::toggleBookmark() bookmarkStructPointer->name = tabWidgetPointer->getCurrentTabTitle(); bookmarkStructPointer->url = tabWidgetPointer->getCurrentTabUrl(); bookmarkStructPointer->parentFolderId = 0; - bookmarkStructPointer->favoriteIcon = tabWidgetPointer->getCurrentTabFavoritIcon(); + bookmarkStructPointer->favoriteIcon = tabWidgetPointer->getCurrentTabFavoriteIcon(); // Add the bookmark. BookmarksDatabase::addBookmark(bookmarkStructPointer); @@ -1950,6 +1957,81 @@ void BrowserWindow::updateFindTextResults(const QWebEngineFindTextResult &findTe findTextLineEditPointer->setPalette(positiveBackgroundPalette); } +void BrowserWindow::updateForwardAndBackActions(QWebEngineHistory *webEngineHistoryPointer) +{ + // Clear the forward and back menus. + backMenuPointer->clear(); + forwardMenuPointer->clear(); + + // Get the history item lists (maximum of 100 items). + QList backItemsList = webEngineHistoryPointer->backItems(100); + QList forwardItemsList = webEngineHistoryPointer->forwardItems(100); + + // Populate the back menu pointer. This must start at the end of the list and move backwards to populate the menu in the correct order. + for (int i = (backItemsList.size() - 1); i >= 0; --i) + { + // Get the WebEngine history item. + const QWebEngineHistoryItem &backHistoryItem = backItemsList.at(i); + + // Get the icon for entry. + QIcon favoriteIcon = tabWidgetPointer->currentPrivacyWebEngineViewPointer->getFavoriteIcon(backHistoryItem.url().toString()); + + // Create a back action. + QAction *backActionPointer = new QAction(); + + // Populate the back action. + backActionPointer->setText(backHistoryItem.title()); + backActionPointer->setIcon(favoriteIcon); + + // Connect the action. + connect(backActionPointer, &QAction::triggered, [this, webEngineHistoryPointer, backHistoryItem] () + { + // Remove the focus from the URL line edit. + urlLineEditPointer->clearFocus(); + + // Go back to the specified page. + webEngineHistoryPointer->goToItem(backHistoryItem); + }); + + // Populate the back menu. + backMenuPointer->addAction(backActionPointer); + } + + // Populate the forward menu pointer. + for (int i = 0; i < forwardItemsList.size(); ++i) + { + // Get the WebEngine history item. + const QWebEngineHistoryItem &forwardHistoryItem = forwardItemsList.at(i); + + // Get the icon for entry. + QIcon favoriteIcon = tabWidgetPointer->currentPrivacyWebEngineViewPointer->getFavoriteIcon(forwardHistoryItem.url().toString()); + + // Create a forward action. + QAction *forwardActionPointer = new QAction(); + + // Populate the forward action. + forwardActionPointer->setText(forwardHistoryItem.title()); + forwardActionPointer->setIcon(favoriteIcon); + + // Connect the action. + connect(forwardActionPointer, &QAction::triggered, [this, webEngineHistoryPointer, forwardHistoryItem] () + { + // Remove the focus from the URL line edit. + urlLineEditPointer->clearFocus(); + + // Go forward to the specified page. + webEngineHistoryPointer->goToItem(forwardHistoryItem); + }); + + // Populate the forward menu. + forwardMenuPointer->addAction(forwardActionPointer); + } + + // Set the status for the actions. + backActionPointer->setEnabled(webEngineHistoryPointer->canGoBack()); + forwardActionPointer->setEnabled(webEngineHistoryPointer->canGoForward()); +} + void BrowserWindow::updateJavaScriptAction(const bool &isEnabled) { // Update the JavaScript status. diff --git a/src/windows/BrowserWindow.h b/src/windows/BrowserWindow.h index 525cb85..199dcbb 100644 --- a/src/windows/BrowserWindow.h +++ b/src/windows/BrowserWindow.h @@ -78,7 +78,7 @@ private Q_SLOTS: void openWithChromium() const; void openWithFirefox() const; void populateBookmarksInAllWindows() const; - void processUrlTextChanges(const QString &newUrlText) const; + void processUrlTextChanges(const QString &newUrlString) const; void refresh() const; void reloadAndBypassCache() const; void restoreUrlText() const; @@ -107,6 +107,7 @@ private Q_SLOTS: void updateDomainSettingsIndicator(const bool status); void updateFindText(const QString &text, const bool findCaseSensitive) const; void updateFindTextResults(const QWebEngineFindTextResult &findTextResult) const; + void updateForwardAndBackActions(QWebEngineHistory *webEngineHistoryPointer); void updateJavaScriptAction(const bool &isEnabled); void updateLocalStorageAction(const bool &isEnabled); void updateRequestsAction(const QVector blockedRequestsVector) const; @@ -121,6 +122,8 @@ private Q_SLOTS: private: // The private variables. KActionCollection *actionCollectionPointer; + QAction *backActionPointer; + QMenu *backMenuPointer; QAction *blockedRequestsActionPointer; QAction *bookmarkedActionPointer; QList *> bookmarkFolderFinalActionList; @@ -154,6 +157,8 @@ private: QAction *findTextLineEditActionPointer; KLineEdit *findTextLineEditPointer; QAction *findTextSpacerActionPointer; + QAction *forwardActionPointer; + QMenu *forwardMenuPointer; KToggleFullScreenAction *fullScreenActionPointer; QAction *hideFindTextActionPointer; QAction *javaScriptActionPointer; -- 2.53.0