VirtualBox

Changeset 48301 in vbox for trunk/src/VBox/Frontends


Ignore:
Timestamp:
Sep 5, 2013 11:52:39 AM (11 years ago)
Author:
vboxsync
Message:

FE/Qt: 6909: Medium-enumeration cleanup/rework (part 10): Switch to new medium-enumeration mechanism.

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

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Frontends/VirtualBox/src/globals/UIDefs.h

    r48124 r48301  
    7171        , SetRegionEventType
    7272        , ModifierKeyChangeEventType
    73         , MediumEnumeratedEventType
    74         , MediumsEnumeratedEventType
    7573#ifdef Q_WS_WIN
    7674        , ShellExecuteEventType
  • trunk/src/VBox/Frontends/VirtualBox/src/globals/VBoxGlobal.cpp

    r48277 r48301  
    7070#include "UISession.h"
    7171#include "UIConverter.h"
     72#include "UIMediumEnumerator.h"
    7273
    7374#ifdef Q_WS_X11
     
    162163#endif
    163164
    164 /* Medium enumerated event: */
    165 class UIMediumEnumeratedEvent : public QEvent
    166 {
    167 public:
    168 
    169     /* Constructor: */
    170     UIMediumEnumeratedEvent(const UIMedium &medium, const VBoxMediaList::iterator &iterator)
    171         : QEvent((QEvent::Type)MediumEnumeratedEventType)
    172         , m_medium(medium), m_iterator(iterator)
    173     {}
    174 
    175     /* Variables: */
    176     const UIMedium m_medium;
    177     const VBoxMediaList::iterator m_iterator;
    178 };
    179 
    180 /* Mediums enumerated event: */
    181 class UIMediumsEnumeratedEvent : public QEvent
    182 {
    183 public:
    184 
    185     /* Constructor: */
    186     UIMediumsEnumeratedEvent(const VBoxMediaList::iterator &iterator)
    187         : QEvent((QEvent::Type)MediumsEnumeratedEventType)
    188         , m_iterator(iterator)
    189     {}
    190 
    191     /* Variable: */
    192     const VBoxMediaList::iterator m_iterator;
    193 };
    194 
    195165// VBoxGlobal
    196166////////////////////////////////////////////////////////////////////////////////
     
    270240    , mSelectorWnd (NULL)
    271241    , m_pVirtualMachine(0)
    272     , m_pMediumEnumerationThread(0)
     242    , m_pMediumEnumerator(0)
    273243    , mIsKWinManaged (false)
    274244#if defined(DEBUG_bird)
     
    16871657}
    16881658
    1689 void VBoxGlobal::createMedium(const UIMedium &uimedium)
    1690 {
    1691     VBoxMediaList::iterator it = m_mediums.begin();
    1692 
    1693     if (uimedium.type() == UIMediumType_HardDisk)
    1694     {
    1695         VBoxMediaList::iterator itParent = m_mediums.end();
    1696 
    1697         for (; it != m_mediums.end(); ++ it)
    1698         {
    1699             /* skip null medium that come first */
    1700             if ((*it).isNull()) continue;
    1701 
    1702             if ((*it).type() != UIMediumType_HardDisk)
    1703                 break;
    1704 
    1705             if (uimedium.parent() != NULL && itParent == m_mediums.end())
    1706             {
    1707                 if (&*it == uimedium.parent())
    1708                     itParent = it;
    1709             }
    1710             else
    1711             {
    1712                 /* break if met a parent's sibling (will insert before it) */
    1713                 if (uimedium.parent() != NULL &&
    1714                     (*it).parent() == (*itParent).parent())
    1715                     break;
    1716 
    1717                 /* compare to uimedium's siblings */
    1718                 if ((*it).parent() == uimedium.parent() &&
    1719                     (*it).name().localeAwareCompare (uimedium.name()) > 0)
    1720                     break;
    1721             }
    1722         }
    1723 
    1724         AssertReturnVoid (uimedium.parent() == NULL || itParent != m_mediums.end());
    1725     }
    1726     else
    1727     {
    1728         for (; it != m_mediums.end(); ++ it)
    1729         {
    1730             /* skip null medium that come first */
    1731             if ((*it).isNull()) continue;
    1732 
    1733             /* skip HardDisks that come first */
    1734             if ((*it).type() == UIMediumType_HardDisk)
    1735                 continue;
    1736 
    1737             /* skip DVD when inserting Floppy */
    1738             if (uimedium.type() == UIMediumType_Floppy &&
    1739                 (*it).type() == UIMediumType_DVD)
    1740                 continue;
    1741 
    1742             if ((*it).name().localeAwareCompare (uimedium.name()) > 0 ||
    1743                 (uimedium.type() == UIMediumType_DVD &&
    1744                  (*it).type() == UIMediumType_Floppy))
    1745                 break;
    1746         }
    1747     }
    1748 
    1749     it = m_mediums.insert (it, uimedium);
    1750 
    1751     emit sigMediumCreated((*it).id());
    1752 }
    1753 
    1754 void VBoxGlobal::updateMedium(const UIMedium &uimedium)
    1755 {
    1756     VBoxMediaList::Iterator it;
    1757     for (it = m_mediums.begin(); it != m_mediums.end(); ++ it)
    1758         if ((*it).id() == uimedium.id())
    1759             break;
    1760 
    1761     AssertReturnVoid (it != m_mediums.end());
    1762 
    1763     if (&*it != &uimedium)
    1764         *it = uimedium;
    1765 
    1766     emit sigMediumUpdated((*it).id());
     1659void VBoxGlobal::createMedium(const UIMedium &medium)
     1660{
     1661    /* Create medium in medium-enumerator: */
     1662    m_pMediumEnumerator->createMedium(medium);
     1663}
     1664
     1665void VBoxGlobal::updateMedium(const UIMedium &medium)
     1666{
     1667    /* Update medium of medium-enumerator: */
     1668    m_pMediumEnumerator->updateMedium(medium);
    17671669}
    17681670
    17691671void VBoxGlobal::deleteMedium(const QString &strMediumID)
    17701672{
    1771     VBoxMediaList::Iterator it;
    1772     for (it = m_mediums.begin(); it != m_mediums.end(); ++it)
    1773         if ((*it).id() == strMediumID)
    1774             break;
    1775 
    1776     AssertReturnVoid(it != m_mediums.end());
    1777 
    1778 #if DEBUG
    1779     /* sanity: must be no children */
    1780     {
    1781         VBoxMediaList::Iterator jt = it;
    1782         ++jt;
    1783         AssertReturnVoid(jt == m_mediums.end() || (*jt).parent() != &*it);
    1784     }
    1785 #endif /* DEBUG */
    1786 
    1787     UIMedium *pParent = (*it).parent();
    1788 
    1789     /* remove the medium from the list to keep it in sync with the server "for
    1790      * free" when the medium is deleted from one of our UIs */
    1791     m_mediums.erase(it);
    1792 
    1793     emit sigMediumDeleted(strMediumID);
    1794 
    1795     /* also emit the parent update signal because some attributes like
    1796      * isReadOnly() may have been changed after child removal */
    1797     if (pParent != NULL)
    1798     {
    1799         pParent->refresh();
    1800         emit sigMediumUpdated(pParent->id());
    1801     }
     1673    /* Delete medium from medium-enumerator: */
     1674    m_pMediumEnumerator->deleteMedium(strMediumID);
    18021675}
    18031676
     
    19371810}
    19381811
    1939 static void addNullMediumToList(VBoxMediaList &mediums, VBoxMediaList::iterator where)
    1940 {
    1941    /* Append the NULL medium to the medium list: */
    1942     UIMedium medium;
    1943     mediums.insert(where, medium);
    1944 }
    1945 
    1946 static void addMediumsToList(const CMediumVector &inputMediums,
    1947                              VBoxMediaList &outputMediums,
    1948                              VBoxMediaList::iterator where,
    1949                              UIMediumType mediumType,
    1950                              UIMedium *pParent = 0)
    1951 {
    1952     /* Appends the given list of input-mediums to the output-mediums: */
    1953     VBoxMediaList::iterator first = where;
    1954 
    1955     for (CMediumVector::ConstIterator it = inputMediums.begin(); it != inputMediums.end(); ++it)
    1956     {
    1957         CMedium cmedium(*it);
    1958         UIMedium medium(cmedium, mediumType, pParent);
    1959 
    1960         /* Search for a proper alphabetic position: */
    1961         VBoxMediaList::iterator jt = first;
    1962         for (; jt != where; ++ jt)
    1963             if ((*jt).name().localeAwareCompare(medium.name()) > 0)
    1964                 break;
    1965 
    1966         outputMediums.insert(jt, medium);
    1967 
    1968         /* Adjust the first item if inserted before it: */
    1969         if (jt == first)
    1970             --first;
    1971     }
    1972 }
    1973 
    1974 static void addHardDisksToList(const CMediumVector &inputMediums,
    1975                                VBoxMediaList &outputMediums,
    1976                                VBoxMediaList::iterator where,
    1977                                UIMedium *pParent = 0)
    1978 {
    1979     /* Appends the given list of input-hard-disks and all their children to the output-mediums: */
    1980     VBoxMediaList::iterator first = where;
    1981 
    1982     /* First pass: Add siblings sorted */
    1983     for (CMediumVector::ConstIterator it = inputMediums.begin(); it != inputMediums.end(); ++it)
    1984     {
    1985         CMedium cmedium(*it);
    1986         UIMedium medium(cmedium, UIMediumType_HardDisk, pParent);
    1987 
    1988         /* Search for a proper alphabetic position: */
    1989         VBoxMediaList::iterator jt = first;
    1990         for (; jt != where; ++ jt)
    1991             if ((*jt).name().localeAwareCompare(medium.name()) > 0)
    1992                 break;
    1993 
    1994         outputMediums.insert(jt, medium);
    1995 
    1996         /* Adjust the first item if inserted before it: */
    1997         if (jt == first)
    1998             --first;
    1999     }
    2000 
    2001     /* Second pass: Add children: */
    2002     for (VBoxMediaList::iterator it = first; it != where;)
    2003     {
    2004         CMediumVector children = (*it).medium().GetChildren();
    2005         UIMedium *parent = &(*it);
    2006 
    2007         ++it; /* go to the next sibling before inserting children */
    2008         addHardDisksToList(children, outputMediums, it, parent);
    2009     }
    2010 }
    2011 
    20121812void VBoxGlobal::startMediumEnumeration(bool fForceStart /*= true*/)
    20131813{
     
    20321832        return;
    20331833
    2034     /* Compose a list of all currently known mediums & their children: */
    2035     m_mediums.clear();
    2036     addNullMediumToList(m_mediums, m_mediums.end());
    2037     addHardDisksToList(mVBox.GetHardDisks(), m_mediums, m_mediums.end());
    2038     addMediumsToList(mHost.GetDVDDrives(), m_mediums, m_mediums.end(), UIMediumType_DVD);
    2039     addMediumsToList(mVBox.GetDVDImages(), m_mediums, m_mediums.end(), UIMediumType_DVD);
    2040     addMediumsToList(mHost.GetFloppyDrives(), m_mediums, m_mediums.end(), UIMediumType_Floppy);
    2041     addMediumsToList(mVBox.GetFloppyImages(), m_mediums, m_mediums.end(), UIMediumType_Floppy);
    2042 
    2043     /* Enumeration thread class: */
    2044     class MediaEnumThread : public QThread
    2045     {
    2046     public:
    2047 
    2048         MediaEnumThread(VBoxMediaList &mediums)
    2049             : m_mediums(mediums.size())
    2050             , m_iterator(mediums.begin())
    2051         {
    2052             int i = 0;
    2053             for (VBoxMediaList::const_iterator it = mediums.begin(); it != mediums.end(); ++it)
    2054                 m_mediums[i++] = *it;
    2055         }
    2056 
    2057         void run()
    2058         {
    2059             LogFlow(("MediaEnumThread started.\n"));
    2060             COMBase::InitializeCOM(false);
    2061 
    2062             QObject *pSelf = &vboxGlobal();
    2063 
    2064             /* Enumerate medium list: */
    2065             for (int i = 0; i < m_mediums.size() && !m_sfCleanupInProgress; ++i)
    2066             {
    2067                 m_mediums[i].blockAndQueryState();
    2068                 QApplication::postEvent(pSelf, new UIMediumEnumeratedEvent(m_mediums[i], m_iterator));
    2069                 ++m_iterator;
    2070             }
    2071 
    2072             /* Post the end-of-enumeration event: */
    2073             if (!m_sfCleanupInProgress)
    2074                 QApplication::postEvent(pSelf, new UIMediumsEnumeratedEvent(m_iterator));
    2075 
    2076             COMBase::CleanupCOM();
    2077             LogFlow(("MediaEnumThread finished.\n"));
    2078         }
    2079 
    2080     private:
    2081 
    2082         QVector<UIMedium> m_mediums;
    2083         VBoxMediaList::iterator m_iterator;
    2084     };
    2085 
    2086     m_pMediumEnumerationThread = new MediaEnumThread(m_mediums);
    2087     AssertReturnVoid(m_pMediumEnumerationThread);
    2088 
    2089     /* Emit signal *after* we set m_pMediumEnumerationThread to != NULL
    2090      * to cause isMediaEnumerationStarted() to return TRUE from slots: */
    2091     emit sigMediumEnumerationStarted();
    2092 
    2093     m_pMediumEnumerationThread->start();
     1834    /* Redirect request to medium-enumerator: */
     1835    m_pMediumEnumerator->enumerateMediums();
     1836}
     1837
     1838bool VBoxGlobal::isMediumEnumerationInProgress() const
     1839{
     1840    /* Redirect request to medium-enumerator: */
     1841    return m_pMediumEnumerator->isMediumEnumerationInProgress();
    20941842}
    20951843
    20961844UIMedium VBoxGlobal::medium(const QString &strMediumID) const
    20971845{
    2098     for (VBoxMediaList::ConstIterator it = m_mediums.begin(); it != m_mediums.end(); ++it)
    2099         if ((*it).id() == strMediumID)
    2100             return *it;
    2101     return UIMedium();
     1846    /* Redirect call to medium-enumerator: */
     1847    return m_pMediumEnumerator->medium(strMediumID);
     1848}
     1849
     1850QList<QString> VBoxGlobal::mediumIDs() const
     1851{
     1852    /* Redirect call to medium-enumerator: */
     1853    return m_pMediumEnumerator->mediumIDs();
    21021854}
    21031855
     
    39823734// Protected members
    39833735////////////////////////////////////////////////////////////////////////////////
    3984 
    3985 bool VBoxGlobal::event(QEvent *pEvent)
    3986 {
    3987     /* Handle events: */
    3988     switch (pEvent->type())
    3989     {
    3990         case MediumEnumeratedEventType:
    3991         {
    3992             /* Cast to corresponding event: */
    3993             UIMediumEnumeratedEvent *pMediumEnumeratedEvent = static_cast<UIMediumEnumeratedEvent*>(pEvent);
    3994 
    3995             /* Show accessibility error message if necessary: */
    3996             if (pMediumEnumeratedEvent->m_medium.state() == KMediumState_Inaccessible &&
    3997                 !pMediumEnumeratedEvent->m_medium.result().isOk())
    3998                 msgCenter().cannotGetMediaAccessibility(pMediumEnumeratedEvent->m_medium);
    3999 
    4000             /* Make sure incoming iterator is valid: */
    4001             AssertReturn(pMediumEnumeratedEvent->m_iterator != m_mediums.end(), false);
    4002 
    4003             /* Assign enumeration result to corresponding medium: */
    4004             *(pMediumEnumeratedEvent->m_iterator) = pMediumEnumeratedEvent->m_medium;
    4005 
    4006             /* Notify listeners about newly enumerated medium: */
    4007             emit sigMediumEnumerated((*pMediumEnumeratedEvent->m_iterator).id());
    4008 
    4009             /* Accept event: */
    4010             return true;
    4011         }
    4012         case MediumsEnumeratedEventType:
    4013         {
    4014             /* Cleanup enumeration thread: */
    4015             m_pMediumEnumerationThread->wait();
    4016             delete m_pMediumEnumerationThread;
    4017             m_pMediumEnumerationThread = 0;
    4018 
    4019             /* Notify listeners about enumeration finished: */
    4020             emit sigMediumEnumerationFinished();
    4021 
    4022             /* Accept event: */
    4023             return true;
    4024         }
    4025         default:
    4026             break;
    4027     }
    4028     /* Call to base-class: */
    4029     return QObject::event(pEvent);
    4030 }
    40313736
    40323737bool VBoxGlobal::eventFilter (QObject *aObject, QEvent *aEvent)
     
    45434248     * but this method should be run anyway just to enumerate null UIMedium object,
    45444249     * used by some VBox smart widgets, like VBoxMediaComboBox: */
     4250    m_pMediumEnumerator = new UIMediumEnumerator;
     4251    {
     4252        /* Prepare medium-enumerator: */
     4253        connect(m_pMediumEnumerator, SIGNAL(sigMediumCreated(const QString&)),
     4254                this, SIGNAL(sigMediumCreated(const QString&)));
     4255        connect(m_pMediumEnumerator, SIGNAL(sigMediumUpdated(const QString&)),
     4256                this, SIGNAL(sigMediumUpdated(const QString&)));
     4257        connect(m_pMediumEnumerator, SIGNAL(sigMediumDeleted(const QString&)),
     4258                this, SIGNAL(sigMediumDeleted(const QString&)));
     4259        connect(m_pMediumEnumerator, SIGNAL(sigMediumEnumerationStarted()),
     4260                this, SIGNAL(sigMediumEnumerationStarted()));
     4261        connect(m_pMediumEnumerator, SIGNAL(sigMediumEnumerated(const QString&)),
     4262                this, SIGNAL(sigMediumEnumerated(const QString&)));
     4263        connect(m_pMediumEnumerator, SIGNAL(sigMediumEnumerationFinished()),
     4264                this, SIGNAL(sigMediumEnumerationFinished()));
     4265    }
    45454266    if (agressiveCaching())
    45464267        startMediumEnumeration();
     
    45994320    UIExtraDataEventHandler::destroy();
    46004321
    4601     /* Cleanup medium enumeration thread: */
    4602     if (m_pMediumEnumerationThread)
    4603     {
    4604         m_pMediumEnumerationThread->wait();
    4605         delete m_pMediumEnumerationThread;
    4606         m_pMediumEnumerationThread = 0;
    4607     }
     4322    /* Cleanup medium-enumerator: */
     4323    delete m_pMediumEnumerator;
     4324    m_pMediumEnumerator = 0;
    46084325
    46094326    if (mSelectorWnd)
     
    46214338    mTypes.clear();
    46224339
    4623     /* media list contains a lot of CUUnknown, release them */
    4624     m_mediums.clear();
    46254340    /* the last steps to ensure we don't use COM any more */
    46264341    mHost.detach();
  • trunk/src/VBox/Frontends/VirtualBox/src/globals/VBoxGlobal.h

    r48269 r48301  
    5252class CUSBDevice;
    5353class QSpinBox;
     54class UIMediumEnumerator;
    5455
    5556// VBoxGlobal class
     
    253254    void startMediumEnumeration(bool fForceStart = true);
    254255    bool agressiveCaching() const { return mAgressiveCaching; }
    255     bool isMediumEnumerationInProgress() const { return !!m_pMediumEnumerationThread; }
     256    bool isMediumEnumerationInProgress() const;
    256257    UIMedium medium(const QString &strMediumID) const;
    257     const VBoxMediaList &currentMediaList() const { return m_mediums; }
     258    QList<QString> mediumIDs() const;
    258259
    259260    /* various helpers */
     
    395396protected:
    396397
    397     bool event(QEvent *pEvent);
    398398    bool eventFilter (QObject *, QEvent *);
    399399
     
    426426    bool mShowStartVMErrors;
    427427
    428     QThread *m_pMediumEnumerationThread;
    429     VBoxMediaList m_mediums;
     428    /* Variable: Medium-enumeration stuff: */
     429    UIMediumEnumerator *m_pMediumEnumerator;
    430430
    431431    RenderMode vm_render_mode;
  • trunk/src/VBox/Frontends/VirtualBox/src/medium/UIMedium.cpp

    r48278 r48301  
    3737#endif /* !VBOX_WITH_PRECOMPILED_HEADERS */
    3838
     39QString UIMedium::m_sstrNullID = QUuid().toString().remove('{').remove('}');
    3940QString UIMedium::m_sstrTable = QString("<table>%1</table>");
    4041QString UIMedium::m_sstrRow = QString("<tr><td>%1</td></tr>");
     
    4344    : m_type(UIMediumType_Invalid)
    4445    , m_state(KMediumState_NotCreated)
    45     , m_pParent(0)
    4646{
    4747    refresh();
     
    4949}
    5050
    51 UIMedium::UIMedium(const CMedium &medium, UIMediumType type, UIMedium *pParent /*= 0*/)
     51UIMedium::UIMedium(const CMedium &medium, UIMediumType type)
    5252    : m_medium(medium)
    5353    , m_type(type)
    5454    , m_state(KMediumState_NotCreated)
    55     , m_pParent(pParent)
    5655{
    5756    refresh();
     
    6362    , m_type(type)
    6463    , m_state(state)
    65     , m_pParent(0)
    6664{
    6765    refresh();
     
    106104    m_curStateMachineIds = other.curStateMachineIds();
    107105
    108     m_pParent = other.parent();
     106    m_strParentID = other.parentID();
     107    m_strRootID = other.rootID();
    109108
    110109    m_noDiffs = other.cache();
     
    194193    }
    195194
     195    /* Initialize parent/root IDs: */
     196    m_strParentID = nullID();
     197    m_strRootID = m_strId;
    196198    if (m_type == UIMediumType_HardDisk)
    197199    {
     
    207209        m_fReadOnly = m_medium.GetReadOnly();
    208210
    209         /* Adjust the parent if its possible: */
     211        /* Adjust parent/root IDs: */
    210212        CMedium parentMedium = m_medium.GetParent();
    211         Assert(!parentMedium.isNull() || m_pParent == NULL);
    212 
    213         if (!parentMedium.isNull() && (m_pParent == NULL || m_pParent->m_medium != parentMedium))
    214         {
    215             /* Search for the parent (might be there): */
    216             const VBoxMediaList &list = vboxGlobal().currentMediaList();
    217             for (VBoxMediaList::const_iterator it = list.begin(); it != list.end(); ++it)
    218             {
    219                 if ((*it).m_type != UIMediumType_HardDisk)
    220                     break;
    221 
    222                 if ((*it).m_medium == parentMedium)
    223                 {
    224                     m_pParent = unconst(&*it);
    225                     break;
    226                 }
    227             }
     213        if (!parentMedium.isNull())
     214            m_strParentID = parentMedium.GetId();
     215        while (!parentMedium.isNull())
     216        {
     217            m_strRootID = parentMedium.GetId();
     218            parentMedium = parentMedium.GetParent();
    228219        }
    229220    }
     
    371362}
    372363
    373 /**
    374  * Returns a root medium of this medium. For non-hard disk media, this is always
    375  * this medium itself.
    376  */
    377 UIMedium &UIMedium::root() const
    378 {
    379     UIMedium *pRoot = unconst(this);
    380     while (pRoot->m_pParent != NULL)
    381         pRoot = pRoot->m_pParent;
    382 
    383     return *pRoot;
     364UIMedium UIMedium::parent() const
     365{
     366    /* Redirect call to VBoxGlobal: */
     367    return vboxGlobal().medium(m_strParentID);
     368}
     369
     370UIMedium UIMedium::root() const
     371{
     372    /* Redirect call to VBoxGlobal: */
     373    return vboxGlobal().medium(m_strRootID);
    384374}
    385375
     
    500490    QString strDetails, strText;
    501491
    502     UIMedium *pRoot = unconst(this);
     492    /* Note: root accessible only if medium enumerated: */
     493    UIMedium rootMedium = root();
    503494    KMediumState eState = m_state;
    504495
     
    507498        if (fNoDiffs)
    508499        {
    509             pRoot = &this->root();
    510 
    511             bool isDiff = (!fPredictDiff && m_pParent != NULL) || (fPredictDiff && m_fReadOnly);
     500            bool isDiff = (!fPredictDiff && parentID() != nullID()) || (fPredictDiff && m_fReadOnly);
    512501
    513502            strDetails = isDiff && fUseHTML ?
    514                 QString("<i>%1</i>, ").arg(pRoot->m_strHardDiskType) :
    515                 QString("%1, ").arg(pRoot->m_strHardDiskType);
     503                QString("<i>%1</i>, ").arg(rootMedium.m_strHardDiskType) :
     504                QString("%1, ").arg(rootMedium.m_strHardDiskType);
    516505
    517506            eState = this->state(true /* fNoDiffs */);
    518507
    519             if (pRoot->m_state == KMediumState_NotCreated)
     508            if (rootMedium.m_state == KMediumState_NotCreated)
    520509                eState = KMediumState_NotCreated;
    521510        }
    522511        else
    523512        {
    524             strDetails = QString("%1, ").arg(pRoot->m_strHardDiskType);
     513            strDetails = QString("%1, ").arg(rootMedium.m_strHardDiskType);
    525514        }
    526515    }
     
    539528            break;
    540529        default:
    541             strDetails += m_type == UIMediumType_HardDisk ? pRoot->m_strLogicalSize : pRoot->m_strSize;
     530            strDetails += m_type == UIMediumType_HardDisk ? rootMedium.m_strLogicalSize : rootMedium.m_strSize;
    542531            break;
    543532    }
    544533
    545534    strDetails = fUseHTML ?
    546         QString("%1 (<nobr>%2</nobr>)").arg(VBoxGlobal::locationForHTML(pRoot->m_strName), strDetails) :
    547         QString("%1 (%2)").arg(VBoxGlobal::locationForHTML(pRoot->m_strName), strDetails);
     535        QString("%1 (<nobr>%2</nobr>)").arg(VBoxGlobal::locationForHTML(rootMedium.m_strName), strDetails) :
     536        QString("%1 (%2)").arg(VBoxGlobal::locationForHTML(rootMedium.m_strName), strDetails);
    548537
    549538    return strDetails;
     
    553542QString UIMedium::nullID()
    554543{
    555     return QUuid().toString().remove('{').remove('}');
     544    return m_sstrNullID;
    556545}
    557546
     
    569558
    570559    m_noDiffs.state = m_state;
    571     for (UIMedium *cur = m_pParent; cur != NULL; cur = cur->m_pParent)
    572     {
    573         if (cur->m_state == KMediumState_Inaccessible)
    574         {
    575             m_noDiffs.state = cur->m_state;
     560    for (UIMedium parentMedium = parent(); !parentMedium.isNull(); parentMedium = parentMedium.parent())
     561    {
     562        if (parentMedium.m_state == KMediumState_Inaccessible)
     563        {
     564            m_noDiffs.state = parentMedium.m_state;
    576565
    577566            if (m_noDiffs.toolTip.isNull())
     
    581570                                                                 "mode to inspect these media.", "medium"));
    582571
    583             if (!cur->m_result.isOk())
     572            if (!parentMedium.m_result.isOk())
    584573            {
    585                 m_noDiffs.result = cur->m_result;
     574                m_noDiffs.result = parentMedium.m_result;
    586575                break;
    587576            }
     
    589578    }
    590579
    591     if (m_pParent != NULL && !m_fReadOnly)
     580    if (parentID() != nullID() && !m_fReadOnly)
    592581    {
    593582        m_noDiffs.toolTip = root().tip() +
  • trunk/src/VBox/Frontends/VirtualBox/src/medium/UIMedium.h

    r48278 r48301  
    2222/* Qt includes: */
    2323#include <QMap>
    24 #include <QLinkedList>
    2524#include <QPixmap>
    2625
     
    8988    /* Lazy wrapping constructor:
    9089     * Creates a uimedium associated with the given medium. */
    91     UIMedium(const CMedium &medium, UIMediumType type, UIMedium *pParent = 0);
     90    UIMedium(const CMedium &medium, UIMediumType type);
    9291
    9392    /* Wrapping constructor with known medium state:
     
    196195    const QList <QString> &curStateMachineIds() const { return m_curStateMachineIds; }
    197196
    198     /**
    199      * Returns a parent medium. For non-hard disk media, this is always NULL.
    200      */
    201     UIMedium* parent() const { return m_pParent; }
    202 
    203     UIMedium& root() const;
     197    /* API: Parent/Root stuff: */
     198    QString parentID() const { return m_strParentID; }
     199    QString rootID() const { return m_strRootID; }
     200    UIMedium parent() const;
     201    UIMedium root() const;
    204202
    205203    QString toolTip(bool fNoDiffs = false, bool fCheckRO = false, bool fNullAllowed = false) const;
     
    259257    QList<QString> m_curStateMachineIds;
    260258
    261     UIMedium *m_pParent;
     259    QString m_strParentID;
     260    QString m_strRootID;
    262261
    263262    NoDiffsCache m_noDiffs;
    264263
     264    static QString m_sstrNullID;
    265265    static QString m_sstrTable;
    266266    static QString m_sstrRow;
     
    268268Q_DECLARE_METATYPE(UIMedium);
    269269
    270 typedef QLinkedList<UIMedium> VBoxMediaList;
    271270typedef QMap<QString, UIMedium> UIMediumMap;
    272271
  • trunk/src/VBox/Frontends/VirtualBox/src/medium/UIMediumEnumerator.cpp

    r48274 r48301  
    100100    /* Get medium ID: */
    101101    QString strMediumID = medium.id();
    102 //    printf("UIMediumEnumerator: Medium with ID={%s} created.\n", strMediumID.toAscii().constData());
     102    LogRel(("UIMediumEnumerator: Medium with ID={%s} created.\n", strMediumID.toAscii().constData()));
    103103
    104104    /* Make sure medium doesn't exists already: */
     
    116116    /* Get medium ID: */
    117117    QString strMediumID = medium.id();
    118 //    printf("UIMediumEnumerator: Medium with ID={%s} updated.\n", strMediumID.toAscii().constData());
     118    LogRel(("UIMediumEnumerator: Medium with ID={%s} updated.\n", strMediumID.toAscii().constData()));
    119119
    120120    /* Make sure medium still exists: */
     
    130130void UIMediumEnumerator::deleteMedium(const QString &strMediumID)
    131131{
    132 //    printf("UIMediumEnumerator: Medium with ID={%s} removed.\n", strMediumID.toAscii().constData());
     132    LogRel(("UIMediumEnumerator: Medium with ID={%s} removed.\n", strMediumID.toAscii().constData()));
    133133
    134134    /* Make sure medium still exists: */
     
    159159
    160160    /* Notify listener: */
    161 //    printf("UIMediumEnumerator: Medium-enumeration started...\n");
     161    LogRel(("UIMediumEnumerator: Medium-enumeration started...\n"));
    162162    m_fMediumEnumerationInProgress = true;
    163163    emit sigMediumEnumerationStarted();
     
    171171void UIMediumEnumerator::sltHandleMachineUpdate(QString strMachineID)
    172172{
    173 //    printf("Machine event received, ID = %s\n", strMachineID.toAscii().constData());
     173    LogRel(("Machine event received, ID = %s\n", strMachineID.toAscii().constData()));
    174174
    175175    /* Compose a map of previous usage: */
     
    182182            oldUsage << strMediumID;
    183183    }
    184 //    printf("Old usage: %s\n", oldUsage.join(", ").toAscii().constData());
     184    LogRel(("Old usage: %s\n", oldUsage.join(", ").toAscii().constData()));
    185185
    186186    /* Compose a map of current usage: */
     
    201201        }
    202202    }
    203 //    printf("New usage: %s\n", newUsage.join(", ").toAscii().constData());
     203    LogRel(("New usage: %s\n", newUsage.join(", ").toAscii().constData()));
    204204
    205205    /* Manipulations over the sets: */
     
    210210    QStringList excludedList = excludedSet.toList();
    211211    QStringList includedList = includedSet.toList();
    212 //    printf("Excluded items of machine usage: %s\n", excludedList.join(", ").toAscii().constData());
    213 //    printf("Included items of machine usage: %s\n", includedList.join(", ").toAscii().constData());
     212    LogRel(("Excluded items of machine usage: %s\n", excludedList.join(", ").toAscii().constData()));
     213    LogRel(("Included items of machine usage: %s\n", includedList.join(", ").toAscii().constData()));
    214214
    215215    /* For each of excluded items: */
     
    244244    }
    245245
    246 //    printf("Machine event processed, ID = %s\n", strMachineID.toAscii().constData());
     246    LogRel(("Machine event processed, ID = %s\n", strMachineID.toAscii().constData()));
    247247}
    248248
     
    256256    UIMedium medium = pTask->data().value<UIMedium>();
    257257    QString strMediumID = medium.id();
    258 //    printf("UIMediumEnumerator: Medium with ID={%s} enumerated.\n", strMediumID.toAscii().constData());
     258    LogRel(("UIMediumEnumerator: Medium with ID={%s} enumerated.\n", strMediumID.toAscii().constData()));
    259259
    260260    /* Delete task: */
     
    275275    {
    276276        /* Notify listener: */
    277 //        printf("UIMediumEnumerator: Medium-enumeration finished!\n");
     277        LogRel(("UIMediumEnumerator: Medium-enumeration finished!\n"));
    278278        m_fMediumEnumerationInProgress = false;
    279279        emit sigMediumEnumerationFinished();
  • trunk/src/VBox/Frontends/VirtualBox/src/medium/UIMediumManager.cpp

    r48269 r48301  
    3838#include "QILabel.h"
    3939#include "UIIconPool.h"
    40 #include "UIVirtualBoxEventHandler.h"
    4140#include "UIMediumTypeChangeDialog.h"
    4241
     
    421420    mTabWidget->setTabIcon(FDTab, m_iconFD);
    422421
    423     /* Load current mediums: */
    424     const VBoxMediaList &mediums = vboxGlobal().currentMediaList();
    425     prepareToRefresh(mediums.size());
    426     VBoxMediaList::const_iterator it;
    427     for (it = mediums.begin(); it != mediums.end(); ++it)
    428         sltHandleMediumCreated((*it).id());
     422    /* Load mediums: */
     423    QList<QString> mediumIDs = vboxGlobal().mediumIDs();
     424    QList<QString> loadedMediumIDs;
     425    prepareToRefresh(mediumIDs.size());
     426    while (!mediumIDs.isEmpty())
     427    {
     428        /* Get first available medium: */
     429        QString strMediumID = mediumIDs.first();
     430        UIMedium medium = vboxGlobal().medium(strMediumID);
     431        /* Make sure medium parent (if any) is already in list: */
     432        while (medium.parentID() != UIMedium::nullID() &&
     433               !loadedMediumIDs.contains(medium.parentID()))
     434        {
     435            medium = medium.parent();
     436            strMediumID = medium.id();
     437        }
     438        /* Insert resulting medium into tree: */
     439        int iItemIndex = mediumIDs.indexOf(strMediumID);
     440        AssertReturnVoid(iItemIndex != -1);
     441        loadedMediumIDs.append(mediumIDs.takeAt(iItemIndex));
     442        sltHandleMediumCreated(strMediumID);
     443    }
    429444
    430445    /* Select the first item to be the current one
     
    878893    connect(&vboxGlobal(), SIGNAL(sigMediumEnumerationFinished()),
    879894            this, SLOT(sltHandleMediumEnumerationFinish()));
    880 
    881     /* Configure Main event connections: */
    882     connect(gVBoxEvents, SIGNAL(sigMachineDataChange(QString)), this, SLOT(refreshAll()));
    883     connect(gVBoxEvents, SIGNAL(sigMachineRegistered(QString, bool)), this, SLOT(refreshAll()));
    884     connect(gVBoxEvents, SIGNAL(sigSnapshotChange(QString, QString)), this, SLOT(refreshAll()));
    885895}
    886896
     
    11591169    {
    11601170        /* Emulate (possible partial) medium-enumeration: */
    1161         const VBoxMediaList &mediums = vboxGlobal().currentMediaList();
    1162         prepareToRefresh(mediums.size());
    1163         VBoxMediaList::const_iterator it;
    1164         /* Add every medium we have into trees: */
    1165         for (it = mediums.begin(); it != mediums.end(); ++it)
    1166         {
    1167             sltHandleMediumCreated((*it).id());
    1168             /* But advance progress-bar only for created mediums: */
    1169             if ((*it).state() != KMediumState_NotCreated)
     1171        QList<QString> mediumIDs = vboxGlobal().mediumIDs();
     1172        QList<QString> loadedMediumIDs;
     1173        prepareToRefresh(mediumIDs.size());
     1174        while (!mediumIDs.isEmpty())
     1175        {
     1176            /* Get first available medium: */
     1177            QString strMediumID = mediumIDs.first();
     1178            UIMedium medium = vboxGlobal().medium(strMediumID);
     1179            /* Make sure medium parent (if any) is already in list: */
     1180            while (medium.parentID() != UIMedium::nullID() &&
     1181                   !loadedMediumIDs.contains(medium.parentID()))
     1182            {
     1183                medium = medium.parent();
     1184                strMediumID = medium.id();
     1185            }
     1186            /* Insert resulting medium into tree: */
     1187            int iItemIndex = mediumIDs.indexOf(strMediumID);
     1188            AssertReturnVoid(iItemIndex != -1);
     1189            loadedMediumIDs.append(mediumIDs.takeAt(iItemIndex));
     1190            sltHandleMediumCreated(strMediumID);
     1191            /* Advance progress-bar only for created mediums: */
     1192            if (medium.state() != KMediumState_NotCreated)
    11701193                m_pProgressBar->setValue(m_pProgressBar->value() + 1);
    11711194        }
     
    16401663        {
    16411664            /* False for children: */
    1642             return !pItem->medium().parent();
     1665            return pItem->medium().parentID() == UIMedium::nullID();
    16431666        }
    16441667        case Action_Modify:
    16451668        {
    16461669            /* False for children: */
    1647             return !pItem->medium().parent();
     1670            return pItem->medium().parentID() == UIMedium::nullID();
    16481671        }
    16491672        case Action_Remove:
     
    17301753
    17311754/* static */
    1732 bool UIMediumManager::isMediumAttachedToHiddenMachinesOnly(const UIMedium &medium)
     1755bool UIMediumManager::isMediumAttachedToHiddenMachinesOnly(UIMedium medium)
    17331756{
    17341757    /* Iterate till the root: */
    1735     const UIMedium *pMedium = &medium;
    17361758    do
    17371759    {
    1738         /* Ignore medium if its hidden or attached to hidden machines only: */
    1739         if (pMedium->isHidden())
     1760        /* Ignore medium if its hidden
     1761         * or attached to hidden machines only: */
     1762        if (medium.isHidden())
    17401763            return true;
    17411764        /* Move iterator to parent: */
    1742         pMedium = pMedium->parent();
    1743     }
    1744     while (pMedium);
     1765        medium = medium.parent();
     1766    }
     1767    while (!medium.isNull());
    17451768    /* False by default: */
    17461769    return false;
  • trunk/src/VBox/Frontends/VirtualBox/src/medium/UIMediumManager.h

    r48264 r48301  
    152152
    153153    /* Static helper: Enumeration stuff: */
    154     static bool isMediumAttachedToHiddenMachinesOnly(const UIMedium &medium);
     154    static bool isMediumAttachedToHiddenMachinesOnly(UIMedium medium);
    155155
    156156    /* Variable: Singleton instance: */
  • trunk/src/VBox/Frontends/VirtualBox/src/selector/UISelectorWindow.cpp

    r48260 r48301  
    191191
    192192    /* Look for at least one inaccessible medium: */
    193     const VBoxMediaList &list = vboxGlobal().currentMediaList();
    194     VBoxMediaList::const_iterator it;
    195     for (it = list.begin(); it != list.end(); ++it)
    196         if ((*it).state() == KMediumState_Inaccessible)
     193    bool fIsThereAnyInaccessibleMedium = false;
     194    foreach (const QString &strMediumID, vboxGlobal().mediumIDs())
     195    {
     196        if (vboxGlobal().medium(strMediumID).state() == KMediumState_Inaccessible)
     197        {
     198            fIsThereAnyInaccessibleMedium = true;
    197199            break;
     200        }
     201    }
    198202
    199203    /* Warn the user about inaccessible medium: */
    200     if (it != list.end() && !msgCenter().warnAboutInaccessibleMedia())
     204    if (fIsThereAnyInaccessibleMedium && !msgCenter().warnAboutInaccessibleMedia())
    201205    {
    202206        /* Open the MM window (without refresh): */
  • trunk/src/VBox/Frontends/VirtualBox/src/settings/machine/UIMachineSettingsStorage.cpp

    r48269 r48301  
    19611961                    storageAttachmentData.m_fAttachmentTempEject = attachment.GetTemporaryEject();
    19621962                    storageAttachmentData.m_fAttachmentNonRotational = attachment.GetNonRotational();
    1963                     CMedium cmedium = attachment.GetMedium();
    1964                     UIMedium uimedium = cmedium.isNull() ? UIMedium() : vboxGlobal().medium(cmedium.GetId());
    1965                     storageAttachmentData.m_strAttachmentMediumId = uimedium.id();
     1963                    const CMedium cmedium = attachment.GetMedium();
     1964                    storageAttachmentData.m_strAttachmentMediumId = cmedium.isNull() ? UIMedium::nullID() : cmedium.GetId();
    19661965                }
    19671966
     
    31923191void UIMachineSettingsStorage::addChooseHostDriveActions(QMenu *pOpenMediumMenu)
    31933192{
    3194     const VBoxMediaList &mediums = vboxGlobal().currentMediaList();
    3195     VBoxMediaList::const_iterator it;
    3196     for (it = mediums.begin(); it != mediums.end(); ++it)
    3197     {
    3198         const UIMedium &medium = *it;
     3193    foreach (const QString &strMediumID, vboxGlobal().mediumIDs())
     3194    {
     3195        const UIMedium medium = vboxGlobal().medium(strMediumID);
    31993196        if (medium.isHostDrive() && m_pMediumIdHolder->type() == medium.type())
    32003197        {
  • trunk/src/VBox/Frontends/VirtualBox/src/widgets/VBoxMediaComboBox.cpp

    r48269 r48301  
    6767    clear(), mMedia.clear();
    6868
    69     VBoxMediaList list (vboxGlobal().currentMediaList());
    70     foreach (UIMedium medium, list)
    71         sltHandleMediumCreated(medium.id());
     69    foreach (const QString &strMediumID, vboxGlobal().mediumIDs())
     70        sltHandleMediumCreated(strMediumID);
    7271
    7372    /* If at least one real medium present, process null medium */
     
    178177
    179178    /* In !mShowDiffs mode, we ignore all diffs: */
    180     if (!mShowDiffs && medium.type() == UIMediumType_HardDisk && medium.parent())
     179    if (!mShowDiffs && medium.type() == UIMediumType_HardDisk && medium.parentID() != UIMedium::nullID())
    181180        return;
    182181
     
    227226    /* If no real medium left, add the NULL medium: */
    228227    if (count() == 0)
    229     {
    230         UIMedium nullMedium;
    231         sltHandleMediumCreated(nullMedium.id());
    232     }
     228        sltHandleMediumCreated(UIMedium::nullID());
    233229
    234230    /* Emit the signal to ensure the parent dialog handles the change of
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