Skip to content

Commit

Permalink
Add a UX for plugins to register a configuration dialog within the pl…
Browse files Browse the repository at this point in the history
…ugin manager popup
  • Loading branch information
nirvn committed Jan 27, 2025
1 parent 41cc96c commit 4839e6e
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 4 deletions.
19 changes: 18 additions & 1 deletion src/core/pluginmanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -322,11 +322,28 @@ void PluginManager::disableAppPlugin( const QString &uuid )
}
}

void PluginManager::configureAppPlugin( const QString &uuid )
{
callPluginMethod( uuid, QStringLiteral( "configure" ) );
}

bool PluginManager::isAppPluginEnabled( const QString &uuid ) const
{
return mAvailableAppPlugins.contains( uuid ) && mLoadedPlugins.contains( mAvailableAppPlugins[uuid].path() );
}

bool PluginManager::isAppPluginConfigurable( const QString &uuid ) const
{
if ( mAvailableAppPlugins.contains( uuid ) && mLoadedPlugins.contains( mAvailableAppPlugins[uuid].path() ) )
{
const char *normalizedSignature = QMetaObject::normalizedSignature( "configure()" );
const int idx = mLoadedPlugins[mAvailableAppPlugins[uuid].path()]->metaObject()->indexOfSlot( normalizedSignature );
return idx >= 0;
}

return false;
}

void PluginManager::installFromUrl( const QString &url )
{
QString sanitizedUrl = url.trimmed();
Expand Down Expand Up @@ -470,7 +487,7 @@ QString PluginManager::findProjectPlugin( const QString &projectPath )
return QString();
}

void PluginManager::callPluginMethod( const QString &uuid, const QString &methodName )
void PluginManager::callPluginMethod( const QString &uuid, const QString &methodName ) const
{
if ( !mAvailableAppPlugins.contains( uuid ) )
{
Expand Down
5 changes: 4 additions & 1 deletion src/core/pluginmanager.h
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,10 @@ class PluginManager : public QObject

Q_INVOKABLE void enableAppPlugin( const QString &uuid );
Q_INVOKABLE void disableAppPlugin( const QString &uuid );
Q_INVOKABLE void configureAppPlugin( const QString &uuid );

Q_INVOKABLE bool isAppPluginEnabled( const QString &uuid ) const;
Q_INVOKABLE bool isAppPluginConfigurable( const QString &uuid ) const;

void refreshAppPlugins();
void restoreAppPlugins();
Expand All @@ -122,7 +125,7 @@ class PluginManager : public QObject

private slots:
void handleWarnings( const QList<QQmlError> &warnings );
void callPluginMethod( const QString &uuid, const QString &methodName );
void callPluginMethod( const QString &uuid, const QString &methodName ) const;

private:
QQmlEngine *mEngine = nullptr;
Expand Down
22 changes: 20 additions & 2 deletions src/qml/PluginManagerSettings.qml
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ Popup {
anchors.leftMargin: 20
anchors.rightMargin: 20

columns: 2
columns: 3
columnSpacing: 0
rowSpacing: 2

Expand Down Expand Up @@ -117,6 +117,19 @@ Popup {
}
}

QfToolButton {
id: configureEnabledPlugin
Layout.preferredWidth: enabled ? 48 : 0
enabled: Configurable

iconSource: Theme.getThemeVectorIcon("ic_tune_white_24dp")
iconColor: Theme.mainTextColor

onClicked: {
pluginManager.configureAppPlugin(Uuid);
}
}

QfSwitch {
id: toggleEnabledPlugin
Layout.preferredWidth: implicitContentWidth
Expand All @@ -133,6 +146,7 @@ Popup {
}

ColumnLayout {
Layout.columnSpan: 2
Layout.fillWidth: true

Label {
Expand Down Expand Up @@ -370,6 +384,7 @@ Popup {
for (let i = 0; i < pluginsList.model.count; i++) {
if (pluginsList.model.get(i).Uuid === uuid) {
pluginsList.model.get(i).Enabled = true;
pluginsList.model.get(i).Configurable = pluginManager.isAppPluginConfigurable(uuid);
}
}
}
Expand All @@ -378,6 +393,7 @@ Popup {
for (let i = 0; i < pluginsList.model.count; i++) {
if (pluginsList.model.get(i).Uuid === uuid) {
pluginsList.model.get(i).Enabled = false;
pluginsList.model.get(i).Configurable = false;
}
}
}
Expand All @@ -390,9 +406,11 @@ Popup {
function refreshAppPluginsList() {
pluginsList.model.clear();
for (const plugin of pluginManager.availableAppPlugins) {
const isEnabled = pluginManager.isAppPluginEnabled(plugin.uuid);
pluginsList.model.append({
"Uuid": plugin.uuid,
"Enabled": pluginManager.isAppPluginEnabled(plugin.uuid),
"Enabled": isEnabled,
"Configurable": isEnabled && pluginManager.isAppPluginConfigurable(plugin.uuid),
"Name": plugin.name,
"Description": plugin.description,
"Author": plugin.author,
Expand Down

1 comment on commit 4839e6e

@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.