From 1b5442aece5bbbfc77595e8a335b34b3f453b023 Mon Sep 17 00:00:00 2001 From: donoban Date: Sat, 14 Nov 2020 14:10:24 +0100 Subject: [PATCH 1/5] Include in backups changed to 'CheckStateRole' --- qubesmanager/qube_manager.py | 32 ++++++++++++++++++++++++-------- 1 file changed, 24 insertions(+), 8 deletions(-) diff --git a/qubesmanager/qube_manager.py b/qubesmanager/qube_manager.py index 91023d1..4e71d3e 100644 --- a/qubesmanager/qube_manager.py +++ b/qubesmanager/qube_manager.py @@ -405,8 +405,6 @@ class QubesTableModel(QAbstractTableModel): return "Yes" if vm.internal else "" if col_name == "IP": return vm.ip - if col_name == "Include in backups": - return "Yes" if vm.inc_backup else "" if col_name == "Last backup": return vm.last_backup if col_name == "Default DispVM": @@ -429,7 +427,6 @@ class QubesTableModel(QAbstractTableModel): return self.klass_pixmap[vm.klass] except exc.QubesDaemonAccessError: return None - if col_name == "Label": try: return self.label_pixmap[vm.icon] @@ -437,23 +434,22 @@ class QubesTableModel(QAbstractTableModel): icon = QIcon.fromTheme(vm.icon) self.label_pixmap[vm.icon] = icon.pixmap(icon_size) return self.label_pixmap[vm.icon] - + if role == Qt.CheckStateRole: + if col_name == "Include in backups": + return Qt.Checked if vm.inc_backup else Qt.Unchecked if role == Qt.FontRole: if col_name == "Template": if vm.template is None: font = QFont() font.setItalic(True) return font - if role == Qt.ForegroundRole: if col_name == "Template": if vm.template is None: return QColor("gray") - # Used for get VM Object if role == Qt.UserRole: return vm - # Used for sorting if role == Qt.UserRole + 1: if vm.klass == 'AdminVM': @@ -466,7 +462,6 @@ class QubesTableModel(QAbstractTableModel): return str(vm.state) if col_name == "Disk Usage": return vm.disk_float - return self.data(index, Qt.DisplayRole) # pylint: disable=invalid-name @@ -477,6 +472,27 @@ class QubesTableModel(QAbstractTableModel): return self.columns_indices[col] return None + def setData(self, index, value, role=Qt.EditRole): + if not index.isValid(): + return False + if role == Qt.CheckStateRole: + col_name = self.columns_indices[index.column()] + if col_name == "Include in backups": + vm = self.qubes_cache.get_vm(index.row()) + vm.vm.include_in_backups = (value == 2) + vm.inc_backup = (value == 2) + return True + return False + + def flags(self, index): + if not index.isValid(): + return False + + col_name = self.columns_indices[index.column()] + if col_name == "Include in backups": + return Qt.ItemIsEnabled | Qt.ItemIsUserCheckable + + return QAbstractTableModel.flags(self, index) vm_shutdown_timeout = 20000 # in msec vm_restart_check_timeout = 1000 # in msec From 409bcd27fcc219f1db9b8a914221e19976b54431 Mon Sep 17 00:00:00 2001 From: donoban Date: Sat, 14 Nov 2020 16:12:11 +0100 Subject: [PATCH 2/5] Fix empty lines --- qubesmanager/qube_manager.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/qubesmanager/qube_manager.py b/qubesmanager/qube_manager.py index 4e71d3e..f09fe9b 100644 --- a/qubesmanager/qube_manager.py +++ b/qubesmanager/qube_manager.py @@ -475,6 +475,7 @@ class QubesTableModel(QAbstractTableModel): def setData(self, index, value, role=Qt.EditRole): if not index.isValid(): return False + if role == Qt.CheckStateRole: col_name = self.columns_indices[index.column()] if col_name == "Include in backups": @@ -491,7 +492,6 @@ class QubesTableModel(QAbstractTableModel): col_name = self.columns_indices[index.column()] if col_name == "Include in backups": return Qt.ItemIsEnabled | Qt.ItemIsUserCheckable - return QAbstractTableModel.flags(self, index) vm_shutdown_timeout = 20000 # in msec From d74b52c00b69ab3de2de5cc6ffce054a80277b14 Mon Sep 17 00:00:00 2001 From: donoban Date: Sun, 15 Nov 2020 19:08:22 +0100 Subject: [PATCH 3/5] flags() rewrite --- qubesmanager/qube_manager.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/qubesmanager/qube_manager.py b/qubesmanager/qube_manager.py index f09fe9b..bb1d3f9 100644 --- a/qubesmanager/qube_manager.py +++ b/qubesmanager/qube_manager.py @@ -489,10 +489,10 @@ class QubesTableModel(QAbstractTableModel): if not index.isValid(): return False - col_name = self.columns_indices[index.column()] - if col_name == "Include in backups": - return Qt.ItemIsEnabled | Qt.ItemIsUserCheckable - return QAbstractTableModel.flags(self, index) + def_flags = QAbstractTableModel.flags(self, index) + if self.columns_indices[index.column()] == "Include in backups": + return def_flags | Qt.ItemIsUserCheckable + return def_flags vm_shutdown_timeout = 20000 # in msec vm_restart_check_timeout = 1000 # in msec From 1812989ecd90f54a1fd171e28e35e78c6c53d635 Mon Sep 17 00:00:00 2001 From: donoban Date: Sat, 12 Dec 2020 14:18:34 +0100 Subject: [PATCH 4/5] Rename 'Include in backups' to 'Backup' --- qubesmanager/qube_manager.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/qubesmanager/qube_manager.py b/qubesmanager/qube_manager.py index bb1d3f9..967fcae 100644 --- a/qubesmanager/qube_manager.py +++ b/qubesmanager/qube_manager.py @@ -360,7 +360,7 @@ class QubesTableModel(QAbstractTableModel): "Disk Usage", "Internal", "IP", - "Include in backups", + "Backup", "Last backup", "Default DispVM", "Is DVM Template", @@ -435,7 +435,7 @@ class QubesTableModel(QAbstractTableModel): self.label_pixmap[vm.icon] = icon.pixmap(icon_size) return self.label_pixmap[vm.icon] if role == Qt.CheckStateRole: - if col_name == "Include in backups": + if col_name == "Backup": return Qt.Checked if vm.inc_backup else Qt.Unchecked if role == Qt.FontRole: if col_name == "Template": @@ -478,7 +478,7 @@ class QubesTableModel(QAbstractTableModel): if role == Qt.CheckStateRole: col_name = self.columns_indices[index.column()] - if col_name == "Include in backups": + if col_name == "Backup": vm = self.qubes_cache.get_vm(index.row()) vm.vm.include_in_backups = (value == 2) vm.inc_backup = (value == 2) @@ -490,7 +490,7 @@ class QubesTableModel(QAbstractTableModel): return False def_flags = QAbstractTableModel.flags(self, index) - if self.columns_indices[index.column()] == "Include in backups": + if self.columns_indices[index.column()] == "Backup": return def_flags | Qt.ItemIsUserCheckable return def_flags From c6663576257a1f2373d2d68a5b622084de2090ad Mon Sep 17 00:00:00 2001 From: donoban Date: Sat, 12 Dec 2020 14:22:15 +0100 Subject: [PATCH 5/5] Replace '2' with Qt.Checked --- qubesmanager/qube_manager.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/qubesmanager/qube_manager.py b/qubesmanager/qube_manager.py index 967fcae..8d7ec92 100644 --- a/qubesmanager/qube_manager.py +++ b/qubesmanager/qube_manager.py @@ -480,8 +480,8 @@ class QubesTableModel(QAbstractTableModel): col_name = self.columns_indices[index.column()] if col_name == "Backup": vm = self.qubes_cache.get_vm(index.row()) - vm.vm.include_in_backups = (value == 2) - vm.inc_backup = (value == 2) + vm.vm.include_in_backups = (value == Qt.Checked) + vm.inc_backup = (value == Qt.Checked) return True return False