def __sync_request(self, url):
        _url = QUrl(url)
        _request = QNetworkRequest(_url)
        self.__replies.append(_request)

        QgsNetworkAccessManager.instance().sslErrors.connect(self.__supress_ssl_errors)

        _reply = QgsNetworkAccessManager.instance().get(_request)

        # wait
        loop = QEventLoop()
        _reply.finished.connect(loop.quit)
        loop.exec_()
        _reply.finished.disconnect(loop.quit)
        QgsNetworkAccessManager.instance().sslErrors.disconnect(self.__supress_ssl_errors)
        loop = None

        error = _reply.error()
        if error != QNetworkReply.NoError:
            raise Exception(error)

        result_code = _reply.attribute(QNetworkRequest.HttpStatusCodeAttribute)

        result = _reply.readAll()
        self.__replies.append(_reply)
        _reply.deleteLater()

        if result_code in [301, 302, 307]:
            redirect_url = _reply.attribute(QNetworkRequest.RedirectionTargetAttribute)
            return self.__sync_request(redirect_url)
        else:
            return result
Example #2
0
    def testSetupProxy(self):
        """Test proxy setup"""
        settings = QgsSettings()
        settings.setValue("proxy/proxyEnabled", True)
        settings.setValue("proxy/proxyPort", '1234')
        settings.setValue("proxy/proxyHost", 'myproxyhostname.com')
        settings.setValue("proxy/proxyUser", 'username')
        settings.setValue("proxy/proxyPassword", 'password')
        settings.setValue("proxy/proxyExcludedUrls", "http://www.myhost.com|http://www.myotherhost.com")
        QgsNetworkAccessManager.instance().setupDefaultProxyAndCache()
        vl = QgsVectorLayer(TEST_DATA_DIR + '/' + 'lines.shp', 'proxy_test', 'ogr')
        self.assertTrue(vl.isValid())
        self.assertEqual(gdal.GetConfigOption("GDAL_HTTP_PROXY"), "myproxyhostname.com:1234")
        self.assertEqual(gdal.GetConfigOption("GDAL_HTTP_PROXYUSERPWD"), "username:password")

        settings.setValue("proxy/proxyEnabled", True)
        settings.remove("proxy/proxyPort")
        settings.setValue("proxy/proxyHost", 'myproxyhostname.com')
        settings.setValue("proxy/proxyUser", 'username')
        settings.remove("proxy/proxyPassword")
        settings.setValue("proxy/proxyExcludedUrls", "http://www.myhost.com|http://www.myotherhost.com")
        QgsNetworkAccessManager.instance().setupDefaultProxyAndCache()
        vl = QgsVectorLayer(TEST_DATA_DIR + '/' + 'lines.shp', 'proxy_test', 'ogr')
        self.assertTrue(vl.isValid())
        self.assertEqual(gdal.GetConfigOption("GDAL_HTTP_PROXY"), "myproxyhostname.com")
        self.assertEqual(gdal.GetConfigOption("GDAL_HTTP_PROXYUSERPWD"), "username")
Example #3
0
def DownLoadOverQT (dlURL, LokFileName):
# QGIS3:  funktioniert unter QGIS 3.x recht zuverlässig auch auf "eingeschränktem Rechner"
# - nutzt die Proxyeinstellungen von QGIS
# - funktioniert in QGIS selbst auch über HTTPS (es wird durch QGIS eiun Abfragefenster geöffnet)
# - bei extrem großen Dateien (z.B. 500MBYte) crasht es bei ReadAll()


# QGIS2:  funktioniert unter QGIS 2.x innerhalb von QGIS aktuell recht zuverlässig auch auf "eingeschränktem Rechner"
#         außerhalb hängt sich der Code auf "eingeschräktem Rechner" auf und bringt dann auch kein Ergebnis
#         Normalrechner funktioniert es 
    def WriteFile(LokFileName, content):
            # 1. Ziel löschen, wenn existent
            if path.exists(LokFileName):
                remove (LokFileName)
            out=open(LokFileName,'wb')
            out.write(content)
            out.close()

    def onfinish():
        WriteFile(LokFileName,reply.readAll());
        loop.quit()


    # 2. Download
    request = QNetworkRequest()
    request.setUrl(QUrl(dlURL))
    manager = QgsNetworkAccessManager.instance()
    
    reply = manager.get(request)
    reply.setParent(None)
    
    loop = QEventLoop()
    reply.finished.connect(onfinish)  
    loop.exec_() 
    
    # Wiederholung bei redirekt (13.08.18 Thüringen leitet an HTTPS weiter)
    status=reply.attribute(QNetworkRequest.HttpStatusCodeAttribute)
    if (status==301):
        redirectUrl = reply.attribute(request.RedirectionTargetAttribute)
        request = QNetworkRequest()
        request.setUrl(redirectUrl)
        manager = QgsNetworkAccessManager.instance()
        
        reply = manager.get(request)
        reply.setParent(None)
        
        loop = QEventLoop()
        reply.finished.connect(onfinish)  
        loop.exec_() 
    
    
    
    if path.exists(LokFileName):
        return path.getsize(LokFileName), reply.attribute(QNetworkRequest.HttpStatusCodeAttribute)
    else:
        return None, reply.attribute(QNetworkRequest.HttpStatusCodeAttribute)
    reply.deleteLater()
Example #4
0
    def sendVote(self, plugin_id, vote):
        """ send vote via the RPC """

        if not plugin_id or not vote:
            return False
        url = "http://plugins.qgis.org/plugins/RPC2/"
        params = "{\"id\":\"djangorpc\",\"method\":\"plugin.vote\",\"params\":[%s,%s]}" % (str(plugin_id), str(vote))
        req = QNetworkRequest(QUrl(url))
        req.setRawHeader("Content-Type", "application/json")
        QgsNetworkAccessManager.instance().post(req, params)
        return True
Example #5
0
    def sendVote(self, plugin_id, vote):
        """ send vote via the RPC """

        if not plugin_id or not vote:
            return False
        url = "http://plugins.qgis.org/plugins/RPC2/"
        params = {"id": "djangorpc", "method": "plugin.vote", "params": [str(plugin_id), str(vote)]}
        req = QNetworkRequest(QUrl(url))
        req.setRawHeader(b"Content-Type", b"application/json")
        QgsNetworkAccessManager.instance().post(req, bytes(json.dumps(params), "utf-8"))
        return True
Example #6
0
 def executeRequest (self, url, callback, post = None):
     self.messageBar.clearWidgets()
     self.cmbOfferings.setEnabled (False)
     self.tabWidget.setEnabled (False)
     
     if post:
         request = QNetworkRequest(url)
         request.setRawHeader('Content-Type', 'application/xml')
         self.reply = QgsNetworkAccessManager.instance().post(request,post)
     else:
         self.reply = QgsNetworkAccessManager.instance().get(QNetworkRequest(url))
         
     progressMessageBar = self.messageBar.createMessage(self.tr("Please wait while downloading"))
     progressBar = QtGui.QProgressBar(self)
     progressBar.setMinimum(0)
     progressBar.setFormat(self.tr("%v bytes downloaded!"))
     progressBar.setAlignment(QtCore.Qt.AlignLeft | QtCore.Qt.AlignVCenter)
     
     def updateProgress (read, total):
         try:
             progressBar.setMaximum (total)
             progressBar.setValue (read)
         except: pass
     updateProgress (0,0)
     self.reply.downloadProgress.connect (updateProgress)
     progressMessageBar.layout().addWidget(progressBar)
     
     btnAbort = QtGui.QPushButton(self.tr("Abort"))
     btnAbort.clicked.connect(self.reply.abort)
     progressMessageBar.layout().addWidget(btnAbort)
     
     fd, replyFilename = mkstemp(suffix=".xml", prefix = callback.__name__, dir = self.selectedWorkDir())
     os.close(fd)
     replyFile = open (replyFilename, "w")
     
     def replyReadyRead ():
         try: replyFile.write (self.reply.readAll())
         except: pass
     self.reply.readyRead.connect(replyReadyRead)
     
     def finishRequest ():
         replyFile.close()
         self.cmbOfferings.setEnabled (True)
         self.tabWidget.setEnabled(True)
         self.messageBar.clearWidgets()
         if self.reply.error() != QNetworkReply.NoError:
             self.messageBar.pushMessage(self.reply.errorString(), QgsMessageBar.CRITICAL)
         else:
             callback(replyFilename)
         self.reply.deleteLater()
     self.reply.finished.connect(finishRequest)
     
     self.messageBar.pushWidget(progressMessageBar, QgsMessageBar.INFO)
Example #7
0
    def __init__(self, url, output_path, progress_dialog=None):
        """Constructor of the class.

        .. versionchanged:: 3.3 removed manager parameter.

        :param url: URL of file.
        :type url: str

        :param output_path: Output path.
        :type output_path: str

        :param progress_dialog: Progress dialog widget.
        :type progress_dialog: QWidget
        """
        # noinspection PyArgumentList
        self.manager = QgsNetworkAccessManager.instance()
        self.url = QUrl(url)
        self.output_path = output_path
        self.progress_dialog = progress_dialog
        if self.progress_dialog:
            self.prefix_text = self.progress_dialog.labelText()
        self.output_file = None
        self.reply = None
        self.downloaded_file_buffer = None
        self.finished_flag = False
Example #8
0
 def __init__(self, server=None, projects_base=''):
     super(ProjectUpdater, self).__init__()
     self.updatethread = None
     self.server = server
     self.net = QgsNetworkAccessManager.instance()
     self.projects_base = projects_base
     self.create_worker()
Example #9
0
    def _getProxySettings(self):
        self.proxyEnabled = self.proxyHost = self.proxyPort = self.proxyUser = self.proxyPassword = None
        self.proxyUrl = ""
        proxyEnabled = self.s.value("proxy/proxyEnabled", "")
        if proxyEnabled == 1 or proxyEnabled == "true":
            self.proxyEnabled = True
            self.proxy_type = self.s.value("proxy/proxyType", "")
            self.proxyHost = self.s.value("proxy/proxyHost", "" )
            self.proxyPort = self.s.value("proxy/proxyPort", "" )
            self.proxyUser = self.s.value("proxy/proxyUser", "" )
            self.proxyPassword = self.s.value("proxy/proxyPassword", "" )

            if self.proxy_type == "DefaultProxy": 
               proxies = urllib.request.getproxies()
               if len(proxies) == 0:
                  qgsNetMan = QgsNetworkAccessManager.instance() 
                  proxy = qgsNetMan.proxy().applicationProxy() 
                  self.proxyHost = proxy.hostName() 
                  self.proxyPort = str(proxy.port()) 
                  self.proxyUser = proxy.user() 
                  self.proxyPassword = proxy.password() 

               elif len(proxies) > 0 and 'http' in list(proxies.keys()):
                  self.proxyUrl = proxies['http']
                  self.proxyUrlS = proxies['https']

            else:
               self.proxyUrl = "http://"
               if self.proxyUser and self.proxyPassword:
                   self.proxyUrl += self.proxyUser + ':' + self.proxyPassword + '@'
               self.proxyUrl += self.proxyHost + ':' + self.proxyPort
               self.proxyUrlS = self.proxyUrl.replace("http://", "https://")
 def __init__(self, url, auth_cfg=None):
     self._network_manager = QgsNetworkAccessManager.instance()
     self._network_finished = False
     self._network_timeout = False
     self._url = url
     self._auth_cfg = auth_cfg
     self._content = None
    def executeProcess(self, processUrl, requestXml):
        self._processExecuted = False
        self.noFilesToFetch = 0

        postData = QByteArray()
        postData.append(requestXml)
    
        scheme = processUrl.scheme()
        path = processUrl.path()
        server = processUrl.host()
        port = processUrl.port()
        
        processUrl.removeQueryItem('Request')
        processUrl.removeQueryItem('identifier')
        processUrl.removeQueryItem('Version')
        processUrl.removeQueryItem('Service')

        qDebug("Post URL=" + pystring(processUrl))
    
        thePostHttp = QgsNetworkAccessManager.instance()
        request = QNetworkRequest(processUrl)
        request.setHeader( QNetworkRequest.ContentTypeHeader, "text/xml" )
        #qDebug("Post REQUEST=" + pystring(postData))
        self.thePostReply = thePostHttp.post(request, postData)
        self.thePostReply.finished.connect(partial(self.resultHandler, self.thePostReply) )
 def __init__(self, parent=None):
     DlgWaiting.__init__(self, parent)
     self.safeties = None
     self.updatedSafeties = None
     self.saved_id = None
     self.saved_number = None
     self.saved_sopralluoghi = None
     self.manager = QgsNetworkAccessManager.instance();
     # clean listeners to avoid overlap 
     try:
         self.manager.authenticationRequired.disconnect()
     except:
         pass
     try:
         self.manager.finished.disconnect()
     except:
         pass
     # add new listeners
     self.manager.authenticationRequired.connect(self.authenticationRequired)
     # get connection conf
     settings = QSettings()
     self.safetyUrl = settings.value("/rt_geosisma_offline/safetyUrl", "/api/v1/safety/")
     self.sopralluoghiUrl = settings.value("/rt_geosisma_offline/sopralluoghiUrl", "/api/v1/sopralluoghi/")
     self.baseApiUrl = settings.value("/rt_geosisma_offline/baseApiUrl", "http://geosisma-test.faunalia.it/")
     self.teamUrl = settings.value("/rt_geosisma_offline/teamUrl", "/api/v1/team/")
     self.requestUrl = settings.value("/rt_geosisma_offline/requestUrl", "/api/v1/request/")
     self.attachmentUrl = settings.value("/rt_geosisma_offline/attachmentUrl", "/api/v1/attachment/")
     self.staffUrl = settings.value("/rt_geosisma_offline/staffUrl", "/api/v1/staff/")
Example #13
0
    def get_qgis_proxy(cls):
        s = cls.get_settings()
        proxy_enabled = s.value("proxy/proxyEnabled", u"", type=unicode)
        proxy_type = s.value("proxy/proxyType", u"", type=unicode)
        proxy_host = s.value("proxy/proxyHost", u"", type=unicode)
        proxy_port = s.value("proxy/proxyPort", u"", type=unicode)
        proxy_user = s.value("proxy/proxyUser", u"", type=unicode)
        proxy_password = s.value("proxy/proxyPassword", u"", type=unicode)

        if proxy_enabled == "true":
            if proxy_type == "DefaultProxy":
                qgsNetMan = QgsNetworkAccessManager.instance()
                proxy = qgsNetMan.proxy().applicationProxy()
                proxy_host = proxy.hostName()
                proxy_port = str(proxy.port())
                proxy_user = proxy.user()
                proxy_password = proxy.password()

            if proxy_type in ["DefaultProxy", "Socks5Proxy", "HttpProxy", "HttpCachingProxy"]:
                return (
                    proxy_host,
                    proxy_port,
                    proxy_user,
                    proxy_password
                )

        return ("", "", "", "")
    def __init__(self, resourceType):
        super(GetScriptsAndModelsDialog, self).__init__(iface.mainWindow())
        self.setupUi(self)
        self.manager = QgsNetworkAccessManager.instance()

        self.resourceType = resourceType
        if self.resourceType == self.MODELS:
            self.folder = ModelerUtils.modelsFolder()
            self.urlBase = 'https://raw.githubusercontent.com/qgis/QGIS-Processing/master/models/'
            self.icon = QIcon(os.path.join(pluginPath, 'images', 'model.png'))
        elif self.resourceType == self.SCRIPTS:
            self.folder = ScriptUtils.scriptsFolder()
            self.urlBase = 'https://raw.githubusercontent.com/qgis/QGIS-Processing/master/scripts/'
            self.icon = QIcon(os.path.join(pluginPath, 'images', 'script.png'))
        else:
            self.folder = RUtils.RScriptsFolder()
            self.urlBase = 'https://raw.githubusercontent.com/qgis/QGIS-Processing/master/rscripts/'
            self.icon = QIcon(os.path.join(pluginPath, 'images', 'r.png'))

        self.lastSelectedItem = None
        self.updateToolbox = False
        self.populateTree()
        self.buttonBox.accepted.connect(self.okPressed)
        self.buttonBox.rejected.connect(self.cancelPressed)
        self.tree.currentItemChanged.connect(self.currentItemChanged)
def search(url, callback):
    QgsMessageLog.logMessage("URL:" + url, "Gazetteer")

    def requestFinished(reply):
        # Disconnect from the signal
        networkAccessManager = QgsNetworkAccessManager.instance()
        networkAccessManager.finished.disconnect(requestFinished)
        # Handle the reply
        if reply.error() != QNetworkReply.NoError:
            QgsMessageLog.logMessage("Network error #{0}: {1}".format(reply.error(), reply.errorString()), "Gazetteer")
            callback(u'')
        else:
            charset = 'UTF-8'
            try:
                _, params = cgi.parse_header(reply.header(QNetworkRequest.ContentTypeHeader))
                charset = params['charset']
            except:
                pass
            QgsMessageLog.logMessage("charset: " + charset, "Gazetteer")
            data = unicode(reply.readAll(), charset)
            reply.deleteLater()
            callback(data)

    networkAccessManager = QgsNetworkAccessManager.instance()
    networkAccessManager.finished.connect(requestFinished)
    networkAccessManager.get(QNetworkRequest(QUrl(QUrl.fromPercentEncoding(url))))
    def __init__(self, resourceType):
        super(GetScriptsAndModelsDialog, self).__init__(iface.mainWindow())
        self.setupUi(self)
        self.manager = QgsNetworkAccessManager.instance()

        repoUrl = ProcessingConfig.getSetting(ProcessingConfig.MODELS_SCRIPTS_REPO)

        self.resourceType = resourceType
        if self.resourceType == self.MODELS:
            self.folder = ModelerUtils.modelsFolders()[0]
            self.urlBase = '{}/models/'.format(repoUrl)
            self.icon = QIcon(os.path.join(pluginPath, 'images', 'model.png'))
        elif self.resourceType == self.SCRIPTS:
            self.folder = ScriptUtils.scriptsFolders()[0]
            self.urlBase = '{}/scripts/'.format(repoUrl)
            self.icon = QIcon(os.path.join(pluginPath, 'images', 'script.png'))
        else:
            self.folder = RUtils.RScriptsFolders()[0]
            self.urlBase = '{}/rscripts/'.format(repoUrl)
            self.icon = QIcon(os.path.join(pluginPath, 'images', 'r.svg'))

        self.lastSelectedItem = None
        self.updateProvider = False
        self.populateTree()
        self.buttonBox.accepted.connect(self.okPressed)
        self.buttonBox.rejected.connect(self.cancelPressed)
        self.tree.currentItemChanged.connect(self.currentItemChanged)
Example #17
0
    def __init__(self, resourceType):
        super(GetScriptsAndModelsDialog, self).__init__(iface.mainWindow())
        self.setupUi(self)

        if hasattr(self.leFilter, "setPlaceholderText"):
            self.leFilter.setPlaceholderText(self.tr("Search..."))

        self.manager = QgsNetworkAccessManager.instance()

        self.resourceType = resourceType
        if self.resourceType == self.MODELS:
            self.folder = ModelerUtils.modelsFolders()[0]
            self.urlBase = "https://raw.githubusercontent.com/qgis/QGIS-Processing/master/models/"
            self.icon = QIcon(os.path.join(pluginPath, "images", "model.png"))
        elif self.resourceType == self.SCRIPTS:
            self.folder = ScriptUtils.scriptsFolders()[0]
            self.urlBase = "https://raw.githubusercontent.com/qgis/QGIS-Processing/master/scripts/"
            self.icon = QIcon(os.path.join(pluginPath, "images", "script.png"))
        else:
            self.folder = RUtils.RScriptsFolders()[0]
            self.urlBase = "https://raw.githubusercontent.com/qgis/QGIS-Processing/master/rscripts/"
            self.icon = QIcon(os.path.join(pluginPath, "images", "r.svg"))

        self.lastSelectedItem = None
        self.updateProvider = False
        self.data = None

        self.populateTree()
        self.buttonBox.accepted.connect(self.okPressed)
        self.buttonBox.rejected.connect(self.cancelPressed)
        self.tree.currentItemChanged.connect(self.currentItemChanged)
        self.leFilter.textChanged.connect(self.fillTree)
    def __init__(self, parent, plugin):
        QDialog.__init__(self, parent)
        self.setupUi(self)
        self.plugin = plugin
        self.mResult = ""
        self.progressBar.setRange(0, 0)
        self.progressBar.setFormat("%p%")
        self.labelName.setText(plugin["name"])
        self.buttonBox.clicked.connect(self.abort)

        url = QUrl(plugin["download_url"])

        fileName = plugin["filename"]
        tmpDir = QDir.tempPath()
        tmpPath = QDir.cleanPath(tmpDir + "/" + fileName)
        self.file = QFile(tmpPath)

        self.request = QNetworkRequest(url)
        authcfg = repositories.all()[plugin["zip_repository"]]["authcfg"]
        if authcfg and isinstance(authcfg, basestring):
            if not QgsAuthManager.instance().updateNetworkRequest(
                    self.request, authcfg.strip()):
                self.mResult = self.tr(
                    "Update of network request with authentication "
                    "credentials FAILED for configuration '{0}'").format(authcfg)
                self.request = None

        if self.request is not None:
            self.reply = QgsNetworkAccessManager.instance().get(self.request)
            self.reply.downloadProgress.connect(self.readProgress)
            self.reply.finished.connect(self.requestFinished)

            self.stateChanged(4)
Example #19
0
    def requestFetching(self, key, url=None, redirectionCounter=0):
        """ start fetching the repository given by key """
        self.mRepositories[key]["state"] = 1
        if not url:
            url = QUrl(self.mRepositories[key]["url"] + self.urlParams())
        # v=str(Qgis.QGIS_VERSION_INT)
        # url.addQueryItem('qgis', '.'.join([str(int(s)) for s in [v[0], v[1:3]]]) ) # don't include the bugfix version!

        self.mRepositories[key]["QRequest"] = QNetworkRequest(url)
        authcfg = self.mRepositories[key]["authcfg"]
        if authcfg and isinstance(authcfg, str):
            if not QgsApplication.authManager().updateNetworkRequest(
                    self.mRepositories[key]["QRequest"], authcfg.strip()):
                msg = QCoreApplication.translate(
                    "QgsPluginInstaller",
                    "Update of network request with authentication "
                    "credentials FAILED for configuration '{0}'").format(authcfg)
                iface.pluginManagerInterface().pushMessage(msg, Qgis.Warning)
                self.mRepositories[key]["QRequest"] = None
                return
        self.mRepositories[key]["QRequest"].setAttribute(QNetworkRequest.User, key)
        self.mRepositories[key]["xmlData"] = QgsNetworkAccessManager.instance().get(self.mRepositories[key]["QRequest"])
        self.mRepositories[key]["xmlData"].setProperty('reposName', key)
        self.mRepositories[key]["xmlData"].setProperty('redirectionCounter', redirectionCounter)
        self.mRepositories[key]["xmlData"].downloadProgress.connect(self.mRepositories[key]["Relay"].dataReadProgress)
        self.mRepositories[key]["xmlData"].finished.connect(self.xmlDownloaded)
Example #20
0
    def __init__(self, config):

        # init superclass, needed for Threading
        QObject.__init__(self)

        if not isinstance(config, ProviderConfig):
            raise TypeError('Provider expected a Provider specific Config, got a {} instead'.format(type(config)))
        self.config = config
        if self.config.url is None:
            raise TypeError('url in config is None')
        elif self.config.url == '' or len(self.config.url) < 10:
            raise TypeError('url in config is empty or too short to be true')
        elif not (self.config.url.startswith('file://')
                  or self.config.url.startswith('http://')
                  or self.config.url.startswith('https://')):
            raise TypeError(
                'url should start with: file://, http:// or https://, but starts with %s' % self.config.url[:8])

        self.network_manager = QgsNetworkAccessManager.instance()

        # while this provider is not ready, keep processing Qt events!!
        self.ready = False

        # data will always be a list of something, so do 'iter(data)' if you want to iterate over the items
        self.data = None
Example #21
0
    def __init__(self, resourceType):
        super(GetScriptsAndModelsDialog, self).__init__(iface.mainWindow())
        self.setupUi(self)

        if hasattr(self.leFilter, 'setPlaceholderText'):
            self.leFilter.setPlaceholderText(self.tr('Search...'))

        self.manager = QgsNetworkAccessManager.instance()

        repoUrl = ProcessingConfig.getSetting(ProcessingConfig.MODELS_SCRIPTS_REPO)

        self.resourceType = resourceType
        if self.resourceType == self.MODELS:
            self.folder = ModelerUtils.modelsFolders()[0]
            self.urlBase = '{}/models/'.format(repoUrl)
            self.icon = QgsApplication.getThemeIcon("/processingModel.svg")
        elif self.resourceType == self.SCRIPTS:
            self.folder = ScriptUtils.scriptsFolders()[0]
            self.urlBase = '{}/scripts/'.format(repoUrl)
            self.icon = QgsApplication.getThemeIcon("/processingScript.svg")

        self.lastSelectedItem = None
        self.updateProvider = False
        self.data = None

        self.populateTree()
        self.buttonBox.accepted.connect(self.okPressed)
        self.buttonBox.rejected.connect(self.cancelPressed)
        self.tree.currentItemChanged.connect(self.currentItemChanged)
        self.leFilter.textChanged.connect(self.fillTree)
Example #22
0
    def __init__(self, alg):
        super(AlgorithmDialogBase, self).__init__(iface.mainWindow())
        self.setupUi(self)

        self.settings = QSettings()
        self.restoreGeometry(self.settings.value("/Processing/dialogBase", QByteArray()))

        self.executed = False
        self.mainWidget = None
        self.alg = alg

        # Rename OK button to Run
        self.btnRun = self.buttonBox.button(QDialogButtonBox.Ok)
        self.btnRun.setText(self.tr('Run'))

        self.btnClose = self.buttonBox.button(QDialogButtonBox.Close)

        self.setWindowTitle(AlgorithmClassification.getDisplayName(self.alg))

        desktop = QDesktopWidget()
        if desktop.physicalDpiX() > 96:
            self.textHelp.setZoomFactor(desktop.physicalDpiX() / 96)

        algHelp = self.alg.shortHelp()
        if algHelp is None:
            self.textShortHelp.setVisible(False)
        else:
            self.textShortHelp.document().setDefaultStyleSheet('''.summary { margin-left: 10px; margin-right: 10px; }
                                                    h2 { color: #555555; padding-bottom: 15px; }
                                                    a { text-decoration: none; color: #3498db; font-weight: bold; }
                                                    p { color: #666666; }
                                                    b { color: #333333; }
                                                    dl dd { margin-bottom: 5px; }''')
            self.textShortHelp.setHtml(algHelp)

        self.textShortHelp.setOpenLinks(False)

        def linkClicked(url):
            webbrowser.open(url.toString())
        self.textShortHelp.anchorClicked.connect(linkClicked)

        self.textHelp.page().setNetworkAccessManager(QgsNetworkAccessManager.instance())

        isText, algHelp = self.alg.help()
        if algHelp is not None:
            algHelp = algHelp if isText else QUrl(algHelp)
            try:
                if isText:
                    self.textHelp.setHtml(algHelp)
                else:
                    self.textHelp.settings().clearMemoryCaches()
                    self.textHelp.load(algHelp)
            except:
                self.tabWidget.removeTab(2)
        else:
            self.tabWidget.removeTab(2)

        self.showDebug = ProcessingConfig.getSetting(
            ProcessingConfig.SHOW_DEBUG_IN_DIALOG)
Example #23
0
    def replyFinished(self):
        reply = self.sender()
        url = reply.request().url().toString()
        self.log("replyFinished: %s" % url)
        if not url in self.fetchedFiles:
            self.fetchedFiles[url] = None
        self.requestingUrls.remove(url)
        self.replies.remove(reply)
        isFromCache = 0
        httpStatusCode = reply.attribute(QNetworkRequest.HttpStatusCodeAttribute)
        if reply.error() == QNetworkReply.NoError:
            self.fetchSuccesses += 1
            if reply.attribute(QNetworkRequest.SourceIsFromCacheAttribute):
                self.cacheHits += 1
                isFromCache = 1
            elif not reply.hasRawHeader("Cache-Control"):
                cache = QgsNetworkAccessManager.instance().cache()
                if cache:
                    metadata = cache.metaData(reply.request().url())
                    # self.log("Expiration date: " + metadata.expirationDate().toString().encode("utf-8"))
                    if metadata.expirationDate().isNull():
                        metadata.setExpirationDate(
                            QDateTime.currentDateTime().addSecs(self.DEFAULT_CACHE_EXPIRATION * 60 * 60)
                        )
                        cache.updateMetaData(metadata)
                        self.log(
                            "Default expiration date has been set: %s (%d h)" % (url, self.DEFAULT_CACHE_EXPIRATION)
                        )

            if reply.isReadable():
                data = reply.readAll()
                self.fetchedFiles[url] = data
            else:
                qDebug("http status code: " + str(httpStatusCode))
        else:
            if self.sync and httpStatusCode == 404:
                self.fetchedFiles[url] = self.NOT_FOUND
            self.fetchErrors += 1
            if self.errorStatus == self.NO_ERROR:
                self.errorStatus = self.UNKNOWN_ERROR

        self.emit(SIGNAL("replyFinished(QString, int, int)"), url, reply.error(), isFromCache)
        reply.deleteLater()

        if debug_mode:
            qDebug("queue: %d, requesting: %d" % (len(self.queue), len(self.requestingUrls)))

        if len(self.queue) + len(self.requestingUrls) == 0:
            # all replies have been received
            if self.sync:
                self.logT("eventLoop.quit()")
                self.eventLoop.quit()
            else:
                self.timer.stop()
        elif len(self.queue) > 0:
            # start fetching the next file
            self.fetchNext()
        self.log("replyFinished End: %s" % url)
    def __init__(self, alg):
        super(AlgorithmDialogBase, self).__init__(iface.mainWindow())
        self.setupUi(self)

        self.settings = QSettings()
        self.restoreGeometry(self.settings.value("/Processing/dialogBase", QByteArray()))

        self.executed = False
        self.mainWidget = None
        self.alg = alg

        # Rename OK button to Run
        self.btnRun = self.buttonBox.button(QDialogButtonBox.Ok)
        self.btnRun.setText(self.tr('Run'))

        self.btnClose = self.buttonBox.button(QDialogButtonBox.Close)

        self.setWindowTitle(self.alg.displayName())

        # ~ desktop = QDesktopWidget()
        # ~ if desktop.physicalDpiX() > 96:
        # ~ self.txtHelp.setZoomFactor(desktop.physicalDpiX() / 96)

        algHelp = self.alg.shortHelp()
        if algHelp is None:
            self.textShortHelp.setVisible(False)
        else:
            self.textShortHelp.document().setDefaultStyleSheet('''.summary { margin-left: 10px; margin-right: 10px; }
                                                    h2 { color: #555555; padding-bottom: 15px; }
                                                    a { text-decoration: none; color: #3498db; font-weight: bold; }
                                                    p { color: #666666; }
                                                    b { color: #333333; }
                                                    dl dd { margin-bottom: 5px; }''')
            self.textShortHelp.setHtml(algHelp)

        self.textShortHelp.setOpenLinks(False)

        def linkClicked(url):
            webbrowser.open(url.toString())

        self.textShortHelp.anchorClicked.connect(linkClicked)

        isText, algHelp = self.alg.help()
        if algHelp is not None:
            algHelp = algHelp if isText else QUrl(algHelp)
            try:
                if isText:
                    self.txtHelp.setHtml(algHelp)
                else:
                    html = self.tr('<p>Downloading algorithm help... Please wait.</p>')
                    self.txtHelp.setHtml(html)
                    rq = QNetworkRequest(algHelp)
                    self.reply = QgsNetworkAccessManager.instance().get(rq)
                    self.reply.finished.connect(self.requestFinished)
            except Exception, e:
                self.tabWidget.removeTab(2)
    def fetchResult(self, encoding, schema,  fileLink, identifier):
        self.noFilesToFetch += 1
        url = QUrl(fileLink)
        self.myHttp = QgsNetworkAccessManager.instance()
        self.theReply = self.myHttp.get(QNetworkRequest(url))
        self.emit(SIGNAL("fetchingResult(int)"), self.noFilesToFetch)

        # Append encoding to 'finished' signal parameters
        self.encoding = encoding
        self.schema = schema
        self.theReply.finished.connect(partial(self.getResultFile, identifier, self.mimeType, encoding, schema,  self.theReply))
Example #26
0
 def testProxyIsUpdated(self):
     """
     Test that proxy is updated
     """
     authm = QgsApplication.authManager()
     nam = QgsNetworkAccessManager.instance()
     proxy = nam.proxy()
     self.assertEqual(proxy.password(), '')
     self.assertEqual(proxy.user(), '')
     self.assertTrue(authm.updateNetworkProxy(proxy, self.auth_config.id()))
     self.assertEqual(proxy.user(), self.username)
     self.assertEqual(proxy.password(), self.password)
Example #27
0
  def _replyFinished(self):
    reply = self.sender()
    url = reply.request().url().toString()
    if url not in self.fetchedFiles:
      self.fetchedFiles[url] = None

    if url in self.requestingReplies:
      del self.requestingReplies[url]

    httpStatusCode = reply.attribute(QNetworkRequest.HttpStatusCodeAttribute)
    if reply.error() == QNetworkReply.NoError:
      self._successes += 1

      if reply.attribute(QNetworkRequest.SourceIsFromCacheAttribute):
        self._cacheHits += 1

      elif not reply.hasRawHeader("Cache-Control"):
        cache = QgsNetworkAccessManager.instance().cache()
        if cache:
          metadata = cache.metaData(reply.request().url())
          if metadata.expirationDate().isNull():
            metadata.setExpirationDate(QDateTime.currentDateTime().addSecs(self.defaultCacheExpiration * 3600))
            cache.updateMetaData(metadata)
            self.log("Default expiration date has been set: %s (%d h)" % (url, self.defaultCacheExpiration))

      if reply.isReadable():
        data = reply.readAll()
        self.fetchedFiles[url] = data
      else:
        qDebug("http status code: " + str(httpStatusCode))

    else:
      self._errors += 1
      if self.errorStatus == self.NO_ERROR:
        self.errorStatus = self.UNKNOWN_ERROR

    self.replyFinished.emit(url)
    reply.deleteLater()

    if len(self.queue) + len(self.requestingReplies) == 0:
      # all replies have been received
      if self.sync:
        self.logT("eventLoop.quit()")
        self.eventLoop.quit()
      else:
        self.timer.stop()

      self.allRepliesFinished.emit()

    elif len(self.queue) > 0:
      # start fetching the next file
      self.fetchNext()
    def fetchResult(self, encoding, schema,  fileLink, identifier, mimeType):
        self.noFilesToFetch += 1

        url = QUrl(fileLink)
        self.myHttp = QgsNetworkAccessManager.instance()
        self.theReply = self.myHttp.get(QNetworkRequest(url))
        self.fetchingResult.emit(self.noFilesToFetch)

        # Append encoding to 'finished' signal parameters
        self.encoding = encoding
        self.schema = schema
        self.theReply.finished.connect(partial(self.getResultFile, identifier, mimeType, encoding, schema,  self.theReply))
        self.theReply.downloadProgress.connect(lambda done,  all,  status="download": self.showProgressBar(done,  all,  status)) 
Example #29
0
  def requestFetching(self,key):
    """ start fetching the repository given by key """
    self.mRepositories[key]["state"] = 1
    url = QUrl(self.mRepositories[key]["url"] + self.urlParams() )
    #v=str(QGis.QGIS_VERSION_INT)
    #url.addQueryItem('qgis', '.'.join([str(int(s)) for s in [v[0], v[1:3]]]) ) # don't include the bugfix version!

    self.mRepositories[key]["QRequest"] = QNetworkRequest(url)
    self.mRepositories[key]["QRequest"].setAttribute( QNetworkRequest.User, key)
    self.mRepositories[key]["xmlData"] = QgsNetworkAccessManager.instance().get( self.mRepositories[key]["QRequest"] )
    self.mRepositories[key]["xmlData"].setProperty( 'reposName', key)
    self.mRepositories[key]["xmlData"].downloadProgress.connect( self.mRepositories[key]["Relay"].dataReadProgress )
    self.mRepositories[key]["xmlData"].finished.connect( self.xmlDownloaded )
Example #30
0
    def fetchNext(self):
        if len(self.queue) == 0:
            return
        url = self.queue.pop(0)
        self.log("fetchNext: %s" % url)

        request = QNetworkRequest(QUrl(url))
        request.setRawHeader("User-Agent", self.userAgent)
        reply = QgsNetworkAccessManager.instance().get(request)
        reply.finished.connect(self.replyFinishedSlot)
        self.requestingUrls.append(url)
        self.replies.append(reply)
        return reply