Index: /applications/editors/josm/plugins/wmsplugin/webkit-image.cpp
===================================================================
--- /applications/editors/josm/plugins/wmsplugin/webkit-image.cpp	(revision 19703)
+++ /applications/editors/josm/plugins/wmsplugin/webkit-image.cpp	(revision 19704)
@@ -11,8 +11,13 @@
 #include <QtCore/QFile>
 #include <QtCore/QString>
+#include <QtCore/QUrl>
 #include <QtWebKit/QWebPage>
 #include <QtWebKit/QWebFrame>
 #include <QtNetwork/QNetworkProxy>
 #include <QtCore/QProcess>
+#if QT_VERSION >= 0x040500
+#include <QDesktopServices>
+#include <QNetworkDiskCache>
+#endif
 
 /* using mingw to set binary mode */
@@ -76,23 +81,79 @@
   if(idx != -1)
   {
-     QString proxyHost;
-     int proxyPort = 8080;
-     QStringList tmpList = environment.at(idx).split("=");
-     QStringList host_port = tmpList.at(1).split(":");
-     proxyHost = host_port.at(0);
-     if(host_port.size() == 2)
-     {
-       bool ok;
-       int port = host_port.at(1).toInt(&ok);
-       if(ok)
-         proxyPort = port;
-     }
+    QString scheme = "http";   // default
+    QString proxyHost;
 
-     QNetworkProxy proxy;
-     proxy.setType(QNetworkProxy::HttpCachingProxy);
-     proxy.setHostName(proxyHost);
-     proxy.setPort(proxyPort);
-     page->networkAccessManager()->setProxy(proxy);
+    int proxyPort = 8080;
+    QStringList tmpList = environment.at(idx).split("=");
+
+#if QT_VERSION >= 0x040600  // Qt4.6: Use QUrl::fromUserInput
+    // set URL (and guess if proto scheme missing)
+    QUrl url (QUrl::fromUserInput(tmpList.at(1)));
+#else
+    // set URL
+    QUrl url (tmpList.at(1));
+#endif
+    if (url.isValid() && !url.host().isEmpty())
+    {
+      proxyHost = url.host();
+
+      if (url.port() != -1)
+        proxyPort = url.port();
+
+      if (!url.scheme().isEmpty())
+        scheme = url.scheme();
+
+      if (scheme == "http")   // we support only http
+      {
+        QNetworkProxy proxy;
+        proxy.setType(QNetworkProxy::HttpCachingProxy);
+        proxy.setHostName(proxyHost);
+        proxy.setPort(proxyPort);
+        if (!url.userName().isEmpty())
+          proxy.setUser(url.userName());
+        if (!url.password().isEmpty())
+          proxy.setPassword(url.password());
+        page->networkAccessManager()->setProxy(proxy);
+      }
+    }
+    else /* manual mode */
+    {
+      QStringList proto_host_port = tmpList.at(1).split("://");
+      QStringList host_port;
+      if (proto_host_port.size() == 2)  // string has proto
+      {
+        scheme = proto_host_port.at(0);
+        host_port = proto_host_port.at(1).split(":");
+      }
+      else  // no proto (or invalid format with several delimiters)
+      {
+        host_port = tmpList.at(1).split(":");
+      }
+      if (scheme == "http")   // we support only http
+      {
+        proxyHost = host_port.at(0);
+        if(host_port.size() == 2)
+        {
+          bool ok;
+          int port = host_port.at(1).toInt(&ok);
+          if(ok)
+            proxyPort = port;
+        }
+
+        QNetworkProxy proxy;
+        proxy.setType(QNetworkProxy::HttpCachingProxy);
+        proxy.setHostName(proxyHost);
+        proxy.setPort(proxyPort);
+        page->networkAccessManager()->setProxy(proxy);
+      }
+    }
   }
+
+#if QT_VERSION >= 0x040500
+  QNetworkDiskCache *diskCache = new QNetworkDiskCache(page);
+  QString location = QDesktopServices::storageLocation(QDesktopServices::CacheLocation);
+  diskCache->setCacheDirectory(location);
+  page->networkAccessManager()->setCache(diskCache);
+#endif
 
   QObject::connect(page, SIGNAL(loadFinished(bool)), s, SLOT(loaded(bool)));
