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/DomainSettingsDialog.h"
26 #include "helpers/SearchEngineHelper.h"
27 #include "helpers/UserAgentHelper.h"
29 // KDE Frameworks headers.
30 #include <KActionCollection>
33 // Qt toolkit headers.
34 #include <QInputDialog>
37 BrowserWindow::BrowserWindow() : KXmlGuiWindow()
39 // Instantiate the main view pointer.
40 browserViewPointer = new BrowserView(this);
42 // Set the main view as the central widget.
43 setCentralWidget(browserViewPointer);
45 // Get a handle for the action collection.
46 KActionCollection *actionCollectionPointer = this->actionCollection();
48 // Add the standard actions.
49 QAction *backActionPointer = KStandardAction::back(this, SLOT(back()), actionCollectionPointer);
50 QAction *forwardActionPointer = KStandardAction::forward(this, SLOT(forward()), actionCollectionPointer);
51 KStandardAction::home(this, SLOT(home()), actionCollectionPointer);
52 KStandardAction::openNew(this, SLOT(fileNew()), actionCollectionPointer);
53 KStandardAction::quit(qApp, SLOT(closeAllWindows()), actionCollectionPointer);
54 KStandardAction::preferences(this, SLOT(settingsConfigure()), actionCollectionPointer);
55 KStandardAction::redisplay(this, SLOT(refresh()), actionCollectionPointer);
57 // Add the custom actions.
58 userAgentPrivacyBrowserActionPointer = actionCollectionPointer->addAction(QStringLiteral("user_agent_privacy_browser"));
59 userAgentWebEngineDefaultActionPointer = actionCollectionPointer->addAction(QStringLiteral("user_agent_webengine_default"));
60 userAgentFirefoxLinuxActionPointer = actionCollectionPointer->addAction(QStringLiteral("user_agent_firefox_linux"));
61 userAgentChromiumLinuxActionPointer = actionCollectionPointer->addAction(QStringLiteral("user_agent_chromium_linux"));
62 userAgentFirefoxWindowsActionPointer = actionCollectionPointer->addAction(QStringLiteral("user_agent_firefox_windows"));
63 userAgentChromeWindowsActionPointer = actionCollectionPointer->addAction(QStringLiteral("user_agent_chrome_windows"));
64 userAgentEdgeWindowsActionPointer = actionCollectionPointer->addAction(QStringLiteral("user_agent_edge_windows"));
65 userAgentSafariMacosActionPointer = actionCollectionPointer->addAction(QStringLiteral("user_agent_safari_macos"));
66 userAgentCustomActionPointer = actionCollectionPointer->addAction(QStringLiteral("user_agent_custom"));
67 zoomFactorActionPointer = actionCollectionPointer->addAction(QStringLiteral("zoom_factor"));
68 searchEngineMojeekActionPointer = actionCollectionPointer->addAction(QStringLiteral("search_engine_mojeek"));
69 searchEngineMonoclesActionPointer = actionCollectionPointer->addAction(QStringLiteral("search_engine_monocles"));
70 searchEngineMetagerActionPointer = actionCollectionPointer->addAction(QStringLiteral("search_engine_metager"));
71 searchEngineGoogleActionPointer = actionCollectionPointer->addAction(QStringLiteral("search_engine_google"));
72 searchEngineBingActionPointer = actionCollectionPointer->addAction(QStringLiteral("search_engine_bing"));
73 searchEngineYahooActionPointer = actionCollectionPointer->addAction(QStringLiteral("search_engine_yahoo"));
74 searchEngineCustomActionPointer = actionCollectionPointer->addAction(QStringLiteral("search_engine_custom"));
75 javaScriptActionPointer = actionCollectionPointer->addAction(QStringLiteral("javascript"));
76 localStorageActionPointer = actionCollectionPointer->addAction(QStringLiteral("local_storage"));
77 domainSettingsActionPointer = actionCollectionPointer->addAction(QStringLiteral("domain_settings"));
79 // Create the action groups
80 QActionGroup *userAgentActionGroupPointer = new QActionGroup(this);
81 QActionGroup *searchEngineActionGroupPointer = new QActionGroup(this);
83 // Add the actions to the groups.
84 userAgentActionGroupPointer->addAction(userAgentPrivacyBrowserActionPointer);
85 userAgentActionGroupPointer->addAction(userAgentWebEngineDefaultActionPointer);
86 userAgentActionGroupPointer->addAction(userAgentFirefoxLinuxActionPointer);
87 userAgentActionGroupPointer->addAction(userAgentChromiumLinuxActionPointer);
88 userAgentActionGroupPointer->addAction(userAgentFirefoxWindowsActionPointer);
89 userAgentActionGroupPointer->addAction(userAgentChromeWindowsActionPointer);
90 userAgentActionGroupPointer->addAction(userAgentEdgeWindowsActionPointer);
91 userAgentActionGroupPointer->addAction(userAgentSafariMacosActionPointer);
92 userAgentActionGroupPointer->addAction(userAgentCustomActionPointer);
93 searchEngineActionGroupPointer->addAction(searchEngineMojeekActionPointer);
94 searchEngineActionGroupPointer->addAction(searchEngineMonoclesActionPointer);
95 searchEngineActionGroupPointer->addAction(searchEngineMetagerActionPointer);
96 searchEngineActionGroupPointer->addAction(searchEngineGoogleActionPointer);
97 searchEngineActionGroupPointer->addAction(searchEngineBingActionPointer);
98 searchEngineActionGroupPointer->addAction(searchEngineYahooActionPointer);
99 searchEngineActionGroupPointer->addAction(searchEngineCustomActionPointer);
101 // Set some actions to be checkable.
102 userAgentPrivacyBrowserActionPointer->setCheckable(true);
103 userAgentWebEngineDefaultActionPointer->setCheckable(true);
104 userAgentFirefoxLinuxActionPointer->setCheckable(true);
105 userAgentChromiumLinuxActionPointer->setCheckable(true);
106 userAgentFirefoxWindowsActionPointer->setCheckable(true);
107 userAgentChromeWindowsActionPointer->setCheckable(true);
108 userAgentEdgeWindowsActionPointer->setCheckable(true);
109 userAgentSafariMacosActionPointer->setCheckable(true);
110 userAgentCustomActionPointer->setCheckable(true);
111 searchEngineMojeekActionPointer->setCheckable(true);
112 searchEngineMonoclesActionPointer->setCheckable(true);
113 searchEngineMetagerActionPointer->setCheckable(true);
114 searchEngineGoogleActionPointer->setCheckable(true);
115 searchEngineBingActionPointer->setCheckable(true);
116 searchEngineYahooActionPointer->setCheckable(true);
117 searchEngineCustomActionPointer->setCheckable(true);
119 // Set the non-mutable action text.
120 userAgentPrivacyBrowserActionPointer->setText(UserAgentHelper::PRIVACY_BROWSER_TRANSLATED);
121 userAgentWebEngineDefaultActionPointer->setText(UserAgentHelper::WEB_ENGINE_DEFAULT_TRANSLATED);
122 userAgentFirefoxLinuxActionPointer->setText(UserAgentHelper::FIREFOX_LINUX_TRANSLATED);
123 userAgentChromiumLinuxActionPointer->setText(UserAgentHelper::CHROMIUM_LINUX_TRANSLATED);
124 userAgentFirefoxWindowsActionPointer->setText(UserAgentHelper::FIREFOX_WINDOWS_TRANSLATED);
125 userAgentChromeWindowsActionPointer->setText(UserAgentHelper::CHROME_WINDOWS_TRANSLATED);
126 userAgentEdgeWindowsActionPointer->setText(UserAgentHelper::EDGE_WINDOWS_TRANSLATED);
127 userAgentSafariMacosActionPointer->setText(UserAgentHelper::SAFARI_MACOS_TRANSLATED);
128 searchEngineMojeekActionPointer->setText(i18nc("Search engine", "Mojeek"));
129 searchEngineMonoclesActionPointer->setText(i18nc("Search engine", "Monocles"));
130 searchEngineMetagerActionPointer->setText(i18nc("Search engine", "MetaGer"));
131 searchEngineGoogleActionPointer->setText(i18nc("Search engine", "Google"));
132 searchEngineBingActionPointer->setText(i18nc("Search engine", "Bing"));
133 searchEngineYahooActionPointer->setText(i18nc("Search engine", "Yahoo"));
134 javaScriptActionPointer->setText(i18nc("JavaScript button", "JavaScript"));
135 localStorageActionPointer->setText(i18nc("Local Storage Button", "Local Storage"));
136 domainSettingsActionPointer->setText(i18nc("Domain Settings button", "Domain Settings"));
138 // Set the action icons.
139 userAgentPrivacyBrowserActionPointer->setIcon(QIcon(":/icons/privacy-mode"));
140 userAgentWebEngineDefaultActionPointer->setIcon(QIcon::fromTheme(QStringLiteral("user-group-properties")));
141 userAgentFirefoxLinuxActionPointer->setIcon(QIcon::fromTheme(QStringLiteral("firefox-esr")));
142 userAgentChromiumLinuxActionPointer->setIcon(QIcon::fromTheme(QStringLiteral("chromium")));
143 userAgentFirefoxWindowsActionPointer->setIcon(QIcon::fromTheme(QStringLiteral("firefox-esr")));
144 userAgentChromeWindowsActionPointer->setIcon(QIcon::fromTheme(QStringLiteral("chromium")));
145 userAgentEdgeWindowsActionPointer->setIcon(QIcon::fromTheme(QStringLiteral("user-group-properties")));
146 userAgentSafariMacosActionPointer->setIcon(QIcon::fromTheme(QStringLiteral("user-group-properties")));
147 userAgentCustomActionPointer->setIcon(QIcon::fromTheme(QStringLiteral("user-group-properties")));
148 searchEngineMojeekActionPointer->setIcon(QIcon::fromTheme(QStringLiteral("search")));
149 searchEngineMonoclesActionPointer->setIcon(QIcon::fromTheme(QStringLiteral("search")));
150 searchEngineMetagerActionPointer->setIcon(QIcon::fromTheme(QStringLiteral("search")));
151 searchEngineGoogleActionPointer->setIcon(QIcon::fromTheme(QStringLiteral("im-google")));
152 searchEngineBingActionPointer->setIcon(QIcon::fromTheme(QStringLiteral("search")));
153 searchEngineYahooActionPointer->setIcon(QIcon::fromTheme(QStringLiteral("im-yahoo")));
154 searchEngineCustomActionPointer->setIcon(QIcon::fromTheme(QStringLiteral("search")));
155 zoomFactorActionPointer->setIcon(QIcon::fromTheme(QStringLiteral("zoom")));
156 domainSettingsActionPointer->setIcon(QIcon::fromTheme(QStringLiteral("settings-configure")));
158 // Update the on-the-fly menus.
159 connect(browserViewPointer, SIGNAL(updateUserAgentActions(QString)), this, SLOT(updateUserAgentActions(QString)));
160 connect(browserViewPointer, SIGNAL(updateZoomFactorAction(double)), this, SLOT(updateZoomFactorAction(double)));
161 connect(browserViewPointer, SIGNAL(updateSearchEngineActions(QString)), this, SLOT(updateSearchEngineActions(QString)));
163 // Apply the on-the-fly settings when selected.
164 connect(userAgentActionGroupPointer, SIGNAL(triggered(QAction*)), browserViewPointer, SLOT(applyOnTheFlyUserAgent(QAction*)));
165 connect(searchEngineActionGroupPointer, SIGNAL(triggered(QAction*)), browserViewPointer, SLOT(applyOnTheFlySearchEngine(QAction*)));
168 connect(zoomFactorActionPointer, SIGNAL(triggered()), this, SLOT(getZoomFactorFromUser()));
170 // Connect the URL toolbar actions.
171 connect(javaScriptActionPointer, SIGNAL(triggered()), this, SLOT(toggleJavaScript()));
172 connect(localStorageActionPointer, SIGNAL(triggered()), this, SLOT(toggleLocalStorage()));
173 connect(domainSettingsActionPointer, SIGNAL(triggered()), this, SLOT(openDomainSettings()));
175 // Update the URL toolbar actions.
176 connect(browserViewPointer, SIGNAL(updateBackAction(bool)), backActionPointer, SLOT(setEnabled(bool)));
177 connect(browserViewPointer, SIGNAL(updateForwardAction(bool)), forwardActionPointer, SLOT(setEnabled(bool)));
178 connect(browserViewPointer, SIGNAL(updateJavaScriptAction(bool)), this, SLOT(updateJavaScriptAction(bool)));
179 connect(browserViewPointer, SIGNAL(updateLocalStorageAction(bool)), this, SLOT(updateLocalStorageAction(bool)));
181 // Setup the GUI based on the browser_ui.rc file.
182 setupGUI(StandardWindowOption::Default, ("browser_ui.rc"));
184 // Get a handle for the URL toolbar.
185 KToolBar *urlToolBarPointer = toolBar(QStringLiteral("url_toolbar"));
187 // Create a URL line edit.
188 urlLineEditPointer = new KLineEdit();
190 // Add an edit or add domain settings action to the URL line edit.
191 QAction *addOrEditDomainSettingsActionPointer = urlLineEditPointer->addAction(QIcon::fromTheme("settings-configure"), QLineEdit::TrailingPosition);
193 // Add or edit the current domain settings.
194 connect(addOrEditDomainSettingsActionPointer, SIGNAL(triggered()), this, SLOT(addOrEditDomainSettings()));
196 // Populate the URL toolbar.
197 urlToolBarPointer->insertWidget(javaScriptActionPointer, urlLineEditPointer);
199 // Load a new URL from the URL line edit.
200 connect(urlLineEditPointer, SIGNAL(returnKeyPressed(const QString)), this, SLOT(loadUrlFromLineEdit(const QString)));
202 // Update the URL line edit on page loads.
203 connect(browserViewPointer, SIGNAL(updateUrlLineEdit(QUrl)), this, SLOT(updateUrlLineEdit(QUrl)));
205 // Get a handle for the status bar.
206 QStatusBar *statusBarPointer = statusBar();
208 // Create a progress bar.
209 progressBarPointer = new QProgressBar();
211 // Add the progress bar to to the status bar.
212 statusBarPointer->addPermanentWidget(progressBarPointer);
214 // Update the status bar with the URL when a link is hovered.
215 connect(browserViewPointer, SIGNAL(linkHovered(QString)), statusBarPointer, SLOT(showMessage(QString)));
217 // Update the progress bar.
218 connect(browserViewPointer, SIGNAL(showProgressBar(const int)), this, SLOT(showProgressBar(const int)));
219 connect(browserViewPointer, SIGNAL(hideProgressBar()), progressBarPointer, SLOT(hide()));
221 // Get the URL line edit palettes.
222 noDomainSettingsPalette = urlLineEditPointer->palette();
223 domainSettingsPalette = urlLineEditPointer->palette();
225 // Modify the domain settings palette.
226 domainSettingsPalette.setColor(QPalette::Base, QColor("#C8E6C9"));
228 // Update the applied palette.
229 connect(browserViewPointer, SIGNAL(updateDomainSettingsIndicator(bool, QString)), this, SLOT(updateDomainSettingsIndicator(bool, QString)));
231 // Load the initial website.
232 browserViewPointer->loadInitialWebsite();
235 void BrowserWindow::addOrEditDomainSettings() const
237 // Remove the focus from the URL line edit.
238 urlLineEditPointer->clearFocus();
240 // Create the domain settings dialog pointer.
241 DomainSettingsDialog *domainSettingsDialogPointer;
243 // Run the commands according to the current domain settings status.
244 if (currentDomainSettingsDomain == "") // Domain settings are not currently applied.
246 // Instruct the domain settings dialog to add a new domain.
247 domainSettingsDialogPointer = new DomainSettingsDialog(DomainSettingsDialog::ADD_DOMAIN, currentUrl.host());
249 else // Domain settings are currently applied.
251 // Instruct the domain settings dialog to edit the current domain.
252 domainSettingsDialogPointer = new DomainSettingsDialog(DomainSettingsDialog::EDIT_DOMAIN, currentDomainSettingsDomain);
255 // Set the dialog window title.
256 domainSettingsDialogPointer->setWindowTitle(i18nc("The domain settings dialog title", "Domain Settings"));
259 domainSettingsDialogPointer->setWindowModality(Qt::WindowModality::WindowModal);;
262 domainSettingsDialogPointer->show();
264 // Reload the tabs when domain settings are updated.
265 connect(domainSettingsDialogPointer, SIGNAL(domainSettingsUpdated()), browserViewPointer, SLOT(applyDomainSettingsAndReload()));
268 void BrowserWindow::back() const
270 // Remove the focus from the URL line edit.
271 urlLineEditPointer->clearFocus();
274 browserViewPointer->back();
277 void BrowserWindow::fileNew() const
279 // Display a new instance of Privacy Browser.
280 (new BrowserWindow)->show();
283 void BrowserWindow::forward() const
285 // Remove the focus from the URL line edit.
286 urlLineEditPointer->clearFocus();
289 browserViewPointer->forward();
292 void BrowserWindow::getZoomFactorFromUser()
294 // Create an OK flag.
297 // 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.
298 double newZoomFactor = QInputDialog::getDouble(this, i18nc("The on-the-fly zoom factor dialog title", "On-The-Fly Zoom Factor"),
299 i18nc("The instruction text of the on-the-fly zoom factor dialog", "Enter a zoom factor between 0.25 and 5.00"),
300 currentZoomFactor, .025, 5.00, 2, &okClicked, Qt::WindowFlags(), 0.25);
302 // Update the zoom factor if the user clicked OK.
305 // Update the current zoom factor.
306 currentZoomFactor = newZoomFactor;
308 // Set the new zoom factor.
309 browserViewPointer->applyOnTheFlyZoomFactor(newZoomFactor);
311 // Update the on-the-fly action text.
312 updateZoomFactorAction(newZoomFactor);
316 void BrowserWindow::home() const
318 // Remove the focus from the URL line edit.
319 urlLineEditPointer->clearFocus();
322 browserViewPointer->home();
325 void BrowserWindow::loadUrlFromLineEdit(const QString &url) const
327 // Remove the focus from the URL line edit.
328 urlLineEditPointer->clearFocus();
331 browserViewPointer->loadUrlFromLineEdit(url);
334 void BrowserWindow::openDomainSettings() const
336 // Remove the focus from the URL line edit.
337 urlLineEditPointer->clearFocus();
339 // Instantiate the domain settings dialog.
340 DomainSettingsDialog *domainSettingsDialogPointer = new DomainSettingsDialog();
342 // Set the dialog window title.
343 domainSettingsDialogPointer->setWindowTitle(i18nc("The domain settings dialog title", "Domain Settings"));
346 domainSettingsDialogPointer->setWindowModality(Qt::WindowModality::WindowModal);;
349 domainSettingsDialogPointer->show();
351 // Reload the tabs when domain settings are updated.
352 connect(domainSettingsDialogPointer, SIGNAL(domainSettingsUpdated()), browserViewPointer, SLOT(applyDomainSettingsAndReload()));
355 void BrowserWindow::refresh() const
357 // Remove the focus from the URL line edit.
358 urlLineEditPointer->clearFocus();
360 // Refresh the web page.
361 browserViewPointer->refresh();
364 void BrowserWindow::showProgressBar(const int &progress) const
366 // Set the progress bar value.
367 progressBarPointer->setValue(progress);
369 // Show the progress bar.
370 progressBarPointer->show();
373 QSize BrowserWindow::sizeHint() const
375 // Return the default window size.
376 return QSize(1500, 1200);
379 void BrowserWindow::settingsConfigure()
381 // Check to make sure the dialog box isn't already displayed.
382 if (KConfigDialog::exists(QStringLiteral("settings")))
384 // Show the existing config dialog if it is hidden.
385 configDialogPointer->show();
387 // Raise the existing config dialog if it is below other windows.
388 configDialogPointer->raise();
390 // Restore the existing config dialog if it has been minimized.
391 if (configDialogPointer->isMinimized()) {
392 configDialogPointer->showNormal();
395 // Activate the existing config dialog, which brings its virtual desktop into focus.
396 configDialogPointer->activateWindow();
400 // Create the settings widgets.
401 QWidget *privacySettingsWidgetPointer = new QWidget;
402 QWidget *generalSettingsWidgetPointer = new QWidget;
404 // Instantiate the settings UI.
405 Ui::PrivacySettings privacySettingsUi;
406 Ui::GeneralSettings generalSettingsUi;
408 // Setup the UI to display the settings widgets.
409 privacySettingsUi.setupUi(privacySettingsWidgetPointer);
410 generalSettingsUi.setupUi(generalSettingsWidgetPointer);
412 // Get handles for the widgets.
413 QComboBox *userAgentComboBoxPointer = privacySettingsUi.kcfg_userAgent;
414 userAgentLabelPointer = privacySettingsUi.userAgentLabel;
415 QComboBox *searchEngineComboBoxPointer = generalSettingsUi.kcfg_searchEngine;
416 searchEngineLabelPointer = generalSettingsUi.searchEngineLabel;
418 // Populate the combo box labels.
419 updateUserAgentLabel(userAgentComboBoxPointer->currentText());
420 updateSearchEngineLabel(searchEngineComboBoxPointer->currentText());
422 // Update the labels when the combo boxes change.
423 connect(userAgentComboBoxPointer, SIGNAL(currentTextChanged(const QString)), this, SLOT(updateUserAgentLabel(const QString)));
424 connect(searchEngineComboBoxPointer, SIGNAL(currentTextChanged(const QString)), this, SLOT(updateSearchEngineLabel(const QString)));
426 // Instantiate a settings config dialog from the settings.kcfg file.
427 configDialogPointer = new KConfigDialog(this, QStringLiteral("settings"), Settings::self());
429 // Add the settings widgets as config dialog pages.
430 configDialogPointer->addPage(privacySettingsWidgetPointer, i18nc("@title:tab", "Privacy"), QStringLiteral("privacy-browser"));
431 configDialogPointer->addPage(generalSettingsWidgetPointer, i18nc("@title:tab", "General"), QStringLiteral("breeze-settings"));
433 // Delete the config dialog when it is closed.
434 configDialogPointer->setAttribute(Qt::WA_DeleteOnClose);
437 configDialogPointer->show();
439 // TODO. KConfigDialog does not respect expanding size policies. <https://redmine.stoutner.com/issues/823>
440 //configDialogPointer->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
441 //privacySettingsWidgetPointer->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
442 //generalSettingsWidgetPointer->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
443 //configDialogPointer->adjustSize();
445 // Expand the config dialog.
446 configDialogPointer->resize(1000, 500);
448 // Apply the settings when they are updated.
449 connect(configDialogPointer, SIGNAL(settingsChanged(QString)), browserViewPointer, SLOT(applyApplicationSettings()));
450 connect(configDialogPointer, SIGNAL(settingsChanged(QString)), browserViewPointer, SLOT(applyDomainSettingsAndReload()));
454 void BrowserWindow::toggleJavaScript() const
456 // Remove the focus from the URL line edit.
457 urlLineEditPointer->clearFocus();
459 // Toggle JavaScript.
460 browserViewPointer->toggleJavaScript();
463 void BrowserWindow::toggleLocalStorage() const
465 // Remove the focus from the URL line edit.
466 urlLineEditPointer->clearFocus();
468 // Toggle JavaScript.
469 browserViewPointer->toggleLocalStorage();
472 void BrowserWindow::updateDomainSettingsIndicator(const bool &status, const QString &domainSettingsDomain)
474 // Set the domain palette according to the status.
475 if (status) urlLineEditPointer->setPalette(domainSettingsPalette);
476 else urlLineEditPointer->setPalette(noDomainSettingsPalette);
479 currentDomainSettingsDomain = domainSettingsDomain;
482 void BrowserWindow::updateJavaScriptAction(const bool &isEnabled) const
484 // Set the icon according to the status.
485 if (isEnabled) javaScriptActionPointer->setIcon(QIcon(":/icons/javascript-warning"));
486 else javaScriptActionPointer->setIcon(QIcon(":/icons/privacy-mode"));
489 void BrowserWindow::updateLocalStorageAction(const bool &isEnabled) const
491 // Set the icon according to the status.
492 if (isEnabled) localStorageActionPointer->setIcon(QIcon::fromTheme("disk-quota-low"));
493 else localStorageActionPointer->setIcon(QIcon::fromTheme("disk-quota"));
496 void BrowserWindow::updateSearchEngineActions(const QString &searchEngine) const
498 // Initialize the custom search engine flag.
499 bool customSearchEngine = false;
501 if (searchEngine == "Mojeek") // Mojeek.
503 searchEngineMojeekActionPointer->setChecked(true);
505 else if (searchEngine == "Monocles") // Monocles.
507 searchEngineMonoclesActionPointer->setChecked(true);
509 else if (searchEngine == "MetaGer") // MetaGer.
511 searchEngineMetagerActionPointer->setChecked(true);
513 else if (searchEngine == "Google") // Google.
515 searchEngineGoogleActionPointer->setChecked(true);
517 else if (searchEngine == "Bing") // Bing.
519 searchEngineBingActionPointer->setChecked(true);
521 else if (searchEngine == "Yahoo") // Yahoo.
523 searchEngineYahooActionPointer->setChecked(true);
525 else // Custom search engine.
527 // Check the user agent.
528 searchEngineCustomActionPointer->setChecked(true);
530 // Set the custom search engine flag.
531 customSearchEngine = true;
534 // Format the custom search engine.
535 if (customSearchEngine)
537 // Enable the custom search engine.
538 searchEngineCustomActionPointer->setEnabled(true);
540 // Set the custom search engine text.
541 searchEngineCustomActionPointer->setText(searchEngine);
545 // Disable the custom search engine.
546 searchEngineCustomActionPointer->setEnabled(false);
548 // Reset the custom search engine text.
549 searchEngineCustomActionPointer->setText(i18nc("@action", "Custom"));
553 void BrowserWindow::updateUserAgentActions(const QString &userAgent) const
555 // Initialize the custom user agent flag.
556 bool customUserAgent = false;
558 // Check the indicated on-the-fly user agent.
559 if (userAgent == UserAgentHelper::PRIVACY_BROWSER_USER_AGENT) userAgentPrivacyBrowserActionPointer->setChecked(true); // Privacy Browser.
560 else if (userAgent == BrowserView::webEngineDefaultUserAgent) userAgentWebEngineDefaultActionPointer->setChecked(true); // WebEngine default.
561 else if (userAgent == UserAgentHelper::FIREFOX_LINUX_USER_AGENT) userAgentFirefoxLinuxActionPointer->setChecked(true); // Firefox Linux.
562 else if (userAgent == UserAgentHelper::CHROMIUM_LINUX_USER_AGENT) userAgentChromiumLinuxActionPointer->setChecked(true); // Chromium Linux.
563 else if (userAgent == UserAgentHelper::FIREFOX_WINDOWS_USER_AGENT) userAgentFirefoxWindowsActionPointer->setChecked(true); // Firefox Windows.
564 else if (userAgent == UserAgentHelper::CHROME_WINDOWS_USER_AGENT) userAgentChromeWindowsActionPointer->setChecked(true); // Chrome Windows.
565 else if (userAgent == UserAgentHelper::EDGE_WINDOWS_USER_AGENT) userAgentEdgeWindowsActionPointer->setChecked(true); // Edge Windows.
566 else if (userAgent == UserAgentHelper::SAFARI_MACOS_USER_AGENT) userAgentSafariMacosActionPointer->setChecked(true); // Safara macOS.
567 else // Custom user agent.
569 // Check the user agent.
570 userAgentCustomActionPointer->setChecked(true);
572 // Set the custom user agent flag.
573 customUserAgent = true;
577 // Format the custom user agent.
580 // Enable the custom user agent.
581 userAgentCustomActionPointer->setEnabled(true);
583 // Set the custom user agent text.
584 userAgentCustomActionPointer->setText(userAgent);
588 // Disable the custom user agent.
589 userAgentCustomActionPointer->setEnabled(false);
591 // Reset the custom user agent text.
592 userAgentCustomActionPointer->setText(i18nc("@action", "Custom"));
596 void BrowserWindow::updateZoomFactorAction(const double &zoomFactor)
598 // Set the current zoom factor.
599 currentZoomFactor = zoomFactor;
601 // Update the zoom factor action text, formatting the double with 2 decimal places.
602 zoomFactorActionPointer->setText(ki18nc("@action", "Zoom Factor - %1").subs(zoomFactor, 0, '0', 2).toString());
605 void BrowserWindow::updateSearchEngineLabel(const QString &searchEngineString) const
607 // Update the search engine label.
608 searchEngineLabelPointer->setText(SearchEngineHelper::getSearchUrl(searchEngineString));
611 void BrowserWindow::updateUrlLineEdit(const QUrl &newUrl)
613 // Update the URL line edit if it does not have focus.
614 if (!urlLineEditPointer->hasFocus())
616 // Update the URL line edit.
617 urlLineEditPointer->setText(newUrl.toString());
620 // Store the current URL.
624 void BrowserWindow::updateUserAgentLabel(const QString &userAgentDatabaseName) const
626 // Update the user agent label.
627 userAgentLabelPointer->setText(UserAgentHelper::getUserAgentFromDatabaseName(userAgentDatabaseName));