VirtualBox

Ignore:
Timestamp:
Oct 8, 2014 11:29:07 AM (10 years ago)
Author:
vboxsync
Message:

FE/Qt: Runtime UI rework/cleanup for 7115 (part #4): Better encapsulation for UIMachine (part #1).

File:
1 edited

Legend:

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

    r52987 r52989  
    2020#else  /* !VBOX_WITH_PRECOMPILED_HEADERS */
    2121
    22 /* Local includes: */
     22/* GUI includes: */
    2323# include "VBoxGlobal.h"
    2424# include "UIExtraDataManager.h"
     
    142142}
    143143
     144UIMachineLogic* UIMachine::machineLogic() const
     145{
     146    if (m_pVisualState && m_pVisualState->machineLogic())
     147        return m_pVisualState->machineLogic();
     148    return 0;
     149}
     150
     151QWidget* UIMachine::activeWindow() const
     152{
     153    if (machineLogic() &&  machineLogic()->activeMachineWindow())
     154        return machineLogic()->activeMachineWindow();
     155    return 0;
     156}
     157
     158void UIMachine::asyncChangeVisualState(UIVisualStateType visualStateType)
     159{
     160    emit sigRequestAsyncVisualStateChange(visualStateType);
     161}
     162
     163void UIMachine::sltChangeVisualState(UIVisualStateType newVisualStateType)
     164{
     165    /* Create new state: */
     166    UIVisualState *pNewVisualState = new UIVisualState(this, m_pSession, newVisualStateType);
     167
     168    /* First we have to check if the selected mode is available at all.
     169     * Only then we delete the old mode and switch to the new mode. */
     170    if (pNewVisualState->prepareChange())
     171    {
     172        /* Delete previous state: */
     173        delete m_pVisualState;
     174
     175        /* Set the new mode as current mode: */
     176        m_pVisualState = pNewVisualState;
     177        m_pVisualState->change();
     178    }
     179    else
     180    {
     181        /* Discard the temporary created new state: */
     182        delete pNewVisualState;
     183
     184        /* If there is no state currently created => we have to exit: */
     185        if (!m_pVisualState)
     186            deleteLater();
     187    }
     188}
     189
    144190UIMachine::UIMachine()
    145191    : QObject(0)
    146     , initialStateType(UIVisualStateType_Normal)
    147192    , m_pSession(0)
     193    , m_allowedVisualStates(UIVisualStateType_Invalid)
     194    , m_initialStateType(UIVisualStateType_Normal)
    148195    , m_pVisualState(0)
    149     , m_allowedVisualStates(UIVisualStateType_Invalid)
    150196{
    151197    /* Make sure VBoxGlobal is aware of VM creation: */
    152198    vboxGlobal().setVirtualMachine(this);
     199}
     200
     201UIMachine::~UIMachine()
     202{
     203    /* Make sure VBoxGlobal is aware of VM destruction: */
     204    vboxGlobal().setVirtualMachine(0);
     205
     206    /* Cleanup machine UI: */
     207    cleanup();
    153208}
    154209
     
    192247    vboxGlobal().startMediumEnumeration(false /* force start */);
    193248
    194     /* Load machine settings: */
    195     loadMachineSettings();
     249    /* Load settings: */
     250    loadSettings();
    196251
    197252    /* Prepare async visual-state change handler: */
     
    217272}
    218273
    219 UIMachine::~UIMachine()
    220 {
    221     /* Save machine settings: */
    222     saveMachineSettings();
    223 
    224     /* Delete visual state: */
    225     delete m_pVisualState;
    226     m_pVisualState = 0;
    227 
    228     /* Delete UI session: */
    229     delete m_pSession;
    230     m_pSession = 0;
    231 
    232     /* Free session finally: */
    233     m_session.UnlockMachine();
    234     m_session.detach();
    235 
    236     /* Make sure VBoxGlobal is aware of VM destruction: */
    237     vboxGlobal().setVirtualMachine(0);
    238 
    239     /* Quit application: */
    240     QApplication::quit();
    241 }
    242 
    243 QWidget* UIMachine::activeWindow() const
    244 {
    245     if (machineLogic() &&  machineLogic()->activeMachineWindow())
    246         return machineLogic()->activeMachineWindow();
    247     return 0;
    248 }
    249 
    250 void UIMachine::asyncChangeVisualState(UIVisualStateType visualStateType)
    251 {
    252     emit sigRequestAsyncVisualStateChange(visualStateType);
    253 }
    254 
    255 void UIMachine::sltChangeVisualState(UIVisualStateType newVisualStateType)
    256 {
    257     /* Create new state: */
    258     UIVisualState *pNewVisualState = new UIVisualState(this, m_pSession, newVisualStateType);
    259 
    260     /* First we have to check if the selected mode is available at all.
    261      * Only then we delete the old mode and switch to the new mode. */
    262     if (pNewVisualState->prepareChange())
    263     {
    264         /* Delete previous state: */
    265         delete m_pVisualState;
    266 
    267         /* Set the new mode as current mode: */
    268         m_pVisualState = pNewVisualState;
    269         m_pVisualState->change();
    270     }
    271     else
    272     {
    273         /* Discard the temporary created new state: */
    274         delete pNewVisualState;
    275 
    276         /* If there is no state currently created => we have to exit: */
    277         if (!m_pVisualState)
    278             deleteLater();
    279     }
    280 }
    281 
    282 void UIMachine::enterInitialVisualState()
    283 {
    284     sltChangeVisualState(initialStateType);
    285 }
    286 
    287 UIMachineLogic* UIMachine::machineLogic() const
    288 {
    289     if (m_pVisualState && m_pVisualState->machineLogic())
    290         return m_pVisualState->machineLogic();
    291     return 0;
    292 }
    293 
    294 void UIMachine::loadMachineSettings()
     274void UIMachine::loadSettings()
    295275{
    296276    /* Load 'visual state' option: */
     
    309289            {
    310290                /* Direct transition to scale/fullscreen mode allowed: */
    311                 case UIVisualStateType_Scale: initialStateType = UIVisualStateType_Scale; break;
    312                 case UIVisualStateType_Fullscreen: initialStateType = UIVisualStateType_Fullscreen; break;
     291                case UIVisualStateType_Scale: m_initialStateType = UIVisualStateType_Scale; break;
     292                case UIVisualStateType_Fullscreen: m_initialStateType = UIVisualStateType_Fullscreen; break;
    313293                /* While to seamless is not, so we have to request transition on GA capability-change event: */
    314294                case UIVisualStateType_Seamless: uisession()->setRequestedVisualState(UIVisualStateType_Seamless); break;
     
    319299}
    320300
    321 void UIMachine::saveMachineSettings()
     301void UIMachine::saveSettings()
    322302{
    323303    /* Save 'visual state' option: */
     
    338318}
    339319
     320void UIMachine::cleanup()
     321{
     322    /* Save settings: */
     323    saveSettings();
     324
     325    /* Delete visual state: */
     326    delete m_pVisualState;
     327    m_pVisualState = 0;
     328
     329    /* Delete UI session: */
     330    delete m_pSession;
     331    m_pSession = 0;
     332
     333    /* Free session finally: */
     334    m_session.UnlockMachine();
     335    m_session.detach();
     336
     337    /* Make sure VBoxGlobal is aware of VM destruction: */
     338    vboxGlobal().setVirtualMachine(0);
     339
     340    /* Quit application: */
     341    QApplication::quit();
     342}
     343
     344void UIMachine::enterInitialVisualState()
     345{
     346    sltChangeVisualState(m_initialStateType);
     347}
     348
    340349#include "UIMachine.moc"
    341350
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