1
0
Fork 0
mirror of https://github.com/borgbase/vorta synced 2025-03-12 15:21:13 +00:00

Allow pasting files/folders from file manager, set model defaults (#759)

This commit is contained in:
samuel-w 2021-01-19 14:02:58 -06:00 committed by GitHub
parent a876aeda3d
commit 031a5f64ce
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 20 additions and 11 deletions

View file

@ -106,9 +106,9 @@ class BackupProfileModel(pw.Model):
class SourceFileModel(pw.Model):
"""A folder to be backed up, related to a Backup Configuration."""
dir = pw.CharField()
dir_size = pw.BigIntegerField()
dir_files_count = pw.BigIntegerField()
path_isdir = pw.BooleanField()
dir_size = pw.BigIntegerField(default=-1)
dir_files_count = pw.BigIntegerField(default=-1)
path_isdir = pw.BooleanField(default=False)
profile = pw.ForeignKeyField(BackupProfileModel, default=1)
added_at = pw.DateTimeField(default=datetime.utcnow)

View file

@ -106,7 +106,10 @@ class SourceTab(SourceBase, SourceUI, BackupProfileMixin):
self.updateThreads.append(getDir) # this is ugly, is there a better way to keep the thread object?
getDir.start()
def add_source_to_table(self, source, update_data):
def add_source_to_table(self, source, update_data=None):
if update_data is None:
update_data = SettingsModel.get(key="get_srcpath_datasize").value
index_row = self.sourceFilesWidget.rowCount()
self.sourceFilesWidget.insertRow(index_row)
# Insert all items on current row
@ -154,13 +157,9 @@ class SourceTab(SourceBase, SourceUI, BackupProfileMixin):
def receive():
dirs = dialog.selectedFiles()
for dir in dirs:
new_source, created = SourceFileModel.get_or_create(dir=dir,
dir_size=-1,
dir_files_count=-1,
path_isdir=False,
profile=self.profile())
new_source, created = SourceFileModel.get_or_create(dir=dir, profile=self.profile())
if created:
self.add_source_to_table(new_source, SettingsModel.get(key="get_srcpath_datasize").value)
self.add_source_to_table(new_source)
new_source.save()
msg = self.tr("Choose directory to back up") if want_folder else self.tr("Choose file(s) to back up")
@ -192,12 +191,14 @@ class SourceTab(SourceBase, SourceUI, BackupProfileMixin):
invalidSources = ""
for source in sources:
if len(source) > 0: # Ignore empty newlines
if source.startswith('file://'): # Allow pasting multiple files/folders copied from file manager
source = source[7:]
if not os.path.exists(source):
invalidSources = invalidSources + "\n" + source
else:
new_source, created = SourceFileModel.get_or_create(dir=source, profile=self.profile())
if created:
self.sourceFilesWidget.addItem(source)
self.add_source_to_table(new_source)
new_source.save()
if len(invalidSources) != 0: # Check if any invalid paths

View file

@ -1,5 +1,8 @@
import os
import vorta.models
import vorta.views
from PyQt5.QtWidgets import QApplication
from PyQt5 import QtCore
def test_add_folder(qapp, qtbot, tmpdir, monkeypatch, choose_file_dialog):
@ -12,3 +15,8 @@ def test_add_folder(qapp, qtbot, tmpdir, monkeypatch, choose_file_dialog):
tab.sourceAddFolder.click()
qtbot.waitUntil(lambda: tab.sourceFilesWidget.rowCount() == 2, timeout=5000)
# Test paste button
QApplication.clipboard().setText(os.path.expanduser('~')) # Load clipboard
qtbot.mouseClick(tab.paste, QtCore.Qt.LeftButton)
assert tab.sourceFilesWidget.rowCount() == 3