VirtualBox

Changeset 49465 in vbox


Ignore:
Timestamp:
Nov 13, 2013 1:27:44 PM (11 years ago)
Author:
vboxsync
Message:

FE/Qt: Runtime UI: Close actions handling rework (step 1): Providing VBoxGlobal and UISession with required stuff.

Location:
trunk/src/VBox/Frontends/VirtualBox/src
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Frontends/VirtualBox/src/globals/UIDefs.h

    r49363 r49465  
    351351enum MachineCloseAction
    352352{
    353     MachineCloseAction_Invalid,
    354     MachineCloseAction_SaveState,
    355     MachineCloseAction_Shutdown,
    356     MachineCloseAction_PowerOff,
    357     MachineCloseAction_PowerOff_RestoringSnapshot,
    358     MachineCloseAction_Max
     353    MachineCloseAction_Invalid                    = 0,
     354    MachineCloseAction_SaveState                  = RT_BIT(0),
     355    MachineCloseAction_Shutdown                   = RT_BIT(1),
     356    MachineCloseAction_PowerOff                   = RT_BIT(2),
     357    MachineCloseAction_PowerOff_RestoringSnapshot = RT_BIT(3),
     358    MachineCloseAction_All                        = 0xFF
    359359};
    360360Q_DECLARE_METATYPE(MachineCloseAction);
  • trunk/src/VBox/Frontends/VirtualBox/src/globals/VBoxGlobal.cpp

    r49363 r49465  
    35333533}
    35343534
     3535/** Returns default machine close action for passed @a machine. */
     3536MachineCloseAction VBoxGlobal::defaultMachineCloseAction(CMachine &machine)
     3537{
     3538    return gpConverter->fromInternalString<MachineCloseAction>(machine.GetExtraData(GUI_DefaultCloseAction));
     3539}
     3540
    35353541/* static */
    35363542RuntimeMenuType VBoxGlobal::restrictedRuntimeMenuTypes(CMachine &machine)
     
    35903596}
    35913597
    3592 /* static */
    3593 QList<MachineCloseAction> VBoxGlobal::restrictedMachineCloseActions(CMachine &machine)
     3598/** Returns merged restricted machine close actions for passed @a machine. */
     3599MachineCloseAction VBoxGlobal::restrictedMachineCloseActions(CMachine &machine)
    35943600{
    35953601    /* Prepare result: */
    3596     QList<MachineCloseAction> result;
     3602    MachineCloseAction result = MachineCloseAction_Invalid;
    35973603    /* Load restricted machine-close-actions: */
    35983604    QString strList(machine.GetExtraData(GUI_RestrictedCloseActions));
     
    36033609        MachineCloseAction value = gpConverter->fromInternalString<MachineCloseAction>(strValue);
    36043610        if (value != MachineCloseAction_Invalid)
    3605             result << value;
     3611            result = static_cast<MachineCloseAction>(result | value);
    36063612    }
    36073613    /* Return result: */
  • trunk/src/VBox/Frontends/VirtualBox/src/globals/VBoxGlobal.h

    r49363 r49465  
    359359    static bool shouldWeAutoMountGuestScreens(CMachine &machine, bool fIncludingSanityCheck = true);
    360360    static bool shouldWeAllowSnapshotOperations(CMachine &machine, bool fIncludingSanityCheck = true);
     361    static MachineCloseAction defaultMachineCloseAction(CMachine &machine);
    361362    static RuntimeMenuType restrictedRuntimeMenuTypes(CMachine &machine);
    362363    static UIVisualStateType restrictedVisualStateTypes(CMachine &machine);
    363364    static QList<IndicatorType> restrictedStatusBarIndicators(CMachine &machine);
    364     static QList<MachineCloseAction> restrictedMachineCloseActions(CMachine &machine);
     365    static MachineCloseAction restrictedMachineCloseActions(CMachine &machine);
    365366    static QList<GlobalSettingsPageType> restrictedGlobalSettingsPages(CVirtualBox &vbox);
    366367    static QList<MachineSettingsPageType> restrictedMachineSettingsPages(CMachine &machine);
  • trunk/src/VBox/Frontends/VirtualBox/src/runtime/UIMachineWindow.cpp

    r49013 r49465  
    253253        return;
    254254
     255    /* Get machine: */
     256    CMachine m = machine();
     257
    255258    /* If there is a close hook script defined: */
    256     QString strScript = machine().GetExtraData(GUI_CloseActionHook);
     259    QString strScript = m.GetExtraData(GUI_CloseActionHook);
    257260    if (!strScript.isEmpty())
    258261    {
    259262        /* Execute asynchronously and leave: */
    260         QProcess::startDetached(strScript, QStringList() << machine().GetId());
     263        QProcess::startDetached(strScript, QStringList() << m.GetId());
    261264        return;
    262265    }
     
    266269
    267270    /* If there IS default close-action defined: */
    268     QString strDefaultAction = machine().GetExtraData(GUI_DefaultCloseAction);
     271    QString strDefaultAction = m.GetExtraData(GUI_DefaultCloseAction);
    269272    if (!strDefaultAction.isEmpty())
    270273    {
     
    279282         * we should check if its possible to discard machine-state: */
    280283        if (closeAction == MachineCloseAction_PowerOff &&
    281             machine().GetSnapshotCount() > 0)
     284            m.GetSnapshotCount() > 0)
    282285            closeAction = MachineCloseAction_PowerOff_RestoringSnapshot;
    283286    }
     
    288291        /* Prepare close-dialog: */
    289292        QWidget *pParentDlg = windowManager().realParentWindow(this);
    290         QPointer<UIVMCloseDialog> pCloseDlg = new UIVMCloseDialog(pParentDlg, machine(), session());
     293        QPointer<UIVMCloseDialog> pCloseDlg = new UIVMCloseDialog(pParentDlg, m, session());
    291294
    292295        /* Make sure close-dialog is valid: */
  • trunk/src/VBox/Frontends/VirtualBox/src/runtime/UISession.cpp

    r49462 r49465  
    132132    , m_pWatchdogDisplayChange(0)
    133133#endif /* Q_WS_MAC */
     134    , m_defaultCloseAction(MachineCloseAction_Invalid)
     135    , m_restrictedCloseActions(MachineCloseAction_Invalid)
    134136    , m_fSnapshotOperationsAllowed(true)
    135137    /* Common flags: */
     
    10871089        updateSessionSettings();
    10881090
     1091        /* What is the default close action and the restricted are? */
     1092        m_defaultCloseAction = vboxGlobal().defaultMachineCloseAction(machine);
     1093        m_restrictedCloseActions = vboxGlobal().restrictedMachineCloseActions(machine);
     1094
    10891095        /* Should we allow snapshot operations? */
    10901096        m_fSnapshotOperationsAllowed = vboxGlobal().shouldWeAllowSnapshotOperations(machine);
  • trunk/src/VBox/Frontends/VirtualBox/src/runtime/UISession.h

    r49462 r49465  
    105105    QCursor cursor() const { return m_cursor; }
    106106
     107    /** @name Application Close configuration stuff.
     108     * @{ */
     109    /** Returns default close action. */
     110    MachineCloseAction defaultCloseAction() const { return m_defaultCloseAction; }
     111    /** Returns merged restricted close actions. */
     112    MachineCloseAction restrictedCloseActions() const { return m_restrictedCloseActions; }
     113    /** @} */
     114
    107115    /** @name Snapshot Operations configuration stuff.
    108116     * @{ */
     
    319327#endif /* Q_WS_MAC */
    320328
     329    /** @name Application Close configuration variables.
     330     * @{ */
     331    /** Default close action. */
     332    MachineCloseAction m_defaultCloseAction;
     333    /** Merged restricted close actions. */
     334    MachineCloseAction m_restrictedCloseActions;
     335    /** @} */
     336
    321337    /** @name Snapshot Operations configuration variables.
    322338     * @{ */
  • trunk/src/VBox/Frontends/VirtualBox/src/runtime/UIVMCloseDialog.cpp

    r47398 r49465  
    3939
    4040/* COM includes: */
     41# include "CMachine.h"
    4142# include "CSession.h"
    4243# include "CConsole.h"
     
    4546#endif /* !VBOX_WITH_PRECOMPILED_HEADERS */
    4647
    47 UIVMCloseDialog::UIVMCloseDialog(QWidget *pParent, const CMachine &machine, const CSession &session)
     48UIVMCloseDialog::UIVMCloseDialog(QWidget *pParent, CMachine &machine, const CSession &session)
    4849    : QIWithRetranslateUI<QIDialog>(pParent)
     50    , m_machine(machine)
     51    , m_session(session)
    4952    , m_fValid(false)
    5053    , m_fIsACPIEnabled(false)
     
    5558
    5659    /* Configure: */
    57     setSizeGripEnabled(false);
    58     configure(machine, session);
    59 
    60     /* Retranslate finally: */
     60    configure();
     61
     62    /* Retranslate: */
    6163    retranslateUi();
    6264}
     
    270272        pMainLayout->addWidget(pButtonBox);
    271273    }
    272 }
    273 
    274 void UIVMCloseDialog::configure(const CMachine &machine, const CSession &session)
    275 {
    276     /* Assign machine: */
    277     m_machine = machine;
    278 
    279     /* Get machine-state: */
     274    /* Prepare size-grip token: */
     275    setSizeGripEnabled(false);
     276}
     277
     278void UIVMCloseDialog::configure()
     279{
     280    /* Get actual machine-state: */
    280281    KMachineState machineState = m_machine.GetState();
    281282
     
    284285
    285286    /* Check which close-actions are resticted: */
    286     QList<MachineCloseAction> restictedCloseActions = vboxGlobal().restrictedMachineCloseActions(m_machine);
    287     bool fIsStateSavingAllowed = !restictedCloseActions.contains(MachineCloseAction_SaveState);
    288     bool fIsACPIShutdownAllowed = !restictedCloseActions.contains(MachineCloseAction_Shutdown);
    289     bool fIsPowerOffAllowed = !restictedCloseActions.contains(MachineCloseAction_PowerOff);
    290     bool fIsPowerOffAndRestoreAllowed = fIsPowerOffAllowed && !restictedCloseActions.contains(MachineCloseAction_PowerOff_RestoringSnapshot);
     287    MachineCloseAction restictedCloseActions = vboxGlobal().restrictedMachineCloseActions(m_machine);
     288    bool fIsStateSavingAllowed = !(restictedCloseActions & MachineCloseAction_SaveState);
     289    bool fIsACPIShutdownAllowed = !(restictedCloseActions & MachineCloseAction_Shutdown);
     290    bool fIsPowerOffAllowed = !(restictedCloseActions & MachineCloseAction_PowerOff);
     291    bool fIsPowerOffAndRestoreAllowed = fIsPowerOffAllowed && !(restictedCloseActions & MachineCloseAction_PowerOff_RestoringSnapshot);
    291292
    292293    /* Make 'Save state' button visible/hidden depending on restriction: */
     
    297298    setShutdownButtonVisible(fIsACPIShutdownAllowed);
    298299    /* Make 'Shutdown button' enabled/disabled depending on ACPI-state & machine-state: */
    299     m_fIsACPIEnabled = session.GetConsole().GetGuestEnteredACPIMode();
     300    m_fIsACPIEnabled = m_session.GetConsole().GetGuestEnteredACPIMode();
    300301    setShutdownButtonEnabled(m_fIsACPIEnabled && machineState != KMachineState_Stuck);
    301302    /* Make 'Power off' button visible/hidden depending on restriction: */
  • trunk/src/VBox/Frontends/VirtualBox/src/runtime/UIVMCloseDialog.h

    r47398 r49465  
    2525#include "UIDefs.h"
    2626
    27 /* COM includes: */
    28 #include "COMEnums.h"
    29 #include "CMachine.h"
    30 
    3127/* Forward declarations: */
     28class CMachine;
    3229class CSession;
    3330class QLabel;
     
    4340
    4441    /* Constructor: */
    45     UIVMCloseDialog(QWidget *pParent, const CMachine &machine, const CSession &session);
     42    UIVMCloseDialog(QWidget *pParent, CMachine &machine, const CSession &session);
    4643
    4744    /* API: Validation stuff: */
     
    7572    /* Helpers: Prepare stuff: */
    7673    void prepare();
    77     void configure(const CMachine &machine, const CSession &session);
     74    void configure();
    7875
    7976    /* Helper: Translate stuff: */
     
    9895
    9996    /* Variables: */
     97    CMachine &m_machine;
     98    const CSession &m_session;
    10099    bool m_fValid;
    101     CMachine m_machine;
    102100    bool m_fIsACPIEnabled;
    103101    QString m_strDiscardCheckBoxText;
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