2008-09-10 20:26:08 +00:00
# -*- coding: utf-8 -*-
2012-10-07 19:50:52 +03:00
2008-11-10 14:39:12 +00:00
"""
2008-10-31 20:06:55 +00:00
Copyright ( C ) 2007 - 2008 Matthew Perry
2010-06-28 19:18:40 +00:00
Copyright ( C ) 2008 - 2010 Borys Jurgiel
2008-09-10 20:26:08 +00:00
/ * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* *
* This program is free software ; you can redistribute it and / or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation ; either version 2 of the License , or *
* ( at your option ) any later version . *
* *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * /
2008-11-10 14:39:12 +00:00
"""
2012-10-07 19:50:52 +03:00
import sys
import time
2008-10-31 20:06:55 +00:00
2008-09-10 20:26:08 +00:00
from PyQt4 . QtCore import *
from PyQt4 . QtGui import *
2012-10-07 19:50:52 +03:00
2008-09-10 20:26:08 +00:00
from qgis . core import QgsApplication , QgsContextHelp
2012-10-07 19:50:52 +03:00
2009-08-16 22:40:48 +00:00
from ui_qgsplugininstallerfetchingbase import Ui_QgsPluginInstallerFetchingDialogBase
from ui_qgsplugininstallerinstallingbase import Ui_QgsPluginInstallerInstallingDialogBase
from ui_qgsplugininstallerrepositorybase import Ui_QgsPluginInstallerRepositoryDetailsDialogBase
from ui_qgsplugininstallerpluginerrorbase import Ui_QgsPluginInstallerPluginErrorDialogBase
from ui_qgsplugininstallerbase import Ui_QgsPluginInstallerDialogBase
2012-10-07 19:50:52 +03:00
2008-09-10 20:26:08 +00:00
from installer_data import *
2009-12-15 17:47:00 +00:00
try :
2010-03-19 15:24:04 +00:00
from qgis . utils import startPlugin , unloadPlugin , loadPlugin # QGIS >= 1.4
2010-06-28 19:18:40 +00:00
from qgis . utils import reloadPlugin , updateAvailablePlugins # QGIS >= 1.5
2009-12-15 17:47:00 +00:00
except Exception :
pass
2008-09-10 20:26:08 +00:00
2008-09-12 22:19:54 +00:00
2008-09-10 20:26:08 +00:00
# --- common functions ------------------------------------------------------------------- #
def removeDir ( path ) :
result = QString ( )
if not QFile ( path ) . exists ( ) :
2008-11-13 01:17:18 +00:00
result = QCoreApplication . translate ( " QgsPluginInstaller " , " Nothing to remove! Plugin directory doesn ' t exist: " ) + " \n " + path
2008-10-31 20:06:55 +00:00
elif QFile ( path ) . remove ( ) : # if it is only link, just remove it without resolving.
2008-09-10 20:26:08 +00:00
pass
else :
fltr = QDir . Dirs | QDir . Files | QDir . Hidden
iterator = QDirIterator ( path , fltr , QDirIterator . Subdirectories )
while iterator . hasNext ( ) :
item = iterator . next ( )
if QFile ( item ) . remove ( ) :
pass
fltr = QDir . Dirs | QDir . Hidden
iterator = QDirIterator ( path , fltr , QDirIterator . Subdirectories )
while iterator . hasNext ( ) :
item = iterator . next ( )
2008-09-12 22:19:54 +00:00
if QDir ( ) . rmpath ( item ) :
2008-09-10 20:26:08 +00:00
pass
if QFile ( path ) . exists ( ) :
2008-11-13 01:17:18 +00:00
result = QCoreApplication . translate ( " QgsPluginInstaller " , " Failed to remove the directory: " ) + " \n " + path + " \n " + QCoreApplication . translate ( " QgsPluginInstaller " , " Check permissions or remove it manually " )
2008-09-12 22:19:54 +00:00
# restore plugin directory if removed by QDir().rmpath()
2008-11-24 23:13:56 +00:00
pluginDir = QFileInfo ( QgsApplication . qgisUserDbFilePath ( ) ) . path ( ) + " /python/plugins "
2008-09-12 22:19:54 +00:00
if not QDir ( pluginDir ) . exists ( ) :
QDir ( ) . mkpath ( pluginDir )
2008-09-10 20:26:08 +00:00
return result
# --- /common functions ------------------------------------------------------------------ #
# --- class QgsPluginInstallerFetchingDialog --------------------------------------------------------------- #
2008-11-13 01:17:18 +00:00
class QgsPluginInstallerFetchingDialog ( QDialog , Ui_QgsPluginInstallerFetchingDialogBase ) :
2008-09-10 20:26:08 +00:00
# ----------------------------------------- #
def __init__ ( self , parent ) :
QDialog . __init__ ( self , parent )
self . setupUi ( self )
self . progressBar . setRange ( 0 , len ( repositories . allEnabled ( ) ) * 100 )
self . itemProgress = { }
self . item = { }
for key in repositories . allEnabled ( ) :
self . item [ key ] = QTreeWidgetItem ( self . treeWidget )
self . item [ key ] . setText ( 0 , key )
if repositories . all ( ) [ key ] [ " state " ] > 1 :
self . itemProgress [ key ] = 100
self . displayState ( key , 0 )
else :
self . itemProgress [ key ] = 0
self . displayState ( key , 2 )
self . treeWidget . resizeColumnToContents ( 0 )
QObject . connect ( repositories , SIGNAL ( " repositoryFetched(QString) " ) , self . repositoryFetched )
QObject . connect ( repositories , SIGNAL ( " anythingChanged(QString, int, int) " ) , self . displayState )
# ----------------------------------------- #
def displayState ( self , key , state , state2 = None ) :
2008-10-31 20:06:55 +00:00
messages = [ self . tr ( " Success " ) , self . tr ( " Resolving host name... " ) , self . tr ( " Connecting... " ) , self . tr ( " Host connected. Sending request... " ) , self . tr ( " Downloading data... " ) , self . tr ( " Idle " ) , self . tr ( " Closing connection... " ) , self . tr ( " Error " ) ]
2008-09-10 20:26:08 +00:00
message = messages [ state ]
if state2 :
message + = " ( %s %% ) " % state2
self . item [ key ] . setText ( 1 , message )
if state == 4 and state2 :
self . itemProgress [ key ] = state2
totalProgress = sum ( self . itemProgress . values ( ) )
self . progressBar . setValue ( totalProgress )
# ----------------------------------------- #
def repositoryFetched ( self , repoName ) :
self . itemProgress [ repoName ] = 100
if repositories . all ( ) [ repoName ] [ " state " ] == 2 :
self . displayState ( repoName , 0 )
else :
self . displayState ( repoName , 7 )
if not repositories . fetchingInProgress ( ) :
self . close ( )
# --- /class QgsPluginInstallerFetchingDialog -------------------------------------------------------------- #
# --- class QgsPluginInstallerRepositoryDialog ------------------------------------------------------------- #
2008-11-13 01:17:18 +00:00
class QgsPluginInstallerRepositoryDialog ( QDialog , Ui_QgsPluginInstallerRepositoryDetailsDialogBase ) :
2008-09-10 20:26:08 +00:00
# ----------------------------------------- #
def __init__ ( self , parent = None ) :
QDialog . __init__ ( self , parent )
self . setupUi ( self )
self . editURL . setText ( " http:// " )
self . connect ( self . editName , SIGNAL ( " textChanged(const QString &) " ) , self . textChanged )
self . connect ( self . editURL , SIGNAL ( " textChanged(const QString &) " ) , self . textChanged )
self . textChanged ( None )
# ----------------------------------------- #
def textChanged ( self , string ) :
enable = ( self . editName . text ( ) . count ( ) > 0 and self . editURL . text ( ) . count ( ) > 0 )
self . buttonBox . button ( QDialogButtonBox . Ok ) . setEnabled ( enable )
# --- /class QgsPluginInstallerRepositoryDialog ------------------------------------------------------------ #
# --- class QgsPluginInstallerInstallingDialog --------------------------------------------------------------- #
2008-11-13 01:17:18 +00:00
class QgsPluginInstallerInstallingDialog ( QDialog , Ui_QgsPluginInstallerInstallingDialogBase ) :
2008-09-10 20:26:08 +00:00
# ----------------------------------------- #
def __init__ ( self , parent , plugin ) :
QDialog . __init__ ( self , parent )
self . setupUi ( self )
self . plugin = plugin
self . mResult = QString ( )
self . progressBar . setRange ( 0 , 0 )
self . progressBar . setFormat ( QString ( " % p % " ) )
self . labelName . setText ( QString ( plugin [ " name " ] ) )
self . connect ( self . buttonBox , SIGNAL ( " clicked(QAbstractButton*) " ) , self . abort )
url = QUrl ( plugin [ " url " ] )
2008-10-31 20:06:55 +00:00
path = QString ( url . toPercentEncoding ( url . path ( ) , " !$& ' ()*+,;=:/@ " ) )
2008-09-10 20:26:08 +00:00
fileName = plugin [ " filename " ]
tmpDir = QDir . tempPath ( )
tmpPath = QDir . cleanPath ( tmpDir + " / " + fileName )
self . file = QFile ( tmpPath )
2009-10-04 12:12:01 +00:00
port = url . port ( )
if port < 0 :
port = 80
self . http = QPHttp ( url . host ( ) , port )
2012-06-06 21:47:55 +02:00
self . connect ( self . http , SIGNAL ( " stateChanged ( int ) " ) , self . stateChanged )
2008-09-10 20:26:08 +00:00
self . connect ( self . http , SIGNAL ( " dataReadProgress ( int , int ) " ) , self . readProgress )
self . connect ( self . http , SIGNAL ( " requestFinished (int, bool) " ) , self . requestFinished )
self . httpGetId = self . http . get ( path , self . file )
# ----------------------------------------- #
def result ( self ) :
return self . mResult
# ----------------------------------------- #
def stateChanged ( self , state ) :
messages = [ self . tr ( " Installing... " ) , self . tr ( " Resolving host name... " ) , self . tr ( " Connecting... " ) , self . tr ( " Host connected. Sending request... " ) , self . tr ( " Downloading data... " ) , self . tr ( " Idle " ) , self . tr ( " Closing connection... " ) , self . tr ( " Error " ) ]
self . labelState . setText ( messages [ state ] )
# ----------------------------------------- #
def readProgress ( self , done , total ) :
self . progressBar . setMaximum ( total )
self . progressBar . setValue ( done )
# ----------------------------------------- #
def requestFinished ( self , requestId , state ) :
if requestId != self . httpGetId :
return
self . buttonBox . setEnabled ( False )
if state :
self . mResult = self . http . errorString ( )
self . reject ( )
return
self . file . close ( )
2008-11-24 23:13:56 +00:00
pluginDir = QFileInfo ( QgsApplication . qgisUserDbFilePath ( ) ) . path ( ) + " /python/plugins "
tmpPath = self . file . fileName ( )
2008-09-10 20:26:08 +00:00
# make sure that the parent directory exists
if not QDir ( pluginDir ) . exists ( ) :
2008-09-12 22:19:54 +00:00
QDir ( ) . mkpath ( pluginDir )
2008-10-31 20:06:55 +00:00
# if the target directory already exists as a link, remove the link without resolving:
QFile ( pluginDir + QString ( QDir . separator ( ) ) + self . plugin [ " localdir " ] ) . remove ( )
2008-09-12 22:19:54 +00:00
try :
un = unzip ( )
2008-11-24 23:13:56 +00:00
un . extract ( unicode ( tmpPath ) , unicode ( pluginDir ) ) # test extract. If fails, then exception will be raised and no removing occurs
# removing old plugin files if exist
2008-09-12 22:19:54 +00:00
removeDir ( QDir . cleanPath ( pluginDir + " / " + self . plugin [ " localdir " ] ) ) # remove old plugin if exists
2008-11-24 23:13:56 +00:00
un . extract ( unicode ( tmpPath ) , unicode ( pluginDir ) ) # final extract.
2008-09-12 22:19:54 +00:00
except :
2008-11-13 01:17:18 +00:00
self . mResult = self . tr ( " Failed to unzip the plugin package. Probably it ' s broken or missing from the repository. You may also want to make sure that you have write permission to the plugin directory: " ) + " \n " + pluginDir
2008-09-12 22:19:54 +00:00
self . reject ( )
return
2008-09-10 20:26:08 +00:00
try :
2008-11-24 23:13:56 +00:00
# cleaning: removing the temporary zip file
2008-09-10 20:26:08 +00:00
QFile ( tmpPath ) . remove ( )
except :
pass
self . close ( )
# ----------------------------------------- #
def abort ( self ) :
self . http . abort ( )
self . mResult = self . tr ( " Aborted by user " )
self . reject ( )
2008-11-13 21:14:53 +00:00
# --- /class QgsPluginInstallerInstallingDialog ------------------------------------------------------------- #
2008-09-10 20:26:08 +00:00
# --- class QgsPluginInstallerPluginErrorDialog -------------------------------------------------------------- #
2008-11-13 01:17:18 +00:00
class QgsPluginInstallerPluginErrorDialog ( QDialog , Ui_QgsPluginInstallerPluginErrorDialogBase ) :
2008-09-10 20:26:08 +00:00
# ----------------------------------------- #
def __init__ ( self , parent , errorMessage ) :
QDialog . __init__ ( self , parent )
self . setupUi ( self )
if not errorMessage :
2008-11-13 01:17:18 +00:00
errorMessage = self . tr ( " no error message received " )
2008-09-10 20:26:08 +00:00
self . textBrowser . setText ( errorMessage )
# --- /class QgsPluginInstallerPluginErrorDialog ------------------------------------------------------------- #
# --- class QgsPluginInstallerDialog ------------------------------------------------------------------------- #
2008-11-13 01:17:18 +00:00
class QgsPluginInstallerDialog ( QDialog , Ui_QgsPluginInstallerDialogBase ) :
2008-09-10 20:26:08 +00:00
# ----------------------------------------- #
2012-01-06 19:34:34 +01:00
def __init__ ( self , parent ) :
QDialog . __init__ ( self , parent )
2008-09-10 20:26:08 +00:00
self . setupUi ( self )
self . reposGroup = " /Qgis/plugin-repos "
self . connect ( self . lineFilter , SIGNAL ( " textChanged (QString) " ) , self . filterChanged )
self . connect ( self . comboFilter1 , SIGNAL ( " currentIndexChanged (int) " ) , self . filterChanged )
self . connect ( self . comboFilter2 , SIGNAL ( " currentIndexChanged (int) " ) , self . filterChanged )
2008-11-13 01:17:18 +00:00
# grab clicks on trees
self . connect ( self . treePlugins , SIGNAL ( " itemSelectionChanged() " ) , self . pluginTreeClicked )
self . connect ( self . treeRepositories , SIGNAL ( " itemSelectionChanged() " ) , self . repositoryTreeClicked )
2008-09-10 20:26:08 +00:00
# buttons
2010-11-12 20:07:39 +00:00
self . connect ( self . buttonUpgradeAll , SIGNAL ( " clicked() " ) , self . upgradeAllClicked )
2010-11-01 00:52:20 +00:00
self . connect ( self . buttonInstall , SIGNAL ( " clicked() " ) , self . installPluginClicked )
self . connect ( self . buttonUninstall , SIGNAL ( " clicked() " ) , self . uninstallPluginClicked )
2008-09-10 20:26:08 +00:00
self . buttonInstall . setEnabled ( False )
self . buttonUninstall . setEnabled ( False )
2009-12-15 17:47:00 +00:00
self . buttonHelp . setEnabled ( QGIS_14 )
self . connect ( self . buttonHelp , SIGNAL ( " clicked() " ) , self . runHelp )
2008-09-10 20:26:08 +00:00
# repositories handling
self . connect ( self . treeRepositories , SIGNAL ( " doubleClicked(QModelIndex) " ) , self . editRepository )
2012-06-06 21:47:55 +02:00
#self.connect(self.buttonFetchRepositories, SIGNAL("clicked()"), self.addKnownRepositories)
2008-09-10 20:26:08 +00:00
self . connect ( self . buttonAddRep , SIGNAL ( " clicked() " ) , self . addRepository )
self . connect ( self . buttonEditRep , SIGNAL ( " clicked() " ) , self . editRepository )
self . connect ( self . buttonDeleteRep , SIGNAL ( " clicked() " ) , self . deleteRepository )
2008-11-13 01:17:18 +00:00
self . buttonEditRep . setEnabled ( False )
self . buttonDeleteRep . setEnabled ( False )
2009-03-20 22:08:03 +00:00
# configuration widgets
self . connect ( self . checkUpdates , SIGNAL ( " toggled (bool) " ) , self . changeCheckingPolicy )
self . connect ( self . comboInterval , SIGNAL ( " currentIndexChanged (int) " ) , self . changeCheckingInterval )
self . connect ( self . radioPluginType0 , SIGNAL ( " toggled (bool) " ) , self . changePluginPolicy )
self . connect ( self . radioPluginType1 , SIGNAL ( " toggled (bool) " ) , self . changePluginPolicy )
self . connect ( self . radioPluginType2 , SIGNAL ( " toggled (bool) " ) , self . changePluginPolicy )
2012-10-09 19:32:00 +03:00
# increase default icon size
self . treePlugins . setIconSize ( QSize ( 22 , 22 ) )
2009-03-20 22:08:03 +00:00
if repositories . checkingOnStart ( ) :
self . checkUpdates . setChecked ( Qt . Checked )
else :
self . checkUpdates . setChecked ( Qt . Unchecked )
interval = repositories . checkingOnStartInterval ( )
intervals = [ 0 , 1 , 3 , 7 , 14 , 30 ] # days
if intervals . count ( interval ) :
index = intervals . index ( interval )
else :
index = 1
self . comboInterval . setCurrentIndex ( index )
2008-09-10 20:26:08 +00:00
self . populateMostWidgets ( )
# ----------------------------------------- #
def getAllAvailablePlugins ( self ) :
2009-04-17 23:41:14 +00:00
""" fetch plugins from all repositories """
2008-09-10 20:26:08 +00:00
repositories . load ( )
2009-04-17 23:41:14 +00:00
plugins . getAllInstalled ( )
2008-09-10 20:26:08 +00:00
for key in repositories . allEnabled ( ) :
repositories . requestFetching ( key )
if repositories . fetchingInProgress ( ) :
self . fetchDlg = QgsPluginInstallerFetchingDialog ( self )
self . fetchDlg . exec_ ( )
del self . fetchDlg
for key in repositories . all ( ) :
repositories . killConnection ( key )
2009-12-26 23:37:48 +00:00
# display error messages for every unavailable reposioty, unless Shift pressed nor all repositories are unavailable
keepQuiet = QgsApplication . keyboardModifiers ( ) == Qt . KeyboardModifiers ( Qt . ShiftModifier )
2008-09-10 20:26:08 +00:00
if repositories . allUnavailable ( ) and repositories . allUnavailable ( ) != repositories . allEnabled ( ) :
for key in repositories . allUnavailable ( ) :
2009-12-26 23:37:48 +00:00
if not keepQuiet :
QMessageBox . warning ( self , self . tr ( " QGIS Python Plugin Installer " ) , self . tr ( " Error reading repository: " ) + " " + key + " \n " + repositories . all ( ) [ key ] [ " error " ] )
if QgsApplication . keyboardModifiers ( ) == Qt . KeyboardModifiers ( Qt . ShiftModifier ) :
keepQuiet = True
2008-09-10 20:26:08 +00:00
# ----------------------------------------- #
def populateMostWidgets ( self ) :
self . comboFilter1 . clear ( )
self . comboFilter1 . addItem ( self . tr ( " all repositories " ) )
self . treeRepositories . clear ( )
for key in repositories . all ( ) :
a = QTreeWidgetItem ( self . treeRepositories )
a . setText ( 1 , key )
a . setText ( 2 , repositories . all ( ) [ key ] [ " url " ] )
if repositories . all ( ) [ key ] [ " enabled " ] and repositories . all ( ) [ key ] [ " valid " ] :
if repositories . all ( ) [ key ] [ " state " ] == 2 :
a . setText ( 0 , self . tr ( " connected " ) )
a . setIcon ( 0 , QIcon ( " :/plugins/installer/repoConnected.png " ) )
a . setToolTip ( 0 , self . tr ( " This repository is connected " ) )
self . comboFilter1 . addItem ( key )
else :
a . setText ( 0 , self . tr ( " unavailable " ) )
a . setIcon ( 0 , QIcon ( " :/plugins/installer/repoUnavailable.png " ) )
a . setToolTip ( 0 , self . tr ( " This repository is enabled, but unavailable " ) )
self . comboFilter1 . addItem ( key )
else :
a . setText ( 0 , self . tr ( " disabled " ) )
a . setIcon ( 0 , QIcon ( " :/plugins/installer/repoDisabled.png " ) )
if repositories . all ( ) [ key ] [ " valid " ] :
a . setToolTip ( 0 , self . tr ( " This repository is disabled " ) )
else :
2008-11-10 14:39:12 +00:00
a . setToolTip ( 0 , self . tr ( " This repository is blocked due to incompatibility with your Quantum GIS version " ) )
2009-10-10 07:25:42 +00:00
for i in [ 0 , 1 , 2 ] :
a . setForeground ( i , QBrush ( QColor ( Qt . gray ) ) )
2008-09-10 20:26:08 +00:00
for i in [ 0 , 1 , 2 ] :
self . treeRepositories . resizeColumnToContents ( i )
self . comboFilter1 . addItem ( self . tr ( " orphans " ) )
2009-03-20 22:08:03 +00:00
# fill the status filter comboBox
2008-09-10 20:26:08 +00:00
self . comboFilter2 . clear ( )
self . comboFilter2 . addItem ( self . tr ( " any status " ) )
2008-10-31 20:06:55 +00:00
self . comboFilter2 . addItem ( self . tr ( " not installed " , " plural " ) )
self . comboFilter2 . addItem ( self . tr ( " installed " , " plural " ) )
2008-09-10 20:26:08 +00:00
if plugins . isThereAnythingNew ( ) :
self . comboFilter2 . addItem ( self . tr ( " upgradeable and news " ) )
2009-03-20 22:08:03 +00:00
settings = QSettings ( )
2012-06-06 21:47:55 +02:00
( i , ok ) = settings . value ( settingsGroup + " /allowedPluginType " , QVariant ( 1 ) ) . toInt ( )
if i == 1 :
2009-03-20 22:08:03 +00:00
self . radioPluginType0 . setChecked ( Qt . Checked )
2012-06-06 21:47:55 +02:00
elif i == 2 :
2009-03-20 22:08:03 +00:00
self . radioPluginType1 . setChecked ( Qt . Checked )
2012-06-06 21:47:55 +02:00
else :
self . radioPluginType2 . setChecked ( Qt . Checked )
2008-09-10 20:26:08 +00:00
# ----------------------------------------- #
def filterChanged ( self , i ) :
""" one of the filter widgets has been changed """
self . populatePluginTree ( )
# ----------------------------------------- #
def filterCheck ( self , plugin ) :
""" the filter for the pluginsTree """
if self . comboFilter1 . currentIndex ( ) != 0 and self . comboFilter1 . currentText ( ) != self . tr ( " orphans " ) :
if self . comboFilter1 . currentText ( ) != plugin [ " repository " ] :
return False
elif self . comboFilter1 . currentText ( ) == self . tr ( " orphans " ) :
if plugin [ " status " ] != " orphan " :
return False
if self . comboFilter2 . currentIndex ( ) == 1 and not plugin [ " status " ] in [ " not installed " , " new " ] :
return False
2008-11-12 00:26:40 +00:00
if self . comboFilter2 . currentIndex ( ) == 2 and not plugin [ " status " ] in [ " installed " , " upgradeable " , " newer " , " orphan " ] :
2008-09-10 20:26:08 +00:00
return False
if self . comboFilter2 . currentIndex ( ) == 3 and not plugin [ " status " ] in [ " upgradeable " , " new " ] :
return False
if self . lineFilter . text ( ) == " " :
return True
else :
for i in [ " name " , " version_inst " , " version_avail " , " desc_repo " , " desc_local " , " author " , " status " , " repository " ] :
2009-03-23 13:18:27 +00:00
item = QString ( plugin [ i ] )
2008-09-10 20:26:08 +00:00
if item != None :
2008-11-24 23:13:56 +00:00
if item . contains ( self . lineFilter . text ( ) , Qt . CaseInsensitive ) :
2008-09-10 20:26:08 +00:00
return True
return False
# ----------------------------------------- #
def populatePluginTree ( self ) :
""" fill up the pluginTree """
2008-11-12 00:26:40 +00:00
statusTips = { " not installed " : self . tr ( " This plugin is not installed " ) ,
2008-09-10 20:26:08 +00:00
" installed " : self . tr ( " This plugin is installed " ) ,
" upgradeable " : self . tr ( " This plugin is installed, but there is an updated version available " ) ,
" orphan " : self . tr ( " This plugin is installed, but I can ' t find it in any enabled repository " ) ,
2008-10-31 20:06:55 +00:00
" new " : self . tr ( " This plugin is not installed and is seen for the first time " ) ,
2008-09-10 20:26:08 +00:00
" newer " : self . tr ( " This plugin is installed and is newer than its version available in a repository " ) ,
2008-11-13 23:44:39 +00:00
" incompatible " : self . tr ( " This plugin is incompatible with your Quantum GIS version and probably won ' t work. " ) ,
2008-12-05 18:51:00 +00:00
" dependent " : self . tr ( " The required Python module is not installed. \n For more information, please visit its homepage and Quantum GIS wiki. " ) ,
2008-11-13 23:44:39 +00:00
" broken " : self . tr ( " This plugin seems to be broken. \n It has been installed but can ' t be loaded. \n Here is the error message: " ) }
2008-11-12 00:26:40 +00:00
statuses = { " not installed " : self . tr ( " not installed " , " singular " ) ,
2008-10-31 20:06:55 +00:00
" installed " : self . tr ( " installed " , " singular " ) ,
" upgradeable " : self . tr ( " upgradeable " , " singular " ) ,
" orphan " : self . tr ( " installed " , " singular " ) ,
" new " : self . tr ( " new! " , " singular " ) ,
" newer " : self . tr ( " installed " , " singular " ) ,
2008-11-12 00:26:40 +00:00
" incompatible " : self . tr ( " invalid " , " singular " ) ,
2008-11-13 21:14:53 +00:00
" dependent " : self . tr ( " invalid " , " singular " ) ,
2008-11-12 00:26:40 +00:00
" broken " : self . tr ( " invalid " , " singular " ) }
2008-11-13 21:14:53 +00:00
orderInvalid = [ " incompatible " , " broken " , " dependent " ]
2008-11-12 00:26:40 +00:00
orderValid = [ " upgradeable " , " new " , " not installed " , " installed " , " orphan " , " newer " ]
2008-09-10 20:26:08 +00:00
def addItem ( p ) :
if self . filterCheck ( p ) :
2008-11-13 23:44:39 +00:00
statusTip = statusTips [ p [ " status " ] ]
2008-09-10 20:26:08 +00:00
if p [ " read-only " ] :
2008-11-13 23:44:39 +00:00
statusTip = statusTip + " \n " + self . tr ( " Note that it ' s an uninstallable core plugin " )
2008-11-12 00:26:40 +00:00
installedVersion = p [ " version_inst " ]
if not installedVersion :
installedVersion = " ? "
availableVersion = p [ " version_avail " ]
if not availableVersion :
availableVersion = " ? "
2008-09-10 20:26:08 +00:00
if p [ " status " ] == " upgradeable " :
2008-11-12 00:26:40 +00:00
ver = installedVersion + " -> " + availableVersion
2008-09-10 20:26:08 +00:00
elif p [ " status " ] == " newer " :
2008-11-12 00:26:40 +00:00
ver = installedVersion + " ( " + availableVersion + " ) "
elif p [ " status " ] in [ " not installed " , " new " ] :
ver = availableVersion
2008-09-10 20:26:08 +00:00
else :
2008-11-12 00:26:40 +00:00
ver = installedVersion
2008-12-19 23:06:38 +00:00
if p [ " status " ] in [ " upgradeable " , " newer " ] or p [ " error " ] :
2008-11-12 00:26:40 +00:00
verTip = self . tr ( " installed version " ) + " : " + installedVersion + " \n " + self . tr ( " available version " ) + " : " + availableVersion
2008-09-10 20:26:08 +00:00
elif p [ " status " ] in [ " not installed " , " new " ] :
2008-11-12 00:26:40 +00:00
verTip = self . tr ( " available version " ) + " : " + availableVersion
2008-09-10 20:26:08 +00:00
elif p [ " status " ] == " installed " :
2008-11-12 00:26:40 +00:00
verTip = self . tr ( " installed version " ) + " : " + installedVersion + " \n " + self . tr ( " That ' s the newest available version " )
2008-09-10 20:26:08 +00:00
elif p [ " status " ] == " orphan " :
2008-11-12 00:26:40 +00:00
verTip = self . tr ( " installed version " ) + " : " + installedVersion + " \n " + self . tr ( " There is no version available for download " )
2008-09-10 20:26:08 +00:00
else :
2008-11-10 14:39:12 +00:00
verTip = " "
2008-11-12 00:26:40 +00:00
if p [ " error " ] == " broken " :
2008-11-13 21:14:53 +00:00
desc = self . tr ( " This plugin is broken " )
2008-11-13 23:44:39 +00:00
descTip = statusTips [ p [ " error " ] ] + " \n " + p [ " error_details " ]
statusTip = descTip
2008-11-12 00:26:40 +00:00
elif p [ " error " ] == " incompatible " :
2008-11-13 21:14:53 +00:00
desc = self . tr ( " This plugin requires a newer version of Quantum GIS " ) + " ( " + self . tr ( " at least " ) + " " + p [ " error_details " ] + " ) "
descTip = statusTips [ p [ " error " ] ]
2008-11-13 23:44:39 +00:00
statusTip = descTip
2008-11-13 21:14:53 +00:00
elif p [ " error " ] == " dependent " :
desc = self . tr ( " This plugin requires a missing module " ) + " ( " + p [ " error_details " ] + " ) "
2008-11-12 00:26:40 +00:00
descTip = statusTips [ p [ " error " ] ]
2008-11-13 23:44:39 +00:00
statusTip = descTip
2008-11-10 14:39:12 +00:00
else :
desc = p [ " desc_local " ]
descTip = p [ " desc_repo " ]
if not desc :
desc = descTip
2008-10-31 20:06:55 +00:00
if not p [ " repository " ] :
2008-09-10 20:26:08 +00:00
repository = self . tr ( " only locally available " )
else :
repository = p [ " repository " ]
2012-10-07 19:50:52 +03:00
a = QgsPluginTreeItem ( self . treePlugins )
if p [ " experimental " ] :
a . setIcon ( 0 , QIcon ( " :/plugins/installer/pluginExperimental.png " ) )
a . setToolTip ( 0 , self . tr ( " Experimental plugin. Use at own risk " ) )
a . setData ( 0 , Qt . UserRole , QVariant ( 0 ) )
else :
2012-10-09 19:32:00 +03:00
# set empty icon to keep row height same for all plugins
a . setIcon ( 0 , QIcon ( " :/plugins/installer/pluginStable.png " ) )
2012-10-07 19:50:52 +03:00
a . setData ( 0 , Qt . UserRole , QVariant ( 1 ) )
2008-11-12 00:26:40 +00:00
if p [ " error " ] :
2012-10-07 19:50:52 +03:00
a . setText ( 1 , statuses [ p [ " error " ] ] )
2008-11-12 00:26:40 +00:00
else :
2012-10-07 19:50:52 +03:00
a . setText ( 1 , statuses [ p [ " status " ] ] )
a . setToolTip ( 1 , statusTip )
a . setText ( 2 , p [ " name " ] )
a . setText ( 3 , ver )
a . setToolTip ( 3 , verTip )
a . setText ( 4 , desc )
2012-06-24 14:17:25 +02:00
# split the tooltip into multiple lines when they are too long
tmp = " "
splitTip = " "
for word in descTip . split ( " " ) :
if len ( tmp + word ) < 80 :
tmp = tmp + " " + word
else :
splitTip + = tmp + " \n "
tmp = word
2012-10-07 19:50:52 +03:00
a . setToolTip ( 4 , splitTip + tmp )
a . setText ( 5 , p [ " author " ] )
2008-09-10 20:26:08 +00:00
if p [ " homepage " ] :
2012-10-07 19:50:52 +03:00
a . setToolTip ( 5 , p [ " homepage " ] )
2008-09-10 20:26:08 +00:00
else :
2012-10-07 19:50:52 +03:00
a . setToolTip ( 6 , " " )
a . setText ( 6 , repository )
a . setToolTip ( 6 , p [ " url " ] )
2009-12-23 16:14:24 +00:00
# set fonts and colors
2012-10-07 19:50:52 +03:00
for i in [ 0 , 1 , 2 , 3 , 4 , 5 , 6 ] :
2008-11-12 00:26:40 +00:00
if p [ " error " ] :
2008-09-10 20:26:08 +00:00
a . setForeground ( i , QBrush ( QColor ( Qt . red ) ) )
2008-11-12 00:26:40 +00:00
if p [ " status " ] in [ " new " , " upgradeable " ] or p [ " error " ] :
2008-09-10 20:26:08 +00:00
font = QFont ( )
font . setWeight ( QFont . Bold )
a . setFont ( i , font )
# -------- #
if not plugins . all ( ) :
return
self . treePlugins . clear ( )
2008-11-12 00:26:40 +00:00
for i in orderInvalid :
for p in plugins . all ( ) . values ( ) :
if p [ " error " ] == i :
addItem ( p )
2010-11-12 20:07:39 +00:00
n = 0 # displayed plugins count
self . upgradeablePlugins = [ ] # list of plugins able to update
2008-11-12 00:26:40 +00:00
for i in orderValid :
2008-09-10 20:26:08 +00:00
for p in plugins . all ( ) . values ( ) :
2008-11-12 00:26:40 +00:00
if p [ " status " ] == i and not p [ " error " ] :
2008-09-10 20:26:08 +00:00
addItem ( p )
2010-11-12 20:07:39 +00:00
if p [ " status " ] == " upgradeable " : self . upgradeablePlugins + = [ p [ " localdir " ] ]
n + = 1
self . setWindowTitle ( self . tr ( " QGIS Python Plugin Installer " ) + self . tr ( " - %d plugins available " % len ( plugins . all ( ) ) ) )
self . buttonUpgradeAll . setEnabled ( len ( self . upgradeablePlugins ) )
2011-08-26 23:01:38 +02:00
2011-08-25 01:21:14 +02:00
# initially, keep insert order
self . treePlugins . sortItems ( 100 , Qt . AscendingOrder )
2012-06-06 21:47:55 +02:00
2008-09-10 20:26:08 +00:00
# resize the columns
for i in [ 0 , 1 , 2 , 3 , 4 , 5 ] :
self . treePlugins . resizeColumnToContents ( i )
for i in [ 0 , 1 , 2 , 4 , 5 ] :
if self . treePlugins . columnWidth ( i ) > 260 :
self . treePlugins . setColumnWidth ( i , 260 )
if self . treePlugins . columnWidth ( 3 ) > 560 :
self . treePlugins . setColumnWidth ( 3 , 560 )
# ----------------------------------------- #
2008-11-13 01:17:18 +00:00
def pluginTreeClicked ( self ) :
2008-09-10 20:26:08 +00:00
""" the pluginsTree has been clicked """
buttons = { " not installed " : ( True , False , self . tr ( " Install plugin " ) ) ,
" installed " : ( True , True , self . tr ( " Reinstall plugin " ) ) ,
2008-10-31 20:06:55 +00:00
" upgradeable " : ( True , True , self . tr ( " Upgrade plugin " ) ) ,
2008-09-10 20:26:08 +00:00
" orphan " : ( False , True , self . tr ( " Install/upgrade plugin " ) ) ,
2008-11-13 01:17:18 +00:00
" new " : ( True , False , self . tr ( " Install plugin " ) ) ,
2008-11-12 00:26:40 +00:00
" newer " : ( True , True , self . tr ( " Downgrade plugin " ) ) }
2008-09-10 20:26:08 +00:00
self . buttonInstall . setEnabled ( False )
self . buttonInstall . setText ( self . tr ( " Install/upgrade plugin " ) )
self . buttonUninstall . setEnabled ( False )
2008-11-13 01:17:18 +00:00
if not self . treePlugins . selectedItems ( ) :
return
2008-09-10 20:26:08 +00:00
item = self . treePlugins . currentItem ( )
if not item :
return
2012-10-08 11:26:32 +03:00
key = plugins . keyByUrl ( item . toolTip ( 6 ) )
2008-09-10 20:26:08 +00:00
if not key :
return
plugin = plugins . all ( ) [ key ]
if not plugin :
return
self . buttonInstall . setEnabled ( buttons [ plugin [ " status " ] ] [ 0 ] )
self . buttonUninstall . setEnabled ( buttons [ plugin [ " status " ] ] [ 1 ] )
self . buttonInstall . setText ( buttons [ plugin [ " status " ] ] [ 2 ] )
if plugin [ " read-only " ] :
self . buttonUninstall . setEnabled ( False )
2010-11-12 20:07:39 +00:00
# ----------------------------------------- #
def upgradeAllClicked ( self ) :
for key in self . upgradeablePlugins :
self . installPlugin ( key , quiet = True )
2008-09-10 20:26:08 +00:00
# ----------------------------------------- #
2010-11-01 00:52:20 +00:00
def installPluginClicked ( self ) :
if not self . treePlugins . currentItem ( ) :
return
2012-10-08 15:21:37 +03:00
key = plugins . keyByUrl ( self . treePlugins . currentItem ( ) . toolTip ( 6 ) )
2010-11-01 00:52:20 +00:00
self . installPlugin ( key )
# ----------------------------------------- #
def uninstallPluginClicked ( self ) :
2008-09-10 20:26:08 +00:00
if not self . treePlugins . currentItem ( ) :
return
2012-10-08 15:21:37 +03:00
key = plugins . keyByUrl ( self . treePlugins . currentItem ( ) . toolTip ( 6 ) )
2010-11-01 00:52:20 +00:00
self . uninstallPlugin ( key )
2010-11-12 20:07:39 +00:00
# ----------------------------------------- #
def installPlugin ( self , key , quiet = False ) :
2010-11-01 00:52:20 +00:00
""" install currently selected plugin """
infoString = ( ' ' , ' ' )
2008-09-10 20:26:08 +00:00
plugin = plugins . all ( ) [ key ]
2008-11-13 21:14:53 +00:00
previousStatus = plugin [ " status " ]
2008-09-10 20:26:08 +00:00
if not plugin :
return
2008-11-13 21:14:53 +00:00
if plugin [ " status " ] == " newer " and not plugin [ " error " ] : # ask for confirmation if user downgrades an usable plugin
2008-11-13 01:17:18 +00:00
if QMessageBox . warning ( self , self . tr ( " QGIS Python Plugin Installer " ) , self . tr ( " Are you sure you want to downgrade the plugin to the latest available version? The installed one is newer! " ) , QMessageBox . Yes , QMessageBox . No ) == QMessageBox . No :
return
2012-06-06 21:47:55 +02:00
2008-09-10 20:26:08 +00:00
dlg = QgsPluginInstallerInstallingDialog ( self , plugin )
dlg . exec_ ( )
if dlg . result ( ) :
infoString = ( self . tr ( " Plugin installation failed " ) , dlg . result ( ) )
2008-11-13 21:14:53 +00:00
elif not QDir ( QDir . cleanPath ( QgsApplication . qgisSettingsDirPath ( ) + " /python/plugins/ " + key ) ) . exists ( ) :
infoString = ( self . tr ( " Plugin has disappeared " ) , self . tr ( " The plugin seems to have been installed but I don ' t know where. Probably the plugin package contained a wrong named directory. \n Please search the list of installed plugins. I ' m nearly sure you ' ll find the plugin there, but I just can ' t determine which of them it is. It also means that I won ' t be able to determine if this plugin is installed and inform you about available updates. However the plugin may work. Please contact the plugin author and submit this issue. " ) )
QApplication . setOverrideCursor ( Qt . WaitCursor )
2009-04-17 23:41:14 +00:00
plugins . getAllInstalled ( )
plugins . rebuild ( )
2008-11-13 21:14:53 +00:00
QApplication . restoreOverrideCursor ( )
2008-09-10 20:26:08 +00:00
else :
2010-03-19 15:24:04 +00:00
if QGIS_14 :
if QGIS_15 : # update the list of plugins in plugin handling routines
updateAvailablePlugins ( )
# try to load the plugin
loadPlugin ( plugin [ " localdir " ] )
else : # QGIS < 1.4
try :
exec ( " sys.path_importer_cache.clear() " )
exec ( " import %s " % plugin [ " localdir " ] )
exec ( " reload ( %s ) " % plugin [ " localdir " ] )
except :
pass
2011-08-26 23:01:38 +02:00
plugins . getAllInstalled ( testLoad = True )
2009-04-17 23:41:14 +00:00
plugins . rebuild ( )
2009-04-07 07:11:43 +00:00
plugin = plugins . all ( ) [ key ]
if not plugin [ " error " ] :
if previousStatus in [ " not installed " , " new " ] :
2010-03-19 15:24:04 +00:00
if QGIS_14 : # plugins can be started in python from QGIS >= 1.4
2009-12-16 00:37:01 +00:00
infoString = ( self . tr ( " Plugin installed successfully " ) , self . tr ( " Plugin installed successfully " ) )
settings = QSettings ( )
settings . setValue ( " /PythonPlugins/ " + plugin [ " localdir " ] , QVariant ( True ) )
2010-03-19 15:24:04 +00:00
startPlugin ( plugin [ " localdir " ] )
2009-12-15 17:47:00 +00:00
else : infoString = ( self . tr ( " Plugin installed successfully " ) , self . tr ( " Python plugin installed. \n Now you need to enable it in Plugin Manager. " ) )
2009-04-07 07:11:43 +00:00
else :
2010-10-31 23:36:26 +00:00
if QGIS_15 : # plugins can be reloaded on the fly in QGIS >= 1.5
settings = QSettings ( )
if key != ' plugin_installer ' and settings . value ( " /PythonPlugins/ " + key ) . toBool ( ) : # plugin will be reloaded on the fly only if currently loaded
infoString = ( self . tr ( " Plugin reinstalled successfully " ) , self . tr ( " Plugin reinstalled successfully " ) )
reloadPlugin ( key )
else :
infoString = ( self . tr ( " Plugin reinstalled successfully " ) , self . tr ( " Python plugin reinstalled. \n You need to restart Quantum GIS in order to reload it. " ) )
else : infoString = ( self . tr ( " Plugin reinstalled successfully " ) , self . tr ( " Python plugin reinstalled. \n You need to restart Quantum GIS in order to reload it. " ) )
2010-11-12 20:07:39 +00:00
if quiet :
infoString = ( None , None )
2008-11-13 01:17:18 +00:00
else :
2009-04-07 07:11:43 +00:00
if plugin [ " error " ] == " incompatible " :
message = self . tr ( " The plugin is designed for a newer version of Quantum GIS. The minimum required version is: " )
message + = " <b> " + plugin [ " error_details " ] + " </b> "
elif plugin [ " error " ] == " dependent " :
message = self . tr ( " The plugin depends on some components missing on your system. You need to install the following Python module in order to enable it: " )
message + = " <b> " + plugin [ " error_details " ] + " </b> "
else :
message = self . tr ( " The plugin is broken. Python said: " )
message + = " <br><b> " + plugin [ " error_details " ] + " </b> "
dlg = QgsPluginInstallerPluginErrorDialog ( self , message )
dlg . exec_ ( )
if dlg . result ( ) :
# revert installation
2009-04-17 23:41:14 +00:00
plugins . getAllInstalled ( )
plugins . rebuild ( )
2009-04-07 07:11:43 +00:00
pluginDir = QFileInfo ( QgsApplication . qgisUserDbFilePath ( ) ) . path ( ) + " /python/plugins/ " + plugin [ " localdir " ]
removeDir ( pluginDir )
if QDir ( pluginDir ) . exists ( ) :
infoString = ( self . tr ( " Plugin uninstall failed " ) , result )
try :
exec ( " sys.path_importer_cache.clear() " )
exec ( " import %s " % plugin [ " localdir " ] )
exec ( " reload ( %s ) " % plugin [ " localdir " ] )
except :
pass
2008-11-13 01:17:18 +00:00
else :
2009-04-07 07:11:43 +00:00
try :
exec ( " del sys.modules[ %s ] " % plugin [ " localdir " ] )
except :
pass
2009-04-17 23:41:14 +00:00
plugins . getAllInstalled ( )
plugins . rebuild ( )
2009-04-09 00:19:51 +00:00
if plugins . all ( ) . has_key ( key ) and not plugins . all ( ) [ key ] [ " status " ] in [ " not installed " , " new " ] :
if previousStatus in [ " not installed " , " new " ] :
history . markChange ( key , ' A ' )
else :
history . markChange ( key , ' R ' )
2008-09-10 20:26:08 +00:00
self . populatePluginTree ( )
2008-11-13 21:14:53 +00:00
if infoString [ 0 ] :
QMessageBox . information ( self , infoString [ 0 ] , infoString [ 1 ] )
2008-09-10 20:26:08 +00:00
# ----------------------------------------- #
2010-11-01 00:52:20 +00:00
def uninstallPlugin ( self , key ) :
2008-09-10 20:26:08 +00:00
""" uninstall currently selected plugin """
plugin = plugins . all ( ) [ key ]
if not plugin :
return
2009-12-15 17:47:00 +00:00
warning = self . tr ( " Are you sure you want to uninstall the following plugin? " ) + " \n ( " + plugin [ " name " ] + " ) "
2008-11-12 00:26:40 +00:00
if plugin [ " status " ] == " orphan " and not plugin [ " error " ] :
2008-09-10 20:26:08 +00:00
warning + = " \n \n " + self . tr ( " Warning: this plugin isn ' t available in any accessible repository! " )
if QMessageBox . warning ( self , self . tr ( " QGIS Python Plugin Installer " ) , warning , QMessageBox . Yes , QMessageBox . No ) == QMessageBox . No :
return
2010-06-28 19:18:40 +00:00
# unload the plugin if it's not plugin_installer itself (otherwise, do it after removing its directory):
if key != " plugin_installer " :
try :
unloadPlugin ( key )
except :
pass
2008-11-24 23:13:56 +00:00
pluginDir = QFileInfo ( QgsApplication . qgisUserDbFilePath ( ) ) . path ( ) + " /python/plugins/ " + plugin [ " localdir " ]
2008-09-10 20:26:08 +00:00
result = removeDir ( pluginDir )
if result :
QMessageBox . warning ( self , self . tr ( " Plugin uninstall failed " ) , result )
else :
2010-06-28 19:18:40 +00:00
# if the uninstalled plugin is the installer itself, reload it and quit
if key == " plugin_installer " :
2010-06-29 20:21:18 +00:00
if QGIS_15 :
try :
QMessageBox . information ( self , self . tr ( " QGIS Python Plugin Installer " ) , self . tr ( " Plugin Installer update uninstalled. Plugin Installer will now close and revert to its primary version. You can find it in the Plugins menu and continue operation. " ) )
reloadPlugin ( key )
return
except :
pass
else :
QMessageBox . information ( self , self . tr ( " QGIS Python Plugin Installer " ) , self . tr ( " Plugin Installer update uninstalled. Please restart QGIS in order to load its primary version. " ) )
2008-11-24 23:13:56 +00:00
# safe remove
2009-12-15 17:47:00 +00:00
try :
unloadPlugin ( plugin [ " localdir " ] )
except :
pass
2008-11-24 23:13:56 +00:00
try :
exec ( " plugins[ %s ].unload() " % plugin [ " localdir " ] )
exec ( " del plugins[ %s ] " % plugin [ " localdir " ] )
except :
pass
2008-09-10 20:26:08 +00:00
try :
exec ( " del sys.modules[ %s ] " % plugin [ " localdir " ] )
except :
pass
2009-04-17 23:41:14 +00:00
plugins . getAllInstalled ( )
plugins . rebuild ( )
2008-09-10 20:26:08 +00:00
self . populatePluginTree ( )
2009-12-15 17:47:00 +00:00
if QGIS_14 : QMessageBox . information ( self , self . tr ( " Plugin uninstalled successfully " ) , self . tr ( " Plugin uninstalled successfully " ) )
else : QMessageBox . information ( self , self . tr ( " Plugin uninstalled successfully " ) , self . tr ( " Python plugin uninstalled. Note that you may need to restart Quantum GIS in order to remove it completely. " ) )
2009-04-09 00:19:51 +00:00
history . markChange ( key , ' D ' )
2008-09-10 20:26:08 +00:00
2008-11-13 01:17:18 +00:00
# ----------------------------------------- #
def repositoryTreeClicked ( self ) :
""" the repositoryTree has been clicked """
if self . treeRepositories . selectedItems ( ) :
self . buttonEditRep . setEnabled ( True )
self . buttonDeleteRep . setEnabled ( True )
else :
self . buttonEditRep . setEnabled ( False )
self . buttonDeleteRep . setEnabled ( False )
2008-09-10 20:26:08 +00:00
# ----------------------------------------- #
2009-03-20 22:08:03 +00:00
def changeCheckingPolicy ( self , policy ) :
""" the Checking On Start checkbox has been clicked """
if policy :
2008-09-10 20:26:08 +00:00
repositories . setCheckingOnStart ( True )
else :
repositories . setCheckingOnStart ( False )
2009-03-20 22:08:03 +00:00
# ----------------------------------------- #
def changeCheckingInterval ( self , interval ) :
""" the Checking on start interval combobox has been clicked """
intervals = [ 0 , 1 , 3 , 7 , 14 , 30 ]
repositories . setCheckingOnStartInterval ( intervals [ interval ] )
# ----------------------------------------- #
def changePluginPolicy ( self , state ) :
""" one of the plugin type radiobuttons has been clicked """
if not state : # radio button released
return
if self . radioPluginType0 . isChecked ( ) :
i = 1
elif self . radioPluginType1 . isChecked ( ) :
i = 2
else :
i = 3
settings = QSettings ( )
settings . setValue ( settingsGroup + " /allowedPluginType " , QVariant ( i ) )
2009-04-17 23:41:14 +00:00
plugins . rebuild ( )
2009-03-20 22:08:03 +00:00
self . populatePluginTree ( )
2012-06-06 21:47:55 +02:00
## depreciated in qgis 1.8 until we use 3rd party repos again
2008-09-10 20:26:08 +00:00
# ----------------------------------------- #
2012-06-06 21:47:55 +02:00
#def addKnownRepositories(self):
#""" update list of known repositories - in the future it will be replaced with an online fetching """
#message = self.tr("You are about to add several plugin repositories that are neither authorized nor supported by the Quantum GIS team. Plugin authors generally make efforts to ensure that their work is useful and safe, however, we can assume no responsibility for them.")
#if QMessageBox.question(self, self.tr("QGIS Python Plugin Installer"), message, QMessageBox.Ok, QMessageBox.Abort) == QMessageBox.Ok:
#repositories.addKnownRepos()
## refresh lists and populate widgets
#QApplication.setOverrideCursor(Qt.WaitCursor)
#self.getAllAvailablePlugins()
#plugins.rebuild()
#self.populateMostWidgets()
#self.populatePluginTree()
#QApplication.restoreOverrideCursor()
2008-09-10 20:26:08 +00:00
# ----------------------------------------- #
def addRepository ( self ) :
""" add repository button has been clicked """
dlg = QgsPluginInstallerRepositoryDialog ( self )
dlg . checkBoxEnabled . setCheckState ( Qt . Checked )
if not dlg . exec_ ( ) :
return
for i in repositories . all ( ) . values ( ) :
2009-03-20 22:08:03 +00:00
if dlg . editURL . text ( ) . trimmed ( ) == i [ " url " ] :
2008-09-10 20:26:08 +00:00
QMessageBox . warning ( self , self . tr ( " QGIS Python Plugin Installer " ) , self . tr ( " Unable to add another repository with the same URL! " ) )
return
settings = QSettings ( )
settings . beginGroup ( self . reposGroup )
reposName = dlg . editName . text ( )
2009-03-20 22:08:03 +00:00
reposURL = dlg . editURL . text ( ) . trimmed ( )
2008-09-10 20:26:08 +00:00
if repositories . all ( ) . has_key ( reposName ) :
reposName = reposName + " (2) "
# add to settings
settings . setValue ( reposName + " /url " , QVariant ( reposURL ) )
settings . setValue ( reposName + " /enabled " , QVariant ( bool ( dlg . checkBoxEnabled . checkState ( ) ) ) )
# refresh lists and populate widgets
QApplication . setOverrideCursor ( Qt . WaitCursor )
2009-04-17 23:41:14 +00:00
plugins . removeRepository ( reposName )
2008-09-10 20:26:08 +00:00
self . getAllAvailablePlugins ( )
2009-04-17 23:41:14 +00:00
plugins . rebuild ( )
2008-09-10 20:26:08 +00:00
self . populateMostWidgets ( )
self . populatePluginTree ( )
QApplication . restoreOverrideCursor ( )
# ----------------------------------------- #
def editRepository ( self ) :
""" edit repository button has been clicked """
checkState = { False : Qt . Unchecked , True : Qt . Checked }
current = self . treeRepositories . currentItem ( )
if current == None :
return
reposName = current . text ( 1 )
dlg = QgsPluginInstallerRepositoryDialog ( self )
dlg . editName . setText ( reposName )
dlg . editURL . setText ( repositories . all ( ) [ reposName ] [ " url " ] )
dlg . checkBoxEnabled . setCheckState ( checkState [ repositories . all ( ) [ reposName ] [ " enabled " ] ] )
if repositories . all ( ) [ reposName ] [ " valid " ] :
dlg . checkBoxEnabled . setEnabled ( True )
2012-06-06 21:47:55 +02:00
dlg . labelInfo . setText ( " " )
2008-09-10 20:26:08 +00:00
else :
dlg . checkBoxEnabled . setEnabled ( False )
2008-11-10 14:39:12 +00:00
dlg . labelInfo . setText ( self . tr ( " This repository is blocked due to incompatibility with your Quantum GIS version " ) )
2008-09-10 20:26:08 +00:00
dlg . labelInfo . setFrameShape ( QFrame . Box )
if not dlg . exec_ ( ) :
return # nothing to do if cancelled
for i in repositories . all ( ) . values ( ) :
2009-03-20 22:08:03 +00:00
if dlg . editURL . text ( ) . trimmed ( ) == i [ " url " ] and dlg . editURL . text ( ) . trimmed ( ) != repositories . all ( ) [ reposName ] [ " url " ] :
2008-09-10 20:26:08 +00:00
QMessageBox . warning ( self , self . tr ( " QGIS Python Plugin Installer " ) , self . tr ( " Unable to add another repository with the same URL! " ) )
return
# delete old repo from QSettings and create new one
settings = QSettings ( )
settings . beginGroup ( self . reposGroup )
settings . remove ( reposName )
newName = dlg . editName . text ( )
if repositories . all ( ) . has_key ( newName ) and newName != reposName :
newName = newName + " (2) "
2009-03-20 22:08:03 +00:00
settings . setValue ( newName + " /url " , QVariant ( dlg . editURL . text ( ) . trimmed ( ) ) )
2008-09-10 20:26:08 +00:00
settings . setValue ( newName + " /enabled " , QVariant ( bool ( dlg . checkBoxEnabled . checkState ( ) ) ) )
2009-03-20 22:08:03 +00:00
if dlg . editURL . text ( ) . trimmed ( ) == repositories . all ( ) [ reposName ] [ " url " ] and dlg . checkBoxEnabled . checkState ( ) == checkState [ repositories . all ( ) [ reposName ] [ " enabled " ] ] :
2008-09-10 20:26:08 +00:00
repositories . rename ( reposName , newName )
self . populateMostWidgets ( )
return # nothing else to do if only repository name was changed
# refresh lists and populate widgets
QApplication . setOverrideCursor ( Qt . WaitCursor )
2009-04-17 23:41:14 +00:00
plugins . removeRepository ( reposName )
2008-09-10 20:26:08 +00:00
self . getAllAvailablePlugins ( )
2009-04-17 23:41:14 +00:00
plugins . rebuild ( )
2008-09-10 20:26:08 +00:00
self . populateMostWidgets ( )
self . populatePluginTree ( )
QApplication . restoreOverrideCursor ( )
# ----------------------------------------- #
def deleteRepository ( self ) :
""" delete repository button has been clicked """
current = self . treeRepositories . currentItem ( )
if current == None :
return
2008-11-10 14:39:12 +00:00
warning = self . tr ( " Are you sure you want to remove the following repository? " ) + " \n " + current . text ( 1 )
2008-09-10 20:26:08 +00:00
if QMessageBox . warning ( self , self . tr ( " QGIS Python Plugin Installer " ) , warning , QMessageBox . Yes , QMessageBox . No ) == QMessageBox . No :
return
reposName = current . text ( 1 )
2009-04-17 23:41:14 +00:00
# delete from the settings, refresh data and repopulate all the widgets
2008-09-10 20:26:08 +00:00
settings = QSettings ( )
settings . beginGroup ( self . reposGroup )
settings . remove ( reposName )
2009-04-17 23:41:14 +00:00
repositories . remove ( reposName )
plugins . removeRepository ( reposName )
plugins . rebuild ( )
2008-09-10 20:26:08 +00:00
self . populateMostWidgets ( )
self . populatePluginTree ( )
2009-12-15 17:47:00 +00:00
# ----------------------------------------- #
def runHelp ( self ) :
""" open the context help browser """
QgsContextHelp . run ( " QgsPluginInstallerDialog " )
2008-09-10 20:26:08 +00:00
# ----------------------------------------- #
def reject ( self ) :
""" update the list of seen plugins before exit (both ' done ' and ' x ' buttons emit ' reject ' signal) """
plugins . updateSeenPluginsList ( )
QDialog . reject ( self )
# --- /class QgsPluginInstallerDialog ------------------------------------------------------------------------ #
2012-10-07 19:50:52 +03:00
class QgsPluginTreeItem ( QTreeWidgetItem ) :
def __init__ ( self , parent = None ) :
QTreeWidgetItem . __init__ ( self , parent )
def __lt__ ( self , otherItem ) :
column = self . treeWidget ( ) . sortColumn ( )
if column == 0 :
return self . data ( column , Qt . UserRole ) . toInt ( ) [ 0 ] < otherItem . data ( column , Qt . UserRole ) . toInt ( ) [ 0 ]
else :
return self . text ( column ) < otherItem . text ( column )