X-Git-Url: https://gitweb.stoutner.com/?a=blobdiff_plain;f=src%2Fwidgets%2FTabWidget.cpp;h=05f10d23b970520b50a919e59cd3146c1b5cd3e2;hb=75a38db8a253d1458aaa5a2811afb58bc4eb7855;hp=76ff617c3e180f3e253884d277dfd2a536f94dce;hpb=dcb48bab299233e40e9518076c3e032ca072cb57;p=PrivacyBrowserPC.git diff --git a/src/widgets/TabWidget.cpp b/src/widgets/TabWidget.cpp index 76ff617..05f10d2 100644 --- a/src/widgets/TabWidget.cpp +++ b/src/widgets/TabWidget.cpp @@ -47,8 +47,24 @@ QString TabWidget::webEngineDefaultUserAgent = QLatin1String(""); // Construct the class. -TabWidget::TabWidget(QWidget *parent) : QWidget(parent) +TabWidget::TabWidget(QWidget *windowPointer) : QWidget(windowPointer) { + // Create a QProcess to check if KDE is running. + QProcess *checkIfRunningKdeQProcessPointer = new QProcess(); + + // Create an argument string list that contains `ksmserver` (KDE Session Manager). + QStringList argument = QStringList(QLatin1String("ksmserver")); + + // Run `pidof` to check for the presence of `ksmserver`. + checkIfRunningKdeQProcessPointer->start(QLatin1String("pidof"), argument); + + // Monitor any standard output. + connect(checkIfRunningKdeQProcessPointer, &QProcess::readyReadStandardOutput, [this] + { + // If there is any standard output, `ksmserver` is running. + isRunningKde = true; + }); + // Instantiate the user agent helper. userAgentHelperPointer = new UserAgentHelper(); @@ -78,6 +94,9 @@ TabWidget::TabWidget(QWidget *parent) : QWidget(parent) // Set the loading favorite icon movie file name. loadingFavoriteIconMoviePointer->setFileName(QStringLiteral(":/icons/loading.gif")); + // Stop the loading favorite icon movie if the window is destroyed. Otherwise, the app will crash if there is more than one window open and a window is closed while at tab is loading. + connect(windowPointer, SIGNAL(destroyed()), this, SLOT(stopLoadingFavoriteIconMovie())); + // Add the first tab. addFirstTab(); @@ -169,7 +188,7 @@ PrivacyWebEngineView* TabWidget::addTab(const bool removeUrlLineEditFocus, const QWebEngineSettings *webEngineSettingsPointer = webEnginePagePointer->settings(); // Update the URL line edit when the URL changes. - connect(privacyWebEngineViewPointer, &PrivacyWebEngineView::urlChanged, [privacyWebEngineViewPointer, this] (const QUrl &newUrl) + connect(privacyWebEngineViewPointer, &PrivacyWebEngineView::urlChanged, [this, privacyWebEngineViewPointer] (const QUrl &newUrl) { // Only update the UI if this is the current tab. if (privacyWebEngineViewPointer == currentPrivacyWebEngineViewPointer) @@ -198,7 +217,7 @@ PrivacyWebEngineView* TabWidget::addTab(const bool removeUrlLineEditFocus, const }); // Connect the loading favorite icon movie to the tab icon. - connect(loadingFavoriteIconMoviePointer, &QMovie::frameChanged, [privacyWebEngineViewPointer, this] + connect(loadingFavoriteIconMoviePointer, &QMovie::frameChanged, [this, privacyWebEngineViewPointer] { // Get the index for this tab. int tabIndex = qTabWidgetPointer->indexOf(privacyWebEngineViewPointer); @@ -209,7 +228,7 @@ PrivacyWebEngineView* TabWidget::addTab(const bool removeUrlLineEditFocus, const }); // Update the icon when it changes. - connect(privacyWebEngineViewPointer, &PrivacyWebEngineView::iconChanged, [privacyWebEngineViewPointer, this] (const QIcon &newFavoriteIcon) + connect(privacyWebEngineViewPointer, &PrivacyWebEngineView::iconChanged, [this, privacyWebEngineViewPointer] (const QIcon &newFavoriteIcon) { // Store the favorite icon in the privacy web engine view. if (newFavoriteIcon.isNull()) @@ -228,7 +247,7 @@ PrivacyWebEngineView* TabWidget::addTab(const bool removeUrlLineEditFocus, const }); // Update the progress bar and the favorite icon when a load is started. - connect(privacyWebEngineViewPointer, &PrivacyWebEngineView::loadStarted, [privacyWebEngineViewPointer, this] () + connect(privacyWebEngineViewPointer, &PrivacyWebEngineView::loadStarted, [this, privacyWebEngineViewPointer] () { // Set the privacy web engine view to be loading. privacyWebEngineViewPointer->isLoading = true; @@ -245,7 +264,7 @@ PrivacyWebEngineView* TabWidget::addTab(const bool removeUrlLineEditFocus, const }); // Update the progress bar when a load progresses. - connect(privacyWebEngineViewPointer, &PrivacyWebEngineView::loadProgress, [privacyWebEngineViewPointer, this] (const int progress) + connect(privacyWebEngineViewPointer, &PrivacyWebEngineView::loadProgress, [this, privacyWebEngineViewPointer] (const int progress) { // Store the load progress. privacyWebEngineViewPointer->loadProgressInt = progress; @@ -256,7 +275,7 @@ PrivacyWebEngineView* TabWidget::addTab(const bool removeUrlLineEditFocus, const }); // Update the progress bar when a load finishes. - connect(privacyWebEngineViewPointer, &PrivacyWebEngineView::loadFinished, [privacyWebEngineViewPointer, this] () + connect(privacyWebEngineViewPointer, &PrivacyWebEngineView::loadFinished, [this, privacyWebEngineViewPointer] () { // Set the privacy web engine view to be not loading. privacyWebEngineViewPointer->isLoading = false; @@ -294,7 +313,7 @@ PrivacyWebEngineView* TabWidget::addTab(const bool removeUrlLineEditFocus, const }); // Display HTTP Ping blocked dialogs. - connect(privacyWebEngineViewPointer, &PrivacyWebEngineView::displayHttpPingBlockedDialog, [privacyWebEngineViewPointer, this] (const QString &httpPingUrl) + connect(privacyWebEngineViewPointer, &PrivacyWebEngineView::displayHttpPingBlockedDialog, [this, privacyWebEngineViewPointer] (const QString &httpPingUrl) { // Only display the HTTP Ping blocked dialog if this is the current tab. if (privacyWebEngineViewPointer == currentPrivacyWebEngineViewPointer) @@ -391,7 +410,7 @@ PrivacyWebEngineView* TabWidget::addTab(const bool removeUrlLineEditFocus, const webEngineSettingsPointer->setAttribute(QWebEngineSettings::PluginsEnabled, true); // Update the cookies action. - connect(privacyWebEngineViewPointer, &PrivacyWebEngineView::updateCookiesAction, [privacyWebEngineViewPointer, this] (const int numberOfCookies) + connect(privacyWebEngineViewPointer, &PrivacyWebEngineView::updateCookiesAction, [this, privacyWebEngineViewPointer] (const int numberOfCookies) { // Update the cookie action if the specified privacy WebEngine view is the current privacy WebEngine view. if (privacyWebEngineViewPointer == currentPrivacyWebEngineViewPointer) @@ -587,7 +606,7 @@ void TabWidget::findText(const QString &text) const void TabWidget::findTextFinished(const QWebEngineFindTextResult &findTextResult) { - // Update the find text UI if it wasn't simply wiping the current find text selection. Otherwise the UI temporarially flashes `0/0`. + // Update the find text UI if it wasn't simply wiping the current find text selection. Otherwise the UI temporarily flashes `0/0`. if (wipingCurrentFindTextSelection) // The current selection is being wiped. { // Reset the flag. @@ -725,6 +744,12 @@ void TabWidget::pageLinkHovered(const QString &linkUrl) const emit linkHovered(linkUrl); } +void TabWidget::stopLoadingFavoriteIconMovie() const +{ + // Stop the loading favorite icon movie. Otherwise, the browser will crash if a second window is closed while a tab in it is loading. + loadingFavoriteIconMoviePointer->stop(); +} + void TabWidget::print() const { // Create a printer. @@ -799,8 +824,8 @@ void TabWidget::showSaveDialog(QWebEngineDownloadItem *webEngineDownloadItemPoin QString suggestedFileName = webEngineDownloadItemPointer->suggestedFileName(); int totalBytes = webEngineDownloadItemPointer->totalBytes(); - // Check to see if local storage (cookies) is enabled. - if (currentPrivacyWebEngineViewPointer->localStorageEnabled) // Local storage (cookies) is enabled. Use WebEngine's downloader. + // Check to see if Privacy Browser is not running KDE or if local storage (cookies) is enabled. + if (!isRunningKde || currentPrivacyWebEngineViewPointer->localStorageEnabled) // KDE is not running or local storage (cookies) is enabled. Use WebEngine's downloader. { // Instantiate the save dialog. SaveDialog *saveDialogPointer = new SaveDialog(downloadUrl, mimeTypeString, totalBytes); @@ -818,7 +843,7 @@ void TabWidget::showSaveDialog(QWebEngineDownloadItem *webEngineDownloadItemPoin if (downloadDirectory == QLatin1String("System Download Directory")) downloadDirectory = QStandardPaths::writableLocation(QStandardPaths::DownloadLocation); - // Display a save file dialog. + // Get a file path from the file picker. QString saveFilePath = QFileDialog::getSaveFileName(this, i18nc("Save file dialog caption", "Save File"), downloadDirectory + QLatin1Char('/') + suggestedFileName); // Process the save file path. @@ -938,14 +963,14 @@ void TabWidget::showSaveDialog(QWebEngineDownloadItem *webEngineDownloadItemPoin webEngineDownloadItemPointer->cancel(); } } - else // Local storage (cookies) is disabled. Use KDE's native downloader. + else // KDE is running and local storage (cookies) is disabled. Use KDE's native downloader. // 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. { // Instantiate the save dialog. `true` instructs it to use the native downloader SaveDialog *saveDialogPointer = new SaveDialog(downloadUrl, mimeTypeString, totalBytes, suggestedFileName, true); // Connect the save button. - connect(saveDialogPointer, SIGNAL(useNativeDownloader(QUrl &, QString &)), this, SLOT(useNativeDownloader(QUrl &, QString &))); + connect(saveDialogPointer, SIGNAL(useNativeKdeDownloader(QUrl &, QString &)), this, SLOT(useNativeKdeDownloader(QUrl &, QString &))); // Show the dialog. saveDialogPointer->show(); @@ -1057,7 +1082,7 @@ void TabWidget::updateUiWithTabSettings() emit hideProgressBar(); } -void TabWidget::useNativeDownloader(QUrl &downloadUrl, QString &suggestedFileName) +void TabWidget::useNativeKdeDownloader(QUrl &downloadUrl, QString &suggestedFileName) { // Get the download directory. QString downloadDirectory = Settings::downloadLocation(); @@ -1087,7 +1112,8 @@ void TabWidget::useNativeDownloader(QUrl &downloadUrl, QString &suggestedFileNam // Create a file copy job. `-1` creates the file with default permissions. KIO::FileCopyJob *fileCopyJobPointer = KIO::file_copy(downloadUrl, saveLocation, -1, KIO::Overwrite); - // Set the download job to display any error messages. + // Set the download job to display any warning and error messages. + fileCopyJobPointer->uiDelegate()->setAutoWarningHandlingEnabled(true); fileCopyJobPointer->uiDelegate()->setAutoErrorHandlingEnabled(true); // Start the download.