mirror of
https://git.mirrors.martin98.com/https://github.com/Ultimaker/Cura
synced 2025-05-01 00:04:27 +08:00

Users with an account and an UM printer should have some basic access to the Digital Library. To this end, and to remain future proof, the online team has made an extension to its API so now feature budgets can be gauge. At the moment it's only checked wether the user has any access to personal projects at all. If so, the interface shows Digital Library functionality. Known issue: Removing the last printer from DF while still logged in leaves the DL access in the Cura interface until logged out or Cura restarted. Additionally, I think the response for a logged in user without any printer from the API is just 'data = empty list' instead of everything set to False and 0 (which should be the case as they're all listed as required fields in their docs ... maybe I'm missing something). In any case, the code as is now can handle that as well. CURA-8138
63 lines
2.5 KiB
Python
63 lines
2.5 KiB
Python
# Copyright (c) 2021 Ultimaker B.V.
|
|
# Cura is released under the terms of the LGPLv3 or higher.
|
|
import os
|
|
|
|
from UM.FileProvider import FileProvider
|
|
from UM.Logger import Logger
|
|
from cura.API import Account
|
|
from cura.CuraApplication import CuraApplication
|
|
from .DigitalFactoryController import DigitalFactoryController
|
|
|
|
|
|
class DigitalFactoryFileProvider(FileProvider):
|
|
|
|
def __init__(self, df_controller: DigitalFactoryController) -> None:
|
|
super().__init__()
|
|
self._controller = df_controller
|
|
|
|
self.menu_item_display_text = "From Digital Library"
|
|
self.shortcut = "Ctrl+Shift+O"
|
|
plugin_path = os.path.dirname(os.path.dirname(__file__))
|
|
self._dialog_path = os.path.join(plugin_path, "resources", "qml", "DigitalFactoryOpenDialog.qml")
|
|
self._dialog = None
|
|
|
|
self._account = CuraApplication.getInstance().getCuraAPI().account # type: Account
|
|
self._controller.userAccessStateChanged.connect(self._onUserAccessStateChanged)
|
|
self.enabled = self._account.isLoggedIn and self._controller.userAccountHasLibraryAccess()
|
|
self.priority = 10
|
|
|
|
def run(self) -> None:
|
|
"""
|
|
Function called every time the 'From Digital Factory' option of the 'Open File(s)' submenu is triggered
|
|
"""
|
|
self.loadWindow()
|
|
|
|
if self._account.isLoggedIn and self._controller.userAccountHasLibraryAccess():
|
|
self._controller.initialize()
|
|
|
|
if not self._dialog:
|
|
Logger.log("e", "Unable to create the Digital Library Open dialog.")
|
|
return
|
|
self._dialog.show()
|
|
|
|
def loadWindow(self) -> None:
|
|
"""
|
|
Create the GUI window for the Digital Library Open dialog. If the window is already open, bring the focus on it.
|
|
"""
|
|
|
|
if self._dialog: # Dialogue is already open.
|
|
self._dialog.requestActivate() # Bring the focus on the dialogue.
|
|
return
|
|
|
|
self._dialog = CuraApplication.getInstance().createQmlComponent(self._dialog_path, {"manager": self._controller})
|
|
if not self._dialog:
|
|
Logger.log("e", "Unable to create the Digital Library Open dialog.")
|
|
|
|
def _onUserAccessStateChanged(self, logged_in: bool) -> None:
|
|
"""
|
|
Sets the enabled status of the DigitalFactoryFileProvider according to the account's login status
|
|
:param logged_in: The new login status
|
|
"""
|
|
self.enabled = logged_in and self._controller.userAccountHasLibraryAccess()
|
|
self.enabledChanged.emit()
|