Skip to content

Commit

Permalink
Merge pull request #5202 from opengisch/plugins_delete
Browse files Browse the repository at this point in the history
Implement plugin uninstall mechanism + adding a pair of metadata details
  • Loading branch information
nirvn committed Apr 23, 2024
2 parents d2306e8 + f8886b4 commit 3024a71
Show file tree
Hide file tree
Showing 3 changed files with 99 additions and 7 deletions.
28 changes: 27 additions & 1 deletion src/core/pluginmanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,9 @@ void PluginManager::refreshAppPlugins()
QString name = candidate.fileName();
QString description;
QString author;
QString homepage;
QString icon;
QString version;

const QString metadataPath = QStringLiteral( "%1/metadata.txt" ).arg( candidate.absoluteFilePath() );
if ( QFileInfo::exists( metadataPath ) )
Expand All @@ -237,12 +239,23 @@ void PluginManager::refreshAppPlugins()
name = metadata.value( "name", candidate.fileName() ).toString();
description = metadata.value( "description" ).toString();
author = metadata.value( "author" ).toString();
homepage = metadata.value( "homepage" ).toString();
if ( !homepage.isEmpty() )
{
// Only tolerate http(s) URLs
const QUrl url( homepage );
if ( !url.scheme().startsWith( QStringLiteral( "http" ) ) )
{
homepage.clear();
}
}
if ( !metadata.value( "icon" ).toString().isEmpty() )
{
icon = QStringLiteral( "%1/%2" ).arg( candidate.absoluteFilePath(), metadata.value( "icon" ).toString() );
}
version = metadata.value( "version" ).toString();
}
mAvailableAppPlugins.insert( candidate.fileName(), PluginInformation( candidate.fileName(), name, description, author, icon, path ) );
mAvailableAppPlugins.insert( candidate.fileName(), PluginInformation( candidate.fileName(), name, description, author, homepage, icon, version, path ) );
}
}
}
Expand Down Expand Up @@ -408,6 +421,19 @@ void PluginManager::installFromUrl( const QString &url )
} );
}

void PluginManager::uninstall( const QString &uuid )
{
if ( mAvailableAppPlugins.contains( uuid ) )
{
disableAppPlugin( uuid );

QFileInfo fi( mAvailableAppPlugins[uuid].path() );
fi.absoluteDir().removeRecursively();

refreshAppPlugins();
}
}

QString PluginManager::findProjectPlugin( const QString &projectPath )
{
const QFileInfo fi( projectPath );
Expand Down
11 changes: 10 additions & 1 deletion src/core/pluginmanager.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,19 @@ class PluginInformation
Q_PROPERTY( QString name READ name )
Q_PROPERTY( QString description READ description )
Q_PROPERTY( QString author READ author )
Q_PROPERTY( QString homepage READ homepage )
Q_PROPERTY( QString icon READ icon )
Q_PROPERTY( QString version READ version )

public:
PluginInformation( const QString &uuid = QString(), const QString &name = QString(), const QString &description = QString(), const QString &author = QString(), const QString &icon = QString(), const QString &path = QString() )
PluginInformation( const QString &uuid = QString(), const QString &name = QString(), const QString &description = QString(), const QString &author = QString(), const QString &homepage = QString(), const QString &icon = QString(), const QString &version = QString(), const QString &path = QString() )
: mUuid( uuid )
, mName( name )
, mDescription( description )
, mAuthor( author )
, mHomepage( homepage )
, mIcon( icon )
, mVersion( version )
, mPath( path )
{}
~PluginInformation() = default;
Expand All @@ -45,15 +49,19 @@ class PluginInformation
QString name() const { return mName; }
QString description() const { return mDescription; }
QString author() const { return mAuthor; }
QString homepage() const { return mHomepage; }
QString icon() const { return mIcon; }
QString version() const { return mVersion; }
QString path() const { return mPath; }

private:
QString mUuid;
QString mName;
QString mDescription;
QString mAuthor;
QString mHomepage;
QString mIcon;
QString mVersion;
QString mPath;
};

Expand Down Expand Up @@ -89,6 +97,7 @@ class PluginManager : public QObject
void restoreAppPlugins();

Q_INVOKABLE void installFromUrl( const QString &url );
Q_INVOKABLE void uninstall( const QString &uuid );

static QString findProjectPlugin( const QString &projectPath );

Expand Down
67 changes: 62 additions & 5 deletions src/qml/PluginManagerSettings.qml
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,11 @@ Popup {
MouseArea {
anchors.fill: parent
onClicked: {
toggleEnabledPlugin.checked = !toggleEnabledPlugin.checked
toggleEnabledPlugin.clicked()
if (!Enabled) {
pluginManager.enableAppPlugin(Uuid)
} else {
pluginManager.disableAppPlugin(Uuid)
}
}
}
}
Expand All @@ -115,7 +118,7 @@ Popup {

onClicked: {
Enabled = checked == true
if (checked) {
if (Enabled) {
pluginManager.enableAppPlugin(Uuid)
} else {
pluginManager.disableAppPlugin(Uuid)
Expand All @@ -128,10 +131,13 @@ Popup {

Label {
Layout.fillWidth: true
text: qsTr('Authored by %1').arg(Author)
text: (Homepage != ''
? qsTr('Authored by %1%2%3').arg('<a href="' + Homepage + '">').arg(Author).arg('</a>')
: qsTr('Authored by %1').arg(Author)) + (Version != "" ? ' (' + Version + ')' : '')
font: Theme.tipFont
color: Theme.secondaryTextColor
wrapMode: Text.WordWrap
onLinkActivated: Qt.openUrlExternally(link)
}

Label {
Expand All @@ -141,6 +147,20 @@ Popup {
color: Theme.secondaryTextColor
wrapMode: Text.WordWrap
}

Label {
Layout.fillWidth: true
text: "<a href='delete'>" + qsTr("Uninstall this plugin") + "</a>"
font: Theme.tipFont
color: Theme.secondaryTextColor
wrapMode: Text.WordWrap

onLinkActivated: (link) => {
uninstallConfirmation.pluginName = Name
uninstallConfirmation.pluginUuid = Uuid
uninstallConfirmation.open()
}
}
}
}
}
Expand Down Expand Up @@ -216,6 +236,43 @@ Popup {
}
}

Dialog {
id: uninstallConfirmation
title: "Uninstall Plugin"
parent: mainWindow.contentItem
x: ( mainWindow.width - width ) / 2
y: ( mainWindow.height - height - 80 ) / 2

property string pluginName: ""
property string pluginUuid: ""

Column {
width: childrenRect.width
height: childrenRect.height
spacing: 10

TextMetrics {
id: uninstallLabelMetrics
font: uninstallLabel.font
text: uninstallLabel.text
}

Label {
id: uninstallLabel
width: mainWindow.width - 60 < uninstallLabelMetrics.width ? mainWindow.width - 60 : uninstallLabelMetrics.width
text: qsTr("Are you sure you want to uninstall `%1`?").arg(uninstallConfirmation.pluginName)
wrapMode: Text.WordWrap
font: Theme.defaultFont
color: Theme.mainTextColor
}
}

standardButtons: Dialog.Ok | Dialog.Cancel
onAccepted: {
pluginManager.uninstall(pluginUuid)
}
}

Connections {
target: pluginManager

Expand Down Expand Up @@ -265,7 +322,7 @@ Popup {
pluginsList.model.clear()

for (const plugin of pluginManager.availableAppPlugins) {
pluginsList.model.append({"Uuid":plugin.uuid, "Enabled":pluginManager.isAppPluginEnabled(plugin.uuid), "Name":plugin.name, "Description":plugin.description, "Author":plugin.author, "Icon": plugin.icon})
pluginsList.model.append({"Uuid":plugin.uuid, "Enabled":pluginManager.isAppPluginEnabled(plugin.uuid), "Name":plugin.name, "Description":plugin.description, "Author":plugin.author, "Homepage":plugin.homepage, "Icon": plugin.icon, "Version": plugin.version})
}
}

Expand Down

1 comment on commit 3024a71

@qfield-fairy
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.