Changeset 48061 in vbox
- Timestamp:
- Aug 26, 2013 1:26:46 PM (11 years ago)
- Location:
- trunk/src/VBox/Frontends/VirtualBox/src
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Frontends/VirtualBox/src/globals/VBoxGlobal.cpp
r47998 r48061 1740 1740 return; 1741 1741 1742 /* composes a list of all currently known media & their children*/1742 /* Compose a list of all currently known mediums & their children: */ 1743 1743 m_mediums.clear(); 1744 addNullMediumToList 1745 addHardDisksToList 1746 addMediumsToList 1747 addMediumsToList 1748 addMediumsToList 1749 addMediumsToList 1750 1751 /* enumeration thread class*/1744 addNullMediumToList(m_mediums, m_mediums.end()); 1745 addHardDisksToList(mVBox.GetHardDisks(), m_mediums, m_mediums.end()); 1746 addMediumsToList(mHost.GetDVDDrives(), m_mediums, m_mediums.end(), UIMediumType_DVD); 1747 addMediumsToList(mVBox.GetDVDImages(), m_mediums, m_mediums.end(), UIMediumType_DVD); 1748 addMediumsToList(mHost.GetFloppyDrives(), m_mediums, m_mediums.end(), UIMediumType_Floppy); 1749 addMediumsToList(mVBox.GetFloppyImages(), m_mediums, m_mediums.end(), UIMediumType_Floppy); 1750 1751 /* Enumeration thread class: */ 1752 1752 class MediaEnumThread : public QThread 1753 1753 { 1754 1754 public: 1755 1755 1756 MediaEnumThread (VBoxMediaList &aList)1757 : m Vector (aList.size())1758 , m SavedIt (aList.begin())1756 MediaEnumThread(VBoxMediaList &mediums) 1757 : m_mediums(mediums.size()) 1758 , m_iterator(mediums.begin()) 1759 1759 { 1760 1760 int i = 0; 1761 for (VBoxMediaList::const_iterator it = aList.begin(); 1762 it != aList.end(); ++ it) 1763 mVector [i ++] = *it; 1764 } 1765 1766 virtual void run() 1767 { 1768 LogFlow (("MediaEnumThread started.\n")); 1761 for (VBoxMediaList::const_iterator it = mediums.begin(); it != mediums.end(); ++it) 1762 m_mediums[i++] = *it; 1763 } 1764 1765 void run() 1766 { 1767 LogFlow(("MediaEnumThread started.\n")); 1769 1768 COMBase::InitializeCOM(false); 1770 1769 1771 CVirtualBox mVBox = vboxGlobal().virtualBox(); 1772 QObject *self = &vboxGlobal(); 1773 1774 /* Enumerate the list */ 1775 for (int i = 0; i < mVector.size() && !m_sfCleanupInProgress; ++ i) 1770 QObject *pSelf = &vboxGlobal(); 1771 1772 /* Enumerate medium list: */ 1773 for (int i = 0; i < m_mediums.size() && !m_sfCleanupInProgress; ++i) 1776 1774 { 1777 mVector [i].blockAndQueryState(); 1778 QApplication:: 1779 postEvent (self, 1780 new VBoxMediaEnumEvent (mVector [i], mSavedIt)); 1781 ++mSavedIt; 1775 m_mediums[i].blockAndQueryState(); 1776 QApplication::postEvent(pSelf, new VBoxMediaEnumEvent(m_mediums[i], m_iterator)); 1777 ++m_iterator; 1782 1778 } 1783 1779 1784 /* Post the end-of-enumeration event */1780 /* Post the end-of-enumeration event: */ 1785 1781 if (!m_sfCleanupInProgress) 1786 QApplication::postEvent (self, new VBoxMediaEnumEvent (mSavedIt));1782 QApplication::postEvent(pSelf, new VBoxMediaEnumEvent(m_iterator)); 1787 1783 1788 1784 COMBase::CleanupCOM(); 1789 LogFlow 1785 LogFlow(("MediaEnumThread finished.\n")); 1790 1786 } 1791 1787 1792 1788 private: 1793 1789 1794 QVector <UIMedium> mVector;1795 VBoxMediaList::iterator m SavedIt;1790 QVector<UIMedium> m_mediums; 1791 VBoxMediaList::iterator m_iterator; 1796 1792 }; 1797 1793 -
trunk/src/VBox/Frontends/VirtualBox/src/medium/UIMedium.cpp
r47952 r48061 25 25 #include <QDir> 26 26 27 /* GUI includes */27 /* GUI includes: */ 28 28 #include "UIMedium.h" 29 29 #include "VBoxGlobal.h" … … 37 37 #endif /* !VBOX_WITH_PRECOMPILED_HEADERS */ 38 38 39 QString UIMedium::m Table = QString("<table>%1</table>");40 QString UIMedium::m Row = QString("<tr><td>%1</td></tr>");41 42 UIMedium& UIMedium::operator= (const UIMedium &aOther)43 { 44 m_fHid e = aOther.m_fHide;45 m_fAttachedToHiddenMachinesOnly = aOther.m_fAttachedToHiddenMachinesOnly;46 47 m Medium = aOther.medium();48 m Type = aOther.type();49 m State = aOther.state();50 m LastAccessError = aOther.lastAccessError();51 m Result = aOther.result();52 53 m Id = aOther.id();54 m Name = aOther.name();55 m Location = aOther.location();56 57 m Size = aOther.size();58 m LogicalSize = aOther.logicalSize();59 60 m HardDiskFormat = aOther.hardDiskFormat();61 m HardDiskType = aOther.hardDiskType();62 63 m StorageDetails = aOther.storageDetails();64 65 m Usage = aOther.usage();66 m ToolTip = aOther.tip();67 68 m IsReadOnly = aOther.isReadOnly();69 m IsUsedInSnapshots = aOther.isUsedInSnapshots();70 m IsHostDrive = aOther.isHostDrive();71 72 m CurStateMachineIds = aOther.curStateMachineIds();73 74 m Parent = aOther.parent();75 76 m NoDiffs = aOther.cache();39 QString UIMedium::m_sstrTable = QString("<table>%1</table>"); 40 QString UIMedium::m_sstrRow = QString("<tr><td>%1</td></tr>"); 41 42 UIMedium& UIMedium::operator=(const UIMedium &other) 43 { 44 m_fHidden = other.m_fHidden; 45 m_fAttachedToHiddenMachinesOnly = other.m_fAttachedToHiddenMachinesOnly; 46 47 m_medium = other.medium(); 48 m_type = other.type(); 49 m_state = other.state(); 50 m_strLastAccessError = other.lastAccessError(); 51 m_result = other.result(); 52 53 m_strId = other.id(); 54 m_strName = other.name(); 55 m_strLocation = other.location(); 56 57 m_strSize = other.size(); 58 m_strLogicalSize = other.logicalSize(); 59 60 m_strHardDiskFormat = other.hardDiskFormat(); 61 m_strHardDiskType = other.hardDiskType(); 62 63 m_strStorageDetails = other.storageDetails(); 64 65 m_strUsage = other.usage(); 66 m_strToolTip = other.tip(); 67 68 m_fReadOnly = other.isReadOnly(); 69 m_fUsedInSnapshots = other.isUsedInSnapshots(); 70 m_fHostDrive = other.isHostDrive(); 71 72 m_curStateMachineIds = other.curStateMachineIds(); 73 74 m_pParent = other.parent(); 75 76 m_noDiffs = other.cache(); 77 77 78 78 return *this; … … 95 95 void UIMedium::blockAndQueryState() 96 96 { 97 if (mMedium.isNull()) return; 98 99 mState = mMedium.RefreshState(); 100 101 /* Save the result to distinguish between inaccessible and e.g. uninitialized objects */ 102 mResult = COMResult (mMedium); 103 104 if (!mResult.isOk()) 105 { 106 mState = KMediumState_Inaccessible; 107 mLastAccessError = QString::null; 97 if (m_medium.isNull()) 98 return; 99 100 m_state = m_medium.RefreshState(); 101 102 /* Save the result to distinguish between 103 * inaccessible and e.g. uninitialized objects: */ 104 m_result = COMResult(m_medium); 105 if (!m_result.isOk()) 106 { 107 m_state = KMediumState_Inaccessible; 108 m_strLastAccessError = QString(); 108 109 } 109 110 else 110 m LastAccessError = mMedium.GetLastAccessError();111 m_strLastAccessError = m_medium.GetLastAccessError(); 111 112 112 113 refresh(); … … 125 126 { 126 127 /* We assume these flags are 'false' by default: */ 127 m_fHid e= false;128 m_fHidden = false; 128 129 m_fAttachedToHiddenMachinesOnly = false; 129 130 130 131 /* Detect basic parameters */ 131 m Id = mMedium.isNull() ? QUuid().toString().remove ('{').remove ('}') : mMedium.GetId();132 133 m IsHostDrive = mMedium.isNull() ? false : mMedium.GetHostDrive();134 135 if (m Medium.isNull())136 m Name = VBoxGlobal::tr("Empty", "medium");137 else if (!m IsHostDrive)138 m Name = mMedium.GetName();139 else if (m Medium.GetDescription().isEmpty())140 m Name = VBoxGlobal::tr ("Host Drive '%1'", "medium").arg (QDir::toNativeSeparators (mMedium.GetLocation()));132 m_strId = m_medium.isNull() ? QUuid().toString().remove ('{').remove ('}') : m_medium.GetId(); 133 134 m_fHostDrive = m_medium.isNull() ? false : m_medium.GetHostDrive(); 135 136 if (m_medium.isNull()) 137 m_strName = VBoxGlobal::tr("Empty", "medium"); 138 else if (!m_fHostDrive) 139 m_strName = m_medium.GetName(); 140 else if (m_medium.GetDescription().isEmpty()) 141 m_strName = VBoxGlobal::tr("Host Drive '%1'", "medium").arg(QDir::toNativeSeparators(m_medium.GetLocation())); 141 142 else 142 m Name = VBoxGlobal::tr ("Host Drive %1 (%2)", "medium").arg (mMedium.GetDescription(), mMedium.GetName());143 144 m Location = mMedium.isNull() || mIsHostDrive ? QString("--") :145 QDir::toNativeSeparators (mMedium.GetLocation());143 m_strName = VBoxGlobal::tr("Host Drive %1 (%2)", "medium").arg(m_medium.GetDescription(), m_medium.GetName()); 144 145 m_strLocation = m_medium.isNull() || m_fHostDrive ? QString("--") : 146 QDir::toNativeSeparators(m_medium.GetLocation()); 146 147 147 148 QString tmp; 148 if (!m Medium.isNull())149 tmp = m Medium.GetProperty("Special/GUI/Hints");149 if (!m_medium.isNull()) 150 tmp = m_medium.GetProperty("Special/GUI/Hints"); 150 151 if (!tmp.isEmpty()) 151 152 { 152 153 QStringList tmpList(tmp.split(',')); 153 154 if (tmpList.contains("Hide", Qt::CaseInsensitive)) 154 m_fHid e= true;155 } 156 157 if (m Type == UIMediumType_HardDisk)158 { 159 m HardDiskFormat = mMedium.GetFormat();160 m HardDiskType = vboxGlobal().mediumTypeString (mMedium);161 162 QVector<KMediumVariant> mediumVariants _QVector = mMedium.GetVariant();163 qlonglong mediumVariant s_qlonglong= 0;164 for (int i = 0; i < mediumVariants _QVector.size(); i++)165 mediumVariant s_qlonglong |= mediumVariants_QVector[i];166 167 m StorageDetails = gpConverter->toString((KMediumVariant)mediumVariants_qlonglong);168 m IsReadOnly = mMedium.GetReadOnly();169 170 /* Adjust the parent if its possible */171 CMedium parentMedium = m Medium.GetParent();172 Assert (!parentMedium.isNull() || mParent == NULL);173 174 if (!parentMedium.isNull() && (m Parent == NULL || mParent->mMedium != parentMedium))175 { 176 /* Search for the parent (might be there) */155 m_fHidden = true; 156 } 157 158 if (m_type == UIMediumType_HardDisk) 159 { 160 m_strHardDiskFormat = m_medium.GetFormat(); 161 m_strHardDiskType = vboxGlobal().mediumTypeString(m_medium); 162 163 QVector<KMediumVariant> mediumVariants = m_medium.GetVariant(); 164 qlonglong mediumVariant = 0; 165 for (int i = 0; i < mediumVariants.size(); ++i) 166 mediumVariant |= mediumVariants[i]; 167 168 m_strStorageDetails = gpConverter->toString((KMediumVariant)mediumVariant); 169 m_fReadOnly = m_medium.GetReadOnly(); 170 171 /* Adjust the parent if its possible: */ 172 CMedium parentMedium = m_medium.GetParent(); 173 Assert(!parentMedium.isNull() || m_pParent == NULL); 174 175 if (!parentMedium.isNull() && (m_pParent == NULL || m_pParent->m_medium != parentMedium)) 176 { 177 /* Search for the parent (might be there): */ 177 178 const VBoxMediaList &list = vboxGlobal().currentMediaList(); 178 for (VBoxMediaList::const_iterator it = list.begin(); it != list.end(); ++ 179 for (VBoxMediaList::const_iterator it = list.begin(); it != list.end(); ++it) 179 180 { 180 if ((*it).m Type != UIMediumType_HardDisk)181 if ((*it).m_type != UIMediumType_HardDisk) 181 182 break; 182 183 183 if ((*it).m Medium == parentMedium)184 if ((*it).m_medium == parentMedium) 184 185 { 185 m Parent = unconst(&*it);186 m_pParent = unconst(&*it); 186 187 break; 187 188 } … … 191 192 else 192 193 { 193 m HardDiskFormat = QString::null;194 m HardDiskType = QString::null;195 m IsReadOnly = false;194 m_strHardDiskFormat = QString(); 195 m_strHardDiskType = QString(); 196 m_fReadOnly = false; 196 197 } 197 198 198 199 /* Detect sizes */ 199 if (m State != KMediumState_Inaccessible && mState != KMediumState_NotCreated && !mIsHostDrive)200 { 201 m Size = vboxGlobal().formatSize (mMedium.GetSize());202 if (m Type == UIMediumType_HardDisk)203 m LogicalSize = vboxGlobal().formatSize(mMedium.GetLogicalSize());200 if (m_state != KMediumState_Inaccessible && m_state != KMediumState_NotCreated && !m_fHostDrive) 201 { 202 m_strSize = vboxGlobal().formatSize(m_medium.GetSize()); 203 if (m_type == UIMediumType_HardDisk) 204 m_strLogicalSize = vboxGlobal().formatSize(m_medium.GetLogicalSize()); 204 205 else 205 m LogicalSize = mSize;206 m_strLogicalSize = m_strSize; 206 207 } 207 208 else 208 209 { 209 m Size = mLogicalSize = QString("--");210 m_strSize = m_strLogicalSize = QString("--"); 210 211 } 211 212 212 213 /* Detect usage */ 213 m Usage = QString::null;214 if (!m Medium.isNull())215 { 216 m CurStateMachineIds.clear();217 QVector <QString> machineIds = m Medium.GetMachineIds();214 m_strUsage = QString(); 215 if (!m_medium.isNull()) 216 { 217 m_curStateMachineIds.clear(); 218 QVector <QString> machineIds = m_medium.GetMachineIds(); 218 219 if (machineIds.size() > 0) 219 220 { … … 221 222 m_fAttachedToHiddenMachinesOnly = true; 222 223 223 QString s Usage;224 QString strUsage; 224 225 225 226 CVirtualBox vbox = vboxGlobal().virtualBox(); 226 227 227 for (QVector <QString>::ConstIterator it = machineIds.begin(); it != machineIds.end(); ++ 228 for (QVector <QString>::ConstIterator it = machineIds.begin(); it != machineIds.end(); ++it) 228 229 { 229 230 CMachine machine = vbox.FindMachine(*it); … … 245 246 m_fAttachedToHiddenMachinesOnly = false; 246 247 247 QString s Name = machine.GetName();248 QString s Snapshots;249 250 QVector <QString> snapIds = m Medium.GetSnapshotIds(*it);251 for (QVector <QString>::ConstIterator jt = snapIds.begin(); jt != snapIds.end(); ++ 248 QString strName = machine.GetName(); 249 QString strSnapshots; 250 251 QVector <QString> snapIds = m_medium.GetSnapshotIds(*it); 252 for (QVector <QString>::ConstIterator jt = snapIds.begin(); jt != snapIds.end(); ++jt) 252 253 { 253 254 if (*jt == *it) … … 256 257 * state, we don't distinguish this for now by always 257 258 * giving the VM name in front of snapshot names. */ 258 m CurStateMachineIds.push_back(*jt);259 m_curStateMachineIds.push_back(*jt); 259 260 continue; 260 261 } 261 262 262 263 CSnapshot snapshot = machine.FindSnapshot(*jt); 263 if (!snapshot.isNull()) 264 if (!snapshot.isNull()) // can be NULL while takeSnaphot is in progress 264 265 { 265 if (!s Snapshots.isNull())266 s Snapshots += ", ";267 s Snapshots += snapshot.GetName();266 if (!strSnapshots.isNull()) 267 strSnapshots += ", "; 268 strSnapshots += snapshot.GetName(); 268 269 } 269 270 } 270 271 271 if (!s Usage.isNull())272 s Usage += ", ";273 274 s Usage += sName;275 276 if (!s Snapshots.isNull())272 if (!strUsage.isNull()) 273 strUsage += ", "; 274 275 strUsage += strName; 276 277 if (!strSnapshots.isNull()) 277 278 { 278 s Usage += QString (" (%2)").arg (sSnapshots);279 m IsUsedInSnapshots = true;279 strUsage += QString(" (%2)").arg(strSnapshots); 280 m_fUsedInSnapshots = true; 280 281 } 281 282 else 282 m IsUsedInSnapshots = false;283 m_fUsedInSnapshots = false; 283 284 } 284 285 285 if (!s Usage.isEmpty())286 m Usage = sUsage;286 if (!strUsage.isEmpty()) 287 m_strUsage = strUsage; 287 288 } 288 289 } 289 290 290 291 /* Compose the tooltip */ 291 if (!m Medium.isNull())292 { 293 m ToolTip = mRow.arg (QString ("<p style=white-space:pre><b>%1</b></p>").arg (mIsHostDrive ? mName : mLocation));294 295 if (m Type == UIMediumType_HardDisk)296 { 297 m ToolTip += mRow.arg (VBoxGlobal::tr("<p style=white-space:pre>Type (Format): %1 (%2)</p>", "medium")298 .arg (mHardDiskType).arg (mHardDiskFormat));299 } 300 301 m ToolTip += mRow.arg (VBoxGlobal::tr("<p>Attached to: %1</p>", "image")302 .arg (mUsage.isNull() ? VBoxGlobal::tr ("<i>Not Attached</i>", "image") : mUsage));303 304 switch (m State)292 if (!m_medium.isNull()) 293 { 294 m_strToolTip = m_sstrRow.arg(QString("<p style=white-space:pre><b>%1</b></p>").arg(m_fHostDrive ? m_strName : m_strLocation)); 295 296 if (m_type == UIMediumType_HardDisk) 297 { 298 m_strToolTip += m_sstrRow.arg(VBoxGlobal::tr("<p style=white-space:pre>Type (Format): %1 (%2)</p>", "medium") 299 .arg(m_strHardDiskType).arg(m_strHardDiskFormat)); 300 } 301 302 m_strToolTip += m_sstrRow.arg(VBoxGlobal::tr("<p>Attached to: %1</p>", "image") 303 .arg(m_strUsage.isNull() ? VBoxGlobal::tr("<i>Not Attached</i>", "image") : m_strUsage)); 304 305 switch (m_state) 305 306 { 306 307 case KMediumState_NotCreated: 307 308 { 308 m ToolTip += mRow.arg (VBoxGlobal::tr("<i>Checking accessibility...</i>", "medium"));309 m_strToolTip += m_sstrRow.arg(VBoxGlobal::tr("<i>Checking accessibility...</i>", "medium")); 309 310 break; 310 311 } 311 312 case KMediumState_Inaccessible: 312 313 { 313 if (m Result.isOk())314 if (m_result.isOk()) 314 315 { 315 316 /* Not Accessible */ 316 m ToolTip += mRow.arg ("<hr>") + mRow.arg (VBoxGlobal::highlight (mLastAccessError, true /* aToolTip */));317 m_strToolTip += m_sstrRow.arg("<hr>") + m_sstrRow.arg(VBoxGlobal::highlight(m_strLastAccessError, true /* aToolTip */)); 317 318 } 318 319 else 319 320 { 320 /* Accessibility check (eg GetState()) itself failed */321 m ToolTip += mRow.arg ("<hr>") + mRow.arg (VBoxGlobal::tr("Failed to check media accessibility.", "medium")) +322 mRow.arg (UIMessageCenter::formatErrorInfo (mResult) + ".");321 /* Accessibility check (eg GetState()) itself failed: */ 322 m_strToolTip += m_sstrRow.arg("<hr>") + m_sstrRow.arg(VBoxGlobal::tr("Failed to check media accessibility.", "medium")) + 323 m_sstrRow.arg(UIMessageCenter::formatErrorInfo(m_result) + "."); 323 324 } 324 325 break; … … 329 330 } 330 331 331 /* Reset m NoDiffs */332 m NoDiffs.isSet = false;332 /* Reset m_noDiffs */ 333 m_noDiffs.isSet = false; 333 334 } 334 335 … … 339 340 UIMedium &UIMedium::root() const 340 341 { 341 UIMedium *pRoot = unconst 342 while (pRoot->m Parent != NULL)343 pRoot = pRoot->m Parent;342 UIMedium *pRoot = unconst(this); 343 while (pRoot->m_pParent != NULL) 344 pRoot = pRoot->m_pParent; 344 345 345 346 return *pRoot; … … 354 355 * medium is actually a differencing hard disk. 355 356 * 356 * @param aNoDiffs @c true to enable user-friendly "don't show diffs" mode.357 * @param aCheckRO @c true to perform the #readOnly() check and add a notice357 * @param fNoDiffs @c true to enable user-friendly "don't show diffs" mode. 358 * @param fCheckRO @c true to perform the #readOnly() check and add a notice 358 359 * accordingly. 359 360 */ 360 QString UIMedium::toolTip (bool aNoDiffs /* = false */, bool aCheckRO /* = false */, bool aNullAllowed /* = false */) const361 { 362 QString s Tip;363 364 if (m Medium.isNull())365 { 366 s Tip = aNullAllowed ? mRow.arg (VBoxGlobal::tr("<b>No medium selected</b>", "medium")) +367 mRow.arg (VBoxGlobal::tr("You can also change this while the machine is running.")) :368 mRow.arg (VBoxGlobal::tr("<b>No media available</b>", "medium")) +369 mRow.arg (VBoxGlobal::tr("You can create media images using the virtual media manager."));361 QString UIMedium::toolTip (bool fNoDiffs /* = false */, bool fCheckRO /* = false */, bool fNullAllowed /* = false */) const 362 { 363 QString strTip; 364 365 if (m_medium.isNull()) 366 { 367 strTip = fNullAllowed ? m_sstrRow.arg(VBoxGlobal::tr("<b>No medium selected</b>", "medium")) + 368 m_sstrRow.arg(VBoxGlobal::tr("You can also change this while the machine is running.")) : 369 m_sstrRow.arg(VBoxGlobal::tr("<b>No media available</b>", "medium")) + 370 m_sstrRow.arg(VBoxGlobal::tr("You can create media images using the virtual media manager.")); 370 371 } 371 372 else 372 373 { 373 unconst (this)->checkNoDiffs (aNoDiffs);374 375 s Tip = aNoDiffs ? mNoDiffs.toolTip : mToolTip;376 377 if ( aCheckRO && mIsReadOnly)378 s Tip += mRow.arg("<hr>") +379 mRow.arg (VBoxGlobal::tr("Attaching this hard disk will be performed indirectly using "380 "a newly created differencing hard disk.", "medium"));381 } 382 383 return m Table.arg (sTip);374 unconst(this)->checkNoDiffs(fNoDiffs); 375 376 strTip = fNoDiffs ? m_noDiffs.toolTip : m_strToolTip; 377 378 if (fCheckRO && m_fReadOnly) 379 strTip += m_sstrRow.arg("<hr>") + 380 m_sstrRow.arg(VBoxGlobal::tr("Attaching this hard disk will be performed indirectly using " 381 "a newly created differencing hard disk.", "medium")); 382 } 383 384 return m_sstrTable.arg(strTip); 384 385 } 385 386 … … 394 395 * media icon. 395 396 * 396 * @param aNoDiffs @c true to enable user-friendly "don't show diffs" mode.397 * @param aCheckRO @c true to perform the #readOnly() check and change the icon397 * @param fNoDiffs @c true to enable user-friendly "don't show diffs" mode. 398 * @param fCheckRO @c true to perform the #readOnly() check and change the icon 398 399 * accordingly. 399 400 */ 400 QPixmap UIMedium::icon (bool aNoDiffs /* = false */, bool aCheckRO /* = false */) const401 QPixmap UIMedium::icon(bool fNoDiffs /* = false */, bool fCheckRO /* = false */) const 401 402 { 402 403 QPixmap pixmap; 403 404 404 if (state (aNoDiffs) == KMediumState_Inaccessible)405 pixmap = result (aNoDiffs).isOk() ? vboxGlobal().warningIcon() : vboxGlobal().errorIcon();406 407 if ( aCheckRO && mIsReadOnly)408 pixmap = VBoxGlobal::joinPixmaps (pixmap, QPixmap(":/hd_new_16px.png"));405 if (state(fNoDiffs) == KMediumState_Inaccessible) 406 pixmap = result(fNoDiffs).isOk() ? vboxGlobal().warningIcon() : vboxGlobal().errorIcon(); 407 408 if (fCheckRO && m_fReadOnly) 409 pixmap = VBoxGlobal::joinPixmaps(pixmap, QPixmap(":/hd_new_16px.png")); 409 410 410 411 return pixmap; … … 415 416 * 416 417 * For hard disks, the details include the location, type and the logical size 417 * of the hard disk. Note that if @a aNoDiffs is @c true, these properties are418 * of the hard disk. Note that if @a fNoDiffs is @c true, these properties are 418 419 * queried on the root hard disk of the given hard disk because the primary 419 420 * purpose of the returned string is to be human readable (so that seeing a … … 421 422 * 422 423 * For other media types, the location and the actual size are returned. 423 * Arguments @a aPredictDiff and @a aNoRoot are ignored in this case.424 * 425 * @param aNoDiffs @c true to enable user-friendly "don't show diffs" mode.426 * @param aPredictDiff @c true to mark the hard disk as differencing if424 * Arguments @a fPredictDiff and @a aNoRoot are ignored in this case. 425 * 426 * @param fNoDiffs @c true to enable user-friendly "don't show diffs" mode. 427 * @param fPredictDiff @c true to mark the hard disk as differencing if 427 428 * attaching it would create a differencing hard disk (not 428 429 * used when @a aNoRoot is true). 429 * @param aUseHTML @c true to allow for emphasizing using bold and italics.430 * 431 * @note Use #detailsHTML() instead of passing @c true for @a aUseHTML.430 * @param fUseHTML @c true to allow for emphasizing using bold and italics. 431 * 432 * @note Use #detailsHTML() instead of passing @c true for @a fUseHTML. 432 433 * 433 434 * @note The media object may become uninitialized by a third party while this … … 435 436 * an empty string. 436 437 */ 437 QString UIMedium::details (bool aNoDiffs /* = false */,438 bool aPredictDiff /* = false */,439 bool aUseHTML /* = false */) const440 { 441 // @todo the below check is rough; if m Medium becomes uninitialized, any438 QString UIMedium::details(bool fNoDiffs /* = false */, 439 bool fPredictDiff /* = false */, 440 bool fUseHTML /* = false */) const 441 { 442 // @todo the below check is rough; if m_medium becomes uninitialized, any 442 443 // of getters called afterwards will also fail. The same relates to the 443 444 // root hard disk object (that will be the hard disk itself in case of … … 454 455 // @bugref{2149}. 455 456 456 if (m Medium.isNull() || mIsHostDrive)457 return m Name;458 459 if (!m Medium.isOk())460 return QString ::null;461 462 QString s Details, sStr;463 464 UIMedium *pRoot = unconst 465 KMediumState eState = m State;466 467 if (m Type == UIMediumType_HardDisk)468 { 469 if ( aNoDiffs)457 if (m_medium.isNull() || m_fHostDrive) 458 return m_strName; 459 460 if (!m_medium.isOk()) 461 return QString(); 462 463 QString strDetails, strText; 464 465 UIMedium *pRoot = unconst(this); 466 KMediumState eState = m_state; 467 468 if (m_type == UIMediumType_HardDisk) 469 { 470 if (fNoDiffs) 470 471 { 471 472 pRoot = &this->root(); 472 473 473 bool isDiff = (! aPredictDiff && mParent != NULL) || (aPredictDiff && mIsReadOnly);474 475 s Details = isDiff && aUseHTML ?476 QString ("<i>%1</i>, ").arg (pRoot->mHardDiskType) :477 QString ("%1, ").arg (pRoot->mHardDiskType);478 479 eState = this->state (true /* aNoDiffs */);480 481 if (pRoot->m State == KMediumState_NotCreated)474 bool isDiff = (!fPredictDiff && m_pParent != NULL) || (fPredictDiff && m_fReadOnly); 475 476 strDetails = isDiff && fUseHTML ? 477 QString("<i>%1</i>, ").arg(pRoot->m_strHardDiskType) : 478 QString("%1, ").arg(pRoot->m_strHardDiskType); 479 480 eState = this->state(true /* fNoDiffs */); 481 482 if (pRoot->m_state == KMediumState_NotCreated) 482 483 eState = KMediumState_NotCreated; 483 484 } 484 485 else 485 486 { 486 s Details = QString ("%1, ").arg (pRoot->mHardDiskType);487 strDetails = QString("%1, ").arg(pRoot->m_strHardDiskType); 487 488 } 488 489 } … … 493 494 { 494 495 case KMediumState_NotCreated: 495 s Str = VBoxGlobal::tr("Checking...", "medium");496 s Details += aUseHTML ? QString ("<i>%1</i>").arg (sStr) : sStr;496 strText = VBoxGlobal::tr("Checking...", "medium"); 497 strDetails += fUseHTML ? QString("<i>%1</i>").arg(strText) : strText; 497 498 break; 498 499 case KMediumState_Inaccessible: 499 s Str = VBoxGlobal::tr("Inaccessible", "medium");500 s Details += aUseHTML ? QString ("<b>%1</b>").arg (sStr) : sStr;500 strText = VBoxGlobal::tr("Inaccessible", "medium"); 501 strDetails += fUseHTML ? QString("<b>%1</b>").arg(strText) : strText; 501 502 break; 502 503 default: 503 s Details += mType == UIMediumType_HardDisk ? pRoot->mLogicalSize : pRoot->mSize;504 strDetails += m_type == UIMediumType_HardDisk ? pRoot->m_strLogicalSize : pRoot->m_strSize; 504 505 break; 505 506 } 506 507 507 s Details = aUseHTML ?508 QString ("%1 (<nobr>%2</nobr>)").arg (VBoxGlobal::locationForHTML (pRoot->mName), sDetails) :509 QString ("%1 (%2)").arg (VBoxGlobal::locationForHTML (pRoot->mName), sDetails);510 511 return s Details;512 } 513 514 /** 515 * Checks if m NoDiffs is filled in and does it if not.516 * 517 * @param aNoDiffs @if false, this method immediately returns.518 */ 519 void UIMedium::checkNoDiffs (bool aNoDiffs)520 { 521 if (! aNoDiffs || mNoDiffs.isSet)508 strDetails = fUseHTML ? 509 QString("%1 (<nobr>%2</nobr>)").arg(VBoxGlobal::locationForHTML(pRoot->m_strName), strDetails) : 510 QString("%1 (%2)").arg(VBoxGlobal::locationForHTML(pRoot->m_strName), strDetails); 511 512 return strDetails; 513 } 514 515 /** 516 * Checks if m_noDiffs is filled in and does it if not. 517 * 518 * @param fNoDiffs @if false, this method immediately returns. 519 */ 520 void UIMedium::checkNoDiffs(bool fNoDiffs) 521 { 522 if (!fNoDiffs || m_noDiffs.isSet) 522 523 return; 523 524 524 m NoDiffs.toolTip = QString::null;525 526 m NoDiffs.state = mState;527 for (UIMedium *cur = m Parent; cur != NULL; cur = cur->mParent)528 { 529 if (cur->m State == KMediumState_Inaccessible)530 { 531 m NoDiffs.state = cur->mState;532 533 if (m NoDiffs.toolTip.isNull())534 m NoDiffs.toolTip = mRow.arg (VBoxGlobal::tr("Some of the media in this hard disk chain "535 "are inaccessible. Please use the Virtual Media "536 "Manager in <b>Show Differencing Hard Disks</b> "537 "mode to inspect these media.", "medium"));538 539 if (!cur->m Result.isOk())525 m_noDiffs.toolTip = QString(); 526 527 m_noDiffs.state = m_state; 528 for (UIMedium *cur = m_pParent; cur != NULL; cur = cur->m_pParent) 529 { 530 if (cur->m_state == KMediumState_Inaccessible) 531 { 532 m_noDiffs.state = cur->m_state; 533 534 if (m_noDiffs.toolTip.isNull()) 535 m_noDiffs.toolTip = m_sstrRow.arg(VBoxGlobal::tr("Some of the media in this hard disk chain " 536 "are inaccessible. Please use the Virtual Media " 537 "Manager in <b>Show Differencing Hard Disks</b> " 538 "mode to inspect these media.", "medium")); 539 540 if (!cur->m_result.isOk()) 540 541 { 541 m NoDiffs.result = cur->mResult;542 m_noDiffs.result = cur->m_result; 542 543 break; 543 544 } … … 545 546 } 546 547 547 if (m Parent != NULL && !mIsReadOnly)548 { 549 m NoDiffs.toolTip = root().tip() +550 mRow.arg("<hr>") +551 mRow.arg (VBoxGlobal::tr("This base hard disk is indirectly attached using "552 "the following differencing hard disk:", "medium")) +553 mToolTip + mNoDiffs.toolTip;554 } 555 556 if (m NoDiffs.toolTip.isNull())557 m NoDiffs.toolTip = mToolTip;558 559 m NoDiffs.isSet = true;560 } 561 548 if (m_pParent != NULL && !m_fReadOnly) 549 { 550 m_noDiffs.toolTip = root().tip() + 551 m_sstrRow.arg("<hr>") + 552 m_sstrRow.arg(VBoxGlobal::tr("This base hard disk is indirectly attached using " 553 "the following differencing hard disk:", "medium")) + 554 m_strToolTip + m_noDiffs.toolTip; 555 } 556 557 if (m_noDiffs.toolTip.isNull()) 558 m_noDiffs.toolTip = m_strToolTip; 559 560 m_noDiffs.isSet = true; 561 } 562 -
trunk/src/VBox/Frontends/VirtualBox/src/medium/UIMedium.h
r47952 r48061 39 39 struct NoDiffsCache 40 40 { 41 NoDiffsCache() : isSet (false), state(KMediumState_NotCreated) {}42 NoDiffsCache& operator= (const NoDiffsCache &aOther)41 NoDiffsCache() : isSet(false), state(KMediumState_NotCreated) {} 42 NoDiffsCache& operator=(const NoDiffsCache &other) 43 43 { 44 isSet = aOther.isSet;45 state = aOther.state;46 result = aOther.result;47 toolTip = aOther.toolTip;44 isSet = other.isSet; 45 state = other.state; 46 result = other.result; 47 toolTip = other.toolTip; 48 48 return *this; 49 49 } … … 87 87 */ 88 88 UIMedium() 89 : m Type(UIMediumType_Invalid)90 , m State(KMediumState_NotCreated)91 , m IsReadOnly(false)92 , m IsUsedInSnapshots(false)93 , m Parent(0) { refresh(); }89 : m_type(UIMediumType_Invalid) 90 , m_state(KMediumState_NotCreated) 91 , m_fReadOnly(false) 92 , m_fUsedInSnapshots(false) 93 , m_pParent(0) { refresh(); } 94 94 95 95 /** … … 101 101 * 102 102 * One of the hardDisk, dvdImage, or floppyImage members is assigned from 103 * aMedium according to aType. @a aParent must be always NULL for non-hard103 * medium according to type. @a pParent must be always NULL for non-hard 104 104 * disk media. 105 105 */ 106 UIMedium (const CMedium &aMedium, UIMediumType aType, UIMedium *aParent = 0)107 : m Medium (aMedium)108 , m Type (aType)109 , m State(KMediumState_NotCreated)110 , m IsReadOnly(false)111 , m IsUsedInSnapshots(false)112 , m Parent (aParent) { refresh(); }106 UIMedium(const CMedium &medium, UIMediumType type, UIMedium *pParent = 0) 107 : m_medium(medium) 108 , m_type(type) 109 , m_state(KMediumState_NotCreated) 110 , m_fReadOnly(false) 111 , m_fUsedInSnapshots(false) 112 , m_pParent(pParent) { refresh(); } 113 113 114 114 /** 115 115 * Similar to the other non-null constructor but sets the media state to 116 * @a aState. Suitable when the media state is known such as right after116 * @a state. Suitable when the media state is known such as right after 117 117 * creation. 118 118 */ 119 UIMedium (const CMedium &aMedium, UIMediumType aType, KMediumState aState)120 : m Medium (aMedium)121 , m Type (aType)122 , m State (aState)123 , m IsReadOnly(false)124 , m IsUsedInSnapshots(false)125 , m Parent(0) { refresh(); }126 127 UIMedium& operator= (const UIMedium &aOther);119 UIMedium(const CMedium &medium, UIMediumType type, KMediumState state) 120 : m_medium(medium) 121 , m_type(type) 122 , m_state(state) 123 , m_fReadOnly(false) 124 , m_fUsedInSnapshots(false) 125 , m_pParent(0) { refresh(); } 126 127 UIMedium& operator=(const UIMedium &other); 128 128 129 129 void blockAndQueryState(); 130 130 void refresh(); 131 131 132 bool isHidden() const { return m_fHid e| m_fAttachedToHiddenMachinesOnly; }133 134 const CMedium &medium() const { return m Medium; }135 136 UIMediumType type() const { return m Type; }132 bool isHidden() const { return m_fHidden | m_fAttachedToHiddenMachinesOnly; } 133 134 const CMedium &medium() const { return m_medium; } 135 136 UIMediumType type() const { return m_type; } 137 137 138 138 /** … … 140 140 * terms of inaccessibility) detected on the given hard disk chain. 141 141 * 142 * @param aNoDiffs @c true to enable user-friendly "don't show diffs" mode.143 */ 144 KMediumState state (bool aNoDiffs = false) const142 * @param fNoDiffs @c true to enable user-friendly "don't show diffs" mode. 143 */ 144 KMediumState state(bool fNoDiffs = false) const 145 145 { 146 unconst (this)->checkNoDiffs (aNoDiffs);147 return aNoDiffs ? mNoDiffs.state : mState;146 unconst (this)->checkNoDiffs(fNoDiffs); 147 return fNoDiffs ? m_noDiffs.state : m_state; 148 148 } 149 149 150 QString lastAccessError() const { return m LastAccessError; }150 QString lastAccessError() const { return m_strLastAccessError; } 151 151 152 152 /** … … 156 156 * detected on the given hard disk chain. 157 157 * 158 * @param aNoDiffs @c true to enable user-friendly "don't show diffs" mode.159 */ 160 const COMResult &result (bool aNoDiffs = false) const158 * @param fNoDiffs @c true to enable user-friendly "don't show diffs" mode. 159 */ 160 const COMResult &result(bool fNoDiffs = false) const 161 161 { 162 unconst (this)->checkNoDiffs (aNoDiffs);163 return aNoDiffs ? mNoDiffs.result : mResult;162 unconst(this)->checkNoDiffs(fNoDiffs); 163 return fNoDiffs ? m_noDiffs.result : m_result; 164 164 } 165 165 166 QString id() const { return m Id; }167 QString name (bool aNoDiffs = false) const { return aNoDiffs ? root().mName : mName; }168 QString location (bool aNoDiffs = false) const { return aNoDiffs ? root().mLocation : mLocation; }169 170 QString size (bool aNoDiffs = false) const { return aNoDiffs ? root().mSize : mSize; }171 QString logicalSize (bool aNoDiffs = false) const { return aNoDiffs ? root().mLogicalSize : mLogicalSize; }172 173 QString hardDiskFormat (bool aNoDiffs = false) const { return aNoDiffs ? root().mHardDiskFormat : mHardDiskFormat; }174 QString hardDiskType (bool aNoDiffs = false) const { return aNoDiffs ? root().mHardDiskType : mHardDiskType; }175 176 QString storageDetails() const { return m StorageDetails; }177 178 QString usage (bool aNoDiffs = false) const { return aNoDiffs ? root().mUsage : mUsage; }179 QString tip() const { return m ToolTip; }180 181 const NoDiffsCache& cache() const { return m NoDiffs; }166 QString id() const { return m_strId; } 167 QString name(bool fNoDiffs = false) const { return fNoDiffs ? root().m_strName : m_strName; } 168 QString location(bool fNoDiffs = false) const { return fNoDiffs ? root().m_strLocation : m_strLocation; } 169 170 QString size(bool fNoDiffs = false) const { return fNoDiffs ? root().m_strSize : m_strSize; } 171 QString logicalSize(bool fNoDiffs = false) const { return fNoDiffs ? root().m_strLogicalSize : m_strLogicalSize; } 172 173 QString hardDiskFormat(bool fNoDiffs = false) const { return fNoDiffs ? root().m_strHardDiskFormat : m_strHardDiskFormat; } 174 QString hardDiskType(bool fNoDiffs = false) const { return fNoDiffs ? root().m_strHardDiskType : m_strHardDiskType; } 175 176 QString storageDetails() const { return m_strStorageDetails; } 177 178 QString usage(bool fNoDiffs = false) const { return fNoDiffs ? root().m_strUsage : m_strUsage; } 179 QString tip() const { return m_strToolTip; } 180 181 const NoDiffsCache& cache() const { return m_noDiffs; } 182 182 183 183 /** … … 186 186 * be attached indirectly. 187 187 */ 188 bool isReadOnly() const { return m IsReadOnly; }188 bool isReadOnly() const { return m_fReadOnly; } 189 189 190 190 /** … … 193 193 * comma-separated VM names (with snapshot names, if any, in parenthesis). 194 194 */ 195 bool isUsed() const { return !m Usage.isNull(); }195 bool isUsed() const { return !m_strUsage.isNull(); } 196 196 197 197 /** 198 198 * Returns @c true if this medium is attached to any VM in any snapshot. 199 199 */ 200 bool isUsedInSnapshots() const { return m IsUsedInSnapshots; }200 bool isUsedInSnapshots() const { return m_fUsedInSnapshots; } 201 201 202 202 /** 203 203 * Returns @c true if this medium corresponds to real host drive. 204 204 */ 205 bool isHostDrive() const { return m IsHostDrive; }205 bool isHostDrive() const { return m_fHostDrive; } 206 206 207 207 /** 208 208 * Returns @c true if this medium is attached to the given machine in the current state. 209 209 */ 210 bool isAttachedInCurStateTo (const QString &aMachineId) const { return mCurStateMachineIds.indexOf (aMachineId) >= 0; }210 bool isAttachedInCurStateTo(const QString &strMachineId) const { return m_curStateMachineIds.indexOf(strMachineId) >= 0; } 211 211 212 212 /** … … 214 214 * to in their current state (i.e. excluding snapshots). 215 215 */ 216 const QList <QString> &curStateMachineIds() const { return m CurStateMachineIds; }216 const QList <QString> &curStateMachineIds() const { return m_curStateMachineIds; } 217 217 218 218 /** 219 219 * Returns a parent medium. For non-hard disk media, this is always NULL. 220 220 */ 221 UIMedium* parent() const { return m Parent; }221 UIMedium* parent() const { return m_pParent; } 222 222 223 223 UIMedium& root() const; 224 224 225 QString toolTip (bool aNoDiffs = false, bool aCheckRO = false, bool aNullAllowed = false) const;226 QPixmap icon (bool aNoDiffs = false, bool aCheckRO = false) const;227 228 /** Shortcut to <tt>#toolTip (aNoDiffs, true)</tt>. */229 QString toolTipCheckRO (bool aNoDiffs = false, bool aNullAllowed = false) const { return toolTip (aNoDiffs, true, aNullAllowed); }230 231 /** Shortcut to <tt>#icon (aNoDiffs, true)</tt>. */232 QPixmap iconCheckRO (bool aNoDiffs = false) const { return icon (aNoDiffs, true); }233 234 QString details (bool aNoDiffs = false, bool aPredictDiff = false, bool aUseHTML = false) const;235 236 /** Shortcut to <tt>#details (aNoDiffs, aPredictDiff, true)</tt>. */237 QString detailsHTML (bool aNoDiffs = false, bool aPredictDiff = false) const { return details (aNoDiffs, aPredictDiff, true); }225 QString toolTip(bool fNoDiffs = false, bool fCheckRO = false, bool fNullAllowed = false) const; 226 QPixmap icon(bool fNoDiffs = false, bool fCheckRO = false) const; 227 228 /** Shortcut to <tt>#toolTip(fNoDiffs, true)</tt>. */ 229 QString toolTipCheckRO(bool fNoDiffs = false, bool fNullAllowed = false) const { return toolTip(fNoDiffs, true, fNullAllowed); } 230 231 /** Shortcut to <tt>#icon(fNoDiffs, true)</tt>. */ 232 QPixmap iconCheckRO(bool fNoDiffs = false) const { return icon(fNoDiffs, true); } 233 234 QString details(bool fNoDiffs = false, bool fPredictDiff = false, bool aUseHTML = false) const; 235 236 /** Shortcut to <tt>#details(fNoDiffs, fPredictDiff, true)</tt>. */ 237 QString detailsHTML(bool fNoDiffs = false, bool fPredictDiff = false) const { return details(fNoDiffs, fPredictDiff, true); } 238 238 239 239 /** Returns @c true if this media descriptor is a null object. */ 240 bool isNull() const { return m Medium.isNull(); }240 bool isNull() const { return m_medium.isNull(); } 241 241 242 242 private: 243 243 244 void checkNoDiffs (bool aNoDiffs);245 246 CMedium m Medium;247 248 UIMediumType m Type;249 250 KMediumState m State;251 QString m LastAccessError;252 COMResult m Result;253 254 QString m Id;255 QString m Name;256 QString m Location;257 258 QString m Size;259 QString m LogicalSize;260 261 QString m HardDiskFormat;262 QString m HardDiskType;263 264 QString m StorageDetails;265 266 QString m Usage;267 QString m ToolTip;268 269 bool m IsReadOnly: 1;270 bool m IsUsedInSnapshots: 1;271 bool m IsHostDrive: 1;272 bool m_fHid e: 1;244 void checkNoDiffs(bool fNoDiffs); 245 246 CMedium m_medium; 247 248 UIMediumType m_type; 249 250 KMediumState m_state; 251 QString m_strLastAccessError; 252 COMResult m_result; 253 254 QString m_strId; 255 QString m_strName; 256 QString m_strLocation; 257 258 QString m_strSize; 259 QString m_strLogicalSize; 260 261 QString m_strHardDiskFormat; 262 QString m_strHardDiskType; 263 264 QString m_strStorageDetails; 265 266 QString m_strUsage; 267 QString m_strToolTip; 268 269 bool m_fReadOnly : 1; 270 bool m_fUsedInSnapshots : 1; 271 bool m_fHostDrive : 1; 272 bool m_fHidden : 1; 273 273 bool m_fAttachedToHiddenMachinesOnly : 1; 274 274 275 QList <QString> mCurStateMachineIds;276 277 UIMedium *m Parent;278 279 NoDiffsCache m NoDiffs;280 281 static QString m Table;282 static QString m Row;275 QList<QString> m_curStateMachineIds; 276 277 UIMedium *m_pParent; 278 279 NoDiffsCache m_noDiffs; 280 281 static QString m_sstrTable; 282 static QString m_sstrRow; 283 283 }; 284 284 285 typedef QLinkedList 285 typedef QLinkedList<UIMedium> VBoxMediaList; 286 286 287 287 #endif /* __UIMedium_h__ */ 288
Note:
See TracChangeset
for help on using the changeset viewer.