Browse Source

Added uninstall functionality

Get it in a sharable state

Contributes to: CURA-8587
Jelle Spijker 3 years ago
parent
commit
00acfe9d72
2 changed files with 26 additions and 3 deletions
  1. 0 1
      cura/CuraPackageManager.py
  2. 26 2
      plugins/Marketplace/PackageList.py

+ 0 - 1
cura/CuraPackageManager.py

@@ -69,7 +69,6 @@ class CuraPackageManager(PackageManager):
     def iterateAllLocalPackages(self) -> Generator[Dict[str, Any], None, None]:
         """ A generator which returns an unordered list of all the PackageModels"""
 
-        # Get all the installed packages, add a section_title depending on package_type and user installed
         for packages in self.getAllInstalledPackagesInfo().values():
             for package_info in packages:
                 yield package_info

+ 26 - 2
plugins/Marketplace/PackageList.py

@@ -12,6 +12,8 @@ from UM.TaskManagement.HttpRequestManager import HttpRequestData , HttpRequestMa
 from UM.Logger import Logger
 
 from cura.CuraApplication import CuraApplication
+from cura.API.Account import Account
+from cura import CuraPackageManager
 from cura.UltimakerCloud.UltimakerCloudScope import UltimakerCloudScope  # To make requests to the Ultimaker API with correct authorization.
 
 from .PackageModel import PackageModel
@@ -31,7 +33,8 @@ class PackageList(ListModel):
 
     def __init__(self, parent: Optional["QObject"] = None) -> None:
         super().__init__(parent)
-        self._manager = CuraApplication.getInstance().getPackageManager()
+        self._manager: CuraPackageManager = CuraApplication.getInstance().getPackageManager()
+        self._account: Account = CuraApplication.getInstance().getCuraAPI().account
         self._error_message = ""
         self.addRoleName(self.PackageRole, "package")
         self._is_loading = False
@@ -126,7 +129,7 @@ class PackageList(ListModel):
         def downloadFinished(reply: "QNetworkReply") -> None:
             self._downloadFinished(package_id, reply, update)
 
-        HttpRequestManager.getInstance().get(
+        self._ongoing_request = HttpRequestManager.getInstance().get(
             url,
             scope = self._scope,
             callback = downloadFinished
@@ -165,13 +168,34 @@ class PackageList(ListModel):
             package.setIsUpdating(False)
         else:
             package.setIsInstalling(False)
+        #self._subscribe(package_id)
+
+    def _subscribe(self, package_id: str) -> None:
+        if self._account.isLoggedIn:
+            Logger.debug(f"Subscribing the user for package: {package_id}")
+            self._ongoing_request = HttpRequestManager.getInstance().put(
+                url = "",
+                data = {},
+                scope = self._scope
+            )
 
     @pyqtSlot(str)
     def uninstallPackage(self, package_id):
         Logger.debug(f"Uninstalling {package_id}")
+        package = self._getPackageModel(package_id)
+        self._manager.removePackage(package_id)
+        package.setIsInstalling(False)
+        package.setManageInstallState(False)
+        #self._unsunscribe(package_id)
+
+    def _unsunscribe(self, package_id: str) -> None:
+        if self._account.isLoggedIn:
+            Logger.debug(f"Unsubscribing the user for package: {package_id}")
+            self._ongoing_request = HttpRequestManager.getInstance().delete(url = "", scope = self._scope)
 
     @pyqtSlot(str)
     def updatePackage(self, package_id):
+        self._manager.removePackage(package_id, force_add = True)
         package = self._getPackageModel(package_id)
         url = package.download_url
         Logger.debug(f"Trying to download and update {package_id} from {url}")