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("settings-configure")));
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 // Add an edit or add domain settings action to the URL line edit.
186 QAction *addOrEditDomainSettingsActionPointer = urlLineEditPointer->addAction(QIcon::fromTheme("settings-configure"), QLineEdit::TrailingPosition);
188 // Add or edit the current domain settings.
189 connect(addOrEditDomainSettingsActionPointer, SIGNAL(triggered()), this, SLOT(addOrEditDomainSettings()));
191 // Populate the URL toolbar.
192 urlToolBarPointer->insertWidget(javaScriptActionPointer, urlLineEditPointer);
194 // Load a new URL from the URL line edit.
195 connect(urlLineEditPointer, SIGNAL(returnKeyPressed(const QString)), this, SLOT(loadUrlFromLineEdit(const QString)));
197 // Update the URL line edit on page loads.
198 connect(browserViewPointer, SIGNAL(updateUrlLineEdit(QUrl)), this, SLOT(updateUrlLineEdit(QUrl)));
200 // Get a handle for the status bar.
201 QStatusBar *statusBarPointer = statusBar();
203 // Create a progress bar.
204 progressBarPointer = new QProgressBar();
206 // Add the progress bar to to the status bar.
207 statusBarPointer->addPermanentWidget(progressBarPointer);
209 // Update the status bar with the URL when a link is hovered.
210 connect(browserViewPointer, SIGNAL(linkHovered(QString)), statusBarPointer, SLOT(showMessage(QString)));
212 // Update the progress bar.
213 connect(browserViewPointer, SIGNAL(showProgressBar(const int)), this, SLOT(showProgressBar(const int)));
214 connect(browserViewPointer, SIGNAL(hideProgressBar()), progressBarPointer, SLOT(hide()));
216 // Get the URL line edit palettes.
217 noDomainSettingsPalette = urlLineEditPointer->palette();
218 domainSettingsPalette = urlLineEditPointer->palette();
220 // Modify the domain settings palette.
221 domainSettingsPalette.setColor(QPalette::Base, QColor("#C8E6C9"));
223 // Update the applied palette.
224 connect(browserViewPointer, SIGNAL(updateDomainSettingsIndicator(bool, QString)), this, SLOT(updateDomainSettingsIndicator(bool, QString)));
226 // Load the initial website.
227 browserViewPointer->loadInitialWebsite();
230 void BrowserWindow::addOrEditDomainSettings() const
232 // Remove the focus from the URL line edit.
233 urlLineEditPointer->clearFocus();
235 // Create the domain settings dialog pointer.
236 DomainSettingsDialog *domainSettingsDialogPointer;
238 // Run the commands according to the current domain settings status.
239 if (currentDomainSettingsDomain == "") // Domain settings are not currently applied.
241 // Instruct the domain settings dialog to add a new domain.
242 domainSettingsDialogPointer = new DomainSettingsDialog(DomainSettingsDialog::ADD_DOMAIN, currentUrl.host());
244 else // Domain settings are currently applied.
246 // Instruct the domain settings dialog to edit the current domain.
247 domainSettingsDialogPointer = new DomainSettingsDialog(DomainSettingsDialog::EDIT_DOMAIN, currentDomainSettingsDomain);
250 // Set the dialog window title.
251 domainSettingsDialogPointer->setWindowTitle(i18nc("The domain settings dialog title", "Domain Settings"));
254 domainSettingsDialogPointer->setWindowModality(Qt::WindowModality::WindowModal);;
257 domainSettingsDialogPointer->show();
259 // Reload the tabs when domain settings are updated.
260 connect(domainSettingsDialogPointer, SIGNAL(domainSettingsUpdated()), browserViewPointer, SLOT(applyDomainSettingsAndReload()));
263 void BrowserWindow::back() const
265 // Remove the focus from the URL line edit.
266 urlLineEditPointer->clearFocus();
269 browserViewPointer->back();
272 void BrowserWindow::fileNew() const
274 // Display a new instance of Privacy Browser.
275 (new BrowserWindow)->show();
278 void BrowserWindow::forward() const
280 // Remove the focus from the URL line edit.
281 urlLineEditPointer->clearFocus();
284 browserViewPointer->forward();
287 void BrowserWindow::getZoomFactorFromUser()
289 // Create an OK flag.
292 // 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.
293 double newZoomFactor = QInputDialog::getDouble(this, i18nc("The on-the-fly zoom factor dialog title", "On-The-Fly Zoom Factor"),
294 i18nc("The instruction text of the on-the-fly zoom factor dialog", "Enter a zoom factor between 0.25 and 5.00"),
295 currentZoomFactor, .025, 5.00, 2, &okClicked, Qt::WindowFlags(), 0.25);
297 // Update the zoom factor if the user clicked OK.
300 // Update the current zoom factor.
301 currentZoomFactor = newZoomFactor;
303 // Set the new zoom factor.
304 browserViewPointer->applyOnTheFlyZoomFactor(newZoomFactor);
306 // Update the on-the-fly action text.
307 updateZoomFactorAction(newZoomFactor);
311 void BrowserWindow::home() const
313 // Remove the focus from the URL line edit.
314 urlLineEditPointer->clearFocus();
317 browserViewPointer->home();
320 void BrowserWindow::loadUrlFromLineEdit(const QString &url) const
322 // Remove the focus from the URL line edit.
323 urlLineEditPointer->clearFocus();
326 browserViewPointer->loadUrlFromLineEdit(url);
329 void BrowserWindow::openDomainSettings() const
331 // Remove the focus from the URL line edit.
332 urlLineEditPointer->clearFocus();
334 // Instantiate the domain settings dialog.
335 DomainSettingsDialog *domainSettingsDialogPointer = new DomainSettingsDialog();
337 // Set the dialog window title.
338 domainSettingsDialogPointer->setWindowTitle(i18nc("The domain settings dialog title", "Domain Settings"));
341 domainSettingsDialogPointer->setWindowModality(Qt::WindowModality::WindowModal);;
344 domainSettingsDialogPointer->show();
346 // Reload the tabs when domain settings are updated.
347 connect(domainSettingsDialogPointer, SIGNAL(domainSettingsUpdated()), browserViewPointer, SLOT(applyDomainSettingsAndReload()));
350 void BrowserWindow::refresh() const
352 // Remove the focus from the URL line edit.
353 urlLineEditPointer->clearFocus();
355 // Refresh the web page.
356 browserViewPointer->refresh();
359 void BrowserWindow::showProgressBar(const int &progress) const
361 // Set the progress bar value.
362 progressBarPointer->setValue(progress);
364 // Show the progress bar.
365 progressBarPointer->show();
368 QSize BrowserWindow::sizeHint() const
370 // Return the default window size.
371 return QSize(1500, 1200);
374 void BrowserWindow::settingsConfigure()
376 // Check to make sure the dialog box isn't already displayed.
377 if (KConfigDialog::exists(QStringLiteral("settings")))
379 // Show the existing config dialog if it is hidden.
380 configDialogPointer->show();
382 // Raise the existing config dialog if it is below other windows.
383 configDialogPointer->raise();
385 // Restore the existing config dialog if it has been minimized.
386 if (configDialogPointer->isMinimized()) {
387 configDialogPointer->showNormal();
390 // Activate the existing config dialog, which brings its virtual desktop into focus.
391 configDialogPointer->activateWindow();
395 // Create the settings widgets.
396 QWidget *privacySettingsWidgetPointer = new QWidget;
397 QWidget *generalSettingsWidgetPointer = new QWidget;
399 // Instantiate the settings UI.
400 Ui::PrivacySettings privacySettingsUi;
401 Ui::GeneralSettings generalSettingsUi;
403 // Setup the UI to display the settings widgets.
404 privacySettingsUi.setupUi(privacySettingsWidgetPointer);
405 generalSettingsUi.setupUi(generalSettingsWidgetPointer);
407 // Get handles for the widgets.
408 QComboBox *userAgentComboBoxPointer = privacySettingsUi.kcfg_userAgent;
409 userAgentLabelPointer = privacySettingsUi.userAgentLabel;
410 QComboBox *searchEngineComboBoxPointer = generalSettingsUi.kcfg_searchEngine;
411 searchEngineLabelPointer = generalSettingsUi.searchEngineLabel;
413 // Populate the combo box labels.
414 updateUserAgentLabel(userAgentComboBoxPointer->currentText());
415 updateSearchEngineLabel(searchEngineComboBoxPointer->currentText());
417 // Update the labels when the combo boxes change.
418 connect(userAgentComboBoxPointer, SIGNAL(currentTextChanged(const QString)), this, SLOT(updateUserAgentLabel(const QString)));
419 connect(searchEngineComboBoxPointer, SIGNAL(currentTextChanged(const QString)), this, SLOT(updateSearchEngineLabel(const QString)));
421 // Instantiate a settings config dialog from the settings.kcfg file.
422 configDialogPointer = new KConfigDialog(this, QStringLiteral("settings"), Settings::self());
424 // Add the settings widgets as config dialog pages.
425 configDialogPointer->addPage(privacySettingsWidgetPointer, i18nc("@title:tab", "Privacy"), QStringLiteral("privacy-browser"));
426 configDialogPointer->addPage(generalSettingsWidgetPointer, i18nc("@title:tab", "General"), QStringLiteral("breeze-settings"));
428 // Delete the config dialog when it is closed.
429 configDialogPointer->setAttribute(Qt::WA_DeleteOnClose);
432 configDialogPointer->show();
434 // TODO. KConfigDialog does not respect expanding size policies. <https://redmine.stoutner.com/issues/823>
435 //configDialogPointer->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
436 //privacySettingsWidgetPointer->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
437 //generalSettingsWidgetPointer->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
438 //configDialogPointer->adjustSize();
440 // Expand the config dialog.
441 configDialogPointer->resize(1000, 500);
443 // Apply the settings when they are updated.
444 connect(configDialogPointer, SIGNAL(settingsChanged(QString)), browserViewPointer, SLOT(applyApplicationSettings()));
445 connect(configDialogPointer, SIGNAL(settingsChanged(QString)), browserViewPointer, SLOT(applyDomainSettingsAndReload()));
449 void BrowserWindow::toggleJavaScript() const
451 // Remove the focus from the URL line edit.
452 urlLineEditPointer->clearFocus();
454 // Toggle JavaScript.
455 browserViewPointer->toggleJavaScript();
458 void BrowserWindow::toggleLocalStorage() const
460 // Remove the focus from the URL line edit.
461 urlLineEditPointer->clearFocus();
463 // Toggle JavaScript.
464 browserViewPointer->toggleLocalStorage();
467 void BrowserWindow::updateDomainSettingsIndicator(const bool &status, const QString &domainSettingsDomain)
469 // Set the domain palette according to the status.
470 if (status) urlLineEditPointer->setPalette(domainSettingsPalette);
471 else urlLineEditPointer->setPalette(noDomainSettingsPalette);
474 currentDomainSettingsDomain = domainSettingsDomain;
477 void BrowserWindow::updateJavaScriptAction(const bool &isEnabled) const
479 // Set the icon according to the status.
480 if (isEnabled) javaScriptActionPointer->setIcon(QIcon(":/icons/javascript-warning"));
481 else javaScriptActionPointer->setIcon(QIcon(":/icons/privacy-mode"));
484 void BrowserWindow::updateLocalStorageAction(const bool &isEnabled) const
486 // Set the icon according to the status.
487 if (isEnabled) localStorageActionPointer->setIcon(QIcon::fromTheme("disk-quota-low"));
488 else localStorageActionPointer->setIcon(QIcon::fromTheme("disk-quota"));
491 void BrowserWindow::updateSearchEngineActions(const QString &searchEngine) const
493 // Initialize the custom search engine flag.
494 bool customSearchEngine = false;
496 if (searchEngine == "Mojeek") // Mojeek.
498 searchEngineMojeekActionPointer->setChecked(true);
500 else if (searchEngine == "Monocles") // Monocles.
502 searchEngineMonoclesActionPointer->setChecked(true);
504 else if (searchEngine == "MetaGer") // MetaGer.
506 searchEngineMetagerActionPointer->setChecked(true);
508 else if (searchEngine == "Google") // Google.
510 searchEngineGoogleActionPointer->setChecked(true);
512 else if (searchEngine == "Bing") // Bing.
514 searchEngineBingActionPointer->setChecked(true);
516 else if (searchEngine == "Yahoo") // Yahoo.
518 searchEngineYahooActionPointer->setChecked(true);
520 else // Custom search engine.
522 // Check the user agent.
523 searchEngineCustomActionPointer->setChecked(true);
525 // Set the custom search engine flag.
526 customSearchEngine = true;
529 // Format the custom search engine.
530 if (customSearchEngine)
532 // Enable the custom search engine.
533 searchEngineCustomActionPointer->setEnabled(true);
535 // Set the custom search engine text.
536 searchEngineCustomActionPointer->setText(searchEngine);
540 // Disable the custom search engine.
541 searchEngineCustomActionPointer->setEnabled(false);
543 // Reset the custom search engine text.
544 searchEngineCustomActionPointer->setText(i18nc("@action", "Custom"));
548 void BrowserWindow::updateUserAgentActions(const QString &userAgent) const
550 // Initialize the custom user agent flag.
551 bool customUserAgent = false;
553 // Check the indicated on-the-fly user agent.
554 if (userAgent == UserAgentHelper::PRIVACY_BROWSER_USER_AGENT) userAgentPrivacyBrowserActionPointer->setChecked(true); // Privacy Browser.
555 else if (userAgent == UserAgentHelper::FIREFOX_LINUX_USER_AGENT) userAgentFirefoxLinuxActionPointer->setChecked(true); // Firefox Linux.
556 else if (userAgent == UserAgentHelper::CHROMIUM_LINUX_USER_AGENT) userAgentChromiumLinuxActionPointer->setChecked(true); // Chromium Linux.
557 else if (userAgent == UserAgentHelper::FIREFOX_WINDOWS_USER_AGENT) userAgentFirefoxWindowsActionPointer->setChecked(true); // Firefox Windows.
558 else if (userAgent == UserAgentHelper::CHROME_WINDOWS_USER_AGENT) userAgentChromeWindowsActionPointer->setChecked(true); // Chrome Windows.
559 else if (userAgent == UserAgentHelper::EDGE_WINDOWS_USER_AGENT) userAgentEdgeWindowsActionPointer->setChecked(true); // Edge Windows.
560 else if (userAgent == UserAgentHelper::SAFARI_MACOS_USER_AGENT) userAgentSafariMacosActionPointer->setChecked(true); // Safara macOS.
561 else // Custom user agent.
563 // Check the user agent.
564 userAgentCustomActionPointer->setChecked(true);
566 // Set the custom user agent flag.
567 customUserAgent = true;
571 // Format the custom user agent.
574 // Enable the custom user agent.
575 userAgentCustomActionPointer->setEnabled(true);
577 // Set the custom user agent text.
578 userAgentCustomActionPointer->setText(userAgent);
582 // Disable the custom user agent.
583 userAgentCustomActionPointer->setEnabled(false);
585 // Reset the custom user agent text.
586 userAgentCustomActionPointer->setText(i18nc("@action", "Custom"));
590 void BrowserWindow::updateZoomFactorAction(const double &zoomFactor)
592 // Set the current zoom factor.
593 currentZoomFactor = zoomFactor;
595 // Update the zoom factor action text, formatting the double with 2 decimal places.
596 zoomFactorActionPointer->setText(ki18nc("@action", "Zoom Factor - %1").subs(zoomFactor, 0, '0', 2).toString());
599 void BrowserWindow::updateSearchEngineLabel(const QString &searchEngineString) const
601 // Update the search engine label.
602 searchEngineLabelPointer->setText(SearchEngineHelper::getSearchUrl(searchEngineString));
605 void BrowserWindow::updateUrlLineEdit(const QUrl &newUrl)
607 // Update the URL line edit if it does not have focus.
608 if (!urlLineEditPointer->hasFocus())
610 // Update the URL line edit.
611 urlLineEditPointer->setText(newUrl.toString());
614 // Store the current URL.
618 void BrowserWindow::updateUserAgentLabel(const QString &userAgentDatabaseName) const
620 // Update the user agent label.
621 userAgentLabelPointer->setText(UserAgentHelper::getUserAgentFromDatabaseName(userAgentDatabaseName));