5 changes: 4 additions & 1 deletion python/pyplugin_installer/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@ SET(PY_PLUGININSTALLER_FILES
__init__.py
installer.py
installer_data.py
installer_gui.py
qgsplugininstallerinstallingdialog.py
qgsplugininstallerpluginerrordialog.py
qgsplugininstallerfetchingdialog.py
qgsplugininstallerrepositorydialog.py
unzip.py
version_compare.py
)
Expand Down
Empty file modified python/pyplugin_installer/__init__.py
100755 → 100644
Empty file.
73 changes: 38 additions & 35 deletions python/pyplugin_installer/installer.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,12 @@
from PyQt4.QtCore import *
from PyQt4.QtGui import *
from qgis.core import *
from qgis.utils import iface
from installer_gui import QgsPluginInstallerInstallingDialog, QgsPluginInstallerPluginErrorDialog
from installer_gui import QgsPluginInstallerFetchingDialog, QgsPluginInstallerRepositoryDialog
from installer_gui import removeDir
from qgis.utils import iface, startPlugin, unloadPlugin, loadPlugin, reloadPlugin, updateAvailablePlugins
from installer_data import *
from qgis.utils import startPlugin, unloadPlugin, loadPlugin, reloadPlugin, updateAvailablePlugins
from qgsplugininstallerinstallingdialog import QgsPluginInstallerInstallingDialog
from qgsplugininstallerpluginerrordialog import QgsPluginInstallerPluginErrorDialog
from qgsplugininstallerfetchingdialog import QgsPluginInstallerFetchingDialog
from qgsplugininstallerrepositorydialog import QgsPluginInstallerRepositoryDialog


# public instances:
Expand Down Expand Up @@ -71,15 +71,23 @@ def __init__(self):
repositories.setRepositoryData(key, "state", 3)

# look for obsolete plugins (the user-installed one is newer than core one)
for i in plugins.obsoletePlugins:
if i == "plugin_installer":
# uninstall the installer itself
QMessageBox.warning(iface.mainWindow(), self.tr("QGIS Plugin Installer update"), self.tr("The Plugin Installer has been updated. Please restart QGIS prior to using it"))
removeDir( QFileInfo(QgsApplication.qgisUserDbFilePath()).path() + "/python/plugins/" + plugins.localCache[i]["id"] )
return
else:
# don't remove brutally other plugins, just inform
QMessageBox.warning(iface.mainWindow(), self.tr("QGIS Plugin Conflict:")+" "+plugins.localCache[i]["name"], "<b>"+ plugins.localCache[i]["name"] + "</b><br/><br/>" + self.tr("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."))
for key in plugins.obsoletePlugins:
plugin = plugins.localCache[key]
msg = QMessageBox()
msg.setIcon( QMessageBox.Warning )
msg.setWindowTitle( self.tr("QGIS Python Plugin Installer") )
msg.addButton( self.tr("Uninstall (recommended)"), QMessageBox.AcceptRole )
msg.addButton( self.tr("I will uninstall it later"), QMessageBox.RejectRole )
msg.setText( "%s <b>%s</b><br/><br/>%s" % ( self.tr("Obsolete plugin:"), plugin["name"] , self.tr("QGIS has detected an obsolete plugin that masks its more recent version shipped with this copy of QGIS. This is likely due to files associated with a previous installation of QGIS. Do you want to remove the old plugin right now and unmask the more recent version?") ) )
msg.exec_()
if not msg.result():
# uninstall, update utils and reload if enabled
self.uninstallPlugin(key, quiet = True)
updateAvailablePlugins()
settings = QSettings()
if settings.value("/PythonPlugins/"+key, False, type=bool):
loadPlugin(key)
startPlugin(key)


# ----------------------------------------- #
Expand Down Expand Up @@ -346,35 +354,30 @@ def installPlugin(self, key, quiet=False):


# ----------------------------------------- #
def uninstallPlugin(self,key):
def uninstallPlugin(self, key, quiet=False):
""" Uninstall given plugin """
plugin = plugins.all()[key]
if plugins.all().has_key(key):
plugin = plugins.all()[key]
else:
plugin = plugins.localCache[key]
if not plugin:
return
warning = self.tr("Are you sure you want to uninstall the following plugin?") + "\n(" + plugin["name"] + ")"
if plugin["status"] == "orphan" and not plugin["error"]:
warning += "\n\n"+self.tr("Warning: this plugin isn't available in any accessible repository!")
if QMessageBox.warning(iface.mainWindow(), self.tr("QGIS Python Plugin Installer"), warning , QMessageBox.Yes, QMessageBox.No) == QMessageBox.No:
return
# 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
if not quiet:
warning = self.tr("Are you sure you want to uninstall the following plugin?") + "\n(" + plugin["name"] + ")"
if plugin["status"] == "orphan" and not plugin["error"]:
warning += "\n\n"+self.tr("Warning: this plugin isn't available in any accessible repository!")
if QMessageBox.warning(iface.mainWindow(), self.tr("QGIS Python Plugin Installer"), warning , QMessageBox.Yes, QMessageBox.No) == QMessageBox.No:
return
# unload the plugin
try:
unloadPlugin(key)
except:
pass
pluginDir = QFileInfo(QgsApplication.qgisUserDbFilePath()).path() + "/python/plugins/" + plugin["id"]
result = removeDir(pluginDir)
if result:
QMessageBox.warning(iface.mainWindow(), self.tr("Plugin uninstall failed"), result)
else:
# if the uninstalled plugin is the installer itself, reload it and quit
if key == "plugin_installer":
try:
QMessageBox.information(iface.mainWindow(), 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
# safe remove
try:
unloadPlugin(plugin["id"])
Expand Down
Empty file modified python/pyplugin_installer/installer_data.py
100755 → 100644
Empty file.
82 changes: 82 additions & 0 deletions python/pyplugin_installer/qgsplugininstallerfetchingdialog.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
# -*- coding:utf-8 -*-
"""
/***************************************************************************
qgsplugininstallerfetchingdialog.py
Plugin Installer module
-------------------
Date : June 2013
Copyright : (C) 2013 by Borys Jurgiel
Email : info at borysjurgiel dot pl
This module is based on former plugin_installer plugin:
Copyright (C) 2007-2008 Matthew Perry
Copyright (C) 2008-2013 Borys Jurgiel
***************************************************************************/
/***************************************************************************
* *
* 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. *
* *
***************************************************************************/
"""

import sys
import time

from PyQt4.QtGui import *

from ui_qgsplugininstallerfetchingbase import Ui_QgsPluginInstallerFetchingDialogBase
from installer_data import *




class QgsPluginInstallerFetchingDialog(QDialog, Ui_QgsPluginInstallerFetchingDialogBase):
# ----------------------------------------- #
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)
repositories.repositoryFetched.connect(self.repositoryFetched)
repositories.anythingChanged.connect(self.displayState)


# ----------------------------------------- #
def displayState(self,key,state,state2=None):
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")]
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()
106 changes: 4 additions & 102 deletions python/pyplugin_installer/installer_gui.py → ...ler/qgsplugininstallerinstallingdialog.py
100755 → 100644
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
# -*- coding:utf-8 -*-
"""
/***************************************************************************
Plugin Installer module
qgsplugininstallerinstallingdialog.py
Plugin Installer module
-------------------
Date : May 2013
Date : June 2013
Copyright : (C) 2013 by Borys Jurgiel
Email : info at borysjurgiel dot pl
Expand All @@ -23,99 +24,18 @@
***************************************************************************/
"""

import sys
import time

from PyQt4.QtCore import *
from PyQt4.QtGui import *

from qgis.core import QgsApplication, QgsContextHelp
from qgis.core import QgsApplication

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 installer_data import *
from unzip import unzip




# --- class QgsPluginInstallerFetchingDialog --------------------------------------------------------------- #
class QgsPluginInstallerFetchingDialog(QDialog, Ui_QgsPluginInstallerFetchingDialogBase):
# ----------------------------------------- #
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)
repositories.repositoryFetched.connect(self.repositoryFetched)
repositories.anythingChanged.connect(self.displayState)


# ----------------------------------------- #
def displayState(self,key,state,state2=None):
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")]
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 ------------------------------------------------------------- #
class QgsPluginInstallerRepositoryDialog(QDialog, Ui_QgsPluginInstallerRepositoryDetailsDialogBase):
# ----------------------------------------- #
def __init__(self, parent=None):
QDialog.__init__(self, parent)
self.setupUi(self)
self.editURL.setText("http://")
self.editName.textChanged.connect(self.textChanged)
self.editURL.textChanged.connect(self.textChanged)
self.textChanged(None)

# ----------------------------------------- #
def textChanged(self, string):
enable = (len(self.editName.text()) > 0 and len(self.editURL.text()) > 0)
self.buttonBox.button(QDialogButtonBox.Ok).setEnabled(enable)
# --- /class QgsPluginInstallerRepositoryDialog ------------------------------------------------------------ #





# --- class QgsPluginInstallerInstallingDialog --------------------------------------------------------------- #
class QgsPluginInstallerInstallingDialog(QDialog, Ui_QgsPluginInstallerInstallingDialogBase):
# ----------------------------------------- #
def __init__(self, parent, plugin):
Expand Down Expand Up @@ -200,21 +120,3 @@ def abort(self):
self.http.abort()
self.mResult = self.tr("Aborted by user")
self.reject()
# --- /class QgsPluginInstallerInstallingDialog ------------------------------------------------------------- #





# --- class QgsPluginInstallerPluginErrorDialog -------------------------------------------------------------- #
class QgsPluginInstallerPluginErrorDialog(QDialog, Ui_QgsPluginInstallerPluginErrorDialogBase):
# ----------------------------------------- #
def __init__(self, parent, errorMessage):
QDialog.__init__(self, parent)
self.setupUi(self)
if not errorMessage:
errorMessage = self.tr("no error message received")
self.textBrowser.setText(errorMessage)
# --- /class QgsPluginInstallerPluginErrorDialog ------------------------------------------------------------- #


Loading