IConnectionProxy ConnectionManager::proxyById(const QUuid &AProxyId) const { static const IConnectionProxy noProxy = {" "+tr("<No Proxy>"), QNetworkProxy(QNetworkProxy::NoProxy) }; if (!AProxyId.isNull()) { OptionsNode pnode; QList<QUuid> plist = proxyList(); if (plist.contains(AProxyId)) pnode = Options::node(OPV_PROXY_ITEM,AProxyId.toString()); else if (plist.contains(defaultProxy())) pnode = Options::node(OPV_PROXY_ITEM,defaultProxy().toString()); if (!pnode.isNull()) { IConnectionProxy proxy; proxy.name = pnode.value("name").toString(); proxy.proxy.setType((QNetworkProxy::ProxyType)pnode.value("type").toInt()); proxy.proxy.setHostName(pnode.value("host").toString()); proxy.proxy.setPort(pnode.value("port").toInt()); proxy.proxy.setUser(pnode.value("user").toString()); proxy.proxy.setPassword(Options::decrypt(pnode.value("pass").toByteArray()).toString()); return proxy; } } return noProxy; }
bool AWebservice::makeRequest(const QNetworkRequest& request, const QString& data) { QNetworkAccessManager http; http.setProxy(defaultProxy()); QNetworkReply* reply = NULL; if (data.length() == 0) reply = http.get(request); else reply = http.post(request, data.toUtf8()); QObject::connect(reply, SIGNAL(sslErrors(const QList<QSslError>&)), this, SLOT(process_ssl_errors(const QList<QSslError>&))); QObject::connect(reply, SIGNAL(downloadProgress(qint64, qint64)), this, SLOT(process_download_progress(qint64, qint64))); QObject::connect(reply, SIGNAL(uploadProgress(qint64, qint64)), this, SLOT(process_upload_progress(qint64, qint64))); QEventLoop loop; QObject::connect(reply, SIGNAL(finished()), &loop, SLOT(quit())); loop.exec(); bool result = parseReply(reply); delete reply; return result; }
void ConnectionManager::setDefaultProxy(const QUuid &AProxyId) { if (defaultProxy()!=AProxyId && (AProxyId.isNull() || proxyList().contains(AProxyId))) { LOG_INFO(QString("Default proxy changed, id=%1").arg(AProxyId.toString())); Options::node(OPV_PROXY_DEFAULT).setValue(AProxyId.toString()); } }
void ConnectionManager::removeProxy(const QUuid &AProxyId) { if (proxyList().contains(AProxyId)) { LOG_INFO(QString("Proxy removed, id=%1").arg(AProxyId.toString())); if (defaultProxy() == AProxyId) setDefaultProxy(QUuid()); Options::node(OPV_PROXY_ROOT).removeChilds("proxy",AProxyId.toString()); emit proxyRemoved(AProxyId); } }