VirtualBox

Changeset 78353 in vbox for trunk/src


Ignore:
Timestamp:
Apr 29, 2019 5:19:02 PM (6 years ago)
Author:
vboxsync
Message:

FE/Qt: bugref:8400. Disabled some medium editing widgets if the current medium is not editable.

Location:
trunk/src/VBox/Frontends/VirtualBox/src/medium
Files:
6 edited

Legend:

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

    r76606 r78353  
    8383}
    8484
     85void UIMediumDetailsWidget::enableDisableMediumModificationWidgets(bool fMediumIsModifiable)
     86{
     87    if (m_pComboBoxType)
     88        m_pComboBoxType->setEnabled(fMediumIsModifiable);
     89    if (m_pEditorLocation)
     90        m_pEditorLocation->setEnabled(fMediumIsModifiable);
     91    if (m_pEditorSize)
     92        m_pEditorSize->setEnabled(fMediumIsModifiable);
     93}
     94
    8595void UIMediumDetailsWidget::setOptionsEnabled(bool fEnabled)
    8696{
     
    134144void UIMediumDetailsWidget::sltTypeIndexChanged(int iIndex)
    135145{
    136     m_newData.m_options.m_enmType = m_pComboBoxType->itemData(iIndex).value<KMediumType>();
     146    m_newData.m_options.m_enmMediumType = m_pComboBoxType->itemData(iIndex).value<KMediumType>();
    137147    revalidate(m_pErrorPaneType);
    138148    updateButtonStates();
     
    620630    {
    621631        /* Populate type combo-box: */
    622         switch (m_newData.m_enmType)
     632        switch (m_newData.m_enmDeviceType)
    623633        {
    624634            case UIMediumDeviceType_HardDisk:
     
    626636                /* No type changes for differencing disks: */
    627637                if (m_oldData.m_enmVariant & KMediumVariant_Diff)
    628                     m_pComboBoxType->addItem(QString(), m_oldData.m_options.m_enmType);
     638                    m_pComboBoxType->addItem(QString(), m_oldData.m_options.m_enmMediumType);
    629639                else
    630640                {
     
    664674    /* Choose the item with required type to be the current one: */
    665675    for (int i = 0; i < m_pComboBoxType->count(); ++i)
    666         if (m_pComboBoxType->itemData(i).value<KMediumType>() == m_newData.m_options.m_enmType)
     676        if (m_pComboBoxType->itemData(i).value<KMediumType>() == m_newData.m_options.m_enmMediumType)
    667677            m_pComboBoxType->setCurrentIndex(i);
    668678    sltTypeIndexChanged(m_pComboBoxType->currentIndex());
     
    681691    /* Load size: */
    682692    const bool fEnableResize =    m_newData.m_fValid
    683                                && m_newData.m_enmType == UIMediumDeviceType_HardDisk
     693                               && m_newData.m_enmDeviceType == UIMediumDeviceType_HardDisk
    684694                               && !(m_newData.m_enmVariant & KMediumVariant_Fixed);
    685695    m_pLabelSize->setEnabled(fEnableResize);
     
    695705{
    696706    /* Get information-labels just to acquire their number: */
    697     const QList<QLabel*> aLabels = m_aLabels.value(m_newData.m_enmType, QList<QLabel*>());
     707    const QList<QLabel*> aLabels = m_aLabels.value(m_newData.m_enmDeviceType, QList<QLabel*>());
    698708    /* Get information-fields just to acquire their number: */
    699     const QList<QILabel*> aFields = m_aFields.value(m_newData.m_enmType, QList<QILabel*>());
     709    const QList<QILabel*> aFields = m_aFields.value(m_newData.m_enmDeviceType, QList<QILabel*>());
    700710    /* For each the label => update contents: */
    701711    for (int i = 0; i < aLabels.size(); ++i)
    702         infoLabel(m_newData.m_enmType, i)->setText(m_newData.m_details.m_aLabels.value(i, QString()));
     712        infoLabel(m_newData.m_enmDeviceType, i)->setText(m_newData.m_details.m_aLabels.value(i, QString()));
    703713    /* For each the field => update contents: */
    704714    for (int i = 0; i < aFields.size(); ++i)
    705715    {
    706         infoField(m_newData.m_enmType, i)->setText(m_newData.m_details.m_aFields.value(i, QString()));
    707         infoField(m_newData.m_enmType, i)->setEnabled(!infoField(m_newData.m_enmType, i)->text().trimmed().isEmpty());
     716        infoField(m_newData.m_enmDeviceType, i)->setText(m_newData.m_details.m_aFields.value(i, QString()));
     717        infoField(m_newData.m_enmDeviceType, i)->setEnabled(!infoField(m_newData.m_enmDeviceType, i)->text().trimmed().isEmpty());
    708718    }
    709719}
     
    846856    return aFields.value(iIndex, 0);
    847857}
    848 
  • trunk/src/VBox/Frontends/VirtualBox/src/medium/UIMediumDetailsWidget.h

    r76581 r78353  
    5454    /** Constructs data. */
    5555    UIDataMediumOptions()
    56         : m_enmType(KMediumType_Normal)
     56        : m_enmMediumType(KMediumType_Normal)
    5757        , m_strLocation(QString())
    5858        , m_strDescription(QString())
     
    6464    {
    6565        return true
    66                && (m_enmType == other.m_enmType)
     66               && (m_enmMediumType == other.m_enmMediumType)
    6767               && (m_strLocation == other.m_strLocation)
    6868               && (m_strDescription == other.m_strDescription)
     
    7676    bool operator!=(const UIDataMediumOptions &other) const { return !equal(other); }
    7777
    78     /** Holds the type. */
    79     KMediumType m_enmType;
     78    /** Holds the medium type. */
     79    KMediumType m_enmMediumType;
    8080    /** Holds the location. */
    8181    QString m_strLocation;
     
    123123    UIDataMedium()
    124124        : m_fValid(false)
    125         , m_enmType(UIMediumDeviceType_Invalid)
     125        , m_enmDeviceType(UIMediumDeviceType_Invalid)
    126126        , m_enmVariant(KMediumVariant_Max)
    127127        , m_fHasChildren(false)
     
    133133    UIDataMedium(UIMediumDeviceType enmType)
    134134        : m_fValid(false)
    135         , m_enmType(enmType)
     135        , m_enmDeviceType(enmType)
    136136        , m_enmVariant(KMediumVariant_Max)
    137137        , m_fHasChildren(false)
     
    145145        return true
    146146               && (m_fValid == other.m_fValid)
    147                && (m_enmType == other.m_enmType)
     147               && (m_enmDeviceType == other.m_enmDeviceType)
    148148               && (m_enmVariant == other.m_enmVariant)
    149149               && (m_fHasChildren == other.m_fHasChildren)
     
    161161    bool m_fValid;
    162162    /** Holds the medium type. */
    163     UIMediumDeviceType m_enmType;
     163    UIMediumDeviceType m_enmDeviceType;
    164164    /** Holds the medium variant. */
    165165    KMediumVariant m_enmVariant;
     
    204204    /** Defines the @a data for passed @a enmType. */
    205205    void setData(const UIDataMedium &data);
     206    /** Enables/disables some of the medium editing widgets of the details tab. */
     207    void enableDisableMediumModificationWidgets(bool fMediumIsModifiable);
     208
    206209
    207210public slots:
     
    355358
    356359#endif /* !FEQT_INCLUDED_SRC_medium_UIMediumDetailsWidget_h */
    357 
  • trunk/src/VBox/Frontends/VirtualBox/src/medium/UIMediumItem.cpp

    r76606 r78353  
    174174}
    175175
     176bool UIMediumItem::isMediumModifiable() const
     177{
     178    if (medium().isNull())
     179        return false;
     180    foreach (const QUuid &uMachineId, medium().curStateMachineIds())
     181    {
     182        CMachine comMachine = vboxGlobal().virtualBox().FindMachine(uMachineId.toString());
     183        if (comMachine.isNull())
     184            continue;
     185        if (comMachine.GetState() != KMachineState_PoweredOff &&
     186            comMachine.GetState() != KMachineState_Aborted)
     187            return false;
     188    }
     189    return true;
     190}
     191
     192bool UIMediumItem::isMediumAttachedTo(QUuid uId)
     193{
     194   if (medium().isNull())
     195        return false;
     196   return medium().curStateMachineIds().contains(uId);
     197}
     198
    176199QString UIMediumItem::defaultText() const
    177200{
     
    197220    m_fValid =    !m_guiMedium.isNull()
    198221               && m_guiMedium.state() != KMediumState_Inaccessible;
    199     m_enmType = m_guiMedium.type();
     222    m_enmDeviceType = m_guiMedium.type();
    200223    m_enmVariant = m_guiMedium.mediumVariant();
    201224    m_fHasChildren = m_guiMedium.hasChildren();
    202225    /* Gather medium options data: */
    203     m_options.m_enmType = m_guiMedium.mediumType();
     226    m_options.m_enmMediumType = m_guiMedium.mediumType();
    204227    m_options.m_strLocation = m_guiMedium.location();
    205228    m_options.m_uLogicalSize = m_guiMedium.logicalSizeInBytes();
     
    207230    /* Gather medium details data: */
    208231    m_details.m_aFields.clear();
    209     switch (m_enmType)
     232    switch (m_enmDeviceType)
    210233    {
    211234        case UIMediumDeviceType_HardDisk:
  • trunk/src/VBox/Frontends/VirtualBox/src/medium/UIMediumItem.h

    r76998 r78353  
    104104    /** Returns whether <i>this</i> item is less than @a other one. */
    105105    bool operator<(const QTreeWidgetItem &other) const;
     106    /** Returns whether the medium can be modified. For
     107      * simplicity's sake this returns false if one of the attached vms is not
     108      * in PoweredOff or Aborted state. */
     109    bool isMediumModifiable() const;
     110    /** Returns true if the medium is attached to the vm with @p uId. */
     111    bool isMediumAttachedTo(QUuid uId);
    106112
    107113protected:
  • trunk/src/VBox/Frontends/VirtualBox/src/medium/UIMediumManager.cpp

    r77359 r78353  
    4343#include "UIIconPool.h"
    4444#include "UIMedium.h"
     45#include "UIVirtualBoxEventHandler.h"
    4546
    4647/* COM includes: */
     
    271272    /* Try to assign new medium type: */
    272273    if (   comMedium.isOk()
    273         && newData.m_options.m_enmType != oldData.m_options.m_enmType)
     274        && newData.m_options.m_enmMediumType != oldData.m_options.m_enmMediumType)
    274275    {
    275276        /* Check if we need to release medium first: */
    276277        bool fDo = true;
    277278        if (   pMediumItem->machineIds().size() > 1
    278             || (   (   newData.m_options.m_enmType == KMediumType_Immutable
    279                     || newData.m_options.m_enmType == KMediumType_MultiAttach)
     279            || (   (   newData.m_options.m_enmMediumType == KMediumType_Immutable
     280                    || newData.m_options.m_enmMediumType == KMediumType_MultiAttach)
    280281                && pMediumItem->machineIds().size() > 0))
    281282            fDo = pMediumItem->release(true);
     
    283284        if (fDo)
    284285        {
    285             comMedium.SetType(newData.m_options.m_enmType);
     286            comMedium.SetType(newData.m_options.m_enmMediumType);
    286287
    287288            /* Show error message if necessary: */
    288289            if (!comMedium.isOk())
    289                 msgCenter().cannotChangeMediumType(comMedium, oldData.m_options.m_enmType, newData.m_options.m_enmType, this);
     290                msgCenter().cannotChangeMediumType(comMedium, oldData.m_options.m_enmMediumType, newData.m_options.m_enmMediumType, this);
    290291        }
    291292    }
     
    486487}
    487488
     489void UIMediumManagerWidget::sltHandleMachineStateChange(const QUuid &uId, const KMachineState state)
     490{
     491    UIMediumItem *pCurrentItem = currentMediumItem();
     492    if (!pCurrentItem)
     493        return;
     494    /* If this machine is not using the current medium then we don't care about its state: */
     495    if (!pCurrentItem->isMediumAttachedTo(uId))
     496        return;
     497    bool fMediumIsModifiable = true;
     498    if (state != KMachineState_Aborted && state != KMachineState_PoweredOff)
     499        fMediumIsModifiable = false;
     500    m_pDetailsWidget->enableDisableMediumModificationWidgets(fMediumIsModifiable);
     501}
     502
    488503void UIMediumManagerWidget::sltAddMedium()
    489504{
     
    719734void UIMediumManagerWidget::prepareConnections()
    720735{
     736    /* Listen to vm state changed event so that we can disable/enable widgets related to the current medium if neds be: */
     737    connect(gVBoxEvents, &UIVirtualBoxEventHandler::sigMachineStateChange,
     738            this, &UIMediumManagerWidget::sltHandleMachineStateChange);
     739
    721740    /* Configure medium-processing connections: */
    722741    connect(&vboxGlobal(), &VBoxGlobal::sigMediumCreated,
     
    10401059    /* Update details-widget: */
    10411060    if (m_pDetailsWidget)
     1061    {
    10421062        m_pDetailsWidget->setData(pMediumItem ? *pMediumItem : UIDataMedium(type));
     1063        if (pMediumItem)
     1064            m_pDetailsWidget->enableDisableMediumModificationWidgets(currentMediumItem()->isMediumModifiable());
     1065    }
    10431066}
    10441067
     
    15941617
    15951618/*********************************************************************************************************************************
    1596 *   Class UIMediumManagerFactory implementation.                                                                                 *
     1619*   Class UIMediumManager implementation.                                                                                 *
    15971620*********************************************************************************************************************************/
    15981621
  • trunk/src/VBox/Frontends/VirtualBox/src/medium/UIMediumManager.h

    r77255 r78353  
    162162        /** Handles VBoxGlobal::sigMediumEnumerationFinished signal. */
    163163        void sltHandleMediumEnumerationFinish();
     164        void sltHandleMachineStateChange(const QUuid &uId, const KMachineState state);
    164165    /** @} */
    165166
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