Set the default window size.
[PrivacyBrowserPC.git] / src / windows / BrowserWindow.cpp
1 /*
2  * Copyright © 2022 Soren Stoutner <soren@stoutner.com>.
3  *
4  * This file is part of Privacy Browser PC <https://www.stoutner.com/privacy-browser-pc>.
5  *
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.
10  *
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.
15  *
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/>.
18  */
19
20 // Application headers.
21 #include "BrowserWindow.h"
22 #include "Settings.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"
28
29 // KDE Frameworks headers.
30 #include <KActionCollection>
31 #include <KToolBar>
32
33 // Qt toolkit headers.
34 #include <QInputDialog>
35 #include <QStatusBar>
36
37 BrowserWindow::BrowserWindow() : KXmlGuiWindow()
38 {
39     // Instantiate the main view pointer.
40     browserViewPointer = new BrowserView(this);
41
42     // Set the main view as the central widget.
43     setCentralWidget(browserViewPointer);
44
45     // Get a handle for the action collection.
46     KActionCollection *actionCollectionPointer = this->actionCollection();
47
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);
56
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"));
76
77     // Create the action groups
78     QActionGroup *userAgentActionGroupPointer = new QActionGroup(this);
79     QActionGroup *searchEngineActionGroupPointer = new QActionGroup(this);
80
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);
97
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);
114
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"));
131
132     // Set the action icons.
133     //refreshActionPointer->setIcon(QIcon::fromTheme(QStringLiteral("view-refresh")));
134     domainSettingsActionPointer->setIcon(QIcon::fromTheme(QStringLiteral("network-server-symbolic")));
135
136     // Update the on-the-fly menus.
137     connect(browserViewPointer, SIGNAL(userAgentUpdated(QString)), this, SLOT(updateOnTheFlyUserAgent(QString)));
138     connect(browserViewPointer, SIGNAL(zoomFactorUpdated(double)), this, SLOT(updateOnTheFlyZoomFactor(double)));
139     connect(browserViewPointer, SIGNAL(searchEngineUpdated(QString)), this, SLOT(updateOnTheFlySearchEngine(QString)));
140
141     // Apply the on-the-fly settings when selected.
142     connect(userAgentActionGroupPointer, SIGNAL(triggered(QAction*)), browserViewPointer, SLOT(applyOnTheFlyUserAgent(QAction*)));
143     connect(searchEngineActionGroupPointer, SIGNAL(triggered(QAction*)), browserViewPointer, SLOT(applyOnTheFlySearchEngine(QAction*)));
144
145     // Display dialogs.
146     connect(zoomFactorActionPointer, SIGNAL(triggered()), this, SLOT(getZoomFactorFromUser()));
147
148     // Connect the URL toolbar actions.
149     connect(javaScriptActionPointer, SIGNAL(triggered()), this, SLOT(toggleJavaScript()));
150     connect(domainSettingsActionPointer, SIGNAL(triggered()), this, SLOT(openDomainSettings()));
151
152     // Update the URL toolbar actions.
153     connect(browserViewPointer, SIGNAL(updateBackAction(bool)), backActionPointer, SLOT(setEnabled(bool)));
154     connect(browserViewPointer, SIGNAL(updateForwardAction(bool)), forwardActionPointer, SLOT(setEnabled(bool)));
155     connect(browserViewPointer, SIGNAL(updateJavaScriptAction(bool)), this, SLOT(updateJavaScriptAction(bool)));
156
157     // Setup the GUI based on the browser_ui.rc file.
158     setupGUI(StandardWindowOption::Default, ("browser_ui.rc"));
159
160     // Get a handle for the URL toolbar.
161     KToolBar *urlToolBarPointer = toolBar(QStringLiteral("url_toolbar"));
162
163     // Create a URL line edit.
164     urlLineEditPointer = new KLineEdit();
165
166     // Populate the URL toolbar.
167     urlToolBarPointer->addWidget(urlLineEditPointer);
168     urlToolBarPointer->addAction(javaScriptActionPointer);
169     urlToolBarPointer->addAction(domainSettingsActionPointer);
170
171     // Load a new URL from the URL line edit.
172     connect(urlLineEditPointer, SIGNAL(returnKeyPressed(const QString)), this, SLOT(loadUrlFromLineEdit(const QString)));
173
174     // Update the URL line edit on page loads.
175     connect(browserViewPointer, SIGNAL(updateUrlLineEdit(QString)), this, SLOT(updateUrlLineEdit(QString)));
176
177     // Get a handle for the status bar.
178     QStatusBar *statusBarPointer = statusBar();
179
180     // Update the status bar with the URL when a link is hovered.
181     connect(browserViewPointer, SIGNAL(linkHovered(QString)), statusBarPointer, SLOT(showMessage(QString)));
182
183     // Get the URL line edit palettes.
184     noDomainSettingsPalette = urlLineEditPointer->palette();
185     domainSettingsPalette = urlLineEditPointer->palette();
186
187     // Modify the domain settings palette.
188     domainSettingsPalette.setColor(QPalette::Base, QColor("#C8E6C9"));
189
190     // Update the applied palette.
191     connect(browserViewPointer, SIGNAL(updateDomainSettingsIndicator(bool)), this, SLOT(updateDomainSettingsIndicator(bool)));
192
193     // Load the initial website.
194     browserViewPointer->loadInitialWebsite();
195 }
196
197 void BrowserWindow::back() const
198 {
199     // Remove the focus from the URL line edit.
200     urlLineEditPointer->clearFocus();
201
202     // Go back.
203     browserViewPointer->back();
204 }
205
206 void BrowserWindow::fileNew() const
207 {
208     // Display a new instance of Privacy Browser.
209     (new BrowserWindow)->show();
210 }
211
212 void BrowserWindow::forward() const
213 {
214     // Remove the focus from the URL line edit.
215     urlLineEditPointer->clearFocus();
216
217     // Go forward.
218     browserViewPointer->forward();
219 }
220
221 void BrowserWindow::getZoomFactorFromUser()
222 {
223     // Create an OK flag.
224     bool okClicked;
225
226     // 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.
227     double newZoomFactor = QInputDialog::getDouble(this, i18nc("The on-the-fly zoom factor dialog title", "On-The-Fly Zoom Factor"),
228                                                    i18nc("The instruction text of the on-the-fly zoom factor dialog", "Enter a zoom factor between 0.25 and 5.00"),
229                                                    currentZoomFactor, .025, 5.00, 2, &okClicked, Qt::WindowFlags(), 0.25);
230
231     // Update the zoom factor if the user clicked OK.
232     if (okClicked)
233     {
234         // Update the current zoom factor.
235         currentZoomFactor = newZoomFactor;
236
237         // Set the new zoom factor.
238         browserViewPointer->applyOnTheFlyZoomFactor(newZoomFactor);
239
240         // Update the on-the-fly action text.
241         updateOnTheFlyZoomFactor(newZoomFactor);
242     }
243 }
244
245 void BrowserWindow::home() const
246 {
247     // Remove the focus from the URL line edit.
248     urlLineEditPointer->clearFocus();
249
250     // Go home.
251     browserViewPointer->home();
252 }
253
254 void BrowserWindow::loadUrlFromLineEdit(const QString &url) const
255 {
256     // Remove the focus from the URL line edit.
257     urlLineEditPointer->clearFocus();
258
259     // Load the URL.
260     browserViewPointer->loadUrlFromLineEdit(url);
261 }
262
263 void BrowserWindow::openDomainSettings() const
264 {
265     // Remove the focus from the URL line edit.
266     urlLineEditPointer->clearFocus();
267
268     // Instantiate the domain settings window.
269     DomainSettingsDialog *domainSettingsDialogPointer = new DomainSettingsDialog();
270
271     // Set the dialog window title.
272     domainSettingsDialogPointer->setWindowTitle(i18nc("The domain settings dialog title", "Domain Settings"));
273
274     // Set the modality.
275     domainSettingsDialogPointer->setWindowModality(Qt::WindowModality::WindowModal);;
276
277     // Show the dialog.
278     domainSettingsDialogPointer->show();
279
280     // Reload the tabs when domain settings are updated.
281     connect(domainSettingsDialogPointer, SIGNAL(domainSettingsUpdated()), browserViewPointer, SLOT(applyDomainSettingsAndReload()));
282 }
283
284 void BrowserWindow::refresh() const
285 {
286     // Remove the focus from the URL line edit.
287     urlLineEditPointer->clearFocus();
288
289     // Refresh the web page.
290     browserViewPointer->refresh();
291 }
292
293 void BrowserWindow::toggleJavaScript() const
294 {
295     // Remove the focus from the URL line edit.
296     urlLineEditPointer->clearFocus();
297
298     // Toggle JavaScript.
299     browserViewPointer->toggleJavaScript();
300 }
301
302 QSize BrowserWindow::sizeHint() const
303 {
304     // Return the default window size.
305     return QSize(1500, 1200);
306 }
307
308 void BrowserWindow::settingsConfigure()
309 {
310     // Check to make sure the dialog box isn't already displayed.
311     if (KConfigDialog::exists(QStringLiteral("settings")))
312     {
313         // Show the existing config dialog if it is hidden.
314         configDialogPointer->show();
315
316         // Raise the existing config dialog if it is below other windows.
317         configDialogPointer->raise();
318
319         // Restore the existing config dialog if it has been minimized.
320         if (configDialogPointer->isMinimized()) {
321             configDialogPointer->showNormal();
322         }
323
324         // Activate the existing config dialog, which brings its virtual desktop into focus.
325         configDialogPointer->activateWindow();
326     }
327     else
328     {
329         // Create the settings widgets.
330         QWidget *privacySettingsWidgetPointer = new QWidget;
331         QWidget *generalSettingsWidgetPointer = new QWidget;
332
333         // Instantiate the settings UI.
334         Ui::PrivacySettings privacySettingsUi;
335         Ui::GeneralSettings generalSettingsUi;
336
337         // Setup the UI to display the settings widgets.
338         privacySettingsUi.setupUi(privacySettingsWidgetPointer);
339         generalSettingsUi.setupUi(generalSettingsWidgetPointer);
340
341         // Get handles for the widgets.
342         QComboBox *userAgentComboBoxPointer = privacySettingsUi.kcfg_userAgent;
343         userAgentLabelPointer = privacySettingsUi.userAgentLabel;
344         QComboBox *searchEngineComboBoxPointer = generalSettingsUi.kcfg_searchEngine;
345         searchEngineLabelPointer = generalSettingsUi.searchEngineLabel;
346
347         // Populate the combo box labels.
348         updateUserAgentLabel(userAgentComboBoxPointer->currentText());
349         updateSearchEngineLabel(searchEngineComboBoxPointer->currentText());
350
351         // Update the labels when the combo boxes change.
352         connect(userAgentComboBoxPointer, SIGNAL(currentTextChanged(const QString)), this, SLOT(updateUserAgentLabel(const QString)));
353         connect(searchEngineComboBoxPointer, SIGNAL(currentTextChanged(const QString)), this, SLOT(updateSearchEngineLabel(const QString)));
354
355         // Instantiate a settings config dialog from the settings.kcfg file.
356         configDialogPointer = new KConfigDialog(this, QStringLiteral("settings"), Settings::self());
357
358         // Add the settings widgets as config dialog pages.
359         configDialogPointer->addPage(privacySettingsWidgetPointer, i18nc("@title:tab", "Privacy"), QStringLiteral("privacy-browser"));
360         configDialogPointer->addPage(generalSettingsWidgetPointer, i18nc("@title:tab", "General"), QStringLiteral("breeze-settings"));
361
362         // Delete the config dialog when it is closed.
363         configDialogPointer->setAttribute(Qt::WA_DeleteOnClose);
364
365         // Make it so.
366         configDialogPointer->show();
367
368         // TODO.  KConfigDialog does not respect expanding size policies.  <https://redmine.stoutner.com/issues/823>
369         //configDialogPointer->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
370         //privacySettingsWidgetPointer->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
371         //generalSettingsWidgetPointer->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
372         //configDialogPointer->adjustSize();
373
374         // Expand the config dialog.
375         configDialogPointer->resize(1000, 500);
376
377         // Apply the settings when they are updated.
378         connect(configDialogPointer, SIGNAL(settingsChanged(QString)), browserViewPointer, SLOT(applyApplicationSettings()));
379         connect(configDialogPointer, SIGNAL(settingsChanged(QString)), browserViewPointer, SLOT(applyDomainSettingsAndReload()));
380     }
381 }
382
383 void BrowserWindow::updateDomainSettingsIndicator(const bool &status) const
384 {
385     // Set the domain palette according to the status.
386     if (status) urlLineEditPointer->setPalette(domainSettingsPalette);
387     else urlLineEditPointer->setPalette(noDomainSettingsPalette);
388 }
389
390 void BrowserWindow::updateJavaScriptAction(const bool &isEnabled) const
391 {
392     // Set the icon according to the status.
393     if (isEnabled) javaScriptActionPointer->setIcon(QIcon(":/icons/javascript-warning"));
394     else javaScriptActionPointer->setIcon(QIcon(":/icons/privacy-mode"));
395 }
396
397 void BrowserWindow::updateOnTheFlySearchEngine(const QString &searchEngine) const
398 {
399     // Initialize the custom search engine flag.
400     bool customSearchEngine = false;
401
402     if (searchEngine == "Mojeek")  // Mojeek.
403     {
404         searchEngineMojeekActionPointer->setChecked(true);
405     }
406     else if (searchEngine == "Monocles")  // Monocles.
407     {
408         searchEngineMonoclesActionPointer->setChecked(true);
409     }
410     else if (searchEngine == "MetaGer")  // MetaGer.
411     {
412         searchEngineMetagerActionPointer->setChecked(true);
413     }
414     else if (searchEngine == "Google")  // Google.
415     {
416         searchEngineGoogleActionPointer->setChecked(true);
417     }
418     else if (searchEngine == "Bing")  // Bing.
419     {
420         searchEngineBingActionPointer->setChecked(true);
421     }
422     else if (searchEngine == "Yahoo")  // Yahoo.
423     {
424         searchEngineYahooActionPointer->setChecked(true);
425     }
426     else  // Custom search engine.
427     {
428         // Check the user agent.
429         searchEngineCustomActionPointer->setChecked(true);
430
431         // Set the custom search engine flag.
432         customSearchEngine = true;
433     }
434
435     // Format the custom search engine.
436     if (customSearchEngine)
437     {
438         // Enable the custom search engine.
439         searchEngineCustomActionPointer->setEnabled(true);
440
441         // Set the custom search engine text.
442         searchEngineCustomActionPointer->setText(searchEngine);
443     }
444     else
445     {
446         // Disable the custom search engine.
447         searchEngineCustomActionPointer->setEnabled(false);
448
449         // Reset the custom search engine text.
450         searchEngineCustomActionPointer->setText(i18nc("@action", "Custom"));
451     }
452 }
453
454 void BrowserWindow::updateOnTheFlyUserAgent(const QString &userAgent) const
455 {
456     // Initialize the custom user agent flag.
457     bool customUserAgent = false;
458
459     // Check the indicated on-the-fly user agent.
460     if (userAgent == UserAgentHelper::PRIVACY_BROWSER_USER_AGENT) userAgentPrivacyBrowserActionPointer->setChecked(true);  // Privacy Browser.
461     else if (userAgent == UserAgentHelper::FIREFOX_LINUX_USER_AGENT) userAgentFirefoxLinuxActionPointer->setChecked(true);  // Firefox Linux.
462     else if (userAgent == UserAgentHelper::CHROMIUM_LINUX_USER_AGENT) userAgentChromiumLinuxActionPointer->setChecked(true);  // Chromium Linux.
463     else if (userAgent == UserAgentHelper::FIREFOX_WINDOWS_USER_AGENT) userAgentFirefoxWindowsActionPointer->setChecked(true);  // Firefox Windows.
464     else if (userAgent == UserAgentHelper::CHROME_WINDOWS_USER_AGENT) userAgentChromeWindowsActionPointer->setChecked(true);  // Chrome Windows.
465     else if (userAgent == UserAgentHelper::EDGE_WINDOWS_USER_AGENT) userAgentEdgeWindowsActionPointer->setChecked(true);  // Edge Windows.
466     else if (userAgent == UserAgentHelper::SAFARI_MACOS_USER_AGENT) userAgentSafariMacosActionPointer->setChecked(true);  // Safara macOS.
467     else  // Custom user agent.
468     {
469         // Check the user agent.
470         userAgentCustomActionPointer->setChecked(true);
471
472         // Set the custom user agent flag.
473         customUserAgent = true;
474     }
475
476
477     // Format the custom user agent.
478     if (customUserAgent)
479     {
480         // Enable the custom user agent.
481         userAgentCustomActionPointer->setEnabled(true);
482
483         // Set the custom user agent text.
484         userAgentCustomActionPointer->setText(userAgent);
485     }
486     else
487     {
488         // Disable the custom user agent.
489         userAgentCustomActionPointer->setEnabled(false);
490
491         // Reset the custom user agent text.
492         userAgentCustomActionPointer->setText(i18nc("@action", "Custom"));
493     }
494 }
495
496 void BrowserWindow::updateOnTheFlyZoomFactor(const double &zoomFactor)
497 {
498     // Set the current zoom factor.
499     currentZoomFactor = Settings::zoomFactor();
500
501     // Update the zoom factor action text, formatting the double with 2 decimal places.
502     zoomFactorActionPointer->setText(ki18nc("@action", "Zoom Factor - %1").subs(zoomFactor, 0, '0', 2).toString());
503 }
504
505 void BrowserWindow::updateSearchEngineLabel(const QString &searchEngineString) const
506 {
507     // Update the search engine label.
508     searchEngineLabelPointer->setText(SearchEngineHelper::getSearchUrl(searchEngineString));
509 }
510
511 void BrowserWindow::updateUrlLineEdit(const QString &newUrl) const
512 {
513     // Update the URL line edit if it does not have focus.
514     if (!urlLineEditPointer->hasFocus())
515     {
516         // Update the URL line edit.
517         urlLineEditPointer->setText(newUrl);
518     }
519 }
520
521 void BrowserWindow::updateUserAgentLabel(const QString &userAgentDatabaseName) const
522 {
523     // Update the user agent label.
524     userAgentLabelPointer->setText(UserAgentHelper::getUserAgentFromDatabaseName(userAgentDatabaseName));
525 }