Changeset 48261 in vbox for trunk/src/VBox/Frontends
- Timestamp:
- Sep 4, 2013 11:53:16 AM (11 years ago)
- Location:
- trunk/src/VBox/Frontends/VirtualBox/src
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Frontends/VirtualBox/src/globals/VBoxGlobal.cpp
r48260 r48261 1653 1653 } 1654 1654 1655 static void addNullMediumToList(VBoxMediaList &mediums, VBoxMediaList::iterator where)1656 {1657 /* Append the NULL medium to the medium list: */1658 UIMedium medium;1659 mediums.insert(where, medium);1660 }1661 1662 static void addMediumsToList(const CMediumVector &inputMediums,1663 VBoxMediaList &outputMediums,1664 VBoxMediaList::iterator where,1665 UIMediumType mediumType,1666 UIMedium *pParent = 0)1667 {1668 /* Appends the given list of input-mediums to the output-mediums: */1669 VBoxMediaList::iterator first = where;1670 1671 for (CMediumVector::ConstIterator it = inputMediums.begin(); it != inputMediums.end(); ++it)1672 {1673 CMedium cmedium(*it);1674 UIMedium medium(cmedium, mediumType, pParent);1675 1676 /* Search for a proper alphabetic position: */1677 VBoxMediaList::iterator jt = first;1678 for (; jt != where; ++ jt)1679 if ((*jt).name().localeAwareCompare(medium.name()) > 0)1680 break;1681 1682 outputMediums.insert(jt, medium);1683 1684 /* Adjust the first item if inserted before it: */1685 if (jt == first)1686 --first;1687 }1688 }1689 1690 static void addHardDisksToList(const CMediumVector &inputMediums,1691 VBoxMediaList &outputMediums,1692 VBoxMediaList::iterator where,1693 UIMedium *pParent = 0)1694 {1695 /* Appends the given list of input-hard-disks and all their children to the output-mediums: */1696 VBoxMediaList::iterator first = where;1697 1698 /* First pass: Add siblings sorted */1699 for (CMediumVector::ConstIterator it = inputMediums.begin(); it != inputMediums.end(); ++it)1700 {1701 CMedium cmedium(*it);1702 UIMedium medium(cmedium, UIMediumType_HardDisk, pParent);1703 1704 /* Search for a proper alphabetic position: */1705 VBoxMediaList::iterator jt = first;1706 for (; jt != where; ++ jt)1707 if ((*jt).name().localeAwareCompare(medium.name()) > 0)1708 break;1709 1710 outputMediums.insert(jt, medium);1711 1712 /* Adjust the first item if inserted before it: */1713 if (jt == first)1714 --first;1715 }1716 1717 /* Second pass: Add children: */1718 for (VBoxMediaList::iterator it = first; it != where;)1719 {1720 CMediumVector children = (*it).medium().GetChildren();1721 UIMedium *parent = &(*it);1722 1723 ++it; /* go to the next sibling before inserting children */1724 addHardDisksToList(children, outputMediums, it, parent);1725 }1726 }1727 1728 void VBoxGlobal::startMediumEnumeration(bool fForceStart /*= true*/)1729 {1730 /* Make sure VBoxGlobal is already valid: */1731 AssertReturnVoid(mValid);1732 1733 /* Make sure enumeration is not already started: */1734 if (m_pMediumEnumerationThread)1735 return;1736 1737 /* Ignore the request during VBoxGlobal cleanup: */1738 if (m_sfCleanupInProgress)1739 return;1740 1741 /* If asked to restore snapshot, don't do this till *after* we're done1742 * restoring or the code with have a heart attack. */1743 if (shouldRestoreCurrentSnapshot())1744 return;1745 1746 /* Developer doesn't want any unnecessary media caching! */1747 if (!fForceStart && !agressiveCaching())1748 return;1749 1750 /* Compose a list of all currently known mediums & their children: */1751 m_mediums.clear();1752 addNullMediumToList(m_mediums, m_mediums.end());1753 addHardDisksToList(mVBox.GetHardDisks(), m_mediums, m_mediums.end());1754 addMediumsToList(mHost.GetDVDDrives(), m_mediums, m_mediums.end(), UIMediumType_DVD);1755 addMediumsToList(mVBox.GetDVDImages(), m_mediums, m_mediums.end(), UIMediumType_DVD);1756 addMediumsToList(mHost.GetFloppyDrives(), m_mediums, m_mediums.end(), UIMediumType_Floppy);1757 addMediumsToList(mVBox.GetFloppyImages(), m_mediums, m_mediums.end(), UIMediumType_Floppy);1758 1759 /* Enumeration thread class: */1760 class MediaEnumThread : public QThread1761 {1762 public:1763 1764 MediaEnumThread(VBoxMediaList &mediums)1765 : m_mediums(mediums.size())1766 , m_iterator(mediums.begin())1767 {1768 int i = 0;1769 for (VBoxMediaList::const_iterator it = mediums.begin(); it != mediums.end(); ++it)1770 m_mediums[i++] = *it;1771 }1772 1773 void run()1774 {1775 LogFlow(("MediaEnumThread started.\n"));1776 COMBase::InitializeCOM(false);1777 1778 QObject *pSelf = &vboxGlobal();1779 1780 /* Enumerate medium list: */1781 for (int i = 0; i < m_mediums.size() && !m_sfCleanupInProgress; ++i)1782 {1783 m_mediums[i].blockAndQueryState();1784 QApplication::postEvent(pSelf, new UIMediumEnumeratedEvent(m_mediums[i], m_iterator));1785 ++m_iterator;1786 }1787 1788 /* Post the end-of-enumeration event: */1789 if (!m_sfCleanupInProgress)1790 QApplication::postEvent(pSelf, new UIMediumsEnumeratedEvent(m_iterator));1791 1792 COMBase::CleanupCOM();1793 LogFlow(("MediaEnumThread finished.\n"));1794 }1795 1796 private:1797 1798 QVector<UIMedium> m_mediums;1799 VBoxMediaList::iterator m_iterator;1800 };1801 1802 m_pMediumEnumerationThread = new MediaEnumThread(m_mediums);1803 AssertReturnVoid(m_pMediumEnumerationThread);1804 1805 /* Emit signal *after* we set m_pMediumEnumerationThread to != NULL1806 * to cause isMediaEnumerationStarted() to return TRUE from slots: */1807 emit sigMediumEnumerationStarted();1808 1809 m_pMediumEnumerationThread->start();1810 }1811 1812 1655 void VBoxGlobal::reloadProxySettings() 1813 1656 { … … 2112 1955 2113 1956 return QString(); 1957 } 1958 1959 static void addNullMediumToList(VBoxMediaList &mediums, VBoxMediaList::iterator where) 1960 { 1961 /* Append the NULL medium to the medium list: */ 1962 UIMedium medium; 1963 mediums.insert(where, medium); 1964 } 1965 1966 static void addMediumsToList(const CMediumVector &inputMediums, 1967 VBoxMediaList &outputMediums, 1968 VBoxMediaList::iterator where, 1969 UIMediumType mediumType, 1970 UIMedium *pParent = 0) 1971 { 1972 /* Appends the given list of input-mediums to the output-mediums: */ 1973 VBoxMediaList::iterator first = where; 1974 1975 for (CMediumVector::ConstIterator it = inputMediums.begin(); it != inputMediums.end(); ++it) 1976 { 1977 CMedium cmedium(*it); 1978 UIMedium medium(cmedium, mediumType, pParent); 1979 1980 /* Search for a proper alphabetic position: */ 1981 VBoxMediaList::iterator jt = first; 1982 for (; jt != where; ++ jt) 1983 if ((*jt).name().localeAwareCompare(medium.name()) > 0) 1984 break; 1985 1986 outputMediums.insert(jt, medium); 1987 1988 /* Adjust the first item if inserted before it: */ 1989 if (jt == first) 1990 --first; 1991 } 1992 } 1993 1994 static void addHardDisksToList(const CMediumVector &inputMediums, 1995 VBoxMediaList &outputMediums, 1996 VBoxMediaList::iterator where, 1997 UIMedium *pParent = 0) 1998 { 1999 /* Appends the given list of input-hard-disks and all their children to the output-mediums: */ 2000 VBoxMediaList::iterator first = where; 2001 2002 /* First pass: Add siblings sorted */ 2003 for (CMediumVector::ConstIterator it = inputMediums.begin(); it != inputMediums.end(); ++it) 2004 { 2005 CMedium cmedium(*it); 2006 UIMedium medium(cmedium, UIMediumType_HardDisk, pParent); 2007 2008 /* Search for a proper alphabetic position: */ 2009 VBoxMediaList::iterator jt = first; 2010 for (; jt != where; ++ jt) 2011 if ((*jt).name().localeAwareCompare(medium.name()) > 0) 2012 break; 2013 2014 outputMediums.insert(jt, medium); 2015 2016 /* Adjust the first item if inserted before it: */ 2017 if (jt == first) 2018 --first; 2019 } 2020 2021 /* Second pass: Add children: */ 2022 for (VBoxMediaList::iterator it = first; it != where;) 2023 { 2024 CMediumVector children = (*it).medium().GetChildren(); 2025 UIMedium *parent = &(*it); 2026 2027 ++it; /* go to the next sibling before inserting children */ 2028 addHardDisksToList(children, outputMediums, it, parent); 2029 } 2030 } 2031 2032 void VBoxGlobal::startMediumEnumeration(bool fForceStart /*= true*/) 2033 { 2034 /* Make sure VBoxGlobal is already valid: */ 2035 AssertReturnVoid(mValid); 2036 2037 /* Make sure enumeration is not already started: */ 2038 if (m_pMediumEnumerationThread) 2039 return; 2040 2041 /* Ignore the request during VBoxGlobal cleanup: */ 2042 if (m_sfCleanupInProgress) 2043 return; 2044 2045 /* If asked to restore snapshot, don't do this till *after* we're done 2046 * restoring or the code with have a heart attack. */ 2047 if (shouldRestoreCurrentSnapshot()) 2048 return; 2049 2050 /* Developer doesn't want any unnecessary media caching! */ 2051 if (!fForceStart && !agressiveCaching()) 2052 return; 2053 2054 /* Compose a list of all currently known mediums & their children: */ 2055 m_mediums.clear(); 2056 addNullMediumToList(m_mediums, m_mediums.end()); 2057 addHardDisksToList(mVBox.GetHardDisks(), m_mediums, m_mediums.end()); 2058 addMediumsToList(mHost.GetDVDDrives(), m_mediums, m_mediums.end(), UIMediumType_DVD); 2059 addMediumsToList(mVBox.GetDVDImages(), m_mediums, m_mediums.end(), UIMediumType_DVD); 2060 addMediumsToList(mHost.GetFloppyDrives(), m_mediums, m_mediums.end(), UIMediumType_Floppy); 2061 addMediumsToList(mVBox.GetFloppyImages(), m_mediums, m_mediums.end(), UIMediumType_Floppy); 2062 2063 /* Enumeration thread class: */ 2064 class MediaEnumThread : public QThread 2065 { 2066 public: 2067 2068 MediaEnumThread(VBoxMediaList &mediums) 2069 : m_mediums(mediums.size()) 2070 , m_iterator(mediums.begin()) 2071 { 2072 int i = 0; 2073 for (VBoxMediaList::const_iterator it = mediums.begin(); it != mediums.end(); ++it) 2074 m_mediums[i++] = *it; 2075 } 2076 2077 void run() 2078 { 2079 LogFlow(("MediaEnumThread started.\n")); 2080 COMBase::InitializeCOM(false); 2081 2082 QObject *pSelf = &vboxGlobal(); 2083 2084 /* Enumerate medium list: */ 2085 for (int i = 0; i < m_mediums.size() && !m_sfCleanupInProgress; ++i) 2086 { 2087 m_mediums[i].blockAndQueryState(); 2088 QApplication::postEvent(pSelf, new UIMediumEnumeratedEvent(m_mediums[i], m_iterator)); 2089 ++m_iterator; 2090 } 2091 2092 /* Post the end-of-enumeration event: */ 2093 if (!m_sfCleanupInProgress) 2094 QApplication::postEvent(pSelf, new UIMediumsEnumeratedEvent(m_iterator)); 2095 2096 COMBase::CleanupCOM(); 2097 LogFlow(("MediaEnumThread finished.\n")); 2098 } 2099 2100 private: 2101 2102 QVector<UIMedium> m_mediums; 2103 VBoxMediaList::iterator m_iterator; 2104 }; 2105 2106 m_pMediumEnumerationThread = new MediaEnumThread(m_mediums); 2107 AssertReturnVoid(m_pMediumEnumerationThread); 2108 2109 /* Emit signal *after* we set m_pMediumEnumerationThread to != NULL 2110 * to cause isMediaEnumerationStarted() to return TRUE from slots: */ 2111 emit sigMediumEnumerationStarted(); 2112 2113 m_pMediumEnumerationThread->start(); 2114 2114 } 2115 2115 -
trunk/src/VBox/Frontends/VirtualBox/src/globals/VBoxGlobal.h
r48260 r48261 242 242 void reloadProxySettings(); 243 243 244 /* API: Medium-processing stuff: */ 245 void createMedium(const UIMedium &medium); 246 void updateMedium(const UIMedium &medium); 247 void deleteMedium(const QString &strMediumID); 248 bool medium(const CMedium &cmedium, UIMedium &uimedium) const; 249 UIMedium medium(const QString &strMediumID) const; 250 244 251 /* API: Medium-enumeration stuff: */ 245 252 void startMediumEnumeration(bool fForceStart = true); … … 248 255 const VBoxMediaList ¤tMediaList() const { return m_mediums; } 249 256 250 /* API: Medium-processing stuff: */251 void createMedium(const UIMedium &medium);252 void updateMedium(const UIMedium &medium);253 void deleteMedium(const QString &strMediumID);254 255 bool medium(const CMedium &cmedium, UIMedium &uimedium) const;256 UIMedium medium(const QString &strMediumID) const;257 258 257 QString openMediumWithFileOpenDialog(UIMediumType mediumType, QWidget *pParent = 0, 259 258 const QString &strDefaultFolder = QString(), bool fUseLastFolder = true); 260 259 QString openMedium(UIMediumType mediumType, QString strMediumLocation, QWidget *pParent = 0); 261 262 /* Returns the number of current running Fe/Qt4 main windows. */263 int mainWindowCount();264 260 265 261 /* various helpers */ … … 376 372 signals: 377 373 374 /* Notifiers: Medium-processing stuff: */ 375 void sigMediumCreated(const UIMedium &medium); 376 void sigMediumUpdated(const UIMedium &medium); 377 void sigMediumDeleted(const QString &strMediumID); 378 378 379 /* Notifiers: Medium-enumeration stuff: */ 379 380 void sigMediumEnumerationStarted(); 380 381 void sigMediumEnumerated(const UIMedium &medium); 381 382 void sigMediumEnumerationFinished(); 382 383 /* Notifiers: Medium-processing stuff: */384 void sigMediumCreated(const UIMedium &medium);385 void sigMediumUpdated(const UIMedium &medium);386 void sigMediumDeleted(const QString &strMediumID);387 383 388 384 public slots: -
trunk/src/VBox/Frontends/VirtualBox/src/widgets/VBoxMediaComboBox.cpp
r48260 r48261 38 38 setSizePolicy (sp1); 39 39 40 /* Setup medium-enumeration handlers: */41 connect(&vboxGlobal(), SIGNAL(sigMediumEnumerationStarted()),42 this, SLOT(sltHandleMediumEnumerationStart()));43 connect(&vboxGlobal(), SIGNAL(sigMediumEnumerated(const UIMedium&)),44 this, SLOT(sltHandleMediumUpdated(const UIMedium&)));45 46 40 /* Setup medium-processing handlers: */ 47 41 connect(&vboxGlobal(), SIGNAL(sigMediumCreated(const UIMedium&)), … … 51 45 connect(&vboxGlobal(), SIGNAL(sigMediumDeleted(const QString&)), 52 46 this, SLOT(sltHandleMediumDeleted(const QString&))); 47 48 /* Setup medium-enumeration handlers: */ 49 connect(&vboxGlobal(), SIGNAL(sigMediumEnumerationStarted()), 50 this, SLOT(sltHandleMediumEnumerationStart())); 51 connect(&vboxGlobal(), SIGNAL(sigMediumEnumerated(const UIMedium&)), 52 this, SLOT(sltHandleMediumUpdated(const UIMedium&))); 53 53 54 54 /* Setup other connections */ -
trunk/src/VBox/Frontends/VirtualBox/src/widgets/VBoxMediaComboBox.h
r48260 r48261 52 52 protected slots: 53 53 54 /* Handler: Medium-enumeration stuff: */55 void sltHandleMediumEnumerationStart();56 57 54 /* Handlers: Medium-processing stuff: */ 58 55 void sltHandleMediumCreated(const UIMedium &medium); 59 56 void sltHandleMediumUpdated(const UIMedium &medium); 60 57 void sltHandleMediumDeleted(const QString &strMediumID); 58 59 /* Handler: Medium-enumeration stuff: */ 60 void sltHandleMediumEnumerationStart(); 61 61 62 62 void processActivated (int aIndex);
Note:
See TracChangeset
for help on using the changeset viewer.