X-Git-Url: https://gitweb.stoutner.com/?a=blobdiff_plain;f=src%2Fwidgets%2FTabWidget.cpp;h=cbb84b3dfe3c9d9f081da5870c48d662b1dbe039;hb=efed1601e5f6e79d746866d55d625d777b64a248;hp=2e32cab37320efa2364d1921a54bcf6b3c4fb965;hpb=8756d450d1d44dd8e840f7e3de7b1d72ca5b7d8e;p=PrivacyBrowserPC.git diff --git a/src/widgets/TabWidget.cpp b/src/widgets/TabWidget.cpp index 2e32cab..cbb84b3 100644 --- a/src/widgets/TabWidget.cpp +++ b/src/widgets/TabWidget.cpp @@ -38,6 +38,7 @@ #include #include #include +#include #include #include #include @@ -48,6 +49,22 @@ QString TabWidget::webEngineDefaultUserAgent = QLatin1String(""); // Construct the class. TabWidget::TabWidget(QWidget *parent) : QWidget(parent) { + // 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(); @@ -71,6 +88,12 @@ TabWidget::TabWidget(QWidget *parent) : QWidget(parent) // Display the add tab widget. qTabWidgetPointer->setCornerWidget(addTabWidgetPointer); + // Create the loading favorite icon movie. + loadingFavoriteIconMoviePointer = new QMovie(); + + // Set the loading favorite icon movie file name. + loadingFavoriteIconMoviePointer->setFileName(QStringLiteral(":/icons/loading.gif")); + // Add the first tab. addFirstTab(); @@ -151,7 +174,7 @@ PrivacyWebEngineView* TabWidget::addTab(const bool removeUrlLineEditFocus, const int newTabIndex = qTabWidgetPointer->addTab(privacyWebEngineViewPointer, i18nc("New tab label.", "New Tab")); // Set the default tab icon. - qTabWidgetPointer->setTabIcon(newTabIndex, defaultTabIcon); + qTabWidgetPointer->setTabIcon(newTabIndex, defaultFavoriteIcon); // Get handles for the WebEngine page and profile. QWebEnginePage *webEnginePagePointer = privacyWebEngineViewPointer->page(); @@ -162,7 +185,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) @@ -176,19 +199,69 @@ PrivacyWebEngineView* TabWidget::addTab(const bool removeUrlLineEditFocus, const } }); - // Update the progress bar when a load is started. - connect(privacyWebEngineViewPointer, &PrivacyWebEngineView::loadStarted, [privacyWebEngineViewPointer, this] () + // Update the title when it changes. + connect(privacyWebEngineViewPointer, &PrivacyWebEngineView::titleChanged, [this, privacyWebEngineViewPointer] (const QString &title) + { + // Get the index for this tab. + int tabIndex = qTabWidgetPointer->indexOf(privacyWebEngineViewPointer); + + // Update the title for this tab. + qTabWidgetPointer->setTabText(tabIndex, title); + + // Update the window title if this is the current tab. + if (tabIndex == qTabWidgetPointer->currentIndex()) + emit updateWindowTitle(title); + }); + + // Connect the loading favorite icon movie to the tab icon. + connect(loadingFavoriteIconMoviePointer, &QMovie::frameChanged, [this, privacyWebEngineViewPointer] { + // Get the index for this tab. + int tabIndex = qTabWidgetPointer->indexOf(privacyWebEngineViewPointer); + + // Display the loading favorite icon if this tab is loading. + if (privacyWebEngineViewPointer->isLoading) + qTabWidgetPointer->setTabIcon(tabIndex, loadingFavoriteIconMoviePointer->currentPixmap()); + }); + + // Update the icon when it changes. + connect(privacyWebEngineViewPointer, &PrivacyWebEngineView::iconChanged, [this, privacyWebEngineViewPointer] (const QIcon &newFavoriteIcon) + { + // Store the favorite icon in the privacy web engine view. + if (newFavoriteIcon.isNull()) + privacyWebEngineViewPointer->favoriteIcon = defaultFavoriteIcon; + else + privacyWebEngineViewPointer->favoriteIcon = newFavoriteIcon; + + // Get the index for this tab. + int tabIndex = qTabWidgetPointer->indexOf(privacyWebEngineViewPointer); + + // Update the icon for this tab. + if (newFavoriteIcon.isNull()) + qTabWidgetPointer->setTabIcon(tabIndex, defaultFavoriteIcon); + else + qTabWidgetPointer->setTabIcon(tabIndex, newFavoriteIcon); + }); + + // Update the progress bar and the favorite icon when a load is started. + connect(privacyWebEngineViewPointer, &PrivacyWebEngineView::loadStarted, [this, privacyWebEngineViewPointer] () + { + // Set the privacy web engine view to be loading. + privacyWebEngineViewPointer->isLoading = true; + // Store the load progress. privacyWebEngineViewPointer->loadProgressInt = 0; // Show the progress bar if this is the current tab. if (privacyWebEngineViewPointer == currentPrivacyWebEngineViewPointer) emit showProgressBar(0); + + // Start the loading favorite icon movie. + loadingFavoriteIconMoviePointer->start(); }); // 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; @@ -199,14 +272,67 @@ 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; + // Store the load progress. privacyWebEngineViewPointer->loadProgressInt = -1; // Hide the progress bar if this is the current tab. if (privacyWebEngineViewPointer == currentPrivacyWebEngineViewPointer) emit hideProgressBar(); + + // Get the index for this tab. + int tabIndex = qTabWidgetPointer->indexOf(privacyWebEngineViewPointer); + + // Display the current favorite icon + qTabWidgetPointer->setTabIcon(tabIndex, privacyWebEngineViewPointer->favoriteIcon); + + // Create a no tabs loading variable. + bool noTabsLoading = true; + + // Check to see if any other tabs are loading. + for (int i = 0; i < qTabWidgetPointer->count(); i++) + { + // Get the privacy WebEngine view for the tab. + PrivacyWebEngineView *webEngineViewPointer = qobject_cast(qTabWidgetPointer->widget(i)); + + // Check to see if it is currently loading. + if (webEngineViewPointer->isLoading) + noTabsLoading = false; + } + + // Stop the loading favorite icon movie if there are no loading tabs. + if (noTabsLoading) + loadingFavoriteIconMoviePointer->stop(); + }); + + // Display HTTP Ping blocked dialogs. + 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) + { + // Instantiate an HTTP ping blocked message box. + QMessageBox httpPingBlockedMessageBox; + + // Set the icon. + httpPingBlockedMessageBox.setIcon(QMessageBox::Information); + + // Set the window title. + httpPingBlockedMessageBox.setWindowTitle(i18nc("HTTP Ping blocked dialog title", "HTTP Ping Blocked")); + + // Set the text. + httpPingBlockedMessageBox.setText(i18nc("HTTP Ping blocked dialog text", "This request has been blocked because it sends a naughty HTTP ping to %1.", httpPingUrl)); + + // Set the standard button. + httpPingBlockedMessageBox.setStandardButtons(QMessageBox::Ok); + + // Display the message box. + httpPingBlockedMessageBox.exec(); + } }); // Update the zoom factor when changed by CTRL-Scrolling. This can be modified when is fixed. @@ -281,7 +407,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) @@ -299,33 +425,6 @@ PrivacyWebEngineView* TabWidget::addTab(const bool removeUrlLineEditFocus, const for (QNetworkCookie *cookiePointer : *durableCookiesListPointer) addCookieToStore(*cookiePointer, webEngineCookieStorePointer); - // Update the title when it changes. - connect(privacyWebEngineViewPointer, &PrivacyWebEngineView::titleChanged, [this, privacyWebEngineViewPointer] (const QString &title) - { - // Get the index for this tab. - int tabIndex = qTabWidgetPointer->indexOf(privacyWebEngineViewPointer); - - // Update the title for this tab. - qTabWidgetPointer->setTabText(tabIndex, title); - - // Update the window title if this is the current tab. - if (tabIndex == qTabWidgetPointer->currentIndex()) - emit updateWindowTitle(title); - }); - - // Update the icon when it changes. - connect(privacyWebEngineViewPointer, &PrivacyWebEngineView::iconChanged, [privacyWebEngineViewPointer, this] (const QIcon &icon) - { - // Get the index for this tab. - int tabIndex = qTabWidgetPointer->indexOf(privacyWebEngineViewPointer); - - // Update the icon for this tab. - if (icon.isNull()) - qTabWidgetPointer->setTabIcon(tabIndex, defaultTabIcon); - else - qTabWidgetPointer->setTabIcon(tabIndex, icon); - }); - // Enable spell checking. webEngineProfilePointer->setSpellCheckEnabled(true); @@ -504,7 +603,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. @@ -716,8 +815,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); @@ -735,7 +834,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. @@ -855,14 +954,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(); @@ -974,7 +1073,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();