sources: add option to add a single file

This commit is contained in:
Thomas Waldmann 2018-11-24 05:12:12 +01:00
parent 94f03f052c
commit cd7c121c1f
3 changed files with 19 additions and 9 deletions

View File

@ -17,7 +17,7 @@
<item> <item>
<widget class="QLabel" name="label_6"> <widget class="QLabel" name="label_6">
<property name="text"> <property name="text">
<string>Choose folders to back up.</string> <string>Source folders and files to back up</string>
</property> </property>
</widget> </widget>
</item> </item>
@ -42,16 +42,23 @@
<item> <item>
<layout class="QVBoxLayout" name="verticalLayout"> <layout class="QVBoxLayout" name="verticalLayout">
<item> <item>
<widget class="QPushButton" name="sourceAdd"> <widget class="QPushButton" name="sourceAddFolder">
<property name="text"> <property name="text">
<string>Add Folder</string> <string>Add Folder</string>
</property> </property>
</widget> </widget>
</item> </item>
<item>
<widget class="QPushButton" name="sourceAddFile">
<property name="text">
<string>Add File</string>
</property>
</widget>
</item>
<item alignment="Qt::AlignTop"> <item alignment="Qt::AlignTop">
<widget class="QPushButton" name="sourceRemove"> <widget class="QPushButton" name="sourceRemove">
<property name="text"> <property name="text">
<string>Remove Folder</string> <string>Remove</string>
</property> </property>
</widget> </widget>
</item> </item>

View File

@ -57,11 +57,12 @@ else: # Fall back to saving password to database.
keyring.set_keyring(VortaKeyring()) keyring.set_keyring(VortaKeyring())
def choose_folder_dialog(parent, title): def choose_folder_dialog(parent, title, want_folder=True):
options = QFileDialog.Options() options = QFileDialog.Options()
if want_folder:
options |= QFileDialog.ShowDirsOnly options |= QFileDialog.ShowDirsOnly
dialog = QFileDialog(parent, title, os.path.expanduser('~'), options=options) dialog = QFileDialog(parent, title, os.path.expanduser('~'), options=options)
dialog.setFileMode(QFileDialog.Directory) dialog.setFileMode(QFileDialog.Directory if want_folder else QFileDialog.AnyFile)
dialog.setParent(parent, QtCore.Qt.Sheet) dialog.setParent(parent, QtCore.Qt.Sheet)
return dialog return dialog

View File

@ -11,7 +11,8 @@ class SourceTab(SourceBase, SourceUI, BackupProfileMixin):
super().__init__(parent) super().__init__(parent)
self.setupUi(parent) self.setupUi(parent)
self.sourceAdd.clicked.connect(self.source_add) self.sourceAddFolder.clicked.connect(lambda: self.source_add(want_folder=True))
self.sourceAddFile.clicked.connect(lambda: self.source_add(want_folder=False))
self.sourceRemove.clicked.connect(self.source_remove) self.sourceRemove.clicked.connect(self.source_remove)
self.excludePatternsField.textChanged.connect(self.save_exclude_patterns) self.excludePatternsField.textChanged.connect(self.save_exclude_patterns)
self.excludeIfPresentField.textChanged.connect(self.save_exclude_if_present) self.excludeIfPresentField.textChanged.connect(self.save_exclude_if_present)
@ -33,7 +34,7 @@ class SourceTab(SourceBase, SourceUI, BackupProfileMixin):
self.excludePatternsField.textChanged.connect(self.save_exclude_patterns) self.excludePatternsField.textChanged.connect(self.save_exclude_patterns)
self.excludeIfPresentField.textChanged.connect(self.save_exclude_if_present) self.excludeIfPresentField.textChanged.connect(self.save_exclude_if_present)
def source_add(self): def source_add(self, want_folder):
def receive(): def receive():
dir = dialog.selectedFiles() dir = dialog.selectedFiles()
if dir: if dir:
@ -42,7 +43,8 @@ class SourceTab(SourceBase, SourceUI, BackupProfileMixin):
self.sourceDirectoriesWidget.addItem(dir[0]) self.sourceDirectoriesWidget.addItem(dir[0])
new_source.save() new_source.save()
dialog = choose_folder_dialog(self, "Choose Directory to back up") item = "directory" if want_folder else "file"
dialog = choose_folder_dialog(self, "Choose %s to back up" % item, want_folder=want_folder)
dialog.open(receive) dialog.open(receive)
def source_remove(self): def source_remove(self):