]> gitweb.stoutner.com Git - PrivacyBrowserPC.git/commitdiff
Add view page source controls. https://redmine.stoutner.com/issues/1022
authorSoren Stoutner <soren@stoutner.com>
Sun, 18 Jun 2023 00:22:47 +0000 (17:22 -0700)
committerSoren Stoutner <soren@stoutner.com>
Sun, 18 Jun 2023 00:22:47 +0000 (17:22 -0700)
doc/index.docbook
src/ui.rcs/browserwindowui.rc
src/widgets/TabWidget.cpp
src/widgets/TabWidget.h
src/windows/BrowserWindow.cpp
src/windows/BrowserWindow.h

index fbad58acd7079e1985191a5da70fdda89fcd9451..f8b1136902b1077f8722c74e2fb9edd4c15690ac 100644 (file)
 
             <listitem>
               <para>
-                Reload the website in the current tab bypassing any information in the cache and loading everything from the server.
+                Reload the website in the current tab bypassing any information in the cache and loading everything from the webserver.
+              </para>
+            </listitem>
+          </varlistentry>
+
+          <!-- View Source. -->
+          <varlistentry id="view-source">
+            <term>
+              <menuchoice>
+                <shortcut>
+                  <keycombo action="simul">&Ctrl;<keycap>U</keycap></keycombo>
+                </shortcut>
+                <guimenu>View</guimenu>
+                <guimenuitem>View Source</guimenuitem>
+              </menuchoice>
+            </term>
+
+            <listitem>
+              <para>
+                Toggle between viewing the source and viewing the rendered website.
+              </para>
+            </listitem>
+          </varlistentry>
+
+          <!-- View Source in New Tab. -->
+          <varlistentry id="view-source-in-new-tab">
+            <term>
+              <menuchoice>
+                <shortcut>
+                  <keycombo action="simul">&Ctrl;&Shift;<keycap>U</keycap></keycombo>
+                </shortcut>
+                <guimenu>View</guimenu>
+                <guimenuitem>View Source in New Tab></guimenuitem>
+              </menuchoice>
+            </term>
+
+            <listitem>
+              <para>
+                Open a new tab displaying the source of the current tab, or a new tab displaying the rendered version if the source is already displayed. Note that right-clicking on the background of a rendered website will display a context menu with a "View page source" entry, which performs the first of these actions.
               </para>
             </listitem>
           </varlistentry>
index d296881739b7ea18f9c5775252b7b08cc9e66ebe..a1f54df3acc63380d1b823b9d02c0b0d730b469b 100644 (file)
         <!-- View. -->
         <Menu name="view">
             <Action name="reload_and_bypass_cache" />
+
+            <Separator />
+
+            <Action name="view_source" />
+            <Action name="view_source_in_new_tab" />
         </Menu>
 
         <!-- On-the-fly Settings. -->
index e19244e59568a5df0d4089d5e7f3a7e9f117aab7..2b14018ca6b419a8eb5dec608e66ca83024f43eb 100644 (file)
@@ -171,7 +171,7 @@ void TabWidget::addFirstTab()
     qTabWidgetPointer->currentWidget()->setFocus();
 }
 
-PrivacyWebEngineView* TabWidget::addTab(const bool removeUrlLineEditFocus, const bool backgroundTab)
+PrivacyWebEngineView* TabWidget::addTab(const bool removeUrlLineEditFocus, const bool backgroundTab, const QString urlString)
 {
     // Create a privacy WebEngine view.
     PrivacyWebEngineView *privacyWebEngineViewPointer = new PrivacyWebEngineView();
@@ -454,6 +454,9 @@ PrivacyWebEngineView* TabWidget::addTab(const bool removeUrlLineEditFocus, const
     if (removeUrlLineEditFocus)
         emit clearUrlLineEditFocus();
 
+    if (urlString != nullptr)
+        privacyWebEngineViewPointer->load(QUrl::fromUserInput(urlString));
+
     // Return the privacy WebEngine view pointer.
     return privacyWebEngineViewPointer;
 }
@@ -715,7 +718,7 @@ void TabWidget::loadInitialWebsite()
 void TabWidget::loadUrlFromLineEdit(QString url) const
 {
     // Decide if the text is more likely to be a URL or a search.
-    if (url.startsWith("file://"))  // The text is likely a file URL.
+    if (url.startsWith("file://") || url.startsWith("view-source:"))  // The text is likely a file or view source URL.
     {
         // Load the URL.
         currentPrivacyWebEngineViewPointer->load(QUrl::fromUserInput(url));
index 57082e0ffa4fd5abc40449881f6116065eaaee74..ab21a4cc5ef7b1b53f1bfbfd1fe7eefa5899a3f3 100644 (file)
@@ -94,7 +94,7 @@ signals:
 public Q_SLOTS:
     // The public slots.
     void addCookieToStore(QNetworkCookie cookie, QWebEngineCookieStore *webEngineCookieStorePointer = nullptr) const;
-    PrivacyWebEngineView* addTab(const bool removeUrlLineEditFocus=false, const bool backgroundTab=false);
+    PrivacyWebEngineView* addTab(const bool removeUrlLineEditFocus = false, const bool backgroundTab = false, const QString urlString = nullptr);
     void applyApplicationSettings();
     void applyDomainSettingsAndReload();
     void applyOnTheFlySearchEngine(QAction *searchEngineActionPointer);
index b5d062bb997f1863380c1d628ca6318968313cfb..3ba0e67c4664dfafe921d19d1753a4ab58bcca5b 100644 (file)
@@ -76,6 +76,8 @@ BrowserWindow::BrowserWindow(bool firstWindow) : KXmlGuiWindow()
     QAction *newTabActionPointer = actionCollectionPointer->addAction(QLatin1String("new_tab"));
     QAction *newWindowActionPointer = actionCollectionPointer->addAction(QLatin1String("new_window"));
     QAction *reloadAndBypassCacheActionPointer = actionCollectionPointer->addAction(QLatin1String("reload_and_bypass_cache"));
+    viewSourceActionPointer = actionCollectionPointer->addAction(QLatin1String("view_source"));
+    QAction *viewSourceInNewTabActionPointer = actionCollectionPointer->addAction(QLatin1String("view_source_in_new_tab"));
     userAgentPrivacyBrowserActionPointer = actionCollectionPointer->addAction(QLatin1String("user_agent_privacy_browser"));
     userAgentWebEngineDefaultActionPointer = actionCollectionPointer->addAction(QLatin1String("user_agent_webengine_default"));
     userAgentFirefoxLinuxActionPointer = actionCollectionPointer->addAction(QLatin1String("user_agent_firefox_linux"));
@@ -128,6 +130,7 @@ BrowserWindow::BrowserWindow(bool firstWindow) : KXmlGuiWindow()
     localStorageActionPointer->setCheckable(true);
     domStorageActionPointer->setCheckable(true);
     findCaseSensitiveActionPointer->setCheckable(true);
+    viewSourceActionPointer->setCheckable(true);
     userAgentPrivacyBrowserActionPointer->setCheckable(true);
     userAgentWebEngineDefaultActionPointer->setCheckable(true);
     userAgentFirefoxLinuxActionPointer->setCheckable(true);
@@ -149,6 +152,8 @@ BrowserWindow::BrowserWindow(bool firstWindow) : KXmlGuiWindow()
     UserAgentHelper *userAgentHelperPointer = new UserAgentHelper();
 
     // Set the action text.
+    viewSourceActionPointer->setText(i18nc("View source action", "View Source"));
+    viewSourceInNewTabActionPointer->setText(i18nc("View source in new tab action", "View Source in New Tab"));
     newTabActionPointer->setText(i18nc("New tab action", "New Tab"));
     newWindowActionPointer->setText(i18nc("New window action", "New Window"));
     reloadAndBypassCacheActionPointer->setText(i18nc("Reload and bypass cache action", "Reload and Bypass Cache"));
@@ -179,17 +184,16 @@ BrowserWindow::BrowserWindow(bool firstWindow) : KXmlGuiWindow()
     newTabActionPointer->setIcon(QIcon::fromTheme(QLatin1String("tab-new")));
     newWindowActionPointer->setIcon(QIcon::fromTheme(QLatin1String("window-new")));
     reloadAndBypassCacheActionPointer->setIcon(QIcon::fromTheme(QLatin1String("view-refresh")));
+    viewSourceActionPointer->setIcon(QIcon::fromTheme(QLatin1String("view-choose"), QIcon::fromTheme(QLatin1String("accessories-text-editor"))));
+    viewSourceInNewTabActionPointer->setIcon(QIcon::fromTheme(QLatin1String("view-choose"), QIcon::fromTheme(QLatin1String("accessories-text-editor"))));
     userAgentPrivacyBrowserActionPointer->setIcon(QIcon(":/icons/privacy-mode.svg"));
-    userAgentWebEngineDefaultActionPointer->setIcon(QIcon::fromTheme(QLatin1String("qtlogo"), QIcon::fromTheme(QLatin1String("user-group-properties"),
-                                                                                                               QIcon::fromTheme(QLatin1String("contact-new")))));
+    userAgentWebEngineDefaultActionPointer->setIcon(QIcon::fromTheme(QLatin1String("qtlogo"), QIcon::fromTheme(QLatin1String("user-group-properties"), QIcon::fromTheme(QLatin1String("contact-new")))));
     userAgentFirefoxLinuxActionPointer->setIcon(QIcon::fromTheme(QLatin1String("firefox-esr"), QIcon::fromTheme(QLatin1String("user-group-properties"),
                                                                                                                 QIcon::fromTheme(QLatin1String("contact-new")))));
-    userAgentChromiumLinuxActionPointer->setIcon(QIcon::fromTheme(QLatin1String("chromium"), QIcon::fromTheme(QLatin1String("user-group-properties"),
-                                                                                                              QIcon::fromTheme(QLatin1String("contact-new")))));
+    userAgentChromiumLinuxActionPointer->setIcon(QIcon::fromTheme(QLatin1String("chromium"), QIcon::fromTheme(QLatin1String("user-group-properties"), QIcon::fromTheme(QLatin1String("contact-new")))));
     userAgentFirefoxWindowsActionPointer->setIcon(QIcon::fromTheme(QLatin1String("firefox-esr"), QIcon::fromTheme(QLatin1String("user-group-properties"),
                                                                                                                   QIcon::fromTheme(QLatin1String("contact-new")))));
-    userAgentChromeWindowsActionPointer->setIcon(QIcon::fromTheme(QLatin1String("chromium"), QIcon::fromTheme(QLatin1String("user-group-properties"),
-                                                                                                              QIcon::fromTheme(QLatin1String("contact-new")))));
+    userAgentChromeWindowsActionPointer->setIcon(QIcon::fromTheme(QLatin1String("chromium"), QIcon::fromTheme(QLatin1String("user-group-properties"), QIcon::fromTheme(QLatin1String("contact-new")))));
     userAgentEdgeWindowsActionPointer->setIcon(QIcon::fromTheme(QLatin1String("user-group-properties"), QIcon::fromTheme(QLatin1String("contact-new"))));
     userAgentSafariMacosActionPointer->setIcon(QIcon::fromTheme(QLatin1String("user-group-properties"), QIcon::fromTheme(QLatin1String("contact-new"))));
     userAgentCustomActionPointer->setIcon(QIcon::fromTheme(QLatin1String("user-group-properties"), QIcon::fromTheme(QLatin1String("contact-new"))));
@@ -211,6 +215,8 @@ BrowserWindow::BrowserWindow(bool firstWindow) : KXmlGuiWindow()
     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 ctrlF5KeySequence = QKeySequence(i18nc("The reload and bypass cache key sequence.", "Ctrl+F5"));
+    QKeySequence ctrlUKeySequence = QKeySequence(i18nc("The view source key sequence.", "Ctrl+U"));
+    QKeySequence ctrlShiftUKeySequence = QKeySequence(i18nc("The view source in new tab key sequence.", "Ctrl+Shift+U"));
     QKeySequence ctrlShiftPKeySequence = QKeySequence(i18nc("The print preview key sequence.", "Ctrl+Shift+P"));
     QKeySequence ctrlAltPKeySequence = QKeySequence(i18nc("The Privacy Browser user agent key sequence.", "Ctrl+Alt+P"));
     QKeySequence ctrlAltWKeySequence = QKeySequence(i18nc("The WebEngine Default user agent key sequence.", "Ctrl+Alt+W"));
@@ -236,6 +242,8 @@ BrowserWindow::BrowserWindow(bool firstWindow) : KXmlGuiWindow()
     actionCollectionPointer->setDefaultShortcut(newTabActionPointer, ctrlTKeySequence);
     actionCollectionPointer->setDefaultShortcut(newWindowActionPointer, ctrlNKeySequence);
     actionCollectionPointer->setDefaultShortcut(reloadAndBypassCacheActionPointer, ctrlF5KeySequence);
+    actionCollectionPointer->setDefaultShortcut(viewSourceActionPointer, ctrlUKeySequence);
+    actionCollectionPointer->setDefaultShortcut(viewSourceInNewTabActionPointer, ctrlShiftUKeySequence);
     actionCollectionPointer->setDefaultShortcut(printPreviewActionPointer, ctrlShiftPKeySequence);
     actionCollectionPointer->setDefaultShortcut(userAgentPrivacyBrowserActionPointer, ctrlAltPKeySequence);
     actionCollectionPointer->setDefaultShortcut(userAgentWebEngineDefaultActionPointer, ctrlAltWKeySequence);
@@ -261,6 +269,8 @@ BrowserWindow::BrowserWindow(bool firstWindow) : KXmlGuiWindow()
     connect(newTabActionPointer, SIGNAL(triggered()), tabWidgetPointer, SLOT(addTab()));
     connect(newWindowActionPointer, SIGNAL(triggered()), this, SLOT(newWindow()));
     connect(reloadAndBypassCacheActionPointer, SIGNAL(triggered()), this, SLOT(reloadAndBypassCache()));
+    connect(viewSourceActionPointer, SIGNAL(triggered()), this, SLOT(toggleViewSource()));
+    connect(viewSourceInNewTabActionPointer, SIGNAL(triggered()), this, SLOT(toggleViewSourceInNewTab()));
     connect(zoomFactorActionPointer, SIGNAL(triggered()), this, SLOT(getZoomFactorFromUser()));
     connect(cookiesActionPointer, SIGNAL(triggered()), this, SLOT(showCookiesDialog()));
     connect(domainSettingsActionPointer, SIGNAL(triggered()), this, SLOT(showDomainSettingsDialog()));
@@ -986,6 +996,48 @@ void BrowserWindow::toggleFullScreen()
     }
 }
 
+void BrowserWindow::toggleViewSource() const
+{
+    // Get the current URL.
+    QString url = urlLineEditPointer->text();
+
+    // Toggle the URL.
+    if (url.startsWith(QLatin1String("view-source:")))  // The source is currently being viewed.
+    {
+        // Remove `view-source:` from the URL.
+        url = url.remove(0, 12);
+    }
+    else  // The source is not currently being viewed.
+    {
+        // Prepend `view-source:` from the URL.
+        url = url.prepend(QLatin1String("view-source:"));
+    }
+
+    // Make it so.
+    loadUrlFromLineEdit(url);
+}
+
+void BrowserWindow::toggleViewSourceInNewTab() const
+{
+    // Get the current URL.
+    QString url = urlLineEditPointer->text();
+
+    // Toggle the URL.
+    if (url.startsWith(QLatin1String("view-source:")))  // The source is currently being viewed.
+    {
+        // Remove `view-source:` from the URL.
+        url = url.remove(0, 12);
+    }
+    else  // The source is not currently being viewed.
+    {
+        // Prepend `view-source:` from the URL.
+        url = url.prepend(QLatin1String("view-source:"));
+    }
+
+    // Add the new tab.  `true` removes the URL line edit focus, `false` does not open a background tab.
+    tabWidgetPointer->addTab(true, false, url);
+}
+
 void BrowserWindow::updateCookiesAction(const int numberOfCookies) const
 {
     // Update the action text.
@@ -1326,12 +1378,15 @@ void BrowserWindow::updateSearchEngineLabel(const QString &searchEngineString) c
 
 void BrowserWindow::updateUrlLineEdit(const QUrl &newUrl)
 {
+    // Get the new URL string.
+    QString newUrlString = newUrl.toString();
+
+    // Update the view source checkbox.
+    viewSourceActionPointer->setChecked(newUrlString.startsWith(QLatin1String("view-source:")));
+
     // Update the URL line edit if it does not have focus.
     if (!urlLineEditPointer->hasFocus())
     {
-        // Get the new URL string.
-        QString newUrlString = newUrl.toString();
-
         // Update the URL line edit.
         urlLineEditPointer->setText(newUrlString);
 
index 44486d945c2e2c0e941959afcb5f6f7aeee695fc..99fd146001fb69b83609b0968e231605725101de 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright © 2022-2023 Soren Stoutner <soren@stoutner.com>.
+ * Copyright 2022-2023 Soren Stoutner <soren@stoutner.com>.
  *
  * This file is part of Privacy Browser PC <https://www.stoutner.com/privacy-browser-pc>.
  *
@@ -76,6 +76,8 @@ private Q_SLOTS:
     void toggleJavaScript() const;
     void toggleLocalStorage() const;
     void toggleFullScreen();
+    void toggleViewSource() const;
+    void toggleViewSourceInNewTab() const;
     void updateCookiesAction(const int numberOfCookies) const;
     void updateDomStorageAction(const bool &isEnabled) const;
     void updateDomainSettingsIndicator(const bool status);
@@ -141,6 +143,7 @@ private:
     QAction *userAgentCustomActionPointer;
     KLineEdit *urlLineEditPointer;
     KToolBar *urlToolBarPointer;
+    QAction *viewSourceActionPointer;
     QAction *zoomFactorActionPointer;
 };
 #endif