- Timestamp:
- Feb 7, 2023 11:15:01 AM (2 years ago)
- 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 71 71 72 72 /* VirtualBox interface declarations: */ 73 #include <iprt/time.h> 73 74 #include <VBox/com/VirtualBox.h> 74 75 … … 1276 1277 } 1277 1278 1279 void 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 1278 1341 void UIDetailsGenerator::acquireDisplayStatusInfo(CMachine &comMachine, QString &strInfo, 1279 1342 bool &fAcceleration3D) -
trunk/src/VBox/Frontends/VirtualBox/src/globals/UIDetailsGenerator.h
r98486 r98487 94 94 bool &fAudioEnabled, bool &fEnabledOutput, bool &fEnabledInput); 95 95 96 SHARED_LIBRARY_STUFF void acquireNetworkStatusInfo(CMachine &comMachine, QString &strInfo, 97 bool &fAdaptersPresent, bool &fCablesDisconnected); 98 96 99 SHARED_LIBRARY_STUFF void acquireDisplayStatusInfo(CMachine &comMachine, QString &strInfo, 97 100 bool &fAcceleration3D); -
trunk/src/VBox/Frontends/VirtualBox/src/runtime/UIIndicatorsPool.cpp
r98486 r98487 51 51 #include "CConsole.h" 52 52 #include "CMachine.h" 53 #include "CSystemProperties.h"54 53 #include "CMachineDebugger.h" 55 54 #include "CGuest.h" 56 #include "CNetworkAdapter.h"57 55 #include "CUSBController.h" 58 56 #include "CUSBDeviceFilters.h" 59 57 #include "CUSBDevice.h" 60 58 #include "CSharedFolder.h" 61 62 /* Other VBox includes: */63 #include <iprt/time.h>64 59 65 60 … … 379 374 public: 380 375 381 /** Construct or, passes @a pSession to the UISessionStateStatusBarIndicator constructor. */376 /** Constructs indicator passing @a pMachine to the base-class. */ 382 377 UIIndicatorNetwork(UIMachine *pMachine, UISession *pSession) 383 378 : UISessionStateStatusBarIndicator(IndicatorType_Network, pMachine, pSession) 384 379 , m_pTimerAutoUpdate(0) 385 , m_cMaxNetworkAdapters(0)386 380 { 387 381 /* Assign state-icons: */ … … 393 387 connect(m_pMachine, &UIMachine::sigMachineStateChange, 394 388 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());399 389 /* Create auto-update timer: */ 400 390 m_pTimerAutoUpdate = new QTimer(this); … … 436 426 void updateAppearance() 437 427 { 438 /* Get machine: */439 const CMachine machine = m_pSession->machine();440 441 /* Prepare tool-tip: */442 428 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: */463 429 bool fAdaptersPresent = false; 464 430 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); 497 432 498 433 /* Hide indicator if there are no enabled adapters: */ 499 if (!fAdaptersPresent) 500 hide(); 434 setVisible(fAdaptersPresent); 501 435 502 436 /* Update tool-tip: */ … … 508 442 /** Holds the auto-update timer instance. */ 509 443 QTimer *m_pTimerAutoUpdate; 510 /** Holds the maximum amount of the network adapters. */511 ulong m_cMaxNetworkAdapters;512 444 }; 513 445 -
trunk/src/VBox/Frontends/VirtualBox/src/runtime/UIMachine.cpp
r98486 r98487 466 466 { 467 467 uisession()->acquireAudioStatusInfo(strInfo, fAudioEnabled, fEnabledOutput, fEnabledInput); 468 } 469 470 void UIMachine::acquireNetworkStatusInfo(QString &strInfo, bool &fAdaptersPresent, bool &fCablesDisconnected) 471 { 472 uisession()->acquireNetworkStatusInfo(strInfo, fAdaptersPresent, fCablesDisconnected); 468 473 } 469 474 -
trunk/src/VBox/Frontends/VirtualBox/src/runtime/UIMachine.h
r98486 r98487 387 387 /** Acquires status info for audio indicator. */ 388 388 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); 389 391 /** Acquires status info for Display indicator. */ 390 392 void acquireDisplayStatusInfo(QString &strInfo, bool &fAcceleration3D); -
trunk/src/VBox/Frontends/VirtualBox/src/runtime/UISession.cpp
r98486 r98487 338 338 CMachine comMachine = machine(); 339 339 UIDetailsGenerator::acquireAudioStatusInfo(comMachine, strInfo, fAudioEnabled, fEnabledOutput, fEnabledInput); 340 } 341 342 void UISession::acquireNetworkStatusInfo(QString &strInfo, bool &fAdaptersPresent, bool &fCablesDisconnected) 343 { 344 CMachine comMachine = machine(); 345 UIDetailsGenerator::acquireNetworkStatusInfo(comMachine, strInfo, fAdaptersPresent, fCablesDisconnected); 340 346 } 341 347 -
trunk/src/VBox/Frontends/VirtualBox/src/runtime/UISession.h
r98486 r98487 273 273 /** Acquires status info for audio indicator. */ 274 274 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); 275 277 /** Acquires status info for Display indicator. */ 276 278 void acquireDisplayStatusInfo(QString &strInfo, bool &fAcceleration3D);
Note:
See TracChangeset
for help on using the changeset viewer.