VirtualBox

Ignore:
Timestamp:
Oct 7, 2014 5:46:32 PM (10 years ago)
Author:
vboxsync
Message:

FE/Qt: Runtime UI rework/cleanup for 7115 (part #3): Move machine starting/creation stuff from VBoxGlobal to UMachine.

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

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Frontends/VirtualBox/src/globals/VBoxGlobal.cpp

    r52957 r52977  
    372372
    373373    return *mSelectorWnd;
    374 }
    375 
    376 bool VBoxGlobal::startMachine(const QString &strMachineId)
    377 {
    378     /* Some restrictions: */
    379     AssertMsg(mValid, ("VBoxGlobal is invalid"));
    380     AssertMsg(!m_pVirtualMachine, ("Machine already started"));
    381 
    382     /* Restore current snapshot if asked to do so: */
    383     if (mRestoreCurrentSnapshot)
    384     {
    385         CSession session = vboxGlobal().openSession(strMachineId, KLockType_VM);
    386         if (session.isNull())
    387             return false;
    388 
    389         CConsole  console  = session.GetConsole();
    390         CMachine  machine  = session.GetMachine();
    391         CSnapshot snapshot = machine.GetCurrentSnapshot();
    392         CProgress progress = console.RestoreSnapshot(snapshot);
    393         if (!console.isOk())
    394             return msgCenter().cannotRestoreSnapshot(console, snapshot.GetName(), machine.GetName());
    395 
    396         /* Show the snapshot-discard progress: */
    397         msgCenter().showModalProgressDialog(progress, machine.GetName(), ":/progress_snapshot_discard_90px.png");
    398         if (progress.GetResultCode() != 0)
    399             return msgCenter().cannotRestoreSnapshot(progress, snapshot.GetName(), machine.GetName());
    400         session.UnlockMachine();
    401 
    402         /* Clear the restore flag so media enum can be started, should be safe now. */
    403         mRestoreCurrentSnapshot = false;
    404     }
    405 
    406     /* Start virtual machine: */
    407     return UIMachine::create(&m_pVirtualMachine);
    408 }
    409 
    410 UIMachine* VBoxGlobal::virtualMachine()
    411 {
    412     return m_pVirtualMachine;
    413374}
    414375
  • trunk/src/VBox/Frontends/VirtualBox/src/globals/VBoxGlobal.h

    r52902 r52977  
    110110    UISelectorWindow &selectorWnd();
    111111
    112     /* VM stuff: */
    113     bool startMachine(const QString &strMachineId);
    114     UIMachine* virtualMachine();
     112    /** Returns current virtual machine. */
     113    UIMachine* virtualMachine() const { return m_pVirtualMachine; }
     114    /** Defines current virtual @a pMachine. */
     115    void setVirtualMachine(UIMachine *pMachine) { m_pVirtualMachine = pMachine; }
     116
    115117    QWidget* activeMachineWindow();
    116118
     
    140142    bool isKWinManaged() const { return mIsKWinManaged; }
    141143
     144    /** Returns whether we should restore current snapshot before VM started. */
    142145    bool shouldRestoreCurrentSnapshot() const { return mRestoreCurrentSnapshot; }
     146    /** Defines whether we should fRestore current snapshot before VM started. */
     147    void setShouldRestoreCurrentSnapshot(bool fRestore) { mRestoreCurrentSnapshot = fRestore; }
     148
    143149    bool isPatmDisabled() const { return mDisablePatm; }
    144150    bool isCsamDisabled() const { return mDisableCsam; }
  • trunk/src/VBox/Frontends/VirtualBox/src/main.cpp

    r52902 r52977  
    2626# include "UIMessageCenter.h"
    2727# include "UISelectorWindow.h"
     28# include "UIMachine.h"
    2829# include "VBoxUtils.h"
    2930# include "UIModalWindowManager.h"
     
    456457            {
    457458                /* Make sure VM is started: */
    458                 if (!vboxGlobal().startMachine(vboxGlobal().managedVMUuid()))
     459                if (!UIMachine::startMachine(vboxGlobal().managedVMUuid()))
    459460                    break;
    460461
  • trunk/src/VBox/Frontends/VirtualBox/src/runtime/UIMachine.cpp

    r52902 r52977  
    3030# include "UIMessageCenter.h"
    3131
     32/* COM includes: */
     33# include "CMachine.h"
     34# include "CConsole.h"
     35# include "CSnapshot.h"
     36# include "CProgress.h"
     37
    3238#endif /* !VBOX_WITH_PRECOMPILED_HEADERS */
    3339
     
    9197
    9298/* static */
    93 bool UIMachine::create(UIMachine **ppSelf)
    94 {
    95     UIMachine *pMachine = new UIMachine(ppSelf);
    96     if (!pMachine)
    97         return false;
     99bool UIMachine::startMachine(const QString &strID)
     100{
     101    /* Some restrictions: */
     102    AssertMsgReturn(vboxGlobal().isValid(), ("VBoxGlobal is invalid.."), false);
     103    AssertMsgReturn(!vboxGlobal().virtualMachine(), ("Machine already started.."), false);
     104
     105    /* Restore current snapshot if requested: */
     106    if (vboxGlobal().shouldRestoreCurrentSnapshot())
     107    {
     108        /* Create temporary session: */
     109        CSession session = vboxGlobal().openSession(strID, KLockType_VM);
     110        if (session.isNull())
     111            return false;
     112
     113        /* Which VM we operate on? */
     114        CMachine machine  = session.GetMachine();
     115        /* Which snapshot we are restoring? */
     116        CSnapshot snapshot = machine.GetCurrentSnapshot();
     117
     118        /* Open corresponding console: */
     119        CConsole console  = session.GetConsole();
     120        /* Prepare restore-snapshot progress: */
     121        CProgress progress = console.RestoreSnapshot(snapshot);
     122        if (!console.isOk())
     123            return msgCenter().cannotRestoreSnapshot(console, snapshot.GetName(), machine.GetName());
     124
     125        /* Show the snapshot-discarding progress: */
     126        msgCenter().showModalProgressDialog(progress, machine.GetName(), ":/progress_snapshot_discard_90px.png");
     127        if (progress.GetResultCode() != 0)
     128            return msgCenter().cannotRestoreSnapshot(progress, snapshot.GetName(), machine.GetName());
     129
     130        /* Unlock session finally: */
     131        session.UnlockMachine();
     132
     133        /* Clear snapshot-restoring request: */
     134        vboxGlobal().setShouldRestoreCurrentSnapshot(false);
     135    }
     136
     137    /* Create machine UI: */
     138    UIMachine *pMachine = new UIMachine;
     139
     140    /* Prepare machine UI: */
    98141    return pMachine->prepare();
    99142}
    100143
    101 UIMachine::UIMachine(UIMachine **ppSelf)
     144UIMachine::UIMachine()
    102145    : QObject(0)
    103     , m_ppThis(ppSelf)
    104146    , initialStateType(UIVisualStateType_Normal)
    105147    , m_pSession(0)
     
    107149    , m_allowedVisualStates(UIVisualStateType_Invalid)
    108150{
    109     /* Store self pointer: */
    110     if (m_ppThis)
    111         *m_ppThis = this;
     151    /* Make sure VBoxGlobal is aware of VM creation: */
     152    vboxGlobal().setVirtualMachine(this);
    112153}
    113154
     
    192233    m_session.detach();
    193234
    194     /* Clear self pointer: */
    195     *m_ppThis = 0;
     235    /* Make sure VBoxGlobal is aware of VM destruction: */
     236    vboxGlobal().setVirtualMachine(0);
    196237
    197238    /* Quit application: */
  • trunk/src/VBox/Frontends/VirtualBox/src/runtime/UIMachine.h

    r52894 r52977  
    4646public:
    4747
    48     static bool create(UIMachine **ppSelf);
     48    /** Static factory to start machine with passed @a strID.
     49      * @return true if machine was started, false otherwise. */
     50    static bool startMachine(const QString &strID);
    4951
    50     /* Virtual Machine constructor/destructor: */
    51     UIMachine(UIMachine **ppSelf);
     52    /** Constructor. */
     53    UIMachine();
     54    /** Destructor. */
    5255    virtual ~UIMachine();
    5356
     
    8487
    8588    /* Private variables: */
    86     UIMachine **m_ppThis;
    8789    UIVisualStateType initialStateType;
    8890    CSession m_session;
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