summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMicah Lee <micah@micahflee.com>2018-11-27 12:10:16 -0800
committerMicah Lee <micah@micahflee.com>2018-11-27 12:10:16 -0800
commit3a0c8dc32317d4b66230663c1c3a40f6969d9275 (patch)
tree737da237f3c3349f3886abc391f76f6c394971cd
parent942f4f6bac805f332c4c51efeabe01cc539d0fd1 (diff)
downloadonionshare-3a0c8dc32317d4b66230663c1c3a40f6969d9275.tar.gz
onionshare-3a0c8dc32317d4b66230663c1c3a40f6969d9275.zip
In macOS, split "Add" button into "Add Files" and "Add Folder" buttons
-rw-r--r--onionshare_gui/mode/share_mode/__init__.py2
-rw-r--r--onionshare_gui/mode/share_mode/file_selection.py51
-rw-r--r--onionshare_gui/widgets.py4
-rw-r--r--share/locale/en.json2
4 files changed, 52 insertions, 7 deletions
diff --git a/onionshare_gui/mode/share_mode/__init__.py b/onionshare_gui/mode/share_mode/__init__.py
index 436d42f7..0cc00f92 100644
--- a/onionshare_gui/mode/share_mode/__init__.py
+++ b/onionshare_gui/mode/share_mode/__init__.py
@@ -47,7 +47,7 @@ class ShareMode(Mode):
self.web = Web(self.common, True, 'share')
# File selection
- self.file_selection = FileSelection(self.common)
+ self.file_selection = FileSelection(self.common, self)
if self.filenames:
for filename in self.filenames:
self.file_selection.file_list.add_file(filename)
diff --git a/onionshare_gui/mode/share_mode/file_selection.py b/onionshare_gui/mode/share_mode/file_selection.py
index ec3b5ea5..0d4229fe 100644
--- a/onionshare_gui/mode/share_mode/file_selection.py
+++ b/onionshare_gui/mode/share_mode/file_selection.py
@@ -288,10 +288,11 @@ class FileSelection(QtWidgets.QVBoxLayout):
The list of files and folders in the GUI, as well as buttons to add and
delete the files and folders.
"""
- def __init__(self, common):
+ def __init__(self, common, parent):
super(FileSelection, self).__init__()
self.common = common
+ self.parent = parent
self.server_on = False
@@ -302,13 +303,25 @@ class FileSelection(QtWidgets.QVBoxLayout):
self.file_list.files_updated.connect(self.update)
# Buttons
- self.add_button = QtWidgets.QPushButton(strings._('gui_add'))
- self.add_button.clicked.connect(self.add)
+ if self.common.platform == 'Darwin':
+ # The macOS sandbox makes it so the Mac version needs separate add files
+ # and folders buttons, in order to use native file selection dialogs
+ self.add_files_button = QtWidgets.QPushButton(strings._('gui_add_files'))
+ self.add_files_button.clicked.connect(self.add_files)
+ self.add_folder_button = QtWidgets.QPushButton(strings._('gui_add_folder'))
+ self.add_folder_button.clicked.connect(self.add_folder)
+ else:
+ self.add_button = QtWidgets.QPushButton(strings._('gui_add'))
+ self.add_button.clicked.connect(self.add)
self.delete_button = QtWidgets.QPushButton(strings._('gui_delete'))
self.delete_button.clicked.connect(self.delete)
button_layout = QtWidgets.QHBoxLayout()
button_layout.addStretch()
- button_layout.addWidget(self.add_button)
+ if self.common.platform == 'Darwin':
+ button_layout.addWidget(self.add_files_button)
+ button_layout.addWidget(self.add_folder_button)
+ else:
+ button_layout.addWidget(self.add_button)
button_layout.addWidget(self.delete_button)
# Add the widgets
@@ -323,10 +336,18 @@ class FileSelection(QtWidgets.QVBoxLayout):
"""
# All buttons should be hidden if the server is on
if self.server_on:
- self.add_button.hide()
+ if self.common.platform == 'Darwin':
+ self.add_files_button.hide()
+ self.add_folder_button.hide()
+ else:
+ self.add_button.hide()
self.delete_button.hide()
else:
- self.add_button.show()
+ if self.common.platform == 'Darwin':
+ self.add_files_button.show()
+ self.add_folder_button.show()
+ else:
+ self.add_button.show()
# Delete button should be hidden if item isn't selected
if len(self.file_list.selectedItems()) == 0:
@@ -349,6 +370,24 @@ class FileSelection(QtWidgets.QVBoxLayout):
self.file_list.setCurrentItem(None)
self.update()
+ def add_files(self):
+ """
+ Add files button clicked.
+ """
+ files = QtWidgets.QFileDialog.getOpenFileNames(self.parent, caption=strings._('gui_choose_items'))
+ filenames = files[0]
+ for filename in filenames:
+ self.file_list.add_file(filename)
+
+ def add_folder(self):
+ """
+ Add folder button clicked.
+ """
+ filename = QtWidgets.QFileDialog.getExistingDirectory(self.parent,
+ caption=strings._('gui_choose_items'),
+ options=QtWidgets.QFileDialog.ShowDirsOnly)
+ self.file_list.add_file(filename)
+
def delete(self):
"""
Delete button clicked
diff --git a/onionshare_gui/widgets.py b/onionshare_gui/widgets.py
index eaa5904d..600165aa 100644
--- a/onionshare_gui/widgets.py
+++ b/onionshare_gui/widgets.py
@@ -44,6 +44,10 @@ 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.
+
+ Note that this dialog can't be used in macOS, only in Windows, Linux, and BSD.
+ This is because the macOS sandbox requires native dialogs, and this is a Qt5
+ dialog.
"""
def __init__(self, common, *args, **kwargs):
QtWidgets.QFileDialog.__init__(self, *args, **kwargs)
diff --git a/share/locale/en.json b/share/locale/en.json
index b02e522f..438274ef 100644
--- a/share/locale/en.json
+++ b/share/locale/en.json
@@ -33,6 +33,8 @@
"help_config": "Custom JSON config file location (optional)",
"gui_drag_and_drop": "Drag and drop files and folders\nto start sharing",
"gui_add": "Add",
+ "gui_add_files": "Add Files",
+ "gui_add_folder": "Add Folder",
"gui_delete": "Delete",
"gui_choose_items": "Choose",
"gui_share_start_server": "Start sharing",