]> gitweb.stoutner.com Git - PrivacyBrowserPC.git/commitdiff
Add forward and back buttons.
authorSoren Stoutner <soren@stoutner.com>
Mon, 31 Jan 2022 20:48:58 +0000 (13:48 -0700)
committerSoren Stoutner <soren@stoutner.com>
Mon, 31 Jan 2022 20:48:58 +0000 (13:48 -0700)
src/com.stoutner.privacybrowser.desktop
src/mainview.cpp
src/mainview.h
src/mainview.ui
src/settings.kcfg

index bdb64ed8f2252b09116c46d06eb03bb8ea12eaf8..a0e17f9f1b5735de6b2eb951bd7eabc0190c28f2 100644 (file)
@@ -30,7 +30,7 @@ GenericName=Web Browser
 Categories=Network;WebBrowser;
 
 # Set the icon.
-Icon=privacy_browser.svg
+Icon=privacy-browser.svg
 
 # Set the executable.
 Exec=privacy-browser
index 5c596624d3a130192f6aae13eea3363d07ac2c07..75767bb587d7ad876f49f4a8498f0ed19dac16aa 100644 (file)
@@ -26,6 +26,7 @@
 #include <KLineEdit>
 
 // Qt framework headers.
+#include <QWebEngineHistory>
 #include <QWebEngineView>
 
 MainView::MainView(QWidget *parent) : QWidget(parent)
@@ -37,19 +38,26 @@ MainView::MainView(QWidget *parent) : QWidget(parent)
     mainViewUi.setupUi(this);
 
     // Get handles for the views.
+    backButtonPointer = mainViewUi.backButton;
+    forwardButtonPointer = mainViewUi.forwardButton;
     urlLineEditPointer = mainViewUi.urlLineEdit;
     webEngineViewPointer = mainViewUi.webEngineView;
 
-    // Get a handle for the webpage.
+    // Get handles for the webpage and history.
     QWebEnginePage *webEnginePagePointer = webEngineViewPointer->page();
+    webEngineHistoryPointer = webEnginePagePointer->history();
 
     // Update the webengine view from the URL line edit.
     connect(urlLineEditPointer, SIGNAL(returnKeyPressed(const QString)), this, SLOT(loadUrl(const QString)));
 
     // Update the URL line edit form the webengine view.
-    connect(webEngineViewPointer, SIGNAL(loadStarted()), this, SLOT(updateUrlLineEdit()));
-    connect(webEngineViewPointer, SIGNAL(loadProgress(int)), this, SLOT(updateUrlLineEdit()));
-    connect(webEngineViewPointer, SIGNAL(loadFinished(bool)), this, SLOT(updateUrlLineEdit()));
+    connect(webEngineViewPointer, SIGNAL(loadStarted()), this, SLOT(updateInterface()));
+    connect(webEngineViewPointer, SIGNAL(loadProgress(int)), this, SLOT(updateInterface()));
+    connect(webEngineViewPointer, SIGNAL(loadFinished(bool)), this, SLOT(updateInterface()));
+
+    // Setup the forward and back buttons.
+    connect(backButtonPointer, SIGNAL(clicked()), webEngineViewPointer, SLOT(back()));
+    connect(forwardButtonPointer, SIGNAL(clicked()), webEngineViewPointer, SLOT(forward()));
 
     // Listen for hovered link URLs.
     connect(webEnginePagePointer, SIGNAL(linkHovered(QString)), this, SLOT(pageLinkHovered(QString)));
@@ -79,7 +87,7 @@ void MainView::pageLinkHovered(const QString &linkUrl)
     emit linkHovered(linkUrl);
 }
 
-void MainView::updateUrlLineEdit()
+void MainView::updateInterface()
 {
     // Update the URL line edit if it does not have focus.
     if (!urlLineEditPointer->hasFocus())
@@ -88,6 +96,9 @@ void MainView::updateUrlLineEdit()
         urlLineEditPointer->setUrl(webEngineViewPointer->url().toString());
     }
 
+    backButtonPointer->setEnabled(webEngineHistoryPointer->canGoBack());
+    forwardButtonPointer->setEnabled(webEngineHistoryPointer->canGoForward());
+
     // Reapply the zoom factor.  This is a bug in QWebEngineView that resets the zoom with every load.  Hopefully it will be fixed in Qt6.  <https://bugreports.qt.io/browse/QTBUG-51992>
     webEngineViewPointer->setZoomFactor(Settings::zoomFactor());
 }
index 47a9f270a14c9dc07a1ef3f61cff7dc89a01525e..a28565e9407be77b60d0adeea1a98939684921d7 100644 (file)
@@ -40,11 +40,14 @@ private Q_SLOTS:
     // Define the private slots.
     void loadUrl(const QString &urlFromUser);
     void pageLinkHovered(const QString &linkUrl);
-    void updateUrlLineEdit();
+    void updateInterface();
 
 private:
     // Define the private variables.
+    QPushButton *backButtonPointer;
+    QPushButton *forwardButtonPointer;
     KLineEdit *urlLineEditPointer;
+    QWebEngineHistory *webEngineHistoryPointer;
     QWebEngineView *webEngineViewPointer;
 };
 #endif
index 2174544c90558deb59ef747c9b7f7b920bf466f2..4865f6eacb46f2d6f8b0295f11c192e383ef7453 100644 (file)
         </property>
 
         <layout class="QVBoxLayout">
+            <!-- Set the spacing between items to 0. -->
+            <property name="spacing">
+                <number>0</number>
+            </property>
+
             <!-- Set the margins to 0. -->
             <property name="topMargin">
                 <number>0</number>
             </property>
 
             <item>
-                <widget class="KLineEdit" name="urlLineEdit" />
+                <layout class="QHBoxLayout">
+                    <!-- Set the spacing between items to 0. -->
+                    <property name="spacing">
+                        <number>0</number>
+                    </property>
+
+                    <item>
+                        <widget class="QPushButton" name="backButton">
+                            <property name="icon">
+                                <iconset theme="arrow-left" />
+                            </property>
+
+                            <property name="iconSize">
+                                <size>
+                                    <width>24</width>
+                                    <height>24</height>
+                                </size>
+                            </property>
+
+                            <property name="flat">
+                                <bool>true</bool>
+                            </property>
+                        </widget>
+                    </item>
+
+                    <item>
+                        <widget class="QPushButton" name="forwardButton">
+                            <property name="icon">
+                                <iconset theme="arrow-right" />
+                            </property>
+
+                            <property name="iconSize">
+                                <size>
+                                    <width>24</width>
+                                    <height>24</height>
+                                </size>
+                            </property>
+
+                            <property name="flat">
+                                <bool>true</bool>
+                            </property>
+                        </widget>
+                    </item>
+
+                    <item>
+                        <widget class="KLineEdit" name="urlLineEdit" />
+                    </item>
+                </layout>
             </item>
 
             <item>
index d4c5ffda7456fad517f1b6e0e2a47077f372848e..8497069364958bd50a72616300804c408ba92bfc 100644 (file)
@@ -24,7 +24,8 @@
     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
     xsi:schemaLocation="http://www.kde.org/standards/kcfg/1.0 http://www.kde.org/standards/kcfg/1.0/kcfg.xsd" >
 
-    <kcfgfile name="settings"/>
+    <!-- This is the name of the file located in `~/.config/` where the settings are stored. -->
+    <kcfgfile name="privacybrowser"/>
 
     <group name="General">
         <entry name="homepage" type="Url">