Example #1
0
bool ClientProxy::isUsingSystemDefault() {
    OCC::ConfigFile cfg;

    // if there is no config file, default to system proxy.
    if( cfg.exists() ) {
        return cfg.proxyType() == QNetworkProxy::DefaultProxy;
    }

    return false;
}
Example #2
0
void ClientProxy::setupQtProxyFromConfig()
{
    OCC::ConfigFile cfg;
    int proxyType = QNetworkProxy::DefaultProxy;
    QNetworkProxy proxy;

    // if there is no config file, default to system proxy.
    if( cfg.exists() ) {
        proxyType = cfg.proxyType();
        proxy  = proxyFromConfig(cfg);
    }

    switch(proxyType) {
    case QNetworkProxy::NoProxy:
        qDebug() << "Set proxy configuration to use NO proxy";
        QNetworkProxyFactory::setUseSystemConfiguration(false);
        QNetworkProxy::setApplicationProxy(QNetworkProxy::NoProxy);
        break;
    case QNetworkProxy::DefaultProxy:
        qDebug() << "Set proxy configuration to use system configuration";
        QNetworkProxyFactory::setUseSystemConfiguration(true);
        break;
    case QNetworkProxy::Socks5Proxy:
        proxy.setType(QNetworkProxy::Socks5Proxy);
        qDebug() << "Set proxy configuration to SOCKS5" << printQNetworkProxy(proxy);
        QNetworkProxyFactory::setUseSystemConfiguration(false);
        QNetworkProxy::setApplicationProxy(proxy);
        break;
    case QNetworkProxy::HttpProxy:
        proxy.setType(QNetworkProxy::HttpProxy);
        qDebug() << "Set proxy configuration to HTTP" << printQNetworkProxy(proxy);
        QNetworkProxyFactory::setUseSystemConfiguration(false);
        QNetworkProxy::setApplicationProxy(proxy);
        break;
    default:
        break;
    }
}