VirtualBox

Changeset 46704 in vbox for trunk/src


Ignore:
Timestamp:
Jun 20, 2013 12:04:30 PM (12 years ago)
Author:
vboxsync
Message:

FE/Qt: Runtime UI: CloseVM dialog and close-event processing: Reusing UI converter tags in extra-data handling.

Location:
trunk/src/VBox/Frontends/VirtualBox/src/runtime
Files:
3 edited

Legend:

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

    r46703 r46704  
    268268    {
    269269        /* Parse the close-action which was defined: */
    270         closeAction = UIVMCloseDialog::parseResultCode(strDefaultAction);
     270        closeAction = gpConverter->fromInternalString<MachineCloseAction>(strDefaultAction);
    271271        /* If VM is stuck, and the default close-action is not 'power-off',
    272272         * we should ask the user about what to do: */
  • trunk/src/VBox/Frontends/VirtualBox/src/runtime/UIVMCloseDialog.cpp

    r46703 r46704  
    3636# include "VBoxGlobal.h"
    3737# include "QIDialogButtonBox.h"
     38# include "UIConverter.h"
    3839
    3940/* COM includes: */
     
    4647UIVMCloseDialog::UIVMCloseDialog(QWidget *pParent, const CMachine &machine, const CSession &session)
    4748    : QIWithRetranslateUI<QIDialog>(pParent)
    48     , m_strExtraDataOptionSave("save")
    49     , m_strExtraDataOptionShutdown("shutdown")
    50     , m_strExtraDataOptionPowerOff("powerOff")
    51     , m_strExtraDataOptionDiscard("discardCurState")
    5249    , m_fValid(false)
    5350    , m_fIsACPIEnabled(false)
     51    , m_lastCloseAction(MachineCloseAction_Invalid)
    5452{
    5553    /* Prepare: */
     
    6260    /* Retranslate finally: */
    6361    retranslateUi();
    64 }
    65 
    66 /* static */
    67 MachineCloseAction UIVMCloseDialog::parseResultCode(const QString &strCloseAction)
    68 {
    69     MachineCloseAction closeAction = MachineCloseAction_Invalid;
    70     if (!strCloseAction.compare("Save", Qt::CaseInsensitive))
    71         closeAction = MachineCloseAction_Save;
    72     else if (!strCloseAction.compare("Shutdown", Qt::CaseInsensitive))
    73         closeAction = MachineCloseAction_Shutdown;
    74     else if (!strCloseAction.compare("PowerOff", Qt::CaseInsensitive))
    75         closeAction = MachineCloseAction_PowerOff;
    76     return closeAction;
    7762}
    7863
     
    9883    }
    9984
    100     /* Read the last user's choice for the given VM: */
    101     QStringList previousChoice = m_machine.GetExtraData(GUI_LastCloseAction).split(',');
    10285    /* Memorize the last user's choice for the given VM: */
    103     QString strLastAction = m_strExtraDataOptionPowerOff;
    104     switch (result())
    105     {
    106         case MachineCloseAction_Save:
    107         {
    108             strLastAction = m_strExtraDataOptionSave;
    109             break;
    110         }
    111         case MachineCloseAction_Shutdown:
    112         {
    113             strLastAction = m_strExtraDataOptionShutdown;
    114             break;
    115         }
    116         case MachineCloseAction_PowerOff:
    117         {
    118             if (previousChoice[0] == m_strExtraDataOptionShutdown && !m_fIsACPIEnabled)
    119                 strLastAction = m_strExtraDataOptionShutdown;
    120             else
    121                 strLastAction = m_strExtraDataOptionPowerOff;
    122             break;
    123         }
    124         case MachineCloseAction_PowerOff_RestoringSnapshot:
    125         {
    126             strLastAction = m_strExtraDataOptionPowerOff + "," +
    127                             m_strExtraDataOptionDiscard;
    128         }
    129         default: break;
    130     }
    131     m_machine.SetExtraData(GUI_LastCloseAction, strLastAction);
     86    MachineCloseAction newCloseAction = static_cast<MachineCloseAction>(result());
     87    /* But make sure 'Shutdown' is preserved if temporary unavailable: */
     88    if (newCloseAction == MachineCloseAction_PowerOff &&
     89        m_lastCloseAction == MachineCloseAction_Shutdown && !m_fIsACPIEnabled)
     90        newCloseAction = MachineCloseAction_Shutdown;
     91    m_machine.SetExtraData(GUI_LastCloseAction, gpConverter->toInternalString(newCloseAction));
    13292
    13393    /* Hide the dialog: */
     
    344304        m_strDiscardCheckBoxText = m_machine.GetCurrentSnapshot().GetName();
    345305
    346     /* Read the last user's choice for the given VM: */
    347     QStringList lastAction = m_machine.GetExtraData(GUI_LastCloseAction).split(',');
    348 
    349306    /* Check which radio-button should be initially chosen: */
    350307    QRadioButton *pRadioButtonToChoose = 0;
    351308    /* If choosing 'last choice' is possible: */
    352     if (lastAction[0] == m_strExtraDataOptionSave && fIsStateSavingAllowed)
     309    m_lastCloseAction = gpConverter->fromInternalString<MachineCloseAction>(m_machine.GetExtraData(GUI_LastCloseAction));
     310    if (m_lastCloseAction == MachineCloseAction_Save && fIsStateSavingAllowed)
    353311    {
    354312        pRadioButtonToChoose = m_pSaveRadio;
    355313    }
    356     else if (lastAction[0] == m_strExtraDataOptionShutdown && fIsACPIShutdownAllowed && m_fIsACPIEnabled)
     314    else if (m_lastCloseAction == MachineCloseAction_Shutdown && fIsACPIShutdownAllowed && m_fIsACPIEnabled)
    357315    {
    358316        pRadioButtonToChoose = m_pShutdownRadio;
    359317    }
    360     else if (lastAction[0] == m_strExtraDataOptionPowerOff && fIsPowerOffAllowed)
     318    else if (m_lastCloseAction == MachineCloseAction_PowerOff && fIsPowerOffAllowed)
    361319    {
    362320        pRadioButtonToChoose = m_pPowerOffRadio;
    363         if (fIsPowerOffAndRestoreAllowed)
    364             m_pDiscardCheckBox->setChecked(lastAction.count() > 1 && lastAction[1] == m_strExtraDataOptionDiscard);
     321    }
     322    else if (m_lastCloseAction == MachineCloseAction_PowerOff_RestoringSnapshot && fIsPowerOffAndRestoreAllowed)
     323    {
     324        pRadioButtonToChoose = m_pPowerOffRadio;
     325        m_pDiscardCheckBox->setChecked(true);
    365326    }
    366327    /* Else 'default choice' will be used: */
    367328    else
    368329    {
    369         if (fIsACPIShutdownAllowed && m_fIsACPIEnabled)
     330        if (fIsStateSavingAllowed)
     331            pRadioButtonToChoose = m_pSaveRadio;
     332        else if (fIsACPIShutdownAllowed && m_fIsACPIEnabled)
    370333            pRadioButtonToChoose = m_pShutdownRadio;
    371         else if (fIsStateSavingAllowed)
    372             pRadioButtonToChoose = m_pSaveRadio;
    373334        else if (fIsPowerOffAllowed)
    374335            pRadioButtonToChoose = m_pPowerOffRadio;
  • trunk/src/VBox/Frontends/VirtualBox/src/runtime/UIVMCloseDialog.h

    r46698 r46704  
    4848    bool isValid() const { return m_fValid; }
    4949
    50     /* Static API: Parse string containing result-code: */
    51     static MachineCloseAction parseResultCode(const QString &strCloseAction);
    52 
    5350private slots:
    5451
     
    9895
    9996    /* Variables: */
    100     const QString m_strExtraDataOptionSave;
    101     const QString m_strExtraDataOptionShutdown;
    102     const QString m_strExtraDataOptionPowerOff;
    103     const QString m_strExtraDataOptionDiscard;
    10497    bool m_fValid;
    10598    CMachine m_machine;
    10699    bool m_fIsACPIEnabled;
    107100    QString m_strDiscardCheckBoxText;
     101    MachineCloseAction m_lastCloseAction;
    108102};
    109103
Note: See TracChangeset for help on using the changeset viewer.

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