VirtualBox

Changeset 92765 in vbox for trunk/src/VBox


Ignore:
Timestamp:
Dec 6, 2021 2:23:24 PM (3 years ago)
Author:
vboxsync
Message:

FE/Qt: bugref:9371. Enabling/disabling guest session dependent widgets.

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

Legend:

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

    r92754 r92765  
    3434#include "UIMessageCenter.h"
    3535#include "UIPathOperations.h"
     36#include "UIVirtualBoxEventHandler.h"
    3637#include "QIToolBar.h"
    3738
     
    155156    , m_comMachine(comMachine)
    156157    , m_pGuestSessionPanel(0)
    157     , m_pSessionWidgetToggleToolBar(0)
    158158{
    159159    if (!m_comMachine.isNull())
     
    162162    prepareGuestSessionPanel();
    163163    prepareActionConnections();
     164    setSessionDependentWidgetsEnabled(isSessionPossible());
     165
     166    connect(gVBoxEvents, &UIVirtualBoxEventHandler::sigMachineStateChange,
     167            this, &UIFileManagerGuestTable::sltMachineStateChange);
     168    if (m_pActionPool && m_pActionPool->action(UIActionIndex_M_FileManager_T_GuestSession))
     169        m_pActionPool->action(UIActionIndex_M_FileManager_T_GuestSession)->setChecked(true);
    164170    retranslateUi();
    165171}
     
    178184    if (m_pLocationLabel)
    179185        m_pLocationLabel->setText(UIFileManager::tr("Guest File System:"));
     186
     187    if (m_pWarningLabel)
     188    {
     189        QString strWarningText;
     190        switch (m_enmCheckMachine)
     191        {
     192            case CheckMachine_InvalidMachineReference:
     193                strWarningText = UIFileManager::tr("Machine reference is invalid.");
     194                break;
     195            case CheckMachine_MachineNotRunning:
     196                strWarningText = UIFileManager::tr("Guest system is not running. File manager work only on running guests.");
     197                break;
     198            case CheckMachine_NoGuestAdditions:
     199                strWarningText = UIFileManager::tr("No guest additions is found on the guest system. File manager needs guest additions to function correctly.");
     200                break;
     201            case CheckMachine_SessionPossible:
     202            default:
     203                break;
     204        }
     205        m_pWarningLabel->setText(QString("<p>%1</p>").arg(strWarningText));
     206    }
     207
    180208    UIFileManagerTable::retranslateUi();
    181209}
     
    671699        m_pActionPool->action(UIActionIndex_M_FileManager_S_Guest_Cut)->setVisible(false);
    672700        m_pActionPool->action(UIActionIndex_M_FileManager_S_Guest_Paste)->setVisible(false);
     701
     702        m_pToolBar->addSeparator();
     703        m_pToolBar->addAction(m_pActionPool->action(UIActionIndex_M_FileManager_T_GuestSession));
    673704    }
    674705
    675706    setSelectionDependentActionsEnabled(false);
    676707    setPasteActionEnabled(false);
    677 
    678     m_pSessionWidgetToggleToolBar = new QIToolBar;
    679     if (m_pSessionWidgetToggleToolBar && toolBarLayout())
    680     {
    681         m_pSessionWidgetToggleToolBar->addAction(m_pActionPool->action(UIActionIndex_M_FileManager_T_GuestSession));
    682         QWidget *pSpaceWidget = new QWidget;
    683         pSpaceWidget->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Preferred);
    684         toolBarLayout()->addWidget(pSpaceWidget);
    685         toolBarLayout()->addWidget(m_pSessionWidgetToggleToolBar);
    686     }
    687708}
    688709
     
    835856}
    836857
     858void UIFileManagerGuestTable::sltMachineStateChange(const QUuid &uMachineId, const KMachineState )
     859{
     860    if (uMachineId.isNull() || m_comMachine.isNull() || uMachineId != m_comMachine.GetId())
     861        return;
     862    setSessionDependentWidgetsEnabled(isSessionPossible());
     863    retranslateUi();
     864}
     865
    837866bool UIFileManagerGuestTable::openSession(const QString &strUserName, const QString &strPassword)
    838867{
     
    897926}
    898927
    899 bool UIFileManagerGuestTable::isGuestAdditionsAvailable(const CGuest &guest)
    900 {
    901     if (!guest.isOk())
    902         return false;
    903     CGuest guestNonConst = const_cast<CGuest&>(guest);
    904     return guestNonConst.GetAdditionsStatus(guestNonConst.GetAdditionsRunLevel());
     928bool UIFileManagerGuestTable::isGuestAdditionsAvailable(CGuest &guest)
     929{
     930    if (guest.isNull())
     931        return false;
     932
     933    return guest.GetAdditionsStatus(guest.GetAdditionsRunLevel());
     934}
     935
     936bool UIFileManagerGuestTable::isGuestAdditionsAvailable()
     937{
     938    if (m_comMachine.isNull())
     939        return false;
     940    CSession comSession = uiCommon().openSession(m_comMachine.GetId(), KLockType_Shared);
     941    if (comSession.isNull())
     942        return false;
     943    CConsole comConsole = comSession.GetConsole();
     944    if (comConsole.isNull())
     945        return false;
     946    CGuest comGuest = comConsole.GetGuest();
     947    if (comGuest.isNull())
     948        return false;
     949    return comGuest.GetAdditionsStatus(comGuest.GetAdditionsRunLevel());
    905950}
    906951
     
    10301075}
    10311076
    1032 bool UIFileManagerGuestTable::isGuestSessionPossible()
     1077bool UIFileManagerGuestTable::isSessionPossible()
    10331078{
    10341079    if (m_comMachine.isNull())
    1035         return false;
     1080    {
     1081        m_enmCheckMachine = CheckMachine_InvalidMachineReference;
     1082        return false;
     1083    }
    10361084    if (m_comMachine.GetState() != KMachineState_Running)
    1037         return false;
    1038     if (!checkGuestSession())
    1039         return false;
     1085    {
     1086        m_enmCheckMachine = CheckMachine_MachineNotRunning;
     1087        return false;
     1088    }
     1089    if (!isGuestAdditionsAvailable())
     1090    {
     1091        m_enmCheckMachine = CheckMachine_NoGuestAdditions;
     1092        return false;
     1093    }
     1094    m_enmCheckMachine = CheckMachine_SessionPossible;
    10401095    return true;
    10411096}
     
    10451100}
    10461101
     1102void UIFileManagerGuestTable::setSessionDependentWidgetsEnabled(bool pEnabled)
     1103{
     1104    UIFileManagerTable::setSessionDependentWidgetsEnabled(pEnabled);
     1105    if (m_pGuestSessionPanel)
     1106        m_pGuestSessionPanel->setEnabled(pEnabled);
     1107}
    10471108
    10481109/*////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////*/
  • trunk/src/VBox/Frontends/VirtualBox/src/guestctrl/UIFileManagerGuestTable.h

    r92754 r92765  
    6565protected:
    6666
    67     void            retranslateUi() /* override */;
    68     virtual void    readDirectory(const QString& strPath, UICustomFileSystemItem *parent, bool isStartDir = false) /* override */;
    69     virtual void    deleteByItem(UICustomFileSystemItem *item) /* override */;
    70     virtual void    deleteByPath(const QStringList &pathList) /* override */;
    71     virtual void    goToHomeDirectory() /* override */;
     67    void            retranslateUi() override final;
     68    virtual void    readDirectory(const QString& strPath, UICustomFileSystemItem *parent, bool isStartDir = false) override final;
     69    virtual void    deleteByItem(UICustomFileSystemItem *item) override final;
     70    virtual void    deleteByPath(const QStringList &pathList) override final;
     71    virtual void    goToHomeDirectory() override final;
    7272    virtual bool    renameItem(UICustomFileSystemItem *item, QString newBaseName);
    7373    virtual bool    createDirectory(const QString &path, const QString &directoryName);
    74     virtual QString fsObjectPropertyString() /* override */;
    75     virtual void    showProperties() /* override */;
    76     virtual void    determineDriveLetters() /* override */;
    77     virtual void    determinePathSeparator() /* override */;
    78     virtual void    prepareToolbar() /* override */;
    79     virtual void    createFileViewContextMenu(const QWidget *pWidget, const QPoint &point) /* override */;
     74    virtual QString fsObjectPropertyString() override final;
     75    virtual void    showProperties() override final;
     76    virtual void    determineDriveLetters() override final;
     77    virtual void    determinePathSeparator() override final;
     78    virtual void    prepareToolbar() override final;
     79    virtual void    createFileViewContextMenu(const QWidget *pWidget, const QPoint &point) override final;
    8080    /** @name Copy/Cut guest-to-guest stuff.
    8181     * @{ */
    8282        /** Disable/enable paste action depending on the m_eFileOperationType. */
    83         virtual void  setPasteActionEnabled(bool fEnabled) /* override */;
    84         virtual void  pasteCutCopiedObjects() /* override */;
     83        virtual void  setPasteActionEnabled(bool fEnabled) override final;
     84        virtual void  pasteCutCopiedObjects() override final;
    8585    /** @} */
     86    /** Returns false if it is not possible to open a guest session on the machine.
     87      * That is if machine is not running etc. */
     88    virtual bool isSessionPossible() override final;
     89    virtual void  setSessionDependentWidgetsEnabled(bool fEnabled) override final;
    8690
    8791private slots:
     
    9599    void sltCreateGuestSession(QString strUserName, QString strPassword);
    96100    void sltHandleCloseSessionRequest();
     101    void sltMachineStateChange(const QUuid &uMachineId, const KMachineState state);
    97102
    98103private:
     104
     105    enum CheckMachine
     106    {
     107        CheckMachine_InvalidMachineReference,
     108        CheckMachine_MachineNotRunning,
     109        CheckMachine_NoGuestAdditions,
     110        CheckMachine_SessionPossible
     111    };
    99112
    100113    KFsObjType  fileType(const CFsObjInfo &fsInfo);
     
    119132    /** Creates a shared machine session, opens a guest session and registers event listeners. */
    120133    bool openSession(const QString& strUserName, const QString& strPassword);
    121     bool isGuestAdditionsAvailable(const CGuest &guest);
     134    bool isGuestAdditionsAvailable(CGuest &guest);
     135    bool isGuestAdditionsAvailable();
    122136
    123137    /** @name Perform operations needed after creating/ending a guest control session
     
    128142
    129143    void initFileTable();
    130     /** Returns false if it is not possible to open a guest session on the machine.
    131       * That is if machine is not running, or does not have guest additions etc. */
    132     bool isGuestSessionPossible();
     144
    133145
    134146    CGuest                    m_comGuest;
     
    142154    CEventListener m_comGuestListener;
    143155    UIFileManagerGuestSessionPanel     *m_pGuestSessionPanel;
    144     /** Hosts only a single action. We seperate this action since others
    145       * are contained in the main toolbar which is dynamically disabled/enabled. */
    146     QIToolBar               *m_pSessionWidgetToggleToolBar;
     156    CheckMachine m_enmCheckMachine;
    147157};
    148158
  • trunk/src/VBox/Frontends/VirtualBox/src/guestctrl/UIFileManagerHostTable.cpp

    r92733 r92765  
    173173    if (m_pLocationLabel)
    174174        m_pLocationLabel->setText(UIFileManager::tr("Host File System:"));
     175    m_strTableName = UIFileManager::tr("Host");
    175176    UIFileManagerTable::retranslateUi();
    176177}
     
    532533}
    533534
     535bool UIFileManagerHostTable::isSessionPossible()
     536{
     537    return true;
     538}
     539
    534540#include "UIFileManagerHostTable.moc"
  • trunk/src/VBox/Frontends/VirtualBox/src/guestctrl/UIFileManagerHostTable.h

    r82968 r92765  
    4646    static void scanDirectory(const QString& strPath, UICustomFileSystemItem *parent,
    4747                              QMap<QString, UICustomFileSystemItem*> &fileObjects);
    48     void            retranslateUi() /* override */;
    49     virtual void    readDirectory(const QString& strPath, UICustomFileSystemItem *parent, bool isStartDir = false) /* override */;
    50     virtual void    deleteByItem(UICustomFileSystemItem *item) /* override */;
    51     virtual void    deleteByPath(const QStringList &pathList) /* override */;
    52     virtual void    goToHomeDirectory() /* override */;
     48    void            retranslateUi() override final;
     49    virtual void    readDirectory(const QString& strPath, UICustomFileSystemItem *parent, bool isStartDir = false) override final;
     50    virtual void    deleteByItem(UICustomFileSystemItem *item) override final;
     51    virtual void    deleteByPath(const QStringList &pathList) override final;
     52    virtual void    goToHomeDirectory() override final;
    5353    virtual bool    renameItem(UICustomFileSystemItem *item, QString newBaseName);
    5454    virtual bool    createDirectory(const QString &path, const QString &directoryName);
    55     virtual QString fsObjectPropertyString() /* override */;
    56     virtual void    showProperties() /* override */;
    57     virtual void    determineDriveLetters() /* override */;
    58     virtual void    determinePathSeparator() /* override */;
    59     virtual void    prepareToolbar() /* override */;
    60     virtual void    createFileViewContextMenu(const QWidget *pWidget, const QPoint &point) /* override */;
     55    virtual QString fsObjectPropertyString() override final;
     56    virtual void    showProperties() override final;
     57    virtual void    determineDriveLetters() override final;
     58    virtual void    determinePathSeparator() override final;
     59    virtual void    prepareToolbar() override final;
     60    virtual void    createFileViewContextMenu(const QWidget *pWidget, const QPoint &point) override final;
     61    virtual bool     isSessionPossible() override final;
    6162    /** @name Copy/Cut host-to-host stuff. Currently not implemented.
    6263     * @{ */
  • trunk/src/VBox/Frontends/VirtualBox/src/guestctrl/UIFileManagerTable.cpp

    r92754 r92765  
    705705    , m_pToolBar(0)
    706706    , m_pMainLayout(0)
     707    , m_pWarningLabel(0)
    707708    , m_pModel(0)
    708709    , m_pView(0)
    709710    , m_pProxyModel(0)
    710711    , m_pNavigationWidget(0)
    711     , m_pWarningLabel(0)
    712712    , m_pathSeparator('/')
    713713    , m_pToolBarLayout(0)
     
    820820        m_pWarningLabel->setWordWrap(true);
    821821    }
    822     m_pWarningLabel->setVisible(!isEnabled());
    823     m_pView->setVisible(isEnabled());
     822    m_pWarningLabel->setVisible(false);
     823    // m_pView->setVisible(isSessionPossible());
    824824
    825825    m_pSearchLineEdit = new QILineEdit;
     
    13081308        pRootItem->setData(UIFileManager::tr("Permissions"), UICustomFileSystemModelColumn_Permissions);
    13091309    }
    1310     if (m_pWarningLabel)
    1311         m_pWarningLabel->setText(UIFileManager::tr("<p>No Guest Session found! Please use the Session Panel to start a new guest session</p>"));
    1312     m_strTableName = UIFileManager::tr("Host");
    13131310}
    13141311
     
    16161613}
    16171614
     1615void 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
    16181629#include "UIFileManagerTable.moc"
  • trunk/src/VBox/Frontends/VirtualBox/src/guestctrl/UIFileManagerTable.h

    r92754 r92765  
    211211    virtual void     determinePathSeparator() = 0;
    212212    virtual void     prepareToolbar() = 0;
     213    /** Returns true if file system can be shown. */
     214    virtual bool     isSessionPossible() = 0;
    213215    virtual void     createFileViewContextMenu(const QWidget *pWidget, const QPoint &point) = 0;
    214216    virtual bool     event(QEvent *pEvent) /* override */;
     
    237239    void             setPathSeparator(const QChar &separator);
    238240    QHBoxLayout*     toolBarLayout();
     241    virtual void     setSessionDependentWidgetsEnabled(bool fEnabled);
    239242
    240243    QILabel                 *m_pLocationLabel;
     
    254257    /** This name is appended to the log messages which are shown in the log panel. */
    255258    QString          m_strTableName;
     259    QILabel         *m_pWarningLabel;
    256260
    257261private slots:
     
    302306    QColor           m_searchLineUnmarkColor;
    303307    QColor           m_searchLineMarkColor;
    304     QILabel         *m_pWarningLabel;
    305308    QChar            m_pathSeparator;
    306309    QHBoxLayout     *m_pToolBarLayout;
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