VirtualBox

Changeset 98487 in vbox for trunk


Ignore:
Timestamp:
Feb 7, 2023 11:15:01 AM (2 years ago)
Author:
vboxsync
Message:

FE/Qt: bugref:10322: Runtime UI: Reworking UIIndicatorsPool network indicator to move COM related logic to UISession.

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

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Frontends/VirtualBox/src/globals/UIDetailsGenerator.cpp

    r98486 r98487  
    7171
    7272/* VirtualBox interface declarations: */
     73#include <iprt/time.h>
    7374#include <VBox/com/VirtualBox.h>
    7475
     
    12761277}
    12771278
     1279void UIDetailsGenerator::acquireNetworkStatusInfo(CMachine &comMachine, QString &strInfo,
     1280                                                  bool &fAdaptersPresent, bool &fCablesDisconnected)
     1281{
     1282    /* Determine max amount of network adapters: */
     1283    const CVirtualBox comVBox = uiCommon().virtualBox();
     1284    const KChipsetType enmChipsetType = comMachine.GetChipsetType();
     1285    CSystemProperties comSystemProperties = comVBox.GetSystemProperties();
     1286    const ulong cMaxNetworkAdapters = comSystemProperties.GetMaxNetworkAdapters(enmChipsetType);
     1287
     1288    /* Gather adapter properties: */
     1289    RTTIMESPEC time;
     1290    uint64_t u64Now = RTTimeSpecGetNano(RTTimeNow(&time));
     1291    QString strFlags, strCount;
     1292    LONG64 iTimestamp;
     1293    comMachine.GetGuestProperty("/VirtualBox/GuestInfo/Net/Count", strCount, iTimestamp, strFlags);
     1294    bool fPropsValid = (u64Now - iTimestamp < UINT64_C(60000000000)); /* timeout beacon */
     1295    QStringList ipList, macList;
     1296    if (fPropsValid)
     1297    {
     1298        const ulong cAdapters = qMin(strCount.toULong(), cMaxNetworkAdapters);
     1299        for (ulong i = 0; i < cAdapters; ++i)
     1300        {
     1301            ipList << comMachine.GetGuestPropertyValue(QString("/VirtualBox/GuestInfo/Net/%1/V4/IP").arg(i));
     1302            macList << comMachine.GetGuestPropertyValue(QString("/VirtualBox/GuestInfo/Net/%1/MAC").arg(i));
     1303        }
     1304    }
     1305
     1306    /* Enumerate up to cMaxNetworkAdapters adapters: */
     1307    for (ulong uSlot = 0; uSlot < cMaxNetworkAdapters; ++uSlot)
     1308    {
     1309        const CNetworkAdapter &comAdapter = comMachine.GetNetworkAdapter(uSlot);
     1310        if (comMachine.isOk() && !comAdapter.isNull() && comAdapter.GetEnabled())
     1311        {
     1312            fAdaptersPresent = true;
     1313            QString strGuestIp;
     1314            if (fPropsValid)
     1315            {
     1316                const QString strGuestMac = comAdapter.GetMACAddress();
     1317                const int iIp = macList.indexOf(strGuestMac);
     1318                if (iIp >= 0)
     1319                    strGuestIp = ipList.at(iIp);
     1320            }
     1321            /* Check if the adapter's cable is connected: */
     1322            const bool fCableConnected = comAdapter.GetCableConnected();
     1323            if (fCablesDisconnected && fCableConnected)
     1324                fCablesDisconnected = false;
     1325            /* Append adapter data: */
     1326            strInfo += e_strTableRow1
     1327                .arg(QApplication::translate("UIIndicatorsPool", "Adapter %1 (%2)", "Network tooltip")
     1328                        .arg(uSlot + 1).arg(gpConverter->toString(comAdapter.GetAttachmentType())));
     1329            if (!strGuestIp.isEmpty())
     1330                strInfo += e_strTableRow3
     1331                    .arg(QApplication::translate("UIIndicatorsPool", "IP", "Network tooltip"), strGuestIp);
     1332            strInfo += e_strTableRow3
     1333                .arg(QApplication::translate("UIIndicatorsPool", "Cable", "Network tooltip"))
     1334                .arg(fCableConnected ?
     1335                     QApplication::translate("UIIndicatorsPool", "Connected", "cable (Network tooltip)") :
     1336                     QApplication::translate("UIIndicatorsPool", "Disconnected", "cable (Network tooltip)"));
     1337        }
     1338    }
     1339}
     1340
    12781341void UIDetailsGenerator::acquireDisplayStatusInfo(CMachine &comMachine, QString &strInfo,
    12791342                                                  bool &fAcceleration3D)
  • trunk/src/VBox/Frontends/VirtualBox/src/globals/UIDetailsGenerator.h

    r98486 r98487  
    9494                                                     bool &fAudioEnabled, bool &fEnabledOutput, bool &fEnabledInput);
    9595
     96    SHARED_LIBRARY_STUFF void acquireNetworkStatusInfo(CMachine &comMachine, QString &strInfo,
     97                                                       bool &fAdaptersPresent, bool &fCablesDisconnected);
     98
    9699    SHARED_LIBRARY_STUFF void acquireDisplayStatusInfo(CMachine &comMachine, QString &strInfo,
    97100                                                       bool &fAcceleration3D);
  • trunk/src/VBox/Frontends/VirtualBox/src/runtime/UIIndicatorsPool.cpp

    r98486 r98487  
    5151#include "CConsole.h"
    5252#include "CMachine.h"
    53 #include "CSystemProperties.h"
    5453#include "CMachineDebugger.h"
    5554#include "CGuest.h"
    56 #include "CNetworkAdapter.h"
    5755#include "CUSBController.h"
    5856#include "CUSBDeviceFilters.h"
    5957#include "CUSBDevice.h"
    6058#include "CSharedFolder.h"
    61 
    62 /* Other VBox includes: */
    63 #include <iprt/time.h>
    6459
    6560
     
    379374public:
    380375
    381     /** Constructor, passes @a pSession to the UISessionStateStatusBarIndicator constructor. */
     376    /** Constructs indicator passing @a pMachine to the base-class. */
    382377    UIIndicatorNetwork(UIMachine *pMachine, UISession *pSession)
    383378        : UISessionStateStatusBarIndicator(IndicatorType_Network, pMachine, pSession)
    384379        , m_pTimerAutoUpdate(0)
    385         , m_cMaxNetworkAdapters(0)
    386380    {
    387381        /* Assign state-icons: */
     
    393387        connect(m_pMachine, &UIMachine::sigMachineStateChange,
    394388                this, &UIIndicatorNetwork::sltHandleMachineStateChange);
    395         /* Fetch maximum network adapters count: */
    396         const CVirtualBox vbox = uiCommon().virtualBox();
    397         const CMachine machine = m_pSession->machine();
    398         m_cMaxNetworkAdapters = vbox.GetSystemProperties().GetMaxNetworkAdapters(machine.GetChipsetType());
    399389        /* Create auto-update timer: */
    400390        m_pTimerAutoUpdate = new QTimer(this);
     
    436426    void updateAppearance()
    437427    {
    438         /* Get machine: */
    439         const CMachine machine = m_pSession->machine();
    440 
    441         /* Prepare tool-tip: */
    442428        QString strFullData;
    443 
    444         /* Gather adapter properties: */
    445         RTTIMESPEC time;
    446         uint64_t u64Now = RTTimeSpecGetNano(RTTimeNow(&time));
    447         QString strFlags, strCount;
    448         LONG64 iTimestamp;
    449         machine.GetGuestProperty("/VirtualBox/GuestInfo/Net/Count", strCount, iTimestamp, strFlags);
    450         bool fPropsValid = (u64Now - iTimestamp < UINT64_C(60000000000)); /* timeout beacon */
    451         QStringList ipList, macList;
    452         if (fPropsValid)
    453         {
    454             const int cAdapters = RT_MIN(strCount.toInt(), (int)m_cMaxNetworkAdapters);
    455             for (int i = 0; i < cAdapters; ++i)
    456             {
    457                 ipList << machine.GetGuestPropertyValue(QString("/VirtualBox/GuestInfo/Net/%1/V4/IP").arg(i));
    458                 macList << machine.GetGuestPropertyValue(QString("/VirtualBox/GuestInfo/Net/%1/MAC").arg(i));
    459             }
    460         }
    461 
    462         /* Enumerate up to m_cMaxNetworkAdapters adapters: */
    463429        bool fAdaptersPresent = false;
    464430        bool fCablesDisconnected = true;
    465         for (ulong uSlot = 0; uSlot < m_cMaxNetworkAdapters; ++uSlot)
    466         {
    467             const CNetworkAdapter &adapter = machine.GetNetworkAdapter(uSlot);
    468             if (machine.isOk() && !adapter.isNull() && adapter.GetEnabled())
    469             {
    470                 fAdaptersPresent = true;
    471                 QString strGuestIp;
    472                 if (fPropsValid)
    473                 {
    474                     const QString strGuestMac = adapter.GetMACAddress();
    475                     int iIp = macList.indexOf(strGuestMac);
    476                     if (iIp >= 0)
    477                         strGuestIp = ipList[iIp];
    478                 }
    479                 /* Check if the adapter's cable is connected: */
    480                 const bool fCableConnected = adapter.GetCableConnected();
    481                 if (fCablesDisconnected && fCableConnected)
    482                     fCablesDisconnected = false;
    483                 /* Append adapter data: */
    484                 strFullData += s_strTableRow1
    485                     .arg(QApplication::translate("UIIndicatorsPool", "Adapter %1 (%2)", "Network tooltip")
    486                             .arg(uSlot + 1).arg(gpConverter->toString(adapter.GetAttachmentType())));
    487                 if (!strGuestIp.isEmpty())
    488                     strFullData += s_strTableRow4
    489                         .arg(QApplication::translate("UIIndicatorsPool", "IP", "Network tooltip"), strGuestIp);
    490                 strFullData += s_strTableRow4
    491                     .arg(QApplication::translate("UIIndicatorsPool", "Cable", "Network tooltip"))
    492                     .arg(fCableConnected ?
    493                          QApplication::translate("UIIndicatorsPool", "Connected", "cable (Network tooltip)") :
    494                          QApplication::translate("UIIndicatorsPool", "Disconnected", "cable (Network tooltip)"));
    495             }
    496         }
     431        m_pMachine->acquireNetworkStatusInfo(strFullData, fAdaptersPresent, fCablesDisconnected);
    497432
    498433        /* Hide indicator if there are no enabled adapters: */
    499         if (!fAdaptersPresent)
    500             hide();
     434        setVisible(fAdaptersPresent);
    501435
    502436        /* Update tool-tip: */
     
    508442    /** Holds the auto-update timer instance. */
    509443    QTimer *m_pTimerAutoUpdate;
    510     /** Holds the maximum amount of the network adapters. */
    511     ulong m_cMaxNetworkAdapters;
    512444};
    513445
  • trunk/src/VBox/Frontends/VirtualBox/src/runtime/UIMachine.cpp

    r98486 r98487  
    466466{
    467467    uisession()->acquireAudioStatusInfo(strInfo, fAudioEnabled, fEnabledOutput, fEnabledInput);
     468}
     469
     470void UIMachine::acquireNetworkStatusInfo(QString &strInfo, bool &fAdaptersPresent, bool &fCablesDisconnected)
     471{
     472    uisession()->acquireNetworkStatusInfo(strInfo, fAdaptersPresent, fCablesDisconnected);
    468473}
    469474
  • trunk/src/VBox/Frontends/VirtualBox/src/runtime/UIMachine.h

    r98486 r98487  
    387387        /** Acquires status info for audio indicator. */
    388388        void acquireAudioStatusInfo(QString &strInfo, bool &fAudioEnabled, bool &fEnabledOutput, bool &fEnabledInput);
     389        /** Acquires status info for network indicator. */
     390        void acquireNetworkStatusInfo(QString &strInfo, bool &fAdaptersPresent, bool &fCablesDisconnected);
    389391        /** Acquires status info for Display indicator. */
    390392        void acquireDisplayStatusInfo(QString &strInfo, bool &fAcceleration3D);
  • trunk/src/VBox/Frontends/VirtualBox/src/runtime/UISession.cpp

    r98486 r98487  
    338338    CMachine comMachine = machine();
    339339    UIDetailsGenerator::acquireAudioStatusInfo(comMachine, strInfo, fAudioEnabled, fEnabledOutput, fEnabledInput);
     340}
     341
     342void UISession::acquireNetworkStatusInfo(QString &strInfo, bool &fAdaptersPresent, bool &fCablesDisconnected)
     343{
     344    CMachine comMachine = machine();
     345    UIDetailsGenerator::acquireNetworkStatusInfo(comMachine, strInfo, fAdaptersPresent, fCablesDisconnected);
    340346}
    341347
  • trunk/src/VBox/Frontends/VirtualBox/src/runtime/UISession.h

    r98486 r98487  
    273273        /** Acquires status info for audio indicator. */
    274274        void acquireAudioStatusInfo(QString &strInfo, bool &fAudioEnabled, bool &fEnabledOutput, bool &fEnabledInput);
     275        /** Acquires status info for network indicator. */
     276        void acquireNetworkStatusInfo(QString &strInfo, bool &fAdaptersPresent, bool &fCablesDisconnected);
    275277        /** Acquires status info for Display indicator. */
    276278        void acquireDisplayStatusInfo(QString &strInfo, bool &fAcceleration3D);
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