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