Changeset 55101 in vbox
- Timestamp:
- Apr 3, 2015 8:22:01 PM (10 years ago)
- svn:sync-xref-src-repo-rev:
- 99396
- Location:
- trunk/src/VBox/Frontends/VirtualBox/src/medium
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Frontends/VirtualBox/src/medium/UIMedium.cpp
r55100 r55101 100 100 101 101 m_fHidden = other.m_fHidden; 102 m_f AttachedToHiddenMachinesOnly = other.m_fAttachedToHiddenMachinesOnly;102 m_fUsedByHiddenMachinesOnly = other.m_fUsedByHiddenMachinesOnly; 103 103 m_fReadOnly = other.isReadOnly(); 104 104 m_fUsedInSnapshots = other.isUsedInSnapshots(); … … 110 110 void UIMedium::blockAndQueryState() 111 111 { 112 /* Ignore for NULL medium: */ 112 113 if (m_medium.isNull()) 113 114 return; 114 115 116 /* Acquire actual medium state: */ 115 117 m_state = m_medium.RefreshState(); 116 118 … … 126 128 m_strLastAccessError = m_medium.GetLastAccessError(); 127 129 130 /* Refresh finally: */ 128 131 refresh(); 129 132 } … … 131 134 void UIMedium::refresh() 132 135 { 133 /* Flags are 'false' by default: */ 136 /* Reset ID parameters: */ 137 m_strId = nullID(); 138 m_strRootId = nullID(); 139 m_strParentId = nullID(); 140 141 /* Reset cache parameters: */ 142 //m_strKey = nullID(); 143 144 /* Reset name/location parameters: */ 145 m_strName = VBoxGlobal::tr("Empty", "medium"); 146 m_strLocation = m_strSize = m_strLogicalSize = QString("--"); 147 148 /* Reset size parameters: */ 149 m_strSize = QString(); 150 m_strLogicalSize = QString(); 151 152 /* Reset hard drive related parameters: */ 153 m_strHardDiskType = QString(); 154 m_strHardDiskFormat = QString(); 155 m_strStorageDetails = QString(); 156 157 /* Reset data parameters: */ 158 m_strUsage = QString(); 159 m_strToolTip = QString(); 160 m_machineIds.clear(); 161 m_curStateMachineIds.clear(); 162 163 /* Reset m_noDiffs: */ 164 m_noDiffs.isSet = false; 165 166 /* Reset flags: */ 134 167 m_fHidden = false; 135 m_f AttachedToHiddenMachinesOnly = false;168 m_fUsedByHiddenMachinesOnly = false; 136 169 m_fReadOnly = false; 137 170 m_fUsedInSnapshots = false; 138 171 m_fHostDrive = false; 139 172 140 /* Detect basic parameters... */ 141 142 m_strId = m_medium.isNull() ? nullID() : m_medium.GetId(); 143 144 if (m_strKey.isNull() && !m_strId.isNull()) 145 m_strKey = m_strId; 146 147 m_fHostDrive = m_medium.isNull() ? false : m_medium.GetHostDrive(); 148 149 if (m_medium.isNull()) 150 m_strName = VBoxGlobal::tr("Empty", "medium"); 151 else if (!m_fHostDrive) 152 m_strName = m_medium.GetName(); 153 else if (m_medium.GetDescription().isEmpty()) 154 m_strName = VBoxGlobal::tr("Host Drive '%1'", "medium").arg(QDir::toNativeSeparators(m_medium.GetLocation())); 155 else 156 m_strName = VBoxGlobal::tr("Host Drive %1 (%2)", "medium").arg(m_medium.GetDescription(), m_medium.GetName()); 157 158 m_strLocation = m_medium.isNull() || m_fHostDrive ? QString("--") : 159 QDir::toNativeSeparators(m_medium.GetLocation()); 160 161 QString tmp; 173 /* For non NULL medium: */ 162 174 if (!m_medium.isNull()) 163 tmp = m_medium.GetProperty("Special/GUI/Hints"); 164 if (!tmp.isEmpty()) 165 { 166 QStringList tmpList(tmp.split(',')); 167 if (tmpList.contains("Hide", Qt::CaseInsensitive)) 168 m_fHidden = true; 169 } 170 171 /* Initialize parent/root IDs: */ 172 m_strParentId = nullID(); 173 m_strRootId = m_strId; 174 if (m_type == UIMediumType_HardDisk) 175 { 176 m_strHardDiskFormat = m_medium.GetFormat(); 177 m_strHardDiskType = vboxGlobal().mediumTypeString(m_medium); 178 179 QVector<KMediumVariant> mediumVariants = m_medium.GetVariant(); 180 qlonglong mediumVariant = 0; 181 for (int i = 0; i < mediumVariants.size(); ++i) 182 mediumVariant |= mediumVariants[i]; 183 184 m_strStorageDetails = gpConverter->toString((KMediumVariant)mediumVariant); 185 m_fReadOnly = m_medium.GetReadOnly(); 186 187 /* Adjust parent/root IDs: */ 188 CMedium parentMedium = m_medium.GetParent(); 189 if (!parentMedium.isNull()) 190 m_strParentId = parentMedium.GetId(); 191 while (!parentMedium.isNull()) 192 { 193 m_strRootId = parentMedium.GetId(); 194 parentMedium = parentMedium.GetParent(); 195 } 196 } 197 else 198 { 199 m_strHardDiskFormat = QString(); 200 m_strHardDiskType = QString(); 201 m_fReadOnly = false; 202 } 203 204 /* Detect sizes */ 205 if (m_state != KMediumState_Inaccessible && m_state != KMediumState_NotCreated && !m_fHostDrive) 206 { 207 m_strSize = vboxGlobal().formatSize(m_medium.GetSize()); 175 { 176 /* Refresh medium ID: */ 177 m_strId = m_medium.GetId(); 178 /* Refresh root medium ID: */ 179 m_strRootId = m_strId; 180 181 /* Init medium key if necessary: */ 182 if (m_strKey.isNull()) 183 m_strKey = m_strId; 184 185 /* Check whether this is host-drive medium: */ 186 m_fHostDrive = m_medium.GetHostDrive(); 187 188 /* Refresh medium name: */ 189 if (!m_fHostDrive) 190 m_strName = m_medium.GetName(); 191 else if (m_medium.GetDescription().isEmpty()) 192 m_strName = VBoxGlobal::tr("Host Drive '%1'", "medium").arg(QDir::toNativeSeparators(m_medium.GetLocation())); 193 else 194 m_strName = VBoxGlobal::tr("Host Drive %1 (%2)", "medium").arg(m_medium.GetDescription(), m_medium.GetName()); 195 /* Refresh medium location: */ 196 if (!m_fHostDrive) 197 m_strLocation = QDir::toNativeSeparators(m_medium.GetLocation()); 198 199 /* Refresh medium size and logical size: */ 200 if (!m_fHostDrive) 201 { 202 /* Only for created and accessible mediums: */ 203 if (m_state != KMediumState_Inaccessible && m_state != KMediumState_NotCreated) 204 { 205 m_strSize = vboxGlobal().formatSize(m_medium.GetSize()); 206 if (m_type == UIMediumType_HardDisk) 207 m_strLogicalSize = vboxGlobal().formatSize(m_medium.GetLogicalSize()); 208 else 209 m_strLogicalSize = m_strSize; 210 } 211 } 212 213 /* For hard drive medium: */ 208 214 if (m_type == UIMediumType_HardDisk) 209 m_strLogicalSize = vboxGlobal().formatSize(m_medium.GetLogicalSize()); 210 else 211 m_strLogicalSize = m_strSize; 212 } 213 else 214 { 215 m_strSize = m_strLogicalSize = QString("--"); 216 } 217 218 /* Detect usage */ 219 m_strUsage = QString(); 220 if (!m_medium.isNull()) 221 { 215 { 216 /* Refresh hard drive disk type: */ 217 m_strHardDiskType = vboxGlobal().mediumTypeString(m_medium); 218 /* Refresh hard drive format: */ 219 m_strHardDiskFormat = m_medium.GetFormat(); 220 221 /* Refresh hard drive storage details: */ 222 qlonglong iMediumVariant = 0; 223 foreach (const KMediumVariant &enmVariant, m_medium.GetVariant()) 224 iMediumVariant |= enmVariant; 225 m_strStorageDetails = gpConverter->toString((KMediumVariant)iMediumVariant); 226 227 /* Check whether this is read-only hard drive: */ 228 m_fReadOnly = m_medium.GetReadOnly(); 229 230 /* Refresh parent hard drive ID: */ 231 CMedium parentMedium = m_medium.GetParent(); 232 if (!parentMedium.isNull()) 233 m_strParentId = parentMedium.GetId(); 234 235 /* Refresh hard drive ID: */ 236 while (!parentMedium.isNull()) 237 { 238 m_strRootId = parentMedium.GetId(); 239 parentMedium = parentMedium.GetParent(); 240 } 241 } 242 243 /* Check whether this is hidden medium: */ 244 QString strHints = m_medium.GetProperty("Special/GUI/Hints"); 245 if (!strHints.isEmpty()) 246 { 247 QStringList hints(strHints.split(',')); 248 if (hints.contains("Hide", Qt::CaseInsensitive)) 249 m_fHidden = true; 250 } 251 252 /* Refresh usage data: */ 222 253 m_curStateMachineIds.clear(); 223 254 m_machineIds = m_medium.GetMachineIds().toList(); 224 255 if (m_machineIds.size() > 0) 225 256 { 226 /* We assume this flag is 'true' if at least one machine present: */ 227 m_fAttachedToHiddenMachinesOnly = true; 228 229 QString strUsage; 230 257 /* Get CVirtualBox object: */ 231 258 CVirtualBox vbox = vboxGlobal().virtualBox(); 232 259 260 /* By default we assuming that this medium is attached 261 * to 'hidden' machines only, if at least one machine present: */ 262 m_fUsedByHiddenMachinesOnly = true; 263 264 /* Prepare machine usage: */ 265 QString strMachineUsage; 266 /* Walk through all the machines this medium attached to: */ 233 267 foreach (const QString &strMachineID, m_machineIds) 234 268 { 269 /* Look for the corresponding machine: */ 235 270 CMachine machine = vbox.FindMachine(strMachineID); 236 271 237 /* UIMedium object can wrap newly created CMedium object which belongs to 238 * not yet registered machine, like while creating VM clone. 239 * We can skip such a machines in usage string. 240 * CVirtualBox::FindMachine() will return null machine for such case. */ 272 /* UIMedium object can wrap newly created CMedium object 273 * which belongs to not yet registered machine, like while creating VM clone. 274 * We can skip such a machines in usage string. */ 241 275 if (machine.isNull()) 242 276 { 243 /* We can't decide for that medium yet,244 * assume this flag is 'false' for now: */245 m_f AttachedToHiddenMachinesOnly = false;277 /* Since we can't precisely check 'hidden' status for that machine in such case, 278 * we have to assume that medium attached not only to 'hidden' machines: */ 279 m_fUsedByHiddenMachinesOnly = false; 246 280 continue; 247 281 } 248 282 249 /* Finally , we are checking if current machine overrides this flag: */250 if ( m_fAttachedToHiddenMachinesOnly &&gEDataManager->showMachineInSelectorChooser(strMachineID))251 m_f AttachedToHiddenMachinesOnly = false;252 253 QString strName = machine.GetName();254 QString strSnapshot s;255 283 /* Finally we can precisely check if current machine is 'hidden': */ 284 if (gEDataManager->showMachineInSelectorChooser(strMachineID)) 285 m_fUsedByHiddenMachinesOnly = false; 286 287 /* Prepare snapshot usage: */ 288 QString strSnapshotUsage; 289 /* Walk through all the snapshots this medium attached to: */ 256 290 foreach (const QString &strSnapshotID, m_medium.GetSnapshotIds(strMachineID)) 257 291 { … … 265 299 } 266 300 301 /* Look for the corresponding snapshot: */ 267 302 CSnapshot snapshot = machine.FindSnapshot(strSnapshotID); 268 if (!snapshot.isNull()) // can be NULL while takeSnaphot is in progress 269 { 270 if (!strSnapshots.isNull()) 271 strSnapshots += ", "; 272 strSnapshots += snapshot.GetName(); 273 } 303 304 /* Snapshot can be NULL while takeSnaphot is in progress: */ 305 if (snapshot.isNull()) 306 continue; 307 308 /* Refresh snapshot usage flag: */ 309 m_fUsedInSnapshots = true; 310 311 /* Append snapshot usage: */ 312 if (!strSnapshotUsage.isNull()) 313 strSnapshotUsage += ", "; 314 strSnapshotUsage += snapshot.GetName(); 274 315 } 275 316 276 if (!strUsage.isNull()) 277 strUsage += ", "; 278 279 strUsage += strName; 280 281 if (!strSnapshots.isNull()) 282 { 283 strUsage += QString(" (%2)").arg(strSnapshots); 284 m_fUsedInSnapshots = true; 285 } 286 else 287 m_fUsedInSnapshots = false; 317 /* Append machine usage: */ 318 if (!strMachineUsage.isNull()) 319 strMachineUsage += ", "; 320 strMachineUsage += machine.GetName(); 321 322 /* Append snapshot usage: */ 323 if (!strSnapshotUsage.isNull()) 324 strMachineUsage += QString(" (%2)").arg(strSnapshotUsage); 288 325 } 289 326 290 if (!strUsage.isEmpty()) 291 m_strUsage = strUsage; 292 } 293 } 294 295 /* Compose the tooltip */ 296 if (!m_medium.isNull()) 297 { 327 /* Append machine usage: */ 328 if (!strMachineUsage.isEmpty()) 329 m_strUsage += strMachineUsage; 330 } 331 332 /* Refresh tool-tip: */ 298 333 m_strToolTip = m_sstrRow.arg(QString("<p style=white-space:pre><b>%1</b></p>").arg(m_fHostDrive ? m_strName : m_strLocation)); 299 300 334 if (m_type == UIMediumType_HardDisk) 301 335 { … … 303 337 .arg(m_strHardDiskType).arg(m_strHardDiskFormat)); 304 338 } 305 306 339 m_strToolTip += m_sstrRow.arg(VBoxGlobal::tr("<p>Attached to: %1</p>", "image") 307 340 .arg(m_strUsage.isNull() ? VBoxGlobal::tr("<i>Not Attached</i>", "image") : m_strUsage)); 308 309 341 switch (m_state) 310 342 { … … 318 350 if (m_result.isOk()) 319 351 { 320 /* Not Accessible */352 /* Not Accessible: */ 321 353 m_strToolTip += m_sstrRow.arg("<hr>") + m_sstrRow.arg(VBoxGlobal::highlight(m_strLastAccessError, true /* aToolTip */)); 322 354 } … … 333 365 } 334 366 } 335 336 /* Reset m_noDiffs */337 m_noDiffs.isSet = false;338 367 } 339 368 -
trunk/src/VBox/Frontends/VirtualBox/src/medium/UIMedium.h
r55099 r55101 253 253 254 254 /** Returns whether this medium is hidden. 255 * @note The medium is considered hiddenif it has corresponding256 * medium property or is connected to hiddenVMs only. */257 bool isHidden() const { return m_fHidden | m_f AttachedToHiddenMachinesOnly; }255 * @note The medium is considered 'hidden' if it has corresponding 256 * medium property or is connected to 'hidden' VMs only. */ 257 bool isHidden() const { return m_fHidden | m_fUsedByHiddenMachinesOnly; } 258 258 259 259 /** Returns whether this medium is read-only … … 346 346 NoDiffsCache m_noDiffs; 347 347 348 /** Holds whether this medium is hiddenby the corresponding medium property. */349 bool m_fHidden 350 /** Holds whether this medium is hidden because it's connected to hiddenVMs only. */351 bool m_f AttachedToHiddenMachinesOnly : 1;348 /** Holds whether this medium is 'hidden' by the corresponding medium property. */ 349 bool m_fHidden : 1; 350 /** Holds whether this medium is 'hidden' because it's used by 'hidden' VMs only. */ 351 bool m_fUsedByHiddenMachinesOnly : 1; 352 352 /** Holds whether this medium is read-only. */ 353 bool m_fReadOnly 353 bool m_fReadOnly : 1; 354 354 /** Holds whether this medium is attached to any VM in any snapshot. */ 355 bool m_fUsedInSnapshots 355 bool m_fUsedInSnapshots : 1; 356 356 /** Holds whether this medium corresponds to real host drive. */ 357 bool m_fHostDrive 357 bool m_fHostDrive : 1; 358 358 359 359 /** Holds the NULL medium ID. */
Note:
See TracChangeset
for help on using the changeset viewer.