diff --git a/cura/CuraApplication.py b/cura/CuraApplication.py index 6a7295ba33..a8cb4b3601 100755 --- a/cura/CuraApplication.py +++ b/cura/CuraApplication.py @@ -248,8 +248,6 @@ class CuraApplication(QtApplication): self._update_platform_activity_timer = None - self._need_to_show_user_agreement = True - self._sidebar_custom_menu_items = [] # type: list # Keeps list of custom menu items for the side bar self._plugins_loaded = False @@ -461,7 +459,7 @@ class CuraApplication(QtApplication): # Misc.: "ConsoleLogger", #You want to be able to read the log if something goes wrong. "CuraEngineBackend", #Cura is useless without this one since you can't slice. - "UserAgreement", #Our lawyers want every user to see this at least once. + # NOTE: User-Agreement is part of the 'onboarding flow' now (See Welcome Pages). "FileLogger", #You want to be able to read the log if something goes wrong. "XmlMaterialProfile", #Cura crashes without this one. "Toolbox", #This contains the interface to enable/disable plug-ins, so if you disable it you can't enable it back. @@ -533,7 +531,7 @@ class CuraApplication(QtApplication): preferences.addPreference("cura/expanded_brands", "") preferences.addPreference("cura/expanded_types", "") - self._need_to_show_user_agreement = not preferences.getValue("general/accepted_user_agreement") + preferences.addPreference("general/accepted_user_agreement", False) for key in [ "dialog_load_path", # dialog_save_path is in LocalFileOutputDevicePlugin @@ -556,13 +554,20 @@ class CuraApplication(QtApplication): @pyqtProperty(bool) def needToShowUserAgreement(self) -> bool: - return self._need_to_show_user_agreement + return not self.getPreferences().getValue("general/accepted_user_agreement") + @pyqtSlot(bool) def setNeedToShowUserAgreement(self, set_value = True) -> None: - self._need_to_show_user_agreement = set_value + self.getPreferences().setValue("general/accepted_user_agreement", not set_value) + + @pyqtSlot(str, str) + def writeToLog(self, severity: str, message: str) -> None: + Logger.log(severity, message) # DO NOT call this function to close the application, use checkAndExitApplication() instead which will perform # pre-exit checks such as checking for in-progress USB printing, etc. + # Except for the 'Decline and close' in the 'User Agreement'-step in the Welcome-pages, that should be a hard exit. + @pyqtSlot() def closeApplication(self) -> None: Logger.log("i", "Close application") main_window = self.getMainWindow() diff --git a/cura/Machines/Models/DiscoveredPrintersModel.py b/cura/Machines/Models/DiscoveredPrintersModel.py index 0dd07eb9ce..e31b8133a8 100644 --- a/cura/Machines/Models/DiscoveredPrintersModel.py +++ b/cura/Machines/Models/DiscoveredPrintersModel.py @@ -126,3 +126,11 @@ class DiscoveredPrintersModel(QObject): @pyqtSlot("QVariant") def createMachineFromDiscoveredPrinter(self, discovered_printer: "DiscoveredPrinter") -> None: discovered_printer.create_callback(discovered_printer.getKey()) + + @pyqtSlot(str) + def createMachineFromDiscoveredPrinterAddress(self, ip_address: str) -> None: + if ip_address not in self._discovered_printer_dict: + Logger.log("i", "Key [%s] does not exist in the discovered printers list.", ip_address) + return + + self.createMachineFromDiscoveredPrinter(self._discovered_printer_dict[ip_address]) diff --git a/plugins/UM3NetworkPrinting/src/UM3OutputDevicePlugin.py b/plugins/UM3NetworkPrinting/src/UM3OutputDevicePlugin.py index 2abd2f15c3..d0fc543cd6 100644 --- a/plugins/UM3NetworkPrinting/src/UM3OutputDevicePlugin.py +++ b/plugins/UM3NetworkPrinting/src/UM3OutputDevicePlugin.py @@ -14,6 +14,8 @@ from PyQt5.QtGui import QDesktopServices from cura.CuraApplication import CuraApplication from cura.PrinterOutputDevice import ConnectionType from cura.Settings.GlobalStack import GlobalStack # typing +from UM.OutputDevice.OutputDevicePlugin import OutputDevicePlugin +from UM.OutputDevice.OutputDeviceManager import ManualDeviceAdditionAttempt from UM.i18n import i18nCatalog from UM.Logger import Logger @@ -35,8 +37,8 @@ i18n_catalog = i18nCatalog("cura") # If we discover a printer that has the same key as the active machine instance a connection is made. @signalemitter class UM3OutputDevicePlugin(OutputDevicePlugin): - addDeviceSignal = Signal() - removeDeviceSignal = Signal() + addDeviceSignal = Signal() # Called '...Signal' to avoid confusion with function-names. + removeDeviceSignal = Signal() # Ditto ^^^. discoveredDevicesChanged = Signal() cloudFlowIsPossible = Signal() @@ -176,6 +178,8 @@ class UM3OutputDevicePlugin(OutputDevicePlugin): self.checkCloudFlowIsPossible() else: self.getOutputDeviceManager().removeOutputDevice(key) + if key.startswith("manual:"): + self.removeManualDeviceSignal.emit(self.getPluginId(), key, self._discovered_devices[key].address) def stop(self): if self._zero_conf is not None: @@ -183,6 +187,10 @@ class UM3OutputDevicePlugin(OutputDevicePlugin): self._zero_conf.close() self._cloud_output_device_manager.stop() + def canAddManualDevice(self, address: str = "") -> ManualDeviceAdditionAttempt: + # This plugin should always be the fallback option (at least try it): + return ManualDeviceAdditionAttempt.POSSIBLE + def removeManualDevice(self, key, address = None): if key in self._discovered_devices: if not address: @@ -194,6 +202,8 @@ class UM3OutputDevicePlugin(OutputDevicePlugin): self._manual_instances.remove(address) self._preferences.setValue("um3networkprinting/manual_instances", ",".join(self._manual_instances)) + self.removeManualDeviceSignal.emit(self.getPluginId(), key, address) + def addManualDevice(self, address): if address not in self._manual_instances: self._manual_instances.append(address) @@ -216,8 +226,6 @@ class UM3OutputDevicePlugin(OutputDevicePlugin): self._checkManualDevice(address) def _createMachineFromDiscoveredPrinter(self, key: str) -> None: - # TODO: This needs to be implemented. It's supposed to create a machine given a unique key as already discovered - # by this plugin. discovered_device = self._discovered_devices.get(key) if discovered_device is None: Logger.log("e", "Could not find discovered device with key [%s]", key) @@ -246,6 +254,10 @@ class UM3OutputDevicePlugin(OutputDevicePlugin): def _onNetworkRequestFinished(self, reply): reply_url = reply.url().toString() + address = "" + device = None + properties = {} # type: Dict[bytes, bytes] + if "system" in reply_url: if reply.attribute(QNetworkRequest.HttpStatusCodeAttribute) != 200: # Something went wrong with checking the firmware version! @@ -305,6 +317,10 @@ class UM3OutputDevicePlugin(OutputDevicePlugin): self._onRemoveDevice(instance_name) self._onAddDevice(instance_name, address, properties) + if device and address in self._manual_instances: + self.getOutputDeviceManager().addOutputDevice(device) + self.addManualDeviceSignal.emit(self.getPluginId(), device.getId(), address, properties) + def _onRemoveDevice(self, device_id): device = self._discovered_devices.pop(device_id, None) if device: diff --git a/plugins/UserAgreement/UserAgreement.py b/plugins/UserAgreement/UserAgreement.py deleted file mode 100644 index 4ea1ccf9bb..0000000000 --- a/plugins/UserAgreement/UserAgreement.py +++ /dev/null @@ -1,46 +0,0 @@ -# Copyright (c) 2017 Ultimaker B.V. -# Cura is released under the terms of the LGPLv3 or higher. - -import os - -from PyQt5.QtCore import QObject, pyqtSlot - -from UM.Extension import Extension -from UM.Logger import Logger - - -class UserAgreement(QObject, Extension): - def __init__(self, application): - super(UserAgreement, self).__init__() - self._application = application - self._user_agreement_window = None - self._user_agreement_context = None - self._application.engineCreatedSignal.connect(self._onEngineCreated) - - self._application.getPreferences().addPreference("general/accepted_user_agreement", False) - - def _onEngineCreated(self): - if not self._application.getPreferences().getValue("general/accepted_user_agreement"): - self.showUserAgreement() - - def showUserAgreement(self): - if not self._user_agreement_window: - self.createUserAgreementWindow() - - self._user_agreement_window.show() - - @pyqtSlot(bool) - def didAgree(self, user_choice): - if user_choice: - Logger.log("i", "User agreed to the user agreement") - self._application.getPreferences().setValue("general/accepted_user_agreement", True) - self._user_agreement_window.hide() - else: - Logger.log("i", "User did NOT agree to the user agreement") - self._application.getPreferences().setValue("general/accepted_user_agreement", False) - self._application.quit() - self._application.setNeedToShowUserAgreement(False) - - def createUserAgreementWindow(self): - path = os.path.join(self._application.getPluginRegistry().getPluginPath(self.getPluginId()), "UserAgreement.qml") - self._user_agreement_window = self._application.createQmlComponent(path, {"manager": self}) diff --git a/plugins/UserAgreement/UserAgreement.qml b/plugins/UserAgreement/UserAgreement.qml deleted file mode 100644 index 2e5893fc41..0000000000 --- a/plugins/UserAgreement/UserAgreement.qml +++ /dev/null @@ -1,63 +0,0 @@ -// Copyright (c) 2017 Ultimaker B.V. -// Cura is released under the terms of the LGPLv3 or higher. - -import QtQuick 2.2 -import QtQuick.Controls 1.4 - -import UM 1.3 as UM - -UM.Dialog -{ - id: baseDialog - minimumWidth: Math.round(UM.Theme.getSize("modal_window_minimum").width * 0.75) - minimumHeight: Math.round(UM.Theme.getSize("modal_window_minimum").height * 0.5) - width: minimumWidth - height: minimumHeight - title: catalog.i18nc("@title:window", "User Agreement") - - TextArea - { - anchors.top: parent.top - width: parent.width - anchors.bottom: buttonRow.top - text: '

DISCLAIMER BY ULTIMAKER

-

PLEASE READ THIS DISCLAIMER CAREFULLY.

-

EXCEPT WHEN OTHERWISE STATED IN WRITING, ULTIMAKER PROVIDES ANY ULTIMAKER SOFTWARE OR THIRD PARTY SOFTWARE “AS IS” WITHOUT WARRANTY OF ANY KIND. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF ULTIMAKER SOFTWARE IS WITH YOU.

-

UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING, IN NO EVENT WILL ULTIMAKER BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE ANY ULTIMAKER SOFTWARE OR THIRD PARTY SOFTWARE.

- ' - readOnly: true; - textFormat: TextEdit.RichText - } - - Item - { - id: buttonRow - anchors.bottom: parent.bottom - width: parent.width - anchors.bottomMargin: UM.Theme.getSize("default_margin").height - - UM.I18nCatalog { id: catalog; name: "cura" } - - Button - { - anchors.right: parent.right - text: catalog.i18nc("@action:button", "I understand and agree") - onClicked: { - baseDialog.accepted() - } - } - - Button - { - anchors.left: parent.left - text: catalog.i18nc("@action:button", "I don't agree") - onClicked: { - baseDialog.rejected() - } - } - } - - onAccepted: manager.didAgree(true) - onRejected: manager.didAgree(false) - onClosing: manager.didAgree(false) -} diff --git a/plugins/UserAgreement/__init__.py b/plugins/UserAgreement/__init__.py deleted file mode 100644 index 3cf81c64f4..0000000000 --- a/plugins/UserAgreement/__init__.py +++ /dev/null @@ -1,10 +0,0 @@ -# Copyright (c) 2017 Ultimaker B.V. -# Cura is released under the terms of the LGPLv3 or higher. - -from . import UserAgreement - -def getMetaData(): - return {} - -def register(app): - return {"extension": UserAgreement.UserAgreement(app)} diff --git a/plugins/UserAgreement/plugin.json b/plugins/UserAgreement/plugin.json deleted file mode 100644 index b172d1f9a2..0000000000 --- a/plugins/UserAgreement/plugin.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "name": "UserAgreement", - "author": "Ultimaker B.V.", - "version": "1.0.1", - "description": "Ask the user once if he/she agrees with our license.", - "api": "6.0", - "i18n-catalog": "cura" -} diff --git a/resources/bundled_packages/cura.json b/resources/bundled_packages/cura.json index 9e126ee028..12cdf7b80a 100644 --- a/resources/bundled_packages/cura.json +++ b/resources/bundled_packages/cura.json @@ -560,23 +560,6 @@ } } }, - "UserAgreement": { - "package_info": { - "package_id": "UserAgreement", - "package_type": "plugin", - "display_name": "User Agreement", - "description": "Ask the user once if he/she agrees with our license.", - "package_version": "1.0.1", - "sdk_version": "6.0", - "website": "https://ultimaker.com", - "author": { - "author_id": "UltimakerPackages", - "display_name": "Ultimaker B.V.", - "email": "plugins@ultimaker.com", - "website": "https://ultimaker.com" - } - } - }, "VersionUpgrade21to22": { "package_info": { "package_id": "VersionUpgrade21to22", diff --git a/resources/qml/Cura.qml b/resources/qml/Cura.qml index 47f712e21a..6af28d3e7b 100644 --- a/resources/qml/Cura.qml +++ b/resources/qml/Cura.qml @@ -45,7 +45,7 @@ UM.MainWindow WelcomeDialog { id: welcomeDialog - visible: false + visible: true // True, so if somehow no preferences are found/loaded, it's shown anyway. } Rectangle @@ -83,6 +83,18 @@ UM.MainWindow // This has been fixed for QtQuick Controls 2 since the Shortcut item has a context property. Cura.Actions.parent = backgroundItem CuraApplication.purgeWindows() + + if (CuraApplication.needToShowUserAgreement) + { + welcomeDialog.visible = true; + welcomeDialog.currentStep = 0; + welcomeDialog.show(); + } + else + { + welcomeDialog.hide() + welcomeDialog.visible = false; + } } Item @@ -838,16 +850,6 @@ UM.MainWindow { base.visible = true; } - - // check later if the user agreement dialog has been closed - if (CuraApplication.needToShowUserAgreement) - { - restart(); - } - else if(Cura.MachineManager.activeMachine == null) - { - addMachineDialog.open(); - } } } diff --git a/resources/qml/WelcomePages/AddPrinterByIpContent.qml b/resources/qml/WelcomePages/AddPrinterByIpContent.qml index 31d2cb4257..3aa3e8dc2b 100644 --- a/resources/qml/WelcomePages/AddPrinterByIpContent.qml +++ b/resources/qml/WelcomePages/AddPrinterByIpContent.qml @@ -22,47 +22,6 @@ Item property bool hasSentRequest: false property bool haveConnection: false - Timer - { - id: tempTimerButton - - interval: 1200 - running: false - repeat: false - onTriggered: - { - hasPushedAdd = true - tempTimerRequest.running = true - } - } - // TODO: Remove timers after review interface! - - Timer - { - id: tempTimerRequest - - interval: 1200 - running: false - repeat: false - onTriggered: - { - hasSentRequest = true - tempTimerConnection.running = true - } - } - // TODO: Remove timers after review interface! - - Timer - { - id: tempTimerConnection - - interval: 1200 - running: false - repeat: false - onTriggered: haveConnection = true - } - // TODO: Remove timers after review interface! - Label { id: titleLabel @@ -70,7 +29,7 @@ Item anchors.topMargin: 40 anchors.horizontalCenter: parent.horizontalCenter horizontalAlignment: Text.AlignHCenter - text: catalog.i18nc("@label", "Add printer by IP adress") + text: catalog.i18nc("@label", "Add printer by IP address") color: UM.Theme.getColor("primary_button") font: UM.Theme.getFont("large_bold") renderType: Text.NativeRendering @@ -96,7 +55,6 @@ Item width: parent.width anchors.top: parent.top anchors.margins: 20 - //anchors.bottomMargin: 20 font: UM.Theme.getFont("default") text: catalog.i18nc("@label", "Enter the IP address or hostname of your printer on the network.") @@ -141,13 +99,10 @@ Item text: catalog.i18nc("@button", "Add") onClicked: { - // TEMP: Simulate successfull connection to printer with 127.0.0.1 or unsuccessful with anything else - // TODO, alter after review interface, now it just starts the timers. - if (hostnameField.text.trim() != "") { addPrinterByIpScreen.hasPushedAdd = true - tempTimerRequest.running = true + UM.OutputDeviceManager.addManualDevice(hostnameField.text, hostnameField.text) } } @@ -155,7 +110,12 @@ Item BusyIndicator { anchors.fill: parent - running: { ! parent.enabled && ! addPrinterByIpScreen.hasSentRequest } + running: + { + ! parent.enabled && + ! addPrinterByIpScreen.hasSentRequest && + ! addPrinterByIpScreen.haveConnection + } } } } @@ -191,23 +151,46 @@ Item anchors.top: parent.top font: UM.Theme.getFont("large") - text: "Davids-desktop" // TODO: placeholder, alter after interface review. + text: "???" } GridLayout { + id: printerInfoGrid anchors.top: printerNameLabel.bottom + anchors.margins: 20 columns: 2 columnSpacing: 20 - Text { font: UM.Theme.getFont("default"); text: "Type" } - Text { font: UM.Theme.getFont("default"); text: "Ultimaker S5" } // TODO: placeholder, alter after interface review. + Label { font: UM.Theme.getFont("default"); text: catalog.i18nc("@label", "Type") } + Label { id: typeText; font: UM.Theme.getFont("default"); text: "?" } - Text { font: UM.Theme.getFont("default"); text: "Firmware version" } - Text { font: UM.Theme.getFont("default"); text: "4.3.3.20180529" } // TODO: placeholder, alter after interface review. + Label { font: UM.Theme.getFont("default"); text: catalog.i18nc("@label", "Firmware version") } + Label { id: firmwareText; font: UM.Theme.getFont("default"); text: "0.0.0.0" } - Text { font: UM.Theme.getFont("default"); text: "Address" } - Text { font: UM.Theme.getFont("default"); text: "10.183.1.115" } // TODO: placeholder, alter after interface review. + Label { font: UM.Theme.getFont("default"); text: catalog.i18nc("@label", "Address") } + Label { id: addressText; font: UM.Theme.getFont("default"); text: "0.0.0.0" } + + Connections + { + target: UM.OutputDeviceManager + onManualDeviceChanged: + { + typeText.text = UM.OutputDeviceManager.manualDeviceProperty("printer_type") + firmwareText.text = UM.OutputDeviceManager.manualDeviceProperty("firmware_version") + addressText.text = UM.OutputDeviceManager.manualDeviceProperty("address") + } + } + } + + Connections + { + target: UM.OutputDeviceManager + onManualDeviceChanged: + { + printerNameLabel.text = UM.OutputDeviceManager.manualDeviceProperty("name") + addPrinterByIpScreen.haveConnection = true + } } } } @@ -220,7 +203,7 @@ Item anchors.left: parent.left anchors.bottom: parent.bottom anchors.margins: 40 - text: catalog.i18nc("@button", "Back") + text: catalog.i18nc("@button", "Cancel") width: 140 fixedWidthMode: true onClicked: base.gotoPage("add_printer_by_selection") @@ -237,7 +220,13 @@ Item text: catalog.i18nc("@button", "Connect") width: 140 fixedWidthMode: true - onClicked: base.showNextPage() + onClicked: + { + CuraApplication.getDiscoveredPrintersModel().createMachineFromDiscoveredPrinterAddress( + UM.OutputDeviceManager.manualDeviceProperty("address")) + UM.OutputDeviceManager.setActiveDevice(UM.OutputDeviceManager.manualDeviceProperty("device_id")) + base.showNextPage() + } enabled: addPrinterByIpScreen.haveConnection } diff --git a/resources/qml/WelcomePages/UserAgreementContent.qml b/resources/qml/WelcomePages/UserAgreementContent.qml index 871dea4602..82b16ba2ee 100644 --- a/resources/qml/WelcomePages/UserAgreementContent.qml +++ b/resources/qml/WelcomePages/UserAgreementContent.qml @@ -62,7 +62,12 @@ Item text: catalog.i18nc("@button", "Agree") width: 140 fixedWidthMode: true - onClicked: base.showNextPage() + onClicked: + { + CuraApplication.writeToLog("i", "User accepted the User-Agreement.") + CuraApplication.setNeedToShowUserAgreement(false) + base.showNextPage() + } } Cura.SecondaryButton @@ -74,6 +79,11 @@ Item text: catalog.i18nc("@button", "Decline and close") width: 140 fixedWidthMode: true - onClicked: base.showNextPage() // TODO: quit + onClicked: + { + CuraApplication.writeToLog("i", "User declined the User Agreement.") + base.passLastPage() + CuraApplication.closeApplication() // NOTE: Hard exit, don't use if anything needs to be saved! + } } }