Skip to content

Commit 58605dc

Browse files
author
wonder
committed
added button in plugin manager for opening plugin installer (if present).
git-svn-id: http://svn.osgeo.org/qgis/trunk@10431 c8812cc2-4d05-0410-92ff-de0c093fc19c
1 parent 60b6bd6 commit 58605dc

File tree

3 files changed

+63
-1
lines changed

3 files changed

+63
-1
lines changed

src/app/qgspluginmanager.cpp

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,16 @@ QgsPluginManager::QgsPluginManager( QgsPythonUtils* pythonUtils, QWidget * paren
9393
connect( btnClearAll, SIGNAL( clicked() ), this, SLOT( clearAll() ) );
9494

9595
qRegisterMetaType<QgsDetailedItemData>();
96+
97+
// check for plugin installer
98+
if (checkForPluginInstaller())
99+
{
100+
connect( btnPluginInstaller, SIGNAL( clicked() ), this, SLOT( showPluginInstaller() ));
101+
}
102+
else
103+
{
104+
btnPluginInstaller->setEnabled(false);
105+
}
96106
}
97107

98108

@@ -500,3 +510,43 @@ void QgsPluginManager::on_leFilter_textChanged( QString theText )
500510
QRegExp myRegExp( theText, myCaseSensitivity, mySyntax );
501511
mModelProxy->setFilterRegExp( myRegExp );
502512
}
513+
514+
bool QgsPluginManager::checkForPluginInstaller()
515+
{
516+
// check whether python's enabled
517+
if (!mPythonUtils)
518+
return false;
519+
520+
// check whether python installer is present
521+
if (!mPythonUtils->pluginList().contains("plugin_installer"))
522+
return false;
523+
524+
QString res;
525+
// check it's loaded and started
526+
bool retval = mPythonUtils->evalString("plugins.has_key('plugin_installer')", res);
527+
if (!retval || res != "True")
528+
{
529+
// TODO: try to load the plugin installer!
530+
return false;
531+
}
532+
533+
return true;
534+
}
535+
536+
void QgsPluginManager::showPluginInstaller()
537+
{
538+
bool res;
539+
QString cls, msg;
540+
res = mPythonUtils->runStringUnsafe("_qgis_plugin_manager = wrapinstance( " + QString::number((unsigned long)this) + ", QtGui.QWidget )");
541+
if (!res)
542+
{
543+
QgsDebugMsg("wrapinstance error: " + cls + " :: " + msg);
544+
}
545+
res = mPythonUtils->runStringUnsafe("plugins['plugin_installer'].run( _qgis_plugin_manager )");
546+
if (!res)
547+
{
548+
mPythonUtils->getError(cls, msg);
549+
QMessageBox::warning(this, tr("Error"), tr("Failed to open plugin installer!"));
550+
mPythonUtils->runStringUnsafe("del _qgis_plugin_manager");
551+
}
552+
}

src/app/qgspluginmanager.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,8 @@ class QgsPluginManager : public QDialog, private Ui::QgsPluginManagerBase
5656
void resizeColumnsToContents();
5757
//! Sort model by column ascending
5858
void sortModel( int );
59+
//! Check whether plugin installer is available (and tries to load it if it's disabled)
60+
bool checkForPluginInstaller();
5961
public slots:
6062
//! Enable disable checkbox
6163
void on_vwPlugins_clicked( const QModelIndex & );
@@ -67,6 +69,8 @@ class QgsPluginManager : public QDialog, private Ui::QgsPluginManagerBase
6769
void clearAll();
6870
//! Update the filter when user changes the filter expression
6971
void on_leFilter_textChanged( QString theText );
72+
//! Show the plugin installer
73+
void showPluginInstaller();
7074
private:
7175
QStandardItemModel *mModelPlugins;
7276
QSortFilterProxyModel * mModelProxy;

src/ui/qgspluginmanagerbase.ui

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,14 @@
7878
</property>
7979
</widget>
8080
</item>
81-
<item row="4" column="0" colspan="3" >
81+
<item row="4" column="0" colspan="2" >
82+
<widget class="QPushButton" name="btnPluginInstaller" >
83+
<property name="text" >
84+
<string>Plugin Installer</string>
85+
</property>
86+
</widget>
87+
</item>
88+
<item row="4" column="2" >
8289
<widget class="QDialogButtonBox" name="buttonBox" >
8390
<property name="standardButtons" >
8491
<set>QDialogButtonBox::Cancel|QDialogButtonBox::NoButton|QDialogButtonBox::Ok</set>
@@ -91,6 +98,7 @@
9198
<tabstops>
9299
<tabstop>vwPlugins</tabstop>
93100
<tabstop>leFilter</tabstop>
101+
<tabstop>btnPluginInstaller</tabstop>
94102
<tabstop>buttonBox</tabstop>
95103
</tabstops>
96104
<resources/>

0 commit comments

Comments
 (0)