Add isOnline role to GlobalStacksModel

This way we can filter for only online printers or display whether printers are online or not in the future.

Contributes to issue CURA-8609.
This commit is contained in:
Ghostkeeper 2021-10-08 14:09:12 +02:00
parent 93953630ec
commit 32c63c2757
No known key found for this signature in database
GPG key ID: D2A8871EE34EC59A
2 changed files with 6 additions and 2 deletions

View file

@ -20,6 +20,7 @@ class GlobalStacksModel(ListModel):
MetaDataRole = Qt.UserRole + 5 MetaDataRole = Qt.UserRole + 5
DiscoverySourceRole = Qt.UserRole + 6 # For separating local and remote printers in the machine management page DiscoverySourceRole = Qt.UserRole + 6 # For separating local and remote printers in the machine management page
RemovalWarningRole = Qt.UserRole + 7 RemovalWarningRole = Qt.UserRole + 7
IsOnlineRole = Qt.UserRole + 8
def __init__(self, parent = None) -> None: def __init__(self, parent = None) -> None:
super().__init__(parent) super().__init__(parent)
@ -31,6 +32,7 @@ class GlobalStacksModel(ListModel):
self.addRoleName(self.HasRemoteConnectionRole, "hasRemoteConnection") self.addRoleName(self.HasRemoteConnectionRole, "hasRemoteConnection")
self.addRoleName(self.MetaDataRole, "metadata") self.addRoleName(self.MetaDataRole, "metadata")
self.addRoleName(self.DiscoverySourceRole, "discoverySource") self.addRoleName(self.DiscoverySourceRole, "discoverySource")
self.addRoleName(self.IsOnlineRole, "isOnline")
self._change_timer = QTimer() self._change_timer = QTimer()
self._change_timer.setInterval(200) self._change_timer.setInterval(200)
@ -91,6 +93,7 @@ class GlobalStacksModel(ListModel):
device_name = container_stack.getMetaDataEntry("group_name", container_stack.getName()) device_name = container_stack.getMetaDataEntry("group_name", container_stack.getName())
section_name = "Connected printers" if has_remote_connection else "Preset printers" section_name = "Connected printers" if has_remote_connection else "Preset printers"
section_name = self._catalog.i18nc("@info:title", section_name) section_name = self._catalog.i18nc("@info:title", section_name)
is_online = container_stack.getMetaDataEntry("is_online", False)
default_removal_warning = self._catalog.i18nc( default_removal_warning = self._catalog.i18nc(
"@label {0} is the name of a printer that's about to be deleted.", "@label {0} is the name of a printer that's about to be deleted.",
@ -103,6 +106,7 @@ class GlobalStacksModel(ListModel):
"hasRemoteConnection": has_remote_connection, "hasRemoteConnection": has_remote_connection,
"metadata": container_stack.getMetaData().copy(), "metadata": container_stack.getMetaData().copy(),
"discoverySource": section_name, "discoverySource": section_name,
"removalWarning": removal_warning}) "removalWarning": removal_warning,
"isOnline": is_online})
items.sort(key=lambda i: (not i["hasRemoteConnection"], i["name"])) items.sort(key=lambda i: (not i["hasRemoteConnection"], i["name"]))
self.setItems(items) self.setItems(items)

View file

@ -247,7 +247,7 @@ Window
} }
source: UM.Theme.getIcon("CloudBadge", "low") source: UM.Theme.getIcon("CloudBadge", "low")
color: "red" //TODO: connectionStatus == "printer_cloud_not_available" ? UM.Theme.getColor("cloud_unavailable") : UM.Theme.getColor("primary") color: model.isOnline ? UM.Theme.getColor("primary") : UM.Theme.getColor("cloud_unavailable")
//Make a themeable circle in the background so we can change it in other themes. //Make a themeable circle in the background so we can change it in other themes.
Rectangle Rectangle