Reworked the Compatibility Dialog and how it shows the subscribed packages

CURA-7038
This commit is contained in:
Dimitriovski 2019-12-30 17:36:46 +01:00
parent 8c0f64633b
commit ada2a776d5
No known key found for this signature in database
GPG Key ID: 4E62757E2B0D304D
2 changed files with 128 additions and 57 deletions

View File

@ -1,13 +1,9 @@
// Copyright (c) 2018 Ultimaker B.V. // Copyright (c) 2020 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.
import QtQuick 2.10 import QtQuick 2.10
import QtQuick.Dialogs 1.1
import QtQuick.Window 2.2 import QtQuick.Window 2.2
import QtQuick.Controls 1.4 import QtQuick.Controls 2.3
import QtQuick.Controls.Styles 1.4
// TODO: Switch to QtQuick.Controls 2.x and remove QtQuick.Controls.Styles
import UM 1.1 as UM import UM 1.1 as UM
import Cura 1.6 as Cura import Cura 1.6 as Cura
@ -15,61 +11,136 @@ import Cura 1.6 as Cura
UM.Dialog{ UM.Dialog{
visible: true visible: true
title: "Changes from your account" title: catalog.i18nc("@title", "Changes from your account")
Label{ width: UM.Theme.getSize("popup_dialog").width
text: "Some text here" height: UM.Theme.getSize("popup_dialog").height
height: 50 minimumWidth: width
} maximumWidth: minimumWidth
Rectangle minimumHeight: height
{ maximumHeight: minimumHeight
id: compatibleRectangle margin: 0
width: parent.width
height: 300
Label{
text: "Some text here"
height: 50
}
Rectangle
{
// Compatible packages id: root
Column{
id: compatibleColumn
anchors.fill: parent anchors.fill: parent
spacing: 2 color: UM.Theme.getColor("main_background")
Repeater{ UM.I18nCatalog
model: toolbox.subscribedPackagesModel {
delegate: Rectangle{ id: catalog
id: someRect name: "cura"
width: parent.width }
height: 50
border.color: "black" ScrollView
Image{ {
source: model.icon_url || "../../images/logobot.svg" width: parent.width
width: 50 height: parent.height - nextButton.height - nextButton.anchors.margins * 2 // We want some leftover space for the button at the bottom
height: parent.height clip: true
//anchors.left: parent.left
//anchors.right: packageName.left Column
anchors.rightMargin: 20 {
anchors.fill: parent
anchors.margins: UM.Theme.getSize("default_margin").width
// Compatible packages
Label
{
font: UM.Theme.getFont("default")
text: catalog.i18nc("@label", "The following packages will be added:")
color: UM.Theme.getColor("text")
height: contentHeight + UM.Theme.getSize("default_margin").height
} }
Text{ Repeater
id: packageName {
text: model.name + " (Compatible: " + model.is_compatible + ")" model: toolbox.subscribedPackagesModel
anchors.centerIn: parent Component
} {
MouseArea{ id: compatibleDelegate
anchors.fill: parent Item
onClicked: { {
console.log("Clicked!") width: parent.width
property var lineHeight: 60
visible: model.is_compatible == "True" ? true : false
height: visible ? (lineHeight + UM.Theme.getSize("default_margin").height) : 0 // We only show the compatible packages here
Image
{
id: packageIcon
source: model.icon_url || "../../images/logobot.svg"
height: lineHeight
width: height
mipmap: true
fillMode: Image.PreserveAspectFit
}
Label
{
id: compatibleLabel
text: model.name
font: UM.Theme.getFont("medium_bold")
anchors.left: packageIcon.right
anchors.leftMargin: 20
anchors.verticalCenter: packageIcon.verticalCenter
color: UM.Theme.getColor("text")
elide: Text.ElideRight
}
}
} }
} }
// Incompatible packages
Label
{
font: UM.Theme.getFont("default")
text: catalog.i18nc("@label", "The following packages can not be installed because of incompatible Cura version:")
color: UM.Theme.getColor("text")
height: contentHeight + UM.Theme.getSize("default_margin").height
}
Repeater
{
model: toolbox.subscribedPackagesModel
Component
{
id: incompatibleDelegate
Item
{
width: parent.width
property var lineHeight: 60
visible: model.is_compatible == "True" ? false : true
height: visible ? (lineHeight + UM.Theme.getSize("default_margin").height) : 0 // We only show the incompatible packages here
Image
{
id: packageIcon
source: model.icon_url || "../../images/logobot.svg"
height: lineHeight
width: height
mipmap: true
fillMode: Image.PreserveAspectFit
}
Label
{
id: incompatibleLabel
text: model.name
font: UM.Theme.getFont("medium_bold")
anchors.left: packageIcon.right
anchors.leftMargin: 20
anchors.verticalCenter: packageIcon.verticalCenter
color: UM.Theme.getColor("text")
elide: Text.ElideRight
}
}
}
}
} }
} // End of ScrollView
Cura.ActionButton
{
id: nextButton
anchors.bottom: parent.bottom
anchors.right: parent.right
anchors.margins: UM.Theme.getSize("default_margin").height
text: catalog.i18nc("@button", "Next")
} }
} }
} }
}

View File

@ -701,7 +701,7 @@ class Toolbox(QObject, Extension):
# Ignore any operation that is not a get operation # Ignore any operation that is not a get operation
pass pass
def _checkCompatibilities(self, json_data): def _checkCompatibilities(self, json_data) -> None:
user_subscribed_packages = [plugin["package_id"] for plugin in json_data] user_subscribed_packages = [plugin["package_id"] for plugin in json_data]
user_installed_packages = self._package_manager.getUserInstalledPackages() user_installed_packages = self._package_manager.getUserInstalledPackages()
@ -725,16 +725,16 @@ class Toolbox(QObject, Extension):
sync_message.show() sync_message.show()
def _onSyncButtonClicked(self, json_data, package_discrepancy, messageId: str, actionId: str) -> None: def _onSyncButtonClicked(self, json_data, package_discrepancy, messageId: str, actionId: str) -> None:
# self.subscribed_packages.clear() self.subscribed_packages.clear()
# We 'create' the packages from the HTTP payload # We 'create' the packages from the HTTP payload
for item in json_data: for item in json_data:
if item["package_id"] not in package_discrepancy: # But we skip packages that the user has locally installed if item["package_id"] not in package_discrepancy: # But we skip packages that the user has locally installed
continue continue
package = {"name": item["package_id"], "sdk_versions": item["sdk_versions"]} package = {"name": item["package_id"], "sdk_versions": item["sdk_versions"]}
if self._sdk_version not in item["sdk_versions"]: if self._sdk_version not in item["sdk_versions"]:
package.update({"is_compatible": False}) package.update({"is_compatible": "False"})
else: else:
package.update({"is_compatible": True}) package.update({"is_compatible": "True"})
try: try:
package.update({"icon_url": item["icon_url"]}) package.update({"icon_url": item["icon_url"]})
except KeyError: # There is no 'icon_url" in the response payload for this package except KeyError: # There is no 'icon_url" in the response payload for this package