VirtualBox

Ignore:
Timestamp:
Nov 19, 2012 3:00:28 PM (12 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
82186
Message:

FE/Qt: Close-dialog handling cleanup/rework.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Frontends/VirtualBox/src/runtime/UIMachineWindow.cpp

    r41819 r43913  
    283283            CMachine m = machine();
    284284
    285             /* Check if there is a close hock script defined. */
     285            /* Check if there is a close hook script defined. */
    286286            const QString& strScript = m.GetExtraData(GUI_CloseActionHook);
    287287            if (!strScript.isEmpty())
     
    292292
    293293            /* Prepare close-dialog: */
    294             UIVMCloseDialog dlg(this);
     294            UIVMCloseDialog *pDlg = new UIVMCloseDialog(this);
    295295
    296296            /* Assign close-dialog pixmap: */
    297             dlg.pmIcon->setPixmap(vboxGlobal().vmGuestOSTypeIcon(m.GetOSTypeId()));
     297            pDlg->pmIcon->setPixmap(vboxGlobal().vmGuestOSTypeIcon(m.GetOSTypeId()));
    298298
    299299            /* Check which close actions are disallowed: */
     
    305305
    306306            /* 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);
    309309            /* 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);
    311311
    312312            /* 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);
    315315            /* Make ACPI shutdown button enabled/disabled depending on ACPI state & machine state: */
    316316            bool isACPIEnabled = session().GetConsole().GetGuestEnteredACPIMode();
    317             dlg.mRbShutdown->setEnabled(isACPIEnabled && uisession()->machineState() != KMachineState_Stuck);
     317            pDlg->mRbShutdown->setEnabled(isACPIEnabled && uisession()->machineState() != KMachineState_Stuck);
    318318
    319319            /* 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);
    322322
    323323            /* 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);
    325325            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()));
    327327
    328328            /* Choice string tags for close-dialog: */
     
    341341            if (lastAction[0] == strSave && fIsStateSavingAllowed)
    342342            {
    343                 pRadioButton = dlg.mRbSave;
     343                pRadioButton = pDlg->mRbSave;
    344344            }
    345345            else if (lastAction[0] == strShutdown && fIsACPIShutdownAllowed && isACPIEnabled)
    346346            {
    347                 pRadioButton = dlg.mRbShutdown;
     347                pRadioButton = pDlg->mRbShutdown;
    348348            }
    349349            else if (lastAction[0] == strPowerOff && fIsPowerOffAllowed)
    350350            {
    351                 pRadioButton = dlg.mRbPowerOff;
     351                pRadioButton = pDlg->mRbPowerOff;
    352352                if (fIsPowerOffAndRestoreAllowed)
    353                     dlg.mCbDiscardCurState->setChecked(lastAction.count() > 1 && lastAction[1] == strDiscardCurState);
     353                    pDlg->mCbDiscardCurState->setChecked(lastAction.count() > 1 && lastAction[1] == strDiscardCurState);
    354354            }
    355355            /* Else 'default choice' will be used: */
     
    357357            {
    358358                if (fIsACPIShutdownAllowed && isACPIEnabled)
    359                     pRadioButton = dlg.mRbShutdown;
     359                    pRadioButton = pDlg->mRbShutdown;
    360360                else if (fIsPowerOffAllowed)
    361                     pRadioButton = dlg.mRbPowerOff;
     361                    pRadioButton = pDlg->mRbPowerOff;
    362362                else if (fIsStateSavingAllowed)
    363                     pRadioButton = dlg.mRbSave;
     363                    pRadioButton = pDlg->mRbSave;
    364364            }
    365365
     
    375375            {
    376376                /* Just break and leave: */
     377                delete pDlg;
     378                pDlg = 0;
    377379                break;
    378380            }
     
    391393                machineLogic()->setPreventAutoClose(true);
    392394
    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)
    395418                {
    396                     /* Get current console: */
     419                    /* Process decision: */
    397420                    CConsole console = session().GetConsole();
    398 
    399421                    fSuccess = false;
    400 
    401                     if (dlg.mRbSave->isChecked())
     422                    switch (decision)
    402423                    {
    403                         CProgress progress = console.SaveState();
    404 
    405                         if (!console.isOk())
    406                             msgCenter().cannotSaveMachineState(console);
    407                         else
     424                        case DD_Save:
    408425                        {
    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                            }
    413437                            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())
    414452                                fSuccess = true;
     453                            else
     454                                msgCenter().cannotACPIShutdownMachine(console);
     455                            break;
    415456                        }
    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:
    440458                        {
    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                            }
    445470                            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)
    453473                            {
    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)
    459476                                {
    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());
    464489                                }
    465490                            }
     491                            if (fSuccess)
     492                                fCloseApplication = true;
     493                            break;
    466494                        }
    467 
    468                         if (fSuccess)
    469                             fCloseApplication = true;
     495                        default:
     496                            break;
    470497                    }
    471498
     
    476503                        /* Memorize the last user's choice for the given VM: */
    477504                        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)
    488521                            (lastAction += ",") += strDiscardCurState;
    489522                        m.SetExtraData(GUI_LastCloseAction, lastAction);
Note: See TracChangeset for help on using the changeset viewer.

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette