VirtualBox

Changeset 98779 in vbox


Ignore:
Timestamp:
Feb 28, 2023 11:48:37 AM (21 months ago)
Author:
vboxsync
Message:

FE/Qt: bugref:10322: Runtime UI: Reworking CMachine wrapper usage step-by-step; Rest of snapshot related stuff, immutable medium check for shared lib.

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

Legend:

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

    r98103 r98779  
    4242#include "UITakeSnapshotDialog.h"
    4343
    44 /* COM includes: */
    45 #include "COMEnums.h"
    46 #include "CMachine.h"
    47 #include "CMedium.h"
    48 #include "CMediumAttachment.h"
    49 
    50 
    51 UITakeSnapshotDialog::UITakeSnapshotDialog(QWidget *pParent, const CMachine &comMachine)
     44
     45UITakeSnapshotDialog::UITakeSnapshotDialog(QWidget *pParent, ulong cImmutableMedia)
    5246    : QIWithRetranslateUI<QIDialog>(pParent)
    53     , m_comMachine(comMachine)
    54     , m_cImmutableMedia(0)
     47    , m_cImmutableMedia(cImmutableMedia)
    5548    , m_pLabelIcon(0)
    5649    , m_pLabelName(0), m_pEditorName(0)
     
    5952    , m_pButtonBox(0)
    6053{
    61     /* Prepare: */
    6254    prepare();
    6355}
     
    289281            m_pLabelInfo->useSizeHintForWidth(400);
    290282
    291             /* Calculate the amount of immutable attachments: */
    292             if (m_comMachine.GetState() == KMachineState_Paused)
    293             {
    294                 foreach (const CMediumAttachment &comAttachment, m_comMachine.GetMediumAttachments())
    295                 {
    296                     CMedium comMedium = comAttachment.GetMedium();
    297                     if (   !comMedium.isNull()
    298                         && !comMedium.GetParent().isNull()
    299                         && comMedium.GetBase().GetType() == KMediumType_Immutable)
    300                         ++m_cImmutableMedia;
    301                 }
    302             }
    303283            /* Hide if machine have no immutable attachments: */
    304284            if (!m_cImmutableMedia)
  • trunk/src/VBox/Frontends/VirtualBox/src/UITakeSnapshotDialog.h

    r98103 r98779  
    4646class QIDialogButtonBox;
    4747class QILabel;
    48 class CMachine;
    4948
    5049/** QIDialog subclass for taking snapshot name/description. */
     
    5655
    5756    /** Constructs take snapshot dialog passing @ pParent to the base-class.
    58       * @param  comMachine  Brings the machine to take snapshot for. */
    59     UITakeSnapshotDialog(QWidget *pParent, const CMachine &comMachine);
     57      * @param  cImmutableMedia  Brings the amount of immutable mediums. */
     58    UITakeSnapshotDialog(QWidget *pParent, ulong cImmutableMedia);
    6059
    6160    /** Defines snapshot @a icon. */
     
    9392    void updatePixmap();
    9493
    95     /** Holds the wrapper of machine to take snapshot for. */
    96     const CMachine &m_comMachine;
     94    /** Holds the amount of immutable mediums. */
     95    const ulong  m_cImmutableMedia;
    9796
    9897    /** Holds the snapshot icon. */
    9998    QIcon m_icon;
    100 
    101     /** Holds the amount of immutable attachments. */
    102     int  m_cImmutableMedia;
    10399
    104100    /** Holds the icon label instance. */
  • trunk/src/VBox/Frontends/VirtualBox/src/globals/UICommon.cpp

    r98682 r98779  
    21642164}
    21652165
     2166/* static */
     2167bool UICommon::acquireAmountOfImmutableImages(const CMachine &comMachine, ulong &cAmount)
     2168{
     2169    /* Acquire state: */
     2170    ulong cAmountOfImmutableImages = 0;
     2171    const KMachineState enmState = comMachine.GetState();
     2172    bool fSuccess = comMachine.isOk();
     2173    if (!fSuccess)
     2174        UINotificationMessage::cannotAcquireMachineParameter(comMachine);
     2175    else
     2176    {
     2177        /// @todo Who knows why 13 years ago this condition was added ..
     2178        if (enmState == KMachineState_Paused)
     2179        {
     2180            const CMediumAttachmentVector comAttachments = comMachine.GetMediumAttachments();
     2181            fSuccess = comMachine.isOk();
     2182            if (!fSuccess)
     2183                UINotificationMessage::cannotAcquireMachineParameter(comMachine);
     2184            else
     2185            {
     2186                /* Calculate the amount of immutable attachments: */
     2187                foreach (const CMediumAttachment &comAttachment, comAttachments)
     2188                {
     2189                    /* Get the medium: */
     2190                    const CMedium comMedium = comAttachment.GetMedium();
     2191                    if (   comMedium.isNull() /* Null medium is valid case as well */
     2192                        || comMedium.GetParent().isNull() /* Null parent is valid case as well */)
     2193                        continue;
     2194                    /* Get the base medium: */
     2195                    const CMedium comBaseMedium = comMedium.GetBase();
     2196                    fSuccess = comMedium.isOk();
     2197                    if (!fSuccess)
     2198                        UINotificationMessage::cannotAcquireMediumParameter(comMedium);
     2199                    else
     2200                    {
     2201                        const KMediumType enmType = comBaseMedium.GetType();
     2202                        fSuccess = comBaseMedium.isOk();
     2203                        if (!fSuccess)
     2204                            UINotificationMessage::cannotAcquireMediumParameter(comBaseMedium);
     2205                        else if (enmType == KMediumType_Immutable)
     2206                            ++cAmountOfImmutableImages;
     2207                    }
     2208                    if (!fSuccess)
     2209                        break;
     2210                }
     2211            }
     2212        }
     2213    }
     2214    if (fSuccess)
     2215        cAmount = cAmountOfImmutableImages;
     2216    return fSuccess;
     2217}
     2218
    21662219#ifdef RT_OS_LINUX
    21672220/* static */
  • trunk/src/VBox/Frontends/VirtualBox/src/globals/UICommon.h

    r98682 r98779  
    441441          * @param  enmMediumType       Passes the medium type. */
    442442        QString defaultFolderPathForType(UIMediumDeviceType enmMediumType);
     443
     444        /** Calculates @a cAmount of immutable images used by @a comMachine specified. */
     445        static bool acquireAmountOfImmutableImages(const CMachine &comMachine, ulong &cAmount);
    443446    /** @} */
    444447
  • trunk/src/VBox/Frontends/VirtualBox/src/runtime/UIMachine.cpp

    r98776 r98779  
    735735{
    736736    return uisession()->addEncryptionPassword(strId, strPassword, fClearOnSuspend);
     737}
     738
     739bool UIMachine::acquireAmountOfImmutableImages(ulong &cAmount)
     740{
     741    return uisession()->acquireAmountOfImmutableImages(cAmount);
    737742}
    738743
  • trunk/src/VBox/Frontends/VirtualBox/src/runtime/UIMachine.h

    r98776 r98779  
    508508        /** Adds encryption password. */
    509509        bool addEncryptionPassword(const QString &strId, const QString &strPassword, bool fClearOnSuspend);
     510
     511        /** Calculates @a cAmount of immutable images. */
     512        bool acquireAmountOfImmutableImages(ulong &cAmount);
    510513    /** @} */
    511514
  • trunk/src/VBox/Frontends/VirtualBox/src/runtime/UIMachineLogic.cpp

    r98776 r98779  
    15871587        return;
    15881588
     1589    /* First of all, we should calculate amount of immutable images: */
     1590    ulong cAmountOfImmutableMediums = 0;
     1591    uimachine()->acquireAmountOfImmutableImages(cAmountOfImmutableMediums);
     1592
    15891593    /* Create take-snapshot dialog: */
    15901594    QWidget *pDlgParent = windowManager().realParentWindow(activeMachineWindow());
    1591     QPointer<UITakeSnapshotDialog> pDlg = new UITakeSnapshotDialog(pDlgParent, machine());
     1595    QPointer<UITakeSnapshotDialog> pDlg = new UITakeSnapshotDialog(pDlgParent, cAmountOfImmutableMediums);
    15921596    windowManager().registerNewParent(pDlg, pDlgParent);
    15931597
  • trunk/src/VBox/Frontends/VirtualBox/src/runtime/UISession.cpp

    r98776 r98779  
    552552        msgCenter().cannotAddDiskEncryptionPassword(comConsole);
    553553    return fSuccess;
     554}
     555
     556bool UISession::acquireAmountOfImmutableImages(ulong &cAmount)
     557{
     558    CMachine comMachine = machine();
     559    return UICommon::acquireAmountOfImmutableImages(comMachine, cAmount);
    554560}
    555561
  • trunk/src/VBox/Frontends/VirtualBox/src/runtime/UISession.h

    r98776 r98779  
    325325        /** Adds encryption password. */
    326326        bool addEncryptionPassword(const QString &strId, const QString &strPassword, bool fClearOnSuspend);
     327
     328        /** Calculates @a cAmount of immutable images. */
     329        bool acquireAmountOfImmutableImages(ulong &cAmount);
    327330    /** @} */
    328331
  • trunk/src/VBox/Frontends/VirtualBox/src/snapshots/UISnapshotPane.cpp

    r98103 r98779  
    16211621    if (!fAutomatically)
    16221622    {
     1623        /* First of all, we should calculate amount of immutable images: */
     1624        ulong cAmountOfImmutableMediums = 0;
     1625        UICommon::acquireAmountOfImmutableImages(comMachine, cAmountOfImmutableMediums);
     1626
    16231627        /* Create take-snapshot dialog: */
    16241628        QWidget *pDlgParent = windowManager().realParentWindow(this);
    1625         QPointer<UITakeSnapshotDialog> pDlg = new UITakeSnapshotDialog(pDlgParent, comMachine);
     1629        QPointer<UITakeSnapshotDialog> pDlg = new UITakeSnapshotDialog(pDlgParent, cAmountOfImmutableMediums);
    16261630        windowManager().registerNewParent(pDlg, pDlgParent);
    16271631
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