Setting proxy parameter in qgis plugins. How to.

For those who are interested I found to set proxy settings from within qgis plugin in a user-transparent way. This is useful if you plan to use urllib or QwebWiew in your plugins. Using Qsetting function is possible to read and write user application options setting stored in registry from qgis application. The problem is that registry keys use is not documented, but digging into qgis source is possible to find them and use it in plugin for other purpouse. Here is a block of code to properly set Proxy parameters.

# procedure to set proxy if needed
    s =QSettings()#getting proxy from qgis options settings
    proxyEnabled = s.value("proxy/proxyEnabled","")
    proxyType = s.value("proxy/proxyType","")
    proxyHost = s.value("proxy/proxyHost","")
    proxyPort = s.value("proxy/proxyPort","")
    proxyUser = s.value("proxy/proxyUser","")
    proxyPassword = s.value("proxy/proxyPassword","")if proxyEnabled =="true":# test if there are proxy settings
       proxy =QNetworkProxy()if proxyType =="DefaultProxy":
           proxy.setType(QNetworkProxy.DefaultProxy)elif proxyType =="Socks5Proxy":
           proxy.setType(QNetworkProxy.Socks5Proxy)elif proxyType =="HttpProxy":
           proxy.setType(QNetworkProxy.HttpProxy)elif proxyType =="HttpCachingProxy":
           proxy.setType(QNetworkProxy.HttpCachingProxy)elif proxyType =="FtpCachingProxy":

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s