Merge remote-tracking branch 'origin/pr/275'

* origin/pr/275:
  Replace '2' with Qt.Checked
  Rename 'Include in backups' to 'Backup'
  flags() rewrite
  Fix empty lines
  Include in backups changed to 'CheckStateRole'
This commit is contained in:
Marek Marczykowski-Górecki 2021-01-05 21:17:12 +01:00
commit 7f257b1c8e
No known key found for this signature in database
GPG Key ID: 063938BA42CFA724

View File

@ -359,7 +359,7 @@ class QubesTableModel(QAbstractTableModel):
"Disk Usage",
"Internal",
"IP",
"Include in backups",
"Backup",
"Last backup",
"Default DispVM",
"Is DVM Template",
@ -404,8 +404,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":
@ -428,7 +426,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]
@ -436,23 +433,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 == "Backup":
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':
@ -465,7 +461,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
@ -476,6 +471,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 == "Backup":
vm = self.qubes_cache.get_vm(index.row())
vm.vm.include_in_backups = (value == Qt.Checked)
vm.inc_backup = (value == Qt.Checked)
return True
return False
def flags(self, index):
if not index.isValid():
return False
def_flags = QAbstractTableModel.flags(self, index)
if self.columns_indices[index.column()] == "Backup":
return def_flags | Qt.ItemIsUserCheckable
return def_flags
vm_shutdown_timeout = 20000 # in msec
vm_restart_check_timeout = 1000 # in msec