Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Setting for number format in archive tab #1719

Merged
merged 17 commits into from
Aug 11, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions src/vorta/store/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,14 @@ def get_misc_settings() -> List[Dict[str, str]]:
'label': trans_late('settings', 'Get statistics of file/folder when added'),
'tooltip': trans_late('settings', 'When adding a new source, calculate its size and the number of files.'),
},
{
'key': 'enable_fixed_units',
'value': False,
'type': 'checkbox',
'group': information,
'label': trans_late('settings', 'Display all archive sizes in a consistent unit of measurement'),
'tooltip': trans_late('settings', 'When enabled, replaces dynamic units of measurement based on file size'),
bigtedde marked this conversation as resolved.
Show resolved Hide resolved
},
{
'key': 'use_system_keyring',
'value': True,
Expand Down
21 changes: 21 additions & 0 deletions src/vorta/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,27 @@ def find_best_unit_for_size(size: Optional[int], metric: bool = True, precision:
return n


def pretty_bytes_dynamic_units(size, metric=True, sign=False, precision=1):
if not isinstance(size, int):
return ''
prefix = '+' if sign and size > 0 else ''
power, units = (
(10**3, ['', 'K', 'M', 'G', 'T', 'P', 'E', 'Z', 'Y'])
real-yfprojects marked this conversation as resolved.
Show resolved Hide resolved
if metric
else (2**10, ['', 'Ki', 'Mi', 'Gi', 'Ti', 'Pi', 'Ei', 'Zi', 'Yi'])
)
n = 0
while abs(round(size, precision)) >= power and n + 1 < len(units):
size /= power
n += 1
real-yfprojects marked this conversation as resolved.
Show resolved Hide resolved
try:
unit = units[n]
return f'{prefix}{round(size, precision)} {unit}B'
except KeyError as e:
logger.error(e)
return "NaN"


def pretty_bytes(
size: int, metric: bool = True, sign: bool = False, precision: int = 1, fixed_unit: Optional[int] = None
) -> str:
Expand Down
18 changes: 14 additions & 4 deletions src/vorta/views/archive_tab.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,15 @@
from vorta.borg.rename import BorgRenameJob
from vorta.borg.umount import BorgUmountJob
from vorta.i18n import translate
from vorta.store.models import ArchiveModel, BackupProfileMixin
from vorta.store.models import ArchiveModel, BackupProfileMixin, SettingsModel
from vorta.utils import (
choose_file_dialog,
find_best_unit_for_sizes,
format_archive_name,
get_asset,
get_mount_points,
pretty_bytes,
pretty_bytes_dynamic_units,
)
from vorta.views import diff_result, extract_dialog
from vorta.views.diff_result import DiffResultDialog, DiffTree
Expand Down Expand Up @@ -263,9 +264,18 @@ def populate_from_profile(self):

formatted_time = archive.time.strftime('%Y-%m-%d %H:%M')
self.archiveTable.setItem(row, 0, QTableWidgetItem(formatted_time))
self.archiveTable.setItem(
row, 1, SizeItem(pretty_bytes(archive.size, fixed_unit=best_unit, precision=SIZE_DECIMAL_DIGITS))
)

if SettingsModel.get(key='enable_fixed_units').value is True:
self.archiveTable.setItem(
row,
1,
SizeItem(pretty_bytes(archive.size, fixed_unit=best_unit, precision=SIZE_DECIMAL_DIGITS)),
)
else:
self.archiveTable.setItem(
row, 1, SizeItem(pretty_bytes_dynamic_units(archive.size, precision=SIZE_DECIMAL_DIGITS))
)

if archive.duration is not None:
formatted_duration = str(timedelta(seconds=round(archive.duration)))
else:
Expand Down
1 change: 1 addition & 0 deletions src/vorta/views/main_window.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ def __init__(self, parent=None):
self.repoTab.repo_changed.connect(self.archiveTab.populate_from_profile)
self.repoTab.repo_changed.connect(self.scheduleTab.populate_from_profile)
self.repoTab.repo_added.connect(self.archiveTab.refresh_archive_list)
self.miscTab.refresh_archive.connect(self.archiveTab.populate_from_profile)

self.createStartBtn.clicked.connect(self.app.create_backup_action)
self.cancelButton.clicked.connect(self.app.backup_cancelled_event.emit)
Expand Down
9 changes: 8 additions & 1 deletion src/vorta/views/misc_tab.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import logging

from PyQt6 import uic
from PyQt6 import QtCore, uic
from PyQt6.QtCore import Qt
from PyQt6.QtWidgets import (
QApplication,
Expand Down Expand Up @@ -28,6 +28,8 @@


class MiscTab(MiscTabBase, MiscTabUI, BackupProfileMixin):
refresh_archive = QtCore.pyqtSignal()

def __init__(self, parent=None):
"""Init."""
super().__init__(parent)
Expand Down Expand Up @@ -100,6 +102,7 @@ def populate(self):
cb.setCheckState(Qt.CheckState(setting.value))
cb.setTristate(False)
cb.stateChanged.connect(lambda v, key=setting.key: self.save_setting(key, v))
cb.stateChanged.connect(lambda v, key=setting.key: self.emit_archive_refresh(key))

tb = ToolTipButton()
tb.setToolTip(setting.tooltip)
Expand All @@ -124,6 +127,10 @@ def set_icons(self):
for button in self.tooltip_buttons:
button.setIcon(get_colored_icon('help-about'))

def emit_archive_refresh(self, key):
if key == 'enable_fixed_units':
self.refresh_archive.emit()

def save_setting(self, key, new_value):
setting = SettingsModel.get(key=key)
setting.value = bool(new_value)
Expand Down