]> git.sur5r.net Git - minitube/blobdiff - src/global.h
Merge commit 'refs/merge-requests/4' of git://gitorious.org/minitube/minitube
[minitube] / src / global.h
index 2736ac1cbbcc3959e9d940077f564e0a3d6fe996..502e329f9f3a9f24aa6eca2bed975490ad556a82 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");
@@ -41,6 +67,10 @@ namespace The {
             QString http_proxy = QString(http_proxy_env);
             http_proxy.remove(QRegExp("^http://"));
 
+            // Remove trailing slash, if any
+            // Fix by Eduardo Suarez-Santana
+            http_proxy.remove(QRegExp("/$"));
+
             // parse username and password
             if (http_proxy.contains(QChar('@'))) {
                 QStringList http_proxy_list = http_proxy.split(QChar('@'));
@@ -65,10 +95,12 @@ namespace The {
                 proxy_port = http_proxy_list[1];
             }
 
+            /*
             qDebug() << "proxy_host: " << proxy_host;
             qDebug() << "proxy_port: " << proxy_port;
             qDebug() << "proxy_user: " << proxy_user;
             qDebug() << "proxy_pass: " << proxy_pass;
+            */
 
             // set proxy setting
             if (!proxy_host.isEmpty()) {
@@ -84,6 +116,8 @@ namespace The {
                 if (!proxy_pass.isEmpty()) {
                     proxy.setPassword(proxy_pass);
                 }
+
+                qDebug() << "Using HTTP proxy:" << http_proxy_env;
                 QNetworkProxy::setApplicationProxy(proxy);
             }
         }
@@ -94,6 +128,7 @@ namespace The {
     QNetworkAccessManager* networkAccessManager() {
         if (!nam) {
             networkHttpProxySetting();
+            maybeSetSystemProxy();
             nam = new QNetworkAccessManager();
 
             // A simple disk based cache
@@ -110,18 +145,13 @@ namespace The {
 
     static NetworkAccess *g_http = 0;
     NetworkAccess* http() {
-        if (!g_http)
+        if (!g_http) {
+            // qDebug() << "Creating NetworkAccess";
             g_http = new NetworkAccess();
+        }
         return g_http;
     }
 
 }
 
 #endif // GLOBAL_H
-
-/*
- * Local Variables:
- * c-basic-offset: 4
- * indent-tabs-mode: nil
- * End:
- */