Changeset 49589 in vbox for trunk/src/VBox/Frontends
- Timestamp:
- Nov 20, 2013 5:08:55 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/UIMediumEnumerator.cpp
r49557 r49589 70 70 /* Prepare Main event handlers: */ 71 71 connect(gVBoxEvents, SIGNAL(sigMachineDataChange(QString)), this, SLOT(sltHandleMachineUpdate(QString))); 72 connect(gVBoxEvents, SIGNAL(sigMachineRegistered(QString, bool)), this, SLOT(sltHandleMachineUpdate(QString)));73 72 connect(gVBoxEvents, SIGNAL(sigSnapshotChange(QString, QString)), this, SLOT(sltHandleMachineUpdate(QString))); 73 connect(gVBoxEvents, SIGNAL(sigMachineRegistered(QString, bool)), this, SLOT(sltHandleMachineRegistration(QString, bool))); 74 74 75 75 /* Prepare thread-pool: */ … … 170 170 void UIMediumEnumerator::sltHandleMachineUpdate(QString strMachineID) 171 171 { 172 LogRel(("UIMediumEnumerator: Machine event received, ID = %s\n", strMachineID.toAscii().constData())); 172 LogRel(("UIMediumEnumerator: Machine (or snapshot) event received, ID = %s\n", 173 strMachineID.toAscii().constData())); 173 174 174 175 /* Compose a map of previous usage: */ … … 192 193 { 193 194 CMedium cmedium = attachment.GetMedium(); 194 if (cmedium.isNull()) 195 continue; 196 QString strMediumID = cmedium.GetId(); 197 newMediumMap.insert(strMediumID, cmedium); 198 newUsage << strMediumID; 195 if (!cmedium.isNull()) 196 { 197 const QString &strMediumID = cmedium.GetId(); 198 newMediumMap.insert(strMediumID, cmedium); 199 newUsage << strMediumID; 200 } 199 201 } 200 202 } … … 214 216 215 217 /* For each of excluded items: */ 216 foreach (const QString &strExcludedMedium Key, excludedList)218 foreach (const QString &strExcludedMediumID, excludedList) 217 219 { 218 220 /* Make sure this medium still in our map: */ 219 if (!m_mediums.contains(strExcludedMedium Key))221 if (!m_mediums.contains(strExcludedMediumID)) 220 222 continue; 221 223 222 224 /* Get excluded UIMedium: */ 223 const UIMedium &uimedium = m_mediums[strExcludedMedium Key];225 const UIMedium &uimedium = m_mediums[strExcludedMediumID]; 224 226 225 227 /* Delete UIMedium if CMedium was closed already: */ … … 228 230 { 229 231 /* Delete this medium: */ 230 m_mediums.remove(strExcludedMedium Key);231 LogRel(("UIMediumEnumerator: Medium with key={%s} closed and deleted (before enumeration).\n", strExcludedMedium Key.toAscii().constData()));232 m_mediums.remove(strExcludedMediumID); 233 LogRel(("UIMediumEnumerator: Medium with key={%s} closed and deleted (before enumeration).\n", strExcludedMediumID.toAscii().constData())); 232 234 /* And notify listener about delete: */ 233 emit sigMediumDeleted(strExcludedMedium Key);235 emit sigMediumDeleted(strExcludedMediumID); 234 236 continue; 235 237 } 236 238 237 /* Enumerate UIMedium if CMedium still exists: */239 /* Enumerate UIMedium: */ 238 240 createMediumEnumerationTask(uimedium); 239 241 } … … 245 247 if (!m_mediums.contains(strIncludedMediumID)) 246 248 { 249 /* Insert medium: */ 247 250 const CMedium &cmedium = newMediumMap[strIncludedMediumID]; 248 251 UIMedium uimedium(cmedium, UIMediumDefs::mediumTypeToLocal(cmedium.GetDeviceType())); 249 createMedium(uimedium); 250 } 251 252 /* Enumerate UIMedium in any case: */ 252 m_mediums[strIncludedMediumID] = uimedium; 253 LogRel(("UIMediumEnumerator: Medium with key={%s} created and inserted.\n", strIncludedMediumID.toAscii().constData())); 254 /* And notify listener about creation: */ 255 emit sigMediumCreated(strIncludedMediumID); 256 } 257 258 /* Enumerate UIMedium: */ 253 259 createMediumEnumerationTask(m_mediums[strIncludedMediumID]); 254 260 } 255 261 256 LogRel(("UIMediumEnumerator: Machine event processed, ID = %s\n", strMachineID.toAscii().constData())); 262 LogRel(("UIMediumEnumerator: Machine (or snapshot) event processed, ID = %s\n", 263 strMachineID.toAscii().constData())); 264 } 265 266 void UIMediumEnumerator::sltHandleMachineRegistration(QString strMachineID, bool fRegistered) 267 { 268 LogRel(("UIMediumEnumerator: Machine %s event received, ID = %s\n", 269 fRegistered ? "registration" : "unregistration", 270 strMachineID.toAscii().constData())); 271 272 /* Was machine registered? */ 273 if (fRegistered) 274 { 275 /* Compose a map of current usage: */ 276 QStringList usage; 277 QMap<QString, CMedium> mediumMap; 278 CMachine machine = vboxGlobal().virtualBox().FindMachine(strMachineID); 279 if (!machine.isNull()) 280 { 281 foreach (const CMediumAttachment &attachment, machine.GetMediumAttachments()) 282 { 283 CMedium cmedium = attachment.GetMedium(); 284 if (!cmedium.isNull()) 285 { 286 const QString &strMediumID = cmedium.GetId(); 287 mediumMap.insert(strMediumID, cmedium); 288 usage << strMediumID; 289 } 290 } 291 } 292 LogRel(("UIMediumEnumerator: Usage: %s\n", usage.isEmpty() ? "<empty>" : usage.join(", ").toAscii().constData())); 293 294 /* For each of related items: */ 295 foreach (const QString &strMediumID, usage) 296 { 297 /* Create UIMedium if it is not in our map: */ 298 if (!m_mediums.contains(strMediumID)) 299 { 300 /* Insert medium: */ 301 const CMedium &cmedium = mediumMap[strMediumID]; 302 UIMedium uimedium(cmedium, UIMediumDefs::mediumTypeToLocal(cmedium.GetDeviceType())); 303 m_mediums[strMediumID] = uimedium; 304 LogRel(("UIMediumEnumerator: Medium with key={%s} created and inserted.\n", strMediumID.toAscii().constData())); 305 /* And notify listener about creation: */ 306 emit sigMediumCreated(strMediumID); 307 } 308 309 /* Enumerate UIMedium: */ 310 createMediumEnumerationTask(m_mediums[strMediumID]); 311 } 312 } 313 314 /* Was machine unregistered? */ 315 else 316 { 317 /* Compose a map of previous usage: */ 318 QStringList usage; 319 foreach (const QString &strMediumID, mediumIDs()) 320 { 321 const UIMedium &uimedium = m_mediums[strMediumID]; 322 const QList<QString> &machineIDs = uimedium.machineIds(); 323 if (machineIDs.contains(strMachineID)) 324 usage << strMediumID; 325 } 326 LogRel(("UIMediumEnumerator: Usage: %s\n", usage.isEmpty() ? "<empty>" : usage.join(", ").toAscii().constData())); 327 328 /* For each of related items: */ 329 foreach (const QString &strMediumID, usage) 330 { 331 /* Make sure this medium still in our map: */ 332 if (!m_mediums.contains(strMediumID)) 333 continue; 334 335 /* Get excluded UIMedium: */ 336 const UIMedium &uimedium = m_mediums[strMediumID]; 337 338 /* Delete UIMedium if CMedium was closed already: */ 339 CMedium cmedium = uimedium.medium(); 340 if (cmedium.GetId().isNull() || !cmedium.isOk()) 341 { 342 /* Delete this medium: */ 343 m_mediums.remove(strMediumID); 344 LogRel(("UIMediumEnumerator: Medium with key={%s} closed and deleted (before enumeration).\n", strMediumID.toAscii().constData())); 345 /* And notify listener about delete: */ 346 emit sigMediumDeleted(strMediumID); 347 continue; 348 } 349 350 /* Enumerate UIMedium: */ 351 createMediumEnumerationTask(uimedium); 352 } 353 } 354 355 LogRel(("UIMediumEnumerator: Machine %s event processed, ID = %s\n", 356 fRegistered ? "registration" : "unregistration", 357 strMachineID.toAscii().constData())); 257 358 } 258 359 -
trunk/src/VBox/Frontends/VirtualBox/src/medium/UIMediumEnumerator.h
r49553 r49589 63 63 private slots: 64 64 65 /* Handler: Machine stuff:*/65 /** Handles machine-data-change and snapshot-change events. */ 66 66 void sltHandleMachineUpdate(QString strMachineID); 67 /** Handles machine-[un]registration events. */ 68 void sltHandleMachineRegistration(QString strMachineID, bool fRegistered); 67 69 68 70 /* Handler: Medium-enumeration stuff: */
Note:
See TracChangeset
for help on using the changeset viewer.