diff --git a/onionshare_gui/file_selection.py b/onionshare_gui/file_selection.py index 5939a865..300525be 100644 --- a/onionshare_gui/file_selection.py +++ b/onionshare_gui/file_selection.py @@ -171,15 +171,12 @@ class FileSelection(QtWidgets.QVBoxLayout): self.file_list.files_dropped.connect(self.update) # buttons - self.add_files_button = QtWidgets.QPushButton(strings._('gui_add_files', True)) - self.add_files_button.clicked.connect(self.add_files) - self.add_dir_button = QtWidgets.QPushButton(strings._('gui_add_folder', True)) - self.add_dir_button.clicked.connect(self.add_dir) + self.add_button = QtWidgets.QPushButton(strings._('gui_add', True)) + self.add_button.clicked.connect(self.add) self.delete_button = QtWidgets.QPushButton(strings._('gui_delete', True)) - self.delete_button.clicked.connect(self.delete_file) + self.delete_button.clicked.connect(self.delete) button_layout = QtWidgets.QHBoxLayout() - button_layout.addWidget(self.add_files_button) - button_layout.addWidget(self.add_dir_button) + button_layout.addWidget(self.add_button) button_layout.addWidget(self.delete_button) # add the widgets @@ -194,12 +191,10 @@ class FileSelection(QtWidgets.QVBoxLayout): """ # all buttons should be disabled if the server is on if self.server_on: - self.add_files_button.setEnabled(False) - self.add_dir_button.setEnabled(False) + self.add_button.setEnabled(False) self.delete_button.setEnabled(False) else: - self.add_files_button.setEnabled(True) - self.add_dir_button.setEnabled(True) + self.add_button.setEnabled(True) # delete button should be disabled if item isn't selected current_item = self.file_list.currentItem() @@ -211,46 +206,18 @@ class FileSelection(QtWidgets.QVBoxLayout): # update the file list self.file_list.update() - def add_files(self): + def add(self): """ - Add files button clicked. + Add button clicked. """ - file_dialog = QtWidgets.QFileDialog(caption=strings._('gui_choose_files', True)) - file_dialog.setFileMode(QtWidgets.QFileDialog.ExistingFiles) - file_dialog.setOption(QtWidgets.QFileDialog.DontUseNativeDialog, True) - file_dialog.setOption(QtWidgets.QFileDialog.ReadOnly, True) - tree_view = file_dialog.findChild(QtWidgets.QTreeView) - tree_view.setSelectionMode(QtWidgets.QAbstractItemView.ExtendedSelection) - list_view = file_dialog.findChild(QtWidgets.QListView, "listView") - list_view.setSelectionMode(QtWidgets.QAbstractItemView.ExtendedSelection) - + file_dialog = FileDialog(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) + for filename in file_dialog.selectedFiles(): + self.file_list.add_file(filename) self.update() - def add_dir(self): - """ - Add folder button clicked. - """ - file_dialog = QtWidgets.QFileDialog(caption=strings._('gui_choose_folder', True)) - file_dialog.setFileMode(QtWidgets.QFileDialog.Directory) - file_dialog.setOption(QtWidgets.QFileDialog.DontUseNativeDialog, True) - file_dialog.setOption(QtWidgets.QFileDialog.ReadOnly, True) - file_dialog.setOption(QtWidgets.QFileDialog.ShowDirsOnly, True) - tree_view = file_dialog.findChild(QtWidgets.QTreeView) - tree_view.setSelectionMode(QtWidgets.QAbstractItemView.ExtendedSelection) - list_view = file_dialog.findChild(QtWidgets.QListView, "listView") - list_view.setSelectionMode(QtWidgets.QAbstractItemView.ExtendedSelection) - - if file_dialog.exec_() == QtWidgets.QDialog.Accepted: - for filename in file_dialog.selectedFiles(): - self.file_list.add_file(filename) - - self.update() - - def delete_file(self): + def delete(self): """ Delete button clicked """ @@ -288,3 +255,22 @@ 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/share/locale/cs.json b/share/locale/cs.json index 8639403b..53525ea3 100644 --- a/share/locale/cs.json +++ b/share/locale/cs.json @@ -22,11 +22,9 @@ "help_debug": "Zaznamenat chyby na disk", "help_filename": "Seznam souborů a složek ke sdílení", "gui_drag_and_drop": "Táhni a pusť\nsoubory sem", - "gui_add_files": "Přidat soubory", - "gui_add_folder": "Přidat složku", + "gui_add": "Přidat", "gui_delete": "Smazat", - "gui_choose_files": "Vybrat soubory", - "gui_choose_folder": "vybrat složku", + "gui_choose_items": "Vybrat", "gui_start_server": "Spustit sdílení", "gui_stop_server": "Zastavit sdílení", "gui_copy_url": "Kopírovat URL", diff --git a/share/locale/de.json b/share/locale/de.json index 3cd0ff79..7347e031 100644 --- a/share/locale/de.json +++ b/share/locale/de.json @@ -22,11 +22,9 @@ "help_debug": "Fehler auf Festplatte schreiben", "help_filename": "Liste der zu teilenden Dateien oder Verzeichnisse", "gui_drag_and_drop": "Drag & drop\nDateien hier", - "gui_add_files": "Dateien hinzufügen", - "gui_add_folder": "Verzeichnis hinzufügen", + "gui_add": "Hinzufügen", "gui_delete": "Löschen", - "gui_choose_files": "Dateien auswählen", - "gui_choose_folder": "Verzeichnis auswählen", + "gui_choose_items": "Auswählen", "gui_start_server": "Server starten", "gui_stop_server": "Server anhalten", "gui_copy_url": "URL kopieren", diff --git a/share/locale/en.json b/share/locale/en.json index 31758de5..7352159e 100644 --- a/share/locale/en.json +++ b/share/locale/en.json @@ -30,11 +30,9 @@ "help_debug": "Log application errors to stdout, and log web errors to disk", "help_filename": "List of files or folders to share", "gui_drag_and_drop": "Drag and drop\nfiles here", - "gui_add_files": "Add Files", - "gui_add_folder": "Add Folders", + "gui_add": "Add", "gui_delete": "Delete", - "gui_choose_files": "Choose files", - "gui_choose_folder": "Choose folders", + "gui_choose_items": "Choose", "gui_start_server": "Start Sharing", "gui_stop_server": "Stop Sharing", "gui_copy_url": "Copy URL", diff --git a/share/locale/eo.json b/share/locale/eo.json index e7c332cd..6d904dc0 100644 --- a/share/locale/eo.json +++ b/share/locale/eo.json @@ -22,11 +22,9 @@ "help_debug": "Protokoli erarojn sur disko", "help_filename": "Listo de dosieroj aŭ dosierujoj por kundividi", "gui_drag_and_drop": "Ŝovu kaj metu\nla dosierojn ĉi tien", - "gui_add_files": "Aldoni dosierojn", - "gui_add_folder": "Aldoni dosierujon", + "gui_add": "Aldoni", "gui_delete": "Forviŝi", - "gui_choose_files": "Elekti dosierojn", - "gui_choose_folder": "Elekti dosierujon", + "gui_choose_items": "Elekti", "gui_start_server": "Komenci kundividon", "gui_stop_server": "Ĉesigi kundividon", "gui_copy_url": "Kopii URL", diff --git a/share/locale/es.json b/share/locale/es.json index 5c9367cf..5d9f8dcd 100644 --- a/share/locale/es.json +++ b/share/locale/es.json @@ -21,11 +21,9 @@ "help_debug": "Guardar registro de errores en el disco", "help_filename": "Lista de archivos o carpetas para compartir", "gui_drag_and_drop": "Arrastre\narchivos aquí", - "gui_add_files": "Añadir Archivos", - "gui_add_folder": "Añadir Carpeta", + "gui_add": "Añadir", "gui_delete": "Eliminar", - "gui_choose_files": "Elegir archivos", - "gui_choose_folder": "Elegir carpeta", + "gui_choose_items": "Elegir", "gui_start_server": "Encender el Servidor", "gui_stop_server": "Detener el Servidor", "gui_copy_url": "Copiar URL", diff --git a/share/locale/fi.json b/share/locale/fi.json index 0e1f5cdd..25fda84b 100644 --- a/share/locale/fi.json +++ b/share/locale/fi.json @@ -23,11 +23,9 @@ "help_debug": "Tallentaa virheet levylle", "help_filename": "Luettele jaettavat tiedostot tai kansiot", "gui_drag_and_drop": "Vedä ja pudota\ntiedostot tänne", - "gui_add_files": "Lisää tiedostoja", - "gui_add_folder": "Lisää kansio", + "gui_add": "Lisää", "gui_delete": "Poista", - "gui_choose_files": "Valitse tiedostoja", - "gui_choose_folder": "Valitse kansio", + "gui_choose_items": "Valitse", "gui_start_server": "Käynnistä palvelin", "gui_stop_server": "Pysäytä palvelin", "gui_copy_url": "Kopioi URL-osoite", diff --git a/share/locale/fr.json b/share/locale/fr.json index 7197f9dc..6236e533 100644 --- a/share/locale/fr.json +++ b/share/locale/fr.json @@ -20,11 +20,9 @@ "help_debug": "Enregistrer les erreurs sur le disque", "help_filename": "Liste des fichiers ou dossiers à partager", "gui_drag_and_drop": "Glissez déposez\nles fichiers ici", - "gui_add_files": "Ajouter des fichiers", - "gui_add_folder": "Ajouter des dossiers", + "gui_add": "Ajouter", "gui_delete": "Supprimer", - "gui_choose_files": "Sélectionnez des fichiers", - "gui_choose_folder": "Sélectionnez des dossiers", + "gui_choose_items": "Sélectionnez", "gui_start_server": "Démarrer le serveur", "gui_stop_server": "Arrêter le serveur", "gui_copy_url": "Copier URL", diff --git a/share/locale/it.json b/share/locale/it.json index 9f4a76e0..75532c34 100644 --- a/share/locale/it.json +++ b/share/locale/it.json @@ -23,11 +23,9 @@ "help_debug": "Registra gli errori sul disco", "help_filename": "Lista dei file o cartelle da condividere", "gui_drag_and_drop": "Prendi e rilascia\ni file qui sopra", - "gui_add_files": "Aggiungi il Files", - "gui_add_folder": "Aggiungi la Cartella", + "gui_add": "Aggiungi", "gui_delete": "Cancella", - "gui_choose_files": "Scegli il file", - "gui_choose_folder": "Scegli la cartella", + "gui_choose_items": "Scegli", "gui_start_server": "Inizia la condivisione", "gui_stop_server": "Ferma la condivisione", "gui_copy_url": "Copia lo URL", diff --git a/share/locale/nl.json b/share/locale/nl.json index 6590be71..90a84ca6 100644 --- a/share/locale/nl.json +++ b/share/locale/nl.json @@ -22,11 +22,9 @@ "help_debug": "Log fouten naar harde schijf", "help_filename": "Lijst van bestanden of mappen om te delen", "gui_drag_and_drop": "Sleep en zet\nbestanden hier neer", - "gui_add_files": "Bestanden toevoegen", - "gui_add_folder": "Map toevoegen", + "gui_add": "Toevoegen", "gui_delete": "Verwijder", - "gui_choose_files": "Kies bestanden", - "gui_choose_folder": "Kies map", + "gui_choose_items": "Kies", "gui_start_server": "Start server", "gui_stop_server": "Stop server", "gui_copy_url": "Kopieer URL", diff --git a/share/locale/tr.json b/share/locale/tr.json index bf37ac69..bd74f5f2 100644 --- a/share/locale/tr.json +++ b/share/locale/tr.json @@ -23,11 +23,9 @@ "help_debug": "Hata kayıtlarını diske kaydet", "help_filename": "Paylaşmak için dosya ve klasörler listesi", "gui_drag_and_drop": "Dosyaları buraya\n Sürükle ve Bırak", - "gui_add_files": "Dosyalar Ekle", - "gui_add_folder": "Klasör Ekle", + "gui_add": "Ekle", "gui_delete": "Sil", - "gui_choose_files": "Dosyalar Seç", - "gui_choose_folder": "Klasör Seç", + "gui_choose_items": "Seç", "gui_start_server": "Paylaşımı Başlat", "gui_stop_server": "Paylaşımı Durdur", "gui_copy_url": "URL Kopyala",