2009-12-15 17:47:00 +00:00
# -*- coding: utf-8 -*-
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
2008-01-25 16:30:35 +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
"""
2008-10-31 20:06:55 +00:00
2007-11-17 19:03:03 +00:00
from PyQt4 . QtCore import *
from PyQt4 . QtGui import *
from qgis . core import *
2008-09-10 20:26:08 +00:00
from installer_gui import *
from installer_data import *
import resources_rc
2007-11-17 19:03:03 +00:00
2008-11-10 14:39:12 +00:00
class InstallerPlugin ( ) :
2007-11-17 19:03:03 +00:00
# ----------------------------------------- #
def __init__ ( self , iface ) :
self . iface = iface
2008-12-14 16:23:38 +00:00
setIface ( self . iface ) #pass self.iface to installer_data module (needed for plugin loading & testing)
2010-10-31 23:36:26 +00:00
self . mainWindow = self . iface . mainWindow
2010-06-28 19:49:28 +00:00
self . guiDlg = None
2007-11-17 19:03:03 +00:00
2009-03-20 22:08:03 +00:00
2009-03-23 13:18:27 +00:00
# ----------------------------------------- #
def setCurrentTheme ( self , theThemeName ) :
""" Set icons to the current theme """
self . action . setIcon ( self . getThemeIcon ( " plugin_installer.png " ) )
2009-03-20 22:08:03 +00:00
# ----------------------------------------- #
def getThemeIcon ( self , theName ) :
2009-03-23 13:18:27 +00:00
""" get the icon from the best available theme """
2009-03-20 22:08:03 +00:00
myCurThemePath = QgsApplication . activeThemePath ( ) + " /plugins/ " + theName ;
myDefThemePath = QgsApplication . defaultThemePath ( ) + " /plugins/ " + theName ;
myQrcPath = " :/plugins/installer/ " + theName ;
if QFile . exists ( myCurThemePath ) :
return QIcon ( myCurThemePath )
elif QFile . exists ( myDefThemePath ) :
return QIcon ( myDefThemePath )
elif QFile . exists ( myQrcPath ) :
return QIcon ( myQrcPath )
else :
return QIcon ( )
2007-11-17 19:03:03 +00:00
# ----------------------------------------- #
def initGui ( self ) :
2008-09-10 20:26:08 +00:00
""" create action that will start plugin window and then add it to menu """
2009-03-20 22:08:03 +00:00
self . action = QAction ( self . getThemeIcon ( " plugin_installer.png " ) , QCoreApplication . translate ( " QgsPluginInstaller " , " Fetch Python Plugins... " ) , self . mainWindow ( ) )
2008-09-10 20:26:08 +00:00
self . action . setWhatsThis ( QCoreApplication . translate ( " QgsPluginInstaller " , " Install more plugins from remote repositories " ) )
self . action . setStatusTip ( QCoreApplication . translate ( " QgsPluginInstaller " , " Install more plugins from remote repositories " ) )
2010-10-31 23:36:26 +00:00
nextAction = self . iface . actionManagePlugins ( )
self . iface . pluginMenu ( ) . insertAction ( nextAction , self . action )
2009-06-23 12:03:18 +00:00
QObject . connect ( self . action , SIGNAL ( " triggered() " ) , self . run )
2009-03-23 13:18:27 +00:00
QObject . connect ( self . iface , SIGNAL ( " currentThemeChanged ( QString ) " ) , self . setCurrentTheme )
2008-09-10 20:26:08 +00:00
self . statusLabel = None
repositories . load ( )
2009-04-17 23:41:14 +00:00
plugins . getAllInstalled ( )
2008-10-31 20:06:55 +00:00
2009-03-20 22:08:03 +00:00
if repositories . checkingOnStart ( ) and repositories . timeForChecking ( ) and repositories . allEnabled ( ) :
2008-09-10 20:26:08 +00:00
self . statusLabel = QLabel ( QCoreApplication . translate ( " QgsPluginInstaller " , " Looking for new plugins... " ) , self . mainWindow ( ) . statusBar ( ) )
self . mainWindow ( ) . statusBar ( ) . insertPermanentWidget ( 0 , self . statusLabel )
2009-03-20 22:08:03 +00:00
QObject . connect ( self . statusLabel , SIGNAL ( " linkActivated (QString) " ) , self . preRun )
2008-09-10 20:26:08 +00:00
QObject . connect ( repositories , SIGNAL ( " checkingDone() " ) , self . checkingDone )
for key in repositories . allEnabled ( ) :
repositories . requestFetching ( key )
else :
for key in repositories . allEnabled ( ) :
repositories . setRepositoryData ( key , " state " , 3 )
2009-04-17 23:41:14 +00:00
for i in plugins . obsoletePlugins :
2010-11-01 00:52:20 +00:00
if i == " plugin_installer " :
# uninstall the installer itself
QMessageBox . warning ( self . mainWindow ( ) , QCoreApplication . translate ( " QgsPluginInstaller " , " QGIS Plugin Installer update " ) , QCoreApplication . translate ( " QgsPluginInstaller " , " The Plugin Installer has been updated. Please restart QGIS prior to using it " ) )
removeDir ( QFileInfo ( QgsApplication . qgisUserDbFilePath ( ) ) . path ( ) + " /python/plugins/ " + plugins . localCache [ i ] [ " localdir " ] )
2012-12-10 00:12:07 +01:00
return
2010-11-01 00:52:20 +00:00
else :
QMessageBox . warning ( self . mainWindow ( ) , QCoreApplication . translate ( " QgsPluginInstaller " , " QGIS Plugin Conflict: " ) + " " + plugins . localCache [ i ] [ " name " ] , " <b> " + plugins . localCache [ i ] [ " name " ] + " </b><br/><br/> " + QCoreApplication . translate ( " QgsPluginInstaller " , " The Plugin Installer has detected an obsolete plugin which masks a newer version shipped with this QGIS version. This is likely due to files associated with a previous installation of QGIS. Please use the Plugin Installer to remove that older plugin in order to unmask the newer version shipped with this copy of QGIS. " ) )
2009-04-17 23:41:14 +00:00
2008-09-10 20:26:08 +00:00
# ----------------------------------------- #
def checkingDone ( self ) :
""" display the notify label if any updates or news available """
if not self . statusLabel :
return
# look for news in the repositories
plugins . markNews ( )
status = " "
# first check for news
for key in plugins . all ( ) :
if plugins . all ( ) [ key ] [ " status " ] == " new " :
status = QCoreApplication . translate ( " QgsPluginInstaller " , " There is a new plugin available " )
# then check for updates (and eventually overwrite status)
for key in plugins . all ( ) :
if plugins . all ( ) [ key ] [ " status " ] == " upgradeable " :
status = QCoreApplication . translate ( " QgsPluginInstaller " , " There is a plugin update available " )
# finally set the notify label
if status :
self . statusLabel . setText ( u ' <a href= " # " > %s </a> ' % status )
else :
self . mainWindow ( ) . statusBar ( ) . removeWidget ( self . statusLabel )
self . statusLabel = None
2007-11-17 19:03:03 +00:00
# ----------------------------------------- #
def unload ( self ) :
2008-09-10 20:26:08 +00:00
""" remove the menu item and notify label """
2010-06-17 19:02:08 +00:00
# kill pending http requests
for key in repositories . all ( ) :
repositories . killConnection ( key )
2010-10-31 23:36:26 +00:00
self . iface . pluginMenu ( ) . removeAction ( self . action )
2008-09-10 20:26:08 +00:00
if self . statusLabel :
self . mainWindow ( ) . statusBar ( ) . removeWidget ( self . statusLabel )
2010-06-28 19:49:28 +00:00
if self . guiDlg :
self . guiDlg . close ( )
2008-09-10 20:26:08 +00:00
2007-11-17 19:03:03 +00:00
# ----------------------------------------- #
2009-03-20 22:08:03 +00:00
def preRun ( self , * params ) :
""" stupid method to get rid of the string value """
self . run ( )
# ----------------------------------------- #
def run ( self , parent = None ) :
2008-09-10 20:26:08 +00:00
""" create and show a configuration dialog """
QApplication . setOverrideCursor ( Qt . WaitCursor )
if self . statusLabel :
self . mainWindow ( ) . statusBar ( ) . removeWidget ( self . statusLabel )
self . statusLabel = None
2009-03-20 22:08:03 +00:00
if not parent :
parent = self . mainWindow ( )
2012-12-10 00:12:07 +01:00
2008-09-10 20:26:08 +00:00
for key in repositories . all ( ) :
if repositories . all ( ) [ key ] [ " state " ] == 3 : # if state = 3 (error), try to fetch once again
repositories . requestFetching ( key )
if repositories . fetchingInProgress ( ) :
2009-03-20 22:08:03 +00:00
self . fetchDlg = QgsPluginInstallerFetchingDialog ( parent )
2008-09-10 20:26:08 +00:00
self . fetchDlg . exec_ ( )
del self . fetchDlg
for key in repositories . all ( ) :
repositories . killConnection ( key )
QApplication . restoreOverrideCursor ( )
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 ( parent , QCoreApplication . translate ( " QgsPluginInstaller " , " QGIS Python Plugin Installer " ) , QCoreApplication . translate ( " QgsPluginInstaller " , " Error reading repository: " ) + QString ( ' %s \n %s ' % ( key , repositories . all ( ) [ key ] [ " error " ] ) ) )
if QgsApplication . keyboardModifiers ( ) == Qt . KeyboardModifiers ( Qt . ShiftModifier ) :
keepQuiet = True
2008-09-10 20:26:08 +00:00
2012-01-06 19:34:34 +01:00
self . guiDlg = QgsPluginInstallerDialog ( parent )
2008-09-10 20:26:08 +00:00
self . guiDlg . show ( )
2009-04-09 00:19:51 +00:00
# ----------------------------------------- #
def newlyInstalledPlugins ( self ) :
""" return the list of newly installed plugins for further loading """
return history . toList ( " A " )
# ----------------------------------------- #
def newlyUninstalledPlugins ( self ) :
""" return the list of newly uninstalled plugins for further unloading """
return history . toList ( " D " )
# ----------------------------------------- #
def newlyReinstalledPlugins ( self ) :
""" return the list of newly reinstalled plugins for further reloading """
return history . toList ( " R " )
# ----------------------------------------- #
def resetNewlyProcessedPlugins ( self ) :
""" clear the dict of newly processed plugins """
2009-10-04 12:12:01 +00:00
history . clear ( )