]> gitweb.stoutner.com Git - PrivacyBrowserPC.git/commitdiff
Fix duplicate download notifications. https://redmine.stoutner.com/issues/1289 master
authorSoren Stoutner <soren@stoutner.com>
Thu, 30 Apr 2026 21:16:01 +0000 (14:16 -0700)
committerSoren Stoutner <soren@stoutner.com>
Thu, 30 Apr 2026 21:16:01 +0000 (14:16 -0700)
doc/index.docbook
src/widgets/TabWidget.cpp

index 2796f5b6995d68cbf89d922684f6dcd35b25f877..bcac573bbcb745d3aa63d952b9e7df990862ac13 100644 (file)
         <!-- Version 0.9. -->
         <sect1 id="version_0.9">
             <title><ulink url="https://www.stoutner.com/privacy-browser-pc-0.9/">0.9</ulink> -
-                25 April 2026</title>
+                <ulink url="https://gitweb.stoutner.com/?p=PrivacyBrowserPC.git;a=commitdiff;h=839656b0fafa1eddedf32e21bc97e7cc8ecea191;ds=sidebyside">25 April 2026</ulink></title>
 
             <itemizedlist>
                 <listitem><para>Enable <ulink url="https://redmine.stoutner.com/issues/1258">JavaScript copying to the clipboard</ulink> with user interaction.</para></listitem>
index ce8978b6ca46f11016090175d137f1b22af01667..f3a08fee323d70000d830c1dc8378ff425c1e6d9 100644 (file)
@@ -1,5 +1,5 @@
 /* SPDX-License-Identifier: GPL-3.0-or-later
- * SPDX-FileCopyrightText: 2022-2025 Soren Stoutner <soren@stoutner.com>
+ * SPDX-FileCopyrightText: 2022-2026 Soren Stoutner <soren@stoutner.com>
  *
  * This file is part of Privacy Browser PC <https://www.stoutner.com/privacy-browser-pc/>.
  *
@@ -1012,15 +1012,15 @@ void TabWidget::showSaveDialog(QWebEngineDownloadRequest *webEngineDownloadReque
                     webEngineDownloadRequestPointer->setDownloadDirectory(absoluteSavePath);
                     webEngineDownloadRequestPointer->setDownloadFileName(saveFileName);
 
+                    // Start the download.
+                    webEngineDownloadRequestPointer->accept();
+
                     // Create a file download notification.
                     KNotification *fileDownloadNotificationPointer = new KNotification(QLatin1String("FileDownload"));
 
                     // Set the notification title.
                     fileDownloadNotificationPointer->setTitle(i18nc("Download notification title", "Download"));
 
-                    // Set the notification text.
-                    fileDownloadNotificationPointer->setText(i18nc("Downloading notification text", "Downloading %1", saveFileName));
-
                     // Get the download icon from the theme.
                     QIcon downloadIcon = QIcon::fromTheme(QLatin1String("download"), QIcon::fromTheme(QLatin1String("document-save")));
 
@@ -1028,13 +1028,13 @@ void TabWidget::showSaveDialog(QWebEngineDownloadRequest *webEngineDownloadReque
                     fileDownloadNotificationPointer->setIconName(downloadIcon.name());
 
                     // Add the cancel action.
-                    KNotificationAction *cancelActionPointer = fileDownloadNotificationPointer->addDefaultAction(i18nc("Download notification action","Cancel"));
+                    KNotificationAction *cancelActionPointer = fileDownloadNotificationPointer->addAction(i18nc("Download notification action","Cancel"));
 
                     // Prevent the notification from being autodeleted if it is closed.  Otherwise, the updates to the notification below cause a crash.
                     fileDownloadNotificationPointer->setAutoDelete(false);
 
                     // Handle clicks on the cancel action.
-                    connect(cancelActionPointer, &KNotificationAction::activated, [webEngineDownloadRequestPointer, saveFileName] ()
+                    connect(cancelActionPointer, &KNotificationAction::activated, [webEngineDownloadRequestPointer, saveFileName, downloadIcon] ()
                     {
                         // Cancel the download.
                         webEngineDownloadRequestPointer->cancel();
@@ -1042,14 +1042,11 @@ void TabWidget::showSaveDialog(QWebEngineDownloadRequest *webEngineDownloadReque
                         // Create a file download notification.
                         KNotification *canceledDownloadNotificationPointer = new KNotification(QLatin1String("FileDownload"));
 
-                        // Set the notification title.
-                        canceledDownloadNotificationPointer->setTitle(i18nc("Download notification title", "Download"));
-
                         // Set the new text.
                         canceledDownloadNotificationPointer->setText(i18nc("Download canceled notification", "%1 download canceled", saveFileName));
 
                         // Set the notification icon.
-                        canceledDownloadNotificationPointer->setIconName(QLatin1String("download"));
+                        canceledDownloadNotificationPointer->setIconName(downloadIcon.name());
 
                         // Display the notification.
                         canceledDownloadNotificationPointer->sendEvent();
@@ -1062,24 +1059,28 @@ void TabWidget::showSaveDialog(QWebEngineDownloadRequest *webEngineDownloadReque
                         qint64 receivedBytes = webEngineDownloadRequestPointer->receivedBytes();
                         qint64 totalBytes = webEngineDownloadRequestPointer->totalBytes();
 
-                        // Set the new text.  Total bytes will be 0 if the download size is unknown.
-                        if (totalBytes > 0)
+                        // Only display the notification if it isn't at 100%.  Otherwise, this notification and the download complete notification could display separately.
+                        if (receivedBytes != totalBytes)
                         {
-                            // Calculate the download percentage.
-                            int downloadPercentage = 100 * receivedBytes / totalBytes;
+                            // Set the new text.  Total bytes will be 0 if the download size is unknown.
+                            if (totalBytes > 0)
+                            {
+                                // Calculate the download percentage.
+                                int downloadPercentage = 100 * receivedBytes / totalBytes;
+
+                                // Set the file download notification text.
+                                fileDownloadNotificationPointer->setText(i18nc("Download progress notification text", "%1% of %2 downloaded (%3 of %4 bytes)", downloadPercentage, saveFileName,
+                                                                            receivedBytes, totalBytes));
+                            }
+                            else
+                            {
+                                // Set the file download notification text.
+                                fileDownloadNotificationPointer->setText(i18nc("Download progress notification text", "%1:  %2 bytes downloaded", saveFileName, receivedBytes));
+                            }
 
-                            // Set the file download notification text.
-                            fileDownloadNotificationPointer->setText(i18nc("Download progress notification text", "%1%% of %2 downloaded (%3 of %4 bytes)", downloadPercentage, saveFileName,
-                                                                           receivedBytes, totalBytes));
-                        }
-                        else
-                        {
-                            // Set the file download notification text.
-                            fileDownloadNotificationPointer->setText(i18nc("Download progress notification text", "%1:  %2 bytes downloaded", saveFileName, receivedBytes));
+                            // Display the updated notification.
+                            fileDownloadNotificationPointer->sendEvent();
                         }
-
-                        // Display the updated notification.
-                        fileDownloadNotificationPointer->sendEvent();
                     });
 
                     // Update the notification when the download finishes.  The save file name must be copied into the lambda or a crash occurs.
@@ -1105,12 +1106,6 @@ void TabWidget::showSaveDialog(QWebEngineDownloadRequest *webEngineDownloadReque
                             fileDownloadNotificationPointer->sendEvent();
                         }
                     });
-
-                    // Display the notification.
-                    fileDownloadNotificationPointer->sendEvent();
-
-                    // Start the download.
-                    webEngineDownloadRequestPointer->accept();
                 }
                 else  // The file save path is not populated.
                 {