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/CookiesDialog.h"
26 #include "dialogs/DomainSettingsDialog.h"
27 #include "helpers/SearchEngineHelper.h"
28 #include "helpers/UserAgentHelper.h"
30 // KDE Frameworks headers.
31 #include <KActionCollection>
32 #include <KColorScheme>
35 // Qt toolkit headers.
36 #include <QFileDialog>
37 #include <QInputDialog>
38 #include <QNetworkCookie>
42 #include <QWebEngineFindTextResult>
44 // Construct the class.
45 BrowserWindow::BrowserWindow(bool firstWindow) : KXmlGuiWindow()
47 // Initialize the variables.
48 javaScriptEnabled = false;
49 localStorageEnabled = false;
51 // Instantiate the privacy tab widget pointer.
52 tabWidgetPointer = new TabWidget(this);
54 // Set the privacy tab widget as the central widget.
55 setCentralWidget(tabWidgetPointer);
57 // Get a handle for the action collection.
58 KActionCollection *actionCollectionPointer = this->actionCollection();
60 // Add the standard actions.
61 KStandardAction::openNew(this, SLOT(fileNew()), actionCollectionPointer);
62 KStandardAction::print(tabWidgetPointer, SLOT(print()), actionCollectionPointer);
63 KStandardAction::printPreview(tabWidgetPointer, SLOT(printPreview()), actionCollectionPointer);
64 KStandardAction::quit(qApp, SLOT(closeAllWindows()), actionCollectionPointer);
65 KStandardAction::redisplay(this, SLOT(refresh()), actionCollectionPointer);
66 fullScreenActionPointer = KStandardAction::fullScreen(this, SLOT(toggleFullScreen()), this, actionCollectionPointer);
67 QAction *backActionPointer = KStandardAction::back(this, SLOT(back()), actionCollectionPointer);
68 QAction *forwardActionPointer = KStandardAction::forward(this, SLOT(forward()), actionCollectionPointer);
69 KStandardAction::home(this, SLOT(home()), actionCollectionPointer);
70 KStandardAction::preferences(this, SLOT(showSettingsDialog()), actionCollectionPointer);
71 KStandardAction::find(this, SLOT(focusFindLineEdit()), actionCollectionPointer);
72 QAction *findNextActionPointer = KStandardAction::findNext(this, SLOT(findNext()), actionCollectionPointer);
73 KStandardAction::findPrev(this, SLOT(findPrevious()), actionCollectionPointer);
75 // Add the custom actions.
76 userAgentPrivacyBrowserActionPointer = actionCollectionPointer->addAction(QStringLiteral("user_agent_privacy_browser"));
77 userAgentWebEngineDefaultActionPointer = actionCollectionPointer->addAction(QStringLiteral("user_agent_webengine_default"));
78 userAgentFirefoxLinuxActionPointer = actionCollectionPointer->addAction(QStringLiteral("user_agent_firefox_linux"));
79 userAgentChromiumLinuxActionPointer = actionCollectionPointer->addAction(QStringLiteral("user_agent_chromium_linux"));
80 userAgentFirefoxWindowsActionPointer = actionCollectionPointer->addAction(QStringLiteral("user_agent_firefox_windows"));
81 userAgentChromeWindowsActionPointer = actionCollectionPointer->addAction(QStringLiteral("user_agent_chrome_windows"));
82 userAgentEdgeWindowsActionPointer = actionCollectionPointer->addAction(QStringLiteral("user_agent_edge_windows"));
83 userAgentSafariMacosActionPointer = actionCollectionPointer->addAction(QStringLiteral("user_agent_safari_macos"));
84 userAgentCustomActionPointer = actionCollectionPointer->addAction(QStringLiteral("user_agent_custom"));
85 zoomFactorActionPointer = actionCollectionPointer->addAction(QStringLiteral("zoom_factor"));
86 searchEngineMojeekActionPointer = actionCollectionPointer->addAction(QStringLiteral("search_engine_mojeek"));
87 searchEngineMonoclesActionPointer = actionCollectionPointer->addAction(QStringLiteral("search_engine_monocles"));
88 searchEngineMetagerActionPointer = actionCollectionPointer->addAction(QStringLiteral("search_engine_metager"));
89 searchEngineGoogleActionPointer = actionCollectionPointer->addAction(QStringLiteral("search_engine_google"));
90 searchEngineBingActionPointer = actionCollectionPointer->addAction(QStringLiteral("search_engine_bing"));
91 searchEngineYahooActionPointer = actionCollectionPointer->addAction(QStringLiteral("search_engine_yahoo"));
92 searchEngineCustomActionPointer = actionCollectionPointer->addAction(QStringLiteral("search_engine_custom"));
93 QAction *domainSettingsActionPointer = actionCollectionPointer->addAction(QStringLiteral("domain_settings"));
94 cookiesActionPointer = actionCollectionPointer->addAction(QStringLiteral("cookies"));
95 javaScriptActionPointer = actionCollectionPointer->addAction(QStringLiteral("javascript"));
96 localStorageActionPointer = actionCollectionPointer->addAction(QStringLiteral("local_storage"));
97 domStorageActionPointer = actionCollectionPointer->addAction(QStringLiteral("dom_storage"));
98 findCaseSensitiveActionPointer = actionCollectionPointer->addAction(QStringLiteral("find_case_sensitive"));
100 // Create the action groups
101 QActionGroup *userAgentActionGroupPointer = new QActionGroup(this);
102 QActionGroup *searchEngineActionGroupPointer = new QActionGroup(this);
104 // Add the actions to the groups.
105 userAgentActionGroupPointer->addAction(userAgentPrivacyBrowserActionPointer);
106 userAgentActionGroupPointer->addAction(userAgentWebEngineDefaultActionPointer);
107 userAgentActionGroupPointer->addAction(userAgentFirefoxLinuxActionPointer);
108 userAgentActionGroupPointer->addAction(userAgentChromiumLinuxActionPointer);
109 userAgentActionGroupPointer->addAction(userAgentFirefoxWindowsActionPointer);
110 userAgentActionGroupPointer->addAction(userAgentChromeWindowsActionPointer);
111 userAgentActionGroupPointer->addAction(userAgentEdgeWindowsActionPointer);
112 userAgentActionGroupPointer->addAction(userAgentSafariMacosActionPointer);
113 userAgentActionGroupPointer->addAction(userAgentCustomActionPointer);
114 searchEngineActionGroupPointer->addAction(searchEngineMojeekActionPointer);
115 searchEngineActionGroupPointer->addAction(searchEngineMonoclesActionPointer);
116 searchEngineActionGroupPointer->addAction(searchEngineMetagerActionPointer);
117 searchEngineActionGroupPointer->addAction(searchEngineGoogleActionPointer);
118 searchEngineActionGroupPointer->addAction(searchEngineBingActionPointer);
119 searchEngineActionGroupPointer->addAction(searchEngineYahooActionPointer);
120 searchEngineActionGroupPointer->addAction(searchEngineCustomActionPointer);
122 // Set some actions to be checkable.
123 javaScriptActionPointer->setCheckable(true);
124 localStorageActionPointer->setCheckable(true);
125 domStorageActionPointer->setCheckable(true);
126 findCaseSensitiveActionPointer->setCheckable(true);
127 userAgentPrivacyBrowserActionPointer->setCheckable(true);
128 userAgentWebEngineDefaultActionPointer->setCheckable(true);
129 userAgentFirefoxLinuxActionPointer->setCheckable(true);
130 userAgentChromiumLinuxActionPointer->setCheckable(true);
131 userAgentFirefoxWindowsActionPointer->setCheckable(true);
132 userAgentChromeWindowsActionPointer->setCheckable(true);
133 userAgentEdgeWindowsActionPointer->setCheckable(true);
134 userAgentSafariMacosActionPointer->setCheckable(true);
135 userAgentCustomActionPointer->setCheckable(true);
136 searchEngineMojeekActionPointer->setCheckable(true);
137 searchEngineMonoclesActionPointer->setCheckable(true);
138 searchEngineMetagerActionPointer->setCheckable(true);
139 searchEngineGoogleActionPointer->setCheckable(true);
140 searchEngineBingActionPointer->setCheckable(true);
141 searchEngineYahooActionPointer->setCheckable(true);
142 searchEngineCustomActionPointer->setCheckable(true);
144 // Instantiate the user agent helper.
145 UserAgentHelper *userAgentHelperPointer = new UserAgentHelper();
147 // Set the action text.
148 userAgentPrivacyBrowserActionPointer->setText(userAgentHelperPointer->PRIVACY_BROWSER_TRANSLATED);
149 userAgentWebEngineDefaultActionPointer->setText(userAgentHelperPointer->WEB_ENGINE_DEFAULT_TRANSLATED);
150 userAgentFirefoxLinuxActionPointer->setText(userAgentHelperPointer->FIREFOX_LINUX_TRANSLATED);
151 userAgentChromiumLinuxActionPointer->setText(userAgentHelperPointer->CHROMIUM_LINUX_TRANSLATED);
152 userAgentFirefoxWindowsActionPointer->setText(userAgentHelperPointer->FIREFOX_WINDOWS_TRANSLATED);
153 userAgentChromeWindowsActionPointer->setText(userAgentHelperPointer->CHROME_WINDOWS_TRANSLATED);
154 userAgentEdgeWindowsActionPointer->setText(userAgentHelperPointer->EDGE_WINDOWS_TRANSLATED);
155 userAgentSafariMacosActionPointer->setText(userAgentHelperPointer->SAFARI_MACOS_TRANSLATED);
156 searchEngineMojeekActionPointer->setText(i18nc("Search engine", "Mojeek"));
157 searchEngineMonoclesActionPointer->setText(i18nc("Search engine", "Monocles"));
158 searchEngineMetagerActionPointer->setText(i18nc("Search engine", "MetaGer"));
159 searchEngineGoogleActionPointer->setText(i18nc("Search engine", "Google"));
160 searchEngineBingActionPointer->setText(i18nc("Search engine", "Bing"));
161 searchEngineYahooActionPointer->setText(i18nc("Search engine", "Yahoo"));
162 domainSettingsActionPointer->setText(i18nc("Domain Settings action", "Domain Settings"));
163 cookiesActionPointer->setText(i18nc("The Cookies action, which also displays the number of cookies", "Cookies - %1", 0));
164 javaScriptActionPointer->setText(i18nc("JavaScript action", "JavaScript"));
165 localStorageActionPointer->setText(i18nc("The Local Storage action", "Local Storage"));
166 domStorageActionPointer->setText(i18nc("DOM Storage action", "DOM Storage"));
167 findCaseSensitiveActionPointer->setText(i18nc("Find Case Sensitive action", "Find Case Sensitive"));
169 // Set the action icons.
170 userAgentPrivacyBrowserActionPointer->setIcon(QIcon(":/icons/privacy-mode"));
171 userAgentWebEngineDefaultActionPointer->setIcon(QIcon::fromTheme(QStringLiteral("user-group-properties")));
172 userAgentFirefoxLinuxActionPointer->setIcon(QIcon::fromTheme(QStringLiteral("firefox-esr")));
173 userAgentChromiumLinuxActionPointer->setIcon(QIcon::fromTheme(QStringLiteral("chromium")));
174 userAgentFirefoxWindowsActionPointer->setIcon(QIcon::fromTheme(QStringLiteral("firefox-esr")));
175 userAgentChromeWindowsActionPointer->setIcon(QIcon::fromTheme(QStringLiteral("chromium")));
176 userAgentEdgeWindowsActionPointer->setIcon(QIcon::fromTheme(QStringLiteral("user-group-properties")));
177 userAgentSafariMacosActionPointer->setIcon(QIcon::fromTheme(QStringLiteral("user-group-properties")));
178 userAgentCustomActionPointer->setIcon(QIcon::fromTheme(QStringLiteral("user-group-properties")));
179 searchEngineMojeekActionPointer->setIcon(QIcon::fromTheme(QStringLiteral("search")));
180 searchEngineMonoclesActionPointer->setIcon(QIcon::fromTheme(QStringLiteral("search")));
181 searchEngineMetagerActionPointer->setIcon(QIcon::fromTheme(QStringLiteral("search")));
182 searchEngineGoogleActionPointer->setIcon(QIcon::fromTheme(QStringLiteral("im-google")));
183 searchEngineBingActionPointer->setIcon(QIcon::fromTheme(QStringLiteral("search")));
184 searchEngineYahooActionPointer->setIcon(QIcon::fromTheme(QStringLiteral("im-yahoo")));
185 searchEngineCustomActionPointer->setIcon(QIcon::fromTheme(QStringLiteral("search")));
186 zoomFactorActionPointer->setIcon(QIcon::fromTheme(QStringLiteral("zoom")));
187 domainSettingsActionPointer->setIcon(QIcon::fromTheme(QStringLiteral("settings-configure")));
188 cookiesActionPointer->setIcon(QIcon::fromTheme(QStringLiteral("preferences-web-browser-cookies")));
189 domStorageActionPointer->setIcon(QIcon::fromTheme(QStringLiteral("code-class")));
190 findCaseSensitiveActionPointer->setIcon(QIcon::fromTheme(QStringLiteral("format-text-lowercase")));
192 // Update the on-the-fly menus.
193 connect(tabWidgetPointer, SIGNAL(updateUserAgentActions(QString, bool)), this, SLOT(updateUserAgentActions(QString, bool)));
194 connect(tabWidgetPointer, SIGNAL(updateZoomFactorAction(double)), this, SLOT(updateZoomFactorAction(double)));
195 connect(tabWidgetPointer, SIGNAL(updateSearchEngineActions(QString, bool)), this, SLOT(updateSearchEngineActions(QString, bool)));
197 // Apply the on-the-fly settings when selected.
198 connect(userAgentActionGroupPointer, SIGNAL(triggered(QAction*)), tabWidgetPointer, SLOT(applyOnTheFlyUserAgent(QAction*)));
199 connect(searchEngineActionGroupPointer, SIGNAL(triggered(QAction*)), tabWidgetPointer, SLOT(applyOnTheFlySearchEngine(QAction*)));
201 // Process cookie changes.
202 connect(tabWidgetPointer, SIGNAL(updateCookiesAction(int)), this, SLOT(updateCookiesAction(int)));
205 connect(zoomFactorActionPointer, SIGNAL(triggered()), this, SLOT(getZoomFactorFromUser()));
206 connect(cookiesActionPointer, SIGNAL(triggered()), this, SLOT(showCookiesDialog()));
207 connect(domainSettingsActionPointer, SIGNAL(triggered()), this, SLOT(showDomainSettingsDialog()));
209 // Connect the URL toolbar actions.
210 connect(javaScriptActionPointer, SIGNAL(triggered()), this, SLOT(toggleJavaScript()));
211 connect(localStorageActionPointer, SIGNAL(triggered()), this, SLOT(toggleLocalStorage()));
212 connect(domStorageActionPointer, SIGNAL(triggered()), this, SLOT(toggleDomStorage()));
214 // Update the URL toolbar actions.
215 connect(tabWidgetPointer, SIGNAL(updateBackAction(bool)), backActionPointer, SLOT(setEnabled(bool)));
216 connect(tabWidgetPointer, SIGNAL(updateForwardAction(bool)), forwardActionPointer, SLOT(setEnabled(bool)));
217 connect(tabWidgetPointer, SIGNAL(updateJavaScriptAction(bool)), this, SLOT(updateJavaScriptAction(bool)));
218 connect(tabWidgetPointer, SIGNAL(updateLocalStorageAction(bool)), this, SLOT(updateLocalStorageAction(bool)));
219 connect(tabWidgetPointer, SIGNAL(updateDomStorageAction(bool)), this, SLOT(updateDomStorageAction(bool)));
221 // Connect the find text actions.
222 connect(findCaseSensitiveActionPointer, SIGNAL(triggered()), this, SLOT(toggleFindCaseSensitive()));
224 // Setup the GUI based on the browser_window_ui.rc file.
225 setupGUI(StandardWindowOption::Default, ("browserwindowui.rc"));
227 // Get lists of the actions' associated widgets.
228 QList<QWidget*> userAgentAssociatedWidgetsPointerList = userAgentPrivacyBrowserActionPointer->associatedWidgets();
229 QList<QWidget*> searchEngineAssociatedWidgetsPointerList = searchEngineMojeekActionPointer->associatedWidgets();
231 // Get the menu widget pointers. It is the second entry, after the main window.
232 QWidget *userAgentMenuWidgetPointer = userAgentAssociatedWidgetsPointerList[1];
233 QWidget *searchEngineMenuWidgetPointer = searchEngineAssociatedWidgetsPointerList[1];
235 // Get the menu pointers.
236 QMenu *userAgentMenuPointer = qobject_cast<QMenu*>(userAgentMenuWidgetPointer);
237 QMenu *searchEngineMenuPointer = qobject_cast<QMenu*>(searchEngineMenuWidgetPointer);
239 // Get the menu actions.
240 userAgentMenuActionPointer = userAgentMenuPointer->menuAction();
241 searchEngineMenuActionPointer = searchEngineMenuPointer->menuAction();
243 // Get handles for the toolbars.
244 navigationToolBarPointer = toolBar(QStringLiteral("navigation_toolbar"));
245 urlToolBarPointer = toolBar(QStringLiteral("url_toolbar"));
247 // Create the line edits.
248 urlLineEditPointer = new KLineEdit();
249 findTextLineEditPointer = new KLineEdit();
251 // Get the line edit size policies.
252 QSizePolicy urlLineEditSizePolicy = urlLineEditPointer->sizePolicy();
253 QSizePolicy findTextLineEditSizePolicy = findTextLineEditPointer->sizePolicy();
255 // Set the URL line edit horizontal stretch to be five times the find text line edit stretch.
256 urlLineEditSizePolicy.setHorizontalStretch(5);
257 findTextLineEditSizePolicy.setHorizontalStretch(1);
260 urlLineEditPointer->setSizePolicy(urlLineEditSizePolicy);
261 findTextLineEditPointer->setSizePolicy(findTextLineEditSizePolicy);
264 urlLineEditPointer->setMinimumWidth(350);
265 findTextLineEditPointer->setMinimumWidth(200);
266 findTextLineEditPointer->setMaximumWidth(350);
268 // Set the placehold text.
269 urlLineEditPointer->setPlaceholderText(i18nc("The URL line edit placeholder text", "URL or Search Terms"));
270 findTextLineEditPointer->setPlaceholderText(i18nc("The find line edit placeholder text", "Find Text"));
272 // Show the clear button on the find line edit.
273 findTextLineEditPointer->setClearButtonEnabled(true);
275 // Add an edit or add domain settings action to the URL line edit.
276 QAction *addOrEditDomainSettingsActionPointer = urlLineEditPointer->addAction(QIcon::fromTheme("settings-configure"), QLineEdit::TrailingPosition);
278 // Add or edit the current domain settings.
279 connect(addOrEditDomainSettingsActionPointer, SIGNAL(triggered()), this, SLOT(addOrEditDomainSettings()));
281 // Create a find text label pointer.
282 findTextLabelPointer = new QLabel();
284 // Set the default label text.
285 findTextLabelPointer->setText(QStringLiteral(" ") + i18nc("Default find results.", "0/0") + QStringLiteral(" "));
287 // Insert the widgets into the toolbars.
288 urlToolBarPointer->insertWidget(javaScriptActionPointer, urlLineEditPointer);
289 urlToolBarPointer->insertWidget(findNextActionPointer, findTextLineEditPointer);
290 urlToolBarPointer->insertWidget(findNextActionPointer, findTextLabelPointer);
292 // Load a new URL from the URL line edit.
293 connect(urlLineEditPointer, SIGNAL(returnKeyPressed(const QString)), this, SLOT(loadUrlFromLineEdit(const QString)));
295 // Find text as it is typed.
296 connect(findTextLineEditPointer, SIGNAL(textEdited(const QString &)), tabWidgetPointer, SLOT(findText(const QString &)));
298 // Find next if the enter key is pressed.
299 connect(findTextLineEditPointer, SIGNAL(returnKeyPressed(const QString &)), tabWidgetPointer, SLOT(findText(const QString &)));
301 // Update find text when switching tabs.
302 connect(tabWidgetPointer, SIGNAL(updateFindText(const QString &, const bool)), this, SLOT(updateFindText(const QString &, const bool)));
304 // Update the find text results.
305 connect(tabWidgetPointer, SIGNAL(updateFindTextResults(const QWebEngineFindTextResult &)), this, SLOT(updateFindTextResults(const QWebEngineFindTextResult &)));
307 // Update the URL line edit on page loads.
308 connect(tabWidgetPointer, SIGNAL(updateUrlLineEdit(QUrl)), this, SLOT(updateUrlLineEdit(QUrl)));
310 // Update the window title.
311 connect(tabWidgetPointer, SIGNAL(updateWindowTitle(const QString)), this, SLOT(updateWindowTitle(const QString)));
313 // Get a handle for the status bar.
314 QStatusBar *statusBarPointer = statusBar();
316 // Create a progress bar.
317 progressBarPointer = new QProgressBar();
319 // Add the progress bar to to the status bar.
320 statusBarPointer->addPermanentWidget(progressBarPointer);
322 // Update the status bar with the URL when a link is hovered.
323 connect(tabWidgetPointer, SIGNAL(linkHovered(QString)), statusBarPointer, SLOT(showMessage(QString)));
325 // Update the progress bar.
326 connect(tabWidgetPointer, SIGNAL(showProgressBar(const int)), this, SLOT(showProgressBar(const int)));
327 connect(tabWidgetPointer, SIGNAL(hideProgressBar()), progressBarPointer, SLOT(hide()));
329 // Update the URL line edit focus.
330 connect(tabWidgetPointer, SIGNAL(clearUrlLineEditFocus()), this, SLOT(clearUrlLineEditFocus()));
332 // Get the URL line edit palettes.
333 normalBackgroundPalette = urlLineEditPointer->palette();
334 negativeBackgroundPalette = normalBackgroundPalette;
335 positiveBackgroundPalette = normalBackgroundPalette;
337 // Modify the palettes.
338 KColorScheme::adjustBackground(negativeBackgroundPalette, KColorScheme::NegativeBackground);
339 KColorScheme::adjustBackground(positiveBackgroundPalette, KColorScheme::PositiveBackground);
341 // Update the applied palette.
342 connect(tabWidgetPointer, SIGNAL(updateDomainSettingsIndicator(const bool)), this, SLOT(updateDomainSettingsIndicator(const bool)));
344 // Process full screen requests.
345 connect(tabWidgetPointer, SIGNAL(fullScreenRequested(bool)), this, SLOT(fullScreenRequested(bool)));
347 // Create keyboard shortcuts.
348 QShortcut *ctrlTShortcutPointer = new QShortcut(QKeySequence(i18nc("The open new tab shortcut.", "Ctrl+t")), this);
349 QShortcut *f11ShortcutPointer = new QShortcut(QKeySequence(i18nc("The toggle full screen shortcut.", "F11")), this);
350 QShortcut *escapeShortcutPointer = new QShortcut(QKeySequence::Cancel, this);
352 // Connect the keyboard shortcuts to the actions.
353 connect(ctrlTShortcutPointer, SIGNAL(activated()), tabWidgetPointer, SLOT(addTab()));
354 connect(f11ShortcutPointer, SIGNAL(activated()), fullScreenActionPointer, SLOT(trigger()));
355 connect(escapeShortcutPointer, SIGNAL(activated()), this, SLOT(escape()));
358 // This must be done here, because otherwise, if a URL is loaded, like a local file, that does not trigger a call to TabWidget::applyDomainSettings, the UI will not be fully populated.
359 updateJavaScriptAction(Settings::javaScriptEnabled());
360 updateLocalStorageAction(Settings::localStorageEnabled());
361 updateDomStorageAction(Settings::domStorageEnabled());
362 updateUserAgentActions(UserAgentHelper::getUserAgentFromDatabaseName(Settings::userAgent()), true);
363 updateZoomFactorAction(Settings::zoomFactor());
365 // Load the initial website if this is the first window.
367 tabWidgetPointer->loadInitialWebsite();
370 void BrowserWindow::addOrEditDomainSettings() const
372 // Remove the focus from the URL line edit.
373 urlLineEditPointer->clearFocus();
375 // Create the domain settings dialog pointer.
376 DomainSettingsDialog *domainSettingsDialogPointer;
378 // Get the current domain settings name.
379 QString ¤tDomainSettingsName = tabWidgetPointer->getDomainSettingsName();
381 // Run the commands according to the current domain settings status.
382 if (currentDomainSettingsName == QStringLiteral("")) // Domain settings are not currently applied.
384 // Instruct the domain settings dialog to add a new domain.
385 domainSettingsDialogPointer = new DomainSettingsDialog(DomainSettingsDialog::ADD_DOMAIN, currentUrl.host());
387 else // Domain settings are currently applied.
389 // Instruct the domain settings dialog to edit the current domain.
390 domainSettingsDialogPointer = new DomainSettingsDialog(DomainSettingsDialog::EDIT_DOMAIN, currentDomainSettingsName);
393 // Set the dialog window title.
394 domainSettingsDialogPointer->setWindowTitle(i18nc("The domain settings dialog title", "Domain Settings"));
397 domainSettingsDialogPointer->setWindowModality(Qt::WindowModality::WindowModal);;
400 domainSettingsDialogPointer->show();
402 // Reload the tabs when domain settings are updated.
403 connect(domainSettingsDialogPointer, SIGNAL(domainSettingsUpdated()), tabWidgetPointer, SLOT(applyDomainSettingsAndReload()));
406 void BrowserWindow::back() const
408 // Remove the focus from the URL line edit.
409 urlLineEditPointer->clearFocus();
412 tabWidgetPointer->back();
415 void BrowserWindow::clearUrlLineEditFocus() const
417 // Remove the focus from the URL line edit.
418 urlLineEditPointer->clearFocus();
421 void BrowserWindow::escape() const
423 // Process the excape according to the status of the browser.
424 if (fullScreenActionPointer->isChecked()) // Full screen browsing is enabled.
426 // Exit full screen browsing.
427 fullScreenActionPointer->trigger();
429 else if (!findTextLineEditPointer->text().isEmpty()) // Find text is activated.
431 // Clear the text in the line edit.
432 findTextLineEditPointer->clear();
434 // Clear the search in the WebEngine.
435 tabWidgetPointer->findText(QStringLiteral(""));
439 void BrowserWindow::fileNew() const
441 // Display a new instance of Privacy Browser.
442 (new BrowserWindow)->show();
445 void BrowserWindow::findNext() const
447 // Get the find string.
448 const QString findString = findTextLineEditPointer->text();
450 // Search for the text if it is not empty.
451 if (!findString.isEmpty())
452 tabWidgetPointer->findText(findString);
455 void BrowserWindow::findPrevious() const
457 // Get the find string.
458 const QString findString = findTextLineEditPointer->text();
460 // Search for the text if it is not empty.
461 if (!findString.isEmpty())
462 tabWidgetPointer->findPrevious(findString);
465 void BrowserWindow::focusFindLineEdit() const
467 // Set the focus on the find line edit.
468 findTextLineEditPointer->setFocus();
470 // Select all the text in the find line edit.
471 findTextLineEditPointer->selectAll();
474 void BrowserWindow::forward() const
476 // Remove the focus from the URL line edit.
477 urlLineEditPointer->clearFocus();
480 tabWidgetPointer->forward();
483 void BrowserWindow::fullScreenRequested(const bool toggleOn)
485 // Toggle full screen mode.
486 if (toggleOn) // Turn full screen mode on.
488 // Set the window to be full screen.
489 fullScreenActionPointer->setFullScreen(window(), true);
491 // Hide all the bars.
492 menuBar()->setVisible(false);
493 navigationToolBarPointer->setVisible(false);
494 urlToolBarPointer->setVisible(false);
495 tabWidgetPointer->setTabBarVisible(false);
496 statusBar()->setVisible(false);
498 else // Turn full screen mode off.
500 // Set the window to not be full screen.
501 fullScreenActionPointer->setFullScreen(window(), false);
503 // Show all the bars.
504 menuBar()->setVisible(true);
505 navigationToolBarPointer->setVisible(true);
506 urlToolBarPointer->setVisible(true);
507 tabWidgetPointer->setTabBarVisible(true);
508 statusBar()->setVisible(true);
512 void BrowserWindow::getZoomFactorFromUser()
514 // Create an OK flag.
517 // 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.
518 double newZoomFactor = QInputDialog::getDouble(this, i18nc("The on-the-fly zoom factor dialog title", "On-The-Fly Zoom Factor"),
519 i18nc("The instruction text of the on-the-fly zoom factor dialog", "Enter a zoom factor between 0.25 and 5.00"),
520 currentZoomFactor, .025, 5.00, 2, &okClicked, Qt::WindowFlags(), 0.25);
522 // Update the zoom factor if the user clicked OK.
525 // Update the current zoom factor.
526 currentZoomFactor = newZoomFactor;
528 // Set the new zoom factor.
529 tabWidgetPointer->applyOnTheFlyZoomFactor(newZoomFactor);
531 // Update the on-the-fly action text.
532 updateZoomFactorAction(newZoomFactor);
536 void BrowserWindow::home() const
538 // Remove the focus from the URL line edit.
539 urlLineEditPointer->clearFocus();
542 tabWidgetPointer->home();
545 void BrowserWindow::loadUrlFromLineEdit(const QString &url) const
547 // Remove the focus from the URL line edit.
548 urlLineEditPointer->clearFocus();
551 tabWidgetPointer->loadUrlFromLineEdit(url);
554 void BrowserWindow::refresh() const
556 // Remove the focus from the URL line edit.
557 urlLineEditPointer->clearFocus();
559 // Refresh the web page.
560 tabWidgetPointer->refresh();
563 void BrowserWindow::showCookiesDialog()
565 // Remove the focus from the URL line edit.
566 urlLineEditPointer->clearFocus();
568 // Instantiate the cookie settings dialog.
569 CookiesDialog *cookiesDialogPointer = new CookiesDialog(tabWidgetPointer->getCookieList());
572 cookiesDialogPointer->show();
574 // Connect the dialog signals.
575 connect(cookiesDialogPointer, SIGNAL(addCookie(QNetworkCookie)), tabWidgetPointer, SLOT(addCookieToStore(QNetworkCookie)));
576 connect(cookiesDialogPointer, SIGNAL(deleteAllCookies()), tabWidgetPointer, SLOT(deleteAllCookies()));
577 connect(cookiesDialogPointer, SIGNAL(deleteCookie(QNetworkCookie)), tabWidgetPointer, SLOT(deleteCookieFromStore(QNetworkCookie)));
580 void BrowserWindow::showDownloadLocationBrowseDialog() const
582 // Get the current download location.
583 QString currentDownloadLocation = downloadLocationComboBoxPointer->currentText();
585 // Resolve the system download directory if specified.
586 if (currentDownloadLocation == QStringLiteral("System Download Directory"))
587 currentDownloadLocation = QStandardPaths::writableLocation(QStandardPaths::DownloadLocation);
589 // Get the new download location.
590 QString newDownloadLocation = QFileDialog::getExistingDirectory(configDialogPointer, i18nc("Select download location dialog caption", "Select Download Location"), currentDownloadLocation);
592 // Populate the download location combo box according to the new download location.
593 if (newDownloadLocation == QStandardPaths::writableLocation(QStandardPaths::DownloadLocation)) // The default download location was selected.
595 // Populate the download location with the default text.
596 downloadLocationComboBoxPointer->setCurrentText("System Download Directory");
598 else if (newDownloadLocation != QStringLiteral("")) // A different directory was selected.
600 // Populate the download location.
601 downloadLocationComboBoxPointer->setCurrentText(newDownloadLocation);
605 void BrowserWindow::showDomainSettingsDialog() const
607 // Remove the focus from the URL line edit.
608 urlLineEditPointer->clearFocus();
610 // Instantiate the domain settings dialog.
611 DomainSettingsDialog *domainSettingsDialogPointer = new DomainSettingsDialog();
614 domainSettingsDialogPointer->show();
616 // Reload the tabs when domain settings are updated.
617 connect(domainSettingsDialogPointer, SIGNAL(domainSettingsUpdated()), tabWidgetPointer, SLOT(applyDomainSettingsAndReload()));
620 void BrowserWindow::showProgressBar(const int &progress) const
622 // Set the progress bar value.
623 progressBarPointer->setValue(progress);
625 // Show the progress bar.
626 progressBarPointer->show();
629 void BrowserWindow::showSettingsDialog()
631 // Create the settings widgets.
632 QWidget *privacySettingsWidgetPointer = new QWidget;
633 QWidget *generalSettingsWidgetPointer = new QWidget;
635 // Instantiate the settings UI.
636 Ui::PrivacySettings privacySettingsUi;
637 Ui::GeneralSettings generalSettingsUi;
639 // Setup the UI to display the settings widgets.
640 privacySettingsUi.setupUi(privacySettingsWidgetPointer);
641 generalSettingsUi.setupUi(generalSettingsWidgetPointer);
643 // Get handles for the widgets.
644 QComboBox *userAgentComboBoxPointer = privacySettingsUi.kcfg_userAgent;
645 userAgentLabelPointer = privacySettingsUi.userAgentLabel;
646 QComboBox *searchEngineComboBoxPointer = generalSettingsUi.kcfg_searchEngine;
647 searchEngineLabelPointer = generalSettingsUi.searchEngineLabel;
648 downloadLocationComboBoxPointer = generalSettingsUi.kcfg_downloadLocation;
649 QPushButton *browseButtonPointer = generalSettingsUi.browseButton;
651 // Populate the combo box labels.
652 updateUserAgentLabel(userAgentComboBoxPointer->currentText());
653 updateSearchEngineLabel(searchEngineComboBoxPointer->currentText());
655 // Update the labels when the combo boxes change.
656 connect(userAgentComboBoxPointer, SIGNAL(currentTextChanged(const QString)), this, SLOT(updateUserAgentLabel(const QString)));
657 connect(searchEngineComboBoxPointer, SIGNAL(currentTextChanged(const QString)), this, SLOT(updateSearchEngineLabel(const QString)));
659 // Connect the download location directory browse button.
660 connect(browseButtonPointer, SIGNAL(clicked()), this, SLOT(showDownloadLocationBrowseDialog()));
662 // Instantiate a settings config dialog from the settings.kcfg file.
663 configDialogPointer = new KConfigDialog(this, QStringLiteral("settings"), Settings::self());
665 // Add the settings widgets as config dialog pages.
666 configDialogPointer->addPage(privacySettingsWidgetPointer, i18nc("@title:tab", "Privacy"), QStringLiteral("privacy-browser"));
667 configDialogPointer->addPage(generalSettingsWidgetPointer, i18nc("@title:tab", "General"), QStringLiteral("breeze-settings"));
669 // Prevent interaction with the parent window while the dialog is open.
670 configDialogPointer->setWindowModality(Qt::WindowModal);
673 configDialogPointer->show();
675 // TODO. KConfigDialog does not respect expanding size policies. <https://redmine.stoutner.com/issues/823>
676 //configDialogPointer->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
677 //privacySettingsWidgetPointer->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
678 //generalSettingsWidgetPointer->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
679 //configDialogPointer->adjustSize();
681 // Expand the config dialog.
682 configDialogPointer->resize(1000, 500);
684 // Apply the settings when they are updated.
685 connect(configDialogPointer, SIGNAL(settingsChanged(QString)), tabWidgetPointer, SLOT(applyApplicationSettings()));
686 connect(configDialogPointer, SIGNAL(settingsChanged(QString)), tabWidgetPointer, SLOT(applyDomainSettingsAndReload()));
689 QSize BrowserWindow::sizeHint() const
691 // Return the default window size.
692 return QSize(1500, 1200);
695 void BrowserWindow::toggleDomStorage() const
697 // Remove the focus from the URL line edit.
698 urlLineEditPointer->clearFocus();
700 // Toggle DOM storage.
701 tabWidgetPointer->toggleDomStorage();
704 void BrowserWindow::toggleFindCaseSensitive() const
706 // Get the current find string.
707 const QString findString = findTextLineEditPointer->text();
709 // Toggle find case sensitive.
710 tabWidgetPointer->toggleFindCaseSensitive(findString);
713 void BrowserWindow::toggleJavaScript() const
715 // Remove the focus from the URL line edit.
716 urlLineEditPointer->clearFocus();
718 // Toggle JavaScript.
719 tabWidgetPointer->toggleJavaScript();
722 void BrowserWindow::toggleLocalStorage() const
724 // Remove the focus from the URL line edit.
725 urlLineEditPointer->clearFocus();
727 // Toggle local storage.
728 tabWidgetPointer->toggleLocalStorage();
731 void BrowserWindow::toggleFullScreen()
733 // Toggle the full screen status.
734 if (fullScreenActionPointer->isChecked()) // Enable full screen browsing mode.
736 // Enable full screen mode.
737 fullScreenActionPointer->setFullScreen(window(), true);
739 // Hide the menu bar if specified.
740 if (Settings::fullScreenHideMenuBar())
741 menuBar()->setVisible(false);
743 // Hide the toolbars if specified.
744 if (Settings::fullScreenHideToolBars())
746 navigationToolBarPointer->setVisible(false);
747 urlToolBarPointer->setVisible(false);
750 // Hide the tab bar if specified.
751 if (Settings::fullScreenHideTabBar())
752 tabWidgetPointer->setTabBarVisible(false);
754 // Hide the status bar if specified.
755 if (Settings::fullScreenHideStatusBar())
756 statusBar()->setVisible(false);
758 else // Disable full screen browsing mode.
760 // Disable full screen mode.
761 fullScreenActionPointer->setFullScreen(window(), false);
763 // Show the menu bar.
764 menuBar()->setVisible(true);
766 // Show the toolbars.
767 navigationToolBarPointer->setVisible(true);
768 urlToolBarPointer->setVisible(true);
771 tabWidgetPointer->setTabBarVisible(true);
773 // Show the status bar.
774 statusBar()->setVisible(true);
778 void BrowserWindow::updateCookiesAction(const int numberOfCookies) const
780 // Update the action text.
781 cookiesActionPointer->setText(i18nc("The Cookies action, which also displays the number of cookies", "Cookies - %1", numberOfCookies));
784 void BrowserWindow::updateDomStorageAction(const bool &isEnabled) const
786 // Set the action checked status.
787 domStorageActionPointer->setChecked(isEnabled);
790 void BrowserWindow::updateDomainSettingsIndicator(const bool status)
792 // Set the domain palette according to the status.
794 urlLineEditPointer->setPalette(positiveBackgroundPalette);
796 urlLineEditPointer->setPalette(normalBackgroundPalette);
799 void BrowserWindow::updateFindText(const QString &text, const bool findCaseSensitive) const
802 findTextLineEditPointer->setText(text);
804 // Set the find case sensitive action checked status.
805 findCaseSensitiveActionPointer->setChecked(findCaseSensitive);
808 void BrowserWindow::updateFindTextResults(const QWebEngineFindTextResult &findTextResult) const
810 // Update the find text label.
811 findTextLabelPointer->setText(QStringLiteral(" %1/%2 ").arg(findTextResult.activeMatch()).arg(findTextResult.numberOfMatches()));
813 // Set the background color according to the find status.
814 if (findTextLineEditPointer->text().isEmpty())
815 findTextLineEditPointer->setPalette(normalBackgroundPalette);
816 else if (findTextResult.numberOfMatches() == 0)
817 findTextLineEditPointer->setPalette(negativeBackgroundPalette);
819 findTextLineEditPointer->setPalette(positiveBackgroundPalette);
822 void BrowserWindow::updateJavaScriptAction(const bool &isEnabled)
824 // Update the JavaScript status.
825 javaScriptEnabled = isEnabled;
827 // Set the icon according to the status.
828 if (javaScriptEnabled)
829 javaScriptActionPointer->setIcon(QIcon(QStringLiteral(":/icons/javascript-warning")));
831 javaScriptActionPointer->setIcon(QIcon(QStringLiteral(":/icons/privacy-mode")));
833 // Set the action checked status.
834 javaScriptActionPointer->setChecked(javaScriptEnabled);
836 // Update the status of the DOM storage action.
837 domStorageActionPointer->setEnabled(javaScriptEnabled & localStorageEnabled);
840 void BrowserWindow::updateLocalStorageAction(const bool &isEnabled)
842 // Update the local storage status.
843 localStorageEnabled = isEnabled;
846 if (localStorageEnabled)
847 localStorageActionPointer->setIcon(QIcon::fromTheme(QStringLiteral("disk-quota-high")));
849 localStorageActionPointer->setIcon(QIcon::fromTheme(QStringLiteral("disk-quota")));
851 // Set the action checked status.
852 localStorageActionPointer->setChecked(localStorageEnabled);
854 // Update the status of the DOM storage action.
855 domStorageActionPointer->setEnabled(localStorageEnabled & javaScriptEnabled);
858 void BrowserWindow::updateSearchEngineActions(const QString &searchEngine, const bool &updateCustomSearchEngineStatus)
860 // Initialize the custom search engine flag.
861 bool customSearchEngine = false;
863 if (searchEngine == "Mojeek") // Mojeek.
865 // Check the Mojeek user agent action.
866 searchEngineMojeekActionPointer->setChecked(true);
868 // Update the search engine menu action text.
869 searchEngineMenuActionPointer->setText(i18nc("The main search engine menu action", "Search Engine - Mojeek"));
871 else if (searchEngine == "Monocles") // Monocles.
873 // Check the Monocles user agent action.
874 searchEngineMonoclesActionPointer->setChecked(true);
876 // Update the search engine menu action text.
877 searchEngineMenuActionPointer->setText(i18nc("The main search engine menu action", "Search Engine - Monocles"));
879 else if (searchEngine == "MetaGer") // MetaGer.
881 // Check the MetaGer user agent action.
882 searchEngineMetagerActionPointer->setChecked(true);
884 // Update the search engine menu action text.
885 searchEngineMenuActionPointer->setText(i18nc("The main search engine menu action", "Search Engine - MetaGer"));
887 else if (searchEngine == "Google") // Google.
889 // Check the Google user agent action.
890 searchEngineGoogleActionPointer->setChecked(true);
892 // Update the search engine menu action text.
893 searchEngineMenuActionPointer->setText(i18nc("The main search engine menu action", "Search Engine - Google"));
895 else if (searchEngine == "Bing") // Bing.
897 // Check the Bing user agent action.
898 searchEngineBingActionPointer->setChecked(true);
900 // Update the search engine menu action text.
901 searchEngineMenuActionPointer->setText(i18nc("The main search engine menu action", "Search Engine - Bing"));
903 else if (searchEngine == "Yahoo") // Yahoo.
905 // Check the Yahoo user agent action.
906 searchEngineYahooActionPointer->setChecked(true);
908 // Update the search engine menu action text.
909 searchEngineMenuActionPointer->setText(i18nc("The main search engine menu action", "Search Engine - Yahoo"));
911 else // Custom search engine.
913 // Check the user agent.
914 searchEngineCustomActionPointer->setChecked(true);
916 // Update the search engine menu action text.
917 searchEngineMenuActionPointer->setText(i18nc("The main search engine menu action", "Search Engine - Custom"));
919 // Set the custom search engine text.
920 searchEngineCustomActionPointer->setText(searchEngine);
922 // Set the custom search engine flag.
923 customSearchEngine = true;
926 // Update the custom search engine enabled boolean.
927 if (updateCustomSearchEngineStatus)
928 customSearchEngineEnabled = customSearchEngine;
930 // Format the custom search engine.
931 if (customSearchEngineEnabled)
933 // Enable the custom search engine.
934 searchEngineCustomActionPointer->setEnabled(true);
938 // Disable the custom search engine.
939 searchEngineCustomActionPointer->setEnabled(false);
941 // Reset the custom search engine text.
942 searchEngineCustomActionPointer->setText(i18nc("@action", "Custom"));
946 void BrowserWindow::updateUserAgentActions(const QString &userAgent, const bool &updateCustomUserAgentStatus)
948 // Initialize the custom user agent flag.
949 bool customUserAgent = false;
951 // Check the indicated on-the-fly user agent.
952 if (userAgent == UserAgentHelper::PRIVACY_BROWSER_USER_AGENT) // Privacy Browser.
954 // Check the Privacy Browser user agent action.
955 userAgentPrivacyBrowserActionPointer->setChecked(true);
957 // Update the user agent menu action text.
958 userAgentMenuActionPointer->setText(i18nc("The main user agent menu action", "User Agent - Privacy Browser"));
960 else if (userAgent == TabWidget::webEngineDefaultUserAgent) // WebEngine default.
962 // check the WebEngine default user agent action.
963 userAgentWebEngineDefaultActionPointer->setChecked(true);
965 // Update the user agent menu action text.
966 userAgentMenuActionPointer->setText(i18nc("The main user agent menu action", "User Agent - WebEngine default"));
968 else if (userAgent == UserAgentHelper::FIREFOX_LINUX_USER_AGENT) // Firefox on Linux.
970 // Check the Firefox on Linux user agent action.
971 userAgentFirefoxLinuxActionPointer->setChecked(true);
973 // Update the user agent menu action text.
974 userAgentMenuActionPointer->setText(i18nc("The main user agent menu action", "User Agent - Firefox on Linux"));
976 else if (userAgent == UserAgentHelper::CHROMIUM_LINUX_USER_AGENT) // Chromium on Linux.
978 // Check the Chromium on Linux user agent action.
979 userAgentChromiumLinuxActionPointer->setChecked(true);
981 // Update the user agent menu action text.
982 userAgentMenuActionPointer->setText(i18nc("The main user agent menu action", "User Agent - Chromium on Linux"));
984 else if (userAgent == UserAgentHelper::FIREFOX_WINDOWS_USER_AGENT) // Firefox on Windows.
986 // Check the Firefox on Windows user agent action.
987 userAgentFirefoxWindowsActionPointer->setChecked(true);
989 // Update the user agent menu action text.
990 userAgentMenuActionPointer->setText(i18nc("The main user agent menu action", "User Agent - Firefox on Windows"));
992 else if (userAgent == UserAgentHelper::CHROME_WINDOWS_USER_AGENT) // Chrome on Windows.
994 // Check the Chrome on Windows user agent action.
995 userAgentChromeWindowsActionPointer->setChecked(true);
997 // Update the user agent menu action text.
998 userAgentMenuActionPointer->setText(i18nc("The main user agent menu action", "User Agent - Chrome on Windows"));
1000 else if (userAgent == UserAgentHelper::EDGE_WINDOWS_USER_AGENT) // Edge on Windows.
1002 // Check the Edge on Windows user agent action.
1003 userAgentEdgeWindowsActionPointer->setChecked(true);
1005 // Update the user agent menu action text.
1006 userAgentMenuActionPointer->setText(i18nc("The main user agent menu action", "User Agent - Edge on Windows"));
1008 else if (userAgent == UserAgentHelper::SAFARI_MACOS_USER_AGENT) // Safari on macOS.
1010 // Check the Safari on macOS user agent action.
1011 userAgentSafariMacosActionPointer->setChecked(true);
1013 // Update the user agent menu action text.
1014 userAgentMenuActionPointer->setText(i18nc("The main user agent menu action", "User Agent - Safari on macOS"));
1016 else // Custom user agent.
1018 // Check the user agent.
1019 userAgentCustomActionPointer->setChecked(true);
1021 // Update the user agent menu action text.
1022 userAgentMenuActionPointer->setText(i18nc("The main user agent menu action", "User Agent - Custom"));
1024 // Set the custom user agent text.
1025 userAgentCustomActionPointer->setText(userAgent);
1027 // Set the custom user agent flag.
1028 customUserAgent = true;
1031 // Update the custom user agent enabled boolean.
1032 // This is not done when the current user agent is a custom one but it is temporarially being changed via on-the-fly settings so that the user can switch back to the custom user agent.
1033 if (updateCustomUserAgentStatus)
1034 customUserAgentEnabled = customUserAgent;
1037 // Format the custom user agent.
1038 if (customUserAgentEnabled)
1040 // Enable the custom user agent.
1041 userAgentCustomActionPointer->setEnabled(true);
1045 // Disable the custom user agent.
1046 userAgentCustomActionPointer->setEnabled(false);
1048 // Reset the custom user agent text.
1049 userAgentCustomActionPointer->setText(i18nc("@action", "Custom"));
1053 void BrowserWindow::updateZoomFactorAction(const double &zoomFactor)
1055 // Set the current zoom factor.
1056 currentZoomFactor = zoomFactor;
1058 // Update the zoom factor action text, formatting the double with 2 decimal places.
1059 zoomFactorActionPointer->setText(ki18nc("@action", "Zoom Factor - %1").subs(zoomFactor, 0, '0', 2).toString());
1062 void BrowserWindow::updateSearchEngineLabel(const QString &searchEngineString) const
1064 // Update the search engine label.
1065 searchEngineLabelPointer->setText(SearchEngineHelper::getSearchUrl(searchEngineString));
1068 void BrowserWindow::updateUrlLineEdit(const QUrl &newUrl)
1070 // Update the URL line edit if it does not have focus.
1071 if (!urlLineEditPointer->hasFocus())
1073 // Get the new URL string.
1074 QString newUrlString = newUrl.toString();
1076 // Update the URL line edit.
1077 urlLineEditPointer->setText(newUrlString);
1079 // Set the focus if the new URL is blank.
1080 if (newUrlString == QStringLiteral(""))
1081 urlLineEditPointer->setFocus();
1084 // Store the current URL.
1085 currentUrl = newUrl;
1088 void BrowserWindow::updateUserAgentLabel(const QString &userAgentDatabaseName) const
1090 // Update the user agent label.
1091 userAgentLabelPointer->setText(UserAgentHelper::getUserAgentFromDatabaseName(userAgentDatabaseName));
1094 void BrowserWindow::updateWindowTitle(const QString &title)
1096 // Update the window title.
1097 setWindowTitle(title);