VirtualBox

Changeset 29403 in vbox for trunk/src/VBox/Frontends


Ignore:
Timestamp:
May 12, 2010 10:07:50 AM (15 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
61515
Message:

FE/Qt: use both guest properties (guest IP and guest MAC) to identify a network adapter

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Frontends/VirtualBox/src/runtime/UIIndicatorsPool.cpp

    r29148 r29403  
    268268    {
    269269        const CMachine &machine = m_session.GetMachine();
     270        QString strFullData;
    270271
    271272        ulong uMaxCount = vboxGlobal().virtualBox().GetSystemProperties().GetNetworkAdapterCount();
    272         ulong uCount = 0;
     273
     274        QString strToolTip = QApplication::translate("VBoxConsoleWnd",
     275                                "<p style='white-space:pre'><nobr>Indicates the activity of the "
     276                                "network interfaces:</nobr>%1</p>", "Network adapters tooltip");
     277
     278        RTTIMESPEC time;
     279        uint64_t u64Now = RTTimeSpecGetNano(RTTimeNow(&time));
     280
     281        QString strFlags, strCount;
     282        ULONG64 timestamp;
     283        machine.GetGuestProperty("/VirtualBox/GuestInfo/Net/Count", strCount, timestamp, strFlags);
     284        bool fPropsValid = (u64Now - timestamp < UINT64_C(60000000000)); /* timeout beacon */
     285
     286        QStringList aIp, aMac;
     287        if (fPropsValid)
     288        {
     289            int cAdapters = RT_MIN(strCount.toInt(), uMaxCount);
     290            for (int i = 0; i < cAdapters; i++)
     291            {
     292                aIp << machine.GetGuestPropertyValue(QString("/VirtualBox/GuestInfo/Net/%1/V4/IP").arg(i));
     293                aMac << machine.GetGuestPropertyValue(QString("/VirtualBox/GuestInfo/Net/%1/MAC").arg(i));
     294            }
     295        }
     296
     297        ulong uEnabled = 0;
    273298        for (ulong uSlot = 0; uSlot < uMaxCount; ++ uSlot)
    274             if (machine.GetNetworkAdapter(uSlot).GetEnabled())
    275                 ++ uCount;
    276         setState(uCount > 0 ? KDeviceActivity_Idle : KDeviceActivity_Null);
    277         if (!uCount)
    278             setHidden(true);
    279 
    280         QString strToolTip = QApplication::translate("VBoxConsoleWnd", "<p style='white-space:pre'><nobr>Indicates the activity of the "
    281                                 "network interfaces:</nobr>%1</p>", "Network adapters tooltip");
    282         QString strFullData;
    283 
    284         for (ulong uSlot = 0, uEnabled = 0; uSlot < uMaxCount; ++ uSlot)
    285299        {
    286300            const CNetworkAdapter &adapter = machine.GetNetworkAdapter(uSlot);
    287301            if (adapter.GetEnabled())
    288302            {
    289                 QString strFlags;
    290                 QString strCount;
    291                 ULONG64 timestamp;
    292                 machine.GetGuestProperty("/VirtualBox/GuestInfo/Net/Count", strCount, timestamp, strFlags);
    293                 RTTIMESPEC time;
    294                 uint64_t u64Now = RTTimeSpecGetNano(RTTimeNow(&time));
    295                 QString strIP;
    296                 if (   u64Now - timestamp < UINT64_C(60000000000)
    297                     && strCount.toInt() > 0)
    298                     strIP = machine.GetGuestPropertyValue(QString("/VirtualBox/GuestInfo/Net/%1/V4/IP").arg(uEnabled));
    299                 strFullData += QApplication::translate("VBoxConsoleWnd", "<br><nobr><b>Adapter %1 (%2)</b>: %3 cable %4</nobr>", "Network adapters tooltip")
     303                QString strGuestIp;
     304                if (fPropsValid)
     305                {
     306                    QString strGuestMac = adapter.GetMACAddress();
     307                    int iIp = aMac.indexOf(strGuestMac);
     308                    if (iIp >= 0)
     309                        strGuestIp = aIp[iIp];
     310                }
     311                strFullData += QApplication::translate("VBoxConsoleWnd",
     312                               "<br><nobr><b>Adapter %1 (%2)</b>: %3 cable %4</nobr>", "Network adapters tooltip")
    300313                    .arg(uSlot + 1)
    301314                    .arg(vboxGlobal().toString(adapter.GetAttachmentType()))
    302                     .arg(strIP.isEmpty() ? "" : "IP " + strIP + ", ")
     315                    .arg(strGuestIp.isEmpty() ? "" : "IP " + strGuestIp + ", ")
    303316                    .arg(adapter.GetCableConnected() ?
    304317                          QApplication::translate("VBoxConsoleWnd", "connected", "Network adapters tooltip") :
    305318                          QApplication::translate("VBoxConsoleWnd", "disconnected", "Network adapters tooltip"));
    306                 uEnabled++;
     319                ++ uEnabled;
    307320            }
    308321        }
    309322
     323        setState(uEnabled > 0 ? KDeviceActivity_Idle : KDeviceActivity_Null);
     324        if (!uEnabled)
     325            setHidden(true);
     326
    310327        if (strFullData.isNull())
    311             strFullData = QApplication::translate("VBoxConsoleWnd", "<br><nobr><b>All network adapters are disabled</b></nobr>", "Network adapters tooltip");
     328            strFullData = QApplication::translate("VBoxConsoleWnd",
     329                             "<br><nobr><b>All network adapters are disabled</b></nobr>", "Network adapters tooltip");
    312330
    313331        setToolTip(strToolTip.arg(strFullData));
Note: See TracChangeset for help on using the changeset viewer.

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