From 69f0e74ca289fa3bdbfea7b3eb5e89ce602ef7bf Mon Sep 17 00:00:00 2001 From: Manu Date: Fri, 2 Nov 2018 19:14:54 +0800 Subject: [PATCH] Implement removing a repo. --- src/vorta/application.py | 3 +- src/vorta/views/main_window.py | 2 +- src/vorta/views/repo_tab.py | 47 ++++++++++++++++++++++++-------- src/vorta/views/snapshots_tab.py | 2 ++ 4 files changed, 41 insertions(+), 13 deletions(-) diff --git a/src/vorta/application.py b/src/vorta/application.py index 09819495..0121f628 100644 --- a/src/vorta/application.py +++ b/src/vorta/application.py @@ -38,7 +38,8 @@ class VortaApp(QApplication, BackupProfileMixin): if msg['ok']: self.thread = BorgThread(msg['cmd'], msg['params'], parent=self) self.thread.start() - return msg + else: + self.backup_log_event.emit(msg['message']) def open_main_window_action(self): self.main_window.show() diff --git a/src/vorta/views/main_window.py b/src/vorta/views/main_window.py index c0a5b38c..830bbfc5 100644 --- a/src/vorta/views/main_window.py +++ b/src/vorta/views/main_window.py @@ -27,7 +27,7 @@ class MainWindow(MainWindowBase, MainWindowUI): self.snapshotTab = SnapshotTab(self.snapshotTabSlot) self.scheduleTab = ScheduleTab(self.scheduleTabSlot) - self.repoTab.repo_changed.connect(lambda: self.snapshotTab.populate()) + self.repoTab.repo_changed.connect(self.snapshotTab.populate) self.createStartBtn.clicked.connect(self.app.create_backup_action) self.cancelButton.clicked.connect(self.app.backup_cancelled_event.emit) diff --git a/src/vorta/views/repo_tab.py b/src/vorta/views/repo_tab.py index 84ba2d71..956de593 100644 --- a/src/vorta/views/repo_tab.py +++ b/src/vorta/views/repo_tab.py @@ -13,7 +13,7 @@ RepoUI, RepoBase = uic.loadUiType(uifile, from_imports=True, import_from='vorta. class RepoTab(RepoBase, RepoUI, BackupProfileMixin): - repo_changed = QtCore.pyqtSignal(int) + repo_changed = QtCore.pyqtSignal() def __init__(self, parent=None): super().__init__(parent) @@ -28,7 +28,9 @@ class RepoTab(RepoBase, RepoUI, BackupProfileMixin): if self.profile.repo: self.repoSelector.setCurrentIndex(self.repoSelector.findData(self.profile.repo.id)) + self.repoSelector.currentIndexChanged.connect(self.repo_select_action) + self.repoRemoveToolbutton.clicked.connect(self.repo_unlink_action) self.repoCompression.addItem('LZ4 (default)', 'lz4') self.repoCompression.addItem('Zstandard (medium)', 'zstd') @@ -38,17 +40,16 @@ class RepoTab(RepoBase, RepoUI, BackupProfileMixin): self.repoCompression.currentIndexChanged.connect(self.compression_select_action) self.init_ssh() - - if self.profile.repo: - self.init_repo_stats() + self.init_repo_stats() def init_repo_stats(self): repo = self.profile.repo - self.sizeCompressed.setText(pretty_bytes(repo.unique_csize)) - self.sizeDeduplicated.setText(pretty_bytes(repo.unique_size)) - self.sizeOriginal.setText(pretty_bytes(repo.total_size)) - self.repoEncryption.setText(str(repo.encryption)) - self.repo_changed.emit(repo.id) + if repo is not None: + self.sizeCompressed.setText(pretty_bytes(repo.unique_csize)) + self.sizeDeduplicated.setText(pretty_bytes(repo.unique_size)) + self.sizeOriginal.setText(pretty_bytes(repo.total_size)) + self.repoEncryption.setText(str(repo.encryption)) + self.repo_changed.emit() def init_ssh(self): keys = get_private_keys() @@ -93,13 +94,14 @@ class RepoTab(RepoBase, RepoUI, BackupProfileMixin): msg.setText("Select a public key from the dropdown first.") msg.exec_() - def compression_select_action(self, index): profile = self.profile profile.compression = self.repoCompression.currentData() profile.save() def repo_select_action(self, index): + if index == 0: + return if index <= 2: if index == 1: window = AddRepoWindow() @@ -153,4 +155,27 @@ class RepoTab(RepoBase, RepoUI, BackupProfileMixin): new_snapshot.save() self.repoSelector.addItem(new_repo.url, new_repo.id) self.repoSelector.setCurrentIndex(self.repoSelector.count()-1) - self.repo_changed.emit(self.profile.repo.id) + self.repo_changed.emit() + + def repo_unlink_action(self): + profile = self.profile + self.init_repo_stats() + msg = QMessageBox() + msg.setStandardButtons(QMessageBox.Ok) + msg.setParent(self, QtCore.Qt.Sheet) + selected_repo_id = self.repoSelector.currentData() + selected_repo_index = self.repoSelector.currentIndex() + if selected_repo_id is not None: + repo = RepoModel.get(id=selected_repo_id) + repo.delete_instance() + profile.repo = None + profile.save() + self.repoSelector.setCurrentIndex(0) + self.repoSelector.removeItem(selected_repo_index) + msg.setText('Repository was Unlinked') + msg.setInformativeText('You can always connect it again later.') + msg.exec_() + + self.repo_changed.emit() + + diff --git a/src/vorta/views/snapshots_tab.py b/src/vorta/views/snapshots_tab.py index cd485d7e..812f1d14 100644 --- a/src/vorta/views/snapshots_tab.py +++ b/src/vorta/views/snapshots_tab.py @@ -51,6 +51,8 @@ class SnapshotTab(SnapshotBase, SnapshotUI, BackupProfileMixin): self.snapshotTable.setItem(row, 2, QTableWidgetItem(formatted_duration)) self.snapshotTable.setItem(row, 3, QTableWidgetItem(snapshot.name)) self.snapshotTable.setRowCount(len(snapshots)) + else: + self.snapshotTable.setRowCount(0) def snapshot_mount(self): profile = self.profile