Skip to content
Permalink
Browse files

[PluginManager] Filter by repository under rightclick on the repo lis…

…t (only active if > 1 repo configured)
  • Loading branch information
borysiasty committed Jun 9, 2013
1 parent 6caa8bc commit 1d2117f9d66bd885a3fdd388f419ca029266688d
@@ -99,6 +99,7 @@ def fetchAvailablePlugins(self, reloadMode):

if reloadMode:
repositories.load()
plugins.clearRepoCache()
plugins.getAllInstalled()

for key in repositories.allEnabled():
@@ -164,13 +165,18 @@ def exportRepositoriesToManager(self):
v=str(QGis.QGIS_VERSION_INT)
url += "?qgis=%d.%d" % ( int(v[0]), int(v[1:3]) )
repository = repositories.all()[key]
if repositories.inspectionFilter():
enabled = ( key == repositories.inspectionFilter() )
else:
enabled = repositories.all()[key]["enabled"]
iface.pluginManagerInterface().addToRepositoryList({
"name" : key,
"url" : url,
"enabled" : repositories.all()[key]["enabled"] and "true" or "false",
"enabled" : enabled and "true" or "false",
"valid" : repositories.all()[key]["valid"] and "true" or "false",
"state" : str(repositories.all()[key]["state"]),
"error" : repositories.all()[key]["error"]
"error" : repositories.all()[key]["error"],
"inspection_filter" : repositories.inspectionFilter() and "true" or "false"
})


@@ -478,3 +484,10 @@ def deleteRepository(self, reposName):
repositories.remove(reposName)
plugins.removeRepository(reposName)
self.reloadAndExportData()


# ----------------------------------------- #
def setRepositoryInspectionFilter(self, reposName = None):
""" temporarily block another repositories to fetch only one for inspection """
repositories.setInspectionFilter(reposName)
self.reloadAndExportData()
@@ -232,6 +232,7 @@ def __init__(self):
QObject.__init__(self)
self.mRepositories = {}
self.httpId = {} # {httpId : repoName}
self.mInspectionFilter = None


# ----------------------------------------- #
@@ -243,6 +244,9 @@ def all(self):
# ----------------------------------------- #
def allEnabled(self):
""" return dict of all enabled and valid repositories """
if self.mInspectionFilter:
return { self.mInspectionFilter: self.mRepositories[self.mInspectionFilter] }

repos = {}
for i in self.mRepositories:
if self.mRepositories[i]["enabled"] and self.mRepositories[i]["valid"]:
@@ -254,6 +258,13 @@ def allEnabled(self):
def allUnavailable(self):
""" return dict of all unavailable repositories """
repos = {}

if self.mInspectionFilter:
# return the inspected repo if unavailable, otherwise empty dict
if self.mRepositories[self.mInspectionFilter]["state"] == 3:
repos [self.mInspectionFilter] = self.mRepositories[self.mInspectionFilter]
return repos

for i in self.mRepositories:
if self.mRepositories[i]["enabled"] and self.mRepositories[i]["valid"] and self.mRepositories[i]["state"] == 3:
repos[i] = self.mRepositories[i]
@@ -479,6 +490,18 @@ def xmlDownloaded(self,nr,state):
if not self.fetchingInProgress():
self.checkingDone.emit()


# ----------------------------------------- #
def inspectionFilter(self):
""" return inspection filter (only one repository to be fetched) """
return self.mInspectionFilter


# ----------------------------------------- #
def setInspectionFilter(self, key = None):
""" temporarily disable all repositories but this for inspection """
self.mInspectionFilter = key

# --- /class Repositories ---------------------------------------------------------------- #


@@ -522,6 +545,12 @@ def keyByUrl(self, name):
return None


# ----------------------------------------- #
def clearRepoCache(self):
""" clears the repo cache before re-fetching repositories """
self.repoCache = {}


# ----------------------------------------- #
def addFromRepository(self, plugin):
""" add given plugin to the repoCache """
@@ -787,6 +787,10 @@ void QgsPluginManager::clearRepositoryList()
buttonRefreshRepos->setEnabled( false );
buttonEditRep->setEnabled( false );
buttonDeleteRep->setEnabled( false );
foreach ( QAction * action, treeRepositories->actions() )
{
treeRepositories->removeAction( action );
}
}


@@ -797,11 +801,14 @@ void QgsPluginManager::addToRepositoryList( QMap<QString, QString> repository )
// If the item is second on the tree, add a context menu
if ( buttonRefreshRepos->isEnabled() && treeRepositories->actions().count() < 1 )
{
QAction* actionEnableThisRepositoryOnly = new QAction( tr( "Enable selected repository only" ), treeRepositories );
actionEnableThisRepositoryOnly->setCheckable( true );
QAction* actionEnableThisRepositoryOnly = new QAction( tr( "Only show plugins from selected repository" ), treeRepositories );
treeRepositories->addAction( actionEnableThisRepositoryOnly );
connect( actionEnableThisRepositoryOnly, SIGNAL( triggered() ), this, SLOT( setRepositoryFilter() ) );
treeRepositories->setContextMenuPolicy( Qt::ActionsContextMenu );
connect( actionEnableThisRepositoryOnly, SIGNAL( toggled( bool ) ), this, SLOT( enableSelectedRepositoryOnly( bool ) ) );
QAction* actionClearFilter = new QAction( tr( "Clear filter" ), treeRepositories );
actionClearFilter->setEnabled( repository.value( "inspection_filter" ) == "true" );
treeRepositories->addAction( actionClearFilter );
connect( actionClearFilter, SIGNAL( triggered( ) ), this, SLOT( clearRepositoryFilter() ) );
}

QString key = repository.value( "name" );
@@ -1062,26 +1069,28 @@ void QgsPluginManager::on_treeRepositories_doubleClicked( QModelIndex )



void QgsPluginManager::enableSelectedRepositoryOnly( bool checked )
void QgsPluginManager::setRepositoryFilter( )
{
if ( ! checked ) {
QgsDebugMsg( "Enabling all repositories back");
QgsPythonRunner::run( QString( "pyplugin_installer.instance().enableThisRepositoryOnly()" ) );
return;
}

QTreeWidgetItem * current = treeRepositories->currentItem();
if ( current )
{
QString key = current->text( 1 );
key = key.replace( "\'", "\\\'" ).replace( "\"", "\\\"" );
QgsDebugMsg( "Disabling all repositories but selected: " + key );
QgsPythonRunner::run( QString( "pyplugin_installer.instance().enableThisRepositoryOnly('%1')" ).arg( key ) );
QgsPythonRunner::run( QString( "pyplugin_installer.instance().setRepositoryInspectionFilter('%1')" ).arg( key ) );
}
}



void QgsPluginManager::clearRepositoryFilter( )
{
QgsDebugMsg( "Enabling all repositories back");
QgsPythonRunner::run( QString( "pyplugin_installer.instance().setRepositoryInspectionFilter()" ) );
}



void QgsPluginManager::on_buttonRefreshRepos_clicked( )
{
QgsDebugMsg( "Refreshing repositories..." );
@@ -156,8 +156,11 @@ class QgsPluginManager : public QgsOptionsDialogBase, private Ui::QgsPluginManag
//! Reimplement QgsOptionsDialogBase method to prevent modifying the tab list by signals from the stacked widget
void optionsStackedWidget_CurrentChanged( int indx ) { Q_UNUSED( indx ) }

//! Enable selected repository only
void enableSelectedRepositoryOnly( bool checked );
//! Only show plugins from selected repository (e.g. for inspection)
void setRepositoryFilter( );

//! Enable all repositories disabled by "Enable selected repository only"
void clearRepositoryFilter( );

private:
//! Return true if given plugin is present in QgsPluginRegistry (c++ plugins) or is enabled in QSettings (Python plugins)

0 comments on commit 1d2117f

Please sign in to comment.
You can’t perform that action at this time.