VirtualBox

Changeset 98749 in vbox


Ignore:
Timestamp:
Feb 27, 2023 12:58:28 PM (2 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
156054
Message:

FE/Qt: bugref:10322: Runtime UI: Reworking CMachine wrapper usage step-by-step; Network related stuff.

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

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Frontends/VirtualBox/src/notificationcenter/UINotificationObjects.cpp

    r98728 r98749  
    704704        QApplication::translate("UIMessageCenter", "Audio adapter failure ..."),
    705705        QApplication::translate("UIMessageCenter", "Failed to acquire audio adapter parameter.") +
     706        UIErrorString::formatErrorInfo(comAdapter));
     707}
     708
     709/* static */
     710void UINotificationMessage::cannotAcquireNetworkAdapterParameter(const CNetworkAdapter &comAdapter)
     711{
     712    createMessage(
     713        QApplication::translate("UIMessageCenter", "Network adapter failure ..."),
     714        QApplication::translate("UIMessageCenter", "Failed to acquire network adapter parameter.") +
    706715        UIErrorString::formatErrorInfo(comAdapter));
    707716}
  • trunk/src/VBox/Frontends/VirtualBox/src/notificationcenter/UINotificationObjects.h

    r98728 r98749  
    308308          * @param  comAdapter  Brings the object parameter get acquired from. */
    309309        static void cannotAcquireAudioAdapterParameter(const CAudioAdapter &comAdapter);
     310        /** Notifies about inability to acquire INetworkAdapter parameter.
     311          * @param  comAdapter  Brings the object parameter get acquired from. */
     312        static void cannotAcquireNetworkAdapterParameter(const CNetworkAdapter &comAdapter);
    310313        /** Notifies about inability to acquire IConsole parameter.
    311314          * @param  comConsole  Brings the object parameter get acquired from. */
  • trunk/src/VBox/Frontends/VirtualBox/src/runtime/UIMachine.cpp

    r98746 r98749  
    742742{
    743743    return uisession()->webcamDetach(strPath, strName);
     744}
     745
     746bool UIMachine::acquireWhetherNetworkAdapterEnabled(ulong uSlot, bool &fEnabled)
     747{
     748    return uisession()->acquireWhetherNetworkAdapterEnabled(uSlot, fEnabled);
     749}
     750
     751bool UIMachine::acquireWhetherNetworkCableConnected(ulong uSlot, bool &fConnected)
     752{
     753    return uisession()->acquireWhetherNetworkCableConnected(uSlot, fConnected);
     754}
     755
     756bool UIMachine::setNetworkCableConnected(ulong uSlot, bool fConnected)
     757{
     758    return uisession()->setNetworkCableConnected(uSlot, fConnected);
    744759}
    745760
  • trunk/src/VBox/Frontends/VirtualBox/src/runtime/UIMachine.h

    r98746 r98749  
    515515    /** @} */
    516516
     517    /** @name Network stuff.
     518     ** @{ */
     519        /** Acquires whether network adapter is enabled. */
     520        bool acquireWhetherNetworkAdapterEnabled(ulong uSlot, bool &fEnabled);
     521        /** Acquires whether network adapter cable is connected. */
     522        bool acquireWhetherNetworkCableConnected(ulong uSlot, bool &fConnected);
     523        /** Set whether network adapter cable is connected. */
     524        bool setNetworkCableConnected(ulong uSlot, bool fConnected);
     525    /** @} */
     526
    517527    /** @name Virtualization stuff.
    518528     ** @{ */
  • trunk/src/VBox/Frontends/VirtualBox/src/runtime/UIMachineLogic.cpp

    r98746 r98749  
    22802280}
    22812281
    2282 void UIMachineLogic::sltToggleNetworkAdapterConnection()
    2283 {
    2284     /* Do not process if window(s) missed! */
    2285     if (!isMachineWindowsCreated())
    2286         return;
    2287 
     2282void UIMachineLogic::sltToggleNetworkAdapterConnection(bool fChecked)
     2283{
    22882284    /* Get and check 'the sender' action object: */
    22892285    QAction *pAction = qobject_cast<QAction*>(sender());
    22902286    AssertMsgReturnVoid(pAction, ("Sender action should NOT be null!\n"));
    22912287
    2292     /* Get operation target: */
    2293     CNetworkAdapter adapter = machine().GetNetworkAdapter((ULONG)pAction->property("slot").toInt());
    2294     AssertMsgReturnVoid(machine().isOk() && !adapter.isNull(),
    2295                         ("Network adapter should NOT be null!\n"));
    2296 
    2297     /* Connect/disconnect cable to/from target: */
    2298     const bool fConnect = !adapter.GetCableConnected();
    2299     adapter.SetCableConnected(fConnect);
    2300     if (!adapter.isOk())
    2301         return UINotificationMessage::cannotToggleNetworkCable(adapter, machineName(), fConnect);
     2288    /* Acquire adapter slot: */
     2289    const ulong uSlot = pAction->property("slot").toUInt();
     2290
     2291    /* Toggle network adapter cable connection: */
     2292    uimachine()->setNetworkCableConnected(uSlot, fChecked);
    23022293
    23032294    /* Save machine-settings: */
     
    27082699{
    27092700    /* Determine how many adapters we should display: */
    2710     const KChipsetType chipsetType = machine().GetChipsetType();
    2711     const ULONG uCount = qMin((ULONG)4, uiCommon().virtualBox().GetSystemProperties().GetMaxNetworkAdapters(chipsetType));
     2701    const KChipsetType enmChipsetType = machine().GetChipsetType();
     2702    const ulong uCount = qMin((ulong)4, (ulong)uiCommon().virtualBox().GetSystemProperties().GetMaxNetworkAdapters(enmChipsetType));
    27122703
    27132704    /* Enumerate existing network adapters: */
    2714     QMap<int, bool> adapterData;
    2715     for (ULONG uSlot = 0; uSlot < uCount; ++uSlot)
    2716     {
    2717         /* Get and check iterated adapter: */
    2718         const CNetworkAdapter adapter = machine().GetNetworkAdapter(uSlot);
    2719         AssertReturnVoid(machine().isOk() && !adapter.isNull());
    2720 
     2705    QMap<ulong, bool> adapterData;
     2706    for (ulong uSlot = 0; uSlot < uCount; ++uSlot)
     2707    {
    27212708        /* Skip disabled adapters: */
    2722         if (!adapter.GetEnabled())
     2709        bool fAdapterEnabled = false;
     2710        uimachine()->acquireWhetherNetworkAdapterEnabled(uSlot, fAdapterEnabled);
     2711        if (!fAdapterEnabled)
    27232712            continue;
    27242713
    27252714        /* Remember adapter data: */
    2726         adapterData.insert((int)uSlot, (bool)adapter.GetCableConnected());
     2715        bool fCableConnected = false;
     2716        uimachine()->acquireWhetherNetworkCableConnected(uSlot, fCableConnected);
     2717        adapterData.insert(uSlot, fCableConnected);
    27272718    }
    27282719
     
    27322723
    27332724    /* Add new actions: */
    2734     foreach (int iSlot, adapterData.keys())
     2725    foreach (ulong uSlot, adapterData.keys())
    27352726    {
    27362727        QAction *pAction = pMenu->addAction(UIIconPool::iconSetOnOff(":/connect_on_16px.png", ":/connect_16px.png"),
    27372728                                            adapterData.size() == 1 ? UIActionPool::tr("&Connect Network Adapter") :
    2738                                                                       UIActionPool::tr("Connect Network Adapter &%1").arg(iSlot + 1),
    2739                                             this, SLOT(sltToggleNetworkAdapterConnection()));
    2740         pAction->setProperty("slot", iSlot);
     2729                                                                      UIActionPool::tr("Connect Network Adapter &%1").arg(uSlot + 1),
     2730                                            this, SLOT(sltToggleNetworkAdapterConnection(bool)));
     2731        pAction->setProperty("slot", (uint)uSlot);
    27412732        pAction->setCheckable(true);
    2742         pAction->setChecked(adapterData[iSlot]);
     2733        pAction->setChecked(adapterData.value(uSlot));
    27432734    }
    27442735}
  • trunk/src/VBox/Frontends/VirtualBox/src/runtime/UIMachineLogic.h

    r98744 r98749  
    301301    void sltAttachWebcamDevice();
    302302    void sltChangeSharedClipboardType(QAction *pAction);
    303     void sltToggleNetworkAdapterConnection();
     303    void sltToggleNetworkAdapterConnection(bool fChecked);
    304304    void sltChangeDragAndDropType(QAction *pAction);
    305305    void sltInstallGuestAdditions();
  • trunk/src/VBox/Frontends/VirtualBox/src/runtime/UISession.cpp

    r98747 r98749  
    682682}
    683683
     684bool UISession::acquireWhetherNetworkAdapterEnabled(ulong uSlot, bool &fEnabled)
     685{
     686    CMachine comMachine = machine();
     687    CNetworkAdapter comAdapter = comMachine.GetNetworkAdapter(uSlot);
     688    bool fSuccess = comMachine.isOk();
     689    if (!fSuccess)
     690        UINotificationMessage::cannotAcquireMachineParameter(comMachine);
     691    else
     692    {
     693        const BOOL fAdapterEnabled = comAdapter.GetEnabled();
     694        fSuccess = comAdapter.isOk();
     695        if (!fSuccess)
     696            UINotificationMessage::cannotAcquireNetworkAdapterParameter(comAdapter);
     697        else
     698            fEnabled = fAdapterEnabled == TRUE;
     699    }
     700    return fSuccess;
     701}
     702
     703bool UISession::acquireWhetherNetworkCableConnected(ulong uSlot, bool &fConnected)
     704{
     705    CMachine comMachine = machine();
     706    CNetworkAdapter comAdapter = comMachine.GetNetworkAdapter(uSlot);
     707    bool fSuccess = comMachine.isOk();
     708    if (!fSuccess)
     709        UINotificationMessage::cannotAcquireMachineParameter(comMachine);
     710    else
     711    {
     712        const BOOL fCableConnected = comAdapter.GetCableConnected();
     713        fSuccess = comAdapter.isOk();
     714        if (!fSuccess)
     715            UINotificationMessage::cannotAcquireNetworkAdapterParameter(comAdapter);
     716        else
     717            fConnected = fCableConnected == TRUE;
     718    }
     719    return fSuccess;
     720}
     721
     722bool UISession::setNetworkCableConnected(ulong uSlot, bool fConnected)
     723{
     724    CMachine comMachine = machine();
     725    CNetworkAdapter comAdapter = comMachine.GetNetworkAdapter(uSlot);
     726    bool fSuccess = comMachine.isOk();
     727    if (!fSuccess)
     728        UINotificationMessage::cannotAcquireMachineParameter(comMachine);
     729    else
     730    {
     731        comAdapter.SetCableConnected(fConnected);
     732        fSuccess = comAdapter.isOk();
     733        if (!fSuccess)
     734            UINotificationMessage::cannotToggleNetworkCable(comAdapter, machineName(), fConnected);
     735    }
     736    return fSuccess;
     737}
     738
    684739bool UISession::guestAdditionsUpgradable()
    685740{
  • trunk/src/VBox/Frontends/VirtualBox/src/runtime/UISession.h

    r98746 r98749  
    330330        /** Detaches web cam device with passed @a strName and @a strPath. */
    331331        bool webcamDetach(const QString &strPath, const QString &strName);
     332    /** @} */
     333
     334    /** @name Network stuff.
     335     ** @{ */
     336        /** Acquires whether network adapter is enabled. */
     337        bool acquireWhetherNetworkAdapterEnabled(ulong uSlot, bool &fEnabled);
     338        /** Acquires whether network adapter cable is connected. */
     339        bool acquireWhetherNetworkCableConnected(ulong uSlot, bool &fConnected);
     340        /** Set whether network adapter cable is connected. */
     341        bool setNetworkCableConnected(ulong uSlot, bool fConnected);
    332342    /** @} */
    333343
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