Changeset 43913 in vbox for trunk/src/VBox/Frontends/VirtualBox
- Timestamp:
- Nov 19, 2012 3:00:28 PM (12 years ago)
- svn:sync-xref-src-repo-rev:
- 82186
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Frontends/VirtualBox/src/runtime/UIMachineWindow.cpp
r41819 r43913 283 283 CMachine m = machine(); 284 284 285 /* Check if there is a close ho ck script defined. */285 /* Check if there is a close hook script defined. */ 286 286 const QString& strScript = m.GetExtraData(GUI_CloseActionHook); 287 287 if (!strScript.isEmpty()) … … 292 292 293 293 /* Prepare close-dialog: */ 294 UIVMCloseDialog dlg(this);294 UIVMCloseDialog *pDlg = new UIVMCloseDialog(this); 295 295 296 296 /* Assign close-dialog pixmap: */ 297 dlg.pmIcon->setPixmap(vboxGlobal().vmGuestOSTypeIcon(m.GetOSTypeId()));297 pDlg->pmIcon->setPixmap(vboxGlobal().vmGuestOSTypeIcon(m.GetOSTypeId())); 298 298 299 299 /* Check which close actions are disallowed: */ … … 305 305 306 306 /* Make Save State button visible/hidden depending on restriction: */ 307 dlg.mRbSave->setVisible(fIsStateSavingAllowed);308 dlg.mTxSave->setVisible(fIsStateSavingAllowed);307 pDlg->mRbSave->setVisible(fIsStateSavingAllowed); 308 pDlg->mTxSave->setVisible(fIsStateSavingAllowed); 309 309 /* Make Save State button enabled/disabled depending on machine state: */ 310 dlg.mRbSave->setEnabled(uisession()->machineState() != KMachineState_Stuck);310 pDlg->mRbSave->setEnabled(uisession()->machineState() != KMachineState_Stuck); 311 311 312 312 /* Make ACPI shutdown button visible/hidden depending on restriction: */ 313 dlg.mRbShutdown->setVisible(fIsACPIShutdownAllowed);314 dlg.mTxShutdown->setVisible(fIsACPIShutdownAllowed);313 pDlg->mRbShutdown->setVisible(fIsACPIShutdownAllowed); 314 pDlg->mTxShutdown->setVisible(fIsACPIShutdownAllowed); 315 315 /* Make ACPI shutdown button enabled/disabled depending on ACPI state & machine state: */ 316 316 bool isACPIEnabled = session().GetConsole().GetGuestEnteredACPIMode(); 317 dlg.mRbShutdown->setEnabled(isACPIEnabled && uisession()->machineState() != KMachineState_Stuck);317 pDlg->mRbShutdown->setEnabled(isACPIEnabled && uisession()->machineState() != KMachineState_Stuck); 318 318 319 319 /* Make Power Off button visible/hidden depending on restriction: */ 320 dlg.mRbPowerOff->setVisible(fIsPowerOffAllowed);321 dlg.mTxPowerOff->setVisible(fIsPowerOffAllowed);320 pDlg->mRbPowerOff->setVisible(fIsPowerOffAllowed); 321 pDlg->mTxPowerOff->setVisible(fIsPowerOffAllowed); 322 322 323 323 /* Make the Restore Snapshot checkbox visible/hidden depending on snapshots count & restrictions: */ 324 dlg.mCbDiscardCurState->setVisible(fIsPowerOffAndRestoreAllowed && m.GetSnapshotCount() > 0);324 pDlg->mCbDiscardCurState->setVisible(fIsPowerOffAndRestoreAllowed && m.GetSnapshotCount() > 0); 325 325 if (!m.GetCurrentSnapshot().isNull()) 326 dlg.mCbDiscardCurState->setText(dlg.mCbDiscardCurState->text().arg(m.GetCurrentSnapshot().GetName()));326 pDlg->mCbDiscardCurState->setText(pDlg->mCbDiscardCurState->text().arg(m.GetCurrentSnapshot().GetName())); 327 327 328 328 /* Choice string tags for close-dialog: */ … … 341 341 if (lastAction[0] == strSave && fIsStateSavingAllowed) 342 342 { 343 pRadioButton = dlg.mRbSave;343 pRadioButton = pDlg->mRbSave; 344 344 } 345 345 else if (lastAction[0] == strShutdown && fIsACPIShutdownAllowed && isACPIEnabled) 346 346 { 347 pRadioButton = dlg.mRbShutdown;347 pRadioButton = pDlg->mRbShutdown; 348 348 } 349 349 else if (lastAction[0] == strPowerOff && fIsPowerOffAllowed) 350 350 { 351 pRadioButton = dlg.mRbPowerOff;351 pRadioButton = pDlg->mRbPowerOff; 352 352 if (fIsPowerOffAndRestoreAllowed) 353 dlg.mCbDiscardCurState->setChecked(lastAction.count() > 1 && lastAction[1] == strDiscardCurState);353 pDlg->mCbDiscardCurState->setChecked(lastAction.count() > 1 && lastAction[1] == strDiscardCurState); 354 354 } 355 355 /* Else 'default choice' will be used: */ … … 357 357 { 358 358 if (fIsACPIShutdownAllowed && isACPIEnabled) 359 pRadioButton = dlg.mRbShutdown;359 pRadioButton = pDlg->mRbShutdown; 360 360 else if (fIsPowerOffAllowed) 361 pRadioButton = dlg.mRbPowerOff;361 pRadioButton = pDlg->mRbPowerOff; 362 362 else if (fIsStateSavingAllowed) 363 pRadioButton = dlg.mRbSave;363 pRadioButton = pDlg->mRbSave; 364 364 } 365 365 … … 375 375 { 376 376 /* Just break and leave: */ 377 delete pDlg; 378 pDlg = 0; 377 379 break; 378 380 } … … 391 393 machineLogic()->setPreventAutoClose(true); 392 394 393 /* If close-dialog accepted: */ 394 if (dlg.exec() == QDialog::Accepted) 395 /* Show the close-dialog: */ 396 bool fDialogAccepted = pDlg->exec() == QDialog::Accepted; 397 398 /* What was the decision? */ 399 enum DialogDecision { DD_Cancel, DD_Save, DD_Shutdown, DD_PowerOff }; 400 DialogDecision decision; 401 if (!fDialogAccepted) 402 decision = DD_Cancel; 403 else if (pDlg->mRbSave->isChecked()) 404 decision = DD_Save; 405 else if (pDlg->mRbShutdown->isChecked()) 406 decision = DD_Shutdown; 407 else 408 decision = DD_PowerOff; 409 bool fDiscardCurState = pDlg->mCbDiscardCurState->isChecked(); 410 bool fDiscardCheckboxVisible = pDlg->mCbDiscardCurState->isVisibleTo(pDlg); 411 412 /* Destroy the dialog early: */ 413 delete pDlg; 414 pDlg = 0; 415 416 /* Was dialog accepted? */ 417 if (fDialogAccepted) 395 418 { 396 /* Get current console: */419 /* Process decision: */ 397 420 CConsole console = session().GetConsole(); 398 399 421 fSuccess = false; 400 401 if (dlg.mRbSave->isChecked()) 422 switch (decision) 402 423 { 403 CProgress progress = console.SaveState(); 404 405 if (!console.isOk()) 406 msgCenter().cannotSaveMachineState(console); 407 else 424 case DD_Save: 408 425 { 409 /* Show the "VM saving" progress dialog: */ 410 msgCenter().showModalProgressDialog(progress, m.GetName(), ":/progress_state_save_90px.png", 0, true); 411 if (progress.GetResultCode() != 0) 412 msgCenter().cannotSaveMachineState(progress); 426 /* Prepare the saving progress: */ 427 CProgress progress = console.SaveState(); 428 if (console.isOk()) 429 { 430 /* Show the saving progress dialog: */ 431 msgCenter().showModalProgressDialog(progress, m.GetName(), ":/progress_state_save_90px.png", 0, true); 432 if (progress.GetResultCode() == 0) 433 fSuccess = true; 434 else 435 msgCenter().cannotSaveMachineState(progress); 436 } 413 437 else 438 msgCenter().cannotSaveMachineState(console); 439 if (fSuccess) 440 fCloseApplication = true; 441 break; 442 } 443 case DD_Shutdown: 444 { 445 /* Unpause the VM to let it grab the ACPI shutdown event: */ 446 uisession()->unpause(); 447 /* Prevent the subsequent unpause request: */ 448 fWasPaused = true; 449 /* Signal ACPI shutdown (if there is no ACPI device, the operation will fail): */ 450 console.PowerButton(); 451 if (console.isOk()) 414 452 fSuccess = true; 453 else 454 msgCenter().cannotACPIShutdownMachine(console); 455 break; 415 456 } 416 417 if (fSuccess) 418 fCloseApplication = true; 419 } 420 else if (dlg.mRbShutdown->isChecked()) 421 { 422 /* Unpause the VM to let it grab the ACPI shutdown event: */ 423 uisession()->unpause(); 424 /* Prevent the subsequent unpause request: */ 425 fWasPaused = true; 426 /* Signal ACPI shutdown (if there is no ACPI device, the operation will fail): */ 427 console.PowerButton(); 428 if (!console.isOk()) 429 msgCenter().cannotACPIShutdownMachine(console); 430 else 431 fSuccess = true; 432 } 433 else if (dlg.mRbPowerOff->isChecked()) 434 { 435 CProgress progress = console.PowerDown(); 436 437 if (!console.isOk()) 438 msgCenter().cannotStopMachine(console); 439 else 457 case DD_PowerOff: 440 458 { 441 /* Show the power down progress dialog: */ 442 msgCenter().showModalProgressDialog(progress, m.GetName(), ":/progress_poweroff_90px.png", 0, true); 443 if (progress.GetResultCode() != 0) 444 msgCenter().cannotStopMachine(progress); 459 /* Prepare the power down progress: */ 460 CProgress progress = console.PowerDown(); 461 if (console.isOk()) 462 { 463 /* Show the power down progress: */ 464 msgCenter().showModalProgressDialog(progress, m.GetName(), ":/progress_poweroff_90px.png", 0, true); 465 if (progress.GetResultCode() == 0) 466 fSuccess = true; 467 else 468 msgCenter().cannotStopMachine(progress); 469 } 445 470 else 446 fSuccess = true; 447 } 448 449 if (fSuccess) 450 { 451 /* Discard the current state if requested: */ 452 if (dlg.mCbDiscardCurState->isChecked() && dlg.mCbDiscardCurState->isVisibleTo(&dlg)) 471 msgCenter().cannotStopMachine(console); 472 if (fSuccess) 453 473 { 454 CSnapshot snapshot = m.GetCurrentSnapshot(); 455 CProgress progress = console.RestoreSnapshot(snapshot); 456 if (!console.isOk()) 457 msgCenter().cannotRestoreSnapshot(console, snapshot.GetName()); 458 else 474 /* Discard the current state if requested: */ 475 if (fDiscardCurState && fDiscardCheckboxVisible) 459 476 { 460 /* Show the progress dialog: */ 461 msgCenter().showModalProgressDialog(progress, m.GetName(), ":/progress_snapshot_discard_90px.png", 0, true); 462 if (progress.GetResultCode() != 0) 463 msgCenter().cannotRestoreSnapshot(progress, snapshot.GetName()); 477 /* Prepare the snapshot discard progress: */ 478 CSnapshot snapshot = m.GetCurrentSnapshot(); 479 CProgress progress = console.RestoreSnapshot(snapshot); 480 if (console.isOk()) 481 { 482 /* Show the snapshot discard progress: */ 483 msgCenter().showModalProgressDialog(progress, m.GetName(), ":/progress_snapshot_discard_90px.png", 0, true); 484 if (progress.GetResultCode() != 0) 485 msgCenter().cannotRestoreSnapshot(progress, snapshot.GetName()); 486 } 487 else 488 msgCenter().cannotRestoreSnapshot(console, snapshot.GetName()); 464 489 } 465 490 } 491 if (fSuccess) 492 fCloseApplication = true; 493 break; 466 494 } 467 468 if (fSuccess) 469 fCloseApplication = true; 495 default: 496 break; 470 497 } 471 498 … … 476 503 /* Memorize the last user's choice for the given VM: */ 477 504 QString lastAction = strPowerOff; 478 if (dlg.mRbSave->isChecked()) 479 lastAction = strSave; 480 else if ((dlg.mRbShutdown->isChecked()) || 481 (dlg.mRbPowerOff->isChecked() && prevAction[0] == strShutdown && !isACPIEnabled)) 482 lastAction = strShutdown; 483 else if (dlg.mRbPowerOff->isChecked()) 484 lastAction = strPowerOff; 485 else 486 AssertFailed(); 487 if (dlg.mCbDiscardCurState->isChecked()) 505 switch (decision) 506 { 507 case DD_Save: lastAction = strSave; break; 508 case DD_Shutdown: lastAction = strShutdown; break; 509 case DD_PowerOff: 510 { 511 if (prevAction[0] == strShutdown && !isACPIEnabled) 512 lastAction = strShutdown; 513 else 514 lastAction = strPowerOff; 515 break; 516 } 517 default: break; 518 } 519 /* Memorize additional options for the given VM: */ 520 if (fDiscardCurState) 488 521 (lastAction += ",") += strDiscardCurState; 489 522 m.SetExtraData(GUI_LastCloseAction, lastAction);
Note:
See TracChangeset
for help on using the changeset viewer.