]> gitweb.stoutner.com Git - PrivacyBrowserPC.git/commitdiff
Add a download location setting.
authorSoren Stoutner <soren@stoutner.com>
Mon, 11 Jul 2022 21:13:18 +0000 (14:13 -0700)
committerSoren Stoutner <soren@stoutner.com>
Mon, 11 Jul 2022 21:13:18 +0000 (14:13 -0700)
src/dialogs/SaveDialog.cpp
src/settings/Settings.kcfg
src/uis/SettingsGeneral.ui
src/views/BrowserView.cpp
src/windows/BrowserWindow.cpp
src/windows/BrowserWindow.h

index 622bc363a1ef2945338651a4774136aa3f3fa30b..281cc77c79a4c4ff97e606e4ce50402159c38242 100644 (file)
@@ -25,7 +25,6 @@
 #include <KLocalizedString>
 
 // Qt toolkit headers.
-#include <QDebug>
 #include <QMimeDatabase>
 #include <QPushButton>
 #include <QShortcut>
index 1bcf275ccd8634fd4a5bd879e1d5a0ebfc7ac056..80726d2277373fb628e5f700c9632539b2cb4779 100644 (file)
             <default>1.00</default>
         </entry>
 
+        <entry name="downloadLocation" type="String">
+            <default>System Download Directory</default>
+        </entry>
+
         <entry name="fullScreenHideMenuBar" type="Bool">
             <default>true</default>
         </entry>
index 5e11e864ec0d98df013b543e4389bf8d7b3c61ab..acd345c4db96547b5776dea827d07c3289f84e85 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>
+
             <!-- Full screen browsing. -->
             <item>
                 <widget class="QGroupBox">
index 2a23d8126ca54b80aa8afdf7747c79be853cacf0..f17a237d6d33d962db9315eb3a9602504f79bddc 100644 (file)
@@ -663,8 +663,15 @@ void BrowserView::showSaveDialog(QWebEngineDownloadItem *downloadItemPointer) co
 
 void BrowserView::showSaveFilePickerDialog(QUrl &downloadUrl, QString &suggestedFileName)
 {
+    // Get the download location.
+    QString downloadDirectory = Settings::downloadLocation();
+
+    // Resolve the system download directory if specified.
+    if (downloadDirectory == QStringLiteral("System Download Directory"))
+        downloadDirectory = QStandardPaths::writableLocation(QStandardPaths::DownloadLocation);
+
     // Create a save file dialog.
-    QFileDialog *saveFileDialogPointer = new QFileDialog(this, i18nc("Save file dialog caption", "Save File"), QStandardPaths::writableLocation(QStandardPaths::DownloadLocation));
+    QFileDialog *saveFileDialogPointer = new QFileDialog(this, i18nc("Save file dialog caption", "Save File"), downloadDirectory);
 
     // Tell the dialog to use a save button.
     saveFileDialogPointer->setAcceptMode(QFileDialog::AcceptSave);
@@ -672,7 +679,7 @@ void BrowserView::showSaveFilePickerDialog(QUrl &downloadUrl, QString &suggested
     // Populate the file name from the download item pointer.
     saveFileDialogPointer->selectFile(suggestedFileName);
 
-    // Prevent interaction with the parent windows while the dialog is open.
+    // Prevent interaction with the parent window while the dialog is open.
     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.
index 2484061633266d0e7e3d5d49ddb57c38aaed5ad1..e44357f25c042bb264ac7384baa00b6ab4b3793c 100644 (file)
@@ -33,6 +33,7 @@
 #include <KToolBar>
 
 // Qt toolkit headers.
+#include <QFileDialog>
 #include <QInputDialog>
 #include <QNetworkCookie>
 #include <QMenuBar>
@@ -66,7 +67,7 @@ BrowserWindow::BrowserWindow() : KXmlGuiWindow()
     QAction *backActionPointer = KStandardAction::back(this, SLOT(back()), actionCollectionPointer);
     QAction *forwardActionPointer = KStandardAction::forward(this, SLOT(forward()), actionCollectionPointer);
     KStandardAction::home(this, SLOT(home()), actionCollectionPointer);
-    KStandardAction::preferences(this, SLOT(settingsConfigure()), actionCollectionPointer);
+    KStandardAction::preferences(this, SLOT(showSettingsDialog()), actionCollectionPointer);
 
     // Add the custom actions.
     userAgentPrivacyBrowserActionPointer = actionCollectionPointer->addAction(QStringLiteral("user_agent_privacy_browser"));
@@ -484,6 +485,31 @@ void BrowserWindow::showCookiesDialog()
     connect(cookiesDialogPointer, SIGNAL(deleteCookie(QNetworkCookie)), browserViewPointer, SLOT(deleteCookieFromStore(QNetworkCookie)));
 }
 
+void BrowserWindow::showDownloadLocationBrowseDialog() const
+{
+    // Get the current download location.
+    QString currentDownloadLocation = downloadLocationComboBoxPointer->currentText();
+
+    // Resolve the system download directory if specified.
+    if (currentDownloadLocation == QStringLiteral("System Download Directory"))
+        currentDownloadLocation = QStandardPaths::writableLocation(QStandardPaths::DownloadLocation);
+
+    // Get the new download location.
+    QString newDownloadLocation = QFileDialog::getExistingDirectory(configDialogPointer, i18nc("Select download location dialog caption", "Select Download Location"), currentDownloadLocation);
+
+    // 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 location with the default text.
+        downloadLocationComboBoxPointer->setCurrentText("System Download Directory");
+    }
+    else if (newDownloadLocation != QStringLiteral(""))  // A different directory was selected.
+    {
+        // Populate the download location.
+        downloadLocationComboBoxPointer->setCurrentText(newDownloadLocation);
+    }
+}
+
 void BrowserWindow::showDomainSettingsDialog() const
 {
     // Remove the focus from the URL line edit.
@@ -508,85 +534,70 @@ void BrowserWindow::showProgressBar(const int &progress) const
     progressBarPointer->show();
 }
 
-QSize BrowserWindow::sizeHint() const
-{
-    // Return the default window size.
-    return QSize(1500, 1200);
-}
-
-void BrowserWindow::settingsConfigure()
+void BrowserWindow::showSettingsDialog()
 {
-    // Check to make sure the dialog box isn't already displayed.
-    if (KConfigDialog::exists(QStringLiteral("settings")))
-    {
-        // Show the existing config dialog if it is hidden.
-        configDialogPointer->show();
+    // Create the settings widgets.
+    QWidget *privacySettingsWidgetPointer = new QWidget;
+    QWidget *generalSettingsWidgetPointer = new QWidget;
 
-        // Raise the existing config dialog if it is below other windows.
-        configDialogPointer->raise();
+    // Instantiate the settings UI.
+    Ui::PrivacySettings privacySettingsUi;
+    Ui::GeneralSettings generalSettingsUi;
 
-        // Restore the existing config dialog if it has been minimized.
-        if (configDialogPointer->isMinimized()) {
-            configDialogPointer->showNormal();
-        }
-
-        // Activate the existing config dialog, which brings its virtual desktop into focus.
-        configDialogPointer->activateWindow();
-    }
-    else
-    {
-        // Create the settings widgets.
-        QWidget *privacySettingsWidgetPointer = new QWidget;
-        QWidget *generalSettingsWidgetPointer = new QWidget;
+    // Setup the UI to display the settings widgets.
+    privacySettingsUi.setupUi(privacySettingsWidgetPointer);
+    generalSettingsUi.setupUi(generalSettingsWidgetPointer);
 
-        // Instantiate the settings UI.
-        Ui::PrivacySettings privacySettingsUi;
-        Ui::GeneralSettings generalSettingsUi;
+    // Get handles for the widgets.
+    QComboBox *userAgentComboBoxPointer = privacySettingsUi.kcfg_userAgent;
+    userAgentLabelPointer = privacySettingsUi.userAgentLabel;
+    QComboBox *searchEngineComboBoxPointer = generalSettingsUi.kcfg_searchEngine;
+    searchEngineLabelPointer = generalSettingsUi.searchEngineLabel;
+    downloadLocationComboBoxPointer = generalSettingsUi.kcfg_downloadLocation;
+    QPushButton *browseButtonPointer = generalSettingsUi.browseButton;
 
-        // Setup the UI to display the settings widgets.
-        privacySettingsUi.setupUi(privacySettingsWidgetPointer);
-        generalSettingsUi.setupUi(generalSettingsWidgetPointer);
+    // Populate the combo box labels.
+    updateUserAgentLabel(userAgentComboBoxPointer->currentText());
+    updateSearchEngineLabel(searchEngineComboBoxPointer->currentText());
 
-        // Get handles for the widgets.
-        QComboBox *userAgentComboBoxPointer = privacySettingsUi.kcfg_userAgent;
-        userAgentLabelPointer = privacySettingsUi.userAgentLabel;
-        QComboBox *searchEngineComboBoxPointer = generalSettingsUi.kcfg_searchEngine;
-        searchEngineLabelPointer = generalSettingsUi.searchEngineLabel;
+    // Update the labels when the combo boxes change.
+    connect(userAgentComboBoxPointer, SIGNAL(currentTextChanged(const QString)), this, SLOT(updateUserAgentLabel(const QString)));
+    connect(searchEngineComboBoxPointer, SIGNAL(currentTextChanged(const QString)), this, SLOT(updateSearchEngineLabel(const QString)));
 
-        // Populate the combo box labels.
-        updateUserAgentLabel(userAgentComboBoxPointer->currentText());
-        updateSearchEngineLabel(searchEngineComboBoxPointer->currentText());
+    // Connect the download location directory browse button.
+    connect(browseButtonPointer, SIGNAL(clicked()), this, SLOT(showDownloadLocationBrowseDialog()));
 
-        // Update the labels when the combo boxes change.
-        connect(userAgentComboBoxPointer, SIGNAL(currentTextChanged(const QString)), this, SLOT(updateUserAgentLabel(const QString)));
-        connect(searchEngineComboBoxPointer, SIGNAL(currentTextChanged(const QString)), this, SLOT(updateSearchEngineLabel(const QString)));
+    // Instantiate a settings config dialog from the settings.kcfg file.
+    configDialogPointer = new KConfigDialog(this, QStringLiteral("settings"), Settings::self());
 
-        // Instantiate a settings config dialog from the settings.kcfg file.
-        configDialogPointer = new KConfigDialog(this, QStringLiteral("settings"), Settings::self());
+    // Add the settings widgets as config dialog pages.
+    configDialogPointer->addPage(privacySettingsWidgetPointer, i18nc("@title:tab", "Privacy"), QStringLiteral("privacy-browser"));
+    configDialogPointer->addPage(generalSettingsWidgetPointer, i18nc("@title:tab", "General"), QStringLiteral("breeze-settings"));
 
-        // Add the settings widgets as config dialog pages.
-        configDialogPointer->addPage(privacySettingsWidgetPointer, i18nc("@title:tab", "Privacy"), QStringLiteral("privacy-browser"));
-        configDialogPointer->addPage(generalSettingsWidgetPointer, i18nc("@title:tab", "General"), QStringLiteral("breeze-settings"));
+    // Prevent interaction with the parent window while the dialog is open.
+    configDialogPointer->setWindowModality(Qt::WindowModal);
 
-        // Delete the config dialog when it is closed.
-        configDialogPointer->setAttribute(Qt::WA_DeleteOnClose);
+    // Make it so.
+    configDialogPointer->show();
 
-        // Make it so.
-        configDialogPointer->show();
+    // TODO.  KConfigDialog does not respect expanding size policies.  <https://redmine.stoutner.com/issues/823>
+    //configDialogPointer->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
+    //privacySettingsWidgetPointer->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
+    //generalSettingsWidgetPointer->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
+    //configDialogPointer->adjustSize();
 
-        // TODO.  KConfigDialog does not respect expanding size policies.  <https://redmine.stoutner.com/issues/823>
-        //configDialogPointer->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
-        //privacySettingsWidgetPointer->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
-        //generalSettingsWidgetPointer->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
-        //configDialogPointer->adjustSize();
+    // Expand the config dialog.
+    configDialogPointer->resize(1000, 500);
 
-        // Expand the config dialog.
-        configDialogPointer->resize(1000, 500);
+    // Apply the settings when they are updated.
+    connect(configDialogPointer, SIGNAL(settingsChanged(QString)), browserViewPointer, SLOT(applyApplicationSettings()));
+    connect(configDialogPointer, SIGNAL(settingsChanged(QString)), browserViewPointer, SLOT(applyDomainSettingsAndReload()));
+}
 
-        // Apply the settings when they are updated.
-        connect(configDialogPointer, SIGNAL(settingsChanged(QString)), browserViewPointer, SLOT(applyApplicationSettings()));
-        connect(configDialogPointer, SIGNAL(settingsChanged(QString)), browserViewPointer, SLOT(applyDomainSettingsAndReload()));
-    }
+QSize BrowserWindow::sizeHint() const
+{
+    // Return the default window size.
+    return QSize(1500, 1200);
 }
 
 void BrowserWindow::toggleDomStorage() const
index c05f9422c85da35d6d6cf9512e45cf3d9f372168..a405b6c957ea947b2d7f3c111fe5bfafbf1dac18 100644 (file)
@@ -29,6 +29,7 @@
 #include <KXmlGuiWindow>
 
 // Qt toolkit headers.
+#include <QComboBox>
 #include <QLabel>
 #include <QProgressBar>
 
@@ -62,10 +63,11 @@ private Q_SLOTS:
     void loadUrlFromLineEdit(const QString &url) const;
     void refresh() const;
     void removeCookieFromList(const QNetworkCookie &cookie) const;
-    void settingsConfigure();
     void showCookiesDialog();
+    void showDownloadLocationBrowseDialog() const;
     void showDomainSettingsDialog() const;
     void showProgressBar(const int &progress) const;
+    void showSettingsDialog();
     void toggleDomStorage() const;
     void toggleJavaScript() const;
     void toggleLocalStorage() const;
@@ -94,6 +96,7 @@ private:
     bool customUserAgentEnabled;
     QAction *domStorageActionPointer;
     QPalette domainSettingsPalette;
+    QComboBox *downloadLocationComboBoxPointer;
     KToggleFullScreenAction *fullScreenActionPointer;
     QAction *javaScriptActionPointer;
     bool javaScriptEnabled;