]> git.sur5r.net Git - minitube/commitdiff
System proxy on the Mac
authorFlavio Tordini <flavio.tordini@gmail.com>
Mon, 7 Sep 2009 08:37:33 +0000 (10:37 +0200)
committerFlavio Tordini <flavio.tordini@gmail.com>
Mon, 7 Sep 2009 08:37:33 +0000 (10:37 +0200)
src/global.h

index c96d3d1054c92946394c74fd671c227328dd9fe3..4f64187dcabf6a5b71cc407a1dda2eee9a084fe4 100644 (file)
@@ -5,6 +5,7 @@
 #include <QStringList>
 #include <QNetworkProxy>
 #include <QNetworkAccessManager>
+#include <QNetworkProxyFactory>
 #include <cstdlib>
 #include "networkaccess.h"
 
@@ -26,6 +27,31 @@ namespace The {
         return g_menus;
     }
 
+    void maybeSetSystemProxy() {
+
+        QNetworkProxyQuery proxyQuery(QUrl("http://www"));
+        proxyQuery.setProtocolTag("http");
+        QList<QNetworkProxy> proxylist = QNetworkProxyFactory::systemProxyForQuery(proxyQuery);
+
+        for (int i = 0; i < proxylist.count(); i++) {
+            QNetworkProxy proxy = proxylist.at(i);
+
+            /*
+            qDebug() << i << " type:"<< proxy.type();
+            qDebug() << i << " host:" << proxy.hostName();
+            qDebug() << i << " port:" << proxy.port();
+            qDebug() << i << " user:" << proxy.user();
+            qDebug() << i << " pass:" << proxy.password();
+            */
+
+            if (!proxy.hostName().isEmpty()) {
+                qDebug() << "Using proxy:" << proxy.hostName() << proxy.port();
+                QNetworkProxy::setApplicationProxy(proxy);
+                return;
+            }
+        }
+    }
+
     void networkHttpProxySetting() {
         char *http_proxy_env;
         http_proxy_env = std::getenv("http_proxy");
@@ -98,6 +124,7 @@ namespace The {
     QNetworkAccessManager* networkAccessManager() {
         if (!nam) {
             networkHttpProxySetting();
+            maybeSetSystemProxy();
             nam = new QNetworkAccessManager();
 
             // A simple disk based cache