VirtualBox

Changeset 92688 in vbox


Ignore:
Timestamp:
Dec 2, 2021 10:20:41 AM (3 years ago)
Author:
vboxsync
Message:

FE/Qt: bugref:9371. Refactoring in file manager to support multiple guest sessions.

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

Legend:

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

    r92645 r92688  
    2222
    2323/* GUI includes: */
     24#include "QITabWidget.h"
    2425#include "QITreeWidget.h"
    2526#include "QIToolBar.h"
     
    3839#include "UIFileManagerHostTable.h"
    3940#include "UIGuestControlInterface.h"
     41#include "UIVirtualMachineItem.h"
    4042
    4143/* COM includes: */
     
    115117                             const CMachine &comMachine, QWidget *pParent, bool fShowToolbar)
    116118    : QIWithRetranslateUI<QWidget>(pParent)
    117     , m_comMachine(comMachine)
    118119    , m_pMainLayout(0)
    119120    , m_pVerticalSplitter(0)
    120121    , m_pFileTableSplitter(0)
    121122    , m_pToolBar(0)
    122     , m_pVerticalToolBar(0)
    123     , m_pGuestFileTable(0)
     123    , m_pVerticalToolBar(0)\
    124124    , m_pHostFileTable(0)
     125    , m_pGuestTablesContainer(0)
    125126    , m_enmEmbedding(enmEmbedding)
    126127    , m_pActionPool(pActionPool)
     
    139140    UIFileManagerOptions::create();
    140141    uiCommon().setHelpKeyword(this, "guestadd-gc-file-manager");
    141     connect(&uiCommon(), &UICommon::sigAskToDetachCOM, this, &UIFileManager::sltCleanupListenerAndGuest);
     142    //connect(&uiCommon(), &UICommon::sigAskToDetachCOM, this, &UIFileManager::sltCleanupListenerAndGuest);
     143    Q_UNUSED(comMachine);
    142144}
    143145
     
    145147{
    146148    UIFileManagerOptions::destroy();
    147 }
    148 
    149 void UIFileManager::setMachine(const QUuid &machineId)
    150 {
    151     m_comMachine = uiCommon().virtualBox().FindMachine(machineId.toString());
    152149}
    153150
     
    206203        m_pFileTableSplitter->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Expanding);
    207204        m_pFileTableSplitter->setContentsMargins(0, 0, 0, 0);
    208         m_pGuestFileTable = new UIFileManagerGuestTable(m_pActionPool);
    209         m_pGuestFileTable->setEnabled(false);
    210205
    211206        /* This widget hosts host file table and vertical toolbar. */
     
    221216        m_pFileTableSplitter->addWidget(pHostTableAndVerticalToolbarWidget);
    222217        prepareVerticalToolBar(pHostTableAndVerticalToolbarLayout);
    223         if (m_pGuestFileTable)
    224             m_pFileTableSplitter->addWidget(m_pGuestFileTable);
     218
     219        m_pGuestTablesContainer = new QITabWidget;
     220        if (m_pGuestTablesContainer)
     221        {
     222            m_pGuestTablesContainer->setTabBarAutoHide(true);
     223            m_pFileTableSplitter->addWidget(m_pGuestTablesContainer);
     224        }
    225225    }
    226226
     
    302302                    this, &UIFileManager::sltCopyHostToGuest);
    303303    }
    304     if (m_pGuestSessionPanel)
    305     {
    306         connect(m_pGuestSessionPanel, &UIFileManagerGuestSessionPanel::sigCreateSession,
    307                 this, &UIFileManager::sltCreateGuestSession);
    308         connect(m_pGuestSessionPanel, &UIFileManagerGuestSessionPanel::sigCloseSession,
    309                 this, &UIFileManager::sltCloseGuestSession);
    310         connect(m_pGuestSessionPanel, &UIFileManagerGuestSessionPanel::sigHidePanel,
    311                 this, &UIFileManager::sltHandleHidePanel);
    312     }
    313304    if (m_pOptionsPanel)
    314305    {
     
    330321                this, &UIFileManager::sltReceieveLogOutput);
    331322        connect(m_pHostFileTable, &UIFileManagerHostTable::sigDeleteConfirmationOptionChanged,
    332                 this, &UIFileManager::sltHandleOptionsUpdated);
    333     }
    334     if (m_pGuestFileTable)
    335     {
    336         connect(m_pGuestFileTable, &UIFileManagerGuestTable::sigLogOutput,
    337                 this, &UIFileManager::sltReceieveLogOutput);
    338         connect(m_pGuestFileTable, &UIFileManagerGuestTable::sigNewFileOperation,
    339                 this, &UIFileManager::sltReceieveNewFileOperation);
    340         connect(m_pGuestFileTable, &UIFileManagerGuestTable::sigDeleteConfirmationOptionChanged,
    341323                this, &UIFileManager::sltHandleOptionsUpdated);
    342324    }
     
    373355}
    374356
    375 void UIFileManager::sltGuestSessionUnregistered(CGuestSession guestSession)
    376 {
    377     if (guestSession.isNull())
    378         return;
    379     if (guestSession == m_comGuestSession && !m_comGuestSession.isNull())
    380     {
    381         m_comGuestSession.detach();
    382         postGuestSessionClosed();
    383         appendLog("Guest session unregistered", FileManagerLogType_Info);
    384     }
    385 }
    386 
    387 void UIFileManager::sltGuestSessionRegistered(CGuestSession guestSession)
    388 {
    389     if (guestSession == m_comGuestSession && !m_comGuestSession.isNull())
    390         appendLog("Guest session registered", FileManagerLogType_Info);
    391 }
    392 
    393 
    394 void UIFileManager::sltCreateGuestSession(QString strUserName, QString strPassword)
    395 {
    396     if (strUserName.isEmpty())
    397     {
    398         appendLog("No user name is given", FileManagerLogType_Error);
    399         if (m_pGuestSessionPanel)
    400             m_pGuestSessionPanel->markForError(true);
    401         return;
    402     }
    403     if (m_pGuestSessionPanel)
    404         m_pGuestSessionPanel->markForError(!openSession(strUserName, strPassword));
    405 }
    406 
    407 void UIFileManager::sltCloseGuestSession()
    408 {
    409     if (!m_comGuestSession.isOk())
    410     {
    411         appendLog("Guest session is not valid", FileManagerLogType_Error);
    412         postGuestSessionClosed();
    413         return;
    414     }
    415     if (m_pGuestFileTable)
    416         m_pGuestFileTable->reset();
    417 
    418     if (m_comGuestSession.isOk() && m_pQtSessionListener && m_comSessionListener.isOk())
    419         cleanupListener(m_pQtSessionListener, m_comSessionListener, m_comGuestSession.GetEventSource());
    420 
    421     m_comGuestSession.Close();
    422     appendLog("Guest session is closed", FileManagerLogType_Info);
    423     postGuestSessionClosed();
    424 }
    425 
    426 void UIFileManager::sltGuestSessionStateChanged(const CGuestSessionStateChangedEvent &cEvent)
    427 {
    428     if (cEvent.isOk())
    429     {
    430         CVirtualBoxErrorInfo cErrorInfo = cEvent.GetError();
    431         if (cErrorInfo.isOk() && !cErrorInfo.GetText().contains("success", Qt::CaseInsensitive))
    432             appendLog(cErrorInfo.GetText(), FileManagerLogType_Error);
    433     }
    434     if (m_comGuestSession.isOk())
    435     {
    436         if (m_comGuestSession.GetStatus() == KGuestSessionStatus_Started)
    437         {
    438             initFileTable();
    439             postGuestSessionCreated();
    440         }
    441         appendLog(QString("%1: %2").arg("Guest session status has changed").arg(gpConverter->toString(m_comGuestSession.GetStatus())),
    442                   FileManagerLogType_Info);
    443     }
    444     else
    445         appendLog("Guest session is not valid", FileManagerLogType_Error);
    446 }
    447 
    448357void UIFileManager::sltReceieveLogOutput(QString strOutput, FileManagerLogType eLogType)
    449358{
     
    491400{
    492401    Q_UNUSED(progressId);
    493     if (!m_pGuestFileTable || !m_pHostFileTable)
    494         return;
    495 
    496     m_pHostFileTable->refresh();
    497     m_pGuestFileTable->refresh();
     402    if (m_pHostFileTable)
     403        m_pHostFileTable->refresh();
     404    // @todo we need to refresh only the table from which the completed file operation has originated
     405    for (int i = 0; i < m_pGuestTablesContainer->count(); ++i)
     406    {
     407        UIFileManagerGuestTable *pTable = qobject_cast<UIFileManagerGuestTable*>(m_pGuestTablesContainer->widget(i));
     408        if (pTable)
     409            pTable->refresh();
     410    }
    498411}
    499412
     
    503416        m_pOptionsPanel->update();
    504417
    505     if (m_pGuestFileTable)
    506         m_pGuestFileTable->optionsUpdated();
     418    for (int i = 0; i < m_pGuestTablesContainer->count(); ++i)
     419    {
     420        UIFileManagerGuestTable *pTable = qobject_cast<UIFileManagerGuestTable*>(m_pGuestTablesContainer->widget(i));
     421        if (pTable)
     422            pTable->optionsUpdated();
     423    }
    507424    if (m_pHostFileTable)
    508425        m_pHostFileTable->optionsUpdated();
     
    515432}
    516433
    517 void UIFileManager::sltCleanupListenerAndGuest()
    518 {
    519     if (m_comGuest.isOk() && m_pQtGuestListener && m_comGuestListener.isOk())
    520         cleanupListener(m_pQtGuestListener, m_comGuestListener, m_comGuest.GetEventSource());
    521     if (m_comGuestSession.isOk() && m_pQtSessionListener && m_comSessionListener.isOk())
    522         cleanupListener(m_pQtSessionListener, m_comSessionListener, m_comGuestSession.GetEventSource());
    523 
    524     if (m_comGuestSession.isOk())
    525         m_comGuestSession.Close();
    526 }
    527 
    528434void UIFileManager::copyToHost()
    529435{
    530     if (!m_pGuestFileTable || !m_pHostFileTable)
    531         return;
    532     QString hostDestinationPath = m_pHostFileTable->currentDirectoryPath();
    533     m_pGuestFileTable->copyGuestToHost(hostDestinationPath);
    534     m_pHostFileTable->refresh();
     436    if (m_pGuestTablesContainer && m_pHostFileTable)
     437    {
     438        UIFileManagerGuestTable *pGuestFileTable = qobject_cast<UIFileManagerGuestTable*>(m_pGuestTablesContainer->currentWidget());
     439        if (pGuestFileTable)
     440            pGuestFileTable->copyGuestToHost(m_pHostFileTable->currentDirectoryPath());
     441    }
    535442}
    536443
    537444void UIFileManager::copyToGuest()
    538445{
    539     if (!m_pGuestFileTable || !m_pHostFileTable)
    540         return;
    541     QStringList hostSourcePathList = m_pHostFileTable->selectedItemPathList();
    542     m_pGuestFileTable->copyHostToGuest(hostSourcePathList);
    543     m_pGuestFileTable->refresh();
    544 }
    545 
    546 void UIFileManager::initFileTable()
    547 {
    548     if (!m_comGuestSession.isOk() || m_comGuestSession.GetStatus() != KGuestSessionStatus_Started)
    549         return;
    550     if (!m_pGuestFileTable)
    551         return;
    552     m_pGuestFileTable->initGuestFileTable(m_comGuestSession);
    553 }
    554 
    555 void UIFileManager::postGuestSessionCreated()
    556 {
    557     if (m_pGuestSessionPanel)
    558         m_pGuestSessionPanel->switchSessionCloseMode();
    559     if (m_pGuestFileTable)
    560         m_pGuestFileTable->setEnabled(true);
    561     if (m_pVerticalToolBar)
    562         m_pVerticalToolBar->setEnabled(true);
    563 }
    564 
    565 void UIFileManager::postGuestSessionClosed()
    566 {
    567     if (m_pGuestSessionPanel)
    568         m_pGuestSessionPanel->switchSessionCreateMode();
    569     if (m_pGuestFileTable)
    570         m_pGuestFileTable->setEnabled(false);
    571     if (m_pVerticalToolBar)
    572         m_pVerticalToolBar->setEnabled(false);
    573 }
    574 
    575 bool UIFileManager::openSession(const QString& strUserName, const QString& strPassword)
    576 {
    577     if (m_comMachine.isNull())
    578     {
    579         appendLog("Invalid machine reference", FileManagerLogType_Error);
    580         return false;
    581     }
    582     m_comSession = uiCommon().openSession(m_comMachine.GetId(), KLockType_Shared);
    583     if (!m_comSession.isNull())
    584     {
    585         appendLog("Could not open machine session", FileManagerLogType_Error);
    586         return false;
    587     }
    588 
    589     CConsole comConsole = m_comSession.GetConsole();
    590     AssertReturn(!comConsole.isNull(), false);
    591     m_comGuest = comConsole.GetGuest();
    592     AssertReturn(!m_comGuest.isNull(), false);
    593 
    594     if (!isGuestAdditionsAvailable(m_comGuest))
    595     {
    596         appendLog("Could not find Guest Additions", FileManagerLogType_Error);
    597         postGuestSessionClosed();
    598         if (m_pGuestSessionPanel)
    599             m_pGuestSessionPanel->markForError(true);
    600         return false;
    601     }
    602 
    603     QVector<KVBoxEventType> eventTypes;
    604     eventTypes << KVBoxEventType_OnGuestSessionRegistered;
    605 
    606     prepareListener(m_pQtGuestListener, m_comGuestListener,
    607                     m_comGuest.GetEventSource(), eventTypes);
    608     connect(m_pQtGuestListener->getWrapped(), &UIMainEventListener::sigGuestSessionUnregistered,
    609             this, &UIFileManager::sltGuestSessionUnregistered);
    610 
    611     connect(m_pQtGuestListener->getWrapped(), &UIMainEventListener::sigGuestSessionRegistered,
    612             this, &UIFileManager::sltGuestSessionRegistered);
    613 
    614     m_comGuestSession = m_comGuest.CreateSession(strUserName, strPassword,
    615                                                  QString() /* Domain */, "File Manager Session");
    616 
    617     if (!m_comGuestSession.isOk())
    618     {
    619         appendLog(UIErrorString::formatErrorInfo(m_comGuestSession), FileManagerLogType_Error);
    620         return false;
    621     }
    622 
    623     if (m_pGuestSessionPanel)
    624         m_pGuestSessionPanel->switchSessionCloseMode();
    625 
    626     /* Prepare guest session listener */
    627     eventTypes.clear();
    628     eventTypes << KVBoxEventType_OnGuestSessionStateChanged;
    629 
    630     prepareListener(m_pQtSessionListener, m_comSessionListener,
    631                     m_comGuestSession.GetEventSource(), eventTypes);
    632 
    633     qRegisterMetaType<CGuestSessionStateChangedEvent>();
    634     connect(m_pQtSessionListener->getWrapped(), &UIMainEventListener::sigGuestSessionStatedChanged,
    635             this, &UIFileManager::sltGuestSessionStateChanged);
    636 
    637     return true;
    638 }
    639 
    640 void UIFileManager::closeSession()
    641 {
    642 }
    643 
    644 void UIFileManager::prepareListener(ComObjPtr<UIMainEventListenerImpl> &QtListener,
    645                                     CEventListener &comEventListener,
    646                                     CEventSource comEventSource, QVector<KVBoxEventType>& eventTypes)
    647 {
    648     if (!comEventSource.isOk())
    649         return;
    650     /* Create event listener instance: */
    651     QtListener.createObject();
    652     QtListener->init(new UIMainEventListener, this);
    653     comEventListener = CEventListener(QtListener);
    654 
    655     /* Register event listener for CProgress event source: */
    656     comEventSource.RegisterListener(comEventListener, eventTypes, FALSE /* active? */);
    657 
    658     /* Register event sources in their listeners as well: */
    659     QtListener->getWrapped()->registerSource(comEventSource, comEventListener);
     446    if (m_pGuestTablesContainer && m_pHostFileTable)
     447    {
     448        UIFileManagerGuestTable *pGuestFileTable = qobject_cast<UIFileManagerGuestTable*>(m_pGuestTablesContainer->currentWidget());
     449        if (pGuestFileTable)
     450            pGuestFileTable->copyHostToGuest(m_pHostFileTable->selectedItemPathList());
     451    }
    660452}
    661453
     
    705497}
    706498
    707 void UIFileManager::cleanupListener(ComObjPtr<UIMainEventListenerImpl> &QtListener,
    708                                                 CEventListener &comEventListener,
    709                                                 CEventSource comEventSource)
    710 {
    711     if (!comEventSource.isOk())
    712         return;
    713     /* Unregister everything: */
    714     QtListener->getWrapped()->unregisterSources();
    715 
    716     /* Make sure VBoxSVC is available: */
    717     if (!uiCommon().isVBoxSVCAvailable())
    718         return;
    719 
    720     /* Unregister event listener for CProgress event source: */
    721     comEventSource.UnregisterListener(comEventListener);
    722 }
    723499
    724500template<typename T>
     
    856632}
    857633
    858 bool UIFileManager::isGuestAdditionsAvailable(const CGuest &guest)
    859 {
    860     if (!guest.isOk())
    861         return false;
    862     CGuest guestNonConst = const_cast<CGuest&>(guest);
    863     return guestNonConst.GetAdditionsStatus(guestNonConst.GetAdditionsRunLevel());
    864 }
     634void UIFileManager::setSelectedVMListItems(const QList<UIVirtualMachineItem*> &items)
     635{
     636    QVector<QUuid> selectedMachines;
     637
     638    foreach (const UIVirtualMachineItem *item, items)
     639    {
     640        if (!item)
     641            continue;
     642        selectedMachines << item->id();
     643    }
     644    setMachines(selectedMachines);
     645}
     646
     647void UIFileManager::setMachines(const QVector<QUuid> &machineIds)
     648{
     649    /* List of machines that are newly added to selected machine list: */
     650    QVector<QUuid> newSelections;
     651    QVector<QUuid> unselectedMachines(m_machineIds);
     652
     653    foreach (const QUuid &id, machineIds)
     654    {
     655        unselectedMachines.removeAll(id);
     656        if (!m_machineIds.contains(id))
     657            newSelections << id;
     658    }
     659    m_machineIds = machineIds;
     660
     661    addTabs(newSelections);
     662    removeTabs(unselectedMachines);
     663}
     664
     665void UIFileManager::removeTabs(const QVector<QUuid> &machineIdsToRemove)
     666{
     667    if (!m_pGuestTablesContainer)
     668        return;
     669    QVector<UIFileManagerGuestTable*> removeList;
     670
     671    for (int i = m_pGuestTablesContainer->count() - 1; i >= 0; --i)
     672    {
     673        UIFileManagerGuestTable *pTable = qobject_cast<UIFileManagerGuestTable*>(m_pGuestTablesContainer->widget(i));
     674        if (!pTable)
     675            continue;
     676        if (machineIdsToRemove.contains(pTable->machineId()))
     677        {
     678            removeList << pTable;
     679            m_pGuestTablesContainer->removeTab(i);
     680        }
     681    }
     682    qDeleteAll(removeList.begin(), removeList.end());
     683}
     684
     685void UIFileManager::addTabs(const QVector<QUuid> &machineIdsToAdd)
     686{
     687    if (!m_pGuestTablesContainer)
     688        return;
     689
     690    foreach (const QUuid &id, machineIdsToAdd)
     691    {
     692        CMachine comMachine = uiCommon().virtualBox().FindMachine(id.toString());
     693        if (comMachine.isNull())
     694            continue;
     695        m_pGuestTablesContainer->addTab(new UIFileManagerGuestTable(m_pActionPool, comMachine, m_pGuestTablesContainer), comMachine.GetName());
     696        // if (m_pGuestFileTable)
     697        // {
     698        //     connect(m_pGuestFileTable, &UIFileManagerGuestTable::sigLogOutput,
     699        //             this, &UIFileManager::sltReceieveLogOutput);
     700        //     connect(m_pGuestFileTable, &UIFileManagerGuestTable::sigNewFileOperation,
     701        //             this, &UIFileManager::sltReceieveNewFileOperation);
     702        //     connect(m_pGuestFileTable, &UIFileManagerGuestTable::sigDeleteConfirmationOptionChanged,
     703        //             this, &UIFileManager::sltHandleOptionsUpdated);
     704        // }
     705    }
     706}
     707
    865708
    866709#include "UIFileManager.moc"
  • trunk/src/VBox/Frontends/VirtualBox/src/guestctrl/UIFileManager.h

    r92645 r92688  
    2626#include <QWidget>
    2727
    28 /* COM includes: */
    29 #include "COMEnums.h"
    30 #include "CEventListener.h"
    31 #include "CEventSource.h"
    32 #include "CGuest.h"
    33 #include "CGuestSession.h"
    34 #include "CMachine.h"
    35 #include "CSession.h"
    3628
    3729/* GUI includes: */
     
    3931#include "QIWithRetranslateUI.h"
    4032#include "UIGuestControlDefs.h"
    41 #include "UIMainEventListener.h"
     33
    4234
    4335/* Forward declarations: */
     
    5547class UIFileManagerGuestTable;
    5648class UIFileManagerHostTable;
     49class UIVirtualMachineItem;
     50class QITabWidget;
    5751class QIToolBar;
    5852
     
    10599#endif
    106100
    107     void setMachine(const QUuid &machineId);
     101    void setSelectedVMListItems(const QList<UIVirtualMachineItem*> &items);
    108102
    109103protected:
     
    113107private slots:
    114108
    115     void sltGuestSessionUnregistered(CGuestSession guestSession);
    116     void sltGuestSessionRegistered(CGuestSession guestSession);
    117     void sltCreateGuestSession(QString strUserName, QString strPassword);
    118     void sltCloseGuestSession();
    119     void sltGuestSessionStateChanged(const CGuestSessionStateChangedEvent &cEvent);
    120109    void sltReceieveLogOutput(QString strOutput, FileManagerLogType eLogType);
    121110    void sltCopyGuestToHost();
     
    127116    void sltHandleOptionsUpdated();
    128117    void sltHandleHidePanel(UIDialogPanel *pPanel);
    129     void sltCleanupListenerAndGuest();
    130118
    131119private:
     
    138126    void prepareOptionsAndSessionPanels(QVBoxLayout *pLayout);
    139127    void prepareOperationsAndLogPanels(QSplitter *pSplitter);
    140 
    141     /** Creates a shared machine session, opens a guest session and registers event listeners. */
    142     bool openSession(const QString& strUserName, const QString& strPassword);
    143     void closeSession();
    144 
    145     void prepareListener(ComObjPtr<UIMainEventListenerImpl> &Qtistener,
    146                          CEventListener &comEventListener,
    147                          CEventSource comEventSource, QVector<KVBoxEventType>& eventTypes);
    148 
    149     void cleanupListener(ComObjPtr<UIMainEventListenerImpl> &QtListener,
    150                          CEventListener &comEventListener,
    151                          CEventSource comEventSource);
    152 
    153     void initFileTable();
    154     /** @name Perform operations needed after creating/ending a guest control session
    155       * @{ */
    156         void postGuestSessionCreated();
    157         void postGuestSessionClosed();
    158     /** @} */
    159128
    160129    /** Saves list of panels and file manager options to the extra data. */
     
    180149    void                      savePanelVisibility();
    181150    bool                      isGuestAdditionsAvailable(const CGuest &guest);
    182     CGuest                    m_comGuest;
    183     CGuestSession             m_comGuestSession;
    184     CSession                  m_comSession;
    185     CMachine                  m_comMachine;
     151
     152    void setMachines(const QVector<QUuid> &machineIDs);
     153    void removeTabs(const QVector<QUuid> &machineIdsToRemove);
     154    void addTabs(const QVector<QUuid> &machineIdsToAdd);
     155
     156
    186157    QVBoxLayout              *m_pMainLayout;
    187158    QSplitter                *m_pVerticalSplitter;
     
    191162    QIToolBar                *m_pVerticalToolBar;
    192163
    193     UIFileManagerGuestTable  *m_pGuestFileTable;
    194164    UIFileManagerHostTable   *m_pHostFileTable;
    195165
    196     ComObjPtr<UIMainEventListenerImpl> m_pQtGuestListener;
    197     ComObjPtr<UIMainEventListenerImpl> m_pQtSessionListener;
    198     CEventListener m_comSessionListener;
    199     CEventListener m_comGuestListener;
     166    QITabWidget              *m_pGuestTablesContainer;
    200167    const EmbedTo  m_enmEmbedding;
    201168    QPointer<UIActionPool>  m_pActionPool;
     
    208175    UIFileManagerOperationsPanel       *m_pOperationsPanel;
    209176    bool                                m_fDialogBeingClosed;
     177
     178
     179    QVector<QUuid> m_machineIds;
     180
    210181    friend class UIFileManagerOptionsPanel;
    211182    friend class UIFileManagerDialog;
  • trunk/src/VBox/Frontends/VirtualBox/src/guestctrl/UIFileManagerGuestTable.cpp

    r92587 r92688  
    145145}
    146146
    147 UIFileManagerGuestTable::UIFileManagerGuestTable(UIActionPool *pActionPool, QWidget *pParent /*= 0*/)
     147UIFileManagerGuestTable::UIFileManagerGuestTable(UIActionPool *pActionPool, const CMachine &comMachine, QWidget *pParent /*= 0*/)
    148148    :UIFileManagerTable(pActionPool, pParent)
     149    , m_comMachine(comMachine)
    149150{
    150151    prepareToolbar();
     
    369370}
    370371
     372QUuid UIFileManagerGuestTable::machineId()
     373{
     374    if (m_comMachine.isNull())
     375        return QUuid();
     376    return m_comMachine.GetId();
     377}
     378
    371379void UIFileManagerGuestTable::copyGuestToHost(const QString& hostDestinationPath)
    372380{
     
    764772}
    765773
     774/*////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////*/
     775/*////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////*/
     776/*////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////*/
     777#if 0
     778    void initFileTable();
     779void UIFileManager::initFileTable()
     780{
     781    if (!m_comGuestSession.isOk() || m_comGuestSession.GetStatus() != KGuestSessionStatus_Started)
     782        return;
     783    if (!m_pGuestFileTable)
     784        return;
     785    m_pGuestFileTable->initGuestFileTable(m_comGuestSession);
     786}
     787
     788    /** @name Perform operations needed after creating/ending a guest control session
     789      * @{ */
     790        void postGuestSessionCreated();
     791        void postGuestSessionClosed();
     792    /** @} */
     793
     794void UIFileManager::postGuestSessionCreated()
     795{
     796    if (m_pGuestSessionPanel)
     797        m_pGuestSessionPanel->switchSessionCloseMode();
     798    if (m_pGuestFileTable)
     799        m_pGuestFileTable->setEnabled(true);
     800    if (m_pVerticalToolBar)
     801        m_pVerticalToolBar->setEnabled(true);
     802}
     803
     804void UIFileManager::postGuestSessionClosed()
     805{
     806    if (m_pGuestSessionPanel)
     807        m_pGuestSessionPanel->switchSessionCreateMode();
     808    if (m_pGuestFileTable)
     809        m_pGuestFileTable->setEnabled(false);
     810    if (m_pVerticalToolBar)
     811        m_pVerticalToolBar->setEnabled(false);
     812}
     813
     814    /** Creates a shared machine session, opens a guest session and registers event listeners. */
     815    bool openSession(const QString& strUserName, const QString& strPassword);
     816    void closeSession();
     817
     818bool UIFileManager::openSession(const QString& strUserName, const QString& strPassword)
     819{
     820    if (m_comMachine.isNull())
     821    {
     822        appendLog("Invalid machine reference", FileManagerLogType_Error);
     823        return false;
     824    }
     825    m_comSession = uiCommon().openSession(m_comMachine.GetId(), KLockType_Shared);
     826    if (m_comSession.isNull())
     827    {
     828        appendLog("Could not open machine session", FileManagerLogType_Error);
     829        return false;
     830    }
     831
     832    CConsole comConsole = m_comSession.GetConsole();
     833    AssertReturn(!comConsole.isNull(), false);
     834    m_comGuest = comConsole.GetGuest();
     835    AssertReturn(!m_comGuest.isNull(), false);
     836
     837    if (!isGuestAdditionsAvailable(m_comGuest))
     838    {
     839        appendLog("Could not find Guest Additions", FileManagerLogType_Error);
     840        postGuestSessionClosed();
     841        if (m_pGuestSessionPanel)
     842            m_pGuestSessionPanel->markForError(true);
     843        return false;
     844    }
     845
     846    QVector<KVBoxEventType> eventTypes;
     847    eventTypes << KVBoxEventType_OnGuestSessionRegistered;
     848
     849    prepareListener(m_pQtGuestListener, m_comGuestListener,
     850                    m_comGuest.GetEventSource(), eventTypes);
     851    connect(m_pQtGuestListener->getWrapped(), &UIMainEventListener::sigGuestSessionUnregistered,
     852            this, &UIFileManager::sltGuestSessionUnregistered);
     853
     854    connect(m_pQtGuestListener->getWrapped(), &UIMainEventListener::sigGuestSessionRegistered,
     855            this, &UIFileManager::sltGuestSessionRegistered);
     856
     857    m_comGuestSession = m_comGuest.CreateSession(strUserName, strPassword,
     858                                                 QString() /* Domain */, "File Manager Session");
     859
     860    if (!m_comGuestSession.isOk())
     861    {
     862        appendLog(UIErrorString::formatErrorInfo(m_comGuestSession), FileManagerLogType_Error);
     863        return false;
     864    }
     865
     866    if (m_pGuestSessionPanel)
     867        m_pGuestSessionPanel->switchSessionCloseMode();
     868
     869    /* Prepare guest session listener */
     870    eventTypes.clear();
     871    eventTypes << KVBoxEventType_OnGuestSessionStateChanged;
     872
     873    prepareListener(m_pQtSessionListener, m_comSessionListener,
     874                    m_comGuestSession.GetEventSource(), eventTypes);
     875
     876    qRegisterMetaType<CGuestSessionStateChangedEvent>();
     877    connect(m_pQtSessionListener->getWrapped(), &UIMainEventListener::sigGuestSessionStatedChanged,
     878            this, &UIFileManager::sltGuestSessionStateChanged);
     879
     880    return true;
     881}
     882
     883void UIFileManager::closeSession()
     884{
     885}
     886
     887void UIFileManager::prepareListener(ComObjPtr<UIMainEventListenerImpl> &QtListener,
     888                                    CEventListener &comEventListener,
     889                                    CEventSource comEventSource, QVector<KVBoxEventType>& eventTypes)
     890{
     891    if (!comEventSource.isOk())
     892        return;
     893    /* Create event listener instance: */
     894    QtListener.createObject();
     895    QtListener->init(new UIMainEventListener, this);
     896    comEventListener = CEventListener(QtListener);
     897
     898    /* Register event listener for CProgress event source: */
     899    comEventSource.RegisterListener(comEventListener, eventTypes, FALSE /* active? */);
     900
     901    /* Register event sources in their listeners as well: */
     902    QtListener->getWrapped()->registerSource(comEventSource, comEventListener);
     903}
     904
     905void UIFileManager::cleanupListener(ComObjPtr<UIMainEventListenerImpl> &QtListener,
     906                                                CEventListener &comEventListener,
     907                                                CEventSource comEventSource)
     908{
     909    if (!comEventSource.isOk())
     910        return;
     911    /* Unregister everything: */
     912    QtListener->getWrapped()->unregisterSources();
     913
     914    /* Make sure VBoxSVC is available: */
     915    if (!uiCommon().isVBoxSVCAvailable())
     916        return;
     917
     918    /* Unregister event listener for CProgress event source: */
     919    comEventSource.UnregisterListener(comEventListener);
     920}
     921
     922bool UIFileManager::isGuestAdditionsAvailable(const CGuest &guest)
     923{
     924    if (!guest.isOk())
     925        return false;
     926    CGuest guestNonConst = const_cast<CGuest&>(guest);
     927    return guestNonConst.GetAdditionsStatus(guestNonConst.GetAdditionsRunLevel());
     928}
     929
     930void UIFileManager::sltGuestSessionUnregistered(CGuestSession guestSession)
     931{
     932    if (guestSession.isNull())
     933        return;
     934    if (guestSession == m_comGuestSession && !m_comGuestSession.isNull())
     935    {
     936        m_comGuestSession.detach();
     937        postGuestSessionClosed();
     938        appendLog("Guest session unregistered", FileManagerLogType_Info);
     939    }
     940}
     941
     942void UIFileManager::sltGuestSessionRegistered(CGuestSession guestSession)
     943{
     944    if (guestSession == m_comGuestSession && !m_comGuestSession.isNull())
     945        appendLog("Guest session registered", FileManagerLogType_Info);
     946}
     947
     948
     949void UIFileManager::sltCreateGuestSession(QString strUserName, QString strPassword)
     950{
     951    if (strUserName.isEmpty())
     952    {
     953        appendLog("No user name is given", FileManagerLogType_Error);
     954        if (m_pGuestSessionPanel)
     955            m_pGuestSessionPanel->markForError(true);
     956        return;
     957    }
     958    if (m_pGuestSessionPanel)
     959        m_pGuestSessionPanel->markForError(!openSession(strUserName, strPassword));
     960}
     961
     962void UIFileManager::sltCloseGuestSession()
     963{
     964    if (!m_comGuestSession.isOk())
     965    {
     966        appendLog("Guest session is not valid", FileManagerLogType_Error);
     967        postGuestSessionClosed();
     968        return;
     969    }
     970    if (m_pGuestFileTable)
     971        m_pGuestFileTable->reset();
     972
     973    if (m_comGuestSession.isOk() && m_pQtSessionListener && m_comSessionListener.isOk())
     974        cleanupListener(m_pQtSessionListener, m_comSessionListener, m_comGuestSession.GetEventSource());
     975
     976    m_comGuestSession.Close();
     977    appendLog("Guest session is closed", FileManagerLogType_Info);
     978    postGuestSessionClosed();
     979}
     980
     981void UIFileManager::sltGuestSessionStateChanged(const CGuestSessionStateChangedEvent &cEvent)
     982{
     983    if (cEvent.isOk())
     984    {
     985        CVirtualBoxErrorInfo cErrorInfo = cEvent.GetError();
     986        if (cErrorInfo.isOk() && !cErrorInfo.GetText().contains("success", Qt::CaseInsensitive))
     987            appendLog(cErrorInfo.GetText(), FileManagerLogType_Error);
     988    }
     989    if (m_comGuestSession.isOk())
     990    {
     991        if (m_comGuestSession.GetStatus() == KGuestSessionStatus_Started)
     992        {
     993            initFileTable();
     994            postGuestSessionCreated();
     995        }
     996        appendLog(QString("%1: %2").arg("Guest session status has changed").arg(gpConverter->toString(m_comGuestSession.GetStatus())),
     997                  FileManagerLogType_Info);
     998    }
     999    else
     1000        appendLog("Guest session is not valid", FileManagerLogType_Error);
     1001}
     1002
     1003
     1004
     1005    void sltGuestSessionUnregistered(CGuestSession guestSession);
     1006    void sltGuestSessionRegistered(CGuestSession guestSession);
     1007    void sltCreateGuestSession(QString strUserName, QString strPassword);
     1008    void sltCloseGuestSession();
     1009    void sltGuestSessionStateChanged(const CGuestSessionStateChangedEvent &cEvent);
     1010    void sltCleanupListenerAndGuest();
     1011
     1012    if (m_pGuestSessionPanel)
     1013    {
     1014        connect(m_pGuestSessionPanel, &UIFileManagerGuestSessionPanel::sigCreateSession,
     1015                this, &UIFileManager::sltCreateGuestSession);
     1016        connect(m_pGuestSessionPanel, &UIFileManagerGuestSessionPanel::sigCloseSession,
     1017                this, &UIFileManager::sltCloseGuestSession);
     1018        connect(m_pGuestSessionPanel, &UIFileManagerGuestSessionPanel::sigHidePanel,
     1019                this, &UIFileManager::sltHandleHidePanel);
     1020    }
     1021
     1022
     1023void UIFileManager::sltCleanupListenerAndGuest()
     1024{
     1025    if (m_comGuest.isOk() && m_pQtGuestListener && m_comGuestListener.isOk())
     1026        cleanupListener(m_pQtGuestListener, m_comGuestListener, m_comGuest.GetEventSource());
     1027    if (m_comGuestSession.isOk() && m_pQtSessionListener && m_comSessionListener.isOk())
     1028        cleanupListener(m_pQtSessionListener, m_comSessionListener, m_comGuestSession.GetEventSource());
     1029
     1030    if (m_comGuestSession.isOk())
     1031        m_comGuestSession.Close();
     1032}
     1033
     1034#endif
     1035/*////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////*/
     1036/*////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////*/
     1037/*////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////*/
     1038
     1039
     1040
     1041
    7661042#include "UIFileManagerGuestTable.moc"
  • trunk/src/VBox/Frontends/VirtualBox/src/guestctrl/UIFileManagerGuestTable.h

    r82968 r92688  
    2727/* COM includes: */
    2828#include "COMEnums.h"
     29#include "CEventListener.h"
     30#include "CEventSource.h"
     31#include "CGuest.h"
    2932#include "CGuestSession.h"
     33#include "CMachine.h"
     34#include "CSession.h"
     35
    3036
    3137/* GUI includes: */
    3238#include "UIFileManagerTable.h"
     39#include "UIMainEventListener.h"
    3340
    3441/* Forward declarations: */
     
    4855public:
    4956
    50     UIFileManagerGuestTable(UIActionPool *pActionPool, QWidget *pParent = 0);
     57    UIFileManagerGuestTable(UIActionPool *pActionPool, const CMachine &comMachine, QWidget *pParent = 0);
    5158    void initGuestFileTable(const CGuestSession &session);
    5259    void copyGuestToHost(const QString& hostDestinationPath);
    5360    void copyHostToGuest(const QStringList &hostSourcePathList,
    5461                         const QString &strDestination = QString());
     62    QUuid machineId();
    5563
    5664protected:
     
    8694    bool isFileObjectHidden(const CFsObjInfo &fsInfo);
    8795
    88     mutable CGuestSession     m_comGuestSession;
     96    void prepareListener(ComObjPtr<UIMainEventListenerImpl> &Qtistener,
     97                         CEventListener &comEventListener,
     98                         CEventSource comEventSource, QVector<KVBoxEventType>& eventTypes);
     99
     100    void cleanupListener(ComObjPtr<UIMainEventListenerImpl> &QtListener,
     101                         CEventListener &comEventListener,
     102                         CEventSource comEventSource);
     103
     104
     105    CGuest                    m_comGuest;
     106    CGuestSession             m_comGuestSession;
     107    CSession                  m_comSession;
     108    CMachine                  m_comMachine;
     109
     110    ComObjPtr<UIMainEventListenerImpl> m_pQtGuestListener;
     111    ComObjPtr<UIMainEventListenerImpl> m_pQtSessionListener;
     112    CEventListener m_comSessionListener;
     113    CEventListener m_comGuestListener;
    89114};
    90115
  • trunk/src/VBox/Frontends/VirtualBox/src/guestctrl/UIFileManagerTable.cpp

    r92587 r92688  
    12961296        pRootItem->setData(UICustomFileSystemModel::tr("Permissions"), UICustomFileSystemModelColumn_Permissions);
    12971297    }
    1298     /// @todo Using \n breaks between words of the same sentence isn't allowed. This isn't easily translateable to other
    1299     ///       languages.  Moreover, using of \n isn't allowed at all.  This isn't exactly a cross-platform identifier.
    1300     ///       You can use only <br> between sentenses of the same paragraph. Most of Qt text is HTML by definition, so
    1301     ///       it does support <br> tags.
    13021298    if (m_pWarningLabel)
    1303         m_pWarningLabel->setText(UIFileManager::tr("No Guest Session found!<br>Please use the Session Panel to start a new guest session"));
     1299        m_pWarningLabel->setText(UIFileManager::tr("<p>No Guest Session found! Please use the Session Panel to start a new guest session</p>"));
    13041300}
    13051301
  • trunk/src/VBox/Frontends/VirtualBox/src/manager/UIToolPaneMachine.cpp

    r92640 r92688  
    231231                /* Configure pane: */
    232232                m_pPaneFileManager->setProperty("ToolType", QVariant::fromValue(UIToolType_FileManager));
    233                 //m_pPaneFileManager->setSelectedVMListItems(m_items);
     233                m_pPaneFileManager->setSelectedVMListItems(m_items);
    234234                /* Add into layout: */
    235235                m_pLayout->addWidget(m_pPaneFileManager);
     
    304304        m_pPaneDetails->setItems(m_items);
    305305    }
    306     /* Update logs pane is open: */
     306    /* Update logs pane if it is open: */
    307307    if (isToolOpened(UIToolType_Logs))
    308308    {
     
    310310        m_pPaneLogViewer->setSelectedVMListItems(m_items);
    311311    }
    312     /* Update performance monitor pane is it is open: */
     312    /* Update performance monitor pane if it is open: */
    313313    if (isToolOpened(UIToolType_VMActivity))
    314314    {
     
    320320        AssertPtrReturnVoid(m_pPaneFileManager);
    321321        if (!m_items.isEmpty() && m_items[0])
    322             m_pPaneFileManager->setMachine(m_items[0]->id());
     322            m_pPaneFileManager->setSelectedVMListItems(m_items);
    323323    }
    324324}
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