aboutData.setCopyrightStatement(i18n("Copyright © 2016-2017,2021-2022 Soren Stoutner <soren@stoutner.com>"));
aboutData.setDesktopFileName(QStringLiteral("com.stoutner.privacybrowser"));
aboutData.setHomepage(QStringLiteral("https://www.stoutner.com/privacy-browser-pc/"));
- aboutData.setLicenseTextFile(":/licenses/GPLv3+.txt");
+ //aboutData.setLicense(KAboutLicense::GPL_V3, KAboutLicense::OrLaterVersions); <https://redmine.stoutner.com/issues/822>
+ aboutData.setLicenseTextFile(QStringLiteral(":/licenses/GPLv3+.txt"));
aboutData.setOrganizationDomain("stoutner.com");
aboutData.setShortDescription(i18n("A web browser that respects your privacy."));
along with Privacy Browser PC. If not, see <http://www.gnu.org/licenses/>. -->
<!-- Documentation at <https://techbase.kde.org/Development/Architecture/KDE4/XMLGUI_Technology>. -->
+<!-- Better documentation at <https://invent.kde.org/frameworks/kxmlgui/-/blob/master/src/kxmlgui.xsd>. -->
<gui
name="privacybrowser"
version="1"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.kde.org/standards/kxmlgui/1.0 http://www.kde.org/standards/kxmlgui/1.0/kxmlgui.xsd" >
+ <!-- The menu bar. -->
<MenuBar>
<Menu name="on_the_fly_settings"> <text>On-The-Fly Settings</text>
<Menu name="user_agent"> <text>User Agent</text>
</Menu>
</MenuBar>
- <ToolBar name="mainToolBar" noMerge="1">
- <text>Main Toolbar</text>
+ <!-- The main toolbar is removed. -->
+ <ToolBar name="mainToolBar" deleted="true" />
+
+ <!-- The navigation toolbar. -->
+ <ToolBar name="navigation_toolbar" iconText="icononly"> <text>Navigation Toolbar</text>
+ <Action name="back" />
+ <Action name="forward" />
+ <Action name="refresh" />
+ <Action name="home" />
</ToolBar>
+
+ <!-- The URL toolbar. -->
+ <ToolBar name="url_toolbar" iconText="icononly"> <text>URL Toolbar</text> </ToolBar>
</gui>
webEngineProfilePointer = webEnginePagePointer->profile();
webEngineSettingsPointer = webEngineViewPointer->settings();
- // Update the webengine view from the URL line edit.
- connect(urlLineEditPointer, SIGNAL(returnKeyPressed(const QString)), this, SLOT(loadUrlFromTextBox(const QString)));
+ // Update the webengine view from the URL line edit. TODO. Remove.
+ connect(urlLineEditPointer, SIGNAL(returnKeyPressed(const QString)), this, SLOT(loadUrlFromLineEdit(const QString)));
// Update the URL line edit from the webengine view.
connect(webEngineViewPointer, SIGNAL(loadStarted()), this, SLOT(updateInterface()));
connect(webEngineViewPointer, SIGNAL(loadProgress(const int)), this, SLOT(updateInterface()));
connect(webEngineViewPointer, SIGNAL(loadFinished(const bool)), this, SLOT(updateInterface()));
- // Setup the URL bar buttons.
+ // Setup the URL bar buttons. TODO. Remove.
connect(backButtonPointer, SIGNAL(clicked()), webEngineViewPointer, SLOT(back()));
connect(forwardButtonPointer, SIGNAL(clicked()), webEngineViewPointer, SLOT(forward()));
connect(refreshButtonPointer, SIGNAL(clicked()), webEngineViewPointer, SLOT(reload()));
- connect(homeButtonPointer, SIGNAL(clicked()), this, SLOT(goHome()));
+ connect(homeButtonPointer, SIGNAL(clicked()), this, SLOT(home()));
connect(javaScriptButtonPointer, SIGNAL(clicked()), this, SLOT(toggleJavaScript()));
connect(domainSettingsButtonPointer, SIGNAL(clicked()), this, SLOT(openDomainSettings()));
- // Get the URL line edit palettes.
+ // Get the URL line edit palettes. TODO. Remove.
noDomainSettingsPalette = urlLineEditPointer->palette();
domainSettingsPalette = urlLineEditPointer->palette();
- // Modify the domain settings palette.
+ // Modify the domain settings palette. TODO. Remove.
domainSettingsPalette.setColor(QPalette::Base, QColor("#C8E6C9"));
// Instantiate the mouse event pointer.
webEngineViewPointer->setZoomFactor(Settings::zoomFactor());
// Apply the domain settings palette to the URL line edit.
- urlLineEditPointer->setPalette(domainSettingsPalette);
+ urlLineEditPointer->setPalette(domainSettingsPalette); // TODO. Remove.
+ emit updateDomainSettingsIndicator(true);
}
else // The hostname does not have domain settings.
{
webEngineViewPointer->setZoomFactor(Settings::zoomFactor());
// Apply the no domain settings palette to the URL line edit.
- urlLineEditPointer->setPalette(noDomainSettingsPalette);
+ urlLineEditPointer->setPalette(noDomainSettingsPalette); // TODO. Remove.
+ emit updateDomainSettingsIndicator(false);
}
// Update the JavaScript button.
webEngineViewPointer->setZoomFactor(zoomFactor);
}
-void BrowserView::goHome() const
+void BrowserView::back() const
+{
+ // Go back.
+ webEngineViewPointer->back();
+}
+
+void BrowserView::forward() const
+{
+ // Go forward.
+ webEngineViewPointer->forward();
+}
+
+void BrowserView::home() const
{
// Load the homepage.
- webEngineViewPointer->setUrl(QUrl::fromUserInput(Settings::homepage()));
+ webEngineViewPointer->load(QUrl::fromUserInput(Settings::homepage()));
}
void BrowserView::loadInitialWebsite()
if (argumentsStringList.size() > 1)
{
// Load the URL from the arguments list.
- webEngineViewPointer->setUrl(QUrl::fromUserInput(argumentsStringList.at(1)));
+ webEngineViewPointer->load(QUrl::fromUserInput(argumentsStringList.at(1)));
}
else
{
// Load the homepage.
- goHome();
+ home();
}
}
-void BrowserView::loadUrlFromTextBox(QString urlFromUser) const
+void BrowserView::loadUrlFromLineEdit(QString url) const
{
- // Remove the focus from the URL line edit.
+ // Remove the focus from the URL line edit. TODO. Remove.
urlLineEditPointer->clearFocus();
// Decide if the text is more likely to be a URL or a search.
- if (urlFromUser.contains(".")) // The text is likely a URL.
+ if (url.contains(".")) // The text is likely a URL.
{
// Check if the URL does not start with a valid protocol.
- if (!urlFromUser.startsWith("http") && !urlFromUser.startsWith("file://"))
+ if (!url.startsWith("http") && !url.startsWith("file://"))
{
// Add `https://` to the beginning of the URL.
- urlFromUser = "https://" + urlFromUser;
+ url = "https://" + url;
}
// Load the URL.
- webEngineViewPointer->setUrl(QUrl::fromUserInput(urlFromUser));
+ webEngineViewPointer->load(QUrl::fromUserInput(url));
}
else // The text is likely a search.
{
// Load the search.
- webEngineViewPointer->setUrl(QUrl::fromUserInput(searchEngineUrl + urlFromUser));
+ webEngineViewPointer->load(QUrl::fromUserInput(searchEngineUrl + url));
}
}
emit linkHovered(linkUrl);
}
+void BrowserView::refresh() const
+{
+ // Reload the website.
+ webEngineViewPointer->reload();
+}
+
void BrowserView::toggleJavaScript() const
{
// Toggle JavaScript.
void BrowserView::updateInterface() const
{
- // Update the URL line edit if it does not have focus.
+ // Update the URL line edit if it does not have focus. TODO. Remove block.
if (!urlLineEditPointer->hasFocus())
{
// Update the URL line edit.
urlLineEditPointer->setText(webEngineViewPointer->url().toString());
}
+ // Update the URL line edit.
+ emit updateUrlLineEdit(webEngineViewPointer->url().toString());
+
// Update the status of the forward and back buttons.
- backButtonPointer->setEnabled(webEngineHistoryPointer->canGoBack());
- forwardButtonPointer->setEnabled(webEngineHistoryPointer->canGoForward());
+ backButtonPointer->setEnabled(webEngineHistoryPointer->canGoBack()); // TODO Remove.
+ emit updateBackAction(webEngineHistoryPointer->canGoBack());
+ forwardButtonPointer->setEnabled(webEngineHistoryPointer->canGoForward()); // TODO Remove.
+ emit updateForwardAction(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());
void linkHovered(const QString &linkUrl) const;
void userAgentUpdated(const QString &userAgent) const;
void searchEngineUpdated(const QString &searchEngine) const;
+ void updateBackAction(const bool &isEnabled) const;
+ void updateDomainSettingsIndicator(const bool status) const;
+ void updateForwardAction(const bool &isEnabled) const;
+ void updateUrlLineEdit(const QString &newUrl) const;
void zoomFactorUpdated(const double &zoomFactor) const;
public Q_SLOTS:
void applyDomainSettingsWithoutReloading(const QString &hostname) const;
void applyOnTheFlySearchEngine(QAction *searchEngineActionPointer);
void applyOnTheFlyUserAgent(QAction *userAgentActionPointer) const;
+ void back() const;
+ void forward() const;
+ void home() const;
+ void loadUrlFromLineEdit(QString url) const;
+ void refresh() const;
private Q_SLOTS:
// The private slots.
- void goHome() const;
- void loadUrlFromTextBox(QString urlFromUser) const;
void pageLinkHovered(const QString &linkUrl) const;
void toggleJavaScript() const;
void openDomainSettings() const;
private:
// The private variables.
QPushButton *backButtonPointer;
- QPalette domainSettingsPalette;
+ QPalette domainSettingsPalette; // TODO. Remove.
QPushButton *forwardButtonPointer;
QPushButton *javaScriptButtonPointer;
- QPalette noDomainSettingsPalette;
+ QPalette noDomainSettingsPalette; // TODO. Remove.
QString searchEngineUrl;
KLineEdit *urlLineEditPointer;
QWebEngineHistory *webEngineHistoryPointer;
// KDE Frameworks headers.
#include <KActionCollection>
+#include <KToolBar>
// Qt toolkit headers.
#include <QInputDialog>
searchEngineBingActionPointer = actionCollectionPointer->addAction(QStringLiteral("search_engine_bing"));
searchEngineYahooActionPointer = actionCollectionPointer->addAction(QStringLiteral("search_engine_yahoo"));
searchEngineCustomActionPointer = actionCollectionPointer->addAction(QStringLiteral("search_engine_custom"));
+ backActionPointer = actionCollectionPointer->addAction(QStringLiteral("back"));
+ forwardActionPointer = actionCollectionPointer->addAction(QStringLiteral("forward"));
+ refreshActionPointer = actionCollectionPointer->addAction(QStringLiteral("refresh"));
+ homeActionPointer = actionCollectionPointer->addAction(QStringLiteral("home"));
// Create the action groups
QActionGroup *userAgentActionGroupPointer = new QActionGroup(this);
userAgentChromeWindowsActionPointer->setText(UserAgentHelper::CHROME_WINDOWS_TRANSLATED);
userAgentEdgeWindowsActionPointer->setText(UserAgentHelper::EDGE_WINDOWS_TRANSLATED);
userAgentSafariMacosActionPointer->setText(UserAgentHelper::SAFARI_MACOS_TRANSLATED);
- searchEngineMojeekActionPointer->setText(i18nc("@action", "Mojeek"));
- searchEngineMonoclesActionPointer->setText(i18nc("@action", "Monocles"));
- searchEngineMetagerActionPointer->setText(i18nc("@action", "MetaGer"));
- searchEngineGoogleActionPointer->setText(i18nc("@action", "Google"));
- searchEngineBingActionPointer->setText(i18nc("@action", "Bing"));
- searchEngineYahooActionPointer->setText(i18nc("@action", "Yahoo"));
+ searchEngineMojeekActionPointer->setText(i18nc("Search engine", "Mojeek"));
+ searchEngineMonoclesActionPointer->setText(i18nc("Search engine", "Monocles"));
+ searchEngineMetagerActionPointer->setText(i18nc("Search engine", "MetaGer"));
+ searchEngineGoogleActionPointer->setText(i18nc("Search engine", "Google"));
+ searchEngineBingActionPointer->setText(i18nc("Search engine", "Bing"));
+ searchEngineYahooActionPointer->setText(i18nc("Search engine", "Yahoo"));
+ backActionPointer->setText(i18nc("Back button", "Back"));
+ forwardActionPointer->setText(i18nc("Forward button", "Forward"));
+ refreshActionPointer->setText(i18nc("Refresh button", "Refresh"));
+ homeActionPointer->setText(i18nc("Home button", "Home"));
+
+ // Set the action icons.
+ backActionPointer->setIcon(QIcon::fromTheme(QStringLiteral("arrow-left")));
+ forwardActionPointer->setIcon(QIcon::fromTheme(QStringLiteral("arrow-right")));
+ refreshActionPointer->setIcon(QIcon::fromTheme(QStringLiteral("view-refresh")));
+ homeActionPointer->setIcon(QIcon::fromTheme(QStringLiteral("home")));
// Update the on-the-fly menus.
connect(browserViewPointer, SIGNAL(userAgentUpdated(QString)), this, SLOT(updateOnTheFlyUserAgent(QString)));
// Display dialogs.
connect(zoomFactorActionPointer, SIGNAL(triggered()), this, SLOT(getZoomFactorFromUser()));
- // Update the status bar with the URL when a link is hovered.
- connect(browserViewPointer, SIGNAL(linkHovered(QString)), this, SLOT(updateStatusBar(QString)));
+ // Connect the URL toolbar actions.
+ connect(backActionPointer, SIGNAL(triggered()), this, SLOT(back()));
+ connect(forwardActionPointer, SIGNAL(triggered()), this, SLOT(forward()));
+ connect(refreshActionPointer, SIGNAL(triggered()), this, SLOT(refresh()));
+ connect(homeActionPointer, SIGNAL(triggered()), this, SLOT(home()));
+
+ // Update the URL toolbar actions.
+ connect(browserViewPointer, SIGNAL(updateBackAction(bool)), backActionPointer, SLOT(setEnabled(bool)));
+ connect(browserViewPointer, SIGNAL(updateForwardAction(bool)), forwardActionPointer, SLOT(setEnabled(bool)));
// Setup the GUI based on the browser_ui.rc file.
setupGUI(StandardWindowOption::Default, ("browser_ui.rc"));
- // Load the initial webstie.
+ // Get a handle for the URL toolbar.
+ KToolBar *urlToolBarPointer = toolBar(QStringLiteral("url_toolbar"));
+
+ // Create a URL line edit.
+ urlLineEditPointer = new KLineEdit();
+
+ // Add the URL line edit to the URL toolbar.
+ urlToolBarPointer->addWidget(urlLineEditPointer);
+
+ // Load a new URL from the URL line edit.
+ connect(urlLineEditPointer, SIGNAL(returnKeyPressed(const QString)), this, SLOT(loadUrlFromLineEdit(const QString)));
+
+ // Update the URL line edit on page loads.
+ connect(browserViewPointer, SIGNAL(updateUrlLineEdit(QString)), this, SLOT(updateUrlLineEdit(QString)));
+
+ // Get a handle for the status bar.
+ QStatusBar *statusBarPointer = statusBar();
+
+ // Update the status bar with the URL when a link is hovered.
+ connect(browserViewPointer, SIGNAL(linkHovered(QString)), statusBarPointer, SLOT(showMessage(QString)));
+
+ // Get the URL line edit palettes.
+ noDomainSettingsPalette = urlLineEditPointer->palette();
+ domainSettingsPalette = urlLineEditPointer->palette();
+
+ // Modify the domain settings palette.
+ domainSettingsPalette.setColor(QPalette::Base, QColor("#C8E6C9"));
+
+ // Update the applied palette.
+ connect(browserViewPointer, SIGNAL(updateDomainSettingsIndicator(bool)), this, SLOT(updateDomainSettingsIndicator(bool)));
+
+ // Load the initial website.
browserViewPointer->loadInitialWebsite();
}
+void BrowserWindow::back() const
+{
+ // Remove the focus from the URL line edit.
+ urlLineEditPointer->clearFocus();
+
+ // Go back.
+ browserViewPointer->back();
+}
+
void BrowserWindow::fileNew() const
{
// Display a new instance of Privacy Browser.
(new BrowserWindow)->show();
}
+void BrowserWindow::forward() const
+{
+ // Remove the focus from the URL line edit.
+ urlLineEditPointer->clearFocus();
+
+ // Go forward.
+ browserViewPointer->forward();
+}
+
void BrowserWindow::getZoomFactorFromUser()
{
// Create an OK flag.
}
}
+void BrowserWindow::home() const
+{
+ // Remove the focus from the URL line edit.
+ urlLineEditPointer->clearFocus();
+
+ // Go home.
+ browserViewPointer->home();
+}
+
+void BrowserWindow::loadUrlFromLineEdit(const QString &url) const
+{
+ // Remove the focus from the URL line edit.
+ urlLineEditPointer->clearFocus();
+
+ // Load the URL.
+ browserViewPointer->loadUrlFromLineEdit(url);
+}
+
+void BrowserWindow::refresh() const
+{
+ // Remove the focus from the URL line edit.
+ urlLineEditPointer->clearFocus();
+
+ // Refresh the web page.
+ browserViewPointer->refresh();
+}
+
void BrowserWindow::settingsConfigure()
{
// Check to make sure the dialog box isn't already displayed.
// Make it so.
configDialogPointer->show();
- // TODO. KConfigDialog does not respect expanding size policies.
- configDialogPointer->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
- privacySettingsWidgetPointer->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
- generalSettingsWidgetPointer->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
- configDialogPointer->adjustSize();
+ // TODO. KConfigDialog does not respect expanding size policies. <https://redmine.stoutner.com/issues/823>
+ //configDialogPointer->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
+ //privacySettingsWidgetPointer->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
+ //generalSettingsWidgetPointer->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
+ //configDialogPointer->adjustSize();
// Expand the config dialog.
configDialogPointer->resize(1000, 500);
}
}
+void BrowserWindow::updateDomainSettingsIndicator(const bool status) const
+{
+ // Set the domain palette according to the status.
+ if (status) urlLineEditPointer->setPalette(domainSettingsPalette);
+ else urlLineEditPointer->setPalette(noDomainSettingsPalette);
+}
+
void BrowserWindow::updateOnTheFlySearchEngine(const QString &searchEngine) const
{
// Initialize the custom search engine flag.
customSearchEngine = true;
}
-
// Format the custom search engine.
if (customSearchEngine)
{
searchEngineLabelPointer->setText(SearchEngineHelper::getSearchUrl(searchEngineString));
}
-void BrowserWindow::updateStatusBar(const QString &statusBarMessage) const
+void BrowserWindow::updateUrlLineEdit(const QString &newUrl) const
{
- // Display the status bar message.
- statusBar()->showMessage(statusBarMessage);
+ // Update the URL line edit if it does not have focus.
+ if (!urlLineEditPointer->hasFocus())
+ {
+ // Update the URL line edit.
+ urlLineEditPointer->setText(newUrl);
+ }
}
void BrowserWindow::updateUserAgentLabel(const QString &userAgentDatabaseName) const
private Q_SLOTS:
// The private slots.
+ void back() const;
void fileNew() const;
+ void forward() const;
void getZoomFactorFromUser();
+ void home() const;
+ void loadUrlFromLineEdit(const QString &url) const;
+ void refresh() const;
void settingsConfigure();
+ void updateDomainSettingsIndicator(const bool status) const;
void updateOnTheFlySearchEngine(const QString &searchEngine) const;
void updateOnTheFlyUserAgent(const QString &userAgent) const;
void updateOnTheFlyZoomFactor(const double &zoomFactor);
void updateSearchEngineLabel(const QString &searchEngineString) const;
- void updateStatusBar(const QString &statusBarMessage) const;
+ void updateUrlLineEdit(const QString &newUrl) const;
void updateUserAgentLabel(const QString &userAgentDatabaseName) const;
private:
// The private variables.
+ QAction *backActionPointer;
BrowserView *browserViewPointer;
+ KConfigDialog *configDialogPointer;
+ QPalette domainSettingsPalette;
double currentZoomFactor;
+ QAction *forwardActionPointer;
+ QAction *homeActionPointer;
+ QPalette noDomainSettingsPalette;
QLabel *searchEngineLabelPointer;
QAction *searchEngineMojeekActionPointer;
QAction *searchEngineMonoclesActionPointer;
QAction *searchEngineBingActionPointer;
QAction *searchEngineYahooActionPointer;
QAction *searchEngineCustomActionPointer;
+ QAction *refreshActionPointer;
QLabel *userAgentLabelPointer;
QAction *userAgentPrivacyBrowserActionPointer;
QAction *userAgentFirefoxLinuxActionPointer;
QAction *userAgentEdgeWindowsActionPointer;
QAction *userAgentSafariMacosActionPointer;
QAction *userAgentCustomActionPointer;
+ KLineEdit *urlLineEditPointer;
QAction *zoomFactorActionPointer;
- KConfigDialog *configDialogPointer;
};
#endif