Changeset 50768 in vbox
- Timestamp:
- Mar 13, 2014 2:39:33 PM (11 years ago)
- Location:
- trunk/src/VBox/Frontends/VirtualBox/src/medium
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Frontends/VirtualBox/src/medium/UIMediumManager.cpp
r50767 r50768 684 684 } 685 685 686 void UIMediumManager::sltRefreshAll()687 {688 /* Start medium-enumeration: */689 vboxGlobal().startMediumEnumeration();690 }691 692 686 void UIMediumManager::sltHandleMediumCreated(const QString &strMediumID) 693 687 { … … 834 828 if (fResult) 835 829 refetchCurrentChosenMediumItem(); 830 } 831 832 void UIMediumManager::sltRefreshAll() 833 { 834 /* Start medium-enumeration: */ 835 vboxGlobal().startMediumEnumeration(); 836 836 } 837 837 … … 1701 1701 } 1702 1702 1703 void UIMediumManager::updateMediumItem(const UIMedium &medium)1704 {1705 /* Get medium type: */1706 UIMediumType type = medium.type();1707 1708 /* Search for existing medium-item, create if was not found: */1709 UIMediumItem *pMediumItem = searchItem(treeWidget(type), CheckIfSuitableByID(medium.id()));1710 if (!pMediumItem) pMediumItem = createMediumItem(medium);1711 AssertPtrReturnVoid(pMediumItem);1712 1713 /* Update medium-item: */1714 pMediumItem->setMedium(medium);1715 LogRel2(("UIMediumManager: Medium-item with ID={%s} updated.\n", medium.id().toAscii().constData()));1716 1717 /* Update tab-icons: */1718 updateTabIcons(pMediumItem, Action_Edit);1719 1720 /* Re-fetch medium-item if it is current one updated: */1721 if (pMediumItem == mediumItem(type))1722 refetchCurrentMediumItem(type);1723 }1724 1725 void UIMediumManager::deleteMediumItem(const QString &strMediumID)1726 {1727 /* Search for corresponding tree-widget: */1728 QList<UIMediumType> types;1729 types << UIMediumType_HardDisk << UIMediumType_DVD << UIMediumType_Floppy;1730 QTreeWidget *pTreeWidget = 0;1731 UIMediumItem *pMediumItem = 0;1732 foreach (UIMediumType type, types)1733 {1734 /* Get iterated tree-widget: */1735 pTreeWidget = treeWidget(type);1736 /* Search for existing medium-item: */1737 pMediumItem = searchItem(pTreeWidget, CheckIfSuitableByID(strMediumID));1738 if (pMediumItem)1739 break;1740 }1741 1742 /* Ignore medium-item (if it was not found): */1743 if (!pMediumItem)1744 return;1745 1746 /* Update tab-icons: */1747 updateTabIcons(pMediumItem, Action_Remove);1748 1749 /* Delete medium-item: */1750 delete pMediumItem;1751 LogRel2(("UIMediumManager: Medium-item with ID={%s} deleted.\n", strMediumID.toAscii().constData()));1752 1753 /* If there is no current medium-item now selected1754 * we have to choose first-available medium-item as current one: */1755 if (!pTreeWidget->currentItem())1756 setCurrentItem(pTreeWidget, pTreeWidget->topLevelItem(0));1757 }1758 1759 UIMediumType UIMediumManager::mediumType(QTreeWidget *pTreeWidget) const1760 {1761 /* Hard-drive tree-widget: */1762 if (pTreeWidget == mTwHD) return UIMediumType_HardDisk;1763 /* Optical-image tree-widget: */1764 if (pTreeWidget == mTwCD) return UIMediumType_DVD;1765 /* Floppy-image tree-widget: */1766 if (pTreeWidget == mTwFD) return UIMediumType_Floppy;1767 /* Invalid by default: */1768 AssertFailedReturn(UIMediumType_Invalid);1769 }1770 1771 UIMediumType UIMediumManager::currentMediumType() const1772 {1773 /* Return current medium type: */1774 switch (mTabWidget->currentIndex())1775 {1776 case TabIndex_HD: return UIMediumType_HardDisk;1777 case TabIndex_CD: return UIMediumType_DVD;1778 case TabIndex_FD: return UIMediumType_Floppy;1779 default: AssertMsgFailed(("Unknown page type: %d\n", mTabWidget->currentIndex())); break;1780 }1781 /* Invalid by default: */1782 return UIMediumType_Invalid;1783 }1784 1785 QTreeWidget* UIMediumManager::treeWidget(UIMediumType type) const1786 {1787 /* Return corresponding tree-widget for known medium types: */1788 switch (type)1789 {1790 case UIMediumType_HardDisk: return mTwHD;1791 case UIMediumType_DVD: return mTwCD;1792 case UIMediumType_Floppy: return mTwFD;1793 default: AssertMsgFailed(("Unknown medium type: %d\n", type)); break;1794 }1795 /* Null by default: */1796 return 0;1797 }1798 1799 QTreeWidget* UIMediumManager::currentTreeWidget() const1800 {1801 /* Return current tree-widget: */1802 return treeWidget(currentMediumType());1803 }1804 1805 UIMediumItem* UIMediumManager::mediumItem(UIMediumType type) const1806 {1807 /* Get corresponding tree-widget: */1808 QTreeWidget *pTreeWidget = treeWidget(type);1809 /* Return corresponding medium-item: */1810 return pTreeWidget ? toMediumItem(pTreeWidget->currentItem()) : 0;1811 }1812 1813 UIMediumItem* UIMediumManager::currentMediumItem() const1814 {1815 /* Return current medium-item: */1816 return mediumItem(currentMediumType());1817 }1818 1819 void UIMediumManager::setCurrentItem(QTreeWidget *pTreeWidget, QTreeWidgetItem *pItem)1820 {1821 /* Make sure passed tree-widget is valid: */1822 AssertPtrReturnVoid(pTreeWidget);1823 1824 /* Make passed item current for passed tree-widget: */1825 pTreeWidget->setCurrentItem(pItem);1826 1827 /* If non NULL item was passed: */1828 if (pItem)1829 {1830 /* Make sure it's also selected, and visible: */1831 pItem->setSelected(true);1832 pTreeWidget->scrollToItem(pItem, QAbstractItemView::EnsureVisible);1833 }1834 1835 /* Re-fetch currently chosen medium-item: */1836 refetchCurrentChosenMediumItem();1837 }1838 1839 /* static */1840 UIMediumItem* UIMediumManager::searchItem(QTreeWidget *pTreeWidget, const CheckIfSuitableBy &condition, CheckIfSuitableBy *pException)1841 {1842 /* Make sure argument is valid: */1843 if (!pTreeWidget)1844 return 0;1845 1846 /* Return wrapper: */1847 return searchItem(pTreeWidget->invisibleRootItem(), condition, pException);1848 }1849 1850 /* static */1851 UIMediumItem* UIMediumManager::searchItem(QTreeWidgetItem *pParentItem, const CheckIfSuitableBy &condition, CheckIfSuitableBy *pException)1852 {1853 /* Make sure argument is valid: */1854 if (!pParentItem)1855 return 0;1856 1857 /* Verify passed item if it is of 'medium' type too: */1858 if (UIMediumItem *pMediumParentItem = toMediumItem(pParentItem))1859 if ( condition.isItSuitable(pMediumParentItem)1860 && (!pException || !pException->isItSuitable(pMediumParentItem)))1861 return pMediumParentItem;1862 1863 /* Iterate other all the children: */1864 for (int iChildIndex = 0; iChildIndex < pParentItem->childCount(); ++iChildIndex)1865 if (UIMediumItem *pMediumChildItem = toMediumItem(pParentItem->child(iChildIndex)))1866 if (UIMediumItem *pRequiredMediumChildItem = searchItem(pMediumChildItem, condition, pException))1867 return pRequiredMediumChildItem;1868 1869 /* Null by default: */1870 return 0;1871 }1872 1873 1703 UIMediumItem* UIMediumManager::createHardDiskItem(const UIMedium &medium) 1874 1704 { … … 1917 1747 } 1918 1748 1749 void UIMediumManager::updateMediumItem(const UIMedium &medium) 1750 { 1751 /* Get medium type: */ 1752 UIMediumType type = medium.type(); 1753 1754 /* Search for existing medium-item, create if was not found: */ 1755 UIMediumItem *pMediumItem = searchItem(treeWidget(type), CheckIfSuitableByID(medium.id())); 1756 if (!pMediumItem) pMediumItem = createMediumItem(medium); 1757 AssertPtrReturnVoid(pMediumItem); 1758 1759 /* Update medium-item: */ 1760 pMediumItem->setMedium(medium); 1761 LogRel2(("UIMediumManager: Medium-item with ID={%s} updated.\n", medium.id().toAscii().constData())); 1762 1763 /* Update tab-icons: */ 1764 updateTabIcons(pMediumItem, Action_Edit); 1765 1766 /* Re-fetch medium-item if it is current one updated: */ 1767 if (pMediumItem == mediumItem(type)) 1768 refetchCurrentMediumItem(type); 1769 } 1770 1771 void UIMediumManager::deleteMediumItem(const QString &strMediumID) 1772 { 1773 /* Search for corresponding tree-widget: */ 1774 QList<UIMediumType> types; 1775 types << UIMediumType_HardDisk << UIMediumType_DVD << UIMediumType_Floppy; 1776 QTreeWidget *pTreeWidget = 0; 1777 UIMediumItem *pMediumItem = 0; 1778 foreach (UIMediumType type, types) 1779 { 1780 /* Get iterated tree-widget: */ 1781 pTreeWidget = treeWidget(type); 1782 /* Search for existing medium-item: */ 1783 pMediumItem = searchItem(pTreeWidget, CheckIfSuitableByID(strMediumID)); 1784 if (pMediumItem) 1785 break; 1786 } 1787 1788 /* Ignore medium-item (if it was not found): */ 1789 if (!pMediumItem) 1790 return; 1791 1792 /* Update tab-icons: */ 1793 updateTabIcons(pMediumItem, Action_Remove); 1794 1795 /* Delete medium-item: */ 1796 delete pMediumItem; 1797 LogRel2(("UIMediumManager: Medium-item with ID={%s} deleted.\n", strMediumID.toAscii().constData())); 1798 1799 /* If there is no current medium-item now selected 1800 * we have to choose first-available medium-item as current one: */ 1801 if (!pTreeWidget->currentItem()) 1802 setCurrentItem(pTreeWidget, pTreeWidget->topLevelItem(0)); 1803 } 1804 1805 UIMediumType UIMediumManager::mediumType(QTreeWidget *pTreeWidget) const 1806 { 1807 /* Hard-drive tree-widget: */ 1808 if (pTreeWidget == mTwHD) return UIMediumType_HardDisk; 1809 /* Optical-image tree-widget: */ 1810 if (pTreeWidget == mTwCD) return UIMediumType_DVD; 1811 /* Floppy-image tree-widget: */ 1812 if (pTreeWidget == mTwFD) return UIMediumType_Floppy; 1813 /* Invalid by default: */ 1814 AssertFailedReturn(UIMediumType_Invalid); 1815 } 1816 1817 UIMediumType UIMediumManager::currentMediumType() const 1818 { 1819 /* Return current medium type: */ 1820 switch (mTabWidget->currentIndex()) 1821 { 1822 case TabIndex_HD: return UIMediumType_HardDisk; 1823 case TabIndex_CD: return UIMediumType_DVD; 1824 case TabIndex_FD: return UIMediumType_Floppy; 1825 default: AssertMsgFailed(("Unknown page type: %d\n", mTabWidget->currentIndex())); break; 1826 } 1827 /* Invalid by default: */ 1828 return UIMediumType_Invalid; 1829 } 1830 1831 QTreeWidget* UIMediumManager::treeWidget(UIMediumType type) const 1832 { 1833 /* Return corresponding tree-widget for known medium types: */ 1834 switch (type) 1835 { 1836 case UIMediumType_HardDisk: return mTwHD; 1837 case UIMediumType_DVD: return mTwCD; 1838 case UIMediumType_Floppy: return mTwFD; 1839 default: AssertMsgFailed(("Unknown medium type: %d\n", type)); break; 1840 } 1841 /* Null by default: */ 1842 return 0; 1843 } 1844 1845 QTreeWidget* UIMediumManager::currentTreeWidget() const 1846 { 1847 /* Return current tree-widget: */ 1848 return treeWidget(currentMediumType()); 1849 } 1850 1851 UIMediumItem* UIMediumManager::mediumItem(UIMediumType type) const 1852 { 1853 /* Get corresponding tree-widget: */ 1854 QTreeWidget *pTreeWidget = treeWidget(type); 1855 /* Return corresponding medium-item: */ 1856 return pTreeWidget ? toMediumItem(pTreeWidget->currentItem()) : 0; 1857 } 1858 1859 UIMediumItem* UIMediumManager::currentMediumItem() const 1860 { 1861 /* Return current medium-item: */ 1862 return mediumItem(currentMediumType()); 1863 } 1864 1865 void UIMediumManager::setCurrentItem(QTreeWidget *pTreeWidget, QTreeWidgetItem *pItem) 1866 { 1867 /* Make sure passed tree-widget is valid: */ 1868 AssertPtrReturnVoid(pTreeWidget); 1869 1870 /* Make passed item current for passed tree-widget: */ 1871 pTreeWidget->setCurrentItem(pItem); 1872 1873 /* If non NULL item was passed: */ 1874 if (pItem) 1875 { 1876 /* Make sure it's also selected, and visible: */ 1877 pItem->setSelected(true); 1878 pTreeWidget->scrollToItem(pItem, QAbstractItemView::EnsureVisible); 1879 } 1880 1881 /* Re-fetch currently chosen medium-item: */ 1882 refetchCurrentChosenMediumItem(); 1883 } 1884 1885 /* static */ 1886 UIMediumItem* UIMediumManager::searchItem(QTreeWidget *pTreeWidget, const CheckIfSuitableBy &condition, CheckIfSuitableBy *pException) 1887 { 1888 /* Make sure argument is valid: */ 1889 if (!pTreeWidget) 1890 return 0; 1891 1892 /* Return wrapper: */ 1893 return searchItem(pTreeWidget->invisibleRootItem(), condition, pException); 1894 } 1895 1896 /* static */ 1897 UIMediumItem* UIMediumManager::searchItem(QTreeWidgetItem *pParentItem, const CheckIfSuitableBy &condition, CheckIfSuitableBy *pException) 1898 { 1899 /* Make sure argument is valid: */ 1900 if (!pParentItem) 1901 return 0; 1902 1903 /* Verify passed item if it is of 'medium' type too: */ 1904 if (UIMediumItem *pMediumParentItem = toMediumItem(pParentItem)) 1905 if ( condition.isItSuitable(pMediumParentItem) 1906 && (!pException || !pException->isItSuitable(pMediumParentItem))) 1907 return pMediumParentItem; 1908 1909 /* Iterate other all the children: */ 1910 for (int iChildIndex = 0; iChildIndex < pParentItem->childCount(); ++iChildIndex) 1911 if (UIMediumItem *pMediumChildItem = toMediumItem(pParentItem->child(iChildIndex))) 1912 if (UIMediumItem *pRequiredMediumChildItem = searchItem(pMediumChildItem, condition, pException)) 1913 return pRequiredMediumChildItem; 1914 1915 /* Null by default: */ 1916 return 0; 1917 } 1918 1919 1919 /* static */ 1920 1920 bool UIMediumManager::checkMediumFor(UIMediumItem *pItem, Action action) -
trunk/src/VBox/Frontends/VirtualBox/src/medium/UIMediumManager.h
r50767 r50768 63 63 private slots: 64 64 65 /** Handles UIMediumManager::m_pActionRefresh action triggering. */66 void sltRefreshAll();67 68 65 /** Handles VBoxGlobal::sigMediumCreated signal. */ 69 66 void sltHandleMediumCreated(const QString &strMediumID); … … 86 83 /** Handles UIMediumManager::m_pActionRelease action triggering. */ 87 84 void sltReleaseMedium(); 85 /** Handles UIMediumManager::m_pActionRefresh action triggering. */ 86 void sltRefreshAll(); 88 87 89 88 /** Handles tab change case. */ … … 169 168 /** Creates UIMediumItem for corresponding @a medium. */ 170 169 UIMediumItem* createMediumItem(const UIMedium &medium); 170 /** Creates UIMediumItemHD for corresponding @a medium. */ 171 UIMediumItem* createHardDiskItem(const UIMedium &medium); 171 172 /** Updates UIMediumItem for corresponding @a medium. */ 172 173 void updateMediumItem(const UIMedium &medium); … … 197 198 /** Performs search for the @a pParentItem child which corresponds to the @a condition but not @a pException. */ 198 199 static UIMediumItem* searchItem(QTreeWidgetItem *pParentItem, const CheckIfSuitableBy &condition, CheckIfSuitableBy *pException = 0); 199 /** Creates UIMediumItemHD for corresponding @a medium. */200 UIMediumItem* createHardDiskItem(const UIMedium &medium);201 200 202 201 /** Checks if @a action can be used for @a pItem. */
Note:
See TracChangeset
for help on using the changeset viewer.