2 * Copyright 2022-2023 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_SettingsGeneral.h"
24 #include "ui_SettingsPrivacy.h"
25 #include "ui_SettingsSpellCheck.h"
26 #include "dialogs/CookiesDialog.h"
27 #include "dialogs/DomainSettingsDialog.h"
28 #include "helpers/SearchEngineHelper.h"
29 #include "helpers/UserAgentHelper.h"
31 // KDE Frameworks headers.
32 #include <KActionCollection>
33 #include <KColorScheme>
36 // Qt toolkit headers.
37 #include <QFileDialog>
38 #include <QInputDialog>
39 #include <QNetworkCookie>
43 #include <QWebEngineFindTextResult>
45 // Construct the class.
46 BrowserWindow::BrowserWindow(bool firstWindow) : KXmlGuiWindow()
48 // Initialize the variables.
49 javaScriptEnabled = false;
50 localStorageEnabled = false;
52 // Instantiate the privacy tab widget pointer.
53 tabWidgetPointer = new TabWidget(this);
55 // Set the privacy tab widget as the central widget.
56 setCentralWidget(tabWidgetPointer);
58 // Get a handle for the action collection.
59 KActionCollection *actionCollectionPointer = this->actionCollection();
61 // Add the standard actions.
62 KStandardAction::print(tabWidgetPointer, SLOT(print()), actionCollectionPointer);
63 QAction *printPreviewActionPointer = 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(showFindTextActions()), actionCollectionPointer);
72 findNextActionPointer = KStandardAction::findNext(this, SLOT(findNext()), actionCollectionPointer);
73 findPreviousActionPointer = KStandardAction::findPrev(this, SLOT(findPrevious()), actionCollectionPointer);
75 // Add the custom actions.
76 QAction *newTabActionPointer = actionCollectionPointer->addAction(QLatin1String("new_tab"));
77 QAction *newWindowActionPointer = actionCollectionPointer->addAction(QLatin1String("new_window"));
78 userAgentPrivacyBrowserActionPointer = actionCollectionPointer->addAction(QLatin1String("user_agent_privacy_browser"));
79 userAgentWebEngineDefaultActionPointer = actionCollectionPointer->addAction(QLatin1String("user_agent_webengine_default"));
80 userAgentFirefoxLinuxActionPointer = actionCollectionPointer->addAction(QLatin1String("user_agent_firefox_linux"));
81 userAgentChromiumLinuxActionPointer = actionCollectionPointer->addAction(QLatin1String("user_agent_chromium_linux"));
82 userAgentFirefoxWindowsActionPointer = actionCollectionPointer->addAction(QLatin1String("user_agent_firefox_windows"));
83 userAgentChromeWindowsActionPointer = actionCollectionPointer->addAction(QLatin1String("user_agent_chrome_windows"));
84 userAgentEdgeWindowsActionPointer = actionCollectionPointer->addAction(QLatin1String("user_agent_edge_windows"));
85 userAgentSafariMacosActionPointer = actionCollectionPointer->addAction(QLatin1String("user_agent_safari_macos"));
86 userAgentCustomActionPointer = actionCollectionPointer->addAction(QLatin1String("user_agent_custom"));
87 zoomFactorActionPointer = actionCollectionPointer->addAction(QLatin1String("zoom_factor"));
88 searchEngineMojeekActionPointer = actionCollectionPointer->addAction(QLatin1String("search_engine_mojeek"));
89 searchEngineMonoclesActionPointer = actionCollectionPointer->addAction(QLatin1String("search_engine_monocles"));
90 searchEngineMetagerActionPointer = actionCollectionPointer->addAction(QLatin1String("search_engine_metager"));
91 searchEngineGoogleActionPointer = actionCollectionPointer->addAction(QLatin1String("search_engine_google"));
92 searchEngineBingActionPointer = actionCollectionPointer->addAction(QLatin1String("search_engine_bing"));
93 searchEngineYahooActionPointer = actionCollectionPointer->addAction(QLatin1String("search_engine_yahoo"));
94 searchEngineCustomActionPointer = actionCollectionPointer->addAction(QLatin1String("search_engine_custom"));
95 QAction *domainSettingsActionPointer = actionCollectionPointer->addAction(QLatin1String("domain_settings"));
96 cookiesActionPointer = actionCollectionPointer->addAction(QLatin1String("cookies"));
97 javaScriptActionPointer = actionCollectionPointer->addAction(QLatin1String("javascript"));
98 localStorageActionPointer = actionCollectionPointer->addAction(QLatin1String("local_storage"));
99 domStorageActionPointer = actionCollectionPointer->addAction(QLatin1String("dom_storage"));
100 findCaseSensitiveActionPointer = actionCollectionPointer->addAction(QLatin1String("find_case_sensitive"));
101 hideFindTextActionPointer = actionCollectionPointer->addAction(QLatin1String("hide_find_actions"));
103 // Create the action groups
104 QActionGroup *userAgentActionGroupPointer = new QActionGroup(this);
105 QActionGroup *searchEngineActionGroupPointer = new QActionGroup(this);
107 // Add the actions to the groups.
108 userAgentActionGroupPointer->addAction(userAgentPrivacyBrowserActionPointer);
109 userAgentActionGroupPointer->addAction(userAgentWebEngineDefaultActionPointer);
110 userAgentActionGroupPointer->addAction(userAgentFirefoxLinuxActionPointer);
111 userAgentActionGroupPointer->addAction(userAgentChromiumLinuxActionPointer);
112 userAgentActionGroupPointer->addAction(userAgentFirefoxWindowsActionPointer);
113 userAgentActionGroupPointer->addAction(userAgentChromeWindowsActionPointer);
114 userAgentActionGroupPointer->addAction(userAgentEdgeWindowsActionPointer);
115 userAgentActionGroupPointer->addAction(userAgentSafariMacosActionPointer);
116 userAgentActionGroupPointer->addAction(userAgentCustomActionPointer);
117 searchEngineActionGroupPointer->addAction(searchEngineMojeekActionPointer);
118 searchEngineActionGroupPointer->addAction(searchEngineMonoclesActionPointer);
119 searchEngineActionGroupPointer->addAction(searchEngineMetagerActionPointer);
120 searchEngineActionGroupPointer->addAction(searchEngineGoogleActionPointer);
121 searchEngineActionGroupPointer->addAction(searchEngineBingActionPointer);
122 searchEngineActionGroupPointer->addAction(searchEngineYahooActionPointer);
123 searchEngineActionGroupPointer->addAction(searchEngineCustomActionPointer);
125 // Set some actions to be checkable.
126 javaScriptActionPointer->setCheckable(true);
127 localStorageActionPointer->setCheckable(true);
128 domStorageActionPointer->setCheckable(true);
129 findCaseSensitiveActionPointer->setCheckable(true);
130 userAgentPrivacyBrowserActionPointer->setCheckable(true);
131 userAgentWebEngineDefaultActionPointer->setCheckable(true);
132 userAgentFirefoxLinuxActionPointer->setCheckable(true);
133 userAgentChromiumLinuxActionPointer->setCheckable(true);
134 userAgentFirefoxWindowsActionPointer->setCheckable(true);
135 userAgentChromeWindowsActionPointer->setCheckable(true);
136 userAgentEdgeWindowsActionPointer->setCheckable(true);
137 userAgentSafariMacosActionPointer->setCheckable(true);
138 userAgentCustomActionPointer->setCheckable(true);
139 searchEngineMojeekActionPointer->setCheckable(true);
140 searchEngineMonoclesActionPointer->setCheckable(true);
141 searchEngineMetagerActionPointer->setCheckable(true);
142 searchEngineGoogleActionPointer->setCheckable(true);
143 searchEngineBingActionPointer->setCheckable(true);
144 searchEngineYahooActionPointer->setCheckable(true);
145 searchEngineCustomActionPointer->setCheckable(true);
147 // Instantiate the user agent helper.
148 UserAgentHelper *userAgentHelperPointer = new UserAgentHelper();
150 // Set the action text.
151 newTabActionPointer->setText(i18nc("New tab action", "New Tab"));
152 newWindowActionPointer->setText(i18nc("New window action", "New Window"));
153 userAgentPrivacyBrowserActionPointer->setText(userAgentHelperPointer->PRIVACY_BROWSER_TRANSLATED);
154 userAgentWebEngineDefaultActionPointer->setText(userAgentHelperPointer->WEB_ENGINE_DEFAULT_TRANSLATED);
155 userAgentFirefoxLinuxActionPointer->setText(userAgentHelperPointer->FIREFOX_LINUX_TRANSLATED);
156 userAgentChromiumLinuxActionPointer->setText(userAgentHelperPointer->CHROMIUM_LINUX_TRANSLATED);
157 userAgentFirefoxWindowsActionPointer->setText(userAgentHelperPointer->FIREFOX_WINDOWS_TRANSLATED);
158 userAgentChromeWindowsActionPointer->setText(userAgentHelperPointer->CHROME_WINDOWS_TRANSLATED);
159 userAgentEdgeWindowsActionPointer->setText(userAgentHelperPointer->EDGE_WINDOWS_TRANSLATED);
160 userAgentSafariMacosActionPointer->setText(userAgentHelperPointer->SAFARI_MACOS_TRANSLATED);
161 searchEngineMojeekActionPointer->setText(i18nc("Search engine", "Mojeek"));
162 searchEngineMonoclesActionPointer->setText(i18nc("Search engine", "Monocles"));
163 searchEngineMetagerActionPointer->setText(i18nc("Search engine", "MetaGer"));
164 searchEngineGoogleActionPointer->setText(i18nc("Search engine", "Google"));
165 searchEngineBingActionPointer->setText(i18nc("Search engine", "Bing"));
166 searchEngineYahooActionPointer->setText(i18nc("Search engine", "Yahoo"));
167 domainSettingsActionPointer->setText(i18nc("Domain Settings action", "Domain Settings"));
168 cookiesActionPointer->setText(i18nc("The Cookies action, which also displays the number of cookies", "Cookies - %1", 0));
169 javaScriptActionPointer->setText(i18nc("JavaScript action", "JavaScript"));
170 localStorageActionPointer->setText(i18nc("The Local Storage action", "Local Storage"));
171 domStorageActionPointer->setText(i18nc("DOM Storage action", "DOM Storage"));
172 findCaseSensitiveActionPointer->setText(i18nc("Find Case Sensitive action", "Find Case Sensitive"));
173 hideFindTextActionPointer->setText(i18nc("Hide Find Text action", "Hide Find Text"));
175 // Set the action icons.
176 newTabActionPointer->setIcon(QIcon::fromTheme(QLatin1String("tab-new")));
177 newWindowActionPointer->setIcon(QIcon::fromTheme(QLatin1String("window-new")));
178 userAgentPrivacyBrowserActionPointer->setIcon(QIcon(":/icons/privacy-mode"));
179 userAgentWebEngineDefaultActionPointer->setIcon(QIcon::fromTheme(QLatin1String("user-group-properties")));
180 userAgentFirefoxLinuxActionPointer->setIcon(QIcon::fromTheme(QLatin1String("firefox-esr")));
181 userAgentChromiumLinuxActionPointer->setIcon(QIcon::fromTheme(QLatin1String("chromium")));
182 userAgentFirefoxWindowsActionPointer->setIcon(QIcon::fromTheme(QLatin1String("firefox-esr")));
183 userAgentChromeWindowsActionPointer->setIcon(QIcon::fromTheme(QLatin1String("chromium")));
184 userAgentEdgeWindowsActionPointer->setIcon(QIcon::fromTheme(QLatin1String("user-group-properties")));
185 userAgentSafariMacosActionPointer->setIcon(QIcon::fromTheme(QLatin1String("user-group-properties")));
186 userAgentCustomActionPointer->setIcon(QIcon::fromTheme(QLatin1String("user-group-properties")));
187 searchEngineMojeekActionPointer->setIcon(QIcon::fromTheme(QLatin1String("search")));
188 searchEngineMonoclesActionPointer->setIcon(QIcon::fromTheme(QLatin1String("search")));
189 searchEngineMetagerActionPointer->setIcon(QIcon::fromTheme(QLatin1String("search")));
190 searchEngineGoogleActionPointer->setIcon(QIcon::fromTheme(QLatin1String("im-google")));
191 searchEngineBingActionPointer->setIcon(QIcon::fromTheme(QLatin1String("search")));
192 searchEngineYahooActionPointer->setIcon(QIcon::fromTheme(QLatin1String("im-yahoo")));
193 searchEngineCustomActionPointer->setIcon(QIcon::fromTheme(QLatin1String("search")));
194 zoomFactorActionPointer->setIcon(QIcon::fromTheme(QLatin1String("zoom")));
195 domainSettingsActionPointer->setIcon(QIcon::fromTheme(QLatin1String("settings-configure")));
196 cookiesActionPointer->setIcon(QIcon::fromTheme(QLatin1String("preferences-web-browser-cookies")));
197 domStorageActionPointer->setIcon(QIcon::fromTheme(QLatin1String("code-class")));
198 findCaseSensitiveActionPointer->setIcon(QIcon::fromTheme(QLatin1String("format-text-lowercase")));
199 hideFindTextActionPointer->setIcon(QIcon::fromTheme(QLatin1String("window-close-symbolic")));
201 // Create the key sequences.
202 QKeySequence ctrlTKeySequence = QKeySequence(i18nc("The open new tab key sequence.", "Ctrl+T"));
203 QKeySequence ctrlNKeySequence = QKeySequence(i18nc("The open new window key sequence.", "Ctrl+N"));
204 QKeySequence ctrlShiftPKeySequence = QKeySequence(i18nc("The print preview key sequence.", "Ctrl+Shift+P"));
205 QKeySequence ctrlAltPKeySequence = QKeySequence(i18nc("The Privacy Browser user agent key sequence.", "Ctrl+Alt+P"));
206 QKeySequence ctrlAltWKeySequence = QKeySequence(i18nc("The WebEngine Default user agent key sequence.", "Ctrl+Alt+W"));
207 QKeySequence ctrlAltFKeySequence = QKeySequence(i18nc("The Firefox on Linux user agent key sequence.", "Ctrl+Alt+F"));
208 QKeySequence ctrlAltCKeySequence = QKeySequence(i18nc("The Chromium on Linux user agent key sequence.", "Ctrl+Alt+C"));
209 QKeySequence ctrlAltShiftFKeySequence = QKeySequence(i18nc("The Firefox on Windows user agent key sequence.", "Ctrl+Alt+Shift+F"));
210 QKeySequence ctrlAltShiftCKeySequence = QKeySequence(i18nc("The Chrome on Windows user agent key sequence.", "Ctrl+Alt+Shift+C"));
211 QKeySequence ctrlAltEKeySequence = QKeySequence(i18nc("The Edge on Windows user agent key sequence.", "Ctrl+Alt+E"));
212 QKeySequence ctrlAltSKeySequence = QKeySequence(i18nc("The Safari on macOS user agent key sequence.", "Ctrl+Alt+S"));
213 QKeySequence altShiftCKeySequence = QKeySequence(i18nc("The custom user agent key sequence.", "Alt+Shift+C"));
214 QKeySequence ctrlAltZKeySequence = QKeySequence(i18nc("The zoom factor key sequence.", "Ctrl+Alt+Z"));
215 QKeySequence ctrlShiftMKeySequence = QKeySequence(i18nc("The Mojeek search engine key sequence.", "Ctrl+Shift+M"));
216 QKeySequence ctrlShiftOKeySequence = QKeySequence(i18nc("The Monocles search engine key sequence.", "Ctrl+Shift+O"));
217 QKeySequence ctrlShiftEKeySequence = QKeySequence(i18nc("The MetaGer search engine key sequence.", "Ctrl+Shift+E"));
218 QKeySequence ctrlShiftGKeySequence = QKeySequence(i18nc("The Google search engine key sequence.", "Ctrl+Shift+G"));
219 QKeySequence ctrlShiftBKeySequence = QKeySequence(i18nc("The Bing search engine key sequence.", "Ctrl+Shift+B"));
220 QKeySequence ctrlShiftYKeySequence = QKeySequence(i18nc("The Yahoo search engine key sequence.", "Ctrl+Shift+Y"));
221 QKeySequence ctrlShiftCKeySequence = QKeySequence(i18nc("The custom search engine key sequence.", "Ctrl+Shift+C"));
222 QKeySequence ctrlDKeySequence = QKeySequence(i18nc("The domain settings key sequence.", "Ctrl+D"));
223 QKeySequence ctrlSemicolonKeySequence = QKeySequence(i18nc("The cookies dialog key sequence.", "Ctrl+;"));
225 // Set the action key sequences.
226 actionCollectionPointer->setDefaultShortcut(newTabActionPointer, ctrlTKeySequence);
227 actionCollectionPointer->setDefaultShortcut(newWindowActionPointer, ctrlNKeySequence);
228 actionCollectionPointer->setDefaultShortcut(printPreviewActionPointer, ctrlShiftPKeySequence);
229 actionCollectionPointer->setDefaultShortcut(userAgentPrivacyBrowserActionPointer, ctrlAltPKeySequence);
230 actionCollectionPointer->setDefaultShortcut(userAgentWebEngineDefaultActionPointer, ctrlAltWKeySequence);
231 actionCollectionPointer->setDefaultShortcut(userAgentFirefoxLinuxActionPointer, ctrlAltFKeySequence);
232 actionCollectionPointer->setDefaultShortcut(userAgentChromiumLinuxActionPointer, ctrlAltCKeySequence);
233 actionCollectionPointer->setDefaultShortcut(userAgentFirefoxWindowsActionPointer, ctrlAltShiftFKeySequence);
234 actionCollectionPointer->setDefaultShortcut(userAgentChromeWindowsActionPointer, ctrlAltShiftCKeySequence);
235 actionCollectionPointer->setDefaultShortcut(userAgentEdgeWindowsActionPointer, ctrlAltEKeySequence);
236 actionCollectionPointer->setDefaultShortcut(userAgentSafariMacosActionPointer, ctrlAltSKeySequence);
237 actionCollectionPointer->setDefaultShortcut(userAgentCustomActionPointer, altShiftCKeySequence);
238 actionCollectionPointer->setDefaultShortcut(zoomFactorActionPointer, ctrlAltZKeySequence);
239 actionCollectionPointer->setDefaultShortcut(searchEngineMojeekActionPointer, ctrlShiftMKeySequence);
240 actionCollectionPointer->setDefaultShortcut(searchEngineMonoclesActionPointer, ctrlShiftOKeySequence);
241 actionCollectionPointer->setDefaultShortcut(searchEngineMetagerActionPointer, ctrlShiftEKeySequence);
242 actionCollectionPointer->setDefaultShortcut(searchEngineGoogleActionPointer, ctrlShiftGKeySequence);
243 actionCollectionPointer->setDefaultShortcut(searchEngineBingActionPointer, ctrlShiftBKeySequence);
244 actionCollectionPointer->setDefaultShortcut(searchEngineYahooActionPointer, ctrlShiftYKeySequence);
245 actionCollectionPointer->setDefaultShortcut(searchEngineCustomActionPointer, ctrlShiftCKeySequence);
246 actionCollectionPointer->setDefaultShortcut(domainSettingsActionPointer, ctrlDKeySequence);
247 actionCollectionPointer->setDefaultShortcut(cookiesActionPointer, ctrlSemicolonKeySequence);
249 // Execute the actions.
250 connect(newTabActionPointer, SIGNAL(triggered()), tabWidgetPointer, SLOT(addTab()));
251 connect(newWindowActionPointer, SIGNAL(triggered()), this, SLOT(newWindow()));
252 connect(zoomFactorActionPointer, SIGNAL(triggered()), this, SLOT(getZoomFactorFromUser()));
253 connect(cookiesActionPointer, SIGNAL(triggered()), this, SLOT(showCookiesDialog()));
254 connect(domainSettingsActionPointer, SIGNAL(triggered()), this, SLOT(showDomainSettingsDialog()));
256 // Update the on-the-fly menus.
257 connect(tabWidgetPointer, SIGNAL(updateUserAgentActions(QString, bool)), this, SLOT(updateUserAgentActions(QString, bool)));
258 connect(tabWidgetPointer, SIGNAL(updateZoomFactorAction(double)), this, SLOT(updateZoomFactorAction(double)));
259 connect(tabWidgetPointer, SIGNAL(updateSearchEngineActions(QString, bool)), this, SLOT(updateSearchEngineActions(QString, bool)));
261 // Apply the on-the-fly settings when selected.
262 connect(userAgentActionGroupPointer, SIGNAL(triggered(QAction*)), tabWidgetPointer, SLOT(applyOnTheFlyUserAgent(QAction*)));
263 connect(searchEngineActionGroupPointer, SIGNAL(triggered(QAction*)), tabWidgetPointer, SLOT(applyOnTheFlySearchEngine(QAction*)));
265 // Process cookie changes.
266 connect(tabWidgetPointer, SIGNAL(updateCookiesAction(int)), this, SLOT(updateCookiesAction(int)));
268 // Connect the URL toolbar actions.
269 connect(javaScriptActionPointer, SIGNAL(triggered()), this, SLOT(toggleJavaScript()));
270 connect(localStorageActionPointer, SIGNAL(triggered()), this, SLOT(toggleLocalStorage()));
271 connect(domStorageActionPointer, SIGNAL(triggered()), this, SLOT(toggleDomStorage()));
273 // Update the URL toolbar actions.
274 connect(tabWidgetPointer, SIGNAL(updateBackAction(bool)), backActionPointer, SLOT(setEnabled(bool)));
275 connect(tabWidgetPointer, SIGNAL(updateForwardAction(bool)), forwardActionPointer, SLOT(setEnabled(bool)));
276 connect(tabWidgetPointer, SIGNAL(updateJavaScriptAction(bool)), this, SLOT(updateJavaScriptAction(bool)));
277 connect(tabWidgetPointer, SIGNAL(updateLocalStorageAction(bool)), this, SLOT(updateLocalStorageAction(bool)));
278 connect(tabWidgetPointer, SIGNAL(updateDomStorageAction(bool)), this, SLOT(updateDomStorageAction(bool)));
280 // Connect the find text actions.
281 connect(findCaseSensitiveActionPointer, SIGNAL(triggered()), this, SLOT(toggleFindCaseSensitive()));
282 connect(hideFindTextActionPointer, SIGNAL(triggered()), this, SLOT(hideFindTextActions()));
284 // Setup the GUI based on the browserwindowui.rc file.
285 setupGUI(StandardWindowOption::Default, ("browserwindowui.rc"));
287 // Get lists of the actions' associated widgets.
288 QList<QWidget*> userAgentAssociatedWidgetsPointerList = userAgentPrivacyBrowserActionPointer->associatedWidgets();
289 QList<QWidget*> searchEngineAssociatedWidgetsPointerList = searchEngineMojeekActionPointer->associatedWidgets();
291 // Get the menu widget pointers. It is the second entry, after the main window.
292 QWidget *userAgentMenuWidgetPointer = userAgentAssociatedWidgetsPointerList[1];
293 QWidget *searchEngineMenuWidgetPointer = searchEngineAssociatedWidgetsPointerList[1];
295 // Get the menu pointers.
296 QMenu *userAgentMenuPointer = qobject_cast<QMenu*>(userAgentMenuWidgetPointer);
297 QMenu *searchEngineMenuPointer = qobject_cast<QMenu*>(searchEngineMenuWidgetPointer);
299 // Get the menu actions.
300 userAgentMenuActionPointer = userAgentMenuPointer->menuAction();
301 searchEngineMenuActionPointer = searchEngineMenuPointer->menuAction();
303 // Get handles for the toolbars.
304 navigationToolBarPointer = toolBar(QLatin1String("navigation_toolbar"));
305 urlToolBarPointer = toolBar(QLatin1String("url_toolbar"));
307 // Create the line edits.
308 urlLineEditPointer = new KLineEdit();
309 findTextLineEditPointer = new KLineEdit();
311 // Get the line edit size policies.
312 QSizePolicy urlLineEditSizePolicy = urlLineEditPointer->sizePolicy();
313 QSizePolicy findTextLineEditSizePolicy = findTextLineEditPointer->sizePolicy();
315 // Set the URL line edit horizontal stretch to be five times the find text line edit stretch.
316 urlLineEditSizePolicy.setHorizontalStretch(5);
317 findTextLineEditSizePolicy.setHorizontalStretch(1);
320 urlLineEditPointer->setSizePolicy(urlLineEditSizePolicy);
321 findTextLineEditPointer->setSizePolicy(findTextLineEditSizePolicy);
324 urlLineEditPointer->setMinimumWidth(350);
325 findTextLineEditPointer->setMinimumWidth(200);
326 findTextLineEditPointer->setMaximumWidth(350);
328 // Set the place holder text.
329 urlLineEditPointer->setPlaceholderText(i18nc("The URL line edit placeholder text", "URL or Search Terms"));
330 findTextLineEditPointer->setPlaceholderText(i18nc("The find line edit placeholder text", "Find Text"));
332 // Show the clear button on the find line edit.
333 findTextLineEditPointer->setClearButtonEnabled(true);
335 // Add an edit or add domain settings action to the URL line edit.
336 QAction *addOrEditDomainSettingsActionPointer = urlLineEditPointer->addAction(QIcon::fromTheme("settings-configure"), QLineEdit::TrailingPosition);
338 // Add or edit the current domain settings.
339 connect(addOrEditDomainSettingsActionPointer, SIGNAL(triggered()), this, SLOT(addOrEditDomainSettings()));
341 // Create a find text label pointer.
342 findTextLabelPointer = new QLabel();
344 // Set the default label text.
345 findTextLabelPointer->setText(QLatin1String(" ") + i18nc("Default find results.", "0/0") + QLatin1String(" "));
347 // Insert the widgets into the toolbars.
348 urlToolBarPointer->insertWidget(javaScriptActionPointer, urlLineEditPointer);
349 findTextLineEditActionPointer = urlToolBarPointer->insertWidget(findNextActionPointer, findTextLineEditPointer);
350 findTextLabelActionPointer = urlToolBarPointer->insertWidget(findNextActionPointer, findTextLabelPointer);
352 // Initially hide the find text actions.
353 hideFindTextActions();
355 // Load a new URL from the URL line edit.
356 connect(urlLineEditPointer, SIGNAL(returnKeyPressed(const QString)), this, SLOT(loadUrlFromLineEdit(const QString)));
358 // Find text as it is typed.
359 connect(findTextLineEditPointer, SIGNAL(textEdited(const QString &)), tabWidgetPointer, SLOT(findText(const QString &)));
361 // Find next if the enter key is pressed.
362 connect(findTextLineEditPointer, SIGNAL(returnKeyPressed(const QString &)), tabWidgetPointer, SLOT(findText(const QString &)));
364 // Update find text when switching tabs.
365 connect(tabWidgetPointer, SIGNAL(updateFindText(const QString &, const bool)), this, SLOT(updateFindText(const QString &, const bool)));
367 // Update the find text results.
368 connect(tabWidgetPointer, SIGNAL(updateFindTextResults(const QWebEngineFindTextResult &)), this, SLOT(updateFindTextResults(const QWebEngineFindTextResult &)));
370 // Update the URL line edit on page loads.
371 connect(tabWidgetPointer, SIGNAL(updateUrlLineEdit(QUrl)), this, SLOT(updateUrlLineEdit(QUrl)));
373 // Update the window title.
374 connect(tabWidgetPointer, SIGNAL(updateWindowTitle(const QString)), this, SLOT(updateWindowTitle(const QString)));
376 // Get a handle for the status bar.
377 QStatusBar *statusBarPointer = statusBar();
379 // Create a progress bar.
380 progressBarPointer = new QProgressBar();
382 // Add the progress bar to to the status bar.
383 statusBarPointer->addPermanentWidget(progressBarPointer);
385 // Update the status bar with the URL when a link is hovered.
386 connect(tabWidgetPointer, SIGNAL(linkHovered(QString)), statusBarPointer, SLOT(showMessage(QString)));
388 // Update the progress bar.
389 connect(tabWidgetPointer, SIGNAL(showProgressBar(const int)), this, SLOT(showProgressBar(const int)));
390 connect(tabWidgetPointer, SIGNAL(hideProgressBar()), progressBarPointer, SLOT(hide()));
392 // Update the URL line edit focus.
393 connect(tabWidgetPointer, SIGNAL(clearUrlLineEditFocus()), this, SLOT(clearUrlLineEditFocus()));
395 // Get the URL line edit palettes.
396 normalBackgroundPalette = urlLineEditPointer->palette();
397 negativeBackgroundPalette = normalBackgroundPalette;
398 positiveBackgroundPalette = normalBackgroundPalette;
400 // Modify the palettes.
401 KColorScheme::adjustBackground(negativeBackgroundPalette, KColorScheme::NegativeBackground);
402 KColorScheme::adjustBackground(positiveBackgroundPalette, KColorScheme::PositiveBackground);
404 // Update the applied palette.
405 connect(tabWidgetPointer, SIGNAL(updateDomainSettingsIndicator(const bool)), this, SLOT(updateDomainSettingsIndicator(const bool)));
407 // Process full screen requests.
408 connect(tabWidgetPointer, SIGNAL(fullScreenRequested(bool)), this, SLOT(fullScreenRequested(bool)));
410 // Create keyboard shortcuts.
411 QShortcut *f11ShortcutPointer = new QShortcut(QKeySequence(i18nc("The toggle full screen shortcut.", "F11")), this);
412 QShortcut *escapeShortcutPointer = new QShortcut(QKeySequence::Cancel, this);
414 // Connect the keyboard shortcuts.
415 connect(f11ShortcutPointer, SIGNAL(activated()), fullScreenActionPointer, SLOT(trigger()));
416 connect(escapeShortcutPointer, SIGNAL(activated()), this, SLOT(escape()));
419 // 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.
420 updateJavaScriptAction(Settings::javaScriptEnabled());
421 updateLocalStorageAction(Settings::localStorageEnabled());
422 updateDomStorageAction(Settings::domStorageEnabled());
423 updateUserAgentActions(UserAgentHelper::getUserAgentFromDatabaseName(Settings::userAgent()), true);
424 updateZoomFactorAction(Settings::zoomFactor());
426 // Load the initial website if this is the first window.
428 tabWidgetPointer->loadInitialWebsite();
431 void BrowserWindow::addOrEditDomainSettings() const
433 // Remove the focus from the URL line edit.
434 urlLineEditPointer->clearFocus();
436 // Create the domain settings dialog pointer.
437 DomainSettingsDialog *domainSettingsDialogPointer;
439 // Get the current domain settings name.
440 QString ¤tDomainSettingsName = tabWidgetPointer->getDomainSettingsName();
442 // Run the commands according to the current domain settings status.
443 if (currentDomainSettingsName == QStringLiteral("")) // Domain settings are not currently applied.
445 // Instruct the domain settings dialog to add a new domain.
446 domainSettingsDialogPointer = new DomainSettingsDialog(DomainSettingsDialog::ADD_DOMAIN, currentUrl.host());
448 else // Domain settings are currently applied.
450 // Instruct the domain settings dialog to edit the current domain.
451 domainSettingsDialogPointer = new DomainSettingsDialog(DomainSettingsDialog::EDIT_DOMAIN, currentDomainSettingsName);
454 // Set the dialog window title.
455 domainSettingsDialogPointer->setWindowTitle(i18nc("The domain settings dialog title", "Domain Settings"));
458 domainSettingsDialogPointer->setWindowModality(Qt::WindowModality::WindowModal);;
461 domainSettingsDialogPointer->show();
463 // Reload the tabs when domain settings are updated.
464 connect(domainSettingsDialogPointer, SIGNAL(domainSettingsUpdated()), tabWidgetPointer, SLOT(applyDomainSettingsAndReload()));
467 void BrowserWindow::back() const
469 // Remove the focus from the URL line edit.
470 urlLineEditPointer->clearFocus();
473 tabWidgetPointer->back();
476 void BrowserWindow::clearUrlLineEditFocus() const
478 // Remove the focus from the URL line edit.
479 urlLineEditPointer->clearFocus();
482 void BrowserWindow::escape() const
484 // Process the escape according to the status of the browser.
485 if (fullScreenActionPointer->isChecked()) // Full screen browsing is enabled.
487 // Exit full screen browsing.
488 fullScreenActionPointer->trigger();
490 else if (!findTextLineEditPointer->text().isEmpty()) // Find text is populated.
492 // Clear the find text line edit.
493 findTextLineEditPointer->clear();
495 // Clear the search in the WebEngine.
496 tabWidgetPointer->findText(QStringLiteral(""));
498 else if (findTextLineEditActionPointer->isVisible()) // Find text actions are visible.
500 // Hide the find text actions.
501 hideFindTextActions();
505 void BrowserWindow::findNext() const
507 // Get the find string.
508 const QString findString = findTextLineEditPointer->text();
510 // Search for the text if it is not empty.
511 if (!findString.isEmpty())
512 tabWidgetPointer->findText(findString);
515 void BrowserWindow::findPrevious() const
517 // Get the find string.
518 const QString findString = findTextLineEditPointer->text();
520 // Search for the text if it is not empty.
521 if (!findString.isEmpty())
522 tabWidgetPointer->findPrevious(findString);
525 void BrowserWindow::forward() const
527 // Remove the focus from the URL line edit.
528 urlLineEditPointer->clearFocus();
531 tabWidgetPointer->forward();
534 void BrowserWindow::fullScreenRequested(const bool toggleOn)
536 // Toggle full screen mode.
537 if (toggleOn) // Turn full screen mode on.
539 // Set the window to be full screen.
540 fullScreenActionPointer->setFullScreen(window(), true);
542 // Hide all the bars.
543 menuBar()->setVisible(false);
544 navigationToolBarPointer->setVisible(false);
545 urlToolBarPointer->setVisible(false);
546 tabWidgetPointer->setTabBarVisible(false);
547 statusBar()->setVisible(false);
549 else // Turn full screen mode off.
551 // Set the window to not be full screen.
552 fullScreenActionPointer->setFullScreen(window(), false);
554 // Show all the bars.
555 menuBar()->setVisible(true);
556 navigationToolBarPointer->setVisible(true);
557 urlToolBarPointer->setVisible(true);
558 tabWidgetPointer->setTabBarVisible(true);
559 statusBar()->setVisible(true);
563 void BrowserWindow::getZoomFactorFromUser()
565 // Create an OK flag.
568 // 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.
569 double newZoomFactor = QInputDialog::getDouble(this, i18nc("The on-the-fly zoom factor dialog title", "On-The-Fly Zoom Factor"),
570 i18nc("The instruction text of the on-the-fly zoom factor dialog", "Enter a zoom factor between 0.25 and 5.00"),
571 currentZoomFactor, .025, 5.00, 2, &okClicked, Qt::WindowFlags(), 0.25);
573 // Update the zoom factor if the user clicked OK.
576 // Update the current zoom factor.
577 currentZoomFactor = newZoomFactor;
579 // Set the new zoom factor.
580 tabWidgetPointer->applyOnTheFlyZoomFactor(newZoomFactor);
582 // Update the on-the-fly action text.
583 updateZoomFactorAction(newZoomFactor);
587 void BrowserWindow::hideFindTextActions() const
589 // Hide the find text actions.
590 findTextLineEditActionPointer->setVisible(false);
591 findTextLabelActionPointer->setVisible(false);
592 findNextActionPointer->setVisible(false);
593 findPreviousActionPointer->setVisible(false);
594 findCaseSensitiveActionPointer->setVisible(false);
595 hideFindTextActionPointer->setVisible(false);
598 void BrowserWindow::home() const
600 // Remove the focus from the URL line edit.
601 urlLineEditPointer->clearFocus();
604 tabWidgetPointer->home();
607 void BrowserWindow::loadUrlFromLineEdit(const QString &url) const
609 // Remove the focus from the URL line edit.
610 urlLineEditPointer->clearFocus();
613 tabWidgetPointer->loadUrlFromLineEdit(url);
616 void BrowserWindow::newWindow() const
618 // Display a new instance of Privacy Browser.
619 (new BrowserWindow)->show();
622 void BrowserWindow::refresh() const
624 // Remove the focus from the URL line edit.
625 urlLineEditPointer->clearFocus();
627 // Refresh the web page.
628 tabWidgetPointer->refresh();
631 void BrowserWindow::showCookiesDialog()
633 // Remove the focus from the URL line edit.
634 urlLineEditPointer->clearFocus();
636 // Instantiate the cookie settings dialog.
637 CookiesDialog *cookiesDialogPointer = new CookiesDialog(tabWidgetPointer->getCookieList());
640 cookiesDialogPointer->show();
642 // Connect the dialog signals.
643 connect(cookiesDialogPointer, SIGNAL(addCookie(QNetworkCookie)), tabWidgetPointer, SLOT(addCookieToStore(QNetworkCookie)));
644 connect(cookiesDialogPointer, SIGNAL(deleteAllCookies()), tabWidgetPointer, SLOT(deleteAllCookies()));
645 connect(cookiesDialogPointer, SIGNAL(deleteCookie(QNetworkCookie)), tabWidgetPointer, SLOT(deleteCookieFromStore(QNetworkCookie)));
648 void BrowserWindow::showDownloadLocationBrowseDialog() const
650 // Get the current download location.
651 QString currentDownloadLocation = downloadLocationComboBoxPointer->currentText();
653 // Resolve the system download directory if specified.
654 if (currentDownloadLocation == QStringLiteral("System Download Directory"))
655 currentDownloadLocation = QStandardPaths::writableLocation(QStandardPaths::DownloadLocation);
657 // Get the new download location.
658 QString newDownloadLocation = QFileDialog::getExistingDirectory(configDialogPointer, i18nc("Select download location dialog caption", "Select Download Location"), currentDownloadLocation);
660 // Populate the download location combo box according to the new download location.
661 if (newDownloadLocation == QStandardPaths::writableLocation(QStandardPaths::DownloadLocation)) // The default download location was selected.
663 // Populate the download location with the default text.
664 downloadLocationComboBoxPointer->setCurrentText("System Download Directory");
666 else if (newDownloadLocation != QStringLiteral("")) // A different directory was selected.
668 // Populate the download location.
669 downloadLocationComboBoxPointer->setCurrentText(newDownloadLocation);
673 void BrowserWindow::showDomainSettingsDialog() const
675 // Remove the focus from the URL line edit.
676 urlLineEditPointer->clearFocus();
678 // Instantiate the domain settings dialog.
679 DomainSettingsDialog *domainSettingsDialogPointer = new DomainSettingsDialog();
682 domainSettingsDialogPointer->show();
684 // Reload the tabs when domain settings are updated.
685 connect(domainSettingsDialogPointer, SIGNAL(domainSettingsUpdated()), tabWidgetPointer, SLOT(applyDomainSettingsAndReload()));
688 void BrowserWindow::showFindTextActions() const
690 // Show the find text actions.
691 findTextLineEditActionPointer->setVisible(true);
692 findTextLabelActionPointer->setVisible(true);
693 findNextActionPointer->setVisible(true);
694 findPreviousActionPointer->setVisible(true);
695 findCaseSensitiveActionPointer->setVisible(true);
696 hideFindTextActionPointer->setVisible(true);
698 // Set the focus on the find line edit.
699 findTextLineEditPointer->setFocus();
701 // Select all the text in the find line edit.
702 findTextLineEditPointer->selectAll();
705 void BrowserWindow::showProgressBar(const int &progress) const
707 // Set the progress bar value.
708 progressBarPointer->setValue(progress);
710 // Show the progress bar.
711 progressBarPointer->show();
714 void BrowserWindow::showSettingsDialog()
716 // Create the settings widgets.
717 QWidget *privacySettingsWidgetPointer = new QWidget;
718 QWidget *generalSettingsWidgetPointer = new QWidget;
719 QWidget *spellCheckSettingsWidgetPointer = new QWidget;
721 // Instantiate the settings UI.
722 Ui::PrivacySettings privacySettingsUi;
723 Ui::GeneralSettings generalSettingsUi;
724 Ui::SpellCheckSettings spellCheckSettingsUi;
726 // Setup the UI to display the settings widgets.
727 privacySettingsUi.setupUi(privacySettingsWidgetPointer);
728 generalSettingsUi.setupUi(generalSettingsWidgetPointer);
729 spellCheckSettingsUi.setupUi(spellCheckSettingsWidgetPointer);
731 // Get handles for the widgets.
732 QComboBox *userAgentComboBoxPointer = privacySettingsUi.kcfg_userAgent;
733 userAgentLabelPointer = privacySettingsUi.userAgentLabel;
734 QComboBox *searchEngineComboBoxPointer = generalSettingsUi.kcfg_searchEngine;
735 searchEngineLabelPointer = generalSettingsUi.searchEngineLabel;
736 downloadLocationComboBoxPointer = generalSettingsUi.kcfg_downloadLocation;
737 QPushButton *browseButtonPointer = generalSettingsUi.browseButton;
738 QListWidget *spellCheckListWidgetPointer = spellCheckSettingsUi.spellCheckListWidget;
740 // Populate the combo box labels.
741 updateUserAgentLabel(userAgentComboBoxPointer->currentText());
742 updateSearchEngineLabel(searchEngineComboBoxPointer->currentText());
744 // Update the labels when the combo boxes change.
745 connect(userAgentComboBoxPointer, SIGNAL(currentTextChanged(const QString)), this, SLOT(updateUserAgentLabel(const QString)));
746 connect(searchEngineComboBoxPointer, SIGNAL(currentTextChanged(const QString)), this, SLOT(updateSearchEngineLabel(const QString)));
748 // Connect the download location directory browse button.
749 connect(browseButtonPointer, SIGNAL(clicked()), this, SLOT(showDownloadLocationBrowseDialog()));
751 // Create a dictionaries QDir from the `QTWEBENGINE_DICTIONARIES_PATH` environment variable.
752 QDir dictionariesDir = QDir(qEnvironmentVariable("QTWEBENGINE_DICTIONARIES_PATH"));
754 // Get a dictionaries string list.
755 QStringList dictionariesStringList = dictionariesDir.entryList(QStringList(QLatin1String("*.bdic")), QDir::Files | QDir::NoSymLinks);
757 // Remove the `.bdic` file extensions from the dictionaries list.
758 dictionariesStringList.replaceInStrings(QLatin1String(".bdic"), QLatin1String(""));
760 // Get a list of the enabled spell check languages.
761 QStringList enabledSpellCheckLanguagesList = Settings::spellCheckLanguages();
763 // Add each dictionary to the spell check list widget.
764 foreach(QString dictionaryString, dictionariesStringList)
766 // Create a new list widget item pointer named after the dictionary string.
767 QListWidgetItem *listWidgetItemPointer = new QListWidgetItem(dictionaryString, spellCheckListWidgetPointer);
769 // Set the list widget item pointer to be checkable.
770 listWidgetItemPointer->setFlags(listWidgetItemPointer->flags() | Qt::ItemIsUserCheckable);
772 // Check the language if it is currently enabled.
773 if (enabledSpellCheckLanguagesList.contains(dictionaryString))
774 listWidgetItemPointer->setCheckState(Qt::Checked);
776 listWidgetItemPointer->setCheckState(Qt::Unchecked);
778 // Add the list widget item to the widget.
779 spellCheckListWidgetPointer->addItem(listWidgetItemPointer);
782 // Get a handle for the KConfig skeleton.
783 KConfigSkeleton *kConfigSkeletonPointer = Settings::self();
785 // Instantiate a settings config dialog from the settings.kcfg file.
786 configDialogPointer = new KConfigDialog(this, QLatin1String("settings"), kConfigSkeletonPointer);
788 // Add the settings widgets as config dialog pages.
789 configDialogPointer->addPage(privacySettingsWidgetPointer, i18nc("Settings tab title", "Privacy"), QLatin1String("privacy-browser"));
790 configDialogPointer->addPage(generalSettingsWidgetPointer, i18nc("Settings tab title", "General"), QLatin1String("breeze-settings"));
791 configDialogPointer->addPage(spellCheckSettingsWidgetPointer, i18nc("Settings tab title", "Spell Check"), QLatin1String("tools-check-spelling"));
793 // Get handles for the buttons.
794 QPushButton *applyButtonPointer = configDialogPointer->button(QDialogButtonBox::Apply);
795 QPushButton *okButtonPointer = configDialogPointer->button(QDialogButtonBox::Ok);
797 // Prevent interaction with the parent window while the dialog is open.
798 configDialogPointer->setWindowModality(Qt::WindowModal);
801 configDialogPointer->show();
803 // TODO. KConfigDialog does not respect expanding size policies. <https://redmine.stoutner.com/issues/823>
804 //configDialogPointer->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
805 //privacySettingsWidgetPointer->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
806 //generalSettingsWidgetPointer->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
807 //configDialogPointer->adjustSize();
809 // Expand the config dialog.
810 configDialogPointer->resize(1000, 500);
812 // Create a save spell check languages lambda.
813 auto saveSpellCheckLanguages = [spellCheckListWidgetPointer, kConfigSkeletonPointer, this] ()
815 // Create a list of enabled languages.
816 QStringList newSpellCheckLanguages = QStringList();
818 // Get a count of all the languages.
819 int allLanguagesCount = spellCheckListWidgetPointer->count();
821 // Get a list of all the checked languages.
822 for (int i = 0; i < allLanguagesCount; ++i) {
823 // Get the language item.
824 QListWidgetItem *languageItemPointer = spellCheckListWidgetPointer->item(i);
826 // Add the item to the enabled languages if it is checked.
827 if (languageItemPointer->checkState() == Qt::Checked)
828 newSpellCheckLanguages.append(languageItemPointer->text());
831 // Update the spell check languages.
832 if (Settings::spellCheckLanguages() != newSpellCheckLanguages)
834 // Update the spell check languages.
835 Settings::setSpellCheckLanguages(newSpellCheckLanguages);
837 // Write the settings to disk.
838 kConfigSkeletonPointer->save();
841 // Apply the spell check languages.
842 tabWidgetPointer->applySpellCheckLanguages();
846 connect(applyButtonPointer, &QPushButton::clicked, this, saveSpellCheckLanguages);
847 connect(okButtonPointer, &QPushButton::clicked, this, saveSpellCheckLanguages);
849 // Apply the settings handled by KConfig.
850 connect(configDialogPointer, SIGNAL(settingsChanged(QString)), tabWidgetPointer, SLOT(applyApplicationSettings()));
851 connect(configDialogPointer, SIGNAL(settingsChanged(QString)), tabWidgetPointer, SLOT(applyDomainSettingsAndReload()));
854 QSize BrowserWindow::sizeHint() const
856 // Return the default window size.
857 return QSize(1500, 1200);
860 void BrowserWindow::toggleDomStorage() const
862 // Remove the focus from the URL line edit.
863 urlLineEditPointer->clearFocus();
865 // Toggle DOM storage.
866 tabWidgetPointer->toggleDomStorage();
869 void BrowserWindow::toggleFindCaseSensitive() const
871 // Get the current find string.
872 const QString findString = findTextLineEditPointer->text();
874 // Toggle find case sensitive.
875 tabWidgetPointer->toggleFindCaseSensitive(findString);
878 void BrowserWindow::toggleJavaScript() const
880 // Remove the focus from the URL line edit.
881 urlLineEditPointer->clearFocus();
883 // Toggle JavaScript.
884 tabWidgetPointer->toggleJavaScript();
887 void BrowserWindow::toggleLocalStorage() const
889 // Remove the focus from the URL line edit.
890 urlLineEditPointer->clearFocus();
892 // Toggle local storage.
893 tabWidgetPointer->toggleLocalStorage();
896 void BrowserWindow::toggleFullScreen()
898 // Toggle the full screen status.
899 if (fullScreenActionPointer->isChecked()) // Enable full screen browsing mode.
901 // Enable full screen mode.
902 fullScreenActionPointer->setFullScreen(window(), true);
904 // Hide the menu bar if specified.
905 if (Settings::fullScreenHideMenuBar())
906 menuBar()->setVisible(false);
908 // Hide the toolbars if specified.
909 if (Settings::fullScreenHideToolBars())
911 navigationToolBarPointer->setVisible(false);
912 urlToolBarPointer->setVisible(false);
915 // Hide the tab bar if specified.
916 if (Settings::fullScreenHideTabBar())
917 tabWidgetPointer->setTabBarVisible(false);
919 // Hide the status bar if specified.
920 if (Settings::fullScreenHideStatusBar())
921 statusBar()->setVisible(false);
923 else // Disable full screen browsing mode.
925 // Disable full screen mode.
926 fullScreenActionPointer->setFullScreen(window(), false);
928 // Show the menu bar.
929 menuBar()->setVisible(true);
931 // Show the toolbars.
932 navigationToolBarPointer->setVisible(true);
933 urlToolBarPointer->setVisible(true);
936 tabWidgetPointer->setTabBarVisible(true);
938 // Show the status bar.
939 statusBar()->setVisible(true);
943 void BrowserWindow::updateCookiesAction(const int numberOfCookies) const
945 // Update the action text.
946 cookiesActionPointer->setText(i18nc("The Cookies action, which also displays the number of cookies", "Cookies - %1", numberOfCookies));
949 void BrowserWindow::updateDomStorageAction(const bool &isEnabled) const
951 // Set the action checked status.
952 domStorageActionPointer->setChecked(isEnabled);
955 void BrowserWindow::updateDomainSettingsIndicator(const bool status)
957 // Set the domain palette according to the status.
959 urlLineEditPointer->setPalette(positiveBackgroundPalette);
961 urlLineEditPointer->setPalette(normalBackgroundPalette);
964 void BrowserWindow::updateFindText(const QString &text, const bool findCaseSensitive) const
967 findTextLineEditPointer->setText(text);
969 // Set the find case sensitive action checked status.
970 findCaseSensitiveActionPointer->setChecked(findCaseSensitive);
973 void BrowserWindow::updateFindTextResults(const QWebEngineFindTextResult &findTextResult) const
975 // Update the find text label.
976 findTextLabelPointer->setText(QStringLiteral(" %1/%2 ").arg(findTextResult.activeMatch()).arg(findTextResult.numberOfMatches()));
978 // Set the background color according to the find status.
979 if (findTextLineEditPointer->text().isEmpty())
980 findTextLineEditPointer->setPalette(normalBackgroundPalette);
981 else if (findTextResult.numberOfMatches() == 0)
982 findTextLineEditPointer->setPalette(negativeBackgroundPalette);
984 findTextLineEditPointer->setPalette(positiveBackgroundPalette);
987 void BrowserWindow::updateJavaScriptAction(const bool &isEnabled)
989 // Update the JavaScript status.
990 javaScriptEnabled = isEnabled;
992 // Set the icon according to the status.
993 if (javaScriptEnabled)
994 javaScriptActionPointer->setIcon(QIcon(QStringLiteral(":/icons/javascript-warning")));
996 javaScriptActionPointer->setIcon(QIcon(QStringLiteral(":/icons/privacy-mode")));
998 // Set the action checked status.
999 javaScriptActionPointer->setChecked(javaScriptEnabled);
1001 // Update the status of the DOM storage action.
1002 domStorageActionPointer->setEnabled(javaScriptEnabled & localStorageEnabled);
1005 void BrowserWindow::updateLocalStorageAction(const bool &isEnabled)
1007 // Update the local storage status.
1008 localStorageEnabled = isEnabled;
1011 if (localStorageEnabled)
1012 localStorageActionPointer->setIcon(QIcon::fromTheme(QStringLiteral("disk-quota-high")));
1014 localStorageActionPointer->setIcon(QIcon::fromTheme(QStringLiteral("disk-quota")));
1016 // Set the action checked status.
1017 localStorageActionPointer->setChecked(localStorageEnabled);
1019 // Update the status of the DOM storage action.
1020 domStorageActionPointer->setEnabled(localStorageEnabled & javaScriptEnabled);
1023 void BrowserWindow::updateSearchEngineActions(const QString &searchEngine, const bool &updateCustomSearchEngineStatus)
1025 // Initialize the custom search engine flag.
1026 bool customSearchEngine = false;
1028 if (searchEngine == "Mojeek") // Mojeek.
1030 // Check the Mojeek user agent action.
1031 searchEngineMojeekActionPointer->setChecked(true);
1033 // Update the search engine menu action text.
1034 searchEngineMenuActionPointer->setText(i18nc("The main search engine menu action", "Search Engine - Mojeek"));
1036 else if (searchEngine == "Monocles") // Monocles.
1038 // Check the Monocles user agent action.
1039 searchEngineMonoclesActionPointer->setChecked(true);
1041 // Update the search engine menu action text.
1042 searchEngineMenuActionPointer->setText(i18nc("The main search engine menu action", "Search Engine - Monocles"));
1044 else if (searchEngine == "MetaGer") // MetaGer.
1046 // Check the MetaGer user agent action.
1047 searchEngineMetagerActionPointer->setChecked(true);
1049 // Update the search engine menu action text.
1050 searchEngineMenuActionPointer->setText(i18nc("The main search engine menu action", "Search Engine - MetaGer"));
1052 else if (searchEngine == "Google") // Google.
1054 // Check the Google user agent action.
1055 searchEngineGoogleActionPointer->setChecked(true);
1057 // Update the search engine menu action text.
1058 searchEngineMenuActionPointer->setText(i18nc("The main search engine menu action", "Search Engine - Google"));
1060 else if (searchEngine == "Bing") // Bing.
1062 // Check the Bing user agent action.
1063 searchEngineBingActionPointer->setChecked(true);
1065 // Update the search engine menu action text.
1066 searchEngineMenuActionPointer->setText(i18nc("The main search engine menu action", "Search Engine - Bing"));
1068 else if (searchEngine == "Yahoo") // Yahoo.
1070 // Check the Yahoo user agent action.
1071 searchEngineYahooActionPointer->setChecked(true);
1073 // Update the search engine menu action text.
1074 searchEngineMenuActionPointer->setText(i18nc("The main search engine menu action", "Search Engine - Yahoo"));
1076 else // Custom search engine.
1078 // Check the user agent.
1079 searchEngineCustomActionPointer->setChecked(true);
1081 // Update the search engine menu action text.
1082 searchEngineMenuActionPointer->setText(i18nc("The main search engine menu action", "Search Engine - Custom"));
1084 // Set the custom search engine text.
1085 searchEngineCustomActionPointer->setText(searchEngine);
1087 // Set the custom search engine flag.
1088 customSearchEngine = true;
1091 // Update the custom search engine enabled boolean.
1092 if (updateCustomSearchEngineStatus)
1093 customSearchEngineEnabled = customSearchEngine;
1095 // Format the custom search engine.
1096 if (customSearchEngineEnabled)
1098 // Enable the custom search engine.
1099 searchEngineCustomActionPointer->setEnabled(true);
1103 // Disable the custom search engine.
1104 searchEngineCustomActionPointer->setEnabled(false);
1106 // Reset the custom search engine text.
1107 searchEngineCustomActionPointer->setText(i18nc("@action", "Custom"));
1111 void BrowserWindow::updateUserAgentActions(const QString &userAgent, const bool &updateCustomUserAgentStatus)
1113 // Initialize the custom user agent flag.
1114 bool customUserAgent = false;
1116 // Check the indicated on-the-fly user agent.
1117 if (userAgent == UserAgentHelper::PRIVACY_BROWSER_USER_AGENT) // Privacy Browser.
1119 // Check the Privacy Browser user agent action.
1120 userAgentPrivacyBrowserActionPointer->setChecked(true);
1122 // Update the user agent menu action text.
1123 userAgentMenuActionPointer->setText(i18nc("The main user agent menu action", "User Agent - Privacy Browser"));
1125 else if (userAgent == TabWidget::webEngineDefaultUserAgent) // WebEngine default.
1127 // check the WebEngine default user agent action.
1128 userAgentWebEngineDefaultActionPointer->setChecked(true);
1130 // Update the user agent menu action text.
1131 userAgentMenuActionPointer->setText(i18nc("The main user agent menu action", "User Agent - WebEngine default"));
1133 else if (userAgent == UserAgentHelper::FIREFOX_LINUX_USER_AGENT) // Firefox on Linux.
1135 // Check the Firefox on Linux user agent action.
1136 userAgentFirefoxLinuxActionPointer->setChecked(true);
1138 // Update the user agent menu action text.
1139 userAgentMenuActionPointer->setText(i18nc("The main user agent menu action", "User Agent - Firefox on Linux"));
1141 else if (userAgent == UserAgentHelper::CHROMIUM_LINUX_USER_AGENT) // Chromium on Linux.
1143 // Check the Chromium on Linux user agent action.
1144 userAgentChromiumLinuxActionPointer->setChecked(true);
1146 // Update the user agent menu action text.
1147 userAgentMenuActionPointer->setText(i18nc("The main user agent menu action", "User Agent - Chromium on Linux"));
1149 else if (userAgent == UserAgentHelper::FIREFOX_WINDOWS_USER_AGENT) // Firefox on Windows.
1151 // Check the Firefox on Windows user agent action.
1152 userAgentFirefoxWindowsActionPointer->setChecked(true);
1154 // Update the user agent menu action text.
1155 userAgentMenuActionPointer->setText(i18nc("The main user agent menu action", "User Agent - Firefox on Windows"));
1157 else if (userAgent == UserAgentHelper::CHROME_WINDOWS_USER_AGENT) // Chrome on Windows.
1159 // Check the Chrome on Windows user agent action.
1160 userAgentChromeWindowsActionPointer->setChecked(true);
1162 // Update the user agent menu action text.
1163 userAgentMenuActionPointer->setText(i18nc("The main user agent menu action", "User Agent - Chrome on Windows"));
1165 else if (userAgent == UserAgentHelper::EDGE_WINDOWS_USER_AGENT) // Edge on Windows.
1167 // Check the Edge on Windows user agent action.
1168 userAgentEdgeWindowsActionPointer->setChecked(true);
1170 // Update the user agent menu action text.
1171 userAgentMenuActionPointer->setText(i18nc("The main user agent menu action", "User Agent - Edge on Windows"));
1173 else if (userAgent == UserAgentHelper::SAFARI_MACOS_USER_AGENT) // Safari on macOS.
1175 // Check the Safari on macOS user agent action.
1176 userAgentSafariMacosActionPointer->setChecked(true);
1178 // Update the user agent menu action text.
1179 userAgentMenuActionPointer->setText(i18nc("The main user agent menu action", "User Agent - Safari on macOS"));
1181 else // Custom user agent.
1183 // Check the user agent.
1184 userAgentCustomActionPointer->setChecked(true);
1186 // Update the user agent menu action text.
1187 userAgentMenuActionPointer->setText(i18nc("The main user agent menu action", "User Agent - Custom"));
1189 // Set the custom user agent text.
1190 userAgentCustomActionPointer->setText(userAgent);
1192 // Set the custom user agent flag.
1193 customUserAgent = true;
1196 // Update the custom user agent enabled boolean.
1197 // 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.
1198 if (updateCustomUserAgentStatus)
1199 customUserAgentEnabled = customUserAgent;
1202 // Format the custom user agent.
1203 if (customUserAgentEnabled)
1205 // Enable the custom user agent.
1206 userAgentCustomActionPointer->setEnabled(true);
1210 // Disable the custom user agent.
1211 userAgentCustomActionPointer->setEnabled(false);
1213 // Reset the custom user agent text.
1214 userAgentCustomActionPointer->setText(i18nc("@action", "Custom"));
1218 void BrowserWindow::updateZoomFactorAction(const double &zoomFactor)
1220 // Set the current zoom factor.
1221 currentZoomFactor = zoomFactor;
1223 // Update the zoom factor action text, formatting the double with 2 decimal places.
1224 zoomFactorActionPointer->setText(ki18nc("@action", "Zoom Factor - %1").subs(zoomFactor, 0, '0', 2).toString());
1227 void BrowserWindow::updateSearchEngineLabel(const QString &searchEngineString) const
1229 // Update the search engine label.
1230 searchEngineLabelPointer->setText(SearchEngineHelper::getSearchUrl(searchEngineString));
1233 void BrowserWindow::updateUrlLineEdit(const QUrl &newUrl)
1235 // Update the URL line edit if it does not have focus.
1236 if (!urlLineEditPointer->hasFocus())
1238 // Get the new URL string.
1239 QString newUrlString = newUrl.toString();
1241 // Update the URL line edit.
1242 urlLineEditPointer->setText(newUrlString);
1244 // Set the focus if the new URL is blank.
1245 if (newUrlString == QStringLiteral(""))
1246 urlLineEditPointer->setFocus();
1249 // Store the current URL.
1250 currentUrl = newUrl;
1253 void BrowserWindow::updateUserAgentLabel(const QString &userAgentDatabaseName) const
1255 // Update the user agent label.
1256 userAgentLabelPointer->setText(UserAgentHelper::getUserAgentFromDatabaseName(userAgentDatabaseName));
1259 void BrowserWindow::updateWindowTitle(const QString &title)
1261 // Update the window title.
1262 setWindowTitle(title);