]> gitweb.stoutner.com Git - PrivacyBrowserPC.git/blob - src/widgets/TabWidget.cpp
Enable the integrated PDF viewer. https://redmine.stoutner.com/issues/835
[PrivacyBrowserPC.git] / src / widgets / TabWidget.cpp
1 /*
2  * Copyright 2022-2023 Soren Stoutner <soren@stoutner.com>.
3  *
4  * This file is part of Privacy Browser PC <https://www.stoutner.com/privacy-browser-pc>.
5  *
6  * Privacy Browser PC is free software: you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation, either version 3 of the License, or
9  * (at your option) any later version.
10  *
11  * Privacy Browser PC is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with Privacy Browser PC.  If not, see <http://www.gnu.org/licenses/>.
18  */
19
20 // Application headers.
21 #include "TabWidget.h"
22 #include "Settings.h"
23 #include "ui_AddTabWidget.h"
24 #include "ui_TabWidget.h"
25 #include "databases/CookiesDatabase.h"
26 #include "databases/DomainsDatabase.h"
27 #include "dialogs/SaveDialog.h"
28 #include "filters/MouseEventFilter.h"
29 #include "helpers/SearchEngineHelper.h"
30 #include "interceptors/UrlRequestInterceptor.h"
31 #include "windows/BrowserWindow.h"
32
33 // KDE Framework headers.
34 #include <KIO/FileCopyJob>
35 #include <KIO/JobUiDelegate>
36 #include <KNotification>
37
38 // Qt toolkit headers.
39 #include <QAction>
40 #include <QFileDialog>
41 #include <QGraphicsScene>
42 #include <QGraphicsView>
43 #include <QPrintDialog>
44 #include <QPrintPreviewDialog>
45 #include <QPrinter>
46
47 // Initialize the public static variables.
48 QString TabWidget::webEngineDefaultUserAgent = QLatin1String("");
49
50 // Construct the class.
51 TabWidget::TabWidget(QWidget *parent) : QWidget(parent)
52 {
53     // Instantiate the user agent helper.
54     userAgentHelperPointer = new UserAgentHelper();
55
56     // Instantiate the UIs.
57     Ui::TabWidget tabWidgetUi;
58     Ui::AddTabWidget addTabWidgetUi;
59
60     // Setup the main UI.
61     tabWidgetUi.setupUi(this);
62
63     // Get a handle for the tab widget.
64     tabWidgetPointer = tabWidgetUi.tabWidget;
65
66     // Setup the add tab UI.
67     addTabWidgetUi.setupUi(tabWidgetPointer);
68
69     // Get handles for the add tab widgets.
70     QWidget *addTabWidgetPointer = addTabWidgetUi.addTabQWidget;
71     QPushButton *addTabButtonPointer = addTabWidgetUi.addTabButton;
72
73     // Display the add tab widget.
74     tabWidgetPointer->setCornerWidget(addTabWidgetPointer);
75
76     // Add the first tab.
77     addFirstTab();
78
79     // Process tab events.
80     connect(tabWidgetPointer, SIGNAL(currentChanged(int)), this, SLOT(updateUiWithTabSettings()));
81     connect(addTabButtonPointer, SIGNAL(clicked()), this, SLOT(addTab()));
82     connect(tabWidgetPointer, SIGNAL(tabCloseRequested(int)), this, SLOT(deleteTab(int)));
83
84     // Store a copy of the WebEngine default user agent.
85     webEngineDefaultUserAgent = currentWebEngineProfilePointer->httpUserAgent();
86
87     // Instantiate the mouse event filter pointer.
88     MouseEventFilter *mouseEventFilterPointer = new MouseEventFilter();
89
90     // Install the mouse event filter.
91     qApp->installEventFilter(mouseEventFilterPointer);
92
93     // Process mouse forward and back commands.
94     connect(mouseEventFilterPointer, SIGNAL(mouseBack()), this, SLOT(mouseBack()));
95     connect(mouseEventFilterPointer, SIGNAL(mouseForward()), this, SLOT(mouseForward()));
96 }
97
98 TabWidget::~TabWidget()
99 {
100     // Manually delete each WebEngine page.
101     for (int i = 0; i < tabWidgetPointer->count(); ++i)
102     {
103         // Get the privacy WebEngine view.
104         PrivacyWebEngineView *privacyWebEngineViewPointer = qobject_cast<PrivacyWebEngineView *>(tabWidgetPointer->widget(i));
105
106         // Deletion the WebEngine page to prevent the following error:  `Release of profile requested but WebEnginePage still not deleted. Expect troubles !`
107         delete privacyWebEngineViewPointer->page();
108     }
109 }
110
111 // The cookie is copied instead of referenced so that changes made to the cookie do not create a race condition with the display of the cookie in the dialog.
112 void TabWidget::addCookieToStore(QNetworkCookie cookie, QWebEngineCookieStore *webEngineCookieStorePointer) const
113 {
114     // Create a url.
115     QUrl url;
116
117     // Check to see if the domain does not start with a `.` because Qt makes this harder than it should be.  <https://doc.qt.io/qt-5/qwebenginecookiestore.html#setCookie>
118     if (!cookie.domain().startsWith(QLatin1String(".")))
119     {
120         // Populate the URL.
121         url.setHost(cookie.domain());
122         url.setScheme(QLatin1String("https"));
123
124         // Clear the domain from the cookie.
125         cookie.setDomain(QLatin1String(""));
126     }
127
128     // Add the cookie to the store.
129     if (webEngineCookieStorePointer == nullptr)
130         currentWebEngineCookieStorePointer->setCookie(cookie, url);
131     else
132         webEngineCookieStorePointer->setCookie(cookie, url);
133 }
134
135 void TabWidget::addFirstTab()
136 {
137     // Create the first tab.
138     addTab();
139
140     // Update the UI with the tab settings.
141     updateUiWithTabSettings();
142
143     // Set the focus on the current tab widget.  This prevents the tab bar from showing a blue bar under the label of the first tab.
144     tabWidgetPointer->currentWidget()->setFocus();
145 }
146
147 PrivacyWebEngineView* TabWidget::addTab(const bool removeUrlLineEditFocus, const bool backgroundTab)
148 {
149     // Create a privacy WebEngine view.
150     PrivacyWebEngineView *privacyWebEngineViewPointer = new PrivacyWebEngineView();
151
152     // Add a new tab.
153     int newTabIndex = tabWidgetPointer->addTab(privacyWebEngineViewPointer, i18nc("New tab label.", "New Tab"));
154
155     // Set the default tab icon.
156     tabWidgetPointer->setTabIcon(newTabIndex, defaultTabIcon);
157
158     // Create an off-the-record profile (the default when no profile name is specified).
159     QWebEngineProfile *webEngineProfilePointer = new QWebEngineProfile(QLatin1String(""));
160
161     // Create a WebEngine page.
162     QWebEnginePage *webEnginePagePointer = new QWebEnginePage(webEngineProfilePointer);
163
164     // Set the WebEngine page.
165     privacyWebEngineViewPointer->setPage(webEnginePagePointer);
166
167     // Get handles for the web engine elements.
168     QWebEngineCookieStore *webEngineCookieStorePointer = webEngineProfilePointer->cookieStore();
169     QWebEngineSettings *webEngineSettingsPointer = webEnginePagePointer->settings();
170
171     // Update the URL line edit when the URL changes.
172     connect(privacyWebEngineViewPointer, &PrivacyWebEngineView::urlChanged, [privacyWebEngineViewPointer, this] (const QUrl &newUrl)
173     {
174         // Only update the UI if this is the current tab.
175         if (privacyWebEngineViewPointer == currentPrivacyWebEngineViewPointer)
176         {
177             // Update the URL line edit.
178             emit updateUrlLineEdit(newUrl);
179
180             // Update the status of the forward and back buttons.
181             emit updateBackAction(currentWebEngineHistoryPointer->canGoBack());
182             emit updateForwardAction(currentWebEngineHistoryPointer->canGoForward());
183         }
184
185         // Reapply the zoom factor.  This is a bug in QWebEngineView that resets the zoom with every load.  It can be removed once <https://redmine.stoutner.com/issues/799> is fixed.
186         privacyWebEngineViewPointer->setZoomFactor(currentZoomFactor);
187     });
188
189     // Update the progress bar when a load is started.
190     connect(privacyWebEngineViewPointer, &PrivacyWebEngineView::loadStarted, [privacyWebEngineViewPointer, this] ()
191     {
192         // Store the load progress.
193         privacyWebEngineViewPointer->loadProgressInt = 0;
194
195         // Show the progress bar if this is the current tab.
196         if (privacyWebEngineViewPointer == currentPrivacyWebEngineViewPointer)
197             emit showProgressBar(0);
198     });
199
200     // Update the progress bar when a load progresses.
201     connect(privacyWebEngineViewPointer, &PrivacyWebEngineView::loadProgress, [privacyWebEngineViewPointer, this] (const int progress)
202     {
203         // Store the load progress.
204         privacyWebEngineViewPointer->loadProgressInt = progress;
205
206         // Update the progress bar if this is the current tab.
207         if (privacyWebEngineViewPointer == currentPrivacyWebEngineViewPointer)
208             emit showProgressBar(progress);
209     });
210
211     // Update the progress bar when a load finishes.
212     connect(privacyWebEngineViewPointer, &PrivacyWebEngineView::loadFinished, [privacyWebEngineViewPointer, this] ()
213     {
214         // Store the load progress.
215         privacyWebEngineViewPointer->loadProgressInt = -1;
216
217         // Hide the progress bar if this is the current tab.
218         if (privacyWebEngineViewPointer == currentPrivacyWebEngineViewPointer)
219             emit hideProgressBar();
220     });
221
222     // Display find text results.
223     connect(webEnginePagePointer, SIGNAL(findTextFinished(const QWebEngineFindTextResult &)), this, SLOT(findTextFinished(const QWebEngineFindTextResult &)));
224
225     // Handle full screen requests.
226     connect(webEnginePagePointer, SIGNAL(fullScreenRequested(QWebEngineFullScreenRequest)), this, SLOT(fullScreenRequested(QWebEngineFullScreenRequest)));
227
228     // Listen for hovered link URLs.
229     connect(webEnginePagePointer, SIGNAL(linkHovered(const QString)), this, SLOT(pageLinkHovered(const QString)));
230
231     // Handle file downloads.
232     connect(webEngineProfilePointer, SIGNAL(downloadRequested(QWebEngineDownloadItem *)), this, SLOT(showSaveDialog(QWebEngineDownloadItem *)));
233
234     // Instantiate the URL request interceptor.
235     UrlRequestInterceptor *urlRequestInterceptorPointer = new UrlRequestInterceptor();
236
237     // Set the URL request interceptor.
238     webEngineProfilePointer->setUrlRequestInterceptor(urlRequestInterceptorPointer);
239
240     // Reapply the domain settings when the host changes.
241     connect(urlRequestInterceptorPointer, SIGNAL(applyDomainSettings(QString)), this, SLOT(applyDomainSettingsWithoutReloading(QString)));
242
243     // Set the local storage filter.
244     webEngineCookieStorePointer->setCookieFilter([privacyWebEngineViewPointer](const QWebEngineCookieStore::FilterRequest &filterRequest)
245     {
246         // Block all third party local storage requests, including the sneaky ones that don't register a first party URL.
247         if (filterRequest.thirdParty || (filterRequest.firstPartyUrl == QStringLiteral("")))
248         {
249             //qDebug().noquote().nospace() << "Third-party request blocked:  " << filterRequest.origin;
250
251             // Return false.
252             return false;
253         }
254
255         // Allow the request if local storage is enabled.
256         if (privacyWebEngineViewPointer->localStorageEnabled)
257         {
258             //qDebug().noquote().nospace() << "Request allowed by local storage:  " << filterRequest.origin;
259
260             // Return true.
261             return true;
262         }
263
264         //qDebug().noquote().nospace() << "Request blocked by default:  " << filterRequest.origin;
265
266         // Block any remaining local storage requests.
267         return false;
268     });
269
270     // Disable JavaScript by default (this prevents JavaScript from being enabled on a new tab before domain settings are loaded).
271     webEngineSettingsPointer->setAttribute(QWebEngineSettings::JavascriptEnabled, false);
272
273     // Don't allow JavaScript to open windows.
274     webEngineSettingsPointer->setAttribute(QWebEngineSettings::JavascriptCanOpenWindows, false);
275
276     // Allow keyboard navigation.
277     webEngineSettingsPointer->setAttribute(QWebEngineSettings::SpatialNavigationEnabled, true);
278
279     // Enable full screen support.
280     webEngineSettingsPointer->setAttribute(QWebEngineSettings::FullScreenSupportEnabled, true);
281
282     // Require user interaction to play media.
283     webEngineSettingsPointer->setAttribute(QWebEngineSettings::PlaybackRequiresUserGesture, true);
284
285     // Limit WebRTC to public IP addresses.
286     webEngineSettingsPointer->setAttribute(QWebEngineSettings::WebRTCPublicInterfacesOnly, true);
287
288     // Enable the PDF viewer (it should be enabled by default, but it is nice to be explicit in case the defaults change).
289     webEngineSettingsPointer->setAttribute(QWebEngineSettings::PdfViewerEnabled, true);
290
291     // Plugins must be enabled for the PDF viewer to work.  <https://doc.qt.io/qt-5/qtwebengine-features.html#pdf-file-viewing>
292     webEngineSettingsPointer->setAttribute(QWebEngineSettings::PluginsEnabled, true);
293
294     // Update the cookies action.
295     connect(privacyWebEngineViewPointer, &PrivacyWebEngineView::updateCookiesAction, [privacyWebEngineViewPointer, this] (const int numberOfCookies)
296     {
297         // Update the cookie action if the specified privacy WebEngine view is the current privacy WebEngine view.
298         if (privacyWebEngineViewPointer == currentPrivacyWebEngineViewPointer)
299             emit updateCookiesAction(numberOfCookies);
300     });
301
302     // Process cookie changes.
303     connect(webEngineCookieStorePointer, SIGNAL(cookieAdded(QNetworkCookie)), privacyWebEngineViewPointer, SLOT(addCookieToList(QNetworkCookie)));
304     connect(webEngineCookieStorePointer, SIGNAL(cookieRemoved(QNetworkCookie)), privacyWebEngineViewPointer, SLOT(removeCookieFromList(QNetworkCookie)));
305
306     // Get a list of durable cookies.
307     QList<QNetworkCookie*> *durableCookiesListPointer = CookiesDatabase::getCookies();
308
309     // Add the durable cookies to the store.
310     for (QNetworkCookie *cookiePointer : *durableCookiesListPointer)
311         addCookieToStore(*cookiePointer, webEngineCookieStorePointer);
312
313     // Update the title when it changes.
314     connect(privacyWebEngineViewPointer, &PrivacyWebEngineView::titleChanged, [this, privacyWebEngineViewPointer] (const QString &title)
315     {
316         // Get the index for this tab.
317         int tabIndex = tabWidgetPointer->indexOf(privacyWebEngineViewPointer);
318
319         // Update the title for this tab.
320         tabWidgetPointer->setTabText(tabIndex, title);
321
322         // Update the window title if this is the current tab.
323         if (tabIndex == tabWidgetPointer->currentIndex())
324             emit updateWindowTitle(title);
325     });
326
327     // Update the icon when it changes.
328     connect(privacyWebEngineViewPointer, &PrivacyWebEngineView::iconChanged, [privacyWebEngineViewPointer, this] (const QIcon &icon)
329     {
330         // Get the index for this tab.
331         int tabIndex = tabWidgetPointer->indexOf(privacyWebEngineViewPointer);
332
333         // Update the icon for this tab.
334         if (icon.isNull())
335             tabWidgetPointer->setTabIcon(tabIndex, defaultTabIcon);
336         else
337             tabWidgetPointer->setTabIcon(tabIndex, icon);
338     });
339
340     // Enable spell checking.
341     webEngineProfilePointer->setSpellCheckEnabled(true);
342
343     // Set the spell check language.
344     webEngineProfilePointer->setSpellCheckLanguages({QLatin1String("en_US")});
345
346     // Populate the zoom factor.  This is necessary if a URL is being loaded, like a local URL, that does not trigger `applyDomainSettings()`.
347     privacyWebEngineViewPointer->setZoomFactor(Settings::zoomFactor());
348
349     // Move to the new tab if it is not a background tab.
350     if (!backgroundTab)
351         tabWidgetPointer->setCurrentIndex(newTabIndex);
352
353     // Clear the URL line edit focus so that it populates correctly when opening a new tab from the context menu.
354     if (removeUrlLineEditFocus)
355         emit clearUrlLineEditFocus();
356
357     // Return the privacy WebEngine view pointer.
358     return privacyWebEngineViewPointer;
359 }
360
361 void TabWidget::applyApplicationSettings()
362 {
363     // Set the tab position.
364     if (Settings::tabsOnTop())
365         tabWidgetPointer->setTabPosition(QTabWidget::North);
366     else
367         tabWidgetPointer->setTabPosition(QTabWidget::South);
368
369     // Set the search engine URL.
370     searchEngineUrl = SearchEngineHelper::getSearchUrl(Settings::searchEngine());
371
372     // Emit the update search engine actions signal.
373     emit updateSearchEngineActions(Settings::searchEngine(), true);
374 }
375
376 // This exists as a separate function from `applyDomainSettings()` so it can be listed as a slot and function without the need for a boolean argument.
377 // Once <https://redmine.stoutner.com/issues/799> has been resolved this can be `const`.
378 void TabWidget::applyDomainSettingsAndReload()
379 {
380     // Apply the domain settings.  `true` reloads the website.
381     applyDomainSettings(currentPrivacyWebEngineViewPointer->url().host(), true);
382 }
383
384 // This exists as a separate function from `applyDomainSettings()` so it can be listed as a slot and function without the need for a boolean argument.
385 // Once <https://redmine.stoutner.com/issues/799> has been resolved this can be `const`.
386 void TabWidget::applyDomainSettingsWithoutReloading(const QString &hostname)
387 {
388     // Apply the domain settings  `false` does not reload the website.
389     applyDomainSettings(hostname, false);
390 }
391
392 // Once <https://redmine.stoutner.com/issues/799> has been resolved this can be `const`.
393 void TabWidget::applyDomainSettings(const QString &hostname, const bool reloadWebsite)
394 {
395     // Get the record for the hostname.
396     QSqlQuery domainQuery = DomainsDatabase::getDomainQuery(hostname);
397
398     // Check if the hostname has domain settings.
399     if (domainQuery.isValid())  // The hostname has domain settings.
400     {
401         // Get the domain record.
402         QSqlRecord domainRecord = domainQuery.record();
403
404         // Store the domain settings name.
405         currentPrivacyWebEngineViewPointer->domainSettingsName = domainRecord.field(DomainsDatabase::DOMAIN_NAME).value().toString();
406
407         // Set the JavaScript status.
408         switch (domainRecord.field(DomainsDatabase::JAVASCRIPT).value().toInt())
409         {
410             // Set the default JavaScript status.
411             case (DomainsDatabase::SYSTEM_DEFAULT):
412             {
413                 currentWebEngineSettingsPointer->setAttribute(QWebEngineSettings::JavascriptEnabled, Settings::javaScriptEnabled());
414
415                 break;
416             }
417
418             // Disable JavaScript.
419             case (DomainsDatabase::DISABLED):
420             {
421                 currentWebEngineSettingsPointer->setAttribute(QWebEngineSettings::JavascriptEnabled, false);
422
423                 break;
424             }
425
426             // Enable JavaScript.
427             case (DomainsDatabase::ENABLED):
428             {
429                 currentWebEngineSettingsPointer->setAttribute(QWebEngineSettings::JavascriptEnabled, true);
430
431                 break;
432             }
433         }
434
435         // Set the local storage status.
436         switch (domainRecord.field(DomainsDatabase::LOCAL_STORAGE).value().toInt())
437         {
438             // Set the default local storage status.
439             case (DomainsDatabase::SYSTEM_DEFAULT):
440             {
441                 currentPrivacyWebEngineViewPointer->localStorageEnabled = Settings::localStorageEnabled();
442
443                 break;
444             }
445
446             // Disable local storage.
447             case (DomainsDatabase::DISABLED):
448             {
449                 currentPrivacyWebEngineViewPointer->localStorageEnabled = false;
450
451                 break;
452             }
453
454             // Enable local storage.
455             case (DomainsDatabase::ENABLED):
456             {
457                 currentPrivacyWebEngineViewPointer->localStorageEnabled = true;
458
459                 break;
460             }
461         }
462
463         // Set the DOM storage status.
464         switch (domainRecord.field(DomainsDatabase::DOM_STORAGE).value().toInt())
465         {
466             // Set the default DOM storage status.  QWebEngineSettings confusingly calls this local storage.
467             case (DomainsDatabase::SYSTEM_DEFAULT):
468             {
469                 currentWebEngineSettingsPointer->setAttribute(QWebEngineSettings::LocalStorageEnabled, Settings::domStorageEnabled());
470
471                 break;
472             }
473
474             // Disable DOM storage.  QWebEngineSettings confusingly calls this local storage.
475             case (DomainsDatabase::DISABLED):
476             {
477                 currentWebEngineSettingsPointer->setAttribute(QWebEngineSettings::LocalStorageEnabled, false);
478
479                 break;
480             }
481
482             // Enable DOM storage.  QWebEngineSettings confusingly calls this local storage.
483             case (DomainsDatabase::ENABLED):
484             {
485                 currentWebEngineSettingsPointer->setAttribute(QWebEngineSettings::LocalStorageEnabled, true);
486
487                 break;
488             }
489         }
490
491         // Set the user agent.
492         currentWebEngineProfilePointer->setHttpUserAgent(UserAgentHelper::getResultingDomainSettingsUserAgent(domainRecord.field(DomainsDatabase::USER_AGENT).value().toString()));
493
494         // Check if a custom zoom factor is set.
495         if (domainRecord.field(DomainsDatabase::ZOOM_FACTOR).value().toInt())
496         {
497             // Store the current zoom factor.
498             currentZoomFactor = domainRecord.field(DomainsDatabase::CUSTOM_ZOOM_FACTOR).value().toDouble();
499         }
500         else
501         {
502             // Reset the current zoom factor.
503             currentZoomFactor = Settings::zoomFactor();
504         }
505
506         // Set the zoom factor.    The use of `currentZoomFactor` can be removed once <https://redmine.stoutner.com/issues/799> has been resolved.
507         currentPrivacyWebEngineViewPointer->setZoomFactor(currentZoomFactor);
508     }
509     else  // The hostname does not have domain settings.
510     {
511         // Reset the domain settings name.
512         currentPrivacyWebEngineViewPointer->domainSettingsName = QLatin1String("");
513
514         // Set the JavaScript status.
515         currentWebEngineSettingsPointer->setAttribute(QWebEngineSettings::JavascriptEnabled, Settings::javaScriptEnabled());
516
517         // Set the local storage status.
518         currentPrivacyWebEngineViewPointer->localStorageEnabled = Settings::localStorageEnabled();
519
520         // Set DOM storage.  In QWebEngineSettings it is called Local Storage.
521         currentWebEngineSettingsPointer->setAttribute(QWebEngineSettings::LocalStorageEnabled, Settings::domStorageEnabled());
522
523         // Set the user agent.
524         currentWebEngineProfilePointer->setHttpUserAgent(UserAgentHelper::getUserAgentFromDatabaseName(Settings::userAgent()));
525
526         // Store the current zoom factor.  This can be removed once <https://redmine.stoutner.com/issues/799> has been resolved.
527         currentZoomFactor = Settings::zoomFactor();
528
529         // Set the zoom factor.
530         currentPrivacyWebEngineViewPointer->setZoomFactor(Settings::zoomFactor());
531     }
532
533     // Update the UI.
534     emit updateDomainSettingsIndicator(currentPrivacyWebEngineViewPointer->domainSettingsName != QLatin1String(""));
535     emit updateJavaScriptAction(currentWebEngineSettingsPointer->testAttribute(QWebEngineSettings::JavascriptEnabled));
536     emit updateLocalStorageAction(currentPrivacyWebEngineViewPointer->localStorageEnabled);
537     emit updateDomStorageAction(currentWebEngineSettingsPointer->testAttribute(QWebEngineSettings::LocalStorageEnabled));
538     emit updateUserAgentActions(currentWebEngineProfilePointer->httpUserAgent(), true);
539     emit updateZoomFactorAction(currentPrivacyWebEngineViewPointer->zoomFactor());
540
541     // Reload the website if requested.
542     if (reloadWebsite)
543         currentPrivacyWebEngineViewPointer->reload();
544 }
545
546 void TabWidget::applyOnTheFlySearchEngine(QAction *searchEngineActionPointer)
547 {
548     // Store the search engine name.
549     QString searchEngineName = searchEngineActionPointer->text();
550
551     // Strip out any `&` characters.
552     searchEngineName.remove('&');
553
554     // Store the search engine string.
555     searchEngineUrl = SearchEngineHelper::getSearchUrl(searchEngineName);
556
557     // Update the search engine actionas.
558     emit updateSearchEngineActions(searchEngineName, false);
559 }
560
561 void TabWidget::applyOnTheFlyUserAgent(QAction *userAgentActionPointer) const
562 {
563     // Get the user agent name.
564     QString userAgentName = userAgentActionPointer->text();
565
566     // Strip out any `&` characters.
567     userAgentName.remove('&');
568
569     // Apply the user agent.
570     currentWebEngineProfilePointer->setHttpUserAgent(userAgentHelperPointer->getUserAgentFromTranslatedName(userAgentName));
571
572     // Update the user agent actions.
573     emit updateUserAgentActions(currentWebEngineProfilePointer->httpUserAgent(), false);
574
575     // Reload the website.
576     currentPrivacyWebEngineViewPointer->reload();
577 }
578
579 // This can be const once <https://redmine.stoutner.com/issues/799> has been resolved.
580 void TabWidget::applyOnTheFlyZoomFactor(const double &zoomFactor)
581 {
582     // Update the current zoom factor.  This can be removed once <https://redmine.stoutner.com/issues/799> has been resolved.
583     currentZoomFactor = zoomFactor;
584
585     // Set the zoom factor.
586     currentPrivacyWebEngineViewPointer->setZoomFactor(zoomFactor);
587 }
588
589 void TabWidget::back() const
590 {
591     // Go back.
592     currentPrivacyWebEngineViewPointer->back();
593 }
594
595 void TabWidget::deleteAllCookies() const
596 {
597     // Delete all the cookies.
598     currentWebEngineCookieStorePointer->deleteAllCookies();
599 }
600
601 void TabWidget::deleteCookieFromStore(const QNetworkCookie &cookie) const
602 {
603     // Delete the cookie.
604     currentWebEngineCookieStorePointer->deleteCookie(cookie);
605 }
606
607 void TabWidget::deleteTab(const int tabIndex)
608 {
609     // Get the privacy WebEngine view.
610     PrivacyWebEngineView *privacyWebEngineViewPointer = qobject_cast<PrivacyWebEngineView *>(tabWidgetPointer->widget(tabIndex));
611
612     // Proccess the tab delete according to the number of tabs.
613     if (tabWidgetPointer->count() > 1)  // There is more than one tab.
614     {
615         // Delete the tab.
616         tabWidgetPointer->removeTab(tabIndex);
617
618         // Delete the WebEngine page to prevent the following error:  `Release of profile requested but WebEnginePage still not deleted. Expect troubles !`
619         delete privacyWebEngineViewPointer->page();
620
621         // Delete the privacy WebEngine view.
622         delete privacyWebEngineViewPointer;
623     }
624     else  // There is only one tab.
625     {
626         // Close Privacy Browser.
627         window()->close();
628     }
629 }
630
631 void TabWidget::findPrevious(const QString &text) const
632 {
633     // Store the current text.
634     currentPrivacyWebEngineViewPointer->findString = text;
635
636     // Find the previous text in the current privacy WebEngine.
637     if (currentPrivacyWebEngineViewPointer->findCaseSensitive)
638         currentPrivacyWebEngineViewPointer->findText(text, QWebEnginePage::FindCaseSensitively|QWebEnginePage::FindBackward);
639     else
640         currentPrivacyWebEngineViewPointer->findText(text, QWebEnginePage::FindBackward);
641 }
642
643 void TabWidget::findText(const QString &text) const
644 {
645     // Store the current text.
646     currentPrivacyWebEngineViewPointer->findString = text;
647
648     // Find the text in the current privacy WebEngine.
649     if (currentPrivacyWebEngineViewPointer->findCaseSensitive)
650         currentPrivacyWebEngineViewPointer->findText(text, QWebEnginePage::FindCaseSensitively);
651     else
652         currentPrivacyWebEngineViewPointer->findText(text);
653
654     // Clear the currently selected text in the WebEngine page if the find text is empty.
655     if (text.isEmpty())
656         currentWebEnginePagePointer->action(QWebEnginePage::Unselect)->activate(QAction::Trigger);
657 }
658
659 void TabWidget::findTextFinished(const QWebEngineFindTextResult &findTextResult)
660 {
661     // Update the find text UI if it wasn't simply wiping the current find text selection.  Otherwise the UI temporarially flashes `0/0`.
662     if (wipingCurrentFindTextSelection)  // The current selection is being wiped.
663     {
664         // Reset the flag.
665         wipingCurrentFindTextSelection = false;
666     }
667     else  // A new search has been performed.
668     {
669         // Store the result.
670         currentPrivacyWebEngineViewPointer->findTextResult = findTextResult;
671
672         // Update the UI.
673         emit updateFindTextResults(findTextResult);
674     }
675 }
676
677 void TabWidget::forward() const
678 {
679     // Go forward.
680     currentPrivacyWebEngineViewPointer->forward();
681 }
682
683 void TabWidget::fullScreenRequested(QWebEngineFullScreenRequest fullScreenRequest) const
684 {
685     // Make it so.
686     emit fullScreenRequested(fullScreenRequest.toggleOn());
687
688     // Accept the request.
689     fullScreenRequest.accept();
690 }
691
692 std::list<QNetworkCookie>* TabWidget::getCookieList() const
693 {
694     // Return the current cookie list.
695     return currentPrivacyWebEngineViewPointer->cookieListPointer;
696 }
697
698 QString& TabWidget::getDomainSettingsName() const
699 {
700     // Return the domain settings name.
701     return currentPrivacyWebEngineViewPointer->domainSettingsName;
702 }
703
704 void TabWidget::home() const
705 {
706     // Load the homepage.
707     currentPrivacyWebEngineViewPointer->load(QUrl::fromUserInput(Settings::homepage()));
708 }
709
710 PrivacyWebEngineView* TabWidget::loadBlankInitialWebsite()
711 {
712     // Apply the application settings.
713     applyApplicationSettings();
714
715     // Return the current privacy WebEngine view pointer.
716     return currentPrivacyWebEngineViewPointer;
717 }
718
719 void TabWidget::loadInitialWebsite()
720 {
721     // Apply the application settings.
722     applyApplicationSettings();
723
724     // Get the arguments.
725     QStringList argumentsStringList = qApp->arguments();
726
727     // Check to see if the arguments lists contains a URL.
728     if (argumentsStringList.size() > 1)
729     {
730         // Load the URL from the arguments list.
731         currentPrivacyWebEngineViewPointer->load(QUrl::fromUserInput(argumentsStringList.at(1)));
732     }
733     else
734     {
735         // Load the homepage.
736         home();
737     }
738 }
739
740 void TabWidget::loadUrlFromLineEdit(QString url) const
741 {
742     // Decide if the text is more likely to be a URL or a search.
743     if (url.startsWith("file://"))  // The text is likely a file URL.
744     {
745         // Load the URL.
746         currentPrivacyWebEngineViewPointer->load(QUrl::fromUserInput(url));
747     }
748     else if (url.contains("."))  // The text is likely a URL.
749     {
750         // Check if the URL does not start with a valid protocol.
751         if (!url.startsWith("http"))
752         {
753             // Add `https://` to the beginning of the URL.
754             url = "https://" + url;
755         }
756
757         // Load the URL.
758         currentPrivacyWebEngineViewPointer->load(QUrl::fromUserInput(url));
759     }
760     else  // The text is likely a search.
761     {
762         // Load the search.
763         currentPrivacyWebEngineViewPointer->load(QUrl::fromUserInput(searchEngineUrl + url));
764     }
765 }
766
767 void TabWidget::mouseBack() const
768 {
769     // Go back if possible.
770     if (currentPrivacyWebEngineViewPointer->isActiveWindow() && currentWebEngineHistoryPointer->canGoBack())
771     {
772         // Clear the URL line edit focus.
773         emit clearUrlLineEditFocus();
774
775         // Go back.
776         currentPrivacyWebEngineViewPointer->back();
777     }
778 }
779
780 void TabWidget::mouseForward() const
781 {
782     // Go forward if possible.
783     if (currentPrivacyWebEngineViewPointer->isActiveWindow() && currentWebEngineHistoryPointer->canGoForward())
784     {
785         // Clear the URL line edit focus.
786         emit clearUrlLineEditFocus();
787
788         // Go forward.
789         currentPrivacyWebEngineViewPointer->forward();
790     }
791 }
792
793 void TabWidget::pageLinkHovered(const QString &linkUrl) const
794 {
795     // Emit a signal so that the browser window can update the status bar.
796     emit linkHovered(linkUrl);
797 }
798
799 void TabWidget::print() const
800 {
801     // Create a printer.
802     QPrinter printer;
803
804     // Set the resolution to be 300 dpi.
805     printer.setResolution(300);
806
807     // Create a printer dialog.
808     QPrintDialog printDialog(&printer, currentPrivacyWebEngineViewPointer);
809
810     // Display the dialog and print the page if instructed.
811     if (printDialog.exec() == QDialog::Accepted)
812         printWebpage(&printer);
813 }
814
815 void TabWidget::printPreview() const
816 {
817     // Create a printer.
818     QPrinter printer;
819
820     // Set the resolution to be 300 dpi.
821     printer.setResolution(300);
822
823     // Create a print preview dialog.
824     QPrintPreviewDialog printPreviewDialog(&printer, currentPrivacyWebEngineViewPointer);
825
826     // Generate the print preview.
827     connect(&printPreviewDialog, SIGNAL(paintRequested(QPrinter *)), this, SLOT(printWebpage(QPrinter *)));
828
829     // Display the dialog.
830     printPreviewDialog.exec();
831 }
832
833 void TabWidget::printWebpage(QPrinter *printerPointer) const
834 {
835     // Create an event loop.  For some reason, the print preview doesn't produce any output unless it is run inside an event loop.
836     QEventLoop eventLoop;
837
838     // Print the webpage, converting the callback above into a `QWebEngineCallback<bool>`.
839     // Printing requires that the printer be a pointer, not a reference, or it will crash with much cursing.
840     currentWebEnginePagePointer->print(printerPointer, [&eventLoop](bool printSuccess)
841     {
842         // Instruct the compiler to ignore the unused parameter.
843         (void) printSuccess;
844
845         // Quit the loop.
846         eventLoop.quit();
847     });
848
849     // Execute the loop.
850     eventLoop.exec();
851 }
852
853 void TabWidget::refresh() const
854 {
855     // Reload the website.
856     currentPrivacyWebEngineViewPointer->reload();
857 }
858
859 void TabWidget::setTabBarVisible(const bool visible) const
860 {
861     // Set the tab bar visibility.
862     tabWidgetPointer->tabBar()->setVisible(visible);
863 }
864
865 void TabWidget::showSaveDialog(QWebEngineDownloadItem *webEngineDownloadItemPointer)
866 {
867     // Get the download attributes.
868     QUrl downloadUrl = webEngineDownloadItemPointer->url();
869     QString mimeTypeString = webEngineDownloadItemPointer->mimeType();
870     QString suggestedFileName = webEngineDownloadItemPointer->suggestedFileName();
871     int totalBytes = webEngineDownloadItemPointer->totalBytes();
872
873     // Check to see if local storage (cookies) is enabled.
874     if (currentPrivacyWebEngineViewPointer->localStorageEnabled)  // Local storage (cookies) is enabled.  Use WebEngine's downloader.
875     {
876         // Instantiate the save dialog.
877         SaveDialog *saveDialogPointer = new SaveDialog(downloadUrl, mimeTypeString, totalBytes);
878
879         // Display the save dialog.
880         int saveDialogResult = saveDialogPointer->exec();
881
882         // Process the save dialog results.
883         if (saveDialogResult == QDialog::Accepted)  // Save was selected.
884         {
885             // Get the download directory.
886             QString downloadDirectory = Settings::downloadLocation();
887
888             // Resolve the system download directory if specified.
889             if (downloadDirectory == QLatin1String("System Download Directory"))
890                 downloadDirectory = QStandardPaths::writableLocation(QStandardPaths::DownloadLocation);
891
892             // Display a save file dialog.
893             QString saveFilePath = QFileDialog::getSaveFileName(this, i18nc("Save file dialog caption", "Save File"), downloadDirectory + QLatin1Char('/') + suggestedFileName);
894
895             // Process the save file path.
896             if (!saveFilePath.isEmpty())  // The file save path is populated.
897             {
898                 // Create a save file path file info.
899                 QFileInfo saveFilePathFileInfo = QFileInfo(saveFilePath);
900
901                 // Get the canonical save path and file name.
902                 QString absoluteSavePath = saveFilePathFileInfo.absolutePath();
903                 QString saveFileName = saveFilePathFileInfo.fileName();
904
905                 // Set the download directory and file name.
906                 webEngineDownloadItemPointer->setDownloadDirectory(absoluteSavePath);
907                 webEngineDownloadItemPointer->setDownloadFileName(saveFileName);
908
909                 // Create a file download notification.
910                 KNotification *fileDownloadNotificationPointer = new KNotification(QLatin1String("FileDownload"));
911
912                 // Set the notification title.
913                 fileDownloadNotificationPointer->setTitle(i18nc("Download notification title", "Download"));
914
915                 // Set the notification text.
916                 fileDownloadNotificationPointer->setText(i18nc("Downloading notification text", "Downloading %1", saveFileName));
917
918                 // Set the notification icon.
919                 fileDownloadNotificationPointer->setIconName(QLatin1String("download"));
920
921                 // Set the action list cancel button.
922                 fileDownloadNotificationPointer->setActions(QStringList({i18nc("Download notification action","Cancel")}));
923
924                 // Set the notification to display indefinitely.
925                 fileDownloadNotificationPointer->setFlags(KNotification::Persistent);
926
927                 // Prevent the notification from being autodeleted if it is closed.  Otherwise, the updates to the notification below cause a crash.
928                 fileDownloadNotificationPointer->setAutoDelete(false);
929
930                 // Display the notification.
931                 fileDownloadNotificationPointer->sendEvent();
932
933                 // Handle clicks on the cancel button.
934                 connect(fileDownloadNotificationPointer, &KNotification::action1Activated, [webEngineDownloadItemPointer, saveFileName] ()
935                 {
936                     // Cancel the download.
937                     webEngineDownloadItemPointer->cancel();
938
939                     // Create a file download notification.
940                     KNotification *canceledDownloadNotificationPointer = new KNotification(QLatin1String("FileDownload"));
941
942                     // Set the notification title.
943                     canceledDownloadNotificationPointer->setTitle(i18nc("Download notification title", "Download"));
944
945                     // Set the new text.
946                     canceledDownloadNotificationPointer->setText(i18nc("Download canceled notification", "%1 download canceled", saveFileName));
947
948                     // Set the notification icon.
949                     canceledDownloadNotificationPointer->setIconName(QLatin1String("download"));
950
951                     // Display the notification.
952                     canceledDownloadNotificationPointer->sendEvent();
953                 });
954
955                 // Update the notification when the download progresses.
956                 connect(webEngineDownloadItemPointer, &QWebEngineDownloadItem::downloadProgress, [fileDownloadNotificationPointer, saveFileName] (qint64 bytesReceived, qint64 totalBytes)
957                 {
958                     // Calculate the download percentage.
959                     int downloadPercentage = 100 * bytesReceived / totalBytes;
960
961                     // Set the new text.  Total bytes will be 0 if the download size is unknown.
962                     if (totalBytes > 0)
963                         fileDownloadNotificationPointer->setText(i18nc("Download progress notification text", "%1\% of %2 downloaded (%3 of %4 bytes)", downloadPercentage, saveFileName,
964                                                                     bytesReceived, totalBytes));
965                     else
966                         fileDownloadNotificationPointer->setText(i18nc("Download progress notification text", "%1:  %2 bytes downloaded", saveFileName, bytesReceived));
967
968                     // Display the updated notification.
969                     fileDownloadNotificationPointer->update();
970                 });
971
972                 // Update the notification when the download finishes.  The save file name must be copied into the lambda or a crash occurs.
973                 connect(webEngineDownloadItemPointer, &QWebEngineDownloadItem::finished, [fileDownloadNotificationPointer, saveFileName, saveFilePath] ()
974                 {
975                     // Set the new text.
976                     fileDownloadNotificationPointer->setText(i18nc("Download finished notification text", "%1 download finished", saveFileName));
977
978                     // Set the URL so the file options will be displayed.
979                     fileDownloadNotificationPointer->setUrls(QList<QUrl> {QUrl(saveFilePath)});
980
981                     // Remove the actions from the notification.
982                     fileDownloadNotificationPointer->setActions(QStringList());
983
984                     // Set the notification to disappear after a timeout.
985                     fileDownloadNotificationPointer->setFlags(KNotification::CloseOnTimeout);
986
987                     // Display the updated notification.
988                     fileDownloadNotificationPointer->update();
989                 });
990
991                 // Start the download.
992                 webEngineDownloadItemPointer->accept();
993             }
994             else  // The file save path is not populated.
995             {
996                 // Cancel the download.
997                 webEngineDownloadItemPointer->cancel();
998             }
999         }
1000         else  // Cancel was selected.
1001         {
1002             // Cancel the download.
1003             webEngineDownloadItemPointer->cancel();
1004         }
1005     }
1006     else  // Local storage (cookies) is disabled.  Use KDE's native downloader.
1007           // This must use the show command to launch a separate dialog which cancels WebEngine's automatic background download of the file to a temporary location.
1008     {
1009         // Instantiate the save dialog.  `true` instructs it to use the native downloader
1010         SaveDialog *saveDialogPointer = new SaveDialog(downloadUrl, mimeTypeString, totalBytes, suggestedFileName, true);
1011
1012         // Connect the save button.
1013         connect(saveDialogPointer, SIGNAL(useNativeDownloader(QUrl &, QString &)), this, SLOT(useNativeDownloader(QUrl &, QString &)));
1014
1015         // Show the dialog.
1016         saveDialogPointer->show();
1017     }
1018 }
1019
1020 void TabWidget::toggleDomStorage() const
1021 {
1022     // Toggle DOM storage.
1023     currentWebEngineSettingsPointer->setAttribute(QWebEngineSettings::LocalStorageEnabled, !currentWebEngineSettingsPointer->testAttribute(QWebEngineSettings::LocalStorageEnabled));
1024
1025     // Update the DOM storage action.
1026     emit updateDomStorageAction(currentWebEngineSettingsPointer->testAttribute(QWebEngineSettings::LocalStorageEnabled));
1027
1028     // Reload the website.
1029     currentPrivacyWebEngineViewPointer->reload();
1030 }
1031
1032 void TabWidget::toggleFindCaseSensitive(const QString &text)
1033 {
1034     // Toggle find case sensitive.
1035     currentPrivacyWebEngineViewPointer->findCaseSensitive = !currentPrivacyWebEngineViewPointer->findCaseSensitive;
1036
1037     // Set the wiping current find text selection flag.
1038     wipingCurrentFindTextSelection = true;
1039
1040     // Wipe the previous search.  Otherwise currently highlighted words will remain highlighted.
1041     findText(QLatin1String(""));
1042
1043     // Update the find text.
1044     findText(text);
1045 }
1046
1047 void TabWidget::toggleJavaScript() const
1048 {
1049     // Toggle JavaScript.
1050     currentWebEngineSettingsPointer->setAttribute(QWebEngineSettings::JavascriptEnabled, !currentWebEngineSettingsPointer->testAttribute(QWebEngineSettings::JavascriptEnabled));
1051
1052     // Update the JavaScript action.
1053     emit updateJavaScriptAction(currentWebEngineSettingsPointer->testAttribute(QWebEngineSettings::JavascriptEnabled));
1054
1055     // Reload the website.
1056     currentPrivacyWebEngineViewPointer->reload();
1057 }
1058
1059 void TabWidget::toggleLocalStorage()
1060 {
1061     // Toggle local storeage.
1062     currentPrivacyWebEngineViewPointer->localStorageEnabled = !currentPrivacyWebEngineViewPointer->localStorageEnabled;
1063
1064     // Update the local storage action.
1065     emit updateLocalStorageAction(currentPrivacyWebEngineViewPointer->localStorageEnabled);
1066
1067     // Reload the website.
1068     currentPrivacyWebEngineViewPointer->reload();
1069 }
1070
1071 void TabWidget::updateUiWithTabSettings()
1072 {
1073     // Update the current WebEngine pointers.
1074     currentPrivacyWebEngineViewPointer = qobject_cast<PrivacyWebEngineView *>(tabWidgetPointer->currentWidget());
1075     currentWebEngineSettingsPointer = currentPrivacyWebEngineViewPointer->settings();
1076     currentWebEnginePagePointer = currentPrivacyWebEngineViewPointer->page();
1077     currentWebEngineProfilePointer = currentWebEnginePagePointer->profile();
1078     currentWebEngineHistoryPointer = currentWebEnginePagePointer->history();
1079     currentWebEngineCookieStorePointer = currentWebEngineProfilePointer->cookieStore();
1080
1081     // Clear the URL line edit focus.
1082     emit clearUrlLineEditFocus();
1083
1084     // Update the actions.
1085     emit updateBackAction(currentWebEngineHistoryPointer->canGoBack());
1086     emit updateCookiesAction(currentPrivacyWebEngineViewPointer->cookieListPointer->size());
1087     emit updateDomStorageAction(currentWebEngineSettingsPointer->testAttribute(QWebEngineSettings::LocalStorageEnabled));
1088     emit updateForwardAction(currentWebEngineHistoryPointer->canGoForward());
1089     emit updateJavaScriptAction(currentWebEngineSettingsPointer->testAttribute(QWebEngineSettings::JavascriptEnabled));
1090     emit updateLocalStorageAction(currentPrivacyWebEngineViewPointer->localStorageEnabled);
1091     emit updateUserAgentActions(currentWebEngineProfilePointer->httpUserAgent(), true);
1092     emit updateZoomFactorAction(currentPrivacyWebEngineViewPointer->zoomFactor());
1093
1094     // Update the URL.
1095     emit updateWindowTitle(currentPrivacyWebEngineViewPointer->title());
1096     emit updateDomainSettingsIndicator(currentPrivacyWebEngineViewPointer->domainSettingsName != QLatin1String(""));
1097     emit updateUrlLineEdit(currentPrivacyWebEngineViewPointer->url());
1098
1099     // Update the find text.
1100     emit updateFindText(currentPrivacyWebEngineViewPointer->findString, currentPrivacyWebEngineViewPointer->findCaseSensitive);
1101     emit updateFindTextResults(currentPrivacyWebEngineViewPointer->findTextResult);
1102
1103     // Update the progress bar.
1104     if (currentPrivacyWebEngineViewPointer->loadProgressInt >= 0)
1105         emit showProgressBar(currentPrivacyWebEngineViewPointer->loadProgressInt);
1106     else
1107         emit hideProgressBar();
1108 }
1109
1110 void TabWidget::useNativeDownloader(QUrl &downloadUrl, QString &suggestedFileName)
1111 {
1112     // Get the download directory.
1113     QString downloadDirectory = Settings::downloadLocation();
1114
1115     // Resolve the system download directory if specified.
1116     if (downloadDirectory == QLatin1String("System Download Directory"))
1117         downloadDirectory = QStandardPaths::writableLocation(QStandardPaths::DownloadLocation);
1118
1119     // Create a save file dialog.
1120     QFileDialog *saveFileDialogPointer = new QFileDialog(this, i18nc("Save file dialog caption", "Save File"), downloadDirectory);
1121
1122     // Tell the dialog to use a save button.
1123     saveFileDialogPointer->setAcceptMode(QFileDialog::AcceptSave);
1124
1125     // Populate the file name from the download item pointer.
1126     saveFileDialogPointer->selectFile(suggestedFileName);
1127
1128     // Prevent interaction with the parent window while the dialog is open.
1129     saveFileDialogPointer->setWindowModality(Qt::WindowModal);
1130
1131     // Process the saving of the file.  The save file dialog pointer must be captured directly instead of by reference or nasty crashes occur.
1132     auto saveFile = [saveFileDialogPointer, downloadUrl] ()
1133     {
1134         // Get the save location.  The dialog box should only allow the selecting of one file location.
1135         QUrl saveLocation = saveFileDialogPointer->selectedUrls().value(0);
1136
1137         // Create a file copy job.  `-1` creates the file with default permissions.
1138         KIO::FileCopyJob *fileCopyJobPointer = KIO::file_copy(downloadUrl, saveLocation, -1, KIO::Overwrite);
1139
1140         // Set the download job to display any error messages.
1141         fileCopyJobPointer->uiDelegate()->setAutoErrorHandlingEnabled(true);
1142
1143         // Start the download.
1144         fileCopyJobPointer->start();
1145     };
1146
1147     // Handle clicks on the save button.
1148     connect(saveFileDialogPointer, &QDialog::accepted, this, saveFile);
1149
1150     // Show the dialog.
1151     saveFileDialogPointer->show();
1152 }