Add option to only show printers that are online

I have a feeling this will be abused later. But fine. We currently need it for the list of printers that we can sync materials to via the cloud.

Contributes to issue CURA-8609.
This commit is contained in:
Ghostkeeper 2021-10-08 14:21:03 +02:00
parent 8234276204
commit 07b2c1b777
No known key found for this signature in database
GPG key ID: D2A8871EE34EC59A

View file

@ -40,6 +40,7 @@ class GlobalStacksModel(ListModel):
self._change_timer.timeout.connect(self._update)
self._filter_connection_type = -1
self._filter_online_only = False
# Listen to changes
CuraContainerRegistry.getInstance().containerAdded.connect(self._onContainerChanged)
@ -48,7 +49,6 @@ class GlobalStacksModel(ListModel):
self._updateDelayed()
filterConnectionTypeChanged = pyqtSignal()
def setFilterConnectionType(self, new_filter: int) -> None:
self._filter_connection_type = new_filter
@ -62,6 +62,17 @@ class GlobalStacksModel(ListModel):
"""
return self._filter_connection_type
filterOnlineOnlyChanged = pyqtSignal()
def setFilterOnlineOnly(self, new_filter: bool) -> None:
self._filter_online_only = new_filter
@pyqtProperty(bool, fset = setFilterOnlineOnly, notify = filterOnlineOnlyChanged)
def filterOnlineOnly(self) -> bool:
"""
Whether to filter the global stacks to show only printers that are online.
"""
return self._filter_online_only
def _onContainerChanged(self, container) -> None:
"""Handler for container added/removed events from registry"""
@ -90,10 +101,13 @@ class GlobalStacksModel(ListModel):
if parseBool(container_stack.getMetaDataEntry("hidden", False)):
continue
is_online = container_stack.getMetaDataEntry("is_online", False)
if self._filter_online_only and not is_online:
continue
device_name = container_stack.getMetaDataEntry("group_name", container_stack.getName())
section_name = "Connected printers" if has_remote_connection else "Preset printers"
section_name = self._catalog.i18nc("@info:title", section_name)
is_online = container_stack.getMetaDataEntry("is_online", False)
default_removal_warning = self._catalog.i18nc(
"@label {0} is the name of a printer that's about to be deleted.",