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