mirror of
https://github.com/Ultimaker/Cura.git
synced 2025-07-11 08:47:50 -06:00
Possible to remove plugins
Note that this required adding an `uninstallPlugin()` method to the `PluginRegistry` class of Uranium.
This commit is contained in:
parent
628314af9e
commit
f27dc4473e
2 changed files with 42 additions and 16 deletions
|
@ -17,6 +17,7 @@ import os
|
||||||
import tempfile
|
import tempfile
|
||||||
import platform
|
import platform
|
||||||
import zipfile
|
import zipfile
|
||||||
|
import shutil
|
||||||
|
|
||||||
i18n_catalog = i18nCatalog("cura")
|
i18n_catalog = i18nCatalog("cura")
|
||||||
|
|
||||||
|
@ -179,10 +180,12 @@ class PluginBrowser(QObject, Extension):
|
||||||
|
|
||||||
@pyqtSlot(str)
|
@pyqtSlot(str)
|
||||||
def installPlugin(self, file_path):
|
def installPlugin(self, file_path):
|
||||||
|
# Ensure that it starts with a /, as otherwise it doesn't work on windows.
|
||||||
if not file_path.startswith("/"):
|
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:
|
else:
|
||||||
location = file_path
|
location = file_path
|
||||||
|
|
||||||
result = PluginRegistry.getInstance().installPlugin("file://" + location)
|
result = PluginRegistry.getInstance().installPlugin("file://" + location)
|
||||||
|
|
||||||
self._newly_installed_plugin_ids.append(result["id"])
|
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"])
|
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)
|
@pyqtProperty(int, notify = onDownloadProgressChanged)
|
||||||
def downloadProgress(self):
|
def downloadProgress(self):
|
||||||
return self._download_progress
|
return self._download_progress
|
||||||
|
@ -226,26 +237,29 @@ class PluginBrowser(QObject, Extension):
|
||||||
if self._plugins_model is None:
|
if self._plugins_model is None:
|
||||||
self._plugins_model = ListModel()
|
self._plugins_model = ListModel()
|
||||||
self._plugins_model.addRoleName(Qt.UserRole + 1, "name")
|
self._plugins_model.addRoleName(Qt.UserRole + 1, "name")
|
||||||
self._plugins_model.addRoleName(Qt.UserRole + 2, "version")
|
self._plugins_model.addRoleName(Qt.UserRole + 2, "id")
|
||||||
self._plugins_model.addRoleName(Qt.UserRole + 3, "short_description")
|
self._plugins_model.addRoleName(Qt.UserRole + 3, "version")
|
||||||
self._plugins_model.addRoleName(Qt.UserRole + 4, "author")
|
self._plugins_model.addRoleName(Qt.UserRole + 4, "short_description")
|
||||||
self._plugins_model.addRoleName(Qt.UserRole + 5, "author_email")
|
self._plugins_model.addRoleName(Qt.UserRole + 5, "author")
|
||||||
self._plugins_model.addRoleName(Qt.UserRole + 6, "already_installed")
|
self._plugins_model.addRoleName(Qt.UserRole + 6, "author_email")
|
||||||
self._plugins_model.addRoleName(Qt.UserRole + 7, "file_location")
|
self._plugins_model.addRoleName(Qt.UserRole + 7, "already_installed")
|
||||||
self._plugins_model.addRoleName(Qt.UserRole + 8, "enabled")
|
self._plugins_model.addRoleName(Qt.UserRole + 8, "file_location")
|
||||||
self._plugins_model.addRoleName(Qt.UserRole + 9, "can_upgrade")
|
self._plugins_model.addRoleName(Qt.UserRole + 9, "enabled")
|
||||||
|
self._plugins_model.addRoleName(Qt.UserRole + 10, "can_upgrade")
|
||||||
else:
|
else:
|
||||||
self._plugins_model.clear()
|
self._plugins_model.clear()
|
||||||
items = []
|
items = []
|
||||||
for metadata in self._plugins_metadata:
|
for metadata in self._plugins_metadata:
|
||||||
items.append({
|
items.append({
|
||||||
"name": metadata["label"],
|
"name": metadata["label"],
|
||||||
|
"id": metadata["id"],
|
||||||
"version": metadata["version"],
|
"version": metadata["version"],
|
||||||
"short_description": metadata["short_description"],
|
"short_description": metadata["short_description"],
|
||||||
"author": metadata["author"],
|
"author": metadata["author"],
|
||||||
"author_email": "author@gmail.com",
|
"author_email": "author@gmail.com",
|
||||||
"already_installed": self._checkAlreadyInstalled(metadata["id"]),
|
"already_installed": self._checkAlreadyInstalled(metadata["id"]),
|
||||||
"file_location": metadata["file_location"],
|
"file_location": metadata["file_location"],
|
||||||
|
# "enabled": self._checkEnabled(metadata["id"]),
|
||||||
"enabled": True,
|
"enabled": True,
|
||||||
"can_upgrade": self._checkCanUpgrade(metadata["id"], metadata["version"])
|
"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 True # We already installed this plugin, but the registry just doesn't know it yet.
|
||||||
return False
|
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):
|
def _onRequestFinished(self, reply):
|
||||||
reply_url = reply.url().toString()
|
reply_url = reply.url().toString()
|
||||||
if reply.error() == QNetworkReply.TimeoutError:
|
if reply.error() == QNetworkReply.TimeoutError:
|
||||||
|
|
|
@ -154,7 +154,7 @@ UM.Dialog {
|
||||||
// Plugin actions
|
// Plugin actions
|
||||||
Row {
|
Row {
|
||||||
id: pluginActions
|
id: pluginActions
|
||||||
width: 72 + UM.Theme.getSize("default_margin").width
|
width: 180 + UM.Theme.getSize("default_margin").width
|
||||||
height: parent.height
|
height: parent.height
|
||||||
anchors {
|
anchors {
|
||||||
top: parent.top
|
top: parent.top
|
||||||
|
@ -165,7 +165,6 @@ UM.Dialog {
|
||||||
layoutDirection: Qt.RightToLeft
|
layoutDirection: Qt.RightToLeft
|
||||||
spacing: UM.Theme.getSize("default_margin").width
|
spacing: UM.Theme.getSize("default_margin").width
|
||||||
|
|
||||||
/*
|
|
||||||
Rectangle {
|
Rectangle {
|
||||||
id: removeControls
|
id: removeControls
|
||||||
visible: model.already_installed
|
visible: model.already_installed
|
||||||
|
@ -182,12 +181,14 @@ UM.Dialog {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
onClicked: {
|
||||||
|
manager.removePlugin(model.id);
|
||||||
|
}
|
||||||
style: ButtonStyle {
|
style: ButtonStyle {
|
||||||
background: Rectangle {
|
background: Rectangle {
|
||||||
color: white
|
color: white
|
||||||
implicitWidth: 108
|
implicitWidth: 108
|
||||||
implicitHeight: 30
|
implicitHeight: 30
|
||||||
// radius: 4
|
|
||||||
border {
|
border {
|
||||||
width: 1
|
width: 1
|
||||||
color: "grey"
|
color: "grey"
|
||||||
|
@ -224,7 +225,6 @@ UM.Dialog {
|
||||||
color: "transparent"
|
color: "transparent"
|
||||||
implicitWidth: 30
|
implicitWidth: 30
|
||||||
implicitHeight: 30
|
implicitHeight: 30
|
||||||
// radius: 4
|
|
||||||
}
|
}
|
||||||
label: Text {
|
label: Text {
|
||||||
verticalAlignment: Text.AlignVCenter
|
verticalAlignment: Text.AlignVCenter
|
||||||
|
@ -246,10 +246,9 @@ UM.Dialog {
|
||||||
else {
|
else {
|
||||||
removeDropDown.open = false
|
removeDropDown.open = false
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
|
||||||
Rectangle {
|
Rectangle {
|
||||||
id: divider
|
id: divider
|
||||||
width: 1
|
width: 1
|
||||||
|
@ -257,6 +256,7 @@ UM.Dialog {
|
||||||
anchors.right: removeDropDown.left
|
anchors.right: removeDropDown.left
|
||||||
color: "grey"
|
color: "grey"
|
||||||
}
|
}
|
||||||
|
|
||||||
Column {
|
Column {
|
||||||
id: options
|
id: options
|
||||||
anchors {
|
anchors {
|
||||||
|
@ -278,7 +278,7 @@ UM.Dialog {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
*/
|
|
||||||
Button {
|
Button {
|
||||||
id: updateButton
|
id: updateButton
|
||||||
visible: model.already_installed && model.can_upgrade
|
visible: model.already_installed && model.can_upgrade
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue