VirtualBox

Changeset 26950 in vbox for trunk/src/VBox/Frontends


Ignore:
Timestamp:
Mar 2, 2010 3:08:43 PM (15 years ago)
Author:
vboxsync
Message:

FE/Qt4: new core: Make it possible to prevent a mode switch in case the new mode isn't available.

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

Legend:

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

    r26873 r26950  
    10151015}
    10161016
     1017int VBoxProblemReporter::cannotEnterFullscreenMode()
     1018{
     1019    return message(mainMachineWindowShown(), Error,
     1020             tr ("<p>Can not switch the guest display to fullscreen mode. You "
     1021                 "have more virtual screens configured than physical screens are "
     1022                 "attached to your host.</p><p>Please either lower the virtual "
     1023                 "screens in your VM configuration or attach additional screens "
     1024                 "to your host.</p>"),
     1025             0, /* aAutoConfirmId */
     1026             QIMessageBox::Ok | QIMessageBox::Default);
     1027}
     1028
    10171029bool VBoxProblemReporter::confirmMachineDeletion (const CMachine &machine)
    10181030{
  • trunk/src/VBox/Frontends/VirtualBox/src/globals/VBoxProblemReporter.h

    r26868 r26950  
    227227                                   ULONG aBpp, ULONG64 aMinVRAM);
    228228
     229    int cannotEnterFullscreenMode();
     230
    229231    bool confirmMachineDeletion (const CMachine &machine);
    230232    bool confirmDiscardSavedState (const CMachine &machine);
  • trunk/src/VBox/Frontends/VirtualBox/src/runtime/UIMachine.cpp

    r26921 r26950  
    3737
    3838    /* Visual state holder constructor: */
    39     UIVisualState(QObject *pParent) : QObject(pParent), m_pMachineLogic(0)
     39    UIVisualState(QObject *pParent, UISession *pSession, UIActionsPool *pActionsPool)
     40        : QObject(pParent)
     41        , m_pSession(pSession)
     42        , m_pActionsPool(pActionsPool)
     43        , m_pMachineLogic(0)
    4044    {
    4145        /* Connect state-change handler: */
     
    4549    /* Public getters: */
    4650    UIMachineLogic* machineLogic() const  { return m_pMachineLogic; }
    47 
     51    virtual UIVisualStateType visualStateType() const = 0;
     52
     53    virtual bool prepareChange()
     54    {
     55        m_pMachineLogic = UIMachineLogic::create(this, m_pSession, m_pActionsPool, visualStateType());
     56        return m_pMachineLogic->checkAvailability();
     57    }
     58
     59    virtual void change() = 0;
     60    virtual void finishChange() {}
    4861signals:
    4962
     
    5467
    5568    /* Protected members: */
     69    UISession *m_pSession;
     70    UIActionsPool *m_pActionsPool;
    5671    UIMachineLogic *m_pMachineLogic;
    5772};
     
    6580    /* Normal visual state holder constructor: */
    6681    UIVisualStateNormal(QObject *pParent, UISession *pSession, UIActionsPool *pActionsPool)
    67         : UIVisualState(pParent)
     82        : UIVisualState(pParent, pSession, pActionsPool)
     83    {}
     84
     85    UIVisualStateType visualStateType() const { return UIVisualStateType_Normal; }
     86
     87    void change()
    6888    {
    6989        /* Connect action handlers: */
    70         connect(pActionsPool->action(UIActionIndex_Toggle_Fullscreen), SIGNAL(triggered(bool)),
     90        connect(m_pActionsPool->action(UIActionIndex_Toggle_Fullscreen), SIGNAL(triggered(bool)),
    7191                this, SLOT(sltGoToFullscreenMode()));
    72         connect(pActionsPool->action(UIActionIndex_Toggle_Seamless), SIGNAL(triggered(bool)),
     92        connect(m_pActionsPool->action(UIActionIndex_Toggle_Seamless), SIGNAL(triggered(bool)),
    7393                this, SLOT(sltGoToSeamlessMode()));
    7494
    75         /* Create state logic: */
    76         m_pMachineLogic = UIMachineLogic::create(this, pSession, pActionsPool, UIVisualStateType_Normal);
     95        /* Initialize the logic object */
     96        m_pMachineLogic->initialize();
    7797    }
    7898
     
    100120    /* Fullscreen visual state holder constructor: */
    101121    UIVisualStateFullscreen(QObject *pParent, UISession *pSession, UIActionsPool *pActionsPool)
    102         : UIVisualState(pParent)
     122        : UIVisualState(pParent, pSession, pActionsPool)
     123    {}
     124
     125    UIVisualStateType visualStateType() const { return UIVisualStateType_Fullscreen; }
     126
     127    void change()
    103128    {
    104129        /* Connect action handlers: */
    105         connect(pActionsPool->action(UIActionIndex_Toggle_Fullscreen), SIGNAL(triggered(bool)),
     130        connect(m_pActionsPool->action(UIActionIndex_Toggle_Fullscreen), SIGNAL(triggered(bool)),
    106131                this, SLOT(sltGoToNormalMode()));
    107         connect(pActionsPool->action(UIActionIndex_Toggle_Seamless), SIGNAL(triggered(bool)),
     132        connect(m_pActionsPool->action(UIActionIndex_Toggle_Seamless), SIGNAL(triggered(bool)),
    108133                this, SLOT(sltGoToSeamlessMode()));
    109134
    110         /* Create state logic: */
    111         m_pMachineLogic = UIMachineLogic::create(this, pSession, pActionsPool, UIVisualStateType_Fullscreen);
     135        /* Initialize the logic object */
     136        m_pMachineLogic->initialize();
    112137    }
    113138
     
    135160    /* Seamless visual state holder constructor: */
    136161    UIVisualStateSeamless(QObject *pParent, UISession *pSession, UIActionsPool *pActionsPool)
    137         : UIVisualState(pParent)
     162        : UIVisualState(pParent, pSession, pActionsPool)
     163    {}
     164
     165    UIVisualStateType visualStateType() const { return UIVisualStateType_Seamless; }
     166
     167    void change()
    138168    {
    139169        /* Connect action handlers */
    140         connect(pActionsPool->action(UIActionIndex_Toggle_Fullscreen), SIGNAL(triggered(bool)),
     170        connect(m_pActionsPool->action(UIActionIndex_Toggle_Fullscreen), SIGNAL(triggered(bool)),
    141171                this, SLOT(sltGoToFullscreenMode()));
    142         connect(pActionsPool->action(UIActionIndex_Toggle_Seamless), SIGNAL(triggered(bool)),
     172        connect(m_pActionsPool->action(UIActionIndex_Toggle_Seamless), SIGNAL(triggered(bool)),
    143173                this, SLOT(sltGoToNormalMode()));
    144174
    145         /* Create state logic */
    146         m_pMachineLogic = UIMachineLogic::create(this, pSession, pActionsPool, UIVisualStateType_Seamless);
     175        /* Initialize the logic object */
     176        m_pMachineLogic->initialize();
    147177    }
    148178
     
    225255void UIMachine::sltChangeVisualState(UIVisualStateType visualStateType)
    226256{
    227     /* Delete previous state: */
    228     delete m_pVisualState;
    229     m_pVisualState = 0;
    230 
     257    UIVisualState *pNewVisualState = 0;
    231258    /* Create new state: */
    232259    switch (visualStateType)
     
    235262        {
    236263            /* Create normal visual state: */
    237             m_pVisualState = new UIVisualStateNormal(this, m_pSession, m_pActionsPool);
     264            pNewVisualState = new UIVisualStateNormal(this, m_pSession, m_pActionsPool);
    238265            break;
    239266        }
     
    241268        {
    242269            /* Create fullscreen visual state: */
    243             m_pVisualState = new UIVisualStateFullscreen(this, m_pSession, m_pActionsPool);
     270            pNewVisualState = new UIVisualStateFullscreen(this, m_pSession, m_pActionsPool);
    244271            break;
    245272        }
     
    247274        {
    248275            /* Create seamless visual state: */
    249             m_pVisualState = new UIVisualStateSeamless(this, m_pSession, m_pActionsPool);
     276            pNewVisualState = new UIVisualStateSeamless(this, m_pSession, m_pActionsPool);
    250277            break;
    251278        }
     
    253280            break;
    254281    }
     282
     283    /* First we have to check if the selected mode is available at all. Only
     284     * then we delete the old mode and switch to the new mode. */
     285    if (pNewVisualState->prepareChange())
     286    {
     287        /* Delete previous state: */
     288        delete m_pVisualState;
     289
     290        /* Set the new mode as current mode. */
     291        m_pVisualState = pNewVisualState;
     292        m_pVisualState->change();
     293        /* Finish any setup. */
     294        m_pVisualState->finishChange();
     295    }
     296    else
     297        /* Discard the temporary create new state */
     298        delete pNewVisualState;
    255299}
    256300
  • trunk/src/VBox/Frontends/VirtualBox/src/runtime/UIMachineLogic.h

    r26938 r26950  
    5858                                  UIVisualStateType visualStateType);
    5959
     60    /* Check if this mode is available */
     61    virtual bool checkAvailability() { return true; }
     62
     63    /* Do the real initialization of the object */
     64    virtual void initialize() {}
     65
    6066    /* Main getters/setters: */
    6167    UISession* uisession() { return m_pSession; }
  • trunk/src/VBox/Frontends/VirtualBox/src/runtime/fullscreen/UIMachineLogicFullscreen.cpp

    r26938 r26950  
    4848    : UIMachineLogic(pParent, pSession, pActionsPool, UIVisualStateType_Fullscreen)
    4949{
    50     /* Prepare console connections: */
    51     prepareConsoleConnections();
    52 
    53     /* Prepare action groups: */
    54     prepareActionGroups();
    55 
    56     /* Prepare action connections: */
    57     prepareActionConnections();
    58 
     50}
     51
     52UIMachineLogicFullscreen::~UIMachineLogicFullscreen()
     53{
     54    /* Cleanup machine window: */
     55    cleanupMachineWindow();
     56}
     57
     58bool UIMachineLogicFullscreen::checkAvailability()
     59{
     60    int cHostScreens = QApplication::desktop()->screenCount();
     61    int cGuestScreens = uisession()->session().GetMachine().GetMonitorCount();
     62    /* Check that there are enough physical screens are connected */
     63    if (cHostScreens < cGuestScreens)
     64    {
     65        vboxProblem().cannotEnterFullscreenMode();
     66        setPreventAutoStart(true);
     67        return false;
     68    }
     69
     70    return true;
     71}
     72
     73void UIMachineLogicFullscreen::initialize()
     74{
    5975    /* Check the status of required features: */
    6076    prepareRequiredFeatures();
    6177
    62     /* Prepare machine window: */
    63     prepareMachineWindows();
    64 
    65     /* Initialization: */
    66     sltMachineStateChanged();
    67     sltAdditionsStateChanged();
    68     sltMouseCapabilityChanged();
    69 }
    70 
    71 UIMachineLogicFullscreen::~UIMachineLogicFullscreen()
    72 {
    73     /* Cleanup machine window: */
    74     cleanupMachineWindow();
     78    /* If required features are ready: */
     79    if (!isPreventAutoStart())
     80    {
     81        /* Prepare console connections: */
     82        prepareConsoleConnections();
     83
     84        /* Prepare action groups: */
     85        prepareActionGroups();
     86
     87        /* Prepare action connections: */
     88        prepareActionConnections();
     89
     90        /* Prepare machine window: */
     91        prepareMachineWindows();
     92
     93        /* Initialization: */
     94        sltMachineStateChanged();
     95        sltAdditionsStateChanged();
     96        sltMouseCapabilityChanged();
     97    }
    7598}
    7699
     
    117140    // TODO_NEW_CORE
    118141//    if (session().GetConsole().isAutoresizeGuestActive())
    119     {
    120 //        QRect screen = QApplication::desktop()->screenGeometry(this);
    121 //        ULONG64 availBits = session().GetMachine().GetVRAMSize() /* vram */
    122 //                          * _1M /* mb to bytes */
    123 //                          * 8; /* to bits */
    124 //        ULONG guestBpp = mConsole->console().GetDisplay().GetBitsPerPixel();
    125 //        ULONG64 usedBits = (screen.width() /* display width */
    126 //                         * screen.height() /* display height */
    127 //                         * guestBpp
    128 //                         + _1M * 8) /* current cache per screen - may be changed in future */
    129 //                         * session().GetMachine().GetMonitorCount() /**< @todo fix assumption that all screens have same resolution */
    130 //                         + 4096 * 8; /* adapter info */
     142//    {
     143//        ULONG64 availBits = session().GetMachine().GetVRAMSize() /* VRAM */
     144//            * _1M /* MB to bytes */
     145//            * 8; /* to bits */
     146//        for (ulong uScreenId = 0; uScreenId < uMonitorCount; ++ uScreenId)
     147//        {
     148//            QRect screen = QApplication::desktop()->screenGeometry(this);
     149//            ULONG guestBpp = mConsole->console().GetDisplay().GetBitsPerPixel();
     150//            ULONG64 usedBits = (screen.width() /* display width */
     151//                                * screen.height() /* display height */
     152//                                * guestBpp
     153//                                + _1M * 8) /* current cache per screen - may be changed in future */
     154//                * session().GetMachine().GetMonitorCount() /**< @todo fix assumption that all screens have same resolution */
     155//                + 4096 * 8; /* adapter info */
     156//        }
     157//
    131158//        if (availBits < usedBits)
    132159//        {
    133160//            int result = vboxProblem().cannotEnterFullscreenMode(
    134 //                   screen.width(), screen.height(), guestBpp,
    135 //                   (((usedBits + 7) / 8 + _1M - 1) / _1M) * _1M);
     161//                                                                 screen.width(), screen.height(), guestBpp,
     162//                                                                 (((usedBits + 7) / 8 + _1M - 1) / _1M) * _1M);
    136163//            if (result == QIMessageBox::Cancel)
    137164//                sltClose();
    138165//        }
    139     }
     166//    }
     167//
     168    UIMachineLogic::prepareRequiredFeatures();
    140169}
    141170
  • trunk/src/VBox/Frontends/VirtualBox/src/runtime/fullscreen/UIMachineLogicFullscreen.h

    r26937 r26950  
    4242    virtual ~UIMachineLogicFullscreen();
    4343
     44    bool checkAvailability();
     45    void initialize();
     46
    4447private slots:
    4548
  • trunk/src/VBox/Frontends/VirtualBox/src/runtime/normal/UIMachineLogicNormal.cpp

    r26938 r26950  
    4141    : UIMachineLogic(pParent, pSession, pActionsPool, UIVisualStateType_Normal)
    4242{
     43}
     44
     45UIMachineLogicNormal::~UIMachineLogicNormal()
     46{
     47    /* Cleanup normal machine window: */
     48    cleanupMachineWindow();
     49}
     50
     51void UIMachineLogicNormal::initialize()
     52{
    4353    /* Check the status of required features: */
    4454    prepareRequiredFeatures();
     
    6474        sltMouseCapabilityChanged();
    6575    }
    66 }
    67 
    68 UIMachineLogicNormal::~UIMachineLogicNormal()
    69 {
    70     /* Cleanup normal machine window: */
    71     cleanupMachineWindow();
    7276}
    7377
  • trunk/src/VBox/Frontends/VirtualBox/src/runtime/normal/UIMachineLogicNormal.h

    r26921 r26950  
    4242    virtual ~UIMachineLogicNormal();
    4343
     44    void initialize();
     45
    4446private slots:
    4547
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