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 domainSettingsActionPointer = actionCollectionPointer->addAction(QStringLiteral("domain_settings"));
77 // Create the action groups
78 QActionGroup *userAgentActionGroupPointer = new QActionGroup(this);
79 QActionGroup *searchEngineActionGroupPointer = new QActionGroup(this);
81 // Add the actions to the groups.
82 userAgentActionGroupPointer->addAction(userAgentPrivacyBrowserActionPointer);
83 userAgentActionGroupPointer->addAction(userAgentFirefoxLinuxActionPointer);
84 userAgentActionGroupPointer->addAction(userAgentChromiumLinuxActionPointer);
85 userAgentActionGroupPointer->addAction(userAgentFirefoxWindowsActionPointer);
86 userAgentActionGroupPointer->addAction(userAgentChromeWindowsActionPointer);
87 userAgentActionGroupPointer->addAction(userAgentEdgeWindowsActionPointer);
88 userAgentActionGroupPointer->addAction(userAgentSafariMacosActionPointer);
89 userAgentActionGroupPointer->addAction(userAgentCustomActionPointer);
90 searchEngineActionGroupPointer->addAction(searchEngineMojeekActionPointer);
91 searchEngineActionGroupPointer->addAction(searchEngineMonoclesActionPointer);
92 searchEngineActionGroupPointer->addAction(searchEngineMetagerActionPointer);
93 searchEngineActionGroupPointer->addAction(searchEngineGoogleActionPointer);
94 searchEngineActionGroupPointer->addAction(searchEngineBingActionPointer);
95 searchEngineActionGroupPointer->addAction(searchEngineYahooActionPointer);
96 searchEngineActionGroupPointer->addAction(searchEngineCustomActionPointer);
98 // Set some actions to be checkable.
99 userAgentPrivacyBrowserActionPointer->setCheckable(true);
100 userAgentFirefoxLinuxActionPointer->setCheckable(true);
101 userAgentChromiumLinuxActionPointer->setCheckable(true);
102 userAgentFirefoxWindowsActionPointer->setCheckable(true);
103 userAgentChromeWindowsActionPointer->setCheckable(true);
104 userAgentEdgeWindowsActionPointer->setCheckable(true);
105 userAgentSafariMacosActionPointer->setCheckable(true);
106 userAgentCustomActionPointer->setCheckable(true);
107 searchEngineMojeekActionPointer->setCheckable(true);
108 searchEngineMonoclesActionPointer->setCheckable(true);
109 searchEngineMetagerActionPointer->setCheckable(true);
110 searchEngineGoogleActionPointer->setCheckable(true);
111 searchEngineBingActionPointer->setCheckable(true);
112 searchEngineYahooActionPointer->setCheckable(true);
113 searchEngineCustomActionPointer->setCheckable(true);
115 // Set the non-mutable action text.
116 userAgentPrivacyBrowserActionPointer->setText(UserAgentHelper::PRIVACY_BROWSER_TRANSLATED);
117 userAgentFirefoxLinuxActionPointer->setText(UserAgentHelper::FIREFOX_LINUX_TRANSLATED);
118 userAgentChromiumLinuxActionPointer->setText(UserAgentHelper::CHROMIUM_LINUX_TRANSLATED);
119 userAgentFirefoxWindowsActionPointer->setText(UserAgentHelper::FIREFOX_WINDOWS_TRANSLATED);
120 userAgentChromeWindowsActionPointer->setText(UserAgentHelper::CHROME_WINDOWS_TRANSLATED);
121 userAgentEdgeWindowsActionPointer->setText(UserAgentHelper::EDGE_WINDOWS_TRANSLATED);
122 userAgentSafariMacosActionPointer->setText(UserAgentHelper::SAFARI_MACOS_TRANSLATED);
123 searchEngineMojeekActionPointer->setText(i18nc("Search engine", "Mojeek"));
124 searchEngineMonoclesActionPointer->setText(i18nc("Search engine", "Monocles"));
125 searchEngineMetagerActionPointer->setText(i18nc("Search engine", "MetaGer"));
126 searchEngineGoogleActionPointer->setText(i18nc("Search engine", "Google"));
127 searchEngineBingActionPointer->setText(i18nc("Search engine", "Bing"));
128 searchEngineYahooActionPointer->setText(i18nc("Search engine", "Yahoo"));
129 javaScriptActionPointer->setText(i18nc("JavaScript button", "JavaScript"));
130 domainSettingsActionPointer->setText(i18nc("Domain Settings button", "Domain Settings"));
132 // Set the action icons.
133 userAgentPrivacyBrowserActionPointer->setIcon(QIcon(":/icons/privacy-mode"));
134 userAgentFirefoxLinuxActionPointer->setIcon(QIcon::fromTheme(QStringLiteral("firefox-esr")));
135 userAgentChromiumLinuxActionPointer->setIcon(QIcon::fromTheme(QStringLiteral("chromium")));
136 userAgentFirefoxWindowsActionPointer->setIcon(QIcon::fromTheme(QStringLiteral("firefox-esr")));
137 userAgentChromeWindowsActionPointer->setIcon(QIcon::fromTheme(QStringLiteral("chromium")));
138 userAgentEdgeWindowsActionPointer->setIcon(QIcon::fromTheme(QStringLiteral("user-group-properties")));
139 userAgentSafariMacosActionPointer->setIcon(QIcon::fromTheme(QStringLiteral("user-group-properties")));
140 userAgentCustomActionPointer->setIcon(QIcon::fromTheme(QStringLiteral("user-group-properties")));
141 searchEngineMojeekActionPointer->setIcon(QIcon::fromTheme(QStringLiteral("search")));
142 searchEngineMonoclesActionPointer->setIcon(QIcon::fromTheme(QStringLiteral("search")));
143 searchEngineMetagerActionPointer->setIcon(QIcon::fromTheme(QStringLiteral("search")));
144 searchEngineGoogleActionPointer->setIcon(QIcon::fromTheme(QStringLiteral("im-google")));
145 searchEngineBingActionPointer->setIcon(QIcon::fromTheme(QStringLiteral("search")));
146 searchEngineYahooActionPointer->setIcon(QIcon::fromTheme(QStringLiteral("im-yahoo")));
147 searchEngineCustomActionPointer->setIcon(QIcon::fromTheme(QStringLiteral("search")));
148 zoomFactorActionPointer->setIcon(QIcon::fromTheme(QStringLiteral("zoom")));
149 domainSettingsActionPointer->setIcon(QIcon::fromTheme(QStringLiteral("network-server-symbolic")));
151 // Update the on-the-fly menus.
152 connect(browserViewPointer, SIGNAL(userAgentUpdated(QString)), this, SLOT(updateOnTheFlyUserAgent(QString)));
153 connect(browserViewPointer, SIGNAL(zoomFactorUpdated(double)), this, SLOT(updateOnTheFlyZoomFactor(double)));
154 connect(browserViewPointer, SIGNAL(searchEngineUpdated(QString)), this, SLOT(updateOnTheFlySearchEngine(QString)));
156 // Apply the on-the-fly settings when selected.
157 connect(userAgentActionGroupPointer, SIGNAL(triggered(QAction*)), browserViewPointer, SLOT(applyOnTheFlyUserAgent(QAction*)));
158 connect(searchEngineActionGroupPointer, SIGNAL(triggered(QAction*)), browserViewPointer, SLOT(applyOnTheFlySearchEngine(QAction*)));
161 connect(zoomFactorActionPointer, SIGNAL(triggered()), this, SLOT(getZoomFactorFromUser()));
163 // Connect the URL toolbar actions.
164 connect(javaScriptActionPointer, SIGNAL(triggered()), this, SLOT(toggleJavaScript()));
165 connect(domainSettingsActionPointer, SIGNAL(triggered()), this, SLOT(openDomainSettings()));
167 // Update the URL toolbar actions.
168 connect(browserViewPointer, SIGNAL(updateBackAction(bool)), backActionPointer, SLOT(setEnabled(bool)));
169 connect(browserViewPointer, SIGNAL(updateForwardAction(bool)), forwardActionPointer, SLOT(setEnabled(bool)));
170 connect(browserViewPointer, SIGNAL(updateJavaScriptAction(bool)), this, SLOT(updateJavaScriptAction(bool)));
172 // Setup the GUI based on the browser_ui.rc file.
173 setupGUI(StandardWindowOption::Default, ("browser_ui.rc"));
175 // Get a handle for the URL toolbar.
176 KToolBar *urlToolBarPointer = toolBar(QStringLiteral("url_toolbar"));
178 // Create a URL line edit.
179 urlLineEditPointer = new KLineEdit();
181 // Populate the URL toolbar.
182 urlToolBarPointer->addWidget(urlLineEditPointer);
183 urlToolBarPointer->addAction(javaScriptActionPointer);
184 urlToolBarPointer->addAction(domainSettingsActionPointer);
186 // Load a new URL from the URL line edit.
187 connect(urlLineEditPointer, SIGNAL(returnKeyPressed(const QString)), this, SLOT(loadUrlFromLineEdit(const QString)));
189 // Update the URL line edit on page loads.
190 connect(browserViewPointer, SIGNAL(updateUrlLineEdit(QString)), this, SLOT(updateUrlLineEdit(QString)));
192 // Get a handle for the status bar.
193 QStatusBar *statusBarPointer = statusBar();
195 // Update the status bar with the URL when a link is hovered.
196 connect(browserViewPointer, SIGNAL(linkHovered(QString)), statusBarPointer, SLOT(showMessage(QString)));
198 // Get the URL line edit palettes.
199 noDomainSettingsPalette = urlLineEditPointer->palette();
200 domainSettingsPalette = urlLineEditPointer->palette();
202 // Modify the domain settings palette.
203 domainSettingsPalette.setColor(QPalette::Base, QColor("#C8E6C9"));
205 // Update the applied palette.
206 connect(browserViewPointer, SIGNAL(updateDomainSettingsIndicator(bool)), this, SLOT(updateDomainSettingsIndicator(bool)));
208 // Load the initial website.
209 browserViewPointer->loadInitialWebsite();
212 void BrowserWindow::back() const
214 // Remove the focus from the URL line edit.
215 urlLineEditPointer->clearFocus();
218 browserViewPointer->back();
221 void BrowserWindow::fileNew() const
223 // Display a new instance of Privacy Browser.
224 (new BrowserWindow)->show();
227 void BrowserWindow::forward() const
229 // Remove the focus from the URL line edit.
230 urlLineEditPointer->clearFocus();
233 browserViewPointer->forward();
236 void BrowserWindow::getZoomFactorFromUser()
238 // Create an OK flag.
241 // 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.
242 double newZoomFactor = QInputDialog::getDouble(this, i18nc("The on-the-fly zoom factor dialog title", "On-The-Fly Zoom Factor"),
243 i18nc("The instruction text of the on-the-fly zoom factor dialog", "Enter a zoom factor between 0.25 and 5.00"),
244 currentZoomFactor, .025, 5.00, 2, &okClicked, Qt::WindowFlags(), 0.25);
246 // Update the zoom factor if the user clicked OK.
249 // Update the current zoom factor.
250 currentZoomFactor = newZoomFactor;
252 // Set the new zoom factor.
253 browserViewPointer->applyOnTheFlyZoomFactor(newZoomFactor);
255 // Update the on-the-fly action text.
256 updateOnTheFlyZoomFactor(newZoomFactor);
260 void BrowserWindow::home() const
262 // Remove the focus from the URL line edit.
263 urlLineEditPointer->clearFocus();
266 browserViewPointer->home();
269 void BrowserWindow::loadUrlFromLineEdit(const QString &url) const
271 // Remove the focus from the URL line edit.
272 urlLineEditPointer->clearFocus();
275 browserViewPointer->loadUrlFromLineEdit(url);
278 void BrowserWindow::openDomainSettings() const
280 // Remove the focus from the URL line edit.
281 urlLineEditPointer->clearFocus();
283 // Instantiate the domain settings window.
284 DomainSettingsDialog *domainSettingsDialogPointer = new DomainSettingsDialog();
286 // Set the dialog window title.
287 domainSettingsDialogPointer->setWindowTitle(i18nc("The domain settings dialog title", "Domain Settings"));
290 domainSettingsDialogPointer->setWindowModality(Qt::WindowModality::WindowModal);;
293 domainSettingsDialogPointer->show();
295 // Reload the tabs when domain settings are updated.
296 connect(domainSettingsDialogPointer, SIGNAL(domainSettingsUpdated()), browserViewPointer, SLOT(applyDomainSettingsAndReload()));
299 void BrowserWindow::refresh() const
301 // Remove the focus from the URL line edit.
302 urlLineEditPointer->clearFocus();
304 // Refresh the web page.
305 browserViewPointer->refresh();
308 void BrowserWindow::toggleJavaScript() const
310 // Remove the focus from the URL line edit.
311 urlLineEditPointer->clearFocus();
313 // Toggle JavaScript.
314 browserViewPointer->toggleJavaScript();
317 QSize BrowserWindow::sizeHint() const
319 // Return the default window size.
320 return QSize(1500, 1200);
323 void BrowserWindow::settingsConfigure()
325 // Check to make sure the dialog box isn't already displayed.
326 if (KConfigDialog::exists(QStringLiteral("settings")))
328 // Show the existing config dialog if it is hidden.
329 configDialogPointer->show();
331 // Raise the existing config dialog if it is below other windows.
332 configDialogPointer->raise();
334 // Restore the existing config dialog if it has been minimized.
335 if (configDialogPointer->isMinimized()) {
336 configDialogPointer->showNormal();
339 // Activate the existing config dialog, which brings its virtual desktop into focus.
340 configDialogPointer->activateWindow();
344 // Create the settings widgets.
345 QWidget *privacySettingsWidgetPointer = new QWidget;
346 QWidget *generalSettingsWidgetPointer = new QWidget;
348 // Instantiate the settings UI.
349 Ui::PrivacySettings privacySettingsUi;
350 Ui::GeneralSettings generalSettingsUi;
352 // Setup the UI to display the settings widgets.
353 privacySettingsUi.setupUi(privacySettingsWidgetPointer);
354 generalSettingsUi.setupUi(generalSettingsWidgetPointer);
356 // Get handles for the widgets.
357 QComboBox *userAgentComboBoxPointer = privacySettingsUi.kcfg_userAgent;
358 userAgentLabelPointer = privacySettingsUi.userAgentLabel;
359 QComboBox *searchEngineComboBoxPointer = generalSettingsUi.kcfg_searchEngine;
360 searchEngineLabelPointer = generalSettingsUi.searchEngineLabel;
362 // Populate the combo box labels.
363 updateUserAgentLabel(userAgentComboBoxPointer->currentText());
364 updateSearchEngineLabel(searchEngineComboBoxPointer->currentText());
366 // Update the labels when the combo boxes change.
367 connect(userAgentComboBoxPointer, SIGNAL(currentTextChanged(const QString)), this, SLOT(updateUserAgentLabel(const QString)));
368 connect(searchEngineComboBoxPointer, SIGNAL(currentTextChanged(const QString)), this, SLOT(updateSearchEngineLabel(const QString)));
370 // Instantiate a settings config dialog from the settings.kcfg file.
371 configDialogPointer = new KConfigDialog(this, QStringLiteral("settings"), Settings::self());
373 // Add the settings widgets as config dialog pages.
374 configDialogPointer->addPage(privacySettingsWidgetPointer, i18nc("@title:tab", "Privacy"), QStringLiteral("privacy-browser"));
375 configDialogPointer->addPage(generalSettingsWidgetPointer, i18nc("@title:tab", "General"), QStringLiteral("breeze-settings"));
377 // Delete the config dialog when it is closed.
378 configDialogPointer->setAttribute(Qt::WA_DeleteOnClose);
381 configDialogPointer->show();
383 // TODO. KConfigDialog does not respect expanding size policies. <https://redmine.stoutner.com/issues/823>
384 //configDialogPointer->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
385 //privacySettingsWidgetPointer->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
386 //generalSettingsWidgetPointer->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
387 //configDialogPointer->adjustSize();
389 // Expand the config dialog.
390 configDialogPointer->resize(1000, 500);
392 // Apply the settings when they are updated.
393 connect(configDialogPointer, SIGNAL(settingsChanged(QString)), browserViewPointer, SLOT(applyApplicationSettings()));
394 connect(configDialogPointer, SIGNAL(settingsChanged(QString)), browserViewPointer, SLOT(applyDomainSettingsAndReload()));
398 void BrowserWindow::updateDomainSettingsIndicator(const bool &status) const
400 // Set the domain palette according to the status.
401 if (status) urlLineEditPointer->setPalette(domainSettingsPalette);
402 else urlLineEditPointer->setPalette(noDomainSettingsPalette);
405 void BrowserWindow::updateJavaScriptAction(const bool &isEnabled) const
407 // Set the icon according to the status.
408 if (isEnabled) javaScriptActionPointer->setIcon(QIcon(":/icons/javascript-warning"));
409 else javaScriptActionPointer->setIcon(QIcon(":/icons/privacy-mode"));
412 void BrowserWindow::updateOnTheFlySearchEngine(const QString &searchEngine) const
414 // Initialize the custom search engine flag.
415 bool customSearchEngine = false;
417 if (searchEngine == "Mojeek") // Mojeek.
419 searchEngineMojeekActionPointer->setChecked(true);
421 else if (searchEngine == "Monocles") // Monocles.
423 searchEngineMonoclesActionPointer->setChecked(true);
425 else if (searchEngine == "MetaGer") // MetaGer.
427 searchEngineMetagerActionPointer->setChecked(true);
429 else if (searchEngine == "Google") // Google.
431 searchEngineGoogleActionPointer->setChecked(true);
433 else if (searchEngine == "Bing") // Bing.
435 searchEngineBingActionPointer->setChecked(true);
437 else if (searchEngine == "Yahoo") // Yahoo.
439 searchEngineYahooActionPointer->setChecked(true);
441 else // Custom search engine.
443 // Check the user agent.
444 searchEngineCustomActionPointer->setChecked(true);
446 // Set the custom search engine flag.
447 customSearchEngine = true;
450 // Format the custom search engine.
451 if (customSearchEngine)
453 // Enable the custom search engine.
454 searchEngineCustomActionPointer->setEnabled(true);
456 // Set the custom search engine text.
457 searchEngineCustomActionPointer->setText(searchEngine);
461 // Disable the custom search engine.
462 searchEngineCustomActionPointer->setEnabled(false);
464 // Reset the custom search engine text.
465 searchEngineCustomActionPointer->setText(i18nc("@action", "Custom"));
469 void BrowserWindow::updateOnTheFlyUserAgent(const QString &userAgent) const
471 // Initialize the custom user agent flag.
472 bool customUserAgent = false;
474 // Check the indicated on-the-fly user agent.
475 if (userAgent == UserAgentHelper::PRIVACY_BROWSER_USER_AGENT) userAgentPrivacyBrowserActionPointer->setChecked(true); // Privacy Browser.
476 else if (userAgent == UserAgentHelper::FIREFOX_LINUX_USER_AGENT) userAgentFirefoxLinuxActionPointer->setChecked(true); // Firefox Linux.
477 else if (userAgent == UserAgentHelper::CHROMIUM_LINUX_USER_AGENT) userAgentChromiumLinuxActionPointer->setChecked(true); // Chromium Linux.
478 else if (userAgent == UserAgentHelper::FIREFOX_WINDOWS_USER_AGENT) userAgentFirefoxWindowsActionPointer->setChecked(true); // Firefox Windows.
479 else if (userAgent == UserAgentHelper::CHROME_WINDOWS_USER_AGENT) userAgentChromeWindowsActionPointer->setChecked(true); // Chrome Windows.
480 else if (userAgent == UserAgentHelper::EDGE_WINDOWS_USER_AGENT) userAgentEdgeWindowsActionPointer->setChecked(true); // Edge Windows.
481 else if (userAgent == UserAgentHelper::SAFARI_MACOS_USER_AGENT) userAgentSafariMacosActionPointer->setChecked(true); // Safara macOS.
482 else // Custom user agent.
484 // Check the user agent.
485 userAgentCustomActionPointer->setChecked(true);
487 // Set the custom user agent flag.
488 customUserAgent = true;
492 // Format the custom user agent.
495 // Enable the custom user agent.
496 userAgentCustomActionPointer->setEnabled(true);
498 // Set the custom user agent text.
499 userAgentCustomActionPointer->setText(userAgent);
503 // Disable the custom user agent.
504 userAgentCustomActionPointer->setEnabled(false);
506 // Reset the custom user agent text.
507 userAgentCustomActionPointer->setText(i18nc("@action", "Custom"));
511 void BrowserWindow::updateOnTheFlyZoomFactor(const double &zoomFactor)
513 // Set the current zoom factor.
514 currentZoomFactor = zoomFactor;
516 // Update the zoom factor action text, formatting the double with 2 decimal places.
517 zoomFactorActionPointer->setText(ki18nc("@action", "Zoom Factor - %1").subs(zoomFactor, 0, '0', 2).toString());
520 void BrowserWindow::updateSearchEngineLabel(const QString &searchEngineString) const
522 // Update the search engine label.
523 searchEngineLabelPointer->setText(SearchEngineHelper::getSearchUrl(searchEngineString));
526 void BrowserWindow::updateUrlLineEdit(const QString &newUrl) const
528 // Update the URL line edit if it does not have focus.
529 if (!urlLineEditPointer->hasFocus())
531 // Update the URL line edit.
532 urlLineEditPointer->setText(newUrl);
536 void BrowserWindow::updateUserAgentLabel(const QString &userAgentDatabaseName) const
538 // Update the user agent label.
539 userAgentLabelPointer->setText(UserAgentHelper::getUserAgentFromDatabaseName(userAgentDatabaseName));