From dd7d97dbbbe40fad79a733afccb1a430f8524ca3 Mon Sep 17 00:00:00 2001 From: Micah Lee Date: Wed, 25 Apr 2018 08:43:40 -0700 Subject: [PATCH] Allow changing downloads_dir from SettingsDialog --- onionshare_gui/__init__.py | 2 +- onionshare_gui/onionshare_gui.py | 2 +- onionshare_gui/settings_dialog.py | 36 ++++++++++++++++++++- onionshare_gui/share_mode/__init__.py | 2 +- onionshare_gui/share_mode/file_selection.py | 23 ++----------- onionshare_gui/share_mode/server_status.py | 2 +- onionshare_gui/tor_connection_dialog.py | 2 +- onionshare_gui/{alert.py => widgets.py} | 25 ++++++++++++++ share/locale/en.json | 5 ++- 9 files changed, 71 insertions(+), 28 deletions(-) rename onionshare_gui/{alert.py => widgets.py} (58%) diff --git a/onionshare_gui/__init__.py b/onionshare_gui/__init__.py index 56354d52..38db94d4 100644 --- a/onionshare_gui/__init__.py +++ b/onionshare_gui/__init__.py @@ -19,7 +19,7 @@ along with this program. If not, see . """ from __future__ import division import os, sys, platform, argparse -from .alert import Alert +from .widgets import Alert from PyQt5 import QtCore, QtWidgets from onionshare import strings diff --git a/onionshare_gui/onionshare_gui.py b/onionshare_gui/onionshare_gui.py index bcde29a6..43204122 100644 --- a/onionshare_gui/onionshare_gui.py +++ b/onionshare_gui/onionshare_gui.py @@ -27,7 +27,7 @@ from .receive_mode import ReceiveMode from .tor_connection_dialog import TorConnectionDialog from .settings_dialog import SettingsDialog -from .alert import Alert +from .widgets import Alert from .update_checker import UpdateThread class OnionShareGui(QtWidgets.QMainWindow): diff --git a/onionshare_gui/settings_dialog.py b/onionshare_gui/settings_dialog.py index a7426317..bdb721c3 100644 --- a/onionshare_gui/settings_dialog.py +++ b/onionshare_gui/settings_dialog.py @@ -24,7 +24,7 @@ from onionshare import strings, common from onionshare.settings import Settings from onionshare.onion import * -from .alert import Alert +from .widgets import Alert from .update_checker import * from .tor_connection_dialog import TorConnectionDialog @@ -77,6 +77,23 @@ class SettingsDialog(QtWidgets.QDialog): sharing_group = QtWidgets.QGroupBox(strings._("gui_settings_sharing_label", True)) sharing_group.setLayout(sharing_group_layout) + # Downloads dir + downloads_label = QtWidgets.QLabel(strings._('gui_settings_downloads_label', True)); + self.downloads_dir_lineedit = QtWidgets.QLineEdit() + self.downloads_dir_lineedit.setReadOnly(True) + downloads_button = QtWidgets.QPushButton(strings._('gui_settings_downloads_button', True)) + downloads_button.clicked.connect(self.downloads_button_clicked) + downloads_layout = QtWidgets.QHBoxLayout() + downloads_layout.addWidget(downloads_label) + downloads_layout.addWidget(self.downloads_dir_lineedit) + downloads_layout.addWidget(downloads_button) + + # Receiving options layout + receiving_group_layout = QtWidgets.QVBoxLayout() + receiving_group_layout.addLayout(downloads_layout) + receiving_group = QtWidgets.QGroupBox(strings._("gui_settings_receiving_label", True)) + receiving_group.setLayout(receiving_group_layout) + # Stealth options # Stealth @@ -349,6 +366,7 @@ class SettingsDialog(QtWidgets.QDialog): # Layout left_col_layout = QtWidgets.QVBoxLayout() left_col_layout.addWidget(sharing_group) + left_col_layout.addWidget(receiving_group) left_col_layout.addWidget(stealth_group) left_col_layout.addWidget(autoupdate_group) left_col_layout.addStretch() @@ -392,6 +410,9 @@ class SettingsDialog(QtWidgets.QDialog): else: self.save_private_key_checkbox.setCheckState(QtCore.Qt.Unchecked) + downloads_dir = self.old_settings.get('downloads_dir') + self.downloads_dir_lineedit.setText(downloads_dir) + use_stealth = self.old_settings.get('use_stealth') if use_stealth: self.stealth_checkbox.setCheckState(QtCore.Qt.Checked) @@ -575,6 +596,18 @@ class SettingsDialog(QtWidgets.QDialog): clipboard = self.qtapp.clipboard() clipboard.setText(self.old_settings.get('hidservauth_string')) + def downloads_button_clicked(self): + """ + Browse for a new downloads directory + """ + downloads_dir = self.downloads_dir_lineedit.text() + selected_dir = QtWidgets.QFileDialog.getExistingDirectory(self, + strings._('gui_settings_downloads_label', True), downloads_dir) + + if selected_dir: + self.common.log('SettingsDialog', 'downloads_button_clicked', 'selected dir: {}'.format(selected_dir)) + self.downloads_dir_lineedit.setText(selected_dir) + def test_tor_clicked(self): """ Test Tor Settings button clicked. With the given settings, see if we can @@ -760,6 +793,7 @@ class SettingsDialog(QtWidgets.QDialog): settings.set('slug', '') # Also unset the HidServAuth if we are removing our reusable private key settings.set('hidservauth_string', '') + settings.set('downloads_dir', self.downloads_dir_lineedit.text()) settings.set('use_stealth', self.stealth_checkbox.isChecked()) # Always unset the HidServAuth if Stealth mode is unset if not self.stealth_checkbox.isChecked(): diff --git a/onionshare_gui/share_mode/__init__.py b/onionshare_gui/share_mode/__init__.py index 69af6eba..8ce9d2a9 100644 --- a/onionshare_gui/share_mode/__init__.py +++ b/onionshare_gui/share_mode/__init__.py @@ -30,7 +30,7 @@ from .file_selection import FileSelection from .server_status import ServerStatus from .downloads import Downloads from ..onion_thread import OnionThread -from ..alert import Alert +from ..widgets import Alert class ShareMode(QtWidgets.QWidget): diff --git a/onionshare_gui/share_mode/file_selection.py b/onionshare_gui/share_mode/file_selection.py index 13efba24..aa50719b 100644 --- a/onionshare_gui/share_mode/file_selection.py +++ b/onionshare_gui/share_mode/file_selection.py @@ -22,7 +22,7 @@ from PyQt5 import QtCore, QtWidgets, QtGui from onionshare import strings -from ..alert import Alert +from ..widgets import Alert, AddFileDialog class DropHereLabel(QtWidgets.QLabel): """ @@ -340,7 +340,7 @@ class FileSelection(QtWidgets.QVBoxLayout): """ Add button clicked. """ - file_dialog = FileDialog(caption=strings._('gui_choose_items', True)) + file_dialog = AddFileDialog(self.common, caption=strings._('gui_choose_items', True)) if file_dialog.exec_() == QtWidgets.QDialog.Accepted: for filename in file_dialog.selectedFiles(): self.file_list.add_file(filename) @@ -388,22 +388,3 @@ class FileSelection(QtWidgets.QVBoxLayout): Set the Qt app focus on the file selection box. """ self.file_list.setFocus() - -class FileDialog(QtWidgets.QFileDialog): - """ - Overridden version of QFileDialog which allows us to select - folders as well as, or instead of, files. - """ - def __init__(self, *args, **kwargs): - QtWidgets.QFileDialog.__init__(self, *args, **kwargs) - self.setOption(self.DontUseNativeDialog, True) - self.setOption(self.ReadOnly, True) - self.setOption(self.ShowDirsOnly, False) - self.setFileMode(self.ExistingFiles) - tree_view = self.findChild(QtWidgets.QTreeView) - tree_view.setSelectionMode(QtWidgets.QAbstractItemView.ExtendedSelection) - list_view = self.findChild(QtWidgets.QListView, "listView") - list_view.setSelectionMode(QtWidgets.QAbstractItemView.ExtendedSelection) - - def accept(self): - QtWidgets.QDialog.accept(self) diff --git a/onionshare_gui/share_mode/server_status.py b/onionshare_gui/share_mode/server_status.py index e74c41a2..4df3de79 100644 --- a/onionshare_gui/share_mode/server_status.py +++ b/onionshare_gui/share_mode/server_status.py @@ -22,7 +22,7 @@ from PyQt5 import QtCore, QtWidgets, QtGui from onionshare import strings -from ..alert import Alert +from ..widgets import Alert class ServerStatus(QtWidgets.QWidget): """ diff --git a/onionshare_gui/tor_connection_dialog.py b/onionshare_gui/tor_connection_dialog.py index ab5a7db9..b3bd1fe5 100644 --- a/onionshare_gui/tor_connection_dialog.py +++ b/onionshare_gui/tor_connection_dialog.py @@ -22,7 +22,7 @@ from PyQt5 import QtCore, QtWidgets, QtGui from onionshare import strings from onionshare.onion import * -from .alert import Alert +from .widgets import Alert class TorConnectionDialog(QtWidgets.QProgressDialog): """ diff --git a/onionshare_gui/alert.py b/onionshare_gui/widgets.py similarity index 58% rename from onionshare_gui/alert.py rename to onionshare_gui/widgets.py index 94886d17..eaa5904d 100644 --- a/onionshare_gui/alert.py +++ b/onionshare_gui/widgets.py @@ -38,3 +38,28 @@ class Alert(QtWidgets.QMessageBox): if autostart: self.exec_() + + +class AddFileDialog(QtWidgets.QFileDialog): + """ + Overridden version of QFileDialog which allows us to select folders as well + as, or instead of, files. For adding files/folders to share. + """ + def __init__(self, common, *args, **kwargs): + QtWidgets.QFileDialog.__init__(self, *args, **kwargs) + + self.common = common + self.common.log('AddFileDialog', '__init__') + + self.setOption(self.DontUseNativeDialog, True) + self.setOption(self.ReadOnly, True) + self.setOption(self.ShowDirsOnly, False) + self.setFileMode(self.ExistingFiles) + tree_view = self.findChild(QtWidgets.QTreeView) + tree_view.setSelectionMode(QtWidgets.QAbstractItemView.ExtendedSelection) + list_view = self.findChild(QtWidgets.QListView, "listView") + list_view.setSelectionMode(QtWidgets.QAbstractItemView.ExtendedSelection) + + def accept(self): + self.common.log('AddFileDialog', 'accept') + QtWidgets.QDialog.accept(self) diff --git a/share/locale/en.json b/share/locale/en.json index 730fe80e..40b3e1d8 100644 --- a/share/locale/en.json +++ b/share/locale/en.json @@ -164,5 +164,8 @@ "receive_mode_warning": "Warning: Some files can hack your computer if you open them! Only open files from people you trust, or if you know what you're doing.", "receive_mode_received_file": "Received file: {}", "gui_mode_share_button": "Share Files", - "gui_mode_receive_button": "Receive Files" + "gui_mode_receive_button": "Receive Files", + "gui_settings_receiving_label": "Receiving options", + "gui_settings_downloads_label": "Save files to", + "gui_settings_downloads_button": "Browse" }