Merge pull request #6624 from Ultimaker/CURA-6569_mandatory_marketplace_login

WIP: CURA-6569_mandatory_marketplace_login
This commit is contained in:
Lipu Fei 2019-11-05 11:04:14 +01:00 committed by GitHub
commit af909b25a2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
32 changed files with 113 additions and 18 deletions

View File

@ -9,7 +9,11 @@ DEFAULT_CURA_DISPLAY_NAME = "Ultimaker Cura"
DEFAULT_CURA_VERSION = "master" DEFAULT_CURA_VERSION = "master"
DEFAULT_CURA_BUILD_TYPE = "" DEFAULT_CURA_BUILD_TYPE = ""
DEFAULT_CURA_DEBUG_MODE = False DEFAULT_CURA_DEBUG_MODE = False
DEFAULT_CURA_SDK_VERSION = "7.0.0"
# Each release has a fixed SDK version coupled with it. It doesn't make sense to make it configurable because, for
# example Cura 3.2 with SDK version 6.1 will not work. So the SDK version is hard-coded here and left out of the
# CuraVersion.py.in template.
CuraSDKVersion = "7.0.0"
try: try:
from cura.CuraVersion import CuraAppName # type: ignore from cura.CuraVersion import CuraAppName # type: ignore
@ -32,6 +36,9 @@ try:
except ImportError: except ImportError:
CuraVersion = DEFAULT_CURA_VERSION # [CodeStyle: Reflecting imported value] CuraVersion = DEFAULT_CURA_VERSION # [CodeStyle: Reflecting imported value]
# CURA-6569
# This string indicates what type of version it is. For example, "enterprise". By default it's empty which indicates
# a default/normal Cura build.
try: try:
from cura.CuraVersion import CuraBuildType # type: ignore from cura.CuraVersion import CuraBuildType # type: ignore
except ImportError: except ImportError:
@ -42,7 +49,8 @@ try:
except ImportError: except ImportError:
CuraDebugMode = DEFAULT_CURA_DEBUG_MODE CuraDebugMode = DEFAULT_CURA_DEBUG_MODE
# Each release has a fixed SDK version coupled with it. It doesn't make sense to make it configurable because, for
# example Cura 3.2 with SDK version 6.1 will not work. So the SDK version is hard-coded here and left out of the # CURA-6569
# CuraVersion.py.in template. # Various convenience flags indicating what kind of Cura build it is.
CuraSDKVersion = "7.0.0" __ENTERPRISE_VERSION_TYPE = "enterprise"
IsEnterpriseVersion = CuraBuildType.lower() == __ENTERPRISE_VERSION_TYPE

View File

@ -1,11 +1,17 @@
// Copyright (c) 2018 Ultimaker B.V. // Copyright (c) 2018 Ultimaker B.V.
// Toolbox is released under the terms of the LGPLv3 or higher. // Toolbox is released under the terms of the LGPLv3 or higher.
// Main window for the Toolbox
import QtQuick 2.2 import QtQuick 2.2
import QtQuick.Dialogs 1.1 import QtQuick.Dialogs 1.1
import QtQuick.Window 2.2 import QtQuick.Window 2.2
import UM 1.1 as UM import UM 1.1 as UM
import "./pages"
import "./dialogs"
import "./components"
Window Window
{ {
id: base id: base
@ -29,9 +35,16 @@ Window
Item Item
{ {
anchors.fill: parent anchors.fill: parent
WelcomePage
{
visible: toolbox.viewPage === "welcome"
}
ToolboxHeader ToolboxHeader
{ {
id: header id: header
visible: toolbox.viewPage !== "welcome"
} }
Item Item

View File

@ -67,7 +67,7 @@ Item
width: UM.Theme.getSize("toolbox_thumbnail_small").width - UM.Theme.getSize("wide_margin").width width: UM.Theme.getSize("toolbox_thumbnail_small").width - UM.Theme.getSize("wide_margin").width
height: UM.Theme.getSize("toolbox_thumbnail_small").height - UM.Theme.getSize("wide_margin").width height: UM.Theme.getSize("toolbox_thumbnail_small").height - UM.Theme.getSize("wide_margin").width
fillMode: Image.PreserveAspectFit fillMode: Image.PreserveAspectFit
source: model.icon_url || "../images/logobot.svg" source: model.icon_url || "../../images/logobot.svg"
mipmap: true mipmap: true
} }
UM.RecolorImage UM.RecolorImage
@ -82,7 +82,7 @@ Item
sourceSize.height: height sourceSize.height: height
visible: installedPackages != 0 visible: installedPackages != 0
color: (installedPackages >= packageCount) ? UM.Theme.getColor("primary") : UM.Theme.getColor("border") color: (installedPackages >= packageCount) ? UM.Theme.getColor("primary") : UM.Theme.getColor("border")
source: "../images/installed_check.svg" source: "../../images/installed_check.svg"
} }
} }
Item Item

View File

@ -23,7 +23,7 @@ Rectangle
height: UM.Theme.getSize("toolbox_thumbnail_large").height - 4 * UM.Theme.getSize("default_margin").height height: UM.Theme.getSize("toolbox_thumbnail_large").height - 4 * UM.Theme.getSize("default_margin").height
width: UM.Theme.getSize("toolbox_thumbnail_large").height - 4 * UM.Theme.getSize("default_margin").height width: UM.Theme.getSize("toolbox_thumbnail_large").height - 4 * UM.Theme.getSize("default_margin").height
fillMode: Image.PreserveAspectFit fillMode: Image.PreserveAspectFit
source: model.icon_url || "../images/logobot.svg" source: model.icon_url || "../../images/logobot.svg"
mipmap: true mipmap: true
anchors anchors
{ {
@ -62,7 +62,7 @@ Rectangle
} }
visible: installedPackages != 0 visible: installedPackages != 0
color: (installedPackages >= packageCount) ? UM.Theme.getColor("primary") : UM.Theme.getColor("border") color: (installedPackages >= packageCount) ? UM.Theme.getColor("primary") : UM.Theme.getColor("border")
source: "../images/installed_check.svg" source: "../../images/installed_check.svg"
} }
SmallRatingWidget SmallRatingWidget

View File

@ -14,7 +14,7 @@ import Cura 1.0 as Cura
UM.Dialog UM.Dialog
{ {
// This dialog asks the user whether he/she wants to open a project file as a project or import models. // This dialog asks the user to confirm he/she wants to uninstall materials/pprofiles which are currently in use
id: base id: base
title: catalog.i18nc("@title:window", "Confirm uninstall") + toolbox.pluginToUninstall title: catalog.i18nc("@title:window", "Confirm uninstall") + toolbox.pluginToUninstall

View File

@ -6,6 +6,8 @@ import QtQuick.Controls 1.4
import QtQuick.Controls.Styles 1.4 import QtQuick.Controls.Styles 1.4
import UM 1.1 as UM import UM 1.1 as UM
import "../components"
Item Item
{ {
id: page id: page
@ -31,7 +33,7 @@ Item
width: UM.Theme.getSize("toolbox_thumbnail_medium").width width: UM.Theme.getSize("toolbox_thumbnail_medium").width
height: UM.Theme.getSize("toolbox_thumbnail_medium").height height: UM.Theme.getSize("toolbox_thumbnail_medium").height
fillMode: Image.PreserveAspectFit fillMode: Image.PreserveAspectFit
source: details.icon_url || "../images/logobot.svg" source: details.icon_url || "../../images/logobot.svg"
mipmap: true mipmap: true
anchors anchors
{ {

View File

@ -8,6 +8,8 @@ import UM 1.1 as UM
import Cura 1.1 as Cura import Cura 1.1 as Cura
import "../components"
Item Item
{ {
id: page id: page
@ -44,7 +46,7 @@ Item
{ {
anchors.fill: parent anchors.fill: parent
fillMode: Image.PreserveAspectFit fillMode: Image.PreserveAspectFit
source: details === null ? "" : (details.icon_url || "../images/logobot.svg") source: details === null ? "" : (details.icon_url || "../../images/logobot.svg")
mipmap: true mipmap: true
} }
} }

View File

@ -5,6 +5,8 @@ import QtQuick 2.10
import QtQuick.Controls 2.3 import QtQuick.Controls 2.3
import UM 1.1 as UM import UM 1.1 as UM
import "../components"
ScrollView ScrollView
{ {
clip: true clip: true

View File

@ -6,6 +6,8 @@ import QtQuick.Controls 2.3
import UM 1.1 as UM import UM 1.1 as UM
import "../components"
ScrollView ScrollView
{ {
id: page id: page

View File

@ -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
}
}

View File

@ -86,7 +86,7 @@ class Toolbox(QObject, Extension):
# View page defines which type of page layout to use. For example, # View page defines which type of page layout to use. For example,
# possible values include "overview", "detail" or "author". # 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, # Active package refers to which package is currently being downloaded,
# installed, or otherwise modified. # installed, or otherwise modified.
@ -105,7 +105,6 @@ class Toolbox(QObject, Extension):
self._restart_dialog_message = "" # type: str self._restart_dialog_message = "" # type: str
self._application.initializationFinished.connect(self._onAppInitialized) self._application.initializationFinished.connect(self._onAppInitialized)
self._application.getCuraAPI().account.loginStateChanged.connect(self._updateRequestHeader)
self._application.getCuraAPI().account.accessTokenChanged.connect(self._updateRequestHeader) self._application.getCuraAPI().account.accessTokenChanged.connect(self._updateRequestHeader)
# Signals: # Signals:
@ -126,6 +125,16 @@ class Toolbox(QObject, Extension):
showLicenseDialog = pyqtSignal() showLicenseDialog = pyqtSignal()
uninstallVariablesChanged = pyqtSignal() uninstallVariablesChanged = pyqtSignal()
## Go back to the start state (welcome screen or loading if no login required)
def _restart(self):
self._updateRequestHeader()
# For an Essentials build, login is mandatory
if not self._application.getCuraAPI().account.isLoggedIn and ApplicationMetadata.IsEnterpriseVersion:
self.setViewPage("welcome")
else:
self.setViewPage("loading")
self._fetchPackageData()
def _updateRequestHeader(self): def _updateRequestHeader(self):
self._request_headers = [ self._request_headers = [
(b"User-Agent", (b"User-Agent",
@ -191,6 +200,8 @@ class Toolbox(QObject, Extension):
"packages": QUrl("{base_url}/packages".format(base_url = self._api_url)) "packages": QUrl("{base_url}/packages".format(base_url = self._api_url))
} }
self._application.getCuraAPI().account.loginStateChanged.connect(self._restart)
if CuraApplication.getInstance().getPreferences().getValue("info/automatic_update_check"): if CuraApplication.getInstance().getPreferences().getValue("info/automatic_update_check"):
# Request the latest and greatest! # Request the latest and greatest!
self._fetchPackageData() self._fetchPackageData()
@ -213,9 +224,9 @@ class Toolbox(QObject, Extension):
# Gather installed packages: # Gather installed packages:
self._updateInstalledModels() self._updateInstalledModels()
# Displays the toolbox
@pyqtSlot() @pyqtSlot()
def browsePackages(self) -> None: def launch(self) -> None:
self._fetchPackageData()
if not self._dialog: if not self._dialog:
self._dialog = self._createDialog("Toolbox.qml") self._dialog = self._createDialog("Toolbox.qml")
@ -224,6 +235,8 @@ class Toolbox(QObject, Extension):
Logger.log("e", "Unexpected error trying to create the 'Marketplace' dialog.") Logger.log("e", "Unexpected error trying to create the 'Marketplace' dialog.")
return return
self._restart()
self._dialog.show() self._dialog.show()
# Apply enabled/disabled state to installed plugins # Apply enabled/disabled state to installed plugins
@ -329,7 +342,7 @@ class Toolbox(QObject, Extension):
self._package_used_qualities = package_used_qualities self._package_used_qualities = package_used_qualities
# Ask change to default material / profile # Ask change to default material / profile
if self._confirm_reset_dialog is None: if self._confirm_reset_dialog is None:
self._confirm_reset_dialog = self._createDialog("ToolboxConfirmUninstallResetDialog.qml") self._confirm_reset_dialog = self._createDialog("dialogs/ToolboxConfirmUninstallResetDialog.qml")
self.uninstallVariablesChanged.emit() self.uninstallVariablesChanged.emit()
if self._confirm_reset_dialog is None: if self._confirm_reset_dialog is None:
Logger.log("e", "ToolboxConfirmUninstallResetDialog should have been initialized, but it is not. Not showing dialog and not uninstalling package.") Logger.log("e", "ToolboxConfirmUninstallResetDialog should have been initialized, but it is not. Not showing dialog and not uninstalling package.")

View File

@ -160,7 +160,7 @@ Item
target: Cura.Actions.browsePackages target: Cura.Actions.browsePackages
onTriggered: onTriggered:
{ {
curaExtensions.callExtensionMethod("Toolbox", "browsePackages") curaExtensions.callExtensionMethod("Toolbox", "launch")
} }
} }
} }