Changeset 90757 in vbox
- Timestamp:
- Aug 20, 2021 9:27:57 AM (3 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Frontends/VirtualBox/src/wizards/newvm/UIWizardNewVM.cpp
r90714 r90757 22 22 /* GUI includes: */ 23 23 #include "UICommon.h" 24 #include "UIProgressObject.h" 24 25 #include "UIWizardNewVM.h" 25 26 #include "UIWizardNewVMNameOSTypePageBasic.h" … … 174 175 bool UIWizardNewVM::createVirtualDisk() 175 176 { 177 /* Prepare result: */ 178 bool fResult = false; 179 176 180 /* Check attributes: */ 177 181 AssertReturn(!m_strMediumPath.isNull(), false); 178 182 AssertReturn(m_uMediumSize > 0, false); 179 183 180 CVirtualBox vbox = uiCommon().virtualBox(); 184 /* Acquire VBox: */ 185 CVirtualBox comVBox = uiCommon().virtualBox(); 181 186 182 187 /* Create new virtual hard-disk: */ 183 CMedium newVirtualDisk = vbox.CreateMedium(m_comMediumFormat.GetName(), m_strMediumPath, KAccessMode_ReadWrite, KDeviceType_HardDisk);184 if (! vbox.isOk())185 { 186 msgCenter().cannotCreateHardDiskStorage( vbox, m_strMediumPath, this);187 return f alse;188 CMedium newVirtualDisk = comVBox.CreateMedium(m_comMediumFormat.GetName(), m_strMediumPath, KAccessMode_ReadWrite, KDeviceType_HardDisk); 189 if (!comVBox.isOk()) 190 { 191 msgCenter().cannotCreateHardDiskStorage(comVBox, m_strMediumPath, this); 192 return fResult; 188 193 } 189 194 … … 198 203 199 204 /* Create base storage for the new virtual-disk: */ 200 CProgress progress = newVirtualDisk.CreateBaseStorage(m_uMediumSize, variants);205 CProgress comProgress = newVirtualDisk.CreateBaseStorage(m_uMediumSize, variants); 201 206 if (!newVirtualDisk.isOk()) 202 {203 207 msgCenter().cannotCreateHardDiskStorage(newVirtualDisk, m_strMediumPath, this); 204 return false; 205 } 206 207 /* Show creation progress: */ 208 msgCenter().showModalProgressDialog(progress, windowTitle(), ":/progress_media_create_90px.png", this); 209 if (progress.GetCanceled()) 210 return false; 211 if (!progress.isOk() || progress.GetResultCode() != 0) 212 { 213 msgCenter().cannotCreateHardDiskStorage(progress, m_strMediumPath, this); 214 return false; 215 } 216 217 /* Inform UICommon about it: */ 218 uiCommon().createMedium(UIMedium(newVirtualDisk, UIMediumDeviceType_HardDisk, KMediumState_Created)); 219 220 /* Remember created virtual-disk: */ 221 m_virtualDisk = newVirtualDisk; 222 223 return true; 208 else 209 { 210 /* Make sure progress initially valid: */ 211 if (!comProgress.isNull() && !comProgress.GetCompleted()) 212 { 213 /* Create take snapshot progress object: */ 214 QPointer<UIProgressObject> pObject = new UIProgressObject(comProgress, this); 215 if (pObject) 216 { 217 connect(pObject.data(), &UIProgressObject::sigProgressChange, 218 this, &UIWizardNewVM::sltHandleProgressChange); 219 connect(pObject.data(), &UIProgressObject::sigProgressComplete, 220 this, &UIWizardNewVM::sltHandleProgressFinished); 221 sltHandleProgressStarted(); 222 pObject->exec(); 223 if (pObject) 224 delete pObject; 225 else 226 { 227 // Premature application shutdown, 228 // exit immediately: 229 return fResult; 230 } 231 } 232 } 233 234 /* Check for progress errors: */ 235 if (!comProgress.isOk() || comProgress.GetResultCode() != 0) 236 msgCenter().cannotCreateHardDiskStorage(comProgress, m_strMediumPath, this); 237 else 238 { 239 /* Inform UICommon about it: */ 240 uiCommon().createMedium(UIMedium(newVirtualDisk, UIMediumDeviceType_HardDisk, KMediumState_Created)); 241 242 /* Remember created virtual-disk: */ 243 m_virtualDisk = newVirtualDisk; 244 245 /* True finally: */ 246 fResult = true; 247 } 248 } 249 250 /* Return result: */ 251 return fResult; 224 252 } 225 253 … … 232 260 /* Remember virtual-disk attributes: */ 233 261 QString strLocation = m_virtualDisk.GetLocation(); 234 /* Prepare delete storage progress: */ 235 CProgress progress = m_virtualDisk.DeleteStorage(); 236 if (m_virtualDisk.isOk()) 237 { 238 /* Show delete storage progress: */ 239 msgCenter().showModalProgressDialog(progress, windowTitle(), ":/progress_media_delete_90px.png", this); 240 if (!progress.isOk() || progress.GetResultCode() != 0) 241 msgCenter().cannotDeleteHardDiskStorage(progress, strLocation, this); 242 } 262 if (!m_virtualDisk.isOk()) 263 { 264 msgCenter().cannotAcquireMediumAttribute(m_virtualDisk, this); 265 return; 266 } 267 268 /* Delete storage of existing disk: */ 269 CProgress comProgress = m_virtualDisk.DeleteStorage(); 270 if (!m_virtualDisk.isOk()) 271 msgCenter().cannotDeleteHardDiskStorage(m_virtualDisk, strLocation, this); 243 272 else 244 msgCenter().cannotDeleteHardDiskStorage(m_virtualDisk, strLocation, this); 245 246 /* Detach virtual-disk anyway: */ 247 m_virtualDisk.detach(); 273 { 274 /* Make sure progress initially valid: */ 275 if (!comProgress.isNull() && !comProgress.GetCompleted()) 276 { 277 /* Create take snapshot progress object: */ 278 QPointer<UIProgressObject> pObject = new UIProgressObject(comProgress, this); 279 if (pObject) 280 { 281 connect(pObject.data(), &UIProgressObject::sigProgressChange, 282 this, &UIWizardNewVM::sltHandleProgressChange); 283 connect(pObject.data(), &UIProgressObject::sigProgressComplete, 284 this, &UIWizardNewVM::sltHandleProgressFinished); 285 sltHandleProgressStarted(); 286 pObject->exec(); 287 if (pObject) 288 delete pObject; 289 else 290 { 291 // Premature application shutdown, 292 // exit immediately: 293 return; 294 } 295 } 296 } 297 298 /* Check for progress errors: */ 299 if (!comProgress.isOk() || comProgress.GetResultCode() != 0) 300 msgCenter().cannotDeleteHardDiskStorage(comProgress, strLocation, this); 301 else 302 { 303 /* Detach virtual-disk anyway: */ 304 m_virtualDisk.detach(); 305 } 306 } 248 307 } 249 308
Note:
See TracChangeset
for help on using the changeset viewer.