Skip to content

Commit 9f8f86d

Browse files
committed
introduced new plugin metadata entry "category". Show hint based on
category in Plugin Manager and update all core plugins respectively
1 parent 8eecfc3 commit 9f8f86d

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+386
-79
lines changed

python/plugins/GdalTools/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ def name():
2121
return "GdalTools"
2222
def description():
2323
return "Integrate gdal tools into qgis"
24+
def category():
25+
return "Raster"
2426
def version():
2527
return "Version 1.2.29"
2628
def qgisMinimumVersion():

python/plugins/fTools/__init__.py

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -29,23 +29,26 @@
2929
#---------------------------------------------------------------------
3030

3131
def name():
32-
return "fTools"
32+
return "fTools"
3333

3434
def description():
35-
return "Tools for vector data analysis and management"
35+
return "Tools for vector data analysis and management"
36+
37+
def category():
38+
return "Vector"
3639

3740
def version():
38-
return "0.6.1"
39-
41+
return "0.6.1"
42+
4043
def qgisMinimumVersion():
41-
return "1.4"
44+
return "1.4"
4245

4346
def icon():
44-
return "icons/logo_small.png"
45-
47+
return "icons/logo_small.png"
48+
4649
def authorName():
47-
return "Carson J. Q. Farmer"
50+
return "Carson J. Q. Farmer"
4851

4952
def classFactory( iface ):
50-
from fTools import fToolsPlugin
51-
return fToolsPlugin( iface )
53+
from fTools import fToolsPlugin
54+
return fToolsPlugin( iface )

python/plugins/mapserver_export/__init__.py

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,19 +19,21 @@
1919
This script initializes the plugin, making it known to QGIS.
2020
"""
2121

22-
def name():
23-
return "MapServer Export"
22+
def name():
23+
return "MapServer Export"
2424
def description():
2525
return "Export a saved QGIS project file to a MapServer map file"
26-
def version():
27-
return "Version 0.4.3"
28-
def qgisMinimumVersion():
26+
def category():
27+
return "Plugins"
28+
def version():
29+
return "Version 0.4.3"
30+
def qgisMinimumVersion():
2931
return "1.0"
3032
def icon():
3133
return "mapserver_export.png"
3234
def authorName():
3335
return "Gary E. Sherman"
34-
def classFactory(iface):
36+
def classFactory(iface):
3537
# load MapServerExport class from file mapserverexport.py
36-
from mapserverexport import MapServerExport
37-
return MapServerExport(iface)
38+
from mapserverexport import MapServerExport
39+
return MapServerExport(iface)

python/plugins/osm/__init__.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,15 @@ def description():
3333
return "Viewer and editor for OpenStreetMap data"
3434

3535

36+
def category():
37+
"""Function returns category of this plugin.
38+
39+
@return category of this plugin.
40+
"""
41+
42+
return "Plugins"
43+
44+
3645
def version():
3746
"""Function returns version of this plugin.
3847
@@ -64,5 +73,5 @@ def classFactory(iface):
6473

6574
from OsmPlugin import OsmPlugin
6675
# return object of our plugin with reference to QGIS interface as the only argument
67-
return OsmPlugin(iface)
76+
return OsmPlugin(iface)
6877

python/plugins/plugin_installer/__init__.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@ def version():
2020
def description():
2121
return "Downloads and installs QGIS python plugins"
2222

23+
def category():
24+
return "Plugins"
25+
2326
def qgisMinimumVersion():
2427
return "1.0"
2528

src/app/qgspluginitem.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,11 @@ QString QgsPluginItem::description()
3232
return m_description;
3333
}
3434

35+
QString QgsPluginItem::category()
36+
{
37+
return m_category;
38+
}
39+
3540
QString QgsPluginItem::fullPath()
3641
{
3742
return m_fullPath;

src/app/qgspluginitem.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,15 @@ class QgsPluginItem
2828
QgsPluginItem( QString name = 0, QString fullPath = 0, QString type = 0, bool python = false );
2929
QString name();
3030
QString description();
31+
QString category();
3132
QString fullPath();
3233
QString type();
3334
bool isPython();
3435
~QgsPluginItem();
3536
private:
3637
QString m_name;
3738
QString m_description;
39+
QString m_category;
3840
QString m_fullPath;
3941
//! Plugin type (either ui or maplayer)
4042
QString m_type;

src/app/qgspluginmanager.cpp

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,12 +171,19 @@ void QgsPluginManager::getPythonPluginDescriptions()
171171
// get information from the plugin
172172
QString pluginName = mPythonUtils->getPluginMetadata( packageName, "name" );
173173
QString description = mPythonUtils->getPluginMetadata( packageName, "description" );
174+
QString category = mPythonUtils->getPluginMetadata( packageName, "category" );
174175
QString version = mPythonUtils->getPluginMetadata( packageName, "version" );
175176
QString iconName = mPythonUtils->getPluginMetadata( packageName, "icon" );
176177

177178
if ( pluginName == "__error__" || description == "__error__" || version == "__error__" )
178179
continue;
179180

181+
// if there is no category in Python plugin assume default 'Plugins' category
182+
if ( category == "__error__" )
183+
{
184+
category = tr( "Plugins" );
185+
}
186+
180187
bool isCompatible = QgsPluginRegistry::instance()->isPythonPluginCompatible( packageName );
181188
QString compatibleString; // empty by default
182189
if ( !isCompatible )
@@ -196,6 +203,7 @@ void QgsPluginManager::getPythonPluginDescriptions()
196203
myData.setTitle( pluginName + " (" + version + ")" + compatibleString );
197204
myData.setEnabled( isCompatible );
198205
myData.setDetail( description );
206+
myData.setCategory( tr( "Installed in %1 menu/toolbar" ).arg( category ) );
199207
//myData.setIcon(pixmap); //todo use a python logo here
200208
myData.setCheckable( true );
201209
myData.setRenderAsWidget( false );
@@ -308,6 +316,7 @@ void QgsPluginManager::getPluginDescriptions()
308316
// resolve the metadata from plugin
309317
name_t *pName = ( name_t * ) cast_to_fptr( myLib->resolve( "name" ) );
310318
description_t *pDesc = ( description_t * ) cast_to_fptr( myLib->resolve( "description" ) );
319+
category_t *pCat = ( category_t * ) cast_to_fptr( myLib->resolve( "category" ) );
311320
version_t *pVersion = ( version_t * ) cast_to_fptr( myLib->resolve( "version" ) );
312321
icon_t* pIcon = ( icon_t * ) cast_to_fptr( myLib->resolve( "icon" ) );
313322

@@ -328,6 +337,14 @@ void QgsPluginManager::getPluginDescriptions()
328337
{
329338
QgsDebugMsg( "Plugin description not returned when queried" );
330339
}
340+
if ( pCat )
341+
{
342+
QgsDebugMsg( "Plugin category: " + pCat() );
343+
}
344+
else
345+
{
346+
QgsDebugMsg( "Plugin category not returned when queried" );
347+
}
331348
if ( pVersion )
332349
{
333350
QgsDebugMsg( "Plugin version: " + pVersion() );
@@ -350,6 +367,8 @@ void QgsPluginManager::getPluginDescriptions()
350367

351368
QString pluginName = pName();
352369
QString pluginDesc = pDesc();
370+
// if no category defined - use default value
371+
QString pluginCat = ( pCat ? pCat() : tr( "Plugins" ) );
353372
QString pluginVersion = pVersion();
354373
QString pluginIconFileName = ( pIcon ? pIcon() : QString() );
355374
QString baseName = QFileInfo( lib ).baseName();
@@ -363,6 +382,7 @@ void QgsPluginManager::getPluginDescriptions()
363382
QgsDetailedItemData myData;
364383
myData.setTitle( pluginName );
365384
myData.setDetail( pluginDesc );
385+
myData.setCategory( tr( "Installed in %1 menu/toolbar" ).arg( pluginCat ) );
366386
myData.setRenderAsWidget( false );
367387
myData.setCheckable( true );
368388
myData.setChecked( false ); //start unchecked - we will check it later if needed

src/app/qgspluginregistry.cpp

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
typedef QgisPlugin *create_ui( QgisInterface * qI );
3737
typedef QString name_t();
3838
typedef QString description_t();
39+
typedef QString category_t();
3940
typedef int type_t();
4041

4142

@@ -455,12 +456,13 @@ bool QgsPluginRegistry::checkCppPlugin( QString pluginFullPath )
455456

456457
name_t * myName = ( name_t * ) cast_to_fptr( myLib.resolve( "name" ) );
457458
description_t * myDescription = ( description_t * ) cast_to_fptr( myLib.resolve( "description" ) );
459+
category_t * myCategory = ( category_t * ) cast_to_fptr( myLib.resolve( "category" ) );
458460
version_t * myVersion = ( version_t * ) cast_to_fptr( myLib.resolve( "version" ) );
459461

460-
if ( myName && myDescription && myVersion )
462+
if ( myName && myDescription && myVersion && myCategory )
461463
return true;
462464

463-
QgsDebugMsg( "Failed to get name, description, or type for " + myLib.fileName() );
465+
QgsDebugMsg( "Failed to get name, description, category or type for " + myLib.fileName() );
464466
return false;
465467
}
466468

@@ -471,7 +473,7 @@ bool QgsPluginRegistry::checkPythonPlugin( QString packageName )
471473
if ( !mPythonUtils->loadPlugin( packageName ) )
472474
return false;
473475

474-
QString pluginName, description, version;
476+
QString pluginName, description, category, version;
475477

476478
// get information from the plugin
477479
// if there are some problems, don't continue with metadata retreival
@@ -481,6 +483,8 @@ bool QgsPluginRegistry::checkPythonPlugin( QString packageName )
481483
description = mPythonUtils->getPluginMetadata( packageName, "description" );
482484
if ( description != "__error__" )
483485
version = mPythonUtils->getPluginMetadata( packageName, "version" );
486+
// for Python plugins category still optional, by default used "Plugins" category
487+
//category = mPythonUtils->getPluginMetadata( packageName, "category" );
484488
}
485489

486490
if ( pluginName == "__error__" || description == "__error__" || version == "__error__" )

src/gui/qgsdetaileditemdata.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,18 +36,26 @@ void QgsDetailedItemData::setDetail( const QString theDetail )
3636
mDetail = theDetail;
3737
}
3838

39+
void QgsDetailedItemData::setCategory( const QString theCategory )
40+
{
41+
mCategory = theCategory;
42+
}
43+
3944
void QgsDetailedItemData::setIcon( const QPixmap theIcon )
4045
{
4146
mPixmap = theIcon;
4247
}
48+
4349
void QgsDetailedItemData::setCheckable( const bool theFlag )
4450
{
4551
mCheckableFlag = theFlag;
4652
}
53+
4754
void QgsDetailedItemData::setChecked( const bool theFlag )
4855
{
4956
mCheckedFlag = theFlag;
5057
}
58+
5159
void QgsDetailedItemData::setRenderAsWidget( const bool theFlag )
5260
{
5361
mRenderAsWidgetFlag = theFlag;
@@ -63,6 +71,11 @@ QString QgsDetailedItemData::detail() const
6371
return mDetail;
6472
}
6573

74+
QString QgsDetailedItemData::category() const
75+
{
76+
return mCategory;
77+
}
78+
6679
QPixmap QgsDetailedItemData::icon() const
6780
{
6881
return mPixmap;

0 commit comments

Comments
 (0)