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 // Clear the URL line edit focus when requested.
222 connect(browserViewPointer, SIGNAL(clearUrlLineEditFocus()), this, SLOT(clearUrlLineEditFocus()));
224 // Get the URL line edit palettes.
225 noDomainSettingsPalette = urlLineEditPointer->palette();
226 domainSettingsPalette = urlLineEditPointer->palette();
228 // Modify the domain settings palette.
229 domainSettingsPalette.setColor(QPalette::Base, QColor("#C8E6C9"));
231 // Update the applied palette.
232 connect(browserViewPointer, SIGNAL(updateDomainSettingsIndicator(bool, QString)), this, SLOT(updateDomainSettingsIndicator(bool, QString)));
234 // Load the initial website.
235 browserViewPointer->loadInitialWebsite();
238 void BrowserWindow::addOrEditDomainSettings() const
240 // Remove the focus from the URL line edit.
241 urlLineEditPointer->clearFocus();
243 // Create the domain settings dialog pointer.
244 DomainSettingsDialog *domainSettingsDialogPointer;
246 // Run the commands according to the current domain settings status.
247 if (currentDomainSettingsDomain == "") // Domain settings are not currently applied.
249 // Instruct the domain settings dialog to add a new domain.
250 domainSettingsDialogPointer = new DomainSettingsDialog(DomainSettingsDialog::ADD_DOMAIN, currentUrl.host());
252 else // Domain settings are currently applied.
254 // Instruct the domain settings dialog to edit the current domain.
255 domainSettingsDialogPointer = new DomainSettingsDialog(DomainSettingsDialog::EDIT_DOMAIN, currentDomainSettingsDomain);
258 // Set the dialog window title.
259 domainSettingsDialogPointer->setWindowTitle(i18nc("The domain settings dialog title", "Domain Settings"));
262 domainSettingsDialogPointer->setWindowModality(Qt::WindowModality::WindowModal);;
265 domainSettingsDialogPointer->show();
267 // Reload the tabs when domain settings are updated.
268 connect(domainSettingsDialogPointer, SIGNAL(domainSettingsUpdated()), browserViewPointer, SLOT(applyDomainSettingsAndReload()));
271 void BrowserWindow::back() const
273 // Remove the focus from the URL line edit.
274 urlLineEditPointer->clearFocus();
277 browserViewPointer->back();
280 void BrowserWindow::clearUrlLineEditFocus() const
282 // Remove the focus from the URL line edit.
283 urlLineEditPointer->clearFocus();
286 void BrowserWindow::fileNew() const
288 // Display a new instance of Privacy Browser.
289 (new BrowserWindow)->show();
292 void BrowserWindow::forward() const
294 // Remove the focus from the URL line edit.
295 urlLineEditPointer->clearFocus();
298 browserViewPointer->forward();
301 void BrowserWindow::getZoomFactorFromUser()
303 // Create an OK flag.
306 // 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.
307 double newZoomFactor = QInputDialog::getDouble(this, i18nc("The on-the-fly zoom factor dialog title", "On-The-Fly Zoom Factor"),
308 i18nc("The instruction text of the on-the-fly zoom factor dialog", "Enter a zoom factor between 0.25 and 5.00"),
309 currentZoomFactor, .025, 5.00, 2, &okClicked, Qt::WindowFlags(), 0.25);
311 // Update the zoom factor if the user clicked OK.
314 // Update the current zoom factor.
315 currentZoomFactor = newZoomFactor;
317 // Set the new zoom factor.
318 browserViewPointer->applyOnTheFlyZoomFactor(newZoomFactor);
320 // Update the on-the-fly action text.
321 updateZoomFactorAction(newZoomFactor);
325 void BrowserWindow::home() const
327 // Remove the focus from the URL line edit.
328 urlLineEditPointer->clearFocus();
331 browserViewPointer->home();
334 void BrowserWindow::loadUrlFromLineEdit(const QString &url) const
336 // Remove the focus from the URL line edit.
337 urlLineEditPointer->clearFocus();
340 browserViewPointer->loadUrlFromLineEdit(url);
343 void BrowserWindow::openDomainSettings() const
345 // Remove the focus from the URL line edit.
346 urlLineEditPointer->clearFocus();
348 // Instantiate the domain settings dialog.
349 DomainSettingsDialog *domainSettingsDialogPointer = new DomainSettingsDialog();
351 // Set the dialog window title.
352 domainSettingsDialogPointer->setWindowTitle(i18nc("The domain settings dialog title", "Domain Settings"));
355 domainSettingsDialogPointer->setWindowModality(Qt::WindowModality::WindowModal);;
358 domainSettingsDialogPointer->show();
360 // Reload the tabs when domain settings are updated.
361 connect(domainSettingsDialogPointer, SIGNAL(domainSettingsUpdated()), browserViewPointer, SLOT(applyDomainSettingsAndReload()));
364 void BrowserWindow::refresh() const
366 // Remove the focus from the URL line edit.
367 urlLineEditPointer->clearFocus();
369 // Refresh the web page.
370 browserViewPointer->refresh();
373 void BrowserWindow::showProgressBar(const int &progress) const
375 // Set the progress bar value.
376 progressBarPointer->setValue(progress);
378 // Show the progress bar.
379 progressBarPointer->show();
382 QSize BrowserWindow::sizeHint() const
384 // Return the default window size.
385 return QSize(1500, 1200);
388 void BrowserWindow::settingsConfigure()
390 // Check to make sure the dialog box isn't already displayed.
391 if (KConfigDialog::exists(QStringLiteral("settings")))
393 // Show the existing config dialog if it is hidden.
394 configDialogPointer->show();
396 // Raise the existing config dialog if it is below other windows.
397 configDialogPointer->raise();
399 // Restore the existing config dialog if it has been minimized.
400 if (configDialogPointer->isMinimized()) {
401 configDialogPointer->showNormal();
404 // Activate the existing config dialog, which brings its virtual desktop into focus.
405 configDialogPointer->activateWindow();
409 // Create the settings widgets.
410 QWidget *privacySettingsWidgetPointer = new QWidget;
411 QWidget *generalSettingsWidgetPointer = new QWidget;
413 // Instantiate the settings UI.
414 Ui::PrivacySettings privacySettingsUi;
415 Ui::GeneralSettings generalSettingsUi;
417 // Setup the UI to display the settings widgets.
418 privacySettingsUi.setupUi(privacySettingsWidgetPointer);
419 generalSettingsUi.setupUi(generalSettingsWidgetPointer);
421 // Get handles for the widgets.
422 QComboBox *userAgentComboBoxPointer = privacySettingsUi.kcfg_userAgent;
423 userAgentLabelPointer = privacySettingsUi.userAgentLabel;
424 QComboBox *searchEngineComboBoxPointer = generalSettingsUi.kcfg_searchEngine;
425 searchEngineLabelPointer = generalSettingsUi.searchEngineLabel;
427 // Populate the combo box labels.
428 updateUserAgentLabel(userAgentComboBoxPointer->currentText());
429 updateSearchEngineLabel(searchEngineComboBoxPointer->currentText());
431 // Update the labels when the combo boxes change.
432 connect(userAgentComboBoxPointer, SIGNAL(currentTextChanged(const QString)), this, SLOT(updateUserAgentLabel(const QString)));
433 connect(searchEngineComboBoxPointer, SIGNAL(currentTextChanged(const QString)), this, SLOT(updateSearchEngineLabel(const QString)));
435 // Instantiate a settings config dialog from the settings.kcfg file.
436 configDialogPointer = new KConfigDialog(this, QStringLiteral("settings"), Settings::self());
438 // Add the settings widgets as config dialog pages.
439 configDialogPointer->addPage(privacySettingsWidgetPointer, i18nc("@title:tab", "Privacy"), QStringLiteral("privacy-browser"));
440 configDialogPointer->addPage(generalSettingsWidgetPointer, i18nc("@title:tab", "General"), QStringLiteral("breeze-settings"));
442 // Delete the config dialog when it is closed.
443 configDialogPointer->setAttribute(Qt::WA_DeleteOnClose);
446 configDialogPointer->show();
448 // TODO. KConfigDialog does not respect expanding size policies. <https://redmine.stoutner.com/issues/823>
449 //configDialogPointer->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
450 //privacySettingsWidgetPointer->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
451 //generalSettingsWidgetPointer->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
452 //configDialogPointer->adjustSize();
454 // Expand the config dialog.
455 configDialogPointer->resize(1000, 500);
457 // Apply the settings when they are updated.
458 connect(configDialogPointer, SIGNAL(settingsChanged(QString)), browserViewPointer, SLOT(applyApplicationSettings()));
459 connect(configDialogPointer, SIGNAL(settingsChanged(QString)), browserViewPointer, SLOT(applyDomainSettingsAndReload()));
463 void BrowserWindow::toggleJavaScript() const
465 // Remove the focus from the URL line edit.
466 urlLineEditPointer->clearFocus();
468 // Toggle JavaScript.
469 browserViewPointer->toggleJavaScript();
472 void BrowserWindow::toggleLocalStorage() const
474 // Remove the focus from the URL line edit.
475 urlLineEditPointer->clearFocus();
477 // Toggle JavaScript.
478 browserViewPointer->toggleLocalStorage();
481 void BrowserWindow::updateDomainSettingsIndicator(const bool &status, const QString &domainSettingsDomain)
483 // Set the domain palette according to the status.
484 if (status) urlLineEditPointer->setPalette(domainSettingsPalette);
485 else urlLineEditPointer->setPalette(noDomainSettingsPalette);
488 currentDomainSettingsDomain = domainSettingsDomain;
491 void BrowserWindow::updateJavaScriptAction(const bool &isEnabled) const
493 // Set the icon according to the status.
494 if (isEnabled) javaScriptActionPointer->setIcon(QIcon(":/icons/javascript-warning"));
495 else javaScriptActionPointer->setIcon(QIcon(":/icons/privacy-mode"));
498 void BrowserWindow::updateLocalStorageAction(const bool &isEnabled) const
500 // Set the icon according to the status.
501 if (isEnabled) localStorageActionPointer->setIcon(QIcon::fromTheme("disk-quota-low"));
502 else localStorageActionPointer->setIcon(QIcon::fromTheme("disk-quota"));
505 void BrowserWindow::updateSearchEngineActions(const QString &searchEngine) const
507 // Initialize the custom search engine flag.
508 bool customSearchEngine = false;
510 if (searchEngine == "Mojeek") // Mojeek.
512 searchEngineMojeekActionPointer->setChecked(true);
514 else if (searchEngine == "Monocles") // Monocles.
516 searchEngineMonoclesActionPointer->setChecked(true);
518 else if (searchEngine == "MetaGer") // MetaGer.
520 searchEngineMetagerActionPointer->setChecked(true);
522 else if (searchEngine == "Google") // Google.
524 searchEngineGoogleActionPointer->setChecked(true);
526 else if (searchEngine == "Bing") // Bing.
528 searchEngineBingActionPointer->setChecked(true);
530 else if (searchEngine == "Yahoo") // Yahoo.
532 searchEngineYahooActionPointer->setChecked(true);
534 else // Custom search engine.
536 // Check the user agent.
537 searchEngineCustomActionPointer->setChecked(true);
539 // Set the custom search engine flag.
540 customSearchEngine = true;
543 // Format the custom search engine.
544 if (customSearchEngine)
546 // Enable the custom search engine.
547 searchEngineCustomActionPointer->setEnabled(true);
549 // Set the custom search engine text.
550 searchEngineCustomActionPointer->setText(searchEngine);
554 // Disable the custom search engine.
555 searchEngineCustomActionPointer->setEnabled(false);
557 // Reset the custom search engine text.
558 searchEngineCustomActionPointer->setText(i18nc("@action", "Custom"));
562 void BrowserWindow::updateUserAgentActions(const QString &userAgent) const
564 // Initialize the custom user agent flag.
565 bool customUserAgent = false;
567 // Check the indicated on-the-fly user agent.
568 if (userAgent == UserAgentHelper::PRIVACY_BROWSER_USER_AGENT) userAgentPrivacyBrowserActionPointer->setChecked(true); // Privacy Browser.
569 else if (userAgent == BrowserView::webEngineDefaultUserAgent) userAgentWebEngineDefaultActionPointer->setChecked(true); // WebEngine default.
570 else if (userAgent == UserAgentHelper::FIREFOX_LINUX_USER_AGENT) userAgentFirefoxLinuxActionPointer->setChecked(true); // Firefox Linux.
571 else if (userAgent == UserAgentHelper::CHROMIUM_LINUX_USER_AGENT) userAgentChromiumLinuxActionPointer->setChecked(true); // Chromium Linux.
572 else if (userAgent == UserAgentHelper::FIREFOX_WINDOWS_USER_AGENT) userAgentFirefoxWindowsActionPointer->setChecked(true); // Firefox Windows.
573 else if (userAgent == UserAgentHelper::CHROME_WINDOWS_USER_AGENT) userAgentChromeWindowsActionPointer->setChecked(true); // Chrome Windows.
574 else if (userAgent == UserAgentHelper::EDGE_WINDOWS_USER_AGENT) userAgentEdgeWindowsActionPointer->setChecked(true); // Edge Windows.
575 else if (userAgent == UserAgentHelper::SAFARI_MACOS_USER_AGENT) userAgentSafariMacosActionPointer->setChecked(true); // Safara macOS.
576 else // Custom user agent.
578 // Check the user agent.
579 userAgentCustomActionPointer->setChecked(true);
581 // Set the custom user agent flag.
582 customUserAgent = true;
586 // Format the custom user agent.
589 // Enable the custom user agent.
590 userAgentCustomActionPointer->setEnabled(true);
592 // Set the custom user agent text.
593 userAgentCustomActionPointer->setText(userAgent);
597 // Disable the custom user agent.
598 userAgentCustomActionPointer->setEnabled(false);
600 // Reset the custom user agent text.
601 userAgentCustomActionPointer->setText(i18nc("@action", "Custom"));
605 void BrowserWindow::updateZoomFactorAction(const double &zoomFactor)
607 // Set the current zoom factor.
608 currentZoomFactor = zoomFactor;
610 // Update the zoom factor action text, formatting the double with 2 decimal places.
611 zoomFactorActionPointer->setText(ki18nc("@action", "Zoom Factor - %1").subs(zoomFactor, 0, '0', 2).toString());
614 void BrowserWindow::updateSearchEngineLabel(const QString &searchEngineString) const
616 // Update the search engine label.
617 searchEngineLabelPointer->setText(SearchEngineHelper::getSearchUrl(searchEngineString));
620 void BrowserWindow::updateUrlLineEdit(const QUrl &newUrl)
622 // Update the URL line edit if it does not have focus.
623 if (!urlLineEditPointer->hasFocus())
625 // Update the URL line edit.
626 urlLineEditPointer->setText(newUrl.toString());
629 // Store the current URL.
633 void BrowserWindow::updateUserAgentLabel(const QString &userAgentDatabaseName) const
635 // Update the user agent label.
636 userAgentLabelPointer->setText(UserAgentHelper::getUserAgentFromDatabaseName(userAgentDatabaseName));