// Called when the user clicked "OK" button of the settings dialog. Return
// true if the proxy settings has been changed by the user.
bool SettingsDialog::updateProxySettings()
{
    SettingsManager *mgr = seafApplet->settingsManager();
    SettingsManager::SeafileProxy old_proxy = mgr->getProxy();

    SettingsManager::ProxyType proxy_type = static_cast<SettingsManager::ProxyType>(mProxyMethodComboBox->currentIndex());
    QString proxy_host = mProxyHost->text().trimmed();
    QString proxy_username = mProxyUsername->text().trimmed();
    QString proxy_password = mProxyPassword->text().trimmed();
    int proxy_port = mProxyPort->value();

    SettingsManager::SeafileProxy new_proxy(proxy_type);

    switch(proxy_type) {
        case SettingsManager::HttpProxy:
            new_proxy.host = proxy_host;
            new_proxy.port = proxy_port;
            if (mProxyRequirePassword->checkState() == Qt::Checked) {
                new_proxy.username = proxy_username;
                new_proxy.password = proxy_password;
                break;
            }
            break;
        case SettingsManager::SocksProxy:
            new_proxy.host = proxy_host;
            new_proxy.port = proxy_port;
            break;
        case SettingsManager::NoProxy:
        case SettingsManager::SystemProxy:
        default:
            break;
    }

    if (new_proxy != old_proxy) {
        mgr->setProxy(new_proxy);
        return true;
    }

    return false;
}
Exemplo n.º 2
0
bool SettingsDialog::updateProxySettings()
{
    bool proxy_changed = false;

    SettingsManager *mgr = seafApplet->settingsManager();
    SettingsManager::ProxyType old_proxy_type;
    QString old_proxy_host;
    QString old_proxy_username;
    QString old_proxy_password;
    int old_proxy_port;
    mgr->getProxy(old_proxy_type, old_proxy_host, old_proxy_port, old_proxy_username, old_proxy_password);

    SettingsManager::ProxyType proxy_type = static_cast<SettingsManager::ProxyType>(mProxyMethodComboBox->currentIndex());
    QString proxy_host = mProxyHost->text().trimmed();
    QString proxy_username = mProxyUsername->text().trimmed();
    QString proxy_password = mProxyPassword->text().trimmed();
    int proxy_port = mProxyPort->value();

    switch(proxy_type) {
        case SettingsManager::HttpProxy:
                // if we setup proxy username now and previously
            if (mProxyRequirePassword->checkState() == Qt::Checked) {
                if (proxy_type == old_proxy_type &&
                    proxy_host == old_proxy_host &&
                    proxy_port == old_proxy_port &&
                    proxy_username == old_proxy_username &&
                    proxy_password == old_proxy_password)
                    break;
                proxy_changed = true;
                mgr->setProxy(SettingsManager::HttpProxy,
                              proxy_host, proxy_port,
                              proxy_username, proxy_password);
                break;
            }
            else {
                // and if we don't setup proxy username now and previously
                if (proxy_type == old_proxy_type &&
                    proxy_host == old_proxy_host &&
                    proxy_port == old_proxy_port &&
                    old_proxy_username.isEmpty())
                    break;
                proxy_changed = true;
                mgr->setProxy(SettingsManager::HttpProxy,
                              proxy_host, proxy_port);
            }
            break;
        case SettingsManager::SocksProxy:
            if (proxy_type == old_proxy_type &&
                proxy_host == old_proxy_host &&
                proxy_port == old_proxy_port)
                break;
            proxy_changed = true;
            mgr->setProxy(SettingsManager::SocksProxy,
                          proxy_host, proxy_port);
            break;
        case SettingsManager::NoneProxy:
        default:
            if (proxy_type == old_proxy_type)
                break;
            proxy_changed = true;
            mgr->setProxy(SettingsManager::NoneProxy);
            break;
    }

    return proxy_changed;
}