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 userAgentFirefoxLinuxActionPointer = actionCollectionPointer->addAction(QStringLiteral("user_agent_firefox_linux"));
60 userAgentChromiumLinuxActionPointer = actionCollectionPointer->addAction(QStringLiteral("user_agent_chromium_linux"));
61 userAgentFirefoxWindowsActionPointer = actionCollectionPointer->addAction(QStringLiteral("user_agent_firefox_windows"));
62 userAgentChromeWindowsActionPointer = actionCollectionPointer->addAction(QStringLiteral("user_agent_chrome_windows"));
63 userAgentEdgeWindowsActionPointer = actionCollectionPointer->addAction(QStringLiteral("user_agent_edge_windows"));
64 userAgentSafariMacosActionPointer = actionCollectionPointer->addAction(QStringLiteral("user_agent_safari_macos"));
65 userAgentCustomActionPointer = actionCollectionPointer->addAction(QStringLiteral("user_agent_custom"));
66 zoomFactorActionPointer = actionCollectionPointer->addAction(QStringLiteral("zoom_factor"));
67 searchEngineMojeekActionPointer = actionCollectionPointer->addAction(QStringLiteral("search_engine_mojeek"));
68 searchEngineMonoclesActionPointer = actionCollectionPointer->addAction(QStringLiteral("search_engine_monocles"));
69 searchEngineMetagerActionPointer = actionCollectionPointer->addAction(QStringLiteral("search_engine_metager"));
70 searchEngineGoogleActionPointer = actionCollectionPointer->addAction(QStringLiteral("search_engine_google"));
71 searchEngineBingActionPointer = actionCollectionPointer->addAction(QStringLiteral("search_engine_bing"));
72 searchEngineYahooActionPointer = actionCollectionPointer->addAction(QStringLiteral("search_engine_yahoo"));
73 searchEngineCustomActionPointer = actionCollectionPointer->addAction(QStringLiteral("search_engine_custom"));
74 javaScriptActionPointer = actionCollectionPointer->addAction(QStringLiteral("javascript"));
75 localStorageActionPointer = actionCollectionPointer->addAction(QStringLiteral("local_storage"));
76 domainSettingsActionPointer = actionCollectionPointer->addAction(QStringLiteral("domain_settings"));
78 // Create the action groups
79 QActionGroup *userAgentActionGroupPointer = new QActionGroup(this);
80 QActionGroup *searchEngineActionGroupPointer = new QActionGroup(this);
82 // Add the actions to the groups.
83 userAgentActionGroupPointer->addAction(userAgentPrivacyBrowserActionPointer);
84 userAgentActionGroupPointer->addAction(userAgentFirefoxLinuxActionPointer);
85 userAgentActionGroupPointer->addAction(userAgentChromiumLinuxActionPointer);
86 userAgentActionGroupPointer->addAction(userAgentFirefoxWindowsActionPointer);
87 userAgentActionGroupPointer->addAction(userAgentChromeWindowsActionPointer);
88 userAgentActionGroupPointer->addAction(userAgentEdgeWindowsActionPointer);
89 userAgentActionGroupPointer->addAction(userAgentSafariMacosActionPointer);
90 userAgentActionGroupPointer->addAction(userAgentCustomActionPointer);
91 searchEngineActionGroupPointer->addAction(searchEngineMojeekActionPointer);
92 searchEngineActionGroupPointer->addAction(searchEngineMonoclesActionPointer);
93 searchEngineActionGroupPointer->addAction(searchEngineMetagerActionPointer);
94 searchEngineActionGroupPointer->addAction(searchEngineGoogleActionPointer);
95 searchEngineActionGroupPointer->addAction(searchEngineBingActionPointer);
96 searchEngineActionGroupPointer->addAction(searchEngineYahooActionPointer);
97 searchEngineActionGroupPointer->addAction(searchEngineCustomActionPointer);
99 // Set some actions to be checkable.
100 userAgentPrivacyBrowserActionPointer->setCheckable(true);
101 userAgentFirefoxLinuxActionPointer->setCheckable(true);
102 userAgentChromiumLinuxActionPointer->setCheckable(true);
103 userAgentFirefoxWindowsActionPointer->setCheckable(true);
104 userAgentChromeWindowsActionPointer->setCheckable(true);
105 userAgentEdgeWindowsActionPointer->setCheckable(true);
106 userAgentSafariMacosActionPointer->setCheckable(true);
107 userAgentCustomActionPointer->setCheckable(true);
108 searchEngineMojeekActionPointer->setCheckable(true);
109 searchEngineMonoclesActionPointer->setCheckable(true);
110 searchEngineMetagerActionPointer->setCheckable(true);
111 searchEngineGoogleActionPointer->setCheckable(true);
112 searchEngineBingActionPointer->setCheckable(true);
113 searchEngineYahooActionPointer->setCheckable(true);
114 searchEngineCustomActionPointer->setCheckable(true);
116 // Set the non-mutable action text.
117 userAgentPrivacyBrowserActionPointer->setText(UserAgentHelper::PRIVACY_BROWSER_TRANSLATED);
118 userAgentFirefoxLinuxActionPointer->setText(UserAgentHelper::FIREFOX_LINUX_TRANSLATED);
119 userAgentChromiumLinuxActionPointer->setText(UserAgentHelper::CHROMIUM_LINUX_TRANSLATED);
120 userAgentFirefoxWindowsActionPointer->setText(UserAgentHelper::FIREFOX_WINDOWS_TRANSLATED);
121 userAgentChromeWindowsActionPointer->setText(UserAgentHelper::CHROME_WINDOWS_TRANSLATED);
122 userAgentEdgeWindowsActionPointer->setText(UserAgentHelper::EDGE_WINDOWS_TRANSLATED);
123 userAgentSafariMacosActionPointer->setText(UserAgentHelper::SAFARI_MACOS_TRANSLATED);
124 searchEngineMojeekActionPointer->setText(i18nc("Search engine", "Mojeek"));
125 searchEngineMonoclesActionPointer->setText(i18nc("Search engine", "Monocles"));
126 searchEngineMetagerActionPointer->setText(i18nc("Search engine", "MetaGer"));
127 searchEngineGoogleActionPointer->setText(i18nc("Search engine", "Google"));
128 searchEngineBingActionPointer->setText(i18nc("Search engine", "Bing"));
129 searchEngineYahooActionPointer->setText(i18nc("Search engine", "Yahoo"));
130 javaScriptActionPointer->setText(i18nc("JavaScript button", "JavaScript"));
131 localStorageActionPointer->setText(i18nc("Local Storage Button", "Local Storage"));
132 domainSettingsActionPointer->setText(i18nc("Domain Settings button", "Domain Settings"));
134 // Set the action icons.
135 userAgentPrivacyBrowserActionPointer->setIcon(QIcon(":/icons/privacy-mode"));
136 userAgentFirefoxLinuxActionPointer->setIcon(QIcon::fromTheme(QStringLiteral("firefox-esr")));
137 userAgentChromiumLinuxActionPointer->setIcon(QIcon::fromTheme(QStringLiteral("chromium")));
138 userAgentFirefoxWindowsActionPointer->setIcon(QIcon::fromTheme(QStringLiteral("firefox-esr")));
139 userAgentChromeWindowsActionPointer->setIcon(QIcon::fromTheme(QStringLiteral("chromium")));
140 userAgentEdgeWindowsActionPointer->setIcon(QIcon::fromTheme(QStringLiteral("user-group-properties")));
141 userAgentSafariMacosActionPointer->setIcon(QIcon::fromTheme(QStringLiteral("user-group-properties")));
142 userAgentCustomActionPointer->setIcon(QIcon::fromTheme(QStringLiteral("user-group-properties")));
143 searchEngineMojeekActionPointer->setIcon(QIcon::fromTheme(QStringLiteral("search")));
144 searchEngineMonoclesActionPointer->setIcon(QIcon::fromTheme(QStringLiteral("search")));
145 searchEngineMetagerActionPointer->setIcon(QIcon::fromTheme(QStringLiteral("search")));
146 searchEngineGoogleActionPointer->setIcon(QIcon::fromTheme(QStringLiteral("im-google")));
147 searchEngineBingActionPointer->setIcon(QIcon::fromTheme(QStringLiteral("search")));
148 searchEngineYahooActionPointer->setIcon(QIcon::fromTheme(QStringLiteral("im-yahoo")));
149 searchEngineCustomActionPointer->setIcon(QIcon::fromTheme(QStringLiteral("search")));
150 zoomFactorActionPointer->setIcon(QIcon::fromTheme(QStringLiteral("zoom")));
151 domainSettingsActionPointer->setIcon(QIcon::fromTheme(QStringLiteral("network-server-symbolic")));
153 // Update the on-the-fly menus.
154 connect(browserViewPointer, SIGNAL(updateUserAgentActions(QString)), this, SLOT(updateUserAgentActions(QString)));
155 connect(browserViewPointer, SIGNAL(updateZoomFactorAction(double)), this, SLOT(updateZoomFactorAction(double)));
156 connect(browserViewPointer, SIGNAL(updateSearchEngineActions(QString)), this, SLOT(updateSearchEngineActions(QString)));
158 // Apply the on-the-fly settings when selected.
159 connect(userAgentActionGroupPointer, SIGNAL(triggered(QAction*)), browserViewPointer, SLOT(applyOnTheFlyUserAgent(QAction*)));
160 connect(searchEngineActionGroupPointer, SIGNAL(triggered(QAction*)), browserViewPointer, SLOT(applyOnTheFlySearchEngine(QAction*)));
163 connect(zoomFactorActionPointer, SIGNAL(triggered()), this, SLOT(getZoomFactorFromUser()));
165 // Connect the URL toolbar actions.
166 connect(javaScriptActionPointer, SIGNAL(triggered()), this, SLOT(toggleJavaScript()));
167 connect(localStorageActionPointer, SIGNAL(triggered()), this, SLOT(toggleLocalStorage()));
168 connect(domainSettingsActionPointer, SIGNAL(triggered()), this, SLOT(openDomainSettings()));
170 // Update the URL toolbar actions.
171 connect(browserViewPointer, SIGNAL(updateBackAction(bool)), backActionPointer, SLOT(setEnabled(bool)));
172 connect(browserViewPointer, SIGNAL(updateForwardAction(bool)), forwardActionPointer, SLOT(setEnabled(bool)));
173 connect(browserViewPointer, SIGNAL(updateJavaScriptAction(bool)), this, SLOT(updateJavaScriptAction(bool)));
174 connect(browserViewPointer, SIGNAL(updateLocalStorageAction(bool)), this, SLOT(updateLocalStorageAction(bool)));
176 // Setup the GUI based on the browser_ui.rc file.
177 setupGUI(StandardWindowOption::Default, ("browser_ui.rc"));
179 // Get a handle for the URL toolbar.
180 KToolBar *urlToolBarPointer = toolBar(QStringLiteral("url_toolbar"));
182 // Create a URL line edit.
183 urlLineEditPointer = new KLineEdit();
185 // Populate the URL toolbar.
186 urlToolBarPointer->insertWidget(javaScriptActionPointer, urlLineEditPointer);
188 // Load a new URL from the URL line edit.
189 connect(urlLineEditPointer, SIGNAL(returnKeyPressed(const QString)), this, SLOT(loadUrlFromLineEdit(const QString)));
191 // Update the URL line edit on page loads.
192 connect(browserViewPointer, SIGNAL(updateUrlLineEdit(QString)), this, SLOT(updateUrlLineEdit(QString)));
194 // Get a handle for the status bar.
195 QStatusBar *statusBarPointer = statusBar();
197 // Create a progress bar.
198 progressBarPointer = new QProgressBar();
200 // Add the progress bar to to the status bar.
201 statusBarPointer->addPermanentWidget(progressBarPointer);
203 // Update the status bar with the URL when a link is hovered.
204 connect(browserViewPointer, SIGNAL(linkHovered(QString)), statusBarPointer, SLOT(showMessage(QString)));
206 // Update the progress bar.
207 connect(browserViewPointer, SIGNAL(showProgressBar(const int)), this, SLOT(showProgressBar(const int)));
208 connect(browserViewPointer, SIGNAL(hideProgressBar()), progressBarPointer, SLOT(hide()));
210 // Get the URL line edit palettes.
211 noDomainSettingsPalette = urlLineEditPointer->palette();
212 domainSettingsPalette = urlLineEditPointer->palette();
214 // Modify the domain settings palette.
215 domainSettingsPalette.setColor(QPalette::Base, QColor("#C8E6C9"));
217 // Update the applied palette.
218 connect(browserViewPointer, SIGNAL(updateDomainSettingsIndicator(bool)), this, SLOT(updateDomainSettingsIndicator(bool)));
220 // Load the initial website.
221 browserViewPointer->loadInitialWebsite();
224 void BrowserWindow::back() const
226 // Remove the focus from the URL line edit.
227 urlLineEditPointer->clearFocus();
230 browserViewPointer->back();
233 void BrowserWindow::fileNew() const
235 // Display a new instance of Privacy Browser.
236 (new BrowserWindow)->show();
239 void BrowserWindow::forward() const
241 // Remove the focus from the URL line edit.
242 urlLineEditPointer->clearFocus();
245 browserViewPointer->forward();
248 void BrowserWindow::getZoomFactorFromUser()
250 // Create an OK flag.
253 // 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.
254 double newZoomFactor = QInputDialog::getDouble(this, i18nc("The on-the-fly zoom factor dialog title", "On-The-Fly Zoom Factor"),
255 i18nc("The instruction text of the on-the-fly zoom factor dialog", "Enter a zoom factor between 0.25 and 5.00"),
256 currentZoomFactor, .025, 5.00, 2, &okClicked, Qt::WindowFlags(), 0.25);
258 // Update the zoom factor if the user clicked OK.
261 // Update the current zoom factor.
262 currentZoomFactor = newZoomFactor;
264 // Set the new zoom factor.
265 browserViewPointer->applyOnTheFlyZoomFactor(newZoomFactor);
267 // Update the on-the-fly action text.
268 updateZoomFactorAction(newZoomFactor);
272 void BrowserWindow::home() const
274 // Remove the focus from the URL line edit.
275 urlLineEditPointer->clearFocus();
278 browserViewPointer->home();
281 void BrowserWindow::loadUrlFromLineEdit(const QString &url) const
283 // Remove the focus from the URL line edit.
284 urlLineEditPointer->clearFocus();
287 browserViewPointer->loadUrlFromLineEdit(url);
290 void BrowserWindow::openDomainSettings() const
292 // Remove the focus from the URL line edit.
293 urlLineEditPointer->clearFocus();
295 // Instantiate the domain settings window.
296 DomainSettingsDialog *domainSettingsDialogPointer = new DomainSettingsDialog();
298 // Set the dialog window title.
299 domainSettingsDialogPointer->setWindowTitle(i18nc("The domain settings dialog title", "Domain Settings"));
302 domainSettingsDialogPointer->setWindowModality(Qt::WindowModality::WindowModal);;
305 domainSettingsDialogPointer->show();
307 // Reload the tabs when domain settings are updated.
308 connect(domainSettingsDialogPointer, SIGNAL(domainSettingsUpdated()), browserViewPointer, SLOT(applyDomainSettingsAndReload()));
311 void BrowserWindow::refresh() const
313 // Remove the focus from the URL line edit.
314 urlLineEditPointer->clearFocus();
316 // Refresh the web page.
317 browserViewPointer->refresh();
320 void BrowserWindow::showProgressBar(const int &progress) const
322 // Set the progress bar value.
323 progressBarPointer->setValue(progress);
325 // Show the progress bar.
326 progressBarPointer->show();
329 QSize BrowserWindow::sizeHint() const
331 // Return the default window size.
332 return QSize(1500, 1200);
335 void BrowserWindow::settingsConfigure()
337 // Check to make sure the dialog box isn't already displayed.
338 if (KConfigDialog::exists(QStringLiteral("settings")))
340 // Show the existing config dialog if it is hidden.
341 configDialogPointer->show();
343 // Raise the existing config dialog if it is below other windows.
344 configDialogPointer->raise();
346 // Restore the existing config dialog if it has been minimized.
347 if (configDialogPointer->isMinimized()) {
348 configDialogPointer->showNormal();
351 // Activate the existing config dialog, which brings its virtual desktop into focus.
352 configDialogPointer->activateWindow();
356 // Create the settings widgets.
357 QWidget *privacySettingsWidgetPointer = new QWidget;
358 QWidget *generalSettingsWidgetPointer = new QWidget;
360 // Instantiate the settings UI.
361 Ui::PrivacySettings privacySettingsUi;
362 Ui::GeneralSettings generalSettingsUi;
364 // Setup the UI to display the settings widgets.
365 privacySettingsUi.setupUi(privacySettingsWidgetPointer);
366 generalSettingsUi.setupUi(generalSettingsWidgetPointer);
368 // Get handles for the widgets.
369 QComboBox *userAgentComboBoxPointer = privacySettingsUi.kcfg_userAgent;
370 userAgentLabelPointer = privacySettingsUi.userAgentLabel;
371 QComboBox *searchEngineComboBoxPointer = generalSettingsUi.kcfg_searchEngine;
372 searchEngineLabelPointer = generalSettingsUi.searchEngineLabel;
374 // Populate the combo box labels.
375 updateUserAgentLabel(userAgentComboBoxPointer->currentText());
376 updateSearchEngineLabel(searchEngineComboBoxPointer->currentText());
378 // Update the labels when the combo boxes change.
379 connect(userAgentComboBoxPointer, SIGNAL(currentTextChanged(const QString)), this, SLOT(updateUserAgentLabel(const QString)));
380 connect(searchEngineComboBoxPointer, SIGNAL(currentTextChanged(const QString)), this, SLOT(updateSearchEngineLabel(const QString)));
382 // Instantiate a settings config dialog from the settings.kcfg file.
383 configDialogPointer = new KConfigDialog(this, QStringLiteral("settings"), Settings::self());
385 // Add the settings widgets as config dialog pages.
386 configDialogPointer->addPage(privacySettingsWidgetPointer, i18nc("@title:tab", "Privacy"), QStringLiteral("privacy-browser"));
387 configDialogPointer->addPage(generalSettingsWidgetPointer, i18nc("@title:tab", "General"), QStringLiteral("breeze-settings"));
389 // Delete the config dialog when it is closed.
390 configDialogPointer->setAttribute(Qt::WA_DeleteOnClose);
393 configDialogPointer->show();
395 // TODO. KConfigDialog does not respect expanding size policies. <https://redmine.stoutner.com/issues/823>
396 //configDialogPointer->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
397 //privacySettingsWidgetPointer->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
398 //generalSettingsWidgetPointer->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
399 //configDialogPointer->adjustSize();
401 // Expand the config dialog.
402 configDialogPointer->resize(1000, 500);
404 // Apply the settings when they are updated.
405 connect(configDialogPointer, SIGNAL(settingsChanged(QString)), browserViewPointer, SLOT(applyApplicationSettings()));
406 connect(configDialogPointer, SIGNAL(settingsChanged(QString)), browserViewPointer, SLOT(applyDomainSettingsAndReload()));
410 void BrowserWindow::toggleJavaScript() const
412 // Remove the focus from the URL line edit.
413 urlLineEditPointer->clearFocus();
415 // Toggle JavaScript.
416 browserViewPointer->toggleJavaScript();
419 void BrowserWindow::toggleLocalStorage() const
421 // Remove the focus from the URL line edit.
422 urlLineEditPointer->clearFocus();
424 // Toggle JavaScript.
425 browserViewPointer->toggleLocalStorage();
428 void BrowserWindow::updateDomainSettingsIndicator(const bool &status) const
430 // Set the domain palette according to the status.
431 if (status) urlLineEditPointer->setPalette(domainSettingsPalette);
432 else urlLineEditPointer->setPalette(noDomainSettingsPalette);
435 void BrowserWindow::updateJavaScriptAction(const bool &isEnabled) const
437 // Set the icon according to the status.
438 if (isEnabled) javaScriptActionPointer->setIcon(QIcon(":/icons/javascript-warning"));
439 else javaScriptActionPointer->setIcon(QIcon(":/icons/privacy-mode"));
442 void BrowserWindow::updateLocalStorageAction(const bool &isEnabled) const
444 // Set the icon according to the status.
445 if (isEnabled) localStorageActionPointer->setIcon(QIcon::fromTheme("disk-quota-low"));
446 else localStorageActionPointer->setIcon(QIcon::fromTheme("disk-quota"));
449 void BrowserWindow::updateSearchEngineActions(const QString &searchEngine) const
451 // Initialize the custom search engine flag.
452 bool customSearchEngine = false;
454 if (searchEngine == "Mojeek") // Mojeek.
456 searchEngineMojeekActionPointer->setChecked(true);
458 else if (searchEngine == "Monocles") // Monocles.
460 searchEngineMonoclesActionPointer->setChecked(true);
462 else if (searchEngine == "MetaGer") // MetaGer.
464 searchEngineMetagerActionPointer->setChecked(true);
466 else if (searchEngine == "Google") // Google.
468 searchEngineGoogleActionPointer->setChecked(true);
470 else if (searchEngine == "Bing") // Bing.
472 searchEngineBingActionPointer->setChecked(true);
474 else if (searchEngine == "Yahoo") // Yahoo.
476 searchEngineYahooActionPointer->setChecked(true);
478 else // Custom search engine.
480 // Check the user agent.
481 searchEngineCustomActionPointer->setChecked(true);
483 // Set the custom search engine flag.
484 customSearchEngine = true;
487 // Format the custom search engine.
488 if (customSearchEngine)
490 // Enable the custom search engine.
491 searchEngineCustomActionPointer->setEnabled(true);
493 // Set the custom search engine text.
494 searchEngineCustomActionPointer->setText(searchEngine);
498 // Disable the custom search engine.
499 searchEngineCustomActionPointer->setEnabled(false);
501 // Reset the custom search engine text.
502 searchEngineCustomActionPointer->setText(i18nc("@action", "Custom"));
506 void BrowserWindow::updateUserAgentActions(const QString &userAgent) const
508 // Initialize the custom user agent flag.
509 bool customUserAgent = false;
511 // Check the indicated on-the-fly user agent.
512 if (userAgent == UserAgentHelper::PRIVACY_BROWSER_USER_AGENT) userAgentPrivacyBrowserActionPointer->setChecked(true); // Privacy Browser.
513 else if (userAgent == UserAgentHelper::FIREFOX_LINUX_USER_AGENT) userAgentFirefoxLinuxActionPointer->setChecked(true); // Firefox Linux.
514 else if (userAgent == UserAgentHelper::CHROMIUM_LINUX_USER_AGENT) userAgentChromiumLinuxActionPointer->setChecked(true); // Chromium Linux.
515 else if (userAgent == UserAgentHelper::FIREFOX_WINDOWS_USER_AGENT) userAgentFirefoxWindowsActionPointer->setChecked(true); // Firefox Windows.
516 else if (userAgent == UserAgentHelper::CHROME_WINDOWS_USER_AGENT) userAgentChromeWindowsActionPointer->setChecked(true); // Chrome Windows.
517 else if (userAgent == UserAgentHelper::EDGE_WINDOWS_USER_AGENT) userAgentEdgeWindowsActionPointer->setChecked(true); // Edge Windows.
518 else if (userAgent == UserAgentHelper::SAFARI_MACOS_USER_AGENT) userAgentSafariMacosActionPointer->setChecked(true); // Safara macOS.
519 else // Custom user agent.
521 // Check the user agent.
522 userAgentCustomActionPointer->setChecked(true);
524 // Set the custom user agent flag.
525 customUserAgent = true;
529 // Format the custom user agent.
532 // Enable the custom user agent.
533 userAgentCustomActionPointer->setEnabled(true);
535 // Set the custom user agent text.
536 userAgentCustomActionPointer->setText(userAgent);
540 // Disable the custom user agent.
541 userAgentCustomActionPointer->setEnabled(false);
543 // Reset the custom user agent text.
544 userAgentCustomActionPointer->setText(i18nc("@action", "Custom"));
548 void BrowserWindow::updateZoomFactorAction(const double &zoomFactor)
550 // Set the current zoom factor.
551 currentZoomFactor = zoomFactor;
553 // Update the zoom factor action text, formatting the double with 2 decimal places.
554 zoomFactorActionPointer->setText(ki18nc("@action", "Zoom Factor - %1").subs(zoomFactor, 0, '0', 2).toString());
557 void BrowserWindow::updateSearchEngineLabel(const QString &searchEngineString) const
559 // Update the search engine label.
560 searchEngineLabelPointer->setText(SearchEngineHelper::getSearchUrl(searchEngineString));
563 void BrowserWindow::updateUrlLineEdit(const QString &newUrl) const
565 // Update the URL line edit if it does not have focus.
566 if (!urlLineEditPointer->hasFocus())
568 // Update the URL line edit.
569 urlLineEditPointer->setText(newUrl);
573 void BrowserWindow::updateUserAgentLabel(const QString &userAgentDatabaseName) const
575 // Update the user agent label.
576 userAgentLabelPointer->setText(UserAgentHelper::getUserAgentFromDatabaseName(userAgentDatabaseName));