diff options
author | Remco Burema <r.burema@ultimaker.com> | 2018-10-11 19:24:07 +0300 |
---|---|---|
committer | Remco Burema <r.burema@ultimaker.com> | 2018-10-11 19:24:07 +0300 |
commit | 4ecac6e27f71b9b8e6cd65aa8e96cc816c7e5428 (patch) | |
tree | f240c992c65b1c32aaf2ba827eb85c95eed1604f /plugins/FirmwareUpdateChecker | |
parent | 472d012c08f8c28a8eba29cf65baa50fa802aeda (diff) |
Set the right firmware-download-URL in the actual update-firmware-message.
Diffstat (limited to 'plugins/FirmwareUpdateChecker')
3 files changed, 23 insertions, 29 deletions
diff --git a/plugins/FirmwareUpdateChecker/FirmwareUpdateChecker.py b/plugins/FirmwareUpdateChecker/FirmwareUpdateChecker.py index 223cf2d433..90590fc5a2 100644 --- a/plugins/FirmwareUpdateChecker/FirmwareUpdateChecker.py +++ b/plugins/FirmwareUpdateChecker/FirmwareUpdateChecker.py @@ -14,8 +14,8 @@ from UM.Settings.ContainerRegistry import ContainerRegistry from cura.Settings.GlobalStack import GlobalStack -from .FirmwareUpdateCheckerJob import FirmwareUpdateCheckerJob, get_settings_key_for_machine -from .FirmwareUpdateCheckerLookup import FirmwareUpdateCheckerLookup +from .FirmwareUpdateCheckerJob import FirmwareUpdateCheckerJob +from .FirmwareUpdateCheckerLookup import FirmwareUpdateCheckerLookup, get_settings_key_for_machine i18n_catalog = i18nCatalog("cura") @@ -39,14 +39,15 @@ class FirmwareUpdateChecker(Extension): self._name_cache = [] ## Callback for the message that is spawned when there is a new version. - # TODO: Set the right download URL for each message! def _onActionTriggered(self, message, action): - if action == "download": - if self._download_url is not None: - QDesktopServices.openUrl(QUrl(self._download_url)) - - def _onSetDownloadUrl(self, download_url): - self._download_url = download_url + try: + download_url = self._lookups.getRedirectUserFor(int(action)) + if download_url is not None: + QDesktopServices.openUrl(QUrl(download_url)) + else: + Logger.log('e', "Can't find URL for {0}".format(action)) + except: + Logger.log('e', "Don't know what to do with {0}".format(action)) def _onContainerAdded(self, container): # Only take care when a new GlobalStack was added @@ -56,7 +57,7 @@ class FirmwareUpdateChecker(Extension): def _onJobFinished(self, *args, **kwargs): self._check_job = None - def lateInit(self): + def doLateInit(self): self._late_init = False self._lookups = FirmwareUpdateCheckerLookup(os.path.join(PluginRegistry.getInstance().getPluginPath( @@ -75,7 +76,7 @@ class FirmwareUpdateChecker(Extension): # This is used when checking for a new firmware version at startup. def checkFirmwareVersion(self, container = None, silent = False): if self._late_init: - self.lateInit() + self.doLateInit() container_name = container.definition.getName() if container_name in self._name_cache: @@ -84,7 +85,6 @@ class FirmwareUpdateChecker(Extension): self._check_job = FirmwareUpdateCheckerJob(container = container, silent = silent, lookups = self._lookups, - callback = self._onActionTriggered, - set_download_url_callback = self._onSetDownloadUrl) + callback = self._onActionTriggered) self._check_job.start() self._check_job.finished.connect(self._onJobFinished) diff --git a/plugins/FirmwareUpdateChecker/FirmwareUpdateCheckerJob.py b/plugins/FirmwareUpdateChecker/FirmwareUpdateCheckerJob.py index 6d72e130b2..342287ca76 100644 --- a/plugins/FirmwareUpdateChecker/FirmwareUpdateCheckerJob.py +++ b/plugins/FirmwareUpdateChecker/FirmwareUpdateCheckerJob.py @@ -11,16 +11,12 @@ import urllib.request from urllib.error import URLError import codecs -from .FirmwareUpdateCheckerLookup import FirmwareUpdateCheckerLookup +from .FirmwareUpdateCheckerLookup import FirmwareUpdateCheckerLookup, get_settings_key_for_machine from UM.i18n import i18nCatalog i18n_catalog = i18nCatalog("cura") -def get_settings_key_for_machine(machine_id: int) -> str: - return "info/latest_checked_firmware_for_{0}".format(machine_id) - - ## This job checks if there is an update available on the provided URL. class FirmwareUpdateCheckerJob(Job): STRING_ZERO_VERSION = "0.0.0" @@ -28,12 +24,12 @@ class FirmwareUpdateCheckerJob(Job): ZERO_VERSION = Version(STRING_ZERO_VERSION) EPSILON_VERSION = Version(STRING_EPSILON_VERSION) - def __init__(self, container=None, silent=False, lookups:FirmwareUpdateCheckerLookup=None, callback=None, set_download_url_callback=None): + def __init__(self, container=None, silent=False, lookups:FirmwareUpdateCheckerLookup=None, callback=None): super().__init__() self._container = container self.silent = silent self._callback = callback - self._set_download_url_callback = set_download_url_callback + self._lookups = lookups self._headers = {} # Don't set headers yet. @@ -109,20 +105,13 @@ class FirmwareUpdateCheckerJob(Job): "@info:title The %s gets replaced with the printer name.", "New %s firmware available") % machine_name) - message.addAction("download", + message.addAction(machine_id, i18n_catalog.i18nc("@action:button", "How to update"), "[no_icon]", "[no_description]", button_style=Message.ActionButtonStyle.LINK, button_align=Message.ActionButtonStyle.BUTTON_ALIGN_LEFT) - # If we do this in a cool way, the download url should be available in the JSON file - if self._set_download_url_callback: - redirect = self._lookups.getRedirectUseror(machine_id) - if redirect is not None: - self._set_download_url_callback(redirect) - else: - Logger.log('w', "No callback-url for firmware of {0}".format(repr(machine_id))) message.actionTriggered.connect(self._callback) message.show() else: diff --git a/plugins/FirmwareUpdateChecker/FirmwareUpdateCheckerLookup.py b/plugins/FirmwareUpdateChecker/FirmwareUpdateCheckerLookup.py index 62d43553c1..f2c9082f76 100644 --- a/plugins/FirmwareUpdateChecker/FirmwareUpdateCheckerLookup.py +++ b/plugins/FirmwareUpdateChecker/FirmwareUpdateCheckerLookup.py @@ -9,6 +9,11 @@ from UM.Version import Version from UM.i18n import i18nCatalog i18n_catalog = i18nCatalog("cura") + +def get_settings_key_for_machine(machine_id: int) -> str: + return "info/latest_checked_firmware_for_{0}".format(machine_id) + + def default_parse_version_response(response: str) -> Version: raw_str = response.split('\n', 1)[0].rstrip() return Version(raw_str.split('.')) # Split it into a list; the default parsing of 'single string' is different. @@ -63,5 +68,5 @@ class FirmwareUpdateCheckerLookup: def getCheckUrlsFor(self, machine_id: int) -> [str]: return self._check_urls_per_machine.get(machine_id) - def getRedirectUseror(self, machine_id: int) -> str: + def getRedirectUserFor(self, machine_id: int) -> str: return self._redirect_user_per_machine.get(machine_id) |