- Timestamp:
- Apr 24, 2019 1:17:15 PM (6 years ago)
- Location:
- trunk/src/VBox/Frontends/VirtualBox/src/wizards/newvm
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Frontends/VirtualBox/src/wizards/newvm/UIWizardNewVM.cpp
r78268 r78271 120 120 } 121 121 122 return configureVM(strTypeId, type); 122 if (configureVM(strTypeId, type)) 123 return attachDefaultDevices(type); 124 return false; 123 125 } 124 126 … … 268 270 return false; 269 271 } 270 271 /* Attach default devices: */ 272 { 273 bool success = false; 274 QUuid uMachineId = m_machine.GetId(); 275 CSession session = vboxGlobal().openSession(uMachineId); 276 if (!session.isNull()) 277 { 278 CMachine machine = session.GetMachine(); 279 280 QUuid uId = field("virtualDiskId").toUuid(); 281 /* Boot virtual hard drive: */ 282 if (!uId.isNull()) 272 return true; 273 } 274 275 bool UIWizardNewVM::attachDefaultDevices(const CGuestOSType &comGuestType) 276 { 277 bool success = false; 278 QUuid uMachineId = m_machine.GetId(); 279 CSession session = vboxGlobal().openSession(uMachineId); 280 if (!session.isNull()) 281 { 282 CMachine machine = session.GetMachine(); 283 284 QUuid uId = field("virtualDiskId").toUuid(); 285 /* Boot virtual hard drive: */ 286 if (!uId.isNull()) 287 { 288 KStorageBus enmHDDBus = comGuestType.GetRecommendedHDStorageBus(); 289 CStorageController comHDDController = m_machine.GetStorageControllerByInstance(enmHDDBus, 0); 290 if (!comHDDController.isNull()) 283 291 { 284 292 UIMedium vmedium = vboxGlobal().medium(uId); 285 293 CMedium medium = vmedium.medium(); /// @todo r=dj can this be cached somewhere? 286 machine.AttachDevice( strHDName, 0, 0, KDeviceType_HardDisk, medium);294 machine.AttachDevice(comHDDController.GetName(), 0, 0, KDeviceType_HardDisk, medium); 287 295 if (!machine.isOk()) 288 296 msgCenter().cannotAttachDevice(machine, UIMediumDeviceType_HardDisk, field("virtualDiskLocation").toString(), 289 StorageSlot( ctrHDBus, 0, 0), this);297 StorageSlot(enmHDDBus, 0, 0), this); 290 298 } 291 292 /* Attach empty optical drive: */ 293 machine.AttachDevice(strDVDName, 1, 0, KDeviceType_DVD, CMedium()); 299 } 300 301 /* Attach empty optical drive: */ 302 KStorageBus enmDVDBus = comGuestType.GetRecommendedDVDStorageBus(); 303 CStorageController comDVDController = m_machine.GetStorageControllerByInstance(enmDVDBus, 0); 304 if (!comDVDController.isNull()) 305 { 306 machine.AttachDevice(comDVDController.GetName(), 1, 0, KDeviceType_DVD, CMedium()); 294 307 if (!machine.isOk()) 295 msgCenter().cannotAttachDevice(machine, UIMediumDeviceType_DVD, QString(), StorageSlot(strDVDBus, 1, 0), this); 296 297 298 /* Attach an empty floppy drive if recommended */ 299 if (comGuestType.GetRecommendedFloppy()) { 300 machine.AttachDevice(strFloppyName, 0, 0, KDeviceType_Floppy, CMedium()); 308 msgCenter().cannotAttachDevice(machine, UIMediumDeviceType_DVD, QString(), 309 StorageSlot(enmDVDBus, 1, 0), this); 310 311 } 312 313 /* Attach an empty floppy drive if recommended */ 314 if (comGuestType.GetRecommendedFloppy()) { 315 CStorageController comFloppyController = m_machine.GetStorageControllerByInstance(KStorageBus_Floppy, 0); 316 if (!comFloppyController.isNull()) 317 { 318 machine.AttachDevice(comFloppyController.GetName(), 0, 0, KDeviceType_Floppy, CMedium()); 301 319 if (!machine.isOk()) 302 320 msgCenter().cannotAttachDevice(machine, UIMediumDeviceType_Floppy, QString(), 303 321 StorageSlot(KStorageBus_Floppy, 0, 0), this); 304 322 } 305 323 } 324 325 if (machine.isOk()) 326 { 327 machine.SaveSettings(); 306 328 if (machine.isOk()) 307 { 308 machine.SaveSettings(); 309 if (machine.isOk()) 310 success = true; 311 else 312 msgCenter().cannotSaveMachineSettings(machine, this); 313 } 314 315 session.UnlockMachine(); 316 } 317 if (!success) 318 { 319 /* Unregister on failure */ 320 QVector<CMedium> aMedia = m_machine.Unregister(KCleanupMode_UnregisterOnly); /// @todo replace with DetachAllReturnHardDisksOnly once a progress dialog is in place below 321 if (vbox.isOk()) 322 { 323 CProgress progress = m_machine.DeleteConfig(aMedia); 324 progress.WaitForCompletion(-1); /// @todo do this nicely with a progress dialog, this can delete lots of files 325 } 326 return false; 327 } 329 success = true; 330 else 331 msgCenter().cannotSaveMachineSettings(machine, this); 332 } 333 334 session.UnlockMachine(); 335 } 336 if (!success) 337 { 338 CVirtualBox vbox = vboxGlobal().virtualBox(); 339 /* Unregister on failure */ 340 QVector<CMedium> aMedia = m_machine.Unregister(KCleanupMode_UnregisterOnly); /// @todo replace with DetachAllReturnHardDisksOnly once a progress dialog is in place below 341 if (vbox.isOk()) 342 { 343 CProgress progress = m_machine.DeleteConfig(aMedia); 344 progress.WaitForCompletion(-1); /// @todo do this nicely with a progress dialog, this can delete lots of files 345 } 346 return false; 328 347 } 329 348 -
trunk/src/VBox/Frontends/VirtualBox/src/wizards/newvm/UIWizardNewVM.h
r78268 r78271 61 61 protected: 62 62 63 /* Create a new VM: */63 /* Creates a new VM: */ 64 64 bool createVM(); 65 /* Configure the newly created VM: */65 /* Configures the newly created VM: */ 66 66 bool configureVM(const QString &strGuestTypeId, const CGuestOSType &comGuestType); 67 /* Attaches default devices: */ 68 bool attachDefaultDevices(const CGuestOSType &comGuestType); 67 69 68 70 /* Who will be able to create virtual-machine: */
Note:
See TracChangeset
for help on using the changeset viewer.