VirtualBox

Ignore:
Timestamp:
Feb 3, 2017 3:54:38 PM (8 years ago)
Author:
vboxsync
Message:

FE/Qt: Global properties: Network page: Host-only networks tab: Propose suitable pattern for DHCP server attributes which are empty or default (0.0.0.0).

Location:
trunk/src/VBox/Frontends/VirtualBox/src/settings/global
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Frontends/VirtualBox/src/settings/global/UIGlobalSettingsNetworkDetailsHost.cpp

    r62493 r65603  
    163163    if (fIsManual)
    164164    {
     165        /* Load values from COM wrappers: */
    165166        m_pDhcpAddressEditor->setText(m_data.m_dhcpserver.m_strDhcpServerAddress);
    166167        m_pDhcpMaskEditor->setText(m_data.m_dhcpserver.m_strDhcpServerMask);
    167168        m_pDhcpLowerAddressEditor->setText(m_data.m_dhcpserver.m_strDhcpLowerAddress);
    168169        m_pDhcpUpperAddressEditor->setText(m_data.m_dhcpserver.m_strDhcpUpperAddress);
     170
     171        /* Invent default values where necessary: */
     172        const quint32 uAddr = ipv4FromQStringToQuint32(m_data.m_interface.m_strInterfaceAddress);
     173        const quint32 uMask = ipv4FromQStringToQuint32(m_data.m_interface.m_strInterfaceMask);
     174        const quint32 uProp = uAddr & uMask;
     175        const QString strMask = ipv4FromQuint32ToQString(uMask);
     176        const QString strProp = ipv4FromQuint32ToQString(uProp);
     177        //printf("Proposal is = %s x %s\n",
     178        //       strProp.toUtf8().constData(),
     179        //       strMask.toUtf8().constData());
     180        if (   m_data.m_dhcpserver.m_strDhcpServerAddress.isEmpty()
     181            || m_data.m_dhcpserver.m_strDhcpServerAddress == "0.0.0.0")
     182            m_pDhcpAddressEditor->setText(strProp);
     183        if (   m_data.m_dhcpserver.m_strDhcpServerMask.isEmpty()
     184            || m_data.m_dhcpserver.m_strDhcpServerMask == "0.0.0.0")
     185            m_pDhcpMaskEditor->setText(strMask);
     186        if (   m_data.m_dhcpserver.m_strDhcpLowerAddress.isEmpty()
     187            || m_data.m_dhcpserver.m_strDhcpLowerAddress == "0.0.0.0")
     188            m_pDhcpLowerAddressEditor->setText(strProp);
     189        if (   m_data.m_dhcpserver.m_strDhcpUpperAddress.isEmpty()
     190            || m_data.m_dhcpserver.m_strDhcpUpperAddress == "0.0.0.0")
     191            m_pDhcpUpperAddressEditor->setText(strProp);
    169192    }
    170193}
     
    196219}
    197220
     221/* static */
     222quint32 UIGlobalSettingsNetworkDetailsHost::ipv4FromQStringToQuint32(const QString &strAddress)
     223{
     224    quint32 uAddress = 0;
     225    foreach (const QString &strPart, strAddress.split('.'))
     226    {
     227        uAddress = uAddress << 8;
     228        bool fOk = false;
     229        uint uPart = strPart.toUInt(&fOk);
     230        if (fOk)
     231            uAddress += uPart;
     232    }
     233    return uAddress;
     234}
     235
     236/* static */
     237QString UIGlobalSettingsNetworkDetailsHost::ipv4FromQuint32ToQString(quint32 uAddress)
     238{
     239    QStringList address;
     240    while (uAddress)
     241    {
     242        uint uPart = uAddress & 0xFF;
     243        address.prepend(QString::number(uPart));
     244        uAddress = uAddress >> 8;
     245    }
     246    return address.join('.');
     247}
     248
  • trunk/src/VBox/Frontends/VirtualBox/src/settings/global/UIGlobalSettingsNetworkDetailsHost.h

    r62493 r65603  
    5959    void save();
    6060
     61    /** Converts IPv4 address from QString to quint32. */
     62    static quint32 ipv4FromQStringToQuint32(const QString &strAddress);
     63    /** Converts IPv4 address from quint32 to QString. */
     64    static QString ipv4FromQuint32ToQString(quint32 uAddress);
     65
    6166    /* Variable: External data reference: */
    6267    UIDataNetworkHost &m_data;
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