VirtualBox

source: vbox/trunk/src/VBox/Frontends/VirtualBox/src/runtime/guestctrl/UIGuestControlFileManager.cpp@ 74947

Last change on this file since 74947 was 74947, checked in by vboxsync, 6 years ago

FE/Qt: bugref:6699. Improving sort/filter functionality of the guest control file manager

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 23.9 KB
Line 
1/* $Id: UIGuestControlFileManager.cpp 74947 2018-10-19 15:03:34Z vboxsync $ */
2/** @file
3 * VBox Qt GUI - UIGuestControlFileManager class implementation.
4 */
5
6/*
7 * Copyright (C) 2016-2017 Oracle Corporation
8 *
9 * This file is part of VirtualBox Open Source Edition (OSE), as
10 * available from http://www.virtualbox.org. This file is free software;
11 * you can redistribute it and/or modify it under the terms of the GNU
12 * General Public License (GPL) as published by the Free Software
13 * Foundation, in version 2 as it comes in the "COPYING" file of the
14 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
15 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
16 */
17
18#ifdef VBOX_WITH_PRECOMPILED_HEADERS
19# include <precomp.h>
20#else /* !VBOX_WITH_PRECOMPILED_HEADERS */
21
22/* Qt includes: */
23# include <QAbstractItemModel>
24# include <QCheckBox>
25# include <QHBoxLayout>
26# include <QHeaderView>
27# include <QTextEdit>
28# include <QPushButton>
29# include <QSplitter>
30# include <QGridLayout>
31
32/* GUI includes: */
33# include "QILabel.h"
34# include "QILineEdit.h"
35# include "QITabWidget.h"
36# include "QITreeWidget.h"
37# include "QIWithRetranslateUI.h"
38# include "UIErrorString.h"
39# include "UIExtraDataManager.h"
40# include "UIIconPool.h"
41# include "UIGuestControlConsole.h"
42# include "UIGuestControlFileManager.h"
43# include "UIGuestFileTable.h"
44# include "UIGuestControlInterface.h"
45# include "UIHostFileTable.h"
46# include "UIToolBar.h"
47# include "UIVMInformationDialog.h"
48# include "VBoxGlobal.h"
49
50/* COM includes: */
51# include "CFsObjInfo.h"
52# include "CGuest.h"
53# include "CGuestDirectory.h"
54# include "CGuestFsObjInfo.h"
55# include "CGuestProcess.h"
56# include "CGuestSession.h"
57# include "CGuestSessionStateChangedEvent.h"
58#endif /* !VBOX_WITH_PRECOMPILED_HEADERS */
59
60UIGuestControlFileManagerSettings *UIGuestControlFileManagerSettings::m_pInstance = 0;
61
62UIGuestControlFileManagerSettings* UIGuestControlFileManagerSettings::instance()
63{
64 return m_pInstance;
65}
66
67void UIGuestControlFileManagerSettings::create()
68{
69 if (m_pInstance)
70 return;
71 m_pInstance = new UIGuestControlFileManagerSettings;
72}
73
74void UIGuestControlFileManagerSettings::destroy()
75{
76 delete m_pInstance;
77}
78
79UIGuestControlFileManagerSettings::UIGuestControlFileManagerSettings()
80 : bListDirectoriesOnTop(true)
81{
82}
83
84/*********************************************************************************************************************************
85* UIFileOperationsList definition. *
86*********************************************************************************************************************************/
87
88class UIFileOperationsList : public QITreeWidget
89{
90 Q_OBJECT;
91public:
92
93 UIFileOperationsList(QWidget *pParent = 0);
94
95private:
96};
97
98/*********************************************************************************************************************************
99* UIGuestSessionCreateWidget definition. *
100*********************************************************************************************************************************/
101
102class UIGuestSessionCreateWidget : public QIWithRetranslateUI<QWidget>
103{
104 Q_OBJECT;
105
106signals:
107
108 void sigCreateSession(QString strUserName, QString strPassword);
109 void sigCloseButtonClick();
110
111public:
112
113 UIGuestSessionCreateWidget(QWidget *pParent = 0);
114 void switchSessionCreateMode();
115 void switchSessionCloseMode();
116
117protected:
118
119 void retranslateUi();
120 void keyPressEvent(QKeyEvent * pEvent);
121
122private slots:
123
124 void sltCreateButtonClick();
125 void sltShowHidePassword(bool flag);
126
127private:
128 void prepareWidgets();
129 QILineEdit *m_pUserNameEdit;
130 QILineEdit *m_pPasswordEdit;
131 QPushButton *m_pCreateButton;
132 QPushButton *m_pCloseButton;
133 QHBoxLayout *m_pMainLayout;
134 QCheckBox *m_pShowPasswordCheckBox;
135
136};
137
138/*********************************************************************************************************************************
139* UIFileOperationsList implementation. *
140*********************************************************************************************************************************/
141
142UIFileOperationsList::UIFileOperationsList(QWidget *pParent)
143 :QITreeWidget(pParent)
144{}
145
146
147/*********************************************************************************************************************************
148* UIGuestSessionCreateWidget implementation. *
149*********************************************************************************************************************************/
150
151UIGuestSessionCreateWidget::UIGuestSessionCreateWidget(QWidget *pParent /* = 0 */)
152 : QIWithRetranslateUI<QWidget>(pParent)
153 , m_pUserNameEdit(0)
154 , m_pPasswordEdit(0)
155 , m_pCreateButton(0)
156 , m_pCloseButton(0)
157 , m_pMainLayout(0)
158 , m_pShowPasswordCheckBox(0)
159{
160 prepareWidgets();
161}
162
163void UIGuestSessionCreateWidget::prepareWidgets()
164{
165 m_pMainLayout = new QHBoxLayout(this);
166 if (!m_pMainLayout)
167 return;
168
169 m_pUserNameEdit = new QILineEdit;
170 if (m_pUserNameEdit)
171 {
172 m_pMainLayout->addWidget(m_pUserNameEdit, 2);
173 m_pUserNameEdit->setPlaceholderText("User Name");
174 }
175
176 m_pPasswordEdit = new QILineEdit;
177 if (m_pPasswordEdit)
178 {
179 m_pMainLayout->addWidget(m_pPasswordEdit, 2);
180 m_pPasswordEdit->setPlaceholderText("Password");
181 m_pPasswordEdit->setEchoMode(QLineEdit::Password);
182 }
183
184 m_pShowPasswordCheckBox = new QCheckBox;
185 if (m_pShowPasswordCheckBox)
186 {
187 m_pShowPasswordCheckBox->setText("Show Password");
188 m_pMainLayout->addWidget(m_pShowPasswordCheckBox);
189 connect(m_pShowPasswordCheckBox, &QCheckBox::toggled,
190 this, &UIGuestSessionCreateWidget::sltShowHidePassword);
191 }
192
193 m_pCreateButton = new QPushButton;
194 if (m_pCreateButton)
195 {
196 m_pMainLayout->addWidget(m_pCreateButton);
197 connect(m_pCreateButton, &QPushButton::clicked, this, &UIGuestSessionCreateWidget::sltCreateButtonClick);
198 }
199
200 m_pCloseButton = new QPushButton;
201 if (m_pCloseButton)
202 {
203 m_pMainLayout->addWidget(m_pCloseButton);
204 connect(m_pCloseButton, &QPushButton::clicked, this, &UIGuestSessionCreateWidget::sigCloseButtonClick);
205 }
206 m_pMainLayout->insertStretch(-1, 1);
207 retranslateUi();
208}
209
210void UIGuestSessionCreateWidget::sltCreateButtonClick()
211{
212 if (m_pUserNameEdit && m_pPasswordEdit)
213 emit sigCreateSession(m_pUserNameEdit->text(), m_pPasswordEdit->text());
214}
215
216void UIGuestSessionCreateWidget::sltShowHidePassword(bool flag)
217{
218 if (!m_pPasswordEdit)
219 return;
220 if (flag)
221 m_pPasswordEdit->setEchoMode(QLineEdit::Normal);
222 else
223 m_pPasswordEdit->setEchoMode(QLineEdit::Password);
224}
225
226void UIGuestSessionCreateWidget::retranslateUi()
227{
228 if (m_pUserNameEdit)
229 {
230 m_pUserNameEdit->setToolTip(UIVMInformationDialog::tr("User name to authenticate session creation"));
231 m_pUserNameEdit->setPlaceholderText(UIVMInformationDialog::tr("User Name"));
232
233 }
234 if (m_pPasswordEdit)
235 {
236 m_pPasswordEdit->setToolTip(UIVMInformationDialog::tr("Password to authenticate session creation"));
237 m_pPasswordEdit->setPlaceholderText(UIVMInformationDialog::tr("Password"));
238 }
239
240 if (m_pCreateButton)
241 m_pCreateButton->setText(UIVMInformationDialog::tr("Create Session"));
242 if (m_pCloseButton)
243 m_pCloseButton->setText(UIVMInformationDialog::tr("Close Session"));
244}
245
246void UIGuestSessionCreateWidget::keyPressEvent(QKeyEvent * pEvent)
247{
248 /* Emit sigCreateSession upon enter press: */
249 if (pEvent->key() == Qt::Key_Enter || pEvent->key() == Qt::Key_Return)
250 {
251 if ((m_pUserNameEdit && m_pUserNameEdit->hasFocus()) ||
252 (m_pPasswordEdit && m_pPasswordEdit->hasFocus()))
253 sigCreateSession(m_pUserNameEdit->text(), m_pPasswordEdit->text());
254 }
255 QWidget::keyPressEvent(pEvent);
256}
257
258void UIGuestSessionCreateWidget::switchSessionCreateMode()
259{
260 if (m_pUserNameEdit)
261 m_pUserNameEdit->setEnabled(true);
262 if (m_pPasswordEdit)
263 m_pPasswordEdit->setEnabled(true);
264 if (m_pCreateButton)
265 m_pCreateButton->setEnabled(true);
266 if (m_pCloseButton)
267 m_pCloseButton->setEnabled(false);
268}
269
270void UIGuestSessionCreateWidget::switchSessionCloseMode()
271{
272 if (m_pUserNameEdit)
273 m_pUserNameEdit->setEnabled(false);
274 if (m_pPasswordEdit)
275 m_pPasswordEdit->setEnabled(false);
276 if (m_pCreateButton)
277 m_pCreateButton->setEnabled(false);
278 if (m_pCloseButton)
279 m_pCloseButton->setEnabled(true);
280}
281
282
283/*********************************************************************************************************************************
284* UIGuestControlFileManager implementation. *
285*********************************************************************************************************************************/
286
287UIGuestControlFileManager::UIGuestControlFileManager(QWidget *pParent, const CGuest &comGuest)
288 : QIWithRetranslateUI<QWidget>(pParent)
289 , m_iMaxRecursionDepth(1)
290 , m_comGuest(comGuest)
291 , m_pMainLayout(0)
292 , m_pVerticalSplitter(0)
293 , m_pLogOutput(0)
294 , m_pToolBar(0)
295 , m_pCopyGuestToHost(0)
296 , m_pCopyHostToGuest(0)
297 , m_pFileTableContainerWidget(0)
298 , m_pFileTableContainerLayout(0)
299 , m_pTabWidget(0)
300 , m_pFileOperationsList(0)
301 , m_pSessionCreateWidget(0)
302 , m_pGuestFileTable(0)
303 , m_pHostFileTable(0)
304{
305 prepareGuestListener();
306 prepareObjects();
307 prepareConnections();
308 retranslateUi();
309 loadSettings();
310 UIGuestControlFileManagerSettings::create();
311}
312
313UIGuestControlFileManager::~UIGuestControlFileManager()
314{
315 if (m_comGuest.isOk() && m_pQtGuestListener && m_comGuestListener.isOk())
316 cleanupListener(m_pQtGuestListener, m_comGuestListener, m_comGuest.GetEventSource());
317 if (m_comGuestSession.isOk() && m_pQtSessionListener && m_comSessionListener.isOk())
318 cleanupListener(m_pQtSessionListener, m_comSessionListener, m_comGuestSession.GetEventSource());
319 saveSettings();
320 UIGuestControlFileManagerSettings::destroy();
321}
322
323void UIGuestControlFileManager::retranslateUi()
324{
325 if (m_pCopyGuestToHost)
326 {
327 m_pCopyGuestToHost->setText(UIVMInformationDialog::tr("Copy the selected object(s) from guest to host"));
328 m_pCopyGuestToHost->setToolTip(UIVMInformationDialog::tr("Copy the selected object(s) from guest to host"));
329 m_pCopyGuestToHost->setStatusTip(UIVMInformationDialog::tr("Copy the selected object(s) from guest to host"));
330 }
331
332 if (m_pCopyHostToGuest)
333 {
334 m_pCopyHostToGuest->setText(UIVMInformationDialog::tr("Copy the selected object(s) from host to guest"));
335 m_pCopyHostToGuest->setToolTip(UIVMInformationDialog::tr("Copy the selected object(s) from host to guest"));
336 m_pCopyHostToGuest->setStatusTip(UIVMInformationDialog::tr("Copy the selected object(s) from host to guest"));
337 }
338
339
340 m_pTabWidget->setTabText(0, tr("Log"));
341 m_pTabWidget->setTabText(1, tr("File Operations"));
342 m_pTabWidget->setTabText(2, tr("Terminal"));
343
344}
345
346void UIGuestControlFileManager::prepareGuestListener()
347{
348 if (m_comGuest.isOk())
349 {
350 QVector<KVBoxEventType> eventTypes;
351 eventTypes << KVBoxEventType_OnGuestSessionRegistered;
352
353 prepareListener(m_pQtGuestListener, m_comGuestListener,
354 m_comGuest.GetEventSource(), eventTypes);
355 }
356}
357
358void UIGuestControlFileManager::prepareObjects()
359{
360 /* Create layout: */
361 m_pMainLayout = new QVBoxLayout(this);
362 if (!m_pMainLayout)
363 return;
364
365 /* Configure layout: */
366 m_pMainLayout->setSpacing(0);
367
368 m_pSessionCreateWidget = new UIGuestSessionCreateWidget();
369 if (m_pSessionCreateWidget)
370 {
371 m_pMainLayout->addWidget(m_pSessionCreateWidget);
372 }
373
374 m_pVerticalSplitter = new QSplitter;
375 if (m_pVerticalSplitter)
376 {
377 m_pMainLayout->addWidget(m_pVerticalSplitter);
378 m_pVerticalSplitter->setOrientation(Qt::Vertical);
379 m_pVerticalSplitter->setHandleWidth(4);
380 }
381
382 m_pFileTableContainerWidget = new QWidget;
383 m_pFileTableContainerLayout = new QHBoxLayout;
384
385 if (m_pFileTableContainerWidget)
386 {
387 if (m_pFileTableContainerLayout)
388 {
389 m_pFileTableContainerWidget->setLayout(m_pFileTableContainerLayout);
390 m_pFileTableContainerLayout->setSpacing(0);
391 m_pFileTableContainerLayout->setContentsMargins(0, 0, 0, 0);
392 m_pGuestFileTable = new UIGuestFileTable;
393 m_pGuestFileTable->setEnabled(false);
394
395 m_pHostFileTable = new UIHostFileTable;
396 if (m_pHostFileTable)
397 {
398 connect(m_pHostFileTable, &UIHostFileTable::sigLogOutput,
399 this, &UIGuestControlFileManager::sltReceieveLogOutput);
400 m_pFileTableContainerLayout->addWidget(m_pHostFileTable);
401 }
402 prepareToolBar();
403 if (m_pGuestFileTable)
404 {
405 connect(m_pGuestFileTable, &UIGuestFileTable::sigLogOutput,
406 this, &UIGuestControlFileManager::sltReceieveLogOutput);
407 m_pFileTableContainerLayout->addWidget(m_pGuestFileTable);
408 }
409
410 }
411 m_pVerticalSplitter->addWidget(m_pFileTableContainerWidget);
412 }
413
414 m_pTabWidget = new QITabWidget;
415 if (m_pTabWidget)
416 {
417 m_pVerticalSplitter->addWidget(m_pTabWidget);
418 m_pTabWidget->setTabPosition(QTabWidget::South);
419 }
420
421 m_pLogOutput = new QTextEdit;
422 if (m_pLogOutput)
423 {
424 m_pTabWidget->addTab(m_pLogOutput, "Log");
425 m_pLogOutput->setReadOnly(true);
426 }
427
428 m_pFileOperationsList = new UIFileOperationsList;
429 if (m_pFileOperationsList)
430 {
431 m_pTabWidget->addTab(m_pFileOperationsList, "File Operatiions");
432 m_pFileOperationsList->header()->hide();
433 }
434
435 m_pVerticalSplitter->setStretchFactor(0, 3);
436 m_pVerticalSplitter->setStretchFactor(1, 1);
437}
438
439void UIGuestControlFileManager::prepareToolBar()
440{
441 m_pToolBar = new UIToolBar;
442 if (!m_pToolBar)
443 return;
444
445 m_pToolBar->setOrientation(Qt::Vertical);
446 m_pToolBar->setEnabled(false);
447
448 /* Add to dummy QWidget to toolbar to center the action icons vertically: */
449 QWidget *topSpacerWidget = new QWidget(this);
450 topSpacerWidget->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Expanding);
451 topSpacerWidget->setVisible(true);
452 QWidget *bottomSpacerWidget = new QWidget(this);
453 bottomSpacerWidget->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Expanding);
454 bottomSpacerWidget->setVisible(true);
455
456 m_pCopyGuestToHost = new QAction(this);
457 if(m_pCopyGuestToHost)
458 {
459 m_pCopyGuestToHost->setIcon(UIIconPool::iconSet(QString(":/arrow_left_10px_x2.png")));
460 connect(m_pCopyGuestToHost, &QAction::triggered, this, &UIGuestControlFileManager::sltCopyGuestToHost);
461 }
462
463 m_pCopyHostToGuest = new QAction(this);
464 if (m_pCopyHostToGuest)
465 {
466 m_pCopyHostToGuest->setIcon(UIIconPool::iconSet(QString(":/arrow_right_10px_x2.png")));
467 connect(m_pCopyHostToGuest, &QAction::triggered, this, &UIGuestControlFileManager::sltCopyHostToGuest);
468 }
469
470 m_pToolBar->addWidget(topSpacerWidget);
471 m_pToolBar->addAction(m_pCopyGuestToHost);
472 m_pToolBar->addAction(m_pCopyHostToGuest);
473 m_pToolBar->addWidget(bottomSpacerWidget);
474
475 m_pFileTableContainerLayout->addWidget(m_pToolBar);
476}
477
478void UIGuestControlFileManager::prepareConnections()
479{
480 if (m_pQtGuestListener)
481 {
482 connect(m_pQtGuestListener->getWrapped(), &UIMainEventListener::sigGuestSessionUnregistered,
483 this, &UIGuestControlFileManager::sltGuestSessionUnregistered);
484 }
485 if (m_pSessionCreateWidget)
486 {
487 connect(m_pSessionCreateWidget, &UIGuestSessionCreateWidget::sigCreateSession,
488 this, &UIGuestControlFileManager::sltCreateSession);
489 connect(m_pSessionCreateWidget, &UIGuestSessionCreateWidget::sigCloseButtonClick,
490 this, &UIGuestControlFileManager::sltCloseSession);
491 }
492}
493
494void UIGuestControlFileManager::sltGuestSessionUnregistered(CGuestSession guestSession)
495{
496 if (guestSession.isNull())
497 return;
498 if (guestSession == m_comGuestSession && !m_comGuestSession.isNull())
499 {
500 m_comGuestSession.detach();
501 postSessionClosed();
502 }
503}
504
505void UIGuestControlFileManager::sltCreateSession(QString strUserName, QString strPassword)
506{
507 if (!UIGuestControlInterface::isGuestAdditionsAvailable(m_comGuest))
508 {
509 if (m_pLogOutput)
510 {
511 m_pLogOutput->append("Could not find Guest Additions");
512 postSessionClosed();
513 return;
514 }
515 }
516 if (strUserName.isEmpty())
517 {
518 if (m_pLogOutput)
519 m_pLogOutput->append("No user name is given");
520 return;
521 }
522 createSession(strUserName, strPassword);
523}
524
525void UIGuestControlFileManager::sltCloseSession()
526{
527 if (!m_comGuestSession.isOk())
528 {
529 m_pLogOutput->append("Guest session is not valid");
530 postSessionClosed();
531 return;
532 }
533 if (m_pGuestFileTable)
534 m_pGuestFileTable->reset();
535
536 if (m_comGuestSession.isOk() && m_pQtSessionListener && m_comSessionListener.isOk())
537 cleanupListener(m_pQtSessionListener, m_comSessionListener, m_comGuestSession.GetEventSource());
538
539 m_comGuestSession.Close();
540 m_pLogOutput->append("Guest session is closed");
541 postSessionClosed();
542}
543
544void UIGuestControlFileManager::sltGuestSessionStateChanged(const CGuestSessionStateChangedEvent &cEvent)
545{
546 if (cEvent.isOk() /*&& m_comGuestSession.isOk()*/)
547 {
548 CVirtualBoxErrorInfo cErrorInfo = cEvent.GetError();
549 if (cErrorInfo.isOk())
550 {
551 m_pLogOutput->append(cErrorInfo.GetText());
552 }
553 }
554 if (m_comGuestSession.GetStatus() == KGuestSessionStatus_Started)
555 {
556 initFileTable();
557 postSessionCreated();
558 }
559 else
560 {
561 m_pLogOutput->append("Session status has changed");
562 }
563}
564
565void UIGuestControlFileManager::sltReceieveLogOutput(QString strOutput)
566{
567 if (m_pLogOutput)
568 m_pLogOutput->append(strOutput);
569}
570
571void UIGuestControlFileManager::sltCopyGuestToHost()
572{
573 if (!m_pGuestFileTable || !m_pHostFileTable)
574 return;
575 QString hostDestinationPath = m_pHostFileTable->currentDirectoryPath();
576 m_pGuestFileTable->copyGuestToHost(hostDestinationPath);
577 m_pHostFileTable->refresh();
578}
579
580void UIGuestControlFileManager::sltCopyHostToGuest()
581{
582 if (!m_pGuestFileTable || !m_pHostFileTable)
583 return;
584 QStringList hostSourcePathList = m_pHostFileTable->selectedItemPathList();
585 m_pGuestFileTable->copyHostToGuest(hostSourcePathList);
586 m_pGuestFileTable->refresh();
587}
588
589void UIGuestControlFileManager::initFileTable()
590{
591 if (!m_comGuestSession.isOk() || m_comGuestSession.GetStatus() != KGuestSessionStatus_Started)
592 return;
593 if (!m_pGuestFileTable)
594 return;
595 m_pGuestFileTable->initGuestFileTable(m_comGuestSession);
596}
597
598void UIGuestControlFileManager::postSessionCreated()
599{
600 if (m_pSessionCreateWidget)
601 m_pSessionCreateWidget->switchSessionCloseMode();
602 if (m_pGuestFileTable)
603 m_pGuestFileTable->setEnabled(true);
604 if (m_pToolBar)
605 m_pToolBar->setEnabled(true);
606}
607
608void UIGuestControlFileManager::postSessionClosed()
609{
610 if (m_pSessionCreateWidget)
611 m_pSessionCreateWidget->switchSessionCreateMode();
612 if (m_pGuestFileTable)
613 m_pGuestFileTable->setEnabled(false);
614 if (m_pToolBar)
615 m_pToolBar->setEnabled(false);
616
617}
618
619
620bool UIGuestControlFileManager::createSession(const QString& strUserName, const QString& strPassword,
621 const QString& strDomain /* not used currently */)
622{
623 if (!m_comGuest.isOk())
624 return false;
625 m_comGuestSession = m_comGuest.CreateSession(strUserName, strPassword,
626 strDomain, "File Manager Session");
627
628 if (!m_comGuestSession.isOk())
629 {
630 m_pLogOutput->append(UIErrorString::formatErrorInfo(m_comGuestSession));
631 return false;
632 }
633
634 m_pLogOutput->append("Guest session has been created");
635 if (m_pSessionCreateWidget)
636 m_pSessionCreateWidget->switchSessionCloseMode();
637
638 /* Prepare session listener */
639 QVector<KVBoxEventType> eventTypes;
640 eventTypes << KVBoxEventType_OnGuestSessionStateChanged;
641 //<< KVBoxEventType_OnGuestProcessRegistered;
642 prepareListener(m_pQtSessionListener, m_comSessionListener,
643 m_comGuestSession.GetEventSource(), eventTypes);
644
645 /* Connect to session listener */
646 qRegisterMetaType<CGuestSessionStateChangedEvent>();
647
648
649 connect(m_pQtSessionListener->getWrapped(), &UIMainEventListener::sigGuestSessionStatedChanged,
650 this, &UIGuestControlFileManager::sltGuestSessionStateChanged);
651 /* Wait session to start. For some reason we cannot get GuestSessionStatusChanged event
652 consistently. So we wait: */
653 m_pLogOutput->append("Waiting the session to start");
654 const ULONG waitTimeout = 2000;
655 KGuestSessionWaitResult waitResult = m_comGuestSession.WaitFor(KGuestSessionWaitForFlag_Start, waitTimeout);
656 if (waitResult != KGuestSessionWaitResult_Start)
657 {
658 m_pLogOutput->append("The session did not start");
659 sltCloseSession();
660 return false;
661 }
662
663 return true;
664}
665
666void UIGuestControlFileManager::prepareListener(ComObjPtr<UIMainEventListenerImpl> &QtListener,
667 CEventListener &comEventListener,
668 CEventSource comEventSource, QVector<KVBoxEventType>& eventTypes)
669{
670 if (!comEventSource.isOk())
671 return;
672 /* Create event listener instance: */
673 QtListener.createObject();
674 QtListener->init(new UIMainEventListener, this);
675 comEventListener = CEventListener(QtListener);
676
677 /* Register event listener for CProgress event source: */
678 comEventSource.RegisterListener(comEventListener, eventTypes,
679 gEDataManager->eventHandlingType() == EventHandlingType_Active ? TRUE : FALSE);
680
681 /* If event listener registered as passive one: */
682 if (gEDataManager->eventHandlingType() == EventHandlingType_Passive)
683 {
684 /* Register event sources in their listeners as well: */
685 QtListener->getWrapped()->registerSource(comEventSource, comEventListener);
686 }
687}
688
689void UIGuestControlFileManager::cleanupListener(ComObjPtr<UIMainEventListenerImpl> &QtListener,
690 CEventListener &comEventListener,
691 CEventSource comEventSource)
692{
693 if (!comEventSource.isOk())
694 return;
695 /* If event listener registered as passive one: */
696 if (gEDataManager->eventHandlingType() == EventHandlingType_Passive)
697 {
698 /* Unregister everything: */
699 QtListener->getWrapped()->unregisterSources();
700 }
701
702 /* Make sure VBoxSVC is available: */
703 if (!vboxGlobal().isVBoxSVCAvailable())
704 return;
705
706 /* Unregister event listener for CProgress event source: */
707 comEventSource.UnregisterListener(comEventListener);
708}
709
710template<typename T>
711QStringList UIGuestControlFileManager::getFsObjInfoStringList(const T &fsObjectInfo) const
712{
713 QStringList objectInfo;
714 if (!fsObjectInfo.isOk())
715 return objectInfo;
716
717 objectInfo << fsObjectInfo.GetName();
718
719 return objectInfo;
720}
721
722void UIGuestControlFileManager::saveSettings()
723{
724 if (!m_pVerticalSplitter)
725 return;
726 gEDataManager->setGuestFileManagerTabSplitterHints(m_pVerticalSplitter->sizes());
727}
728
729void UIGuestControlFileManager::loadSettings()
730{
731 if (!m_pVerticalSplitter)
732 return;
733 QList<int> splitterHints = gEDataManager->guestFileManagerTabSplitterHints();
734 if (splitterHints.size() != 2)
735 return;
736 if (splitterHints[0] != 0 && splitterHints[1] != 0)
737 m_pVerticalSplitter->setSizes(splitterHints);
738}
739
740#include "UIGuestControlFileManager.moc"
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette