VirtualBox

Changeset 69553 in vbox for trunk/src/VBox


Ignore:
Timestamp:
Nov 2, 2017 3:11:26 PM (7 years ago)
Author:
vboxsync
Message:

FE/Qt: bugref:8400: Media Manager: Propose to automatically release medium when changing medium type in certain cases, hard-coded rules taken from Medium::setType.

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

Legend:

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

    r69500 r69553  
    12201220}
    12211221
    1222 bool UIMessageCenter::confirmMediumRelease(const UIMedium &medium, QWidget *pParent /* = 0*/) const
     1222bool UIMessageCenter::confirmMediumRelease(const UIMedium &medium, bool fInduced, QWidget *pParent /* = 0 */) const
    12231223{
    12241224    /* Prepare the usage: */
     
    12331233    }
    12341234    /* Show the question: */
    1235     return questionBinary(pParent, MessageType_Question,
    1236                           tr("<p>Are you sure you want to release the disk image file <nobr><b>%1</b></nobr>?</p>"
    1237                              "<p>This will detach it from the following virtual machine(s): <b>%2</b>.</p>")
    1238                              .arg(medium.location(), usage.join(", ")),
    1239                           0 /* auto-confirm id */,
    1240                           tr("Release", "detach medium"));
     1235    return !fInduced
     1236           ? questionBinary(pParent, MessageType_Question,
     1237                            tr("<p>Are you sure you want to release the disk image file <nobr><b>%1</b></nobr>?</p>"
     1238                               "<p>This will detach it from the following virtual machine(s): <b>%2</b>.</p>")
     1239                               .arg(medium.location(), usage.join(", ")),
     1240                            0 /* auto-confirm id */,
     1241                            tr("Release", "detach medium"))
     1242           : questionBinary(pParent, MessageType_Question,
     1243                            tr("<p>The changes you requested require this disk to "
     1244                               "be released from the machines it is attached to.</p>"
     1245                               "<p>Are you sure you want to release the disk image file <nobr><b>%1</b></nobr>?</p>"
     1246                               "<p>This will detach it from the following virtual machine(s): <b>%2</b>.</p>")
     1247                               .arg(medium.location(), usage.join(", ")),
     1248                            0 /* auto-confirm id */,
     1249                            tr("Release", "detach medium"));
    12411250}
    12421251
  • trunk/src/VBox/Frontends/VirtualBox/src/globals/UIMessageCenter.h

    r69500 r69553  
    246246    void cannotMoveMediumStorage(const CProgress &comProgress, const QString &strLocationOld, const QString &strLocationNew, QWidget *pParent = 0) const;
    247247    void cannotChangeMediumDescription(const CMedium &comMedium, const QString &strLocation, QWidget *pParent = 0) const;
    248     bool confirmMediumRelease(const UIMedium &medium, QWidget *pParent = 0) const;
     248    bool confirmMediumRelease(const UIMedium &medium, bool fInduced, QWidget *pParent = 0) const;
    249249    bool confirmMediumRemoval(const UIMedium &medium, QWidget *pParent = 0) const;
    250250    int confirmDeleteHardDiskStorage(const QString &strLocation, QWidget *pParent = 0) const;
  • trunk/src/VBox/Frontends/VirtualBox/src/medium/UIMediumManager.cpp

    r69548 r69553  
    7878    /** Removes UIMedium wrapped by <i>this</i> item. */
    7979    virtual bool remove() = 0;
    80     /** Releases UIMedium wrapped by <i>this</i> item. */
    81     virtual bool release();
     80    /** Releases UIMedium wrapped by <i>this</i> item.
     81      * @param  fInduced  Brings whether this action is caused by other user's action,
     82      *                   not a direct order to release particularly selected medium. */
     83    virtual bool release(bool fInduced = false);
    8284
    8385    /** Refreshes item fully. */
     
    113115    QString toolTip() const { return m_guiMedium.toolTip(); }
    114116
     117    /** Returns a vector of IDs of all machines wrapped UIMedium is attached to. */
     118    const QList<QString> &machineIds() const { return m_guiMedium.machineIds(); }
    115119    /** Returns QString <i>usage</i> of the wrapped UIMedium. */
    116120    QString usage() const { return m_guiMedium.usage(); }
     
    328332}
    329333
    330 bool UIMediumItem::release()
     334bool UIMediumItem::release(bool fInduced /* = false */)
    331335{
    332336    /* Refresh medium and item: */
     
    339343
    340344    /* Confirm release: */
    341     if (!msgCenter().confirmMediumRelease(medium(), treeWidget()))
     345    if (!msgCenter().confirmMediumRelease(medium(), fInduced, treeWidget()))
    342346        return false;
    343347
     
    979983        && newData.m_options.m_enmType != oldData.m_options.m_enmType)
    980984    {
    981         comMedium.SetType(newData.m_options.m_enmType);
    982 
    983         /* Show error message if necessary: */
    984         if (!comMedium.isOk())
    985             msgCenter().cannotChangeMediumType(comMedium, oldData.m_options.m_enmType, newData.m_options.m_enmType, this);
     985        /* Check if we need to release medium first: */
     986        bool fDo = true;
     987        if (   pMediumItem->machineIds().size() > 1
     988            || (   (   newData.m_options.m_enmType == KMediumType_Immutable
     989                    || newData.m_options.m_enmType == KMediumType_MultiAttach)
     990                && pMediumItem->machineIds().size() > 0))
     991            fDo = pMediumItem->release(true);
     992
     993        if (fDo)
     994        {
     995            comMedium.SetType(newData.m_options.m_enmType);
     996
     997            /* Show error message if necessary: */
     998            if (!comMedium.isOk())
     999                msgCenter().cannotChangeMediumType(comMedium, oldData.m_options.m_enmType, newData.m_options.m_enmType, this);
     1000        }
    9861001    }
    9871002
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