Changeset 67740 in vbox for trunk/src/VBox/Frontends/VirtualBox
- Timestamp:
- Jun 30, 2017 3:39:48 PM (8 years ago)
- svn:sync-xref-src-repo-rev:
- 116609
- Location:
- trunk/src/VBox/Frontends/VirtualBox/src/medium
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Frontends/VirtualBox/src/medium/UIMediumManager.cpp
r67737 r67740 56 56 57 57 58 /** Virtual Media Manager: Medium details data structure. */ 59 struct UIDataMediumDetails 60 { 61 /** Constructs data. */ 62 UIDataMediumDetails() 63 : m_aDetails(QStringList()) 64 {} 65 66 /** Returns whether the @a other passed data is equal to this one. */ 67 bool equal(const UIDataMediumDetails &other) const 68 { 69 return true 70 && (m_aDetails == other.m_aDetails) 71 ; 72 } 73 74 /** Returns whether the @a other passed data is equal to this one. */ 75 bool operator==(const UIDataMediumDetails &other) const { return equal(other); } 76 /** Returns whether the @a other passed data is different from this one. */ 77 bool operator!=(const UIDataMediumDetails &other) const { return !equal(other); } 78 79 /** Holds the details list. */ 80 QStringList m_aDetails; 81 }; 82 83 84 /** Virtual Media Manager: Medium data structure. */ 85 struct UIDataMedium 86 { 87 /** Constructs data. */ 88 UIDataMedium() 89 : m_enmType(UIMediumType_Invalid) 90 , m_details(UIDataMediumDetails()) 91 {} 92 93 /** Returns whether the @a other passed data is equal to this one. */ 94 bool equal(const UIDataMedium &other) const 95 { 96 return true 97 && (m_enmType == other.m_enmType) 98 && (m_details == other.m_details) 99 ; 100 } 101 102 /** Returns whether the @a other passed data is equal to this one. */ 103 bool operator==(const UIDataMedium &other) const { return equal(other); } 104 /** Returns whether the @a other passed data is different from this one. */ 105 bool operator!=(const UIDataMedium &other) const { return !equal(other); } 106 107 /** Holds the medium type. */ 108 UIMediumType m_enmType; 109 110 /** Holds the details data. */ 111 UIDataMediumDetails m_details; 112 }; 113 114 58 115 /** QITreeWidgetItem extension representing Medium Manager item. */ 59 class UIMediumItem : public QITreeWidgetItem 116 class UIMediumItem : public QITreeWidgetItem, public UIDataMedium 60 117 { 61 118 public: … … 136 193 /** Releases UIMedium wrapped by <i>this</i> item from virtual machine with @a strMachineId. */ 137 194 bool releaseFrom(const QString &strMachineId); 195 196 /** Formats field text. */ 197 static QString formatFieldText(const QString &strText, bool fCompact = true, const QString &strElipsis = "middle"); 138 198 139 199 /** Holds the UIMedium wrapped by <i>this</i> item. */ … … 384 444 for (int i = 0; i < treeWidget()->columnCount(); ++i) 385 445 setToolTip(i, strToolTip); 446 447 /* Gather medium data: */ 448 m_enmType = m_guiMedium.type(); 449 /* Gather medium details data: */ 450 m_details.m_aDetails.clear(); 451 switch (m_enmType) 452 { 453 case UIMediumType_HardDisk: 454 { 455 m_details.m_aDetails << hardDiskType(); 456 m_details.m_aDetails << formatFieldText(location(), true, "end"); 457 m_details.m_aDetails << hardDiskFormat(); 458 m_details.m_aDetails << details(); 459 m_details.m_aDetails << (usage().isNull() ? 460 formatFieldText(UIMediumManager::tr("<i>Not Attached</i>"), false) : 461 formatFieldText(usage())); 462 m_details.m_aDetails << (encryptionPasswordID().isNull() ? 463 formatFieldText(UIMediumManager::tr("<i>Not Encrypted</i>"), false) : 464 formatFieldText(encryptionPasswordID())); 465 m_details.m_aDetails << id(); 466 break; 467 } 468 case UIMediumType_DVD: 469 case UIMediumType_Floppy: 470 { 471 m_details.m_aDetails << formatFieldText(location(), true, "end"); 472 m_details.m_aDetails << (usage().isNull() ? 473 formatFieldText(UIMediumManager::tr("<i>Not Attached</i>"), false) : 474 formatFieldText(usage())); 475 m_details.m_aDetails << id(); 476 break; 477 } 478 default: 479 break; 480 } 386 481 } 387 482 … … 415 510 /* Return result: */ 416 511 return fSuccess; 512 } 513 514 /* static */ 515 QString UIMediumItem::formatFieldText(const QString &strText, bool fCompact /* = true */, 516 const QString &strElipsis /* = "middle" */) 517 { 518 QString strCompactString = QString("<compact elipsis=\"%1\">").arg(strElipsis); 519 QString strInfo = QString("<nobr>%1%2%3</nobr>") 520 .arg(fCompact ? strCompactString : "") 521 .arg(strText.isEmpty() ? UIMediumManager::tr("--", "no info") : strText) 522 .arg(fCompact ? "</compact>" : ""); 523 return strInfo; 417 524 } 418 525 … … 1064 1171 /* Update HD information-panes: */ 1065 1172 if (fResult) 1066 updateInformationFields HD();1173 updateInformationFields(UIMediumType_HardDisk); 1067 1174 } 1068 1175 … … 1468 1575 } 1469 1576 1470 void UIMediumManagerWidget::prepareInformationContainer(UIMediumType type, int iFields)1577 void UIMediumManagerWidget::prepareInformationContainer(UIMediumType enmType, int cFields) 1471 1578 { 1472 1579 /* Create information-container: */ 1473 int iIndex = tabIndex(type); 1474 m_containers.insert(iIndex, new QFrame); 1475 QFrame *pInformationContainer = infoContainer(type); 1580 m_containers[enmType] = new QFrame; 1581 QFrame *pInformationContainer = infoContainer(enmType); 1476 1582 AssertPtrReturnVoid(pInformationContainer); 1477 1583 { … … 1489 1595 pInformationContainerLayout->setColumnStretch(1, 1); 1490 1596 /* Create information-container labels & fields: */ 1491 for (int i = 0; i < iFields; ++i)1597 for (int i = 0; i < cFields; ++i) 1492 1598 { 1493 1599 /* Create information-label: */ 1494 m_labels[ iIndex] << new QLabel;1495 QLabel *pLabel = infoLabel( type, i);1600 m_labels[enmType] << new QLabel; 1601 QLabel *pLabel = infoLabel(enmType, i); 1496 1602 AssertPtrReturnVoid(pLabel); 1497 1603 /* Create information-field: */ 1498 m_fields[ iIndex] << new QILabel;1499 QILabel *pField = infoField( type, i);1604 m_fields[enmType] << new QILabel; 1605 QILabel *pField = infoField(enmType, i); 1500 1606 AssertPtrReturnVoid(pField); 1501 1607 { … … 1510 1616 } 1511 1617 /* Add information-container into tab layout: */ 1512 tab( type)->layout()->addWidget(pInformationContainer);1618 tab(enmType)->layout()->addWidget(pInformationContainer); 1513 1619 } 1514 1620 } … … 1768 1874 } 1769 1875 1770 void UIMediumManagerWidget::updateInformationFields(UIMediumType type /* = UIMediumType_Invalid */) 1771 { 1772 /* Make sure type is valid: */ 1773 if (type == UIMediumType_Invalid) 1774 type = currentMediumType(); 1775 1776 /* Depending on required type: */ 1777 switch (type) 1778 { 1779 case UIMediumType_HardDisk: updateInformationFieldsHD(); break; 1780 case UIMediumType_DVD: updateInformationFieldsCD(); break; 1781 case UIMediumType_Floppy: updateInformationFieldsFD(); break; 1782 case UIMediumType_All: 1783 updateInformationFieldsHD(); 1784 updateInformationFieldsCD(); 1785 updateInformationFieldsFD(); 1786 break; 1787 default: break; 1788 } 1789 } 1790 1791 void UIMediumManagerWidget::updateInformationFieldsHD() 1792 { 1793 /* Get current hard-drive medium-item: */ 1794 UIMediumItem *pCurrentItem = mediumItem(UIMediumType_HardDisk); 1795 1796 /* If current item is not set: */ 1797 if (!pCurrentItem) 1798 { 1799 /* Just clear information panes: */ 1800 for (int i = 0; i < m_fields[tabIndex(UIMediumType_HardDisk)].size(); ++i) 1801 infoField(UIMediumType_HardDisk, i)->clear(); 1802 } 1803 /* If current item is set: */ 1804 else 1805 { 1806 /* Acquire required details: */ 1807 const QString strDetails = pCurrentItem->details(); 1808 const QString strUsage = pCurrentItem->usage().isNull() ? 1809 formatFieldText(UIMediumManager::tr("<i>Not Attached</i>"), false) : 1810 formatFieldText(pCurrentItem->usage()); 1811 const QString strEncryptionPasswordID = pCurrentItem->encryptionPasswordID().isNull() ? 1812 formatFieldText(UIMediumManager::tr("<i>Not Encrypted</i>"), false) : 1813 formatFieldText(pCurrentItem->encryptionPasswordID()); 1814 const QString strID = pCurrentItem->id(); 1815 if (infoField(UIMediumType_HardDisk, 0)) 1816 infoField(UIMediumType_HardDisk, 0)->setText(pCurrentItem->hardDiskType()); 1817 if (infoField(UIMediumType_HardDisk, 1)) 1818 infoField(UIMediumType_HardDisk, 1)->setText(formatFieldText(pCurrentItem->location(), true, "end")); 1819 if (infoField(UIMediumType_HardDisk, 2)) 1820 infoField(UIMediumType_HardDisk, 2)->setText(pCurrentItem->hardDiskFormat()); 1821 if (infoField(UIMediumType_HardDisk, 3)) 1822 infoField(UIMediumType_HardDisk, 3)->setText(strDetails); 1823 if (infoField(UIMediumType_HardDisk, 4)) 1824 infoField(UIMediumType_HardDisk, 4)->setText(strUsage); 1825 if (infoField(UIMediumType_HardDisk, 5)) 1826 infoField(UIMediumType_HardDisk, 5)->setText(strEncryptionPasswordID); 1827 if (infoField(UIMediumType_HardDisk, 6)) 1828 infoField(UIMediumType_HardDisk, 6)->setText(strID); 1829 } 1830 1831 /* Enable/disable information-panes container: */ 1832 if (infoContainer(UIMediumType_HardDisk)) 1833 infoContainer(UIMediumType_HardDisk)->setEnabled(pCurrentItem); 1834 } 1835 1836 void UIMediumManagerWidget::updateInformationFieldsCD() 1837 { 1838 /* Get current optical medium-item: */ 1839 UIMediumItem *pCurrentItem = mediumItem(UIMediumType_DVD); 1840 1841 /* If current item is not set: */ 1842 if (!pCurrentItem) 1843 { 1844 /* Just clear information panes: */ 1845 for (int i = 0; i < m_fields[tabIndex(UIMediumType_DVD)].size(); ++i) 1846 infoField(UIMediumType_DVD, i)->clear(); 1847 } 1848 /* If current item is set: */ 1849 else 1850 { 1851 /* Update required details: */ 1852 QString strUsage = pCurrentItem->usage().isNull() ? 1853 formatFieldText(UIMediumManager::tr("<i>Not Attached</i>"), false) : 1854 formatFieldText(pCurrentItem->usage()); 1855 const QString strID = pCurrentItem->id(); 1856 if (infoField(UIMediumType_DVD, 0)) 1857 infoField(UIMediumType_DVD, 0)->setText(formatFieldText(pCurrentItem->location(), true, "end")); 1858 if (infoField(UIMediumType_DVD, 1)) 1859 infoField(UIMediumType_DVD, 1)->setText(strUsage); 1860 if (infoField(UIMediumType_DVD, 2)) 1861 infoField(UIMediumType_DVD, 2)->setText(strID); 1862 } 1863 1864 /* Enable/disable information-panes container: */ 1865 if (infoContainer(UIMediumType_DVD)) 1866 infoContainer(UIMediumType_DVD)->setEnabled(pCurrentItem); 1867 } 1868 1869 void UIMediumManagerWidget::updateInformationFieldsFD() 1870 { 1871 /* Get current floppy medium-item: */ 1872 UIMediumItem *pCurrentItem = mediumItem(UIMediumType_Floppy); 1873 1874 /* If current item is not set: */ 1875 if (!pCurrentItem) 1876 { 1877 /* Just clear information panes: */ 1878 for (int i = 0; i < m_fields[tabIndex(UIMediumType_Floppy)].size(); ++i) 1879 infoField(UIMediumType_Floppy, i)->clear(); 1880 } 1881 /* If current item is set: */ 1882 else 1883 { 1884 /* Update required details: */ 1885 QString strUsage = pCurrentItem->usage().isNull() ? 1886 formatFieldText(UIMediumManager::tr("<i>Not Attached</i>"), false) : 1887 formatFieldText(pCurrentItem->usage()); 1888 const QString strID = pCurrentItem->id(); 1889 if (infoField(UIMediumType_Floppy, 0)) 1890 infoField(UIMediumType_Floppy, 0)->setText(formatFieldText(pCurrentItem->location(), true, "end")); 1891 if (infoField(UIMediumType_Floppy, 1)) 1892 infoField(UIMediumType_Floppy, 1)->setText(strUsage); 1893 if (infoField(UIMediumType_Floppy, 2)) 1894 infoField(UIMediumType_Floppy, 2)->setText(strID); 1895 } 1896 1897 /* Enable/disable information-panes container: */ 1898 if (infoContainer(UIMediumType_Floppy)) 1899 infoContainer(UIMediumType_Floppy)->setEnabled(pCurrentItem); 1876 void UIMediumManagerWidget::updateInformationFields(UIMediumType enmType /* = UIMediumType_Invalid */) 1877 { 1878 /* Make sure passed medium type is valid: */ 1879 if (enmType == UIMediumType_Invalid) 1880 enmType = currentMediumType(); 1881 1882 /* Which medium types should we update? */ 1883 const QList<UIMediumType> aTypes = enmType == UIMediumType_All 1884 ? m_fields.keys() 1885 : QList<UIMediumType>() << enmType; 1886 1887 /* For each requested type: */ 1888 foreach (UIMediumType enmType, aTypes) 1889 { 1890 /* Get current medium-item: */ 1891 UIMediumItem *pCurrentItem = currentMediumItem(); 1892 1893 /* Get information-fields just to acquire their number: */ 1894 const QList<QILabel*> aFields = m_fields.value(enmType, QList<QILabel*>()); 1895 /* For each field => clear the contents: */ 1896 for (int i = 0; i < aFields.size(); ++i) 1897 if (pCurrentItem) 1898 infoField(enmType, i)->setText(pCurrentItem->m_details.m_aDetails.value(i, QString())); 1899 else 1900 infoField(enmType, i)->clear(); 1901 } 1900 1902 } 1901 1903 … … 2139 2141 } 2140 2142 2141 QFrame* UIMediumManagerWidget::infoContainer(UIMediumType type) const 2142 { 2143 /* Determine tab index for passed medium type: */ 2144 int iIndex = tabIndex(type); 2145 2146 /* Return information-container for known tab index: */ 2147 if (iIndex >= 0 && iIndex < m_iTabCount) 2148 return m_containers.value(iIndex, 0); 2149 2150 /* Null by default: */ 2151 return 0; 2152 } 2153 2154 QLabel* UIMediumManagerWidget::infoLabel(UIMediumType type, int iLabelIndex) const 2155 { 2156 /* Determine tab index for passed medium type: */ 2157 int iIndex = tabIndex(type); 2158 2159 /* Look for corresponding information-label list for known tab index: */ 2160 if (iIndex >= 0 && iIndex < m_iTabCount) 2161 { 2162 const QList<QLabel*> labels = m_labels.value(iIndex, QList<QLabel*>()); 2163 2164 /* Return information-label for known index: */ 2165 return labels.value(iLabelIndex, 0); 2166 } 2167 2168 /* Null by default: */ 2169 return 0; 2170 } 2171 2172 QILabel* UIMediumManagerWidget::infoField(UIMediumType type, int iFieldIndex) const 2173 { 2174 /* Determine tab index for passed medium type: */ 2175 int iIndex = tabIndex(type); 2176 2177 /* Look for corresponding information-field list for known tab index: */ 2178 if (iIndex >= 0 && iIndex < m_iTabCount) 2179 { 2180 const QList<QILabel*> fields = m_fields.value(iIndex, QList<QILabel*>()); 2181 2182 /* Return information-field for known index: */ 2183 return fields.value(iFieldIndex, 0); 2184 } 2185 2186 /* Null by default: */ 2187 return 0; 2143 QFrame *UIMediumManagerWidget::infoContainer(UIMediumType enmType) const 2144 { 2145 /* Return information-container for known medium type: */ 2146 return m_containers.value(enmType, 0); 2147 } 2148 2149 QLabel *UIMediumManagerWidget::infoLabel(UIMediumType enmType, int iIndex) const 2150 { 2151 /* Look for corresponding information-label list for known medium type: */ 2152 const QList<QLabel*> labels = m_labels.value(enmType, QList<QLabel*>()); 2153 2154 /* Return information-label for known index: */ 2155 return labels.value(iIndex, 0); 2156 } 2157 2158 QILabel *UIMediumManagerWidget::infoField(UIMediumType enmType, int iIndex) const 2159 { 2160 /* Look for corresponding information-field list for known medium type: */ 2161 const QList<QILabel*> fields = m_fields.value(enmType, QList<QILabel*>()); 2162 2163 /* Return information-field for known index: */ 2164 return fields.value(iIndex, 0); 2188 2165 } 2189 2166 … … 2351 2328 } 2352 2329 2353 /* static */2354 QString UIMediumManagerWidget::formatFieldText(const QString &strText, bool fCompact /* = true */,2355 const QString &strElipsis /* = "middle" */)2356 {2357 QString compactString = QString("<compact elipsis=\"%1\">").arg(strElipsis);2358 QString strInfo = QString("<nobr>%1%2%3</nobr>")2359 .arg(fCompact ? compactString : "")2360 .arg(strText.isEmpty() ?2361 UIMediumManager::tr("--", "no info") :2362 strText)2363 .arg(fCompact ? "</compact>" : "");2364 return strInfo;2365 }2366 2367 2330 2368 2331 /********************************************************************************************************************************* -
trunk/src/VBox/Frontends/VirtualBox/src/medium/UIMediumManager.h
r67737 r67740 162 162 void prepareTreeWidget(UIMediumType type, int iColumns); 163 163 /** Prepares tab-widget's information-container. */ 164 void prepareInformationContainer(UIMediumType type, int iFields);164 void prepareInformationContainer(UIMediumType enmType, int cFields); 165 165 // /** Prepares progress-bar. */ 166 166 // void prepareProgressBar(); … … 182 182 /** Updates tab icons according last @a action happened with @a pItem. */ 183 183 void updateTabIcons(UIMediumItem *pItem, Action action); 184 /** Updates information fields of passed medium @a type. */ 185 void updateInformationFields(UIMediumType type = UIMediumType_Invalid); 186 /** Updates information fields for hard-drive tab. */ 187 void updateInformationFieldsHD(); 188 /** Updates information fields for optical-disk tab. */ 189 void updateInformationFieldsCD(); 190 /** Updates information fields for floppy-disk tab. */ 191 void updateInformationFieldsFD(); 184 /** Updates information fields of passed medium @a enmType. */ 185 void updateInformationFields(UIMediumType enmType = UIMediumType_Invalid); 192 186 /** @} */ 193 187 … … 209 203 /** Returns item for passed medium @a type. */ 210 204 UIMediumItem *mediumItem(UIMediumType type) const; 211 /** Returns information-container for passed medium @a type. */212 QFrame *infoContainer(UIMediumType type) const;213 /** Returns information-label for passed medium @a type and @a iLabelIndex. */214 QLabel *infoLabel(UIMediumType type, int iLabelIndex) const;215 /** Returns information-field for passed medium @a type and @a iFieldIndex. */216 QILabel *infoField(UIMediumType type, int iFieldIndex) const;205 /** Returns information-container for passed medium @a enmType. */ 206 QFrame *infoContainer(UIMediumType enmType) const; 207 /** Returns information-label for passed medium @a enmType and @a iIndex. */ 208 QLabel *infoLabel(UIMediumType enmType, int iIndex) const; 209 /** Returns information-field for passed medium @a enmType and @a iIndex. */ 210 QILabel *infoField(UIMediumType enmType, int iIndex) const; 217 211 218 212 /** Returns medium type for passed @a pTreeWidget. */ … … 249 243 /** Casts passed QTreeWidgetItem @a pItem to UIMediumItem if possible. */ 250 244 static UIMediumItem *toMediumItem(QTreeWidgetItem *pItem); 251 252 /** Formats information-field content. */253 static QString formatFieldText(const QString &strText, bool fCompact = true, const QString &strElipsis = "middle");254 245 /** @} */ 255 246 … … 272 263 QMap<int, QITreeWidget*> m_trees; 273 264 /** Holds the map of information-container instances. */ 274 QMap< int, QFrame*> m_containers;265 QMap<UIMediumType, QFrame*> m_containers; 275 266 /** Holds the map of information-container label instances. */ 276 QMap< int, QList<QLabel*> > m_labels;267 QMap<UIMediumType, QList<QLabel*> > m_labels; 277 268 /** Holds the information-container field instances. */ 278 QMap< int, QList<QILabel*> > m_fields;269 QMap<UIMediumType, QList<QILabel*> > m_fields; 279 270 /** Holds whether hard-drive tab-widget have inaccessible item. */ 280 271 bool m_fInaccessibleHD;
Note:
See TracChangeset
for help on using the changeset viewer.