Skip to content

Commit 33cf659

Browse files
committed
Allow for an app-wide plugin ZIP to include the plugin directory within the archive itself
1 parent 9b16480 commit 33cf659

File tree

2 files changed

+19
-4
lines changed

2 files changed

+19
-4
lines changed

src/core/pluginmanager.cpp

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -400,26 +400,41 @@ void PluginManager::installFromUrl( const QString &url )
400400
file.write( data );
401401
file.close();
402402

403+
bool pluginDirectoryWithinZip = false;
404+
QString pluginDirectoryName;
403405
QStringList zipFiles = QgsZipUtils::files( filePath );
404-
if ( zipFiles.contains( QStringLiteral( "main.qml" ) ) )
406+
if ( zipFiles.at( 0 ).indexOf( '/' ) >= 0 )
407+
{
408+
pluginDirectoryName = zipFiles.at( 0 ).mid( 0, zipFiles.at( 0 ).indexOf( '/' ) );
409+
pluginDirectoryWithinZip = true;
410+
}
411+
if ( zipFiles.contains( QStringLiteral( "%1main.qml" ).arg( !pluginDirectoryName.isEmpty() ? pluginDirectoryName + "/" : QString() ) ) )
405412
{
406413
// Insure no previous version is running
407414
disableAppPlugin( fileInfo.completeBaseName() );
408415

409416
// Remove the .zip suffix as well as version information (e.g. myplugin-v1.0.zip becomes myplugin)
410-
const QString pluginDirectoryName = fileName.replace( QRegularExpression( "(-v?\\d+(\\.\\d+)*)?.zIP$", QRegularExpression::CaseInsensitiveOption ), QString() );
417+
if ( !pluginDirectoryWithinZip )
418+
{
419+
pluginDirectoryName = fileName.replace( QRegularExpression( "(-v?\\d+(\\.\\d+)*)?.zIP$", QRegularExpression::CaseInsensitiveOption ), QString() );
420+
}
421+
411422
QDir pluginDirectory = QStringLiteral( "%1/plugins/%2" ).arg( dataDir, pluginDirectoryName );
412423
if ( pluginDirectory.exists() )
413424
{
414425
pluginDirectory.removeRecursively();
415426
}
416427
pluginDirectory.mkpath( "." );
428+
if ( pluginDirectoryWithinZip )
429+
{
430+
pluginDirectory.cdUp();
431+
}
417432
if ( QgsZipUtils::unzip( filePath, pluginDirectory.absolutePath(), zipFiles, false ) )
418433
{
419434
file.remove();
420435

421436
refreshAppPlugins();
422-
emit installEnded( pluginDirectory.dirName() );
437+
emit installEnded( pluginDirectoryName );
423438

424439
return;
425440
}

src/qml/PluginManagerSettings.qml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ Popup {
7171

7272
delegate: Rectangle {
7373
id: rectangle
74-
width: parent.width
74+
width: parent ? parent.width : 10
7575
height: inner.height + 10
7676
color: "transparent"
7777

0 commit comments

Comments
 (0)