Show welcome page in marketplace window when not logged in

TODO: marketplace logo

CURA-6569
This commit is contained in:
Nino van Hooff 2019-11-04 15:44:04 +01:00
parent ad85e29c0a
commit 3d352b3585
4 changed files with 82 additions and 5 deletions

View file

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

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,
# 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

View file

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