VirtualBox

Changeset 92860 in vbox


Ignore:
Timestamp:
Dec 10, 2021 12:39:38 PM (3 years ago)
Author:
vboxsync
Message:

FE/Qt: bugref:9371. Better state management for file manager.

Location:
trunk/src/VBox/Frontends/VirtualBox/src/guestctrl
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Frontends/VirtualBox/src/guestctrl/UIFileManagerGuestTable.cpp

    r92847 r92860  
    5353*********************************************************************************************************************************/
    5454/** A QWidget extension containing text entry fields for password and username and buttons to
    55  *  start/stop a guest session. */
     55  *  start/stop a guest session. */
    5656class UIGuestSessionCreateWidget : public QIWithRetranslateUI<QWidget>
    5757{
     
    393393    if (!m_comMachine.isNull() && m_comMachine.GetState() == KMachineState_Running)
    394394        openMachineSession();
    395     setSessionDependentWidgetsEnabled(isSessionPossible());
     395    setStateAndEnableWidgets();
    396396
    397397    retranslateUi();
     
    420420    {
    421421        QString strWarningText;
    422         switch (m_enmCheckMachine)
     422        switch (m_enmState)
    423423        {
    424             case CheckMachine_InvalidMachineReference:
     424            case State_InvalidMachineReference:
    425425                strWarningText = UIFileManager::tr("Machine reference is invalid.");
    426426                break;
    427             case CheckMachine_MachineNotRunning:
     427            case State_MachineNotRunning:
    428428                strWarningText = UIFileManager::tr("File manager cannot work since it works only with running guests.");
    429429                break;
    430             case CheckMachine_NoGuestAdditions:
     430            case State_NoGuestAdditions:
    431431                strWarningText = UIFileManager::tr("File manager cannot work since it needs running guest additions in the guest system.");
    432432                break;
    433             case CheckMachine_SessionPossible:
     433            case State_SessionPossible:
    434434            default:
    435435                break;
     
    10861086}
    10871087
    1088 // void UIFileManagerGuestTable::sltHandleGuestSessionPanelHidden()
    1089 // {
    1090 //     if (m_pActionPool && m_pActionPool->action(UIActionIndex_M_FileManager_T_GuestSession))
    1091 //         m_pActionPool->action(UIActionIndex_M_FileManager_T_GuestSession)->setChecked(false);
    1092 // }
    1093 
    1094 // void UIFileManagerGuestTable::sltHandleGuestSessionPanelShown()
    1095 // {
    1096 //     if (m_pActionPool && m_pActionPool->action(UIActionIndex_M_FileManager_T_GuestSession))
    1097 //         m_pActionPool->action(UIActionIndex_M_FileManager_T_GuestSession)->setChecked(true);
    1098 // }
    1099 
    11001088void UIFileManagerGuestTable::sltMachineStateChange(const QUuid &uMachineId, const KMachineState enmMachineState)
    11011089{
     
    11091097    else
    11101098        cleanAll();
    1111 
    1112     setSessionDependentWidgetsEnabled(isSessionPossible());
    1113     retranslateUi();
     1099    setStateAndEnableWidgets();
    11141100}
    11151101
     
    12561242    /* Unregister everything: */
    12571243    QtListener->getWrapped()->unregisterSources();
    1258 
     1244    QtListener.setNull();
    12591245    /* Make sure VBoxSVC is available: */
    12601246    if (!uiCommon().isVBoxSVCAvailable())
     
    12941280    {
    12951281        if (m_comGuestSession.GetStatus() == KGuestSessionStatus_Started)
    1296         {
    12971282            initFileTable();
    1298             postGuestSessionCreated();
    1299         }
    13001283        emit sigLogOutput(QString("%1: %2").arg("Guest session status has changed").arg(gpConverter->toString(m_comGuestSession.GetStatus())),
    13011284                  m_strTableName, FileManagerLogType_Info);
     
    13031286    else
    13041287        emit sigLogOutput("Guest session is not valid", m_strTableName, FileManagerLogType_Error);
     1288    postGuestSessionCreated();
     1289    setStateAndEnableWidgets();
    13051290}
    13061291
     
    13181303}
    13191304
    1320 bool UIFileManagerGuestTable::isSessionPossible()
     1305void UIFileManagerGuestTable::setState()
    13211306{
    13221307    if (m_comMachine.isNull())
    13231308    {
    1324         m_enmCheckMachine = CheckMachine_InvalidMachineReference;
    1325         return false;
     1309        m_enmState = State_InvalidMachineReference;
     1310        return;
    13261311    }
    13271312    if (m_comMachine.GetState() != KMachineState_Running)
    13281313    {
    1329         m_enmCheckMachine = CheckMachine_MachineNotRunning;
    1330         return false;
     1314        m_enmState = State_MachineNotRunning;
     1315        return;
    13311316    }
    13321317    if (!isGuestAdditionsAvailable())
    13331318    {
    1334         m_enmCheckMachine = CheckMachine_NoGuestAdditions;
    1335         return false;
    1336     }
    1337     m_enmCheckMachine = CheckMachine_SessionPossible;
    1338     return true;
     1319        m_enmState = State_NoGuestAdditions;
     1320        return;
     1321    }
     1322    if (!m_comGuestSession.isNull() && m_comGuestSession.GetStatus() == KGuestSessionStatus_Started)
     1323    {
     1324        m_enmState = State_SessionRunning;
     1325        return;
     1326    }
     1327    m_enmState = State_SessionPossible;
     1328}
     1329
     1330void UIFileManagerGuestTable::setStateAndEnableWidgets()
     1331{
     1332    setState();
     1333    setSessionDependentWidgetsEnabled();
     1334    retranslateUi();
    13391335}
    13401336
    13411337void UIFileManagerGuestTable::sltHandleCloseSessionRequest()
    13421338{
    1343     cleanupGuestSessionListener();
    1344 
    13451339    closeGuestSession();
    13461340}
     
    13551349void UIFileManagerGuestTable::sltAdditionsStateChange()
    13561350{
    1357     setSessionDependentWidgetsEnabled(isSessionPossible());
    1358 
    1359 }
    1360 
    1361 void UIFileManagerGuestTable::setSessionDependentWidgetsEnabled(bool pEnabled)
    1362 {
    1363     UIFileManagerTable::setSessionDependentWidgetsEnabled(pEnabled);
    1364     if (m_pGuestSessionPanel)
    1365         m_pGuestSessionPanel->setEnabled(pEnabled);
     1351    setStateAndEnableWidgets();
     1352}
     1353
     1354void UIFileManagerGuestTable::setSessionDependentWidgetsEnabled()
     1355{
     1356    switch (m_enmState)
     1357    {
     1358        case State_InvalidMachineReference:
     1359        case State_MachineNotRunning:
     1360        case State_NoGuestAdditions:
     1361            setSessionWidgetsEnabled(false);
     1362            m_pWarningLabel->setVisible(true);
     1363            m_pGuestSessionPanel->setEnabled(false);
     1364            break;
     1365        case State_SessionPossible:
     1366            setSessionWidgetsEnabled(false);
     1367            m_pWarningLabel->setVisible(true);
     1368            m_pGuestSessionPanel->setEnabled(true);
     1369            break;
     1370        case State_SessionRunning:
     1371            setSessionWidgetsEnabled(true);
     1372            m_pWarningLabel->setVisible(false);
     1373            m_pGuestSessionPanel->setEnabled(true);
     1374            break;
     1375        default:
     1376            break;
     1377    }
    13661378}
    13671379
     
    14081420void UIFileManagerGuestTable::closeGuestSession()
    14091421{
     1422    cleanupGuestSessionListener();
    14101423    if (!m_comGuestSession.isNull())
    1411     {
    14121424        m_comGuestSession.Close();
    1413         m_comGuestSession.detach();
    1414         emit sigLogOutput("Guest session is closed", m_strTableName, FileManagerLogType_Info);
    1415     }
    1416     reset();
    1417     postGuestSessionClosed();
     1425    // if (!m_comGuestSession.isNull())
     1426    // {
     1427    //     m_comGuestSession.Close();
     1428    //     m_comGuestSession.detach();
     1429    //     emit sigLogOutput("Guest session is closed", m_strTableName, FileManagerLogType_Info);
     1430    // }
     1431    // reset();
     1432    // postGuestSessionClosed();
    14181433}
    14191434
    14201435void UIFileManagerGuestTable::cleanAll()
    14211436{
     1437    printf("UIFileManagerGuestTable::cleanAll()\n");
     1438
    14221439    cleanupConsoleListener();
    14231440    cleanupGuestListener();
  • trunk/src/VBox/Frontends/VirtualBox/src/guestctrl/UIFileManagerGuestTable.h

    r92847 r92860  
    8787        virtual void  pasteCutCopiedObjects() override final;
    8888    /** @} */
    89     /** Returns false if it is not possible to open a guest session on the machine.
    90       * That is if machine is not running etc. */
    91     virtual bool isSessionPossible() override final;
    92     virtual void  setSessionDependentWidgetsEnabled(bool fEnabled) override final;
     89    virtual void  setState();
     90    virtual void  setSessionDependentWidgetsEnabled();
    9391
    9492private slots:
    9593
    9694    void sltGuestSessionPanelToggled(bool fChecked);
    97     // void sltHandleGuestSessionPanelHidden();
    98     // void sltHandleGuestSessionPanelShown();
    9995    void sltGuestSessionUnregistered(CGuestSession guestSession);
    10096    void sltGuestSessionRegistered(CGuestSession guestSession);
     
    108104private:
    109105
    110     enum CheckMachine
     106    enum State
    111107    {
    112         CheckMachine_InvalidMachineReference,
    113         CheckMachine_MachineNotRunning,
    114         CheckMachine_NoGuestAdditions,
    115         CheckMachine_SessionPossible
     108        State_InvalidMachineReference,
     109        State_MachineNotRunning,
     110        State_NoGuestAdditions,
     111        State_SessionPossible,
     112        State_SessionRunning,
     113        State_Max
    116114    };
    117115
     
    134132    void cleanupGuestSessionListener();
    135133    void cleanupConsoleListener();
    136 
    137134    void prepareGuestSessionPanel();
    138 
    139135    bool openGuestSession(const QString& strUserName, const QString& strPassword);
    140136    void closeGuestSession();
    141 
    142137    bool openMachineSession();
    143138    bool closeMachineSession();
    144 
    145139    bool isGuestAdditionsAvailable();
     140    void setStateAndEnableWidgets();
    146141
    147142    /** @name Perform operations needed after creating/ending a guest control session
     
    168163    UIGuestSessionCreateWidget *m_pGuestSessionPanel;
    169164;
    170     CheckMachine m_enmCheckMachine;
     165    State m_enmState;
    171166};
    172167
  • trunk/src/VBox/Frontends/VirtualBox/src/guestctrl/UIFileManagerHostTable.cpp

    r92765 r92860  
    533533}
    534534
    535 bool UIFileManagerHostTable::isSessionPossible()
    536 {
    537     return true;
    538 }
    539 
    540535#include "UIFileManagerHostTable.moc"
  • trunk/src/VBox/Frontends/VirtualBox/src/guestctrl/UIFileManagerHostTable.h

    r92766 r92860  
    5959    virtual void    prepareToolbar() override final;
    6060    virtual void    createFileViewContextMenu(const QWidget *pWidget, const QPoint &point) override final;
    61     virtual bool     isSessionPossible() override final;
    6261    /** @name Copy/Cut host-to-host stuff. Currently not implemented.
    6362     * @{ */
  • trunk/src/VBox/Frontends/VirtualBox/src/guestctrl/UIFileManagerTable.cpp

    r92765 r92860  
    746746        m_pToolBar = new QIToolBar;
    747747        if (m_pToolBar)
     748        {
    748749            m_pToolBarLayout->addWidget(m_pToolBar);
     750            m_sessionWidgets << m_pToolBar;
     751        }
    749752
    750753        m_pMainLayout->addLayout(m_pToolBarLayout, 0, 0, 1, 7);
     
    753756    m_pLocationLabel = new QILabel;
    754757    if (m_pLocationLabel)
     758    {
    755759        m_pMainLayout->addWidget(m_pLocationLabel, 1, 0, 1, 1);
     760        m_sessionWidgets << m_pLocationLabel;
     761    }
    756762
    757763    m_pNavigationWidget = new UIFileManagerNavigationWidget;
     
    762768                this, &UIFileManagerTable::sltHandleNavigationWidgetPathChange);
    763769        m_pMainLayout->addWidget(m_pNavigationWidget, 1, 1, 1, 6);
     770        m_sessionWidgets << m_pNavigationWidget;
    764771    }
    765772
     
    804811        m_pView->hideColumn(UICustomFileSystemModelColumn_Path);
    805812        m_pView->hideColumn(UICustomFileSystemModelColumn_LocalPath);
     813        m_sessionWidgets << m_pView;
    806814    }
    807815    m_pWarningLabel = new QILabel(this);
     
    821829    }
    822830    m_pWarningLabel->setVisible(false);
    823     // m_pView->setVisible(isSessionPossible());
    824831
    825832    m_pSearchLineEdit = new QILineEdit;
     
    16131620}
    16141621
    1615 void UIFileManagerTable::setSessionDependentWidgetsEnabled(bool fEnabled)
    1616 {
    1617     if (m_pWarningLabel)
    1618         m_pWarningLabel->setVisible(!fEnabled);
    1619     if (m_pView)
    1620         m_pView->setEnabled(fEnabled);
    1621     if (m_pNavigationWidget)
    1622         m_pNavigationWidget->setEnabled(fEnabled);
    1623     if (m_pLocationLabel)
    1624         m_pLocationLabel->setEnabled(fEnabled);
    1625     if (m_pToolBar)
    1626         m_pToolBar->setEnabled(fEnabled);
    1627 }
    1628 
     1622void UIFileManagerTable::setSessionWidgetsEnabled(bool fEnabled)
     1623{
     1624    foreach (QWidget *pWidget, m_sessionWidgets)
     1625    {
     1626        if (pWidget)
     1627            pWidget->setEnabled(fEnabled);
     1628    }
     1629}
    16291630#include "UIFileManagerTable.moc"
  • trunk/src/VBox/Frontends/VirtualBox/src/guestctrl/UIFileManagerTable.h

    r92765 r92860  
    211211    virtual void     determinePathSeparator() = 0;
    212212    virtual void     prepareToolbar() = 0;
    213     /** Returns true if file system can be shown. */
    214     virtual bool     isSessionPossible() = 0;
    215213    virtual void     createFileViewContextMenu(const QWidget *pWidget, const QPoint &point) = 0;
    216214    virtual bool     event(QEvent *pEvent) /* override */;
     
    239237    void             setPathSeparator(const QChar &separator);
    240238    QHBoxLayout*     toolBarLayout();
    241     virtual void     setSessionDependentWidgetsEnabled(bool fEnabled);
     239    void             setSessionWidgetsEnabled(bool fEnabled);
    242240
    243241    QILabel                 *m_pLocationLabel;
     
    308306    QChar            m_pathSeparator;
    309307    QHBoxLayout     *m_pToolBarLayout;
     308    QVector<QWidget*> m_sessionWidgets;
    310309    friend class     UICustomFileSystemModel;
    311310};
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