Changeset 92688 in vbox
- Timestamp:
- Dec 2, 2021 10:20:41 AM (3 years ago)
- 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 22 22 23 23 /* GUI includes: */ 24 #include "QITabWidget.h" 24 25 #include "QITreeWidget.h" 25 26 #include "QIToolBar.h" … … 38 39 #include "UIFileManagerHostTable.h" 39 40 #include "UIGuestControlInterface.h" 41 #include "UIVirtualMachineItem.h" 40 42 41 43 /* COM includes: */ … … 115 117 const CMachine &comMachine, QWidget *pParent, bool fShowToolbar) 116 118 : QIWithRetranslateUI<QWidget>(pParent) 117 , m_comMachine(comMachine)118 119 , m_pMainLayout(0) 119 120 , m_pVerticalSplitter(0) 120 121 , m_pFileTableSplitter(0) 121 122 , m_pToolBar(0) 122 , m_pVerticalToolBar(0) 123 , m_pGuestFileTable(0) 123 , m_pVerticalToolBar(0)\ 124 124 , m_pHostFileTable(0) 125 , m_pGuestTablesContainer(0) 125 126 , m_enmEmbedding(enmEmbedding) 126 127 , m_pActionPool(pActionPool) … … 139 140 UIFileManagerOptions::create(); 140 141 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); 142 144 } 143 145 … … 145 147 { 146 148 UIFileManagerOptions::destroy(); 147 }148 149 void UIFileManager::setMachine(const QUuid &machineId)150 {151 m_comMachine = uiCommon().virtualBox().FindMachine(machineId.toString());152 149 } 153 150 … … 206 203 m_pFileTableSplitter->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Expanding); 207 204 m_pFileTableSplitter->setContentsMargins(0, 0, 0, 0); 208 m_pGuestFileTable = new UIFileManagerGuestTable(m_pActionPool);209 m_pGuestFileTable->setEnabled(false);210 205 211 206 /* This widget hosts host file table and vertical toolbar. */ … … 221 216 m_pFileTableSplitter->addWidget(pHostTableAndVerticalToolbarWidget); 222 217 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 } 225 225 } 226 226 … … 302 302 this, &UIFileManager::sltCopyHostToGuest); 303 303 } 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 }313 304 if (m_pOptionsPanel) 314 305 { … … 330 321 this, &UIFileManager::sltReceieveLogOutput); 331 322 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,341 323 this, &UIFileManager::sltHandleOptionsUpdated); 342 324 } … … 373 355 } 374 356 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 else445 appendLog("Guest session is not valid", FileManagerLogType_Error);446 }447 448 357 void UIFileManager::sltReceieveLogOutput(QString strOutput, FileManagerLogType eLogType) 449 358 { … … 491 400 { 492 401 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 } 498 411 } 499 412 … … 503 416 m_pOptionsPanel->update(); 504 417 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 } 507 424 if (m_pHostFileTable) 508 425 m_pHostFileTable->optionsUpdated(); … … 515 432 } 516 433 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 528 434 void UIFileManager::copyToHost() 529 435 { 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 } 535 442 } 536 443 537 444 void UIFileManager::copyToGuest() 538 445 { 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 } 660 452 } 661 453 … … 705 497 } 706 498 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 }723 499 724 500 template<typename T> … … 856 632 } 857 633 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 } 634 void 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 647 void 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 665 void 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 685 void 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 865 708 866 709 #include "UIFileManager.moc" -
trunk/src/VBox/Frontends/VirtualBox/src/guestctrl/UIFileManager.h
r92645 r92688 26 26 #include <QWidget> 27 27 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"36 28 37 29 /* GUI includes: */ … … 39 31 #include "QIWithRetranslateUI.h" 40 32 #include "UIGuestControlDefs.h" 41 #include "UIMainEventListener.h" 33 42 34 43 35 /* Forward declarations: */ … … 55 47 class UIFileManagerGuestTable; 56 48 class UIFileManagerHostTable; 49 class UIVirtualMachineItem; 50 class QITabWidget; 57 51 class QIToolBar; 58 52 … … 105 99 #endif 106 100 107 void set Machine(const QUuid &machineId);101 void setSelectedVMListItems(const QList<UIVirtualMachineItem*> &items); 108 102 109 103 protected: … … 113 107 private slots: 114 108 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);120 109 void sltReceieveLogOutput(QString strOutput, FileManagerLogType eLogType); 121 110 void sltCopyGuestToHost(); … … 127 116 void sltHandleOptionsUpdated(); 128 117 void sltHandleHidePanel(UIDialogPanel *pPanel); 129 void sltCleanupListenerAndGuest();130 118 131 119 private: … … 138 126 void prepareOptionsAndSessionPanels(QVBoxLayout *pLayout); 139 127 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 session155 * @{ */156 void postGuestSessionCreated();157 void postGuestSessionClosed();158 /** @} */159 128 160 129 /** Saves list of panels and file manager options to the extra data. */ … … 180 149 void savePanelVisibility(); 181 150 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 186 157 QVBoxLayout *m_pMainLayout; 187 158 QSplitter *m_pVerticalSplitter; … … 191 162 QIToolBar *m_pVerticalToolBar; 192 163 193 UIFileManagerGuestTable *m_pGuestFileTable;194 164 UIFileManagerHostTable *m_pHostFileTable; 195 165 196 ComObjPtr<UIMainEventListenerImpl> m_pQtGuestListener; 197 ComObjPtr<UIMainEventListenerImpl> m_pQtSessionListener; 198 CEventListener m_comSessionListener; 199 CEventListener m_comGuestListener; 166 QITabWidget *m_pGuestTablesContainer; 200 167 const EmbedTo m_enmEmbedding; 201 168 QPointer<UIActionPool> m_pActionPool; … … 208 175 UIFileManagerOperationsPanel *m_pOperationsPanel; 209 176 bool m_fDialogBeingClosed; 177 178 179 QVector<QUuid> m_machineIds; 180 210 181 friend class UIFileManagerOptionsPanel; 211 182 friend class UIFileManagerDialog; -
trunk/src/VBox/Frontends/VirtualBox/src/guestctrl/UIFileManagerGuestTable.cpp
r92587 r92688 145 145 } 146 146 147 UIFileManagerGuestTable::UIFileManagerGuestTable(UIActionPool *pActionPool, QWidget *pParent /*= 0*/)147 UIFileManagerGuestTable::UIFileManagerGuestTable(UIActionPool *pActionPool, const CMachine &comMachine, QWidget *pParent /*= 0*/) 148 148 :UIFileManagerTable(pActionPool, pParent) 149 , m_comMachine(comMachine) 149 150 { 150 151 prepareToolbar(); … … 369 370 } 370 371 372 QUuid UIFileManagerGuestTable::machineId() 373 { 374 if (m_comMachine.isNull()) 375 return QUuid(); 376 return m_comMachine.GetId(); 377 } 378 371 379 void UIFileManagerGuestTable::copyGuestToHost(const QString& hostDestinationPath) 372 380 { … … 764 772 } 765 773 774 /*////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////*/ 775 /*////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////*/ 776 /*////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////*/ 777 #if 0 778 void initFileTable(); 779 void 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 794 void 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 804 void 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 818 bool 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 883 void UIFileManager::closeSession() 884 { 885 } 886 887 void 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 905 void 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 922 bool 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 930 void 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 942 void UIFileManager::sltGuestSessionRegistered(CGuestSession guestSession) 943 { 944 if (guestSession == m_comGuestSession && !m_comGuestSession.isNull()) 945 appendLog("Guest session registered", FileManagerLogType_Info); 946 } 947 948 949 void 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 962 void 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 981 void 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 1023 void 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 766 1042 #include "UIFileManagerGuestTable.moc" -
trunk/src/VBox/Frontends/VirtualBox/src/guestctrl/UIFileManagerGuestTable.h
r82968 r92688 27 27 /* COM includes: */ 28 28 #include "COMEnums.h" 29 #include "CEventListener.h" 30 #include "CEventSource.h" 31 #include "CGuest.h" 29 32 #include "CGuestSession.h" 33 #include "CMachine.h" 34 #include "CSession.h" 35 30 36 31 37 /* GUI includes: */ 32 38 #include "UIFileManagerTable.h" 39 #include "UIMainEventListener.h" 33 40 34 41 /* Forward declarations: */ … … 48 55 public: 49 56 50 UIFileManagerGuestTable(UIActionPool *pActionPool, QWidget *pParent = 0);57 UIFileManagerGuestTable(UIActionPool *pActionPool, const CMachine &comMachine, QWidget *pParent = 0); 51 58 void initGuestFileTable(const CGuestSession &session); 52 59 void copyGuestToHost(const QString& hostDestinationPath); 53 60 void copyHostToGuest(const QStringList &hostSourcePathList, 54 61 const QString &strDestination = QString()); 62 QUuid machineId(); 55 63 56 64 protected: … … 86 94 bool isFileObjectHidden(const CFsObjInfo &fsInfo); 87 95 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; 89 114 }; 90 115 -
trunk/src/VBox/Frontends/VirtualBox/src/guestctrl/UIFileManagerTable.cpp
r92587 r92688 1296 1296 pRootItem->setData(UICustomFileSystemModel::tr("Permissions"), UICustomFileSystemModelColumn_Permissions); 1297 1297 } 1298 /// @todo Using \n breaks between words of the same sentence isn't allowed. This isn't easily translateable to other1299 /// 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, so1301 /// it does support <br> tags.1302 1298 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>")); 1304 1300 } 1305 1301 -
trunk/src/VBox/Frontends/VirtualBox/src/manager/UIToolPaneMachine.cpp
r92640 r92688 231 231 /* Configure pane: */ 232 232 m_pPaneFileManager->setProperty("ToolType", QVariant::fromValue(UIToolType_FileManager)); 233 //m_pPaneFileManager->setSelectedVMListItems(m_items);233 m_pPaneFileManager->setSelectedVMListItems(m_items); 234 234 /* Add into layout: */ 235 235 m_pLayout->addWidget(m_pPaneFileManager); … … 304 304 m_pPaneDetails->setItems(m_items); 305 305 } 306 /* Update logs pane i s open: */306 /* Update logs pane if it is open: */ 307 307 if (isToolOpened(UIToolType_Logs)) 308 308 { … … 310 310 m_pPaneLogViewer->setSelectedVMListItems(m_items); 311 311 } 312 /* Update performance monitor pane i sit is open: */312 /* Update performance monitor pane if it is open: */ 313 313 if (isToolOpened(UIToolType_VMActivity)) 314 314 { … … 320 320 AssertPtrReturnVoid(m_pPaneFileManager); 321 321 if (!m_items.isEmpty() && m_items[0]) 322 m_pPaneFileManager->set Machine(m_items[0]->id());322 m_pPaneFileManager->setSelectedVMListItems(m_items); 323 323 } 324 324 }
Note:
See TracChangeset
for help on using the changeset viewer.