Changeset 48301 in vbox for trunk/src/VBox/Frontends
- Timestamp:
- Sep 5, 2013 11:52:39 AM (11 years ago)
- 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 71 71 , SetRegionEventType 72 72 , ModifierKeyChangeEventType 73 , MediumEnumeratedEventType74 , MediumsEnumeratedEventType75 73 #ifdef Q_WS_WIN 76 74 , ShellExecuteEventType -
trunk/src/VBox/Frontends/VirtualBox/src/globals/VBoxGlobal.cpp
r48277 r48301 70 70 #include "UISession.h" 71 71 #include "UIConverter.h" 72 #include "UIMediumEnumerator.h" 72 73 73 74 #ifdef Q_WS_X11 … … 162 163 #endif 163 164 164 /* Medium enumerated event: */165 class UIMediumEnumeratedEvent : public QEvent166 {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 QEvent182 {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 195 165 // VBoxGlobal 196 166 //////////////////////////////////////////////////////////////////////////////// … … 270 240 , mSelectorWnd (NULL) 271 241 , m_pVirtualMachine(0) 272 , m_pMediumEnumerat ionThread(0)242 , m_pMediumEnumerator(0) 273 243 , mIsKWinManaged (false) 274 244 #if defined(DEBUG_bird) … … 1687 1657 } 1688 1658 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()); 1659 void VBoxGlobal::createMedium(const UIMedium &medium) 1660 { 1661 /* Create medium in medium-enumerator: */ 1662 m_pMediumEnumerator->createMedium(medium); 1663 } 1664 1665 void VBoxGlobal::updateMedium(const UIMedium &medium) 1666 { 1667 /* Update medium of medium-enumerator: */ 1668 m_pMediumEnumerator->updateMedium(medium); 1767 1669 } 1768 1670 1769 1671 void VBoxGlobal::deleteMedium(const QString &strMediumID) 1770 1672 { 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); 1802 1675 } 1803 1676 … … 1937 1810 } 1938 1811 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 2012 1812 void VBoxGlobal::startMediumEnumeration(bool fForceStart /*= true*/) 2013 1813 { … … 2032 1832 return; 2033 1833 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 1838 bool VBoxGlobal::isMediumEnumerationInProgress() const 1839 { 1840 /* Redirect request to medium-enumerator: */ 1841 return m_pMediumEnumerator->isMediumEnumerationInProgress(); 2094 1842 } 2095 1843 2096 1844 UIMedium VBoxGlobal::medium(const QString &strMediumID) const 2097 1845 { 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 1850 QList<QString> VBoxGlobal::mediumIDs() const 1851 { 1852 /* Redirect call to medium-enumerator: */ 1853 return m_pMediumEnumerator->mediumIDs(); 2102 1854 } 2103 1855 … … 3982 3734 // Protected members 3983 3735 //////////////////////////////////////////////////////////////////////////////// 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 }4031 3736 4032 3737 bool VBoxGlobal::eventFilter (QObject *aObject, QEvent *aEvent) … … 4543 4248 * but this method should be run anyway just to enumerate null UIMedium object, 4544 4249 * 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 } 4545 4266 if (agressiveCaching()) 4546 4267 startMediumEnumeration(); … … 4599 4320 UIExtraDataEventHandler::destroy(); 4600 4321 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; 4608 4325 4609 4326 if (mSelectorWnd) … … 4621 4338 mTypes.clear(); 4622 4339 4623 /* media list contains a lot of CUUnknown, release them */4624 m_mediums.clear();4625 4340 /* the last steps to ensure we don't use COM any more */ 4626 4341 mHost.detach(); -
trunk/src/VBox/Frontends/VirtualBox/src/globals/VBoxGlobal.h
r48269 r48301 52 52 class CUSBDevice; 53 53 class QSpinBox; 54 class UIMediumEnumerator; 54 55 55 56 // VBoxGlobal class … … 253 254 void startMediumEnumeration(bool fForceStart = true); 254 255 bool agressiveCaching() const { return mAgressiveCaching; } 255 bool isMediumEnumerationInProgress() const { return !!m_pMediumEnumerationThread; }256 bool isMediumEnumerationInProgress() const; 256 257 UIMedium medium(const QString &strMediumID) const; 257 const VBoxMediaList ¤tMediaList() const { return m_mediums; }258 QList<QString> mediumIDs() const; 258 259 259 260 /* various helpers */ … … 395 396 protected: 396 397 397 bool event(QEvent *pEvent);398 398 bool eventFilter (QObject *, QEvent *); 399 399 … … 426 426 bool mShowStartVMErrors; 427 427 428 QThread *m_pMediumEnumerationThread;429 VBoxMediaList m_mediums;428 /* Variable: Medium-enumeration stuff: */ 429 UIMediumEnumerator *m_pMediumEnumerator; 430 430 431 431 RenderMode vm_render_mode; -
trunk/src/VBox/Frontends/VirtualBox/src/medium/UIMedium.cpp
r48278 r48301 37 37 #endif /* !VBOX_WITH_PRECOMPILED_HEADERS */ 38 38 39 QString UIMedium::m_sstrNullID = QUuid().toString().remove('{').remove('}'); 39 40 QString UIMedium::m_sstrTable = QString("<table>%1</table>"); 40 41 QString UIMedium::m_sstrRow = QString("<tr><td>%1</td></tr>"); … … 43 44 : m_type(UIMediumType_Invalid) 44 45 , m_state(KMediumState_NotCreated) 45 , m_pParent(0)46 46 { 47 47 refresh(); … … 49 49 } 50 50 51 UIMedium::UIMedium(const CMedium &medium, UIMediumType type , UIMedium *pParent /*= 0*/)51 UIMedium::UIMedium(const CMedium &medium, UIMediumType type) 52 52 : m_medium(medium) 53 53 , m_type(type) 54 54 , m_state(KMediumState_NotCreated) 55 , m_pParent(pParent)56 55 { 57 56 refresh(); … … 63 62 , m_type(type) 64 63 , m_state(state) 65 , m_pParent(0)66 64 { 67 65 refresh(); … … 106 104 m_curStateMachineIds = other.curStateMachineIds(); 107 105 108 m_pParent = other.parent(); 106 m_strParentID = other.parentID(); 107 m_strRootID = other.rootID(); 109 108 110 109 m_noDiffs = other.cache(); … … 194 193 } 195 194 195 /* Initialize parent/root IDs: */ 196 m_strParentID = nullID(); 197 m_strRootID = m_strId; 196 198 if (m_type == UIMediumType_HardDisk) 197 199 { … … 207 209 m_fReadOnly = m_medium.GetReadOnly(); 208 210 209 /* Adjust the parent if its possible: */211 /* Adjust parent/root IDs: */ 210 212 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(); 228 219 } 229 220 } … … 371 362 } 372 363 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; 364 UIMedium UIMedium::parent() const 365 { 366 /* Redirect call to VBoxGlobal: */ 367 return vboxGlobal().medium(m_strParentID); 368 } 369 370 UIMedium UIMedium::root() const 371 { 372 /* Redirect call to VBoxGlobal: */ 373 return vboxGlobal().medium(m_strRootID); 384 374 } 385 375 … … 500 490 QString strDetails, strText; 501 491 502 UIMedium *pRoot = unconst(this); 492 /* Note: root accessible only if medium enumerated: */ 493 UIMedium rootMedium = root(); 503 494 KMediumState eState = m_state; 504 495 … … 507 498 if (fNoDiffs) 508 499 { 509 pRoot = &this->root(); 510 511 bool isDiff = (!fPredictDiff && m_pParent != NULL) || (fPredictDiff && m_fReadOnly); 500 bool isDiff = (!fPredictDiff && parentID() != nullID()) || (fPredictDiff && m_fReadOnly); 512 501 513 502 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); 516 505 517 506 eState = this->state(true /* fNoDiffs */); 518 507 519 if ( pRoot->m_state == KMediumState_NotCreated)508 if (rootMedium.m_state == KMediumState_NotCreated) 520 509 eState = KMediumState_NotCreated; 521 510 } 522 511 else 523 512 { 524 strDetails = QString("%1, ").arg( pRoot->m_strHardDiskType);513 strDetails = QString("%1, ").arg(rootMedium.m_strHardDiskType); 525 514 } 526 515 } … … 539 528 break; 540 529 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; 542 531 break; 543 532 } 544 533 545 534 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); 548 537 549 538 return strDetails; … … 553 542 QString UIMedium::nullID() 554 543 { 555 return QUuid().toString().remove('{').remove('}');544 return m_sstrNullID; 556 545 } 557 546 … … 569 558 570 559 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; 576 565 577 566 if (m_noDiffs.toolTip.isNull()) … … 581 570 "mode to inspect these media.", "medium")); 582 571 583 if (! cur->m_result.isOk())572 if (!parentMedium.m_result.isOk()) 584 573 { 585 m_noDiffs.result = cur->m_result;574 m_noDiffs.result = parentMedium.m_result; 586 575 break; 587 576 } … … 589 578 } 590 579 591 if ( m_pParent != NULL&& !m_fReadOnly)580 if (parentID() != nullID() && !m_fReadOnly) 592 581 { 593 582 m_noDiffs.toolTip = root().tip() + -
trunk/src/VBox/Frontends/VirtualBox/src/medium/UIMedium.h
r48278 r48301 22 22 /* Qt includes: */ 23 23 #include <QMap> 24 #include <QLinkedList>25 24 #include <QPixmap> 26 25 … … 89 88 /* Lazy wrapping constructor: 90 89 * 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); 92 91 93 92 /* Wrapping constructor with known medium state: … … 196 195 const QList <QString> &curStateMachineIds() const { return m_curStateMachineIds; } 197 196 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; 204 202 205 203 QString toolTip(bool fNoDiffs = false, bool fCheckRO = false, bool fNullAllowed = false) const; … … 259 257 QList<QString> m_curStateMachineIds; 260 258 261 UIMedium *m_pParent; 259 QString m_strParentID; 260 QString m_strRootID; 262 261 263 262 NoDiffsCache m_noDiffs; 264 263 264 static QString m_sstrNullID; 265 265 static QString m_sstrTable; 266 266 static QString m_sstrRow; … … 268 268 Q_DECLARE_METATYPE(UIMedium); 269 269 270 typedef QLinkedList<UIMedium> VBoxMediaList;271 270 typedef QMap<QString, UIMedium> UIMediumMap; 272 271 -
trunk/src/VBox/Frontends/VirtualBox/src/medium/UIMediumEnumerator.cpp
r48274 r48301 100 100 /* Get medium ID: */ 101 101 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())); 103 103 104 104 /* Make sure medium doesn't exists already: */ … … 116 116 /* Get medium ID: */ 117 117 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())); 119 119 120 120 /* Make sure medium still exists: */ … … 130 130 void UIMediumEnumerator::deleteMedium(const QString &strMediumID) 131 131 { 132 // printf("UIMediumEnumerator: Medium with ID={%s} removed.\n", strMediumID.toAscii().constData());132 LogRel(("UIMediumEnumerator: Medium with ID={%s} removed.\n", strMediumID.toAscii().constData())); 133 133 134 134 /* Make sure medium still exists: */ … … 159 159 160 160 /* Notify listener: */ 161 // printf("UIMediumEnumerator: Medium-enumeration started...\n");161 LogRel(("UIMediumEnumerator: Medium-enumeration started...\n")); 162 162 m_fMediumEnumerationInProgress = true; 163 163 emit sigMediumEnumerationStarted(); … … 171 171 void UIMediumEnumerator::sltHandleMachineUpdate(QString strMachineID) 172 172 { 173 // printf("Machine event received, ID = %s\n", strMachineID.toAscii().constData());173 LogRel(("Machine event received, ID = %s\n", strMachineID.toAscii().constData())); 174 174 175 175 /* Compose a map of previous usage: */ … … 182 182 oldUsage << strMediumID; 183 183 } 184 // printf("Old usage: %s\n", oldUsage.join(", ").toAscii().constData());184 LogRel(("Old usage: %s\n", oldUsage.join(", ").toAscii().constData())); 185 185 186 186 /* Compose a map of current usage: */ … … 201 201 } 202 202 } 203 // printf("New usage: %s\n", newUsage.join(", ").toAscii().constData());203 LogRel(("New usage: %s\n", newUsage.join(", ").toAscii().constData())); 204 204 205 205 /* Manipulations over the sets: */ … … 210 210 QStringList excludedList = excludedSet.toList(); 211 211 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())); 214 214 215 215 /* For each of excluded items: */ … … 244 244 } 245 245 246 // printf("Machine event processed, ID = %s\n", strMachineID.toAscii().constData());246 LogRel(("Machine event processed, ID = %s\n", strMachineID.toAscii().constData())); 247 247 } 248 248 … … 256 256 UIMedium medium = pTask->data().value<UIMedium>(); 257 257 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())); 259 259 260 260 /* Delete task: */ … … 275 275 { 276 276 /* Notify listener: */ 277 // printf("UIMediumEnumerator: Medium-enumeration finished!\n");277 LogRel(("UIMediumEnumerator: Medium-enumeration finished!\n")); 278 278 m_fMediumEnumerationInProgress = false; 279 279 emit sigMediumEnumerationFinished(); -
trunk/src/VBox/Frontends/VirtualBox/src/medium/UIMediumManager.cpp
r48269 r48301 38 38 #include "QILabel.h" 39 39 #include "UIIconPool.h" 40 #include "UIVirtualBoxEventHandler.h"41 40 #include "UIMediumTypeChangeDialog.h" 42 41 … … 421 420 mTabWidget->setTabIcon(FDTab, m_iconFD); 422 421 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 } 429 444 430 445 /* Select the first item to be the current one … … 878 893 connect(&vboxGlobal(), SIGNAL(sigMediumEnumerationFinished()), 879 894 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()));885 895 } 886 896 … … 1159 1169 { 1160 1170 /* 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) 1170 1193 m_pProgressBar->setValue(m_pProgressBar->value() + 1); 1171 1194 } … … 1640 1663 { 1641 1664 /* False for children: */ 1642 return !pItem->medium().parent();1665 return pItem->medium().parentID() == UIMedium::nullID(); 1643 1666 } 1644 1667 case Action_Modify: 1645 1668 { 1646 1669 /* False for children: */ 1647 return !pItem->medium().parent();1670 return pItem->medium().parentID() == UIMedium::nullID(); 1648 1671 } 1649 1672 case Action_Remove: … … 1730 1753 1731 1754 /* static */ 1732 bool UIMediumManager::isMediumAttachedToHiddenMachinesOnly( const UIMedium &medium)1755 bool UIMediumManager::isMediumAttachedToHiddenMachinesOnly(UIMedium medium) 1733 1756 { 1734 1757 /* Iterate till the root: */ 1735 const UIMedium *pMedium = &medium;1736 1758 do 1737 1759 { 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()) 1740 1763 return true; 1741 1764 /* Move iterator to parent: */ 1742 pMedium = pMedium->parent();1743 } 1744 while ( pMedium);1765 medium = medium.parent(); 1766 } 1767 while (!medium.isNull()); 1745 1768 /* False by default: */ 1746 1769 return false; -
trunk/src/VBox/Frontends/VirtualBox/src/medium/UIMediumManager.h
r48264 r48301 152 152 153 153 /* Static helper: Enumeration stuff: */ 154 static bool isMediumAttachedToHiddenMachinesOnly( const UIMedium &medium);154 static bool isMediumAttachedToHiddenMachinesOnly(UIMedium medium); 155 155 156 156 /* Variable: Singleton instance: */ -
trunk/src/VBox/Frontends/VirtualBox/src/selector/UISelectorWindow.cpp
r48260 r48301 191 191 192 192 /* 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; 197 199 break; 200 } 201 } 198 202 199 203 /* Warn the user about inaccessible medium: */ 200 if ( it != list.end()&& !msgCenter().warnAboutInaccessibleMedia())204 if (fIsThereAnyInaccessibleMedium && !msgCenter().warnAboutInaccessibleMedia()) 201 205 { 202 206 /* Open the MM window (without refresh): */ -
trunk/src/VBox/Frontends/VirtualBox/src/settings/machine/UIMachineSettingsStorage.cpp
r48269 r48301 1961 1961 storageAttachmentData.m_fAttachmentTempEject = attachment.GetTemporaryEject(); 1962 1962 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(); 1966 1965 } 1967 1966 … … 3192 3191 void UIMachineSettingsStorage::addChooseHostDriveActions(QMenu *pOpenMediumMenu) 3193 3192 { 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); 3199 3196 if (medium.isHostDrive() && m_pMediumIdHolder->type() == medium.type()) 3200 3197 { -
trunk/src/VBox/Frontends/VirtualBox/src/widgets/VBoxMediaComboBox.cpp
r48269 r48301 67 67 clear(), mMedia.clear(); 68 68 69 VBoxMediaList list (vboxGlobal().currentMediaList()); 70 foreach (UIMedium medium, list) 71 sltHandleMediumCreated(medium.id()); 69 foreach (const QString &strMediumID, vboxGlobal().mediumIDs()) 70 sltHandleMediumCreated(strMediumID); 72 71 73 72 /* If at least one real medium present, process null medium */ … … 178 177 179 178 /* 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()) 181 180 return; 182 181 … … 227 226 /* If no real medium left, add the NULL medium: */ 228 227 if (count() == 0) 229 { 230 UIMedium nullMedium; 231 sltHandleMediumCreated(nullMedium.id()); 232 } 228 sltHandleMediumCreated(UIMedium::nullID()); 233 229 234 230 /* Emit the signal to ensure the parent dialog handles the change of
Note:
See TracChangeset
for help on using the changeset viewer.