6 #include <QNetworkProxy>
7 #include <QNetworkAccessManager>
9 #include "networkaccess.h"
13 static QMap<QString, QAction*> *g_actions = 0;
15 QMap<QString, QAction*>* globalActions() {
17 g_actions = new QMap<QString, QAction*>;
21 static QMap<QString, QMenu*> *g_menus = 0;
23 QMap<QString, QMenu*>* globalMenus() {
25 g_menus = new QMap<QString, QMenu*>;
29 void networkHttpProxySetting() {
31 http_proxy_env = std::getenv("http_proxy");
32 if (!http_proxy_env) {
33 http_proxy_env = std::getenv("HTTP_PROXY");
37 QString proxy_host = "";
38 QString proxy_port = "";
39 QString proxy_user = "";
40 QString proxy_pass = "";
41 QString http_proxy = QString(http_proxy_env);
42 http_proxy.remove(QRegExp("^http://"));
44 // parse username and password
45 if (http_proxy.contains(QChar('@'))) {
46 QStringList http_proxy_list = http_proxy.split(QChar('@'));
47 QStringList http_proxy_user_pass = http_proxy_list[0].split(QChar(':'));
48 if (http_proxy_user_pass.size() > 0) {
49 proxy_user = http_proxy_user_pass[0];
51 if (http_proxy_user_pass.size() == 2) {
52 proxy_pass = http_proxy_user_pass[1];
54 if (http_proxy_list.size() > 1) {
55 http_proxy = http_proxy_list[1];
59 // parse hostname and port
60 QStringList http_proxy_list = http_proxy.split(QChar(':'));
61 if (http_proxy_list.size() > 0) {
62 proxy_host = http_proxy_list[0];
64 if (http_proxy_list.size() > 1) {
65 proxy_port = http_proxy_list[1];
69 qDebug() << "proxy_host: " << proxy_host;
70 qDebug() << "proxy_port: " << proxy_port;
71 qDebug() << "proxy_user: " << proxy_user;
72 qDebug() << "proxy_pass: " << proxy_pass;
76 if (!proxy_host.isEmpty()) {
78 proxy.setType(QNetworkProxy::HttpProxy);
79 proxy.setHostName(proxy_host);
80 if (!proxy_port.isEmpty()) {
81 proxy.setPort(proxy_port.toUShort());
83 if (!proxy_user.isEmpty()) {
84 proxy.setUser(proxy_user);
86 if (!proxy_pass.isEmpty()) {
87 proxy.setPassword(proxy_pass);
90 qDebug() << "Using HTTP proxy:" << http_proxy_env;
91 QNetworkProxy::setApplicationProxy(proxy);
96 static QNetworkAccessManager *nam = 0;
98 QNetworkAccessManager* networkAccessManager() {
100 networkHttpProxySetting();
101 nam = new QNetworkAccessManager();
103 // A simple disk based cache
105 QNetworkDiskCache *cache = new QNetworkDiskCache();
106 QString cacheLocation = QDesktopServices::storageLocation(QDesktopServices::DataLocation);
107 qDebug() << cacheLocation;
108 cache->setCacheDirectory(cacheLocation);
109 nam->setCache(cache);
115 static NetworkAccess *g_http = 0;
116 NetworkAccess* http() {
118 g_http = new NetworkAccess();
129 * indent-tabs-mode: nil