]> gitweb.stoutner.com Git - PrivacyBrowserPC.git/commitdiff
Add option to auto update the download directory. https://redmine.stoutner.com/issue...
authorSoren Stoutner <soren@stoutner.com>
Thu, 28 Dec 2023 21:19:10 +0000 (14:19 -0700)
committerSoren Stoutner <soren@stoutner.com>
Thu, 28 Dec 2023 21:19:10 +0000 (14:19 -0700)
src/settings/Settings.kcfg
src/settings/Settings.kcfgc
src/uis/SettingsGeneral.ui
src/widgets/TabWidget.cpp
src/widgets/TabWidget.h
src/windows/BrowserWindow.cpp
src/windows/BrowserWindow.h

index 42160135f957f5e767387e0c4ca77c97943a0445..3607793f4cd49bc9a1164a82551ad2c089d495d2 100644 (file)
             <default>1.00</default>
         </entry>
 
-        <entry name="downloadLocation" type="String">
+        <entry name="downloadDirectory" type="String">
             <default>System Download Directory</default>
         </entry>
 
+        <entry name="autoUpateDownloadDirectory" type="Bool">
+            <default>true</default>
+        </entry>
+
         <entry name="tabsOnTop" type="Bool">
             <default>true</default>
         </entry>
index dce7cb8f7b95450a8245234ff9885cd4b8588876..3cb234cfc330ccc5a267e125d3d0a6a8f7d5f497 100644 (file)
@@ -29,4 +29,4 @@ ClassName=Settings
 Singleton=true
 
 # List of variables that can be manually changed.
-Mutators=spellCheckLanguages
+Mutators=spellCheckLanguages,downloadDirectory
index 4c08bda737f9dddb09a0def326de10552a05bb9b..15f776fa8b392b08b3f9fe37eb68e906560be53a 100644 (file)
                 </layout>
             </item>
 
-            <!-- Download location. -->
-            <item>
-                <layout class="QHBoxLayout">
-                    <item>
-                        <widget class="QLabel">
-                            <property name="text">
-                                <string>Download Location</string>
-                            </property>
-
-                            <property name="toolTip">
-                                <string>The default is System Download Directory.</string>
-                            </property>
-                        </widget>
-                    </item>
-
-                    <item>
-                        <widget class="QComboBox" name="kcfg_downloadLocation">
-                            <property name="sizePolicy">
-                                <sizepolicy hsizetype="Expanding" vsizetype="Fixed">
-                                    <horstretch>0</horstretch>
-                                    <verstretch>0</verstretch>
-                                </sizepolicy>
-                            </property>
-
-                            <property name="editable">
-                                <bool>true</bool>
-                            </property>
-
-                            <item>
-                                <property name="text">
-                                    <string>System Download Directory</string>
-                                </property>
-                            </item>
-                        </widget>
-                    </item>
-
-                    <item>
-                        <widget class="QPushButton" name="browseButton">
-                            <property name="text">
-                                <string>Browse</string>
-                            </property>
-                        </widget>
-                    </item>
-                </layout>
-            </item>
-
             <!-- Tabs on top. -->
             <item>
                 <widget class="QCheckBox" name="kcfg_tabsOnTop">
                     </property>
 
                     <property name="toolTip">
-                        <string>Spatial navigation allows the moving between links and input fields using the keyboard arrow keys.  The default is enabled.</string>
+                        <string>Allow moving between links and input fields using the keyboard arrow keys.  The default is enabled.</string>
+                    </property>
+                </widget>
+            </item>
+
+            <!-- Download location. -->
+            <item>
+                <widget class="QGroupBox">
+                    <property name="title">
+                        <string>Download Location</string>
                     </property>
+
+                    <layout class="QVBoxLayout">
+                        <!-- Download directory. -->
+                        <item>
+                            <layout class="QHBoxLayout">
+                                <item>
+                                    <widget class="QComboBox" name="kcfg_downloadDirectory">
+                                        <property name="sizePolicy">
+                                            <sizepolicy hsizetype="Expanding" vsizetype="Fixed">
+                                                <horstretch>0</horstretch>
+                                                <verstretch>0</verstretch>
+                                            </sizepolicy>
+                                        </property>
+
+                                        <property name="editable">
+                                            <bool>true</bool>
+                                        </property>
+
+                                        <item>
+                                            <property name="text">
+                                                <string>System Download Directory</string>
+                                            </property>
+                                        </item>
+                                    </widget>
+                                </item>
+
+                                <item>
+                                    <widget class="QPushButton" name="browseButton">
+                                        <property name="text">
+                                            <string>Browse</string>
+                                        </property>
+                                    </widget>
+                                </item>
+                            </layout>
+                        </item>
+
+                        <!-- Auto update download directory. -->
+                        <item>
+                            <widget class="QCheckBox" name="kcfg_autoUpateDownloadDirectory">
+                                <property name="text">
+                                    <string>Auto update the download directory</string>
+                                </property>
+
+                                <property name="toolTip">
+                                    <string>Automatically update the download directory to be whatever was used for the last download. The default is enabled.</string>
+                                </property>
+                            </widget>
+                        </item>
+                    </layout>
                 </widget>
             </item>
 
index efd677d73e636d37f9018839a019edaf54c1feb8..4f4a635651a16fca4ebd60a335408081cd056b13 100644 (file)
@@ -916,7 +916,7 @@ void TabWidget::saveArchive()
     QString suggestedFileName = currentPrivacyWebEngineViewPointer->title() + ".mht";
 
     // Get the download directory.
-    QString downloadDirectory = Settings::downloadLocation();
+    QString downloadDirectory = Settings::downloadDirectory();
 
     // Resolve the system download directory if specified.
     if (downloadDirectory == QLatin1String("System Download Directory"))
@@ -928,6 +928,10 @@ void TabWidget::saveArchive()
     // Save the webpage as an archive if the file save path is populated.
     if (!saveFilePath.isEmpty())
     {
+        // Update the download directory if specified.
+        if (Settings::autoUpateDownloadDirectory())
+            updateDownloadDirectory(saveFilePath);
+
         // Set the saving archive flag.  Otherwise, a second download tries to run.
         savingArchive = true;
 
@@ -966,7 +970,7 @@ void TabWidget::showSaveDialog(QWebEngineDownloadItem *webEngineDownloadItemPoin
             if (saveDialogResult == QDialog::Accepted)  // Save was selected.
             {
                 // Get the download directory.
-                QString downloadDirectory = Settings::downloadLocation();
+                QString downloadDirectory = Settings::downloadDirectory();
 
                 // Resolve the system download directory if specified.
                 if (downloadDirectory == QLatin1String("System Download Directory"))
@@ -978,6 +982,10 @@ void TabWidget::showSaveDialog(QWebEngineDownloadItem *webEngineDownloadItemPoin
                 // Process the save file path.
                 if (!saveFilePath.isEmpty())  // The file save path is populated.
                 {
+                    // Update the download directory if specified.
+                    if (Settings::autoUpateDownloadDirectory())
+                        updateDownloadDirectory(saveFilePath);
+
                     // Create a save file path file info.
                     QFileInfo saveFilePathFileInfo = QFileInfo(saveFilePath);
 
@@ -1199,6 +1207,21 @@ void TabWidget::toggleLocalStorage()
     currentPrivacyWebEngineViewPointer->reload();
 }
 
+void TabWidget::updateDownloadDirectory(QString newDownloadDirectory) const
+{
+    // Remove the file name from the save file path.
+    newDownloadDirectory.truncate(newDownloadDirectory.lastIndexOf(QLatin1Char('/')));
+
+    // Update the download location.
+    Settings::setDownloadDirectory(newDownloadDirectory);
+
+    // Get a handle for the KConfig skeleton.
+    KConfigSkeleton *kConfigSkeletonPointer = Settings::self();
+
+    // Write the settings to disk.
+    kConfigSkeletonPointer->save();
+}
+
 void TabWidget::updateUiFromWebEngineView(const PrivacyWebEngineView *privacyWebEngineViewPointer) const
 {
     // Only update the UI if the signal was emitted from the current privacy WebEngine.
@@ -1262,7 +1285,7 @@ void TabWidget::updateUiWithTabSettings()
 void TabWidget::useNativeKdeDownloader(QUrl &downloadUrl, QString &suggestedFileName)
 {
     // Get the download directory.
-    QString downloadDirectory = Settings::downloadLocation();
+    QString downloadDirectory = Settings::downloadDirectory();
 
     // Resolve the system download directory if specified.
     if (downloadDirectory == QLatin1String("System Download Directory"))
@@ -1281,11 +1304,15 @@ void TabWidget::useNativeKdeDownloader(QUrl &downloadUrl, QString &suggestedFile
     saveFileDialogPointer->setWindowModality(Qt::WindowModal);
 
     // Process the saving of the file.  The save file dialog pointer must be captured directly instead of by reference or nasty crashes occur.
-    auto saveFile = [saveFileDialogPointer, downloadUrl] ()
+    auto saveFile = [saveFileDialogPointer, downloadUrl, this] ()
     {
         // Get the save location.  The dialog box should only allow the selecting of one file location.
         QUrl saveLocation = saveFileDialogPointer->selectedUrls().value(0);
 
+        // Update the download directory if specified.
+        if (Settings::autoUpateDownloadDirectory())
+            updateDownloadDirectory(saveLocation.toLocalFile());
+
         // Create a file copy job.  `-1` creates the file with default permissions.
         KIO::FileCopyJob *fileCopyJobPointer = KIO::file_copy(downloadUrl, saveLocation, -1, KIO::Overwrite);
 
index e47370c3ec4480e811091e757966e5533d95cf6c..06676d642e14cbe91b871323bf3dc25f59c13635 100644 (file)
@@ -136,6 +136,9 @@ private Q_SLOTS:
     void useNativeKdeDownloader(QUrl &downloadUrl, QString &suggestedFileName);
 
 private:
+    // The private functions.
+    void updateDownloadDirectory(QString newDownloadDirectory) const;
+
     // The private variables.
     PrivacyWebEngineView *currentPrivacyWebEngineViewPointer;
     QWebEngineCookieStore *currentWebEngineCookieStorePointer;
index 394340bb9ba56c996e9b2f90c4bcc159cf1e287a..1513d1af30e7eb31ccd3435ff22a1524cd6a8867 100644 (file)
@@ -1446,28 +1446,29 @@ void BrowserWindow::showCookiesDialog()
     connect(cookiesDialogPointer, SIGNAL(deleteCookie(QNetworkCookie)), tabWidgetPointer, SLOT(deleteCookieFromStore(QNetworkCookie)));
 }
 
-void BrowserWindow::showDownloadLocationBrowseDialog() const
+void BrowserWindow::showDownloadDirectoryBrowseDialog() const
 {
-    // Get the current download location.
-    QString currentDownloadLocation = downloadLocationComboBoxPointer->currentText();
+    // Get the current download directory.
+    QString currentDownloadDirectory = downloadDirectoryComboBoxPointer->currentText();
 
     // Resolve the system download directory if specified.
-    if (currentDownloadLocation == QStringLiteral("System Download Directory"))
-        currentDownloadLocation = QStandardPaths::writableLocation(QStandardPaths::DownloadLocation);
+    if (currentDownloadDirectory == QStringLiteral("System Download Directory"))
+        currentDownloadDirectory = QStandardPaths::writableLocation(QStandardPaths::DownloadLocation);
 
-    // Get the new download location.
-    QString newDownloadLocation = QFileDialog::getExistingDirectory(configDialogPointer, i18nc("Select download location dialog caption", "Select Download Location"), currentDownloadLocation);
+    // Get the new download directory.
+    QString newDownloadDirectory = QFileDialog::getExistingDirectory(configDialogPointer, i18nc("Select download directory dialog caption", "Select Download Directory"),
+                                                                     currentDownloadDirectory);
 
-    // Populate the download location combo box according to the new download location.
-    if (newDownloadLocation == QStandardPaths::writableLocation(QStandardPaths::DownloadLocation))  // The default download location was selected.
+    // Populate the download directory combo box according to the new download location.
+    if (newDownloadDirectory == QStandardPaths::writableLocation(QStandardPaths::DownloadLocation))  // The default download location was selected.
     {
         // Populate the download location with the default text.
-        downloadLocationComboBoxPointer->setCurrentText("System Download Directory");
+        downloadDirectoryComboBoxPointer->setCurrentText("System Download Directory");
     }
-    else if (newDownloadLocation != QStringLiteral(""))  // A different directory was selected.
+    else if (newDownloadDirectory != QStringLiteral(""))  // A different directory was selected.
     {
         // Populate the download location.
-        downloadLocationComboBoxPointer->setCurrentText(newDownloadLocation);
+        downloadDirectoryComboBoxPointer->setCurrentText(newDownloadDirectory);
     }
 }
 
@@ -1542,7 +1543,7 @@ void BrowserWindow::showSettingsDialog()
     userAgentLabelPointer = privacySettingsUi.userAgentLabel;
     QComboBox *searchEngineComboBoxPointer = generalSettingsUi.kcfg_searchEngine;
     searchEngineLabelPointer = generalSettingsUi.searchEngineLabel;
-    downloadLocationComboBoxPointer = generalSettingsUi.kcfg_downloadLocation;
+    downloadDirectoryComboBoxPointer = generalSettingsUi.kcfg_downloadDirectory;
     QPushButton *browseButtonPointer = generalSettingsUi.browseButton;
     QListWidget *spellCheckListWidgetPointer = spellCheckSettingsUi.spellCheckListWidget;
 
@@ -1554,8 +1555,8 @@ void BrowserWindow::showSettingsDialog()
     connect(userAgentComboBoxPointer, SIGNAL(currentTextChanged(const QString)), this, SLOT(updateUserAgentLabel(const QString)));
     connect(searchEngineComboBoxPointer, SIGNAL(currentTextChanged(const QString)), this, SLOT(updateSearchEngineLabel(const QString)));
 
-    // Connect the download location directory browse button.
-    connect(browseButtonPointer, SIGNAL(clicked()), this, SLOT(showDownloadLocationBrowseDialog()));
+    // Connect the download directory directory browse button.
+    connect(browseButtonPointer, SIGNAL(clicked()), this, SLOT(showDownloadDirectoryBrowseDialog()));
 
     // Create a dictionaries QDir from the `QTWEBENGINE_DICTIONARIES_PATH` environment variable.
     QDir dictionariesDir = QDir(qEnvironmentVariable("QTWEBENGINE_DICTIONARIES_PATH"));
index 87297dc12347deebf7476ca6ca82bc46a3733ad8..143e35f1571ecbec87eba2f136f937358bea7577 100644 (file)
@@ -77,7 +77,7 @@ private Q_SLOTS:
     void reloadAndBypassCache() const;
     void showBookmarkContextMenu(const QPoint &point);
     void showCookiesDialog();
-    void showDownloadLocationBrowseDialog() const;
+    void showDownloadDirectoryBrowseDialog() const;
     void showDomainSettingsDialog() const;
     void showFindTextActions() const;
     void showProgressBar(const int &progress) const;
@@ -133,7 +133,7 @@ private:
     double defaultZoomFactor;
     QAction *developerToolsActionPointer;
     QAction *domStorageActionPointer;
-    QComboBox *downloadLocationComboBoxPointer;
+    QComboBox *downloadDirectoryComboBoxPointer;
     QList<QPair<QMenu *, QAction *> *> finalBookmarkFolderMenuActionList;
     QAction *findCaseSensitiveActionPointer;
     QAction *findNextActionPointer;