Skip to content

Commit f76195e

Browse files
authored
Disable compact button for older borg versions. By @diivi (#1727)
1 parent c56c670 commit f76195e

File tree

4 files changed

+19
-4
lines changed

4 files changed

+19
-4
lines changed

src/vorta/application.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,7 @@ def set_borg_details_result(self, result):
175175
borg_compat.set_version(result['data']['version'], result['data']['path'])
176176
self.main_window.miscTab.set_borg_details(borg_compat.version, borg_compat.path)
177177
self.main_window.repoTab.toggle_available_compression()
178+
self.main_window.archiveTab.toggle_compact_button_visibility()
178179
self.scheduler.reload_all_timers() # Start timer after Borg version is set.
179180
else:
180181
self._alert_missing_borg()

src/vorta/borg/compact.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from typing import Any, Dict
22

33
from vorta import config
4-
from vorta.i18n import trans_late, translate
4+
from vorta.i18n import translate
55
from vorta.utils import borg_compat
66

77
from .borg_job import BorgJob
@@ -44,9 +44,7 @@ def prepare(cls, profile):
4444
ret['ok'] = False # Set back to false, so we can do our own checks here.
4545

4646
if not borg_compat.check('COMPACT_SUBCOMMAND'):
47-
ret['ok'] = False
48-
ret['message'] = trans_late('messages', 'This feature needs Borg 1.2.0 or higher.')
49-
return ret
47+
raise Exception('The compact action needs Borg >= 1.2.0')
5048

5149
cmd = ['borg', '--info', '--log-json', 'compact', '--progress']
5250
if borg_compat.check('V2'):

src/vorta/views/archive_tab.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
from vorta.i18n import translate
3636
from vorta.store.models import ArchiveModel, BackupProfileMixin
3737
from vorta.utils import (
38+
borg_compat,
3839
choose_file_dialog,
3940
find_best_unit_for_sizes,
4041
format_archive_name,
@@ -83,6 +84,7 @@ def __init__(self, parent=None, app=None):
8384
self.tooltip_dict: Dict[QWidget, str] = {}
8485
self.tooltip_dict[self.bDiff] = self.bDiff.toolTip()
8586
self.tooltip_dict[self.bDelete] = self.bDelete.toolTip()
87+
self.tooltip_dict[self.compactButton] = self.compactButton.toolTip()
8688

8789
header = self.archiveTable.horizontalHeader()
8890
header.setVisible(True)
@@ -981,3 +983,16 @@ def rename_result(self, result):
981983
self.populate_from_profile()
982984
else:
983985
self._toggle_all_buttons(True)
986+
987+
def toggle_compact_button_visibility(self):
988+
"""
989+
Enable or disable the compact button depending on the Borg version.
990+
This function runs once on startup, and everytime the profile is changed.
991+
"""
992+
if borg_compat.check("COMPACT_SUBCOMMAND"):
993+
self.compactButton.setEnabled(True)
994+
self.compactButton.setToolTip(self.tooltip_dict[self.compactButton])
995+
else:
996+
self.compactButton.setEnabled(False)
997+
tooltip = self.tooltip_dict[self.compactButton]
998+
self.compactButton.setToolTip(tooltip + " " + self.tr("(This feature needs Borg 1.2.0 or higher)"))

src/vorta/views/main_window.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,7 @@ def profile_select_action(self, index):
167167
SettingsModel.update({SettingsModel.str_value: self.current_profile.id}).where(
168168
SettingsModel.key == 'previous_profile_id'
169169
).execute()
170+
self.archiveTab.toggle_compact_button_visibility()
170171

171172
def profile_rename_action(self):
172173
window = EditProfileWindow(rename_existing_id=self.profileSelector.currentData())

0 commit comments

Comments
 (0)