VirtualBox

Ignore:
Timestamp:
Oct 19, 2015 4:23:50 PM (9 years ago)
Author:
vboxsync
Message:

FE/Qt: Networking cleanup/rework (part 17): Tri-state proxy setting support.

Location:
trunk/src/VBox/Frontends/VirtualBox/src
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Frontends/VirtualBox/src/globals/VBoxUtils.h

    r58311 r58312  
    152152public:
    153153
     154    /** Proxy states. */
     155    enum ProxyState
     156    {
     157        ProxyState_Disabled,
     158        ProxyState_Enabled,
     159        ProxyState_Auto
     160    };
     161
    154162    /** Constructs object which parses passed @a strProxySettings. */
    155163    UIProxyManager(const QString &strProxySettings = QString())
    156         : m_fProxyEnabled(false)
     164        : m_enmProxyState(ProxyState_Auto)
    157165        , m_fAuthEnabled(false)
    158166    {
     
    164172        /* Parse proxy state, host and port: */
    165173        if (proxySettings.size() > 0)
    166             m_fProxyEnabled = proxySettings[0] == "proxyEnabled";
     174            m_enmProxyState = proxyStateFromString(proxySettings[0]);
    167175        if (proxySettings.size() > 1)
    168176            m_strProxyHost = proxySettings[1];
     
    184192        /* Serialize settings: */
    185193        QString strResult;
    186         if (m_fProxyEnabled || !m_strProxyHost.isEmpty() || !m_strProxyPort.isEmpty() ||
     194        if (m_enmProxyState != ProxyState_Auto || !m_strProxyHost.isEmpty() || !m_strProxyPort.isEmpty() ||
    187195            m_fAuthEnabled || !m_strAuthLogin.isEmpty() || !m_strAuthPassword.isEmpty())
    188196        {
    189197            QStringList proxySettings;
    190             proxySettings << QString(m_fProxyEnabled ? "proxyEnabled" : "proxyDisabled");
     198            proxySettings << proxyStateToString(m_enmProxyState);
    191199            proxySettings << m_strProxyHost;
    192200            proxySettings << m_strProxyPort;
     
    199207    }
    200208
    201     /** Returns whether the proxy is enabled. */
    202     bool proxyEnabled() const { return m_fProxyEnabled; }
     209    /** Returns the proxy state. */
     210    ProxyState proxyState() const { return m_enmProxyState; }
    203211    /** Returns the proxy host. */
    204212    const QString& proxyHost() const { return m_strProxyHost; }
     
    213221    const QString& authPassword() const { return m_strAuthPassword; }
    214222
    215     /** Defines whether the proxy is @a fEnabled. */
    216     void setProxyEnabled(bool fEnabled) { m_fProxyEnabled = fEnabled; }
     223    /** Defines the proxy @a enmState. */
     224    void setProxyState(ProxyState enmState) { m_enmProxyState = enmState; }
    217225    /** Defines the proxy @a strHost. */
    218226    void setProxyHost(const QString &strHost) { m_strProxyHost = strHost; }
     
    229237private:
    230238
    231     /** Holds whether the proxy is enabled. */
    232     bool m_fProxyEnabled;
     239    /** Converts passed @a state to corresponding #QString. */
     240    static QString proxyStateToString(ProxyState state)
     241    {
     242        switch (state)
     243        {
     244            case ProxyState_Disabled: return QString("ProxyDisabled");
     245            case ProxyState_Enabled:  return QString("ProxyEnabled");
     246            case ProxyState_Auto:     break;
     247        }
     248        return QString("ProxyAuto");
     249    }
     250
     251    /** Converts passed @a strState to corresponding #ProxyState. */
     252    static ProxyState proxyStateFromString(const QString &strState)
     253    {
     254        /* Compose the map of known states: */
     255        QMap<QString, ProxyState> states;
     256        states["ProxyDisabled"] = ProxyState_Disabled; // New since VBox 5.0
     257        states["proxyEnabled"]  = ProxyState_Enabled;  // Old since VBox 4.1
     258        states["ProxyEnabled"]  = ProxyState_Enabled;  // New since VBox 5.0
     259        /* Return one of registered or 'Auto' by default: */
     260        return states.value(strState, ProxyState_Auto);
     261    }
     262
     263    /** Holds the proxy state. */
     264    ProxyState m_enmProxyState;
    233265    /** Holds the proxy host. */
    234266    QString m_strProxyHost;
  • trunk/src/VBox/Frontends/VirtualBox/src/net/UINetworkReply.cpp

    r58266 r58312  
    383383
    384384#ifndef VBOX_GUI_IN_TST_SSL_CERT_DOWNLOADS
    385     /* Get the proxymanager: */
     385    /* Get the proxy-manager: */
    386386    UIProxyManager proxyManager(vboxGlobal().settings().proxySettings());
    387387
    388     /* If the specific proxy settings aren't enabled, we'll use the
    389        system default proxy.  Otherwise assume it's configured. */
    390     if (proxyManager.proxyEnabled())
    391         return RTHttpSetProxy(m_hHttp,
    392                               proxyManager.proxyHost().toUtf8().constData(),
    393                               proxyManager.proxyPort().toUInt(),
    394                               NULL /* pszProxyUser */, NULL /* pszProxyPwd */);
    395 
    396     /** @todo This should be some kind of tristate:
    397      *      - system configured proxy ("proxyDisabled" as well as default "")
    398      *      - user configured proxy ("proxyEnabled").
    399      *      - user configured "no proxy" (currently missing).
    400      * In the two last cases, call RTHttpSetProxy.
    401      *
    402      * Alternatively, we could opt not to give the user a way of doing "no proxy",
    403      * that would require no real changes to the visible GUI... Just a thought.
    404      */
    405 #endif
     388    /* If the specific proxy settings are enabled, we'll use them
     389     * unless user disabled that functionality manually. */
     390    switch (proxyManager.proxyState())
     391    {
     392        case UIProxyManager::ProxyState_Enabled:
     393            return RTHttpSetProxy(m_hHttp,
     394                                  proxyManager.proxyHost().toUtf8().constData(),
     395                                  proxyManager.proxyPort().toUInt(),
     396                                  NULL /* pszProxyUser */, NULL /* pszProxyPwd */);
     397        case UIProxyManager::ProxyState_Disabled:
     398            return VINF_SUCCESS;
     399        default:
     400            break;
     401    }
     402#endif /* VBOX_GUI_IN_TST_SSL_CERT_DOWNLOADS */
     403
     404    /* By default, use system proxy: */
    406405    return RTHttpUseSystemProxySettings(m_hHttp);
    407406}
     
    532531            if (RT_SUCCESS(rc))
    533532            {
    534                 m_reply = QByteArray((char*)pvResponse, cbResponse);
     533                m_reply = QByteArray((char*)pvResponse, (int)cbResponse);
    535534                RTHttpFreeResponse(pvResponse);
    536535            }
     
    559558            if (RT_SUCCESS(rc))
    560559            {
    561                 m_reply = QByteArray((char*)pvResponse, cbResponse);
     560                m_reply = QByteArray((char*)pvResponse, (int)cbResponse);
    562561                RTHttpFreeResponse(pvResponse);
    563562            }
  • trunk/src/VBox/Frontends/VirtualBox/src/settings/global/UIGlobalSettingsProxy.cpp

    r52730 r58312  
    3838
    3939    /* Setup widgets: */
     40    QButtonGroup *pButtonGroup = new QButtonGroup(this);
     41    pButtonGroup->addButton(m_pRadioProxyAuto);
     42    pButtonGroup->addButton(m_pRadioProxyDisabled);
     43    pButtonGroup->addButton(m_pRadioProxyEnabled);
    4044    m_pPortEditor->setFixedWidthByText(QString().fill('0', 6));
    4145    m_pHostEditor->setValidator(new QRegExpValidator(QRegExp("\\S+"), m_pHostEditor));
     
    4347
    4448    /* Setup connections: */
    45     connect(m_pCheckboxProxy, SIGNAL(toggled(bool)), this, SLOT(sltProxyToggled()));
     49    connect(pButtonGroup, SIGNAL(buttonClicked(QAbstractButton*)), this, SLOT(sltProxyToggled()));
    4650    connect(m_pHostEditor, SIGNAL(textEdited(const QString&)), this, SLOT(revalidate()));
    4751    connect(m_pPortEditor, SIGNAL(textEdited(const QString&)), this, SLOT(revalidate()));
     
    6064    /* Load to cache: */
    6165    UIProxyManager proxyManager(m_settings.proxySettings());
    62     m_cache.m_fProxyEnabled = proxyManager.proxyEnabled();
     66    m_cache.m_enmProxyState = proxyManager.proxyState();
    6367    m_cache.m_strProxyHost = proxyManager.proxyHost();
    6468    m_cache.m_strProxyPort = proxyManager.proxyPort();
     
    7377{
    7478    /* Fetch from cache: */
    75     m_pCheckboxProxy->setChecked(m_cache.m_fProxyEnabled);
     79    switch (m_cache.m_enmProxyState)
     80    {
     81        case UIProxyManager::ProxyState_Auto:     m_pRadioProxyAuto->setChecked(true); break;
     82        case UIProxyManager::ProxyState_Disabled: m_pRadioProxyDisabled->setChecked(true); break;
     83        case UIProxyManager::ProxyState_Enabled:  m_pRadioProxyEnabled->setChecked(true); break;
     84    }
    7685    m_pHostEditor->setText(m_cache.m_strProxyHost);
    7786    m_pPortEditor->setText(m_cache.m_strProxyPort);
     
    8796{
    8897    /* Upload to cache: */
    89     m_cache.m_fProxyEnabled = m_pCheckboxProxy->isChecked();
     98    m_cache.m_enmProxyState = m_pRadioProxyEnabled->isChecked()  ? UIProxyManager::ProxyState_Enabled :
     99                              m_pRadioProxyDisabled->isChecked() ? UIProxyManager::ProxyState_Disabled :
     100                                                                   UIProxyManager::ProxyState_Auto;
    90101    m_cache.m_strProxyHost = m_pHostEditor->text();
    91102    m_cache.m_strProxyPort = m_pPortEditor->text();
     
    100111
    101112    UIProxyManager proxyManager;
    102     proxyManager.setProxyEnabled(m_cache.m_fProxyEnabled);
     113    proxyManager.setProxyState(m_cache.m_enmProxyState);
    103114    proxyManager.setProxyHost(m_cache.m_strProxyHost);
    104115    proxyManager.setProxyPort(m_cache.m_strProxyPort);
     
    112123{
    113124    /* Pass if proxy is disabled: */
    114     if (!m_pCheckboxProxy->isChecked())
     125    if (!m_pRadioProxyEnabled->isChecked())
    115126        return true;
    116127
     
    146157{
    147158    /* Configure navigation: */
    148     setTabOrder(pWidget, m_pCheckboxProxy);
    149     setTabOrder(m_pCheckboxProxy, m_pHostEditor);
     159    setTabOrder(pWidget, m_pRadioProxyAuto);
     160    setTabOrder(m_pRadioProxyAuto, m_pRadioProxyDisabled);
     161    setTabOrder(m_pRadioProxyDisabled, m_pRadioProxyEnabled);
     162    setTabOrder(m_pRadioProxyEnabled, m_pHostEditor);
    150163    setTabOrder(m_pHostEditor, m_pPortEditor);
    151164}
     
    160173{
    161174    /* Update widgets availability: */
    162     m_pContainerProxy->setEnabled(m_pCheckboxProxy->isChecked());
     175    m_pContainerProxy->setEnabled(m_pRadioProxyEnabled->isChecked());
    163176
    164177    /* Revalidate: */
  • trunk/src/VBox/Frontends/VirtualBox/src/settings/global/UIGlobalSettingsProxy.h

    r55401 r58312  
    2020
    2121/* Local includes */
     22#include "VBoxUtils.h"
    2223#include "UISettingsPage.h"
    2324#include "UIGlobalSettingsProxy.gen.h"
     
    2728{
    2829    UISettingsCacheGlobalProxy()
    29         : m_fProxyEnabled(false)
     30        : m_enmProxyState(UIProxyManager::ProxyState_Auto)
    3031    {}
    31     bool m_fProxyEnabled;
     32    UIProxyManager::ProxyState m_enmProxyState;
    3233    QString m_strProxyHost;
    3334    QString m_strProxyPort;
  • trunk/src/VBox/Frontends/VirtualBox/src/settings/global/UIGlobalSettingsProxy.ui

    r56153 r58312  
    2020   </property>
    2121   <item row="0" column="0" colspan="2">
    22     <widget class="QCheckBox" name="m_pCheckboxProxy">
     22    <widget class="QRadioButton" name="m_pRadioProxyAuto">
    2323     <property name="whatsThis">
    24       <string>When checked, VirtualBox will use the proxy settings supplied for tasks like downloading Guest Additions from the network or checking for updates.</string>
     24      <string>When chosen, VirtualBox will try to auto-detect host proxy settings for tasks like downloading Guest Additions from the network or checking for updates.</string>
    2525     </property>
    2626     <property name="text">
    27       <string>&amp;Enable Proxy</string>
     27      <string>&amp;Auto-detect Host Proxy Settings</string>
    2828     </property>
    2929    </widget>
    3030   </item>
    31    <item row="1" column="0">
     31   <item row="1" column="0" colspan="2">
     32    <widget class="QRadioButton" name="m_pRadioProxyDisabled">
     33     <property name="whatsThis">
     34      <string>When chosen, VirtualBox will use direct Internet connection for tasks like downloading Guest Additions from the network or checking for updates.</string>
     35     </property>
     36     <property name="text">
     37      <string>&amp;Direct Connection to the Internet</string>
     38     </property>
     39    </widget>
     40   </item>
     41   <item row="2" column="0" colspan="2">
     42    <widget class="QRadioButton" name="m_pRadioProxyEnabled">
     43     <property name="whatsThis">
     44      <string>When chosen, VirtualBox will use the proxy settings supplied for tasks like downloading Guest Additions from the network or checking for updates.</string>
     45     </property>
     46     <property name="text">
     47      <string>&amp;Manual Proxy Configuration</string>
     48     </property>
     49    </widget>
     50   </item>
     51   <item row="3" column="0">
    3252    <spacer>
    3353     <property name="orientation">
     
    4565    </spacer>
    4666   </item>
    47    <item row="1" column="1" colspan="2">
     67   <item row="3" column="1">
    4868    <widget class="QWidget" name="m_pContainerProxy">
    4969     <property name="sizePolicy">
     
    100120    </widget>
    101121   </item>
    102    <item row="2" column="0" colspan="3">
     122   <item row="4" column="0" colspan="2">
    103123    <spacer>
    104124     <property name="orientation">
Note: See TracChangeset for help on using the changeset viewer.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette