Merge pull request #6961 from Ultimaker/CURA-7090

CURA-7090/Limit incompatible package message to one per time
This commit is contained in:
konskarm 2020-01-14 14:18:39 +01:00 committed by GitHub
commit 9f023eb28e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 59 additions and 23 deletions

View File

@ -74,7 +74,7 @@ UM.Dialog{
} }
Label Label
{ {
text: model.name text: model.display_name
font: UM.Theme.getFont("medium_bold") font: UM.Theme.getFont("medium_bold")
anchors.left: packageIcon.right anchors.left: packageIcon.right
anchors.leftMargin: UM.Theme.getSize("default_margin").width anchors.leftMargin: UM.Theme.getSize("default_margin").width
@ -104,7 +104,7 @@ UM.Dialog{
{ {
width: parent.width width: parent.width
property int lineHeight: 60 property int lineHeight: 60
visible: !model.is_compatible visible: !model.is_compatible && !model.is_dismissed
height: visible ? (lineHeight + UM.Theme.getSize("default_margin").height) : 0 // We only show the incompatible packages here height: visible ? (lineHeight + UM.Theme.getSize("default_margin").height) : 0 // We only show the incompatible packages here
Image Image
{ {
@ -117,7 +117,7 @@ UM.Dialog{
} }
Label Label
{ {
text: model.name text: model.display_name
font: UM.Theme.getFont("medium_bold") font: UM.Theme.getFont("medium_bold")
anchors.left: packageIcon.right anchors.left: packageIcon.right
anchors.leftMargin: UM.Theme.getSize("default_margin").width anchors.leftMargin: UM.Theme.getSize("default_margin").width
@ -125,6 +125,26 @@ UM.Dialog{
color: UM.Theme.getColor("text") color: UM.Theme.getColor("text")
elide: Text.ElideRight elide: Text.ElideRight
} }
UM.TooltipArea
{
width: childrenRect.width;
height: childrenRect.height;
text: catalog.i18nc("@info:tooltip", "Dismisses the package and won't be shown in this dialog anymore")
anchors.right: parent.right
anchors.verticalCenter: packageIcon.verticalCenter
Label
{
text: "(Dismiss)"
font: UM.Theme.getFont("small")
color: UM.Theme.getColor("text")
MouseArea
{
cursorShape: Qt.PointingHandCursor
anchors.fill: parent
onClicked: toolbox.dismissIncompatiblePackage(model.package_id)
}
}
}
} }
} }
} }

View File

@ -4,6 +4,8 @@
from PyQt5.QtCore import Qt from PyQt5.QtCore import Qt
from UM.Qt.ListModel import ListModel from UM.Qt.ListModel import ListModel
from cura import ApplicationMetadata from cura import ApplicationMetadata
from UM.Logger import Logger
from typing import List, Dict, Any
class SubscribedPackagesModel(ListModel): class SubscribedPackagesModel(ListModel):
@ -15,25 +17,27 @@ class SubscribedPackagesModel(ListModel):
self._discrepancies = None self._discrepancies = None
self._sdk_version = ApplicationMetadata.CuraSDKVersion self._sdk_version = ApplicationMetadata.CuraSDKVersion
self.addRoleName(Qt.UserRole + 1, "name") self.addRoleName(Qt.UserRole + 1, "package_id")
self.addRoleName(Qt.UserRole + 2, "icon_url") self.addRoleName(Qt.UserRole + 2, "display_name")
self.addRoleName(Qt.UserRole + 3, "is_compatible") self.addRoleName(Qt.UserRole + 3, "icon_url")
self.addRoleName(Qt.UserRole + 4, "is_compatible")
self.addRoleName(Qt.UserRole + 5, "is_dismissed")
def setMetadata(self, data): def setMetadata(self, data: List[Dict[str, List[Any]]]) -> None:
if self._metadata != data: self._metadata = data
self._metadata = data
def addValue(self, discrepancy): def addDiscrepancies(self, discrepancy: List[str]) -> None:
if self._discrepancies != discrepancy: self._discrepancies = discrepancy
self._discrepancies = discrepancy
def update(self): def initialize(self) -> None:
self._items.clear() self._items.clear()
for item in self._metadata: for item in self._metadata:
if item["package_id"] not in self._discrepancies: if item["package_id"] not in self._discrepancies:
continue continue
package = {"name": item["display_name"], "sdk_versions": item["sdk_versions"]} package = {"package_id": item["package_id"],
"display_name": item["display_name"],
"sdk_versions": item["sdk_versions"],
"is_dismissed": False}
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:
@ -42,7 +46,6 @@ class SubscribedPackagesModel(ListModel):
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
package.update({"icon_url": ""}) package.update({"icon_url": ""})
self._items.append(package) self._items.append(package)
self.setItems(self._items) self.setItems(self._items)
@ -58,4 +61,11 @@ class SubscribedPackagesModel(ListModel):
for item in self._items: for item in self._items:
if item['is_compatible'] == False: if item['is_compatible'] == False:
has_incompatible_items = True has_incompatible_items = True
return has_incompatible_items return has_incompatible_items
# Sets the "is_compatible" to True for the given package, in memory
def dismissPackage(self, package_id: str) -> None:
package = self.find(key="package_id", value=package_id)
if package != -1:
self.setProperty(package, property="is_dismissed", value=True)
Logger.debug("Package {} has been dismissed".format(package_id))

View File

@ -556,6 +556,11 @@ class Toolbox(QObject, Extension):
populated += 1 populated += 1
return populated == len(self._server_response_data.items()) return populated == len(self._server_response_data.items())
@pyqtSlot(str)
def dismissIncompatiblePackage(self, package_id: str):
self._models["subscribed_packages"].dismissPackage(package_id) # sets "is_compatible" to True, in-memory
self._package_manager.dismissPackage(package_id) # adds this package_id as dismissed in the user config file
# Make API Calls # Make API Calls
# -------------------------------------------------------------------------- # --------------------------------------------------------------------------
def _makeRequestByType(self, request_type: str) -> None: def _makeRequestByType(self, request_type: str) -> None:
@ -663,13 +668,15 @@ class Toolbox(QObject, Extension):
def _checkCompatibilities(self, json_data) -> None: 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()
user_dismissed_packages = self._package_manager.getDismissedPackages()
# We check if there are packages installed in Cloud Marketplace but not in Cura marketplace (discrepancy) if user_dismissed_packages:
user_installed_packages += user_dismissed_packages
# We check if there are packages installed in Cloud Marketplace but not in Cura marketplace
package_discrepancy = list(set(user_subscribed_packages).difference(user_installed_packages)) package_discrepancy = list(set(user_subscribed_packages).difference(user_installed_packages))
if package_discrepancy: if package_discrepancy:
self._models["subscribed_packages"].addValue(package_discrepancy) self._models["subscribed_packages"].addDiscrepancies(package_discrepancy)
self._models["subscribed_packages"].update() self._models["subscribed_packages"].initialize()
Logger.log("d", "Discrepancy found between Cloud subscribed packages and Cura installed packages") Logger.debug("Discrepancy found between Cloud subscribed packages and Cura installed packages")
sync_message = Message(i18n_catalog.i18nc( sync_message = Message(i18n_catalog.i18nc(
"@info:generic", "@info:generic",
"\nDo you want to sync material and software packages with your account?"), "\nDo you want to sync material and software packages with your account?"),
@ -680,7 +687,6 @@ class Toolbox(QObject, Extension):
icon="", icon="",
description="Sync your Cloud subscribed packages to your local environment.", description="Sync your Cloud subscribed packages to your local environment.",
button_align=Message.ActionButtonAlignment.ALIGN_RIGHT) button_align=Message.ActionButtonAlignment.ALIGN_RIGHT)
sync_message.actionTriggered.connect(self._onSyncButtonClicked) sync_message.actionTriggered.connect(self._onSyncButtonClicked)
sync_message.show() sync_message.show()