Possible to remove plugins

Note that this required adding an `uninstallPlugin()` method to the `PluginRegistry` class of Uranium.
This commit is contained in:
Ian Paschal 2018-01-22 14:25:34 +01:00
parent 628314af9e
commit f27dc4473e
2 changed files with 42 additions and 16 deletions

View file

@ -17,6 +17,7 @@ import os
import tempfile
import platform
import zipfile
import shutil
i18n_catalog = i18nCatalog("cura")
@ -179,10 +180,12 @@ class PluginBrowser(QObject, Extension):
@pyqtSlot(str)
def installPlugin(self, file_path):
# Ensure that it starts with a /, as otherwise it doesn't work on windows.
if not file_path.startswith("/"):
location = "/" + file_path # Ensure that it starts with a /, as otherwise it doesn't work on windows.
location = "/" + file_path
else:
location = file_path
result = PluginRegistry.getInstance().installPlugin("file://" + location)
self._newly_installed_plugin_ids.append(result["id"])
@ -190,6 +193,14 @@ class PluginBrowser(QObject, Extension):
Application.getInstance().messageBox(i18n_catalog.i18nc("@window:title", "Plugin browser"), result["message"])
@pyqtSlot(str)
def removePlugin(self, plugin_id):
result = PluginRegistry.getInstance().uninstallPlugin(plugin_id)
self.pluginsMetadataChanged.emit()
Application.getInstance().messageBox(i18n_catalog.i18nc("@window:title", "Plugin browser"), result["message"])
@pyqtProperty(int, notify = onDownloadProgressChanged)
def downloadProgress(self):
return self._download_progress
@ -226,26 +237,29 @@ class PluginBrowser(QObject, Extension):
if self._plugins_model is None:
self._plugins_model = ListModel()
self._plugins_model.addRoleName(Qt.UserRole + 1, "name")
self._plugins_model.addRoleName(Qt.UserRole + 2, "version")
self._plugins_model.addRoleName(Qt.UserRole + 3, "short_description")
self._plugins_model.addRoleName(Qt.UserRole + 4, "author")
self._plugins_model.addRoleName(Qt.UserRole + 5, "author_email")
self._plugins_model.addRoleName(Qt.UserRole + 6, "already_installed")
self._plugins_model.addRoleName(Qt.UserRole + 7, "file_location")
self._plugins_model.addRoleName(Qt.UserRole + 8, "enabled")
self._plugins_model.addRoleName(Qt.UserRole + 9, "can_upgrade")
self._plugins_model.addRoleName(Qt.UserRole + 2, "id")
self._plugins_model.addRoleName(Qt.UserRole + 3, "version")
self._plugins_model.addRoleName(Qt.UserRole + 4, "short_description")
self._plugins_model.addRoleName(Qt.UserRole + 5, "author")
self._plugins_model.addRoleName(Qt.UserRole + 6, "author_email")
self._plugins_model.addRoleName(Qt.UserRole + 7, "already_installed")
self._plugins_model.addRoleName(Qt.UserRole + 8, "file_location")
self._plugins_model.addRoleName(Qt.UserRole + 9, "enabled")
self._plugins_model.addRoleName(Qt.UserRole + 10, "can_upgrade")
else:
self._plugins_model.clear()
items = []
for metadata in self._plugins_metadata:
items.append({
"name": metadata["label"],
"id": metadata["id"],
"version": metadata["version"],
"short_description": metadata["short_description"],
"author": metadata["author"],
"author_email": "author@gmail.com",
"already_installed": self._checkAlreadyInstalled(metadata["id"]),
"file_location": metadata["file_location"],
# "enabled": self._checkEnabled(metadata["id"]),
"enabled": True,
"can_upgrade": self._checkCanUpgrade(metadata["id"], metadata["version"])
})
@ -274,6 +288,18 @@ class PluginBrowser(QObject, Extension):
return True # We already installed this plugin, but the registry just doesn't know it yet.
return False
def _checkEnabled(self, id):
plugin_registry = PluginRegistry.getInstance()
metadata = plugin_registry.getMetaData(id)
# if metadata != {}:
# if id in self._newly_installed_plugin_ids:
# return False # We already updated this plugin.
# current_version = Version(metadata["plugin"]["version"])
# new_version = Version(version)
# if new_version > current_version:
# return True
return False
def _onRequestFinished(self, reply):
reply_url = reply.url().toString()
if reply.error() == QNetworkReply.TimeoutError:

View file

@ -154,7 +154,7 @@ UM.Dialog {
// Plugin actions
Row {
id: pluginActions
width: 72 + UM.Theme.getSize("default_margin").width
width: 180 + UM.Theme.getSize("default_margin").width
height: parent.height
anchors {
top: parent.top
@ -165,7 +165,6 @@ UM.Dialog {
layoutDirection: Qt.RightToLeft
spacing: UM.Theme.getSize("default_margin").width
/*
Rectangle {
id: removeControls
visible: model.already_installed
@ -182,12 +181,14 @@ UM.Dialog {
return true;
}
}
onClicked: {
manager.removePlugin(model.id);
}
style: ButtonStyle {
background: Rectangle {
color: white
implicitWidth: 108
implicitHeight: 30
// radius: 4
border {
width: 1
color: "grey"
@ -224,7 +225,6 @@ UM.Dialog {
color: "transparent"
implicitWidth: 30
implicitHeight: 30
// radius: 4
}
label: Text {
verticalAlignment: Text.AlignVCenter
@ -246,10 +246,9 @@ UM.Dialog {
else {
removeDropDown.open = false
}
}
}
}
Rectangle {
id: divider
width: 1
@ -257,6 +256,7 @@ UM.Dialog {
anchors.right: removeDropDown.left
color: "grey"
}
Column {
id: options
anchors {
@ -278,7 +278,7 @@ UM.Dialog {
}
}
}
*/
Button {
id: updateButton
visible: model.already_installed && model.can_upgrade