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