From 3d352b3585cd3730912836d4105169b9221e3813 Mon Sep 17 00:00:00 2001 From: Nino van Hooff Date: Mon, 4 Nov 2019 15:44:04 +0100 Subject: [PATCH] Show welcome page in marketplace window when not logged in TODO: marketplace logo CURA-6569 --- plugins/Toolbox/resources/qml/Toolbox.qml | 9 ++++ plugins/Toolbox/resources/qml/WelcomePage.qml | 53 +++++++++++++++++++ plugins/Toolbox/src/Toolbox.py | 23 ++++++-- resources/qml/MainWindow/ApplicationMenu.qml | 2 +- 4 files changed, 82 insertions(+), 5 deletions(-) create mode 100644 plugins/Toolbox/resources/qml/WelcomePage.qml diff --git a/plugins/Toolbox/resources/qml/Toolbox.qml b/plugins/Toolbox/resources/qml/Toolbox.qml index f70dab03d8..cf69231428 100644 --- a/plugins/Toolbox/resources/qml/Toolbox.qml +++ b/plugins/Toolbox/resources/qml/Toolbox.qml @@ -1,6 +1,8 @@ // Copyright (c) 2018 Ultimaker B.V. // Toolbox is released under the terms of the LGPLv3 or higher. +// Main window for the Toolbox + import QtQuick 2.2 import QtQuick.Dialogs 1.1 import QtQuick.Window 2.2 @@ -29,9 +31,16 @@ Window Item { anchors.fill: parent + + WelcomePage + { + visible: toolbox.viewPage === "welcome" + } + ToolboxHeader { id: header + visible: toolbox.viewPage !== "welcome" } Item diff --git a/plugins/Toolbox/resources/qml/WelcomePage.qml b/plugins/Toolbox/resources/qml/WelcomePage.qml new file mode 100644 index 0000000000..a89b490b51 --- /dev/null +++ b/plugins/Toolbox/resources/qml/WelcomePage.qml @@ -0,0 +1,53 @@ +// Copyright (c) 2018 Ultimaker B.V. +// Cura is released under the terms of the LGPLv3 or higher. + +import QtQuick 2.7 +import QtQuick.Controls 2.1 +import QtQuick.Window 2.2 + +import UM 1.3 as UM +import Cura 1.1 as Cura + +Column +{ + id: welcomePage + spacing: UM.Theme.getSize("wide_margin").height + width: parent.width + height: childrenRect.height + anchors.centerIn: parent + + Image + { + id: profileImage + fillMode: Image.PreserveAspectFit + source: "../images/logobot.svg" + anchors.horizontalCenter: parent.horizontalCenter + width: Math.round(parent.width / 4) + } + + Label + { + id: welcomeTextLabel + text: catalog.i18nc("@description", "Get plugins and materials verified by Ultimaker") + width: Math.round(parent.width / 2) + font: UM.Theme.getFont("default") + color: UM.Theme.getColor("text") + verticalAlignment: Text.AlignVCenter + horizontalAlignment: Text.AlignHCenter + anchors.horizontalCenter: parent.horizontalCenter + wrapMode: Label.WordWrap + renderType: Text.NativeRendering + } + + Cura.PrimaryButton + { + id: loginButton + width: UM.Theme.getSize("account_button").width + height: UM.Theme.getSize("account_button").height + anchors.horizontalCenter: parent.horizontalCenter + text: catalog.i18nc("@button", "Sign in") + onClicked: Cura.API.account.login() + fixedWidthMode: true + } +} + diff --git a/plugins/Toolbox/src/Toolbox.py b/plugins/Toolbox/src/Toolbox.py index 869ac6ab5e..9f8273d6e8 100644 --- a/plugins/Toolbox/src/Toolbox.py +++ b/plugins/Toolbox/src/Toolbox.py @@ -86,7 +86,7 @@ class Toolbox(QObject, Extension): # View page defines which type of page layout to use. For example, # possible values include "overview", "detail" or "author". - self._view_page = "loading" # type: str + self._view_page = "welcome" # type: str # Active package refers to which package is currently being downloaded, # installed, or otherwise modified. @@ -105,7 +105,6 @@ class Toolbox(QObject, Extension): self._restart_dialog_message = "" # type: str self._application.initializationFinished.connect(self._onAppInitialized) - self._application.getCuraAPI().account.loginStateChanged.connect(self._updateRequestHeader) self._application.getCuraAPI().account.accessTokenChanged.connect(self._updateRequestHeader) # Signals: @@ -126,6 +125,14 @@ class Toolbox(QObject, Extension): showLicenseDialog = pyqtSignal() uninstallVariablesChanged = pyqtSignal() + def _loginStateChanged(self): + self._updateRequestHeader() + if self._application.getCuraAPI().account.isLoggedIn: + self.setViewPage("loading") + self._fetchPackageData() + else: + self.setViewPage("welcome") + def _updateRequestHeader(self): self._request_headers = [ (b"User-Agent", @@ -191,6 +198,8 @@ class Toolbox(QObject, Extension): "packages": QUrl("{base_url}/packages".format(base_url = self._api_url)) } + self._application.getCuraAPI().account.loginStateChanged.connect(self._loginStateChanged) + if CuraApplication.getInstance().getPreferences().getValue("info/automatic_update_check"): # Request the latest and greatest! self._fetchPackageData() @@ -213,9 +222,9 @@ class Toolbox(QObject, Extension): # Gather installed packages: self._updateInstalledModels() + # Displays the toolbox @pyqtSlot() - def browsePackages(self) -> None: - self._fetchPackageData() + def launch(self) -> None: if not self._dialog: self._dialog = self._createDialog("Toolbox.qml") @@ -224,6 +233,12 @@ class Toolbox(QObject, Extension): Logger.log("e", "Unexpected error trying to create the 'Marketplace' dialog.") return + if self._application.getCuraAPI().account.isLoggedIn: + self.setViewPage("loading") + self._fetchPackageData() + else: + self.setViewPage("welcome") + self._dialog.show() # Apply enabled/disabled state to installed plugins diff --git a/resources/qml/MainWindow/ApplicationMenu.qml b/resources/qml/MainWindow/ApplicationMenu.qml index 70d7cd422c..30e44d7d3b 100644 --- a/resources/qml/MainWindow/ApplicationMenu.qml +++ b/resources/qml/MainWindow/ApplicationMenu.qml @@ -160,7 +160,7 @@ Item target: Cura.Actions.browsePackages onTriggered: { - curaExtensions.callExtensionMethod("Toolbox", "browsePackages") + curaExtensions.callExtensionMethod("Toolbox", "launch") } } } \ No newline at end of file