2 * Copyright © 2022 Soren Stoutner <soren@stoutner.com>.
4 * This file is part of Privacy Browser PC <https://www.stoutner.com/privacy-browser-pc>.
6 * Privacy Browser PC is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
11 * Privacy Browser PC is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with Privacy Browser PC. If not, see <http://www.gnu.org/licenses/>.
20 // Application headers.
21 #include "BrowserWindow.h"
23 #include "ui_SettingsPrivacy.h"
24 #include "ui_SettingsGeneral.h"
25 #include "dialogs/CookiesDialog.h"
26 #include "dialogs/DomainSettingsDialog.h"
27 #include "helpers/SearchEngineHelper.h"
28 #include "helpers/UserAgentHelper.h"
30 // KDE Frameworks headers.
31 #include <KActionCollection>
34 // Qt toolkit headers.
35 #include <QInputDialog>
36 #include <QNetworkCookie>
39 BrowserWindow::BrowserWindow() : KXmlGuiWindow()
41 // Instantiate the main view pointer.
42 browserViewPointer = new BrowserView(this);
44 // Set the main view as the central widget.
45 setCentralWidget(browserViewPointer);
47 // Get a handle for the action collection.
48 KActionCollection *actionCollectionPointer = this->actionCollection();
50 // Add the standard actions.
51 QAction *backActionPointer = KStandardAction::back(this, SLOT(back()), actionCollectionPointer);
52 QAction *forwardActionPointer = KStandardAction::forward(this, SLOT(forward()), actionCollectionPointer);
53 KStandardAction::home(this, SLOT(home()), actionCollectionPointer);
54 KStandardAction::openNew(this, SLOT(fileNew()), actionCollectionPointer);
55 KStandardAction::quit(qApp, SLOT(closeAllWindows()), actionCollectionPointer);
56 KStandardAction::preferences(this, SLOT(settingsConfigure()), actionCollectionPointer);
57 KStandardAction::redisplay(this, SLOT(refresh()), actionCollectionPointer);
59 // Add the custom actions.
60 userAgentPrivacyBrowserActionPointer = actionCollectionPointer->addAction(QStringLiteral("user_agent_privacy_browser"));
61 userAgentWebEngineDefaultActionPointer = actionCollectionPointer->addAction(QStringLiteral("user_agent_webengine_default"));
62 userAgentFirefoxLinuxActionPointer = actionCollectionPointer->addAction(QStringLiteral("user_agent_firefox_linux"));
63 userAgentChromiumLinuxActionPointer = actionCollectionPointer->addAction(QStringLiteral("user_agent_chromium_linux"));
64 userAgentFirefoxWindowsActionPointer = actionCollectionPointer->addAction(QStringLiteral("user_agent_firefox_windows"));
65 userAgentChromeWindowsActionPointer = actionCollectionPointer->addAction(QStringLiteral("user_agent_chrome_windows"));
66 userAgentEdgeWindowsActionPointer = actionCollectionPointer->addAction(QStringLiteral("user_agent_edge_windows"));
67 userAgentSafariMacosActionPointer = actionCollectionPointer->addAction(QStringLiteral("user_agent_safari_macos"));
68 userAgentCustomActionPointer = actionCollectionPointer->addAction(QStringLiteral("user_agent_custom"));
69 zoomFactorActionPointer = actionCollectionPointer->addAction(QStringLiteral("zoom_factor"));
70 searchEngineMojeekActionPointer = actionCollectionPointer->addAction(QStringLiteral("search_engine_mojeek"));
71 searchEngineMonoclesActionPointer = actionCollectionPointer->addAction(QStringLiteral("search_engine_monocles"));
72 searchEngineMetagerActionPointer = actionCollectionPointer->addAction(QStringLiteral("search_engine_metager"));
73 searchEngineGoogleActionPointer = actionCollectionPointer->addAction(QStringLiteral("search_engine_google"));
74 searchEngineBingActionPointer = actionCollectionPointer->addAction(QStringLiteral("search_engine_bing"));
75 searchEngineYahooActionPointer = actionCollectionPointer->addAction(QStringLiteral("search_engine_yahoo"));
76 searchEngineCustomActionPointer = actionCollectionPointer->addAction(QStringLiteral("search_engine_custom"));
77 QAction *domainSettingsActionPointer = actionCollectionPointer->addAction(QStringLiteral("domain_settings"));
78 QAction *cookiesActionPointer = actionCollectionPointer->addAction(QStringLiteral("cookies"));
79 javaScriptActionPointer = actionCollectionPointer->addAction(QStringLiteral("javascript"));
80 localStorageActionPointer = actionCollectionPointer->addAction(QStringLiteral("local_storage"));
82 // Create the action groups
83 QActionGroup *userAgentActionGroupPointer = new QActionGroup(this);
84 QActionGroup *searchEngineActionGroupPointer = new QActionGroup(this);
86 // Add the actions to the groups.
87 userAgentActionGroupPointer->addAction(userAgentPrivacyBrowserActionPointer);
88 userAgentActionGroupPointer->addAction(userAgentWebEngineDefaultActionPointer);
89 userAgentActionGroupPointer->addAction(userAgentFirefoxLinuxActionPointer);
90 userAgentActionGroupPointer->addAction(userAgentChromiumLinuxActionPointer);
91 userAgentActionGroupPointer->addAction(userAgentFirefoxWindowsActionPointer);
92 userAgentActionGroupPointer->addAction(userAgentChromeWindowsActionPointer);
93 userAgentActionGroupPointer->addAction(userAgentEdgeWindowsActionPointer);
94 userAgentActionGroupPointer->addAction(userAgentSafariMacosActionPointer);
95 userAgentActionGroupPointer->addAction(userAgentCustomActionPointer);
96 searchEngineActionGroupPointer->addAction(searchEngineMojeekActionPointer);
97 searchEngineActionGroupPointer->addAction(searchEngineMonoclesActionPointer);
98 searchEngineActionGroupPointer->addAction(searchEngineMetagerActionPointer);
99 searchEngineActionGroupPointer->addAction(searchEngineGoogleActionPointer);
100 searchEngineActionGroupPointer->addAction(searchEngineBingActionPointer);
101 searchEngineActionGroupPointer->addAction(searchEngineYahooActionPointer);
102 searchEngineActionGroupPointer->addAction(searchEngineCustomActionPointer);
104 // Set some actions to be checkable.
105 userAgentPrivacyBrowserActionPointer->setCheckable(true);
106 userAgentWebEngineDefaultActionPointer->setCheckable(true);
107 userAgentFirefoxLinuxActionPointer->setCheckable(true);
108 userAgentChromiumLinuxActionPointer->setCheckable(true);
109 userAgentFirefoxWindowsActionPointer->setCheckable(true);
110 userAgentChromeWindowsActionPointer->setCheckable(true);
111 userAgentEdgeWindowsActionPointer->setCheckable(true);
112 userAgentSafariMacosActionPointer->setCheckable(true);
113 userAgentCustomActionPointer->setCheckable(true);
114 searchEngineMojeekActionPointer->setCheckable(true);
115 searchEngineMonoclesActionPointer->setCheckable(true);
116 searchEngineMetagerActionPointer->setCheckable(true);
117 searchEngineGoogleActionPointer->setCheckable(true);
118 searchEngineBingActionPointer->setCheckable(true);
119 searchEngineYahooActionPointer->setCheckable(true);
120 searchEngineCustomActionPointer->setCheckable(true);
122 // Set the non-mutable action text.
123 userAgentPrivacyBrowserActionPointer->setText(UserAgentHelper::PRIVACY_BROWSER_TRANSLATED);
124 userAgentWebEngineDefaultActionPointer->setText(UserAgentHelper::WEB_ENGINE_DEFAULT_TRANSLATED);
125 userAgentFirefoxLinuxActionPointer->setText(UserAgentHelper::FIREFOX_LINUX_TRANSLATED);
126 userAgentChromiumLinuxActionPointer->setText(UserAgentHelper::CHROMIUM_LINUX_TRANSLATED);
127 userAgentFirefoxWindowsActionPointer->setText(UserAgentHelper::FIREFOX_WINDOWS_TRANSLATED);
128 userAgentChromeWindowsActionPointer->setText(UserAgentHelper::CHROME_WINDOWS_TRANSLATED);
129 userAgentEdgeWindowsActionPointer->setText(UserAgentHelper::EDGE_WINDOWS_TRANSLATED);
130 userAgentSafariMacosActionPointer->setText(UserAgentHelper::SAFARI_MACOS_TRANSLATED);
131 searchEngineMojeekActionPointer->setText(i18nc("Search engine", "Mojeek"));
132 searchEngineMonoclesActionPointer->setText(i18nc("Search engine", "Monocles"));
133 searchEngineMetagerActionPointer->setText(i18nc("Search engine", "MetaGer"));
134 searchEngineGoogleActionPointer->setText(i18nc("Search engine", "Google"));
135 searchEngineBingActionPointer->setText(i18nc("Search engine", "Bing"));
136 searchEngineYahooActionPointer->setText(i18nc("Search engine", "Yahoo"));
137 domainSettingsActionPointer->setText(i18nc("Domain Settings action", "Domain Settings"));
138 cookiesActionPointer->setText(i18nc("Cookies action", "Cookies"));
139 javaScriptActionPointer->setText(i18nc("JavaScript action", "JavaScript"));
140 localStorageActionPointer->setText(i18nc("Local Storage action", "Local Storage"));
142 // Set the action icons.
143 userAgentPrivacyBrowserActionPointer->setIcon(QIcon(":/icons/privacy-mode"));
144 userAgentWebEngineDefaultActionPointer->setIcon(QIcon::fromTheme(QStringLiteral("user-group-properties")));
145 userAgentFirefoxLinuxActionPointer->setIcon(QIcon::fromTheme(QStringLiteral("firefox-esr")));
146 userAgentChromiumLinuxActionPointer->setIcon(QIcon::fromTheme(QStringLiteral("chromium")));
147 userAgentFirefoxWindowsActionPointer->setIcon(QIcon::fromTheme(QStringLiteral("firefox-esr")));
148 userAgentChromeWindowsActionPointer->setIcon(QIcon::fromTheme(QStringLiteral("chromium")));
149 userAgentEdgeWindowsActionPointer->setIcon(QIcon::fromTheme(QStringLiteral("user-group-properties")));
150 userAgentSafariMacosActionPointer->setIcon(QIcon::fromTheme(QStringLiteral("user-group-properties")));
151 userAgentCustomActionPointer->setIcon(QIcon::fromTheme(QStringLiteral("user-group-properties")));
152 searchEngineMojeekActionPointer->setIcon(QIcon::fromTheme(QStringLiteral("search")));
153 searchEngineMonoclesActionPointer->setIcon(QIcon::fromTheme(QStringLiteral("search")));
154 searchEngineMetagerActionPointer->setIcon(QIcon::fromTheme(QStringLiteral("search")));
155 searchEngineGoogleActionPointer->setIcon(QIcon::fromTheme(QStringLiteral("im-google")));
156 searchEngineBingActionPointer->setIcon(QIcon::fromTheme(QStringLiteral("search")));
157 searchEngineYahooActionPointer->setIcon(QIcon::fromTheme(QStringLiteral("im-yahoo")));
158 searchEngineCustomActionPointer->setIcon(QIcon::fromTheme(QStringLiteral("search")));
159 zoomFactorActionPointer->setIcon(QIcon::fromTheme(QStringLiteral("zoom")));
160 domainSettingsActionPointer->setIcon(QIcon::fromTheme(QStringLiteral("settings-configure")));
161 cookiesActionPointer->setIcon(QIcon::fromTheme(QStringLiteral("preferences-web-browser-cookies")));
163 // Update the on-the-fly menus.
164 connect(browserViewPointer, SIGNAL(updateUserAgentActions(QString)), this, SLOT(updateUserAgentActions(QString)));
165 connect(browserViewPointer, SIGNAL(updateZoomFactorAction(double)), this, SLOT(updateZoomFactorAction(double)));
166 connect(browserViewPointer, SIGNAL(updateSearchEngineActions(QString)), this, SLOT(updateSearchEngineActions(QString)));
168 // Apply the on-the-fly settings when selected.
169 connect(userAgentActionGroupPointer, SIGNAL(triggered(QAction*)), browserViewPointer, SLOT(applyOnTheFlyUserAgent(QAction*)));
170 connect(searchEngineActionGroupPointer, SIGNAL(triggered(QAction*)), browserViewPointer, SLOT(applyOnTheFlySearchEngine(QAction*)));
173 connect(zoomFactorActionPointer, SIGNAL(triggered()), this, SLOT(getZoomFactorFromUser()));
174 connect(cookiesActionPointer, SIGNAL(triggered()), this, SLOT(openCookiesDialog()));
175 connect(domainSettingsActionPointer, SIGNAL(triggered()), this, SLOT(openDomainSettings()));
177 // Connect the URL toolbar actions.
178 connect(javaScriptActionPointer, SIGNAL(triggered()), this, SLOT(toggleJavaScript()));
179 connect(localStorageActionPointer, SIGNAL(triggered()), this, SLOT(toggleLocalStorage()));
181 // Update the URL toolbar actions.
182 connect(browserViewPointer, SIGNAL(updateBackAction(bool)), backActionPointer, SLOT(setEnabled(bool)));
183 connect(browserViewPointer, SIGNAL(updateForwardAction(bool)), forwardActionPointer, SLOT(setEnabled(bool)));
184 connect(browserViewPointer, SIGNAL(updateJavaScriptAction(bool)), this, SLOT(updateJavaScriptAction(bool)));
185 connect(browserViewPointer, SIGNAL(updateLocalStorageAction(bool)), this, SLOT(updateLocalStorageAction(bool)));
187 // Setup the GUI based on the browser_ui.rc file.
188 setupGUI(StandardWindowOption::Default, ("browser_ui.rc"));
190 // Get a handle for the URL toolbar.
191 KToolBar *urlToolBarPointer = toolBar(QStringLiteral("url_toolbar"));
193 // Create a URL line edit.
194 urlLineEditPointer = new KLineEdit();
196 // Add an edit or add domain settings action to the URL line edit.
197 QAction *addOrEditDomainSettingsActionPointer = urlLineEditPointer->addAction(QIcon::fromTheme("settings-configure"), QLineEdit::TrailingPosition);
199 // Add or edit the current domain settings.
200 connect(addOrEditDomainSettingsActionPointer, SIGNAL(triggered()), this, SLOT(addOrEditDomainSettings()));
202 // Populate the URL toolbar.
203 urlToolBarPointer->insertWidget(javaScriptActionPointer, urlLineEditPointer);
205 // Load a new URL from the URL line edit.
206 connect(urlLineEditPointer, SIGNAL(returnKeyPressed(const QString)), this, SLOT(loadUrlFromLineEdit(const QString)));
208 // Update the URL line edit on page loads.
209 connect(browserViewPointer, SIGNAL(updateUrlLineEdit(QUrl)), this, SLOT(updateUrlLineEdit(QUrl)));
211 // Get a handle for the status bar.
212 QStatusBar *statusBarPointer = statusBar();
214 // Create a progress bar.
215 progressBarPointer = new QProgressBar();
217 // Add the progress bar to to the status bar.
218 statusBarPointer->addPermanentWidget(progressBarPointer);
220 // Update the status bar with the URL when a link is hovered.
221 connect(browserViewPointer, SIGNAL(linkHovered(QString)), statusBarPointer, SLOT(showMessage(QString)));
223 // Update the progress bar.
224 connect(browserViewPointer, SIGNAL(showProgressBar(const int)), this, SLOT(showProgressBar(const int)));
225 connect(browserViewPointer, SIGNAL(hideProgressBar()), progressBarPointer, SLOT(hide()));
227 // Clear the URL line edit focus when requested.
228 connect(browserViewPointer, SIGNAL(clearUrlLineEditFocus()), this, SLOT(clearUrlLineEditFocus()));
230 // Get the URL line edit palettes.
231 noDomainSettingsPalette = urlLineEditPointer->palette();
232 domainSettingsPalette = urlLineEditPointer->palette();
234 // Modify the domain settings palette.
235 domainSettingsPalette.setColor(QPalette::Base, QColor("#C8E6C9"));
237 // Update the applied palette.
238 connect(browserViewPointer, SIGNAL(updateDomainSettingsIndicator(bool, QString)), this, SLOT(updateDomainSettingsIndicator(bool, QString)));
240 // Initialize the cookie list.
241 cookieListPointer = new std::forward_list<QNetworkCookie>;
243 // Process cookie changes.
244 connect(browserViewPointer, SIGNAL(addCookie(QNetworkCookie)), this, SLOT(addCookieToList(QNetworkCookie)));
245 connect(browserViewPointer, SIGNAL(removeCookie(QNetworkCookie)), this, SLOT(removeCookieFromList(QNetworkCookie)));
247 // Load the initial website.
248 browserViewPointer->loadInitialWebsite();
251 void BrowserWindow::addCookieToList(const QNetworkCookie &newCookie) const
253 qDebug() << "Add cookie: " << newCookie.toRawForm();
254 // Add the new cookie to the list.
255 cookieListPointer->push_front(newCookie);
258 void BrowserWindow::addOrEditDomainSettings() const
260 // Remove the focus from the URL line edit.
261 urlLineEditPointer->clearFocus();
263 // Create the domain settings dialog pointer.
264 DomainSettingsDialog *domainSettingsDialogPointer;
266 // Run the commands according to the current domain settings status.
267 if (currentDomainSettingsDomain == "") // Domain settings are not currently applied.
269 // Instruct the domain settings dialog to add a new domain.
270 domainSettingsDialogPointer = new DomainSettingsDialog(DomainSettingsDialog::ADD_DOMAIN, currentUrl.host());
272 else // Domain settings are currently applied.
274 // Instruct the domain settings dialog to edit the current domain.
275 domainSettingsDialogPointer = new DomainSettingsDialog(DomainSettingsDialog::EDIT_DOMAIN, currentDomainSettingsDomain);
278 // Set the dialog window title.
279 domainSettingsDialogPointer->setWindowTitle(i18nc("The domain settings dialog title", "Domain Settings"));
282 domainSettingsDialogPointer->setWindowModality(Qt::WindowModality::WindowModal);;
285 domainSettingsDialogPointer->show();
287 // Reload the tabs when domain settings are updated.
288 connect(domainSettingsDialogPointer, SIGNAL(domainSettingsUpdated()), browserViewPointer, SLOT(applyDomainSettingsAndReload()));
291 void BrowserWindow::back() const
293 // Remove the focus from the URL line edit.
294 urlLineEditPointer->clearFocus();
297 browserViewPointer->back();
300 void BrowserWindow::clearUrlLineEditFocus() const
302 // Remove the focus from the URL line edit.
303 urlLineEditPointer->clearFocus();
306 void BrowserWindow::fileNew() const
308 // Display a new instance of Privacy Browser.
309 (new BrowserWindow)->show();
312 void BrowserWindow::forward() const
314 // Remove the focus from the URL line edit.
315 urlLineEditPointer->clearFocus();
318 browserViewPointer->forward();
321 void BrowserWindow::getZoomFactorFromUser()
323 // Create an OK flag.
326 // Display a dialog to get the new zoom factor from the user. Format the double to display two decimals and have a 0.25 step.
327 double newZoomFactor = QInputDialog::getDouble(this, i18nc("The on-the-fly zoom factor dialog title", "On-The-Fly Zoom Factor"),
328 i18nc("The instruction text of the on-the-fly zoom factor dialog", "Enter a zoom factor between 0.25 and 5.00"),
329 currentZoomFactor, .025, 5.00, 2, &okClicked, Qt::WindowFlags(), 0.25);
331 // Update the zoom factor if the user clicked OK.
334 // Update the current zoom factor.
335 currentZoomFactor = newZoomFactor;
337 // Set the new zoom factor.
338 browserViewPointer->applyOnTheFlyZoomFactor(newZoomFactor);
340 // Update the on-the-fly action text.
341 updateZoomFactorAction(newZoomFactor);
345 void BrowserWindow::home() const
347 // Remove the focus from the URL line edit.
348 urlLineEditPointer->clearFocus();
351 browserViewPointer->home();
354 void BrowserWindow::loadUrlFromLineEdit(const QString &url) const
356 // Remove the focus from the URL line edit.
357 urlLineEditPointer->clearFocus();
360 browserViewPointer->loadUrlFromLineEdit(url);
363 void BrowserWindow::openCookiesDialog()
365 // Remove the focus from the URL line edit.
366 urlLineEditPointer->clearFocus();
368 // Instantiate the cookie settings dialog.
369 CookiesDialog *cookiesDialogPointer = new CookiesDialog(cookieListPointer);
372 cookiesDialogPointer->show();
374 // Connect the dialog signals.
375 connect(cookiesDialogPointer, SIGNAL(addCookie(QNetworkCookie)), browserViewPointer, SLOT(addCookieToStore(QNetworkCookie)));
376 connect(cookiesDialogPointer, SIGNAL(deleteAllCookies()), browserViewPointer, SLOT(deleteAllCookies()));
377 connect(cookiesDialogPointer, SIGNAL(deleteCookie(QNetworkCookie)), browserViewPointer, SLOT(deleteCookieFromStore(QNetworkCookie)));
380 void BrowserWindow::openDomainSettings() const
382 // Remove the focus from the URL line edit.
383 urlLineEditPointer->clearFocus();
385 // Instantiate the domain settings dialog.
386 DomainSettingsDialog *domainSettingsDialogPointer = new DomainSettingsDialog();
389 domainSettingsDialogPointer->show();
391 // Reload the tabs when domain settings are updated.
392 connect(domainSettingsDialogPointer, SIGNAL(domainSettingsUpdated()), browserViewPointer, SLOT(applyDomainSettingsAndReload()));
395 void BrowserWindow::refresh() const
397 // Remove the focus from the URL line edit.
398 urlLineEditPointer->clearFocus();
400 // Refresh the web page.
401 browserViewPointer->refresh();
404 void BrowserWindow::removeCookieFromList(const QNetworkCookie &cookie) const
406 qDebug() << "Remove cookie: " << cookie.toRawForm();
408 // Remove the cookie from the list.
409 cookieListPointer->remove(cookie);
412 void BrowserWindow::showProgressBar(const int &progress) const
414 // Set the progress bar value.
415 progressBarPointer->setValue(progress);
417 // Show the progress bar.
418 progressBarPointer->show();
421 QSize BrowserWindow::sizeHint() const
423 // Return the default window size.
424 return QSize(1500, 1200);
427 void BrowserWindow::settingsConfigure()
429 // Check to make sure the dialog box isn't already displayed.
430 if (KConfigDialog::exists(QStringLiteral("settings")))
432 // Show the existing config dialog if it is hidden.
433 configDialogPointer->show();
435 // Raise the existing config dialog if it is below other windows.
436 configDialogPointer->raise();
438 // Restore the existing config dialog if it has been minimized.
439 if (configDialogPointer->isMinimized()) {
440 configDialogPointer->showNormal();
443 // Activate the existing config dialog, which brings its virtual desktop into focus.
444 configDialogPointer->activateWindow();
448 // Create the settings widgets.
449 QWidget *privacySettingsWidgetPointer = new QWidget;
450 QWidget *generalSettingsWidgetPointer = new QWidget;
452 // Instantiate the settings UI.
453 Ui::PrivacySettings privacySettingsUi;
454 Ui::GeneralSettings generalSettingsUi;
456 // Setup the UI to display the settings widgets.
457 privacySettingsUi.setupUi(privacySettingsWidgetPointer);
458 generalSettingsUi.setupUi(generalSettingsWidgetPointer);
460 // Get handles for the widgets.
461 QComboBox *userAgentComboBoxPointer = privacySettingsUi.kcfg_userAgent;
462 userAgentLabelPointer = privacySettingsUi.userAgentLabel;
463 QComboBox *searchEngineComboBoxPointer = generalSettingsUi.kcfg_searchEngine;
464 searchEngineLabelPointer = generalSettingsUi.searchEngineLabel;
466 // Populate the combo box labels.
467 updateUserAgentLabel(userAgentComboBoxPointer->currentText());
468 updateSearchEngineLabel(searchEngineComboBoxPointer->currentText());
470 // Update the labels when the combo boxes change.
471 connect(userAgentComboBoxPointer, SIGNAL(currentTextChanged(const QString)), this, SLOT(updateUserAgentLabel(const QString)));
472 connect(searchEngineComboBoxPointer, SIGNAL(currentTextChanged(const QString)), this, SLOT(updateSearchEngineLabel(const QString)));
474 // Instantiate a settings config dialog from the settings.kcfg file.
475 configDialogPointer = new KConfigDialog(this, QStringLiteral("settings"), Settings::self());
477 // Add the settings widgets as config dialog pages.
478 configDialogPointer->addPage(privacySettingsWidgetPointer, i18nc("@title:tab", "Privacy"), QStringLiteral("privacy-browser"));
479 configDialogPointer->addPage(generalSettingsWidgetPointer, i18nc("@title:tab", "General"), QStringLiteral("breeze-settings"));
481 // Delete the config dialog when it is closed.
482 configDialogPointer->setAttribute(Qt::WA_DeleteOnClose);
485 configDialogPointer->show();
487 // TODO. KConfigDialog does not respect expanding size policies. <https://redmine.stoutner.com/issues/823>
488 //configDialogPointer->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
489 //privacySettingsWidgetPointer->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
490 //generalSettingsWidgetPointer->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
491 //configDialogPointer->adjustSize();
493 // Expand the config dialog.
494 configDialogPointer->resize(1000, 500);
496 // Apply the settings when they are updated.
497 connect(configDialogPointer, SIGNAL(settingsChanged(QString)), browserViewPointer, SLOT(applyApplicationSettings()));
498 connect(configDialogPointer, SIGNAL(settingsChanged(QString)), browserViewPointer, SLOT(applyDomainSettingsAndReload()));
502 void BrowserWindow::toggleJavaScript() const
504 // Remove the focus from the URL line edit.
505 urlLineEditPointer->clearFocus();
507 // Toggle JavaScript.
508 browserViewPointer->toggleJavaScript();
511 void BrowserWindow::toggleLocalStorage() const
513 // Remove the focus from the URL line edit.
514 urlLineEditPointer->clearFocus();
516 // Toggle JavaScript.
517 browserViewPointer->toggleLocalStorage();
520 void BrowserWindow::updateDomainSettingsIndicator(const bool &status, const QString &domainSettingsDomain)
522 // Set the domain palette according to the status.
523 if (status) urlLineEditPointer->setPalette(domainSettingsPalette);
524 else urlLineEditPointer->setPalette(noDomainSettingsPalette);
527 currentDomainSettingsDomain = domainSettingsDomain;
530 void BrowserWindow::updateJavaScriptAction(const bool &isEnabled) const
532 // Set the icon according to the status.
533 if (isEnabled) javaScriptActionPointer->setIcon(QIcon(":/icons/javascript-warning"));
534 else javaScriptActionPointer->setIcon(QIcon(":/icons/privacy-mode"));
537 void BrowserWindow::updateLocalStorageAction(const bool &isEnabled) const
539 // Set the icon according to the status.
540 if (isEnabled) localStorageActionPointer->setIcon(QIcon::fromTheme("disk-quota-low"));
541 else localStorageActionPointer->setIcon(QIcon::fromTheme("disk-quota"));
544 void BrowserWindow::updateSearchEngineActions(const QString &searchEngine) const
546 // Initialize the custom search engine flag.
547 bool customSearchEngine = false;
549 if (searchEngine == "Mojeek") // Mojeek.
551 searchEngineMojeekActionPointer->setChecked(true);
553 else if (searchEngine == "Monocles") // Monocles.
555 searchEngineMonoclesActionPointer->setChecked(true);
557 else if (searchEngine == "MetaGer") // MetaGer.
559 searchEngineMetagerActionPointer->setChecked(true);
561 else if (searchEngine == "Google") // Google.
563 searchEngineGoogleActionPointer->setChecked(true);
565 else if (searchEngine == "Bing") // Bing.
567 searchEngineBingActionPointer->setChecked(true);
569 else if (searchEngine == "Yahoo") // Yahoo.
571 searchEngineYahooActionPointer->setChecked(true);
573 else // Custom search engine.
575 // Check the user agent.
576 searchEngineCustomActionPointer->setChecked(true);
578 // Set the custom search engine flag.
579 customSearchEngine = true;
582 // Format the custom search engine.
583 if (customSearchEngine)
585 // Enable the custom search engine.
586 searchEngineCustomActionPointer->setEnabled(true);
588 // Set the custom search engine text.
589 searchEngineCustomActionPointer->setText(searchEngine);
593 // Disable the custom search engine.
594 searchEngineCustomActionPointer->setEnabled(false);
596 // Reset the custom search engine text.
597 searchEngineCustomActionPointer->setText(i18nc("@action", "Custom"));
601 void BrowserWindow::updateUserAgentActions(const QString &userAgent) const
603 // Initialize the custom user agent flag.
604 bool customUserAgent = false;
606 // Check the indicated on-the-fly user agent.
607 if (userAgent == UserAgentHelper::PRIVACY_BROWSER_USER_AGENT) userAgentPrivacyBrowserActionPointer->setChecked(true); // Privacy Browser.
608 else if (userAgent == BrowserView::webEngineDefaultUserAgent) userAgentWebEngineDefaultActionPointer->setChecked(true); // WebEngine default.
609 else if (userAgent == UserAgentHelper::FIREFOX_LINUX_USER_AGENT) userAgentFirefoxLinuxActionPointer->setChecked(true); // Firefox Linux.
610 else if (userAgent == UserAgentHelper::CHROMIUM_LINUX_USER_AGENT) userAgentChromiumLinuxActionPointer->setChecked(true); // Chromium Linux.
611 else if (userAgent == UserAgentHelper::FIREFOX_WINDOWS_USER_AGENT) userAgentFirefoxWindowsActionPointer->setChecked(true); // Firefox Windows.
612 else if (userAgent == UserAgentHelper::CHROME_WINDOWS_USER_AGENT) userAgentChromeWindowsActionPointer->setChecked(true); // Chrome Windows.
613 else if (userAgent == UserAgentHelper::EDGE_WINDOWS_USER_AGENT) userAgentEdgeWindowsActionPointer->setChecked(true); // Edge Windows.
614 else if (userAgent == UserAgentHelper::SAFARI_MACOS_USER_AGENT) userAgentSafariMacosActionPointer->setChecked(true); // Safara macOS.
615 else // Custom user agent.
617 // Check the user agent.
618 userAgentCustomActionPointer->setChecked(true);
620 // Set the custom user agent flag.
621 customUserAgent = true;
625 // Format the custom user agent.
628 // Enable the custom user agent.
629 userAgentCustomActionPointer->setEnabled(true);
631 // Set the custom user agent text.
632 userAgentCustomActionPointer->setText(userAgent);
636 // Disable the custom user agent.
637 userAgentCustomActionPointer->setEnabled(false);
639 // Reset the custom user agent text.
640 userAgentCustomActionPointer->setText(i18nc("@action", "Custom"));
644 void BrowserWindow::updateZoomFactorAction(const double &zoomFactor)
646 // Set the current zoom factor.
647 currentZoomFactor = zoomFactor;
649 // Update the zoom factor action text, formatting the double with 2 decimal places.
650 zoomFactorActionPointer->setText(ki18nc("@action", "Zoom Factor - %1").subs(zoomFactor, 0, '0', 2).toString());
653 void BrowserWindow::updateSearchEngineLabel(const QString &searchEngineString) const
655 // Update the search engine label.
656 searchEngineLabelPointer->setText(SearchEngineHelper::getSearchUrl(searchEngineString));
659 void BrowserWindow::updateUrlLineEdit(const QUrl &newUrl)
661 // Update the URL line edit if it does not have focus.
662 if (!urlLineEditPointer->hasFocus())
664 // Update the URL line edit.
665 urlLineEditPointer->setText(newUrl.toString());
668 // Store the current URL.
672 void BrowserWindow::updateUserAgentLabel(const QString &userAgentDatabaseName) const
674 // Update the user agent label.
675 userAgentLabelPointer->setText(UserAgentHelper::getUserAgentFromDatabaseName(userAgentDatabaseName));