VirtualBox

source: vbox/trunk/src/VBox/Frontends/VirtualBox/src/guestctrl/UIFileManagerGuestTable.cpp

Last change on this file was 105081, checked in by vboxsync, 2 months ago

FE/Qt: Moving local machine related stuff from UICommon to new UILocalMachineStuff namespace; Reworking GUI to use it accordingly; Dependencies and includes cleanup.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 61.5 KB
RevLine 
[71025]1/* $Id: UIFileManagerGuestTable.cpp 105081 2024-07-01 15:38:32Z vboxsync $ */
2/** @file
[76177]3 * VBox Qt GUI - UIFileManagerGuestTable class implementation.
[71025]4 */
5
6/*
[98103]7 * Copyright (C) 2016-2023 Oracle and/or its affiliates.
[71025]8 *
[96407]9 * This file is part of VirtualBox base platform packages, as
10 * available from https://www.virtualbox.org.
11 *
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation, in version 3 of the
15 * License.
16 *
17 * This program is distributed in the hope that it will be useful, but
18 * WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 * General Public License for more details.
21 *
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, see <https://www.gnu.org/licenses>.
24 *
25 * SPDX-License-Identifier: GPL-3.0-only
[71025]26 */
27
28/* Qt includes: */
[104393]29#include <QApplication>
[76606]30#include <QDateTime>
31#include <QFileInfo>
[92710]32#include <QHBoxLayout>
[92847]33#include <QPushButton>
[76606]34#include <QUuid>
[71025]35
36/* GUI includes: */
[76606]37#include "QILabel.h"
38#include "UIActionPool.h"
[92733]39#include "UIConverter.h"
[92741]40#include "UICommon.h"
[103771]41#include "UIErrorString.h"
[102485]42#include "UIFileSystemModel.h"
[76606]43#include "UIFileManager.h"
[92913]44#include "UIFileManagerHostTable.h"
[76606]45#include "UIFileManagerGuestTable.h"
[100302]46#include "UIFileTableNavigationWidget.h"
[103771]47#include "UIGlobalSession.h"
[93186]48#include "UIIconPool.h"
[105081]49#include "UILocalMachineStuff.h"
[76606]50#include "UIMessageCenter.h"
51#include "UIPathOperations.h"
[92847]52#include "UIUserNamePasswordEditor.h"
[92765]53#include "UIVirtualBoxEventHandler.h"
[92847]54#include "QILineEdit.h"
[86233]55#include "QIToolBar.h"
[104228]56#include "UITranslationEventListener.h"
[71025]57
58/* COM includes: */
[92733]59#include "CConsole.h"
[76606]60#include "CFsObjInfo.h"
61#include "CGuestFsObjInfo.h"
62#include "CGuestDirectory.h"
63#include "CProgress.h"
[92733]64#include "CGuestSessionStateChangedEvent.h"
[71025]65
[103711]66/* Other VBox includes: */
[92894]67#include <iprt/err.h>
[71025]68
[92847]69/*********************************************************************************************************************************
[93697]70* UIGuestSessionWidget definition. *
[92847]71*********************************************************************************************************************************/
72/** A QWidget extension containing text entry fields for password and username and buttons to
[92860]73 * start/stop a guest session. */
[104297]74class UIGuestSessionWidget : public QWidget
[92847]75{
76 Q_OBJECT;
[92544]77
[92847]78signals:
79
[93697]80 void sigOpenSession(QString strUserName, QString strPassword);
[92847]81 void sigCloseSession();
82
83public:
84
[93697]85 UIGuestSessionWidget(QWidget *pParent = 0);
86 /** Disables certain widget after a guest session has been opened. */
87 void switchSessionOpenMode();
88 /** Makes sure certain widgets are enabled so that a guest session can be opened. */
[92847]89 void switchSessionCloseMode();
90 void markForError(bool fMarkForError);
[93682]91 void setStatusLabelIconAndToolTip(const QIcon &icon, const QString &strToolTip);
92 void setLoginWidgetsEnabled(bool fEnabled);
[92847]93
94protected:
95
[93990]96 void keyPressEvent(QKeyEvent * pEvent) RT_OVERRIDE;
97 void showEvent(QShowEvent *pEvent) RT_OVERRIDE;
[92847]98
99private slots:
100
[104297]101 void sltRetranslateUI();
[92847]102 void sltButtonClick();
103 void sltHandleTextChanged(const QString &strText);
104
105private:
106
107 enum ButtonMode
108 {
[93697]109 ButtonMode_Open,
[92847]110 ButtonMode_Close
111 };
112
113 void prepareWidgets();
114 void updateButton();
115
116 ButtonMode m_enmButtonMode;
117 QILineEdit *m_pUserNameEdit;
118 UIPasswordLineEdit *m_pPasswordEdit;
119 QPushButton *m_pButton;
120 QHBoxLayout *m_pMainLayout;
121 QColor m_defaultBaseColor;
122 QColor m_errorBaseColor;
123 bool m_fMarkedForError;
[93682]124 QLabel *m_pStatusIconLabel;
[92847]125};
126
127
[71563]128/*********************************************************************************************************************************
[93697]129* UIGuestSessionWidget implementation. *
[92847]130*********************************************************************************************************************************/
131
[93697]132UIGuestSessionWidget::UIGuestSessionWidget(QWidget *pParent /* = 0 */)
[104297]133 : QWidget(pParent)
[93697]134 , m_enmButtonMode(ButtonMode_Open)
[92847]135 , m_pUserNameEdit(0)
136 , m_pPasswordEdit(0)
137 , m_pButton(0)
138 , m_pMainLayout(0)
139 , m_fMarkedForError(0)
[93682]140 , m_pStatusIconLabel(0)
[92847]141{
142 prepareWidgets();
143}
144
[93697]145void UIGuestSessionWidget::prepareWidgets()
[92847]146{
147 m_pMainLayout = new QHBoxLayout(this);
148 if (!m_pMainLayout)
149 return;
150
151 m_pMainLayout->setContentsMargins(0, 0, 0, 0);
152
153 m_pUserNameEdit = new QILineEdit;
154 if (m_pUserNameEdit)
155 {
156 m_pMainLayout->addWidget(m_pUserNameEdit, 2);
157 m_pUserNameEdit->setPlaceholderText(QApplication::translate("UIFileManager", "User Name"));
158 m_defaultBaseColor = m_pUserNameEdit->palette().color(QPalette::Base);
159 m_errorBaseColor = QColor(m_defaultBaseColor.red(),
160 0.5 * m_defaultBaseColor.green(),
161 0.5 * m_defaultBaseColor.blue());
162 connect(m_pUserNameEdit, &QILineEdit::textChanged,
[93697]163 this, &UIGuestSessionWidget::sltHandleTextChanged);
[92847]164 }
165
166 m_pPasswordEdit = new UIPasswordLineEdit;
167 if (m_pPasswordEdit)
168 {
169 m_pMainLayout->addWidget(m_pPasswordEdit, 2);
170 m_pPasswordEdit->setPlaceholderText(QApplication::translate("UIFileManager", "Password"));
171 m_pPasswordEdit->setEchoMode(QLineEdit::Password);
172 connect(m_pPasswordEdit, &UIPasswordLineEdit::textChanged,
[93697]173 this, &UIGuestSessionWidget::sltHandleTextChanged);
[92847]174 }
175
176 m_pButton = new QPushButton;
177 if (m_pButton)
178 {
179 m_pMainLayout->addWidget(m_pButton);
[93697]180 connect(m_pButton, &QPushButton::clicked, this, &UIGuestSessionWidget::sltButtonClick);
[92847]181 }
[93682]182 m_pStatusIconLabel = new QLabel(this);
183 if (m_pStatusIconLabel)
184 {
185 m_pMainLayout->addWidget(m_pStatusIconLabel);
186 m_pStatusIconLabel->setSizePolicy(QSizePolicy::Maximum, QSizePolicy::Maximum);
187 }
[92847]188
189 m_pMainLayout->insertStretch(-1, 1);
[93697]190 switchSessionOpenMode();
[104297]191 sltRetranslateUI();
192 connect(&translationEventListener(), &UITranslationEventListener::sigRetranslateUI,
193 this, &UIGuestSessionWidget::sltRetranslateUI);
[92847]194}
195
[93697]196void UIGuestSessionWidget::sltButtonClick()
[92847]197{
[93697]198 if (m_enmButtonMode == ButtonMode_Open && m_pUserNameEdit && m_pPasswordEdit)
199 emit sigOpenSession(m_pUserNameEdit->text(), m_pPasswordEdit->text());
[92847]200 else if (m_enmButtonMode == ButtonMode_Close)
201 emit sigCloseSession();
202}
203
[93697]204void UIGuestSessionWidget::sltHandleTextChanged(const QString &strText)
[92847]205{
206 Q_UNUSED(strText);
207 markForError(false);
208}
209
[104297]210void UIGuestSessionWidget::sltRetranslateUI()
[92847]211{
212 if (m_pUserNameEdit)
213 {
214 m_pUserNameEdit->setToolTip(QApplication::translate("UIFileManager", "User name to authenticate session creation"));
215 m_pUserNameEdit->setPlaceholderText(QApplication::translate("UIFileManager", "User Name"));
216
217 }
218 if (m_pPasswordEdit)
219 {
220 m_pPasswordEdit->setToolTip(QApplication::translate("UIFileManager", "Password to authenticate session creation"));
221 m_pPasswordEdit->setPlaceholderText(QApplication::translate("UIFileManager", "Password"));
222 }
223
224 if (m_pButton)
225 {
[93697]226 if (m_enmButtonMode == ButtonMode_Open)
[93682]227 {
[93697]228 m_pButton->setText(QApplication::translate("UIFileManager", "Open Session"));
229 m_pButton->setToolTip(QApplication::translate("UIFileManager", "Open Session"));
[93682]230 }
[92847]231 else
[93682]232 {
[92847]233 m_pButton->setText(QApplication::translate("UIFileManager", "Close Session"));
[93682]234 m_pButton->setToolTip(QApplication::translate("UIFileManager", "Close Session"));
235 }
[92847]236 }
237}
238
[93697]239void UIGuestSessionWidget::keyPressEvent(QKeyEvent * pEvent)
[92847]240{
[93697]241 /* Emit sigOpenSession upon enter press: */
[92847]242 if (pEvent->key() == Qt::Key_Enter || pEvent->key() == Qt::Key_Return)
243 {
244 if ((m_pUserNameEdit && m_pUserNameEdit->hasFocus()) ||
245 (m_pPasswordEdit && m_pPasswordEdit->hasFocus()))
[93697]246 sigOpenSession(m_pUserNameEdit->text(), m_pPasswordEdit->text());
[92847]247 }
248 QWidget::keyPressEvent(pEvent);
249}
250
[93697]251void UIGuestSessionWidget::showEvent(QShowEvent *pEvent)
[92847]252{
[104297]253 QWidget::showEvent(pEvent);
[92847]254 if (m_pUserNameEdit)
255 m_pUserNameEdit->setFocus();
256}
257
[93697]258void UIGuestSessionWidget::switchSessionOpenMode()
[92847]259{
260 if (m_pUserNameEdit)
261 m_pUserNameEdit->setEnabled(true);
262 if (m_pPasswordEdit)
263 m_pPasswordEdit->setEnabled(true);
[93697]264 m_enmButtonMode = ButtonMode_Open;
[104297]265 sltRetranslateUI();
[92847]266}
267
[93697]268void UIGuestSessionWidget::switchSessionCloseMode()
[92847]269{
270 if (m_pUserNameEdit)
271 m_pUserNameEdit->setEnabled(false);
272 if (m_pPasswordEdit)
273 m_pPasswordEdit->setEnabled(false);
274 m_enmButtonMode = ButtonMode_Close;
[104297]275 sltRetranslateUI();
[92847]276}
277
[93697]278void UIGuestSessionWidget::markForError(bool fMarkForError)
[92847]279{
280 if (m_fMarkedForError == fMarkForError)
281 return;
282 m_fMarkedForError = fMarkForError;
283
[92884]284 if (m_pUserNameEdit)
285 {
286 QPalette mPalette = m_pUserNameEdit->palette();
287 if (m_fMarkedForError)
288 mPalette.setColor(QPalette::Base, m_errorBaseColor);
289 else
290 mPalette.setColor(QPalette::Base, m_defaultBaseColor);
291 m_pUserNameEdit->setPalette(mPalette);
292 }
293 if (m_pPasswordEdit)
294 {
295 QPalette mPalette = m_pPasswordEdit->palette();
296 if (m_fMarkedForError)
297 mPalette.setColor(QPalette::Base, m_errorBaseColor);
298 else
299 mPalette.setColor(QPalette::Base, m_defaultBaseColor);
300 m_pPasswordEdit->setPalette(mPalette);
301 }
[92847]302}
303
[93697]304void UIGuestSessionWidget::setStatusLabelIconAndToolTip(const QIcon &icon, const QString &strToolTip)
[93682]305{
306 if (!m_pStatusIconLabel)
307 return;
308 const int iIconMetric = QApplication::style()->pixelMetric(QStyle::PM_ButtonIconSize);
309 m_pStatusIconLabel->setPixmap(icon.pixmap(QSize(iIconMetric, iIconMetric)));
310 m_pStatusIconLabel->setToolTip(strToolTip);
311}
[92847]312
[93697]313void UIGuestSessionWidget::setLoginWidgetsEnabled(bool fEnabled)
[93682]314{
315 if (m_pUserNameEdit)
316 m_pUserNameEdit->setEnabled(fEnabled);
317 if (m_pPasswordEdit)
318 m_pPasswordEdit->setEnabled(fEnabled);
319 if (m_pButton)
320 m_pButton->setEnabled(fEnabled);
321}
322
[93683]323
[92847]324/*********************************************************************************************************************************
[71563]325* UIGuestDirectoryDiskUsageComputer definition. *
326*********************************************************************************************************************************/
327
328/** Open directories recursively and sum the disk usage. Don't block the GUI thread while doing this */
329class UIGuestDirectoryDiskUsageComputer : public UIDirectoryDiskUsageComputer
330{
331 Q_OBJECT;
332
333public:
334
335 UIGuestDirectoryDiskUsageComputer(QObject *parent, QStringList strStartPath, const CGuestSession &session);
336
337protected:
338
[93990]339 virtual void run() RT_OVERRIDE;
340 virtual void directoryStatisticsRecursive(const QString &path, UIDirectoryStatistics &statistics) RT_OVERRIDE;
[71563]341
342private:
343
344 CGuestSession m_comGuestSession;
345};
346
347
348/*********************************************************************************************************************************
349* UIGuestDirectoryDiskUsageComputer implementation. *
350*********************************************************************************************************************************/
351
352UIGuestDirectoryDiskUsageComputer::UIGuestDirectoryDiskUsageComputer(QObject *parent, QStringList pathList, const CGuestSession &session)
353 :UIDirectoryDiskUsageComputer(parent, pathList)
354 , m_comGuestSession(session)
355{
356}
357
[71645]358void UIGuestDirectoryDiskUsageComputer::run()
359{
360 /* Initialize COM: */
361 COMBase::InitializeCOM(false);
362 UIDirectoryDiskUsageComputer::run();
363 /* Cleanup COM: */
364 COMBase::CleanupCOM();
365}
366
[71563]367void UIGuestDirectoryDiskUsageComputer::directoryStatisticsRecursive(const QString &path, UIDirectoryStatistics &statistics)
368{
369 if (m_comGuestSession.isNull())
370 return;
[71645]371 /* Prevent modification of the continue flag while reading: */
372 m_mutex.lock();
373 /* Check if m_fOkToContinue is set to false. if so just end recursion: */
374 if (!isOkToContinue())
375 {
376 m_mutex.unlock();
[71563]377 return;
[71645]378 }
379 m_mutex.unlock();
380
[71563]381 CGuestFsObjInfo fileInfo = m_comGuestSession.FsObjQueryInfo(path, true);
382
383 if (!m_comGuestSession.isOk())
384 return;
385 /* if the object is a file or a symlink then read the size and return: */
386 if (fileInfo.GetType() == KFsObjType_File)
387 {
388 statistics.m_totalSize += fileInfo.GetObjectSize();
389 ++statistics.m_uFileCount;
390 sigResultUpdated(statistics);
391 return;
392 }
393 else if (fileInfo.GetType() == KFsObjType_Symlink)
394 {
395 statistics.m_totalSize += fileInfo.GetObjectSize();
396 ++statistics.m_uSymlinkCount;
397 sigResultUpdated(statistics);
398 return;
399 }
400
401 if (fileInfo.GetType() != KFsObjType_Directory)
402 return;
403 /* Open the directory to start reading its content: */
[78057]404 QVector<KDirectoryOpenFlag> flag(1, KDirectoryOpenFlag_None);
[71563]405 CGuestDirectory directory = m_comGuestSession.DirectoryOpen(path, /*aFilter*/ "", flag);
[71693]406 if (!m_comGuestSession.isOk())
407 return;
[71563]408
409 if (directory.isOk())
410 {
411 CFsObjInfo fsInfo = directory.Read();
412 while (fsInfo.isOk())
413 {
414 if (fsInfo.GetType() == KFsObjType_File)
415 statistics.m_uFileCount++;
416 else if (fsInfo.GetType() == KFsObjType_Symlink)
417 statistics.m_uSymlinkCount++;
418 else if(fsInfo.GetType() == KFsObjType_Directory)
419 {
420 QString dirPath = UIPathOperations::mergePaths(path, fsInfo.GetName());
421 directoryStatisticsRecursive(dirPath, statistics);
422 }
423 }
424 }
425 sigResultUpdated(statistics);
426}
427
[92688]428UIFileManagerGuestTable::UIFileManagerGuestTable(UIActionPool *pActionPool, const CMachine &comMachine, QWidget *pParent /*= 0*/)
[76177]429 :UIFileManagerTable(pActionPool, pParent)
[92688]430 , m_comMachine(comMachine)
[93682]431 , m_pGuestSessionWidget(0)
[92979]432 , m_fIsCurrent(false)
[100174]433 , pszMinimumGuestAdditionVersion("6.1")
[71185]434{
[102378]435 setModelFileSystem(isWindowsFileSystem());
[92733]436 if (!m_comMachine.isNull())
437 m_strTableName = m_comMachine.GetName();
[75148]438 prepareToolbar();
[92710]439 prepareGuestSessionPanel();
[75148]440 prepareActionConnections();
[92765]441 connect(gVBoxEvents, &UIVirtualBoxEventHandler::sigMachineStateChange,
442 this, &UIFileManagerGuestTable::sltMachineStateChange);
[92787]443 connect(&uiCommon(), &UICommon::sigAskToCommitData,
444 this, &UIFileManagerGuestTable::sltCommitDataSignalReceived);
445
[92765]446 if (m_pActionPool && m_pActionPool->action(UIActionIndex_M_FileManager_T_GuestSession))
447 m_pActionPool->action(UIActionIndex_M_FileManager_T_GuestSession)->setChecked(true);
[92790]448
449 if (!m_comMachine.isNull() && m_comMachine.GetState() == KMachineState_Running)
450 openMachineSession();
[92860]451 setStateAndEnableWidgets();
[92790]452
[104228]453 sltRetranslateUI();
454 connect(&translationEventListener(), &UITranslationEventListener::sigRetranslateUI,
455 this, &UIFileManagerGuestTable::sltRetranslateUI);
[71185]456}
457
[92814]458UIFileManagerGuestTable::~UIFileManagerGuestTable()
459{
460 cleanAll();
461}
462
[92733]463void UIFileManagerGuestTable::initFileTable()
[71185]464{
[92733]465 if (!m_comGuestSession.isOk() || m_comGuestSession.GetStatus() != KGuestSessionStatus_Started)
[71185]466 return;
[78146]467 /* To determine the path separator we need to have a valid guest session: */
468 determinePathSeparator();
[71185]469 initializeFileTree();
470}
471
[104228]472void UIFileManagerGuestTable::sltRetranslateUI()
[71191]473{
474 if (m_pLocationLabel)
[92587]475 m_pLocationLabel->setText(UIFileManager::tr("Guest File System:"));
[92765]476
[93682]477 if (m_pGuestSessionWidget)
[92765]478 {
[93682]479 QIcon icon;
[92765]480 QString strWarningText;
[92860]481 switch (m_enmState)
[92765]482 {
[92860]483 case State_InvalidMachineReference:
[96232]484 strWarningText = UIFileManager::tr("Machine reference is invalid.");
[93682]485 icon = UIIconPool::iconSet(":/status_error_16px.png");
[92765]486 break;
[92860]487 case State_MachineNotRunning:
[96232]488 strWarningText = UIFileManager::tr("File manager cannot work since the selected guest is not currently running.");
[93682]489 icon = UIIconPool::iconSet(":/status_error_16px.png");
[92765]490 break;
[93726]491 case State_MachinePaused:
[96232]492 strWarningText = UIFileManager::tr("File manager cannot work since the guest is paused.");
[93726]493 icon = UIIconPool::iconSet(":/session_info_16px.png");
494 break;
[92860]495 case State_NoGuestAdditions:
[100174]496 strWarningText = UIFileManager::tr("File manager cannot work since no guest additions were detected.");
[93682]497 icon = UIIconPool::iconSet(":/status_error_16px.png");
[92765]498 break;
[100174]499 case State_GuestAdditionsTooOld:
500 strWarningText = UIFileManager::tr("File manager cannot work. The guest additions need to be updated.");
501 icon = UIIconPool::iconSet(":/status_error_16px.png");
502 break;
[92860]503 case State_SessionPossible:
[96232]504 strWarningText = UIFileManager::tr("Enter a valid user name and password to initiate the file manager.");
[93682]505 icon = UIIconPool::iconSet(":/session_info_16px.png");
[93185]506 break;
[93682]507 case State_SessionRunning:
[96232]508 strWarningText = UIFileManager::tr("Guest control session is running.");
[93682]509 icon = UIIconPool::iconSet(":/status_check_16px.png");
510 break;
[95711]511 case State_SessionError:
[96232]512 strWarningText = UIFileManager::tr("Some error has occurred. Please check the log panel.");
[95711]513 icon = UIIconPool::iconSet(":/status_error_16px.png");
514 break;
[92765]515 default:
516 break;
517 }
[93682]518 m_pGuestSessionWidget->setStatusLabelIconAndToolTip(icon, strWarningText);
[92765]519 }
520
[104228]521 UIFileManagerTable::sltRetranslateUI();
[71191]522}
523
[102418]524bool UIFileManagerGuestTable::readDirectory(const QString& strPath,
[102485]525 UIFileSystemItem *parent, bool isStartDir /*= false*/)
[71169]526{
[71181]527 if (!parent)
[102418]528 return false;
[71185]529
[71169]530 CGuestDirectory directory;
531 QVector<KDirectoryOpenFlag> flag;
532 flag.push_back(KDirectoryOpenFlag_None);
533
[71832]534 directory = m_comGuestSession.DirectoryOpen(UIPathOperations::sanitize(strPath), /*aFilter*/ "", flag);
[71693]535 if (!m_comGuestSession.isOk())
536 {
[92733]537 emit sigLogOutput(UIErrorString::formatErrorInfo(m_comGuestSession), m_strTableName, FileManagerLogType_Error);
[102418]538 return false;
[71693]539 }
540
[71181]541 parent->setIsOpened(true);
[71169]542 if (directory.isOk())
543 {
[99391]544 int const cMaxEntries = _4K; /* Maximum number of entries to read at once per List() call. */
545 bool fUseRead = false; /* Whether to use the Read() API or the newer (faster) List() call. */
[99089]546
547 QVector<CFsObjInfo> vecFsInfo = directory.List(cMaxEntries);
[99391]548 /* IGuestDirectory::List() will return VBOX_E_NOT_SUPPORTED if older Guest Additions are installed. */
549 if (directory.rc() == VBOX_E_NOT_SUPPORTED)
550 {
551 CFsObjInfo fsInfo = directory.Read();
552 if (directory.isOk())
553 {
554 vecFsInfo.push_back(fsInfo);
555 fUseRead = true;
556 }
557 }
558
[102485]559 QMap<QString, UIFileSystemItem*> fileObjects;
[71169]560
[99089]561 while (directory.isOk())
[71169]562 {
[99089]563 for (int i = 0; i < vecFsInfo.size(); i++)
[76429]564 {
[99089]565 CFsObjInfo const &fsInfo = vecFsInfo[i];
566
567 if (fsInfo.GetName() != "." && fsInfo.GetName() != "..")
568 {
569 QVector<QVariant> data;
570 QDateTime changeTime = QDateTime::fromMSecsSinceEpoch(fsInfo.GetChangeTime()/RT_NS_1MS);
571 KFsObjType fsObjectType = fileType(fsInfo);
[102485]572 UIFileSystemItem *item = new UIFileSystemItem(fsInfo.GetName(), parent, fsObjectType);
[99089]573 if (!item)
574 continue;
[102485]575 item->setData(static_cast<qulonglong>(fsInfo.GetObjectSize()), UIFileSystemModelData_Size);
576 item->setData(changeTime, UIFileSystemModelData_ChangeTime);
577 item->setData(fsInfo.GetUserName(), UIFileSystemModelData_Owner);
578 item->setData(permissionString(fsInfo), UIFileSystemModelData_Permissions);
[99089]579 item->setIsOpened(false);
580 item->setIsHidden(isFileObjectHidden(fsInfo));
581 fileObjects.insert(fsInfo.GetName(), item);
582 /* @todo. We will need to wait a fully implemented SymlinkRead function
583 * to be able to handle sym links properly: */
584 // QString path = UIPathOperations::mergePaths(strPath, fsInfo.GetName());
585 // QVector<KSymlinkReadFlag> aFlags;
586 // printf("%s %s %s\n", qPrintable(fsInfo.GetName()), qPrintable(path),
587 // qPrintable(m_comGuestSession.SymlinkRead(path, aFlags)));
588 }
[71350]589 }
[99089]590
[99391]591 if (fUseRead)
592 {
593 CFsObjInfo fsInfo = directory.Read();
594 if (directory.isOk())
595 {
596 vecFsInfo.clear();
597 vecFsInfo.push_back(fsInfo);
598 }
599 }
600 else
601 vecFsInfo = directory.List(cMaxEntries);
[71169]602 }
[99089]603
[76429]604 checkDotDot(fileObjects, parent, isStartDir);
[71169]605 }
[102418]606 else
607 {
608 directory.Close();
609 return false;
610 }
[71298]611 directory.Close();
[102418]612 return true;
[71169]613}
614
[102485]615void UIFileManagerGuestTable::deleteByItem(UIFileSystemItem *item)
[71201]616{
[71208]617 if (!item)
618 return;
619 if (item->isUpDirectory())
620 return;
621
622 if (item->isDirectory())
623 {
[78056]624 QVector<KDirectoryRemoveRecFlag> aFlags(1, KDirectoryRemoveRecFlag_ContentAndDir);
[102393]625 m_comGuestSession.DirectoryRemoveRecursive(UIPathOperations::removeTrailingDelimiters(item->path()), aFlags);
[71208]626 }
627 else
[102393]628 m_comGuestSession.FsObjRemove(UIPathOperations::removeTrailingDelimiters(item->path()));
[71258]629 if (!m_comGuestSession.isOk())
[71693]630 {
[92733]631 emit sigLogOutput(QString(item->path()).append(" could not be deleted"), m_strTableName, FileManagerLogType_Error);
632 emit sigLogOutput(UIErrorString::formatErrorInfo(m_comGuestSession), m_strTableName, FileManagerLogType_Error);
[71693]633 }
[71201]634}
[71187]635
[76177]636void UIFileManagerGuestTable::goToHomeDirectory()
[71255]637{
[71325]638 if (m_comGuestSession.isNull())
639 return;
[76309]640 if (!rootItem() || rootItem()->childCount() <= 0)
[71325]641 return;
[102485]642 UIFileSystemItem *startDirItem = rootItem()->child(0);
[71325]643 if (!startDirItem)
644 return;
[71412]645
[104586]646 const QString strUserHome = UIPathOperations::sanitize(m_comGuestSession.GetUserHome());
[71693]647 if (!m_comGuestSession.isOk())
648 {
[92733]649 emit sigLogOutput(UIErrorString::formatErrorInfo(m_comGuestSession), m_strTableName, FileManagerLogType_Error);
[71693]650 return;
651 }
[104586]652 goIntoDirectory(UIPathOperations::pathTrail(strUserHome));
[71255]653}
[71234]654
[102485]655bool UIFileManagerGuestTable::renameItem(UIFileSystemItem *item, const QString &strOldPath)
[71255]656{
[100408]657 if (!item || item->isUpDirectory())
[71255]658 return false;
[100408]659 //QString newPath = UIPathOperations::removeTrailingDelimiters(UIPathOperations::constructNewItemPath(item->path(), newBaseName));
[78057]660 QVector<KFsObjRenameFlag> aFlags(1, KFsObjRenameFlag_Replace);
[71255]661
[100408]662 m_comGuestSession.FsObjRename(strOldPath, item->path(), aFlags);
[81155]663
[71274]664 if (!m_comGuestSession.isOk())
[71693]665 {
[92733]666 emit sigLogOutput(UIErrorString::formatErrorInfo(m_comGuestSession), m_strTableName, FileManagerLogType_Error);
[71255]667 return false;
[71693]668 }
[100408]669
[71255]670 return true;
671}
672
[76177]673bool UIFileManagerGuestTable::createDirectory(const QString &path, const QString &directoryName)
[71269]674{
[71298]675 QString newDirectoryPath = UIPathOperations::mergePaths(path, directoryName);
[78057]676 QVector<KDirectoryCreateFlag> flags(1, KDirectoryCreateFlag_None);
[71269]677
[71670]678 m_comGuestSession.DirectoryCreate(newDirectoryPath, 0/*aMode*/, flags);
[71693]679
[71269]680 if (!m_comGuestSession.isOk())
681 {
[92733]682 emit sigLogOutput(newDirectoryPath.append(" could not be created"), m_strTableName, FileManagerLogType_Error);
683 emit sigLogOutput(UIErrorString::formatErrorInfo(m_comGuestSession), m_strTableName, FileManagerLogType_Error);
[71269]684 return false;
685 }
[92733]686 emit sigLogOutput(newDirectoryPath.append(" has been created"), m_strTableName, FileManagerLogType_Info);
[71269]687 return true;
688}
689
[76177]690void UIFileManagerGuestTable::copyHostToGuest(const QStringList &hostSourcePathList,
[92544]691 const QString &strDestination /* = QString() */)
[71276]692{
[75732]693 if (!checkGuestSession())
694 return;
[75000]695 QVector<QString> sourcePaths = hostSourcePathList.toVector();
[102404]696 /* Remove empty source paths. Typically happens when up directory is selected: */
697 sourcePaths.removeAll(QString());
698
[92544]699 QVector<QString> aFilters;
700 QVector<QString> aFlags;
[102393]701 QString strDestinationPath = UIPathOperations::addTrailingDelimiters(strDestination);
[75425]702 if (strDestinationPath.isEmpty())
[102404]703 strDestinationPath = UIPathOperations::addTrailingDelimiters(currentDirectoryPath());
[75897]704
705 if (strDestinationPath.isEmpty())
[75184]706 {
[92733]707 emit sigLogOutput("No destination for copy operation", m_strTableName, FileManagerLogType_Error);
[75184]708 return;
709 }
[97498]710 if (sourcePaths.empty())
[75425]711 {
[92733]712 emit sigLogOutput("No source for copy operation", m_strTableName, FileManagerLogType_Error);
[75425]713 return;
714 }
[92912]715 QString strDirectoryFlags("CopyIntoExisting,Recursive,FollowLinks");
[97554]716 QString strFileFlags("FollowLinks");
[102393]717
718 for (int i = 0; i < sourcePaths.size(); ++i)
[92544]719 {
[102393]720 sourcePaths[i] = UIPathOperations::removeTrailingDelimiters(sourcePaths[i]);
721 KFsObjType enmFileType = UIFileManagerHostTable::fileType(sourcePaths[i]);
[92913]722 if (enmFileType == KFsObjType_Unknown)
[102393]723 emit sigLogOutput(QString("Querying information for host item %1 failed.").arg(sourcePaths[i]), m_strTableName, FileManagerLogType_Error);
[92913]724 /* If the source is an directory, make sure to add the appropriate flag to make copying work
725 * into existing directories on the guest. This otherwise would fail (default): */
726 else if (enmFileType == KFsObjType_Directory)
727 aFlags << strDirectoryFlags;
[92544]728 else
[92913]729 aFlags << strFileFlags;
[92544]730 }
731
[75425]732 CProgress progress = m_comGuestSession.CopyToGuest(sourcePaths, aFilters, aFlags, strDestinationPath);
[75732]733 if (!checkGuestSession())
[75184]734 return;
[92917]735 emit sigNewFileOperation(progress, m_strTableName);
[71276]736}
737
[92688]738QUuid UIFileManagerGuestTable::machineId()
739{
740 if (m_comMachine.isNull())
741 return QUuid();
742 return m_comMachine.GetId();
743}
744
[92847]745bool UIFileManagerGuestTable::isGuestSessionRunning() const
746{
[93180]747 return m_enmState == State_SessionRunning;
[92847]748}
749
[92979]750void UIFileManagerGuestTable::setIsCurrent(bool fIsCurrent)
751{
752 if (m_fIsCurrent == fIsCurrent)
753 return;
754 m_fIsCurrent = fIsCurrent;
755 prepareActionConnections();
756}
757
[76177]758void UIFileManagerGuestTable::copyGuestToHost(const QString& hostDestinationPath)
[71298]759{
[75732]760 if (!checkGuestSession())
761 return;
[75193]762 QVector<QString> sourcePaths = selectedItemPathList().toVector();
[92544]763 QVector<QString> aFilters;
764 QVector<QString> aFlags;
[75193]765
[97498]766 /* Remove empty source paths. Typically happens when up directory is selected: */
767 sourcePaths.removeAll(QString());
768
[75425]769 if (hostDestinationPath.isEmpty())
770 {
[92733]771 emit sigLogOutput("No destination for copy operation", m_strTableName, FileManagerLogType_Error);
[75425]772 return;
773 }
774 if (sourcePaths.empty())
775 {
[92733]776 emit sigLogOutput("No source for copy operation", m_strTableName, FileManagerLogType_Error);
[75425]777 return;
778 }
779
[102393]780 QString strDestinationPath = UIPathOperations::addTrailingDelimiters(hostDestinationPath);
[92912]781 QString strDirectoryFlags("CopyIntoExisting,Recursive,FollowLinks");
782 QString strFileFlags;
[102393]783 //foreach (const QString &strSource, sourcePaths)
784 for (int i = 0; i < sourcePaths.size(); ++i)
[92544]785 {
[102393]786 sourcePaths[i] = UIPathOperations::removeTrailingDelimiters(sourcePaths[i]);
[92544]787 /** @todo Cache this info and use the item directly, which has this info already? */
788
789 /* If the source is an directory, make sure to add the appropriate flag to make copying work
790 * into existing directories on the guest. This otherwise would fail (default). */
[102393]791 CGuestFsObjInfo fileInfo = m_comGuestSession.FsObjQueryInfo(sourcePaths[i], true);
[92544]792 if (!m_comGuestSession.isOk())
793 {
[92733]794 emit sigLogOutput(UIErrorString::formatErrorInfo(m_comGuestSession), m_strTableName, FileManagerLogType_Error);
[92544]795 return;
796 }
797
[92912]798 if (fileType(fileInfo) == KFsObjType_Directory)
799 aFlags << strDirectoryFlags;
800 else
801 aFlags << strFileFlags;
[102393]802
[92544]803 }
804
[97395]805 CProgress progress = m_comGuestSession.CopyFromGuest(sourcePaths, aFilters, aFlags, strDestinationPath);
[75732]806 if (!checkGuestSession())
[75184]807 return;
[92917]808 emit sigNewFileOperation(progress, m_strTableName);
[71298]809}
810
[76300]811KFsObjType UIFileManagerGuestTable::fileType(const CFsObjInfo &fsInfo)
[71350]812{
813 if (fsInfo.isNull() || !fsInfo.isOk())
[76300]814 return KFsObjType_Unknown;
[71350]815 if (fsInfo.GetType() == KFsObjType_Directory)
[76300]816 return KFsObjType_Directory;
[71350]817 else if (fsInfo.GetType() == KFsObjType_File)
[76300]818 return KFsObjType_File;
[71350]819 else if (fsInfo.GetType() == KFsObjType_Symlink)
[76300]820 return KFsObjType_Symlink;
[71298]821
[76300]822 return KFsObjType_Unknown;
[71350]823}
824
[76300]825KFsObjType UIFileManagerGuestTable::fileType(const CGuestFsObjInfo &fsInfo)
[71385]826{
827 if (fsInfo.isNull() || !fsInfo.isOk())
[76300]828 return KFsObjType_Unknown;
[71385]829 if (fsInfo.GetType() == KFsObjType_Directory)
[76300]830 return KFsObjType_Directory;
[71385]831 else if (fsInfo.GetType() == KFsObjType_File)
[76300]832 return KFsObjType_File;
[71385]833 else if (fsInfo.GetType() == KFsObjType_Symlink)
[76300]834 return KFsObjType_Symlink;
[71385]835
[76300]836 return KFsObjType_Unknown;
[71385]837}
838
839
[76177]840QString UIFileManagerGuestTable::fsObjectPropertyString()
[71380]841{
[71385]842 QStringList selectedObjects = selectedItemPathList();
843 if (selectedObjects.isEmpty())
844 return QString();
845 if (selectedObjects.size() == 1)
846 {
847 if (selectedObjects.at(0).isNull())
848 return QString();
[71563]849
[75932]850 CGuestFsObjInfo fileInfo = m_comGuestSession.FsObjQueryInfo(selectedObjects.at(0), false /*aFollowSymlinks*/);
[71385]851 if (!m_comGuestSession.isOk())
[71693]852 {
[92733]853 emit sigLogOutput(UIErrorString::formatErrorInfo(m_comGuestSession), m_strTableName, FileManagerLogType_Error);
[71385]854 return QString();
[71693]855 }
[71385]856
[75682]857 QStringList propertyStringList;
[71563]858
[71385]859 /* Name: */
[76345]860 propertyStringList << UIFileManager::tr("<b>Name:</b> %1<br/>").arg(UIPathOperations::getObjectName(fileInfo.GetName()));
[75928]861
[71385]862 /* Size: */
[71412]863 LONG64 size = fileInfo.GetObjectSize();
[76177]864 propertyStringList << UIFileManager::tr("<b>Size:</b> %1 bytes").arg(QString::number(size));
865 if (size >= UIFileManagerTable::m_iKiloByte)
[75928]866 propertyStringList << QString(" (%1)<br/>").arg(humanReadableSize(size));
[75682]867 else
868 propertyStringList << QString("<br/>");
[75928]869
870 /* Allocated size: */
871 size = fileInfo.GetAllocatedSize();
[76177]872 propertyStringList << UIFileManager::tr("<b>Allocated:</b> %1 bytes").arg(QString::number(size));
873 if (size >= UIFileManagerTable::m_iKiloByte)
[75928]874 propertyStringList << QString(" (%1)<br/>").arg(humanReadableSize(size));
875 else
876 propertyStringList << QString("<br/>");
877
[71385]878 /* Type: */
[75928]879 QString str;
[75932]880 KFsObjType const enmType = fileInfo.GetType();
881 switch (enmType)
[75928]882 {
[76210]883 case KFsObjType_Directory: str = UIFileManager::tr("directory"); break;
884 case KFsObjType_File: str = UIFileManager::tr("file"); break;
885 case KFsObjType_Symlink: str = UIFileManager::tr("symbolic link"); break;
886 case KFsObjType_DevChar: str = UIFileManager::tr("character device"); break;
887 case KFsObjType_DevBlock: str = UIFileManager::tr("block device"); break;
888 case KFsObjType_Fifo: str = UIFileManager::tr("fifo"); break;
889 case KFsObjType_Socket: str = UIFileManager::tr("socket"); break;
890 case KFsObjType_WhiteOut: str = UIFileManager::tr("whiteout"); break;
891 case KFsObjType_Unknown: str = UIFileManager::tr("unknown"); break;
892 default: str = UIFileManager::tr("illegal-value"); break;
[75928]893 }
[76177]894 propertyStringList << UIFileManager::tr("<b>Type:</b> %1<br/>").arg(str);
[75928]895
896 /* INode number, device, link count: */
[76177]897 propertyStringList << UIFileManager::tr("<b>INode:</b> %1<br/>").arg(fileInfo.GetNodeId());
898 propertyStringList << UIFileManager::tr("<b>Device:</b> %1<br/>").arg(fileInfo.GetNodeIdDevice()); /** @todo hex */
899 propertyStringList << UIFileManager::tr("<b>Hardlinks:</b> %1<br/>").arg(fileInfo.GetHardLinks());
[75928]900
901 /* Attributes: */
902 str = fileInfo.GetFileAttributes();
903 if (!str.isEmpty())
904 {
[75932]905 int offSpace = str.indexOf(' ');
[75928]906 if (offSpace < 0)
907 offSpace = str.length();
[76177]908 propertyStringList << UIFileManager::tr("<b>Mode:</b> %1<br/>").arg(str.left(offSpace));
909 propertyStringList << UIFileManager::tr("<b>Attributes:</b> %1<br/>").arg(str.mid(offSpace + 1).trimmed());
[75928]910 }
911
912 /* Character/block device ID: */
913 ULONG uDeviceNo = fileInfo.GetDeviceNumber();
[75932]914 if (uDeviceNo != 0 || enmType == KFsObjType_DevChar || enmType == KFsObjType_DevBlock)
[76177]915 propertyStringList << UIFileManager::tr("<b>Device ID:</b> %1<br/>").arg(uDeviceNo); /** @todo hex */
[75928]916
917 /* Owner: */
[76177]918 propertyStringList << UIFileManager::tr("<b>Owner:</b> %1 (%2)<br/>").
[75928]919 arg(fileInfo.GetUserName()).arg(fileInfo.GetUID());
[76177]920 propertyStringList << UIFileManager::tr("<b>Group:</b> %1 (%2)<br/>").
[75928]921 arg(fileInfo.GetGroupName()).arg(fileInfo.GetGID());
922
923 /* Timestamps: */
[76177]924 propertyStringList << UIFileManager::tr("<b>Birth:</b> %1<br/>").
[75928]925 arg(QDateTime::fromMSecsSinceEpoch(fileInfo.GetBirthTime() / RT_NS_1MS).toString());
[76177]926 propertyStringList << UIFileManager::tr("<b>Change:</b> %1<br/>").
[75928]927 arg(QDateTime::fromMSecsSinceEpoch(fileInfo.GetChangeTime() / RT_NS_1MS).toString());
[76177]928 propertyStringList << UIFileManager::tr("<b>Modified:</b> %1<br/>").
[75928]929 arg(QDateTime::fromMSecsSinceEpoch(fileInfo.GetModificationTime() / RT_NS_1MS).toString());
[76177]930 propertyStringList << UIFileManager::tr("<b>Access:</b> %1<br/>").
[75928]931 arg(QDateTime::fromMSecsSinceEpoch(fileInfo.GetAccessTime() / RT_NS_1MS).toString());
932
[75682]933 /* Join the list elements into a single string seperated by empty string: */
934 return propertyStringList.join(QString());
[71385]935 }
[71563]936
937 int fileCount = 0;
938 int directoryCount = 0;
939 ULONG64 totalSize = 0;
940
941 for(int i = 0; i < selectedObjects.size(); ++i)
942 {
943 CGuestFsObjInfo fileInfo = m_comGuestSession.FsObjQueryInfo(selectedObjects.at(0), true);
944 if (!m_comGuestSession.isOk())
[71693]945 {
[92733]946 emit sigLogOutput(UIErrorString::formatErrorInfo(m_comGuestSession), m_strTableName, FileManagerLogType_Error);
[71563]947 continue;
[71693]948 }
949
[76300]950 KFsObjType type = fileType(fileInfo);
[71563]951
[76300]952 if (type == KFsObjType_File)
[71563]953 ++fileCount;
[76300]954 if (type == KFsObjType_Directory)
[71563]955 ++directoryCount;
956 totalSize += fileInfo.GetObjectSize();
957 }
[75682]958 QStringList propertyStringList;
[76177]959 propertyStringList << UIFileManager::tr("<b>Selected:</b> %1 files and %2 directories<br/>").
[75682]960 arg(QString::number(fileCount)).arg(QString::number(directoryCount));
[76177]961 propertyStringList << UIFileManager::tr("<b>Size (non-recursive):</b> %1 bytes").arg(QString::number(totalSize));
[71563]962 if (totalSize >= m_iKiloByte)
[75682]963 propertyStringList << QString(" (%1)").arg(humanReadableSize(totalSize));
[71563]964
[75682]965 return propertyStringList.join(QString());;
[71380]966}
[71505]967
[76177]968void UIFileManagerGuestTable::showProperties()
[71505]969{
[71563]970 if (m_comGuestSession.isNull())
971 return;
[71505]972 QString fsPropertyString = fsObjectPropertyString();
973 if (fsPropertyString.isEmpty())
974 return;
975
[77647]976 m_pPropertiesDialog = new UIPropertiesDialog(this);
[71563]977 if (!m_pPropertiesDialog)
[71505]978 return;
[71563]979
980 QStringList selectedObjects = selectedItemPathList();
981 if (selectedObjects.size() == 0)
982 return;
983
[76177]984 m_pPropertiesDialog->setWindowTitle(UIFileManager::tr("Properties"));
[71563]985 m_pPropertiesDialog->setPropertyText(fsPropertyString);
986 m_pPropertiesDialog->execute();
987
988 delete m_pPropertiesDialog;
[75184]989 m_pPropertiesDialog = 0;
[71505]990}
[71563]991
[76177]992void UIFileManagerGuestTable::determineDriveLetters()
[71832]993{
994 if (m_comGuestSession.isNull())
995 return;
[102798]996
[71832]997 KPathStyle pathStyle = m_comGuestSession.GetPathStyle();
998 if (pathStyle != KPathStyle_DOS)
999 return;
1000
[75157]1001 m_driveLetterList.clear();
[102928]1002
1003 QVector<QString> mountPoints = m_comGuestSession.GetMountPoints();
1004 if (m_comGuestSession.isOk())
[71832]1005 {
[102928]1006 foreach (const QString &strPoint, mountPoints)
1007 m_driveLetterList.push_back(UIPathOperations::replaceDosDelimeter(strPoint));
[71832]1008 }
[102928]1009 else
1010 {
1011 for (int i = 'A'; i <= 'Z'; ++i)
1012 {
1013 QString path((char)i);
1014 path += ":/";
1015 bool exists = m_comGuestSession.DirectoryExists(path, false /* aFollowSymlinks */);
1016 if (exists)
1017 m_driveLetterList.push_back(path);
1018 }
1019 }
[71832]1020}
1021
[78146]1022void UIFileManagerGuestTable::determinePathSeparator()
1023{
1024 if (m_comGuestSession.isNull())
1025 return;
1026 KPathStyle pathStyle = m_comGuestSession.GetPathStyle();
1027 if (pathStyle == KPathStyle_DOS)
1028 setPathSeparator(UIPathOperations::dosDelimiter);
1029}
1030
[76177]1031void UIFileManagerGuestTable::prepareToolbar()
[75136]1032{
1033 if (m_pToolBar && m_pActionPool)
1034 {
[100302]1035 m_pToolBar->addAction(m_pActionPool->action(UIActionIndex_M_FileManager_S_Guest_GoBackward));
1036 m_pToolBar->addAction(m_pActionPool->action(UIActionIndex_M_FileManager_S_Guest_GoForward));
[76177]1037 m_pToolBar->addAction(m_pActionPool->action(UIActionIndex_M_FileManager_S_Guest_GoUp));
1038 m_pToolBar->addAction(m_pActionPool->action(UIActionIndex_M_FileManager_S_Guest_GoHome));
1039 m_pToolBar->addAction(m_pActionPool->action(UIActionIndex_M_FileManager_S_Guest_Refresh));
[75136]1040 m_pToolBar->addSeparator();
[76177]1041 m_pToolBar->addAction(m_pActionPool->action(UIActionIndex_M_FileManager_S_Guest_Delete));
1042 m_pToolBar->addAction(m_pActionPool->action(UIActionIndex_M_FileManager_S_Guest_Rename));
1043 m_pToolBar->addAction(m_pActionPool->action(UIActionIndex_M_FileManager_S_Guest_CreateNewDirectory));
[75907]1044
[76177]1045 m_pToolBar->addAction(m_pActionPool->action(UIActionIndex_M_FileManager_S_Guest_Copy));
1046 m_pToolBar->addAction(m_pActionPool->action(UIActionIndex_M_FileManager_S_Guest_Cut));
1047 m_pToolBar->addAction(m_pActionPool->action(UIActionIndex_M_FileManager_S_Guest_Paste));
[75136]1048 m_pToolBar->addSeparator();
[76177]1049 m_pToolBar->addAction(m_pActionPool->action(UIActionIndex_M_FileManager_S_Guest_SelectAll));
1050 m_pToolBar->addAction(m_pActionPool->action(UIActionIndex_M_FileManager_S_Guest_InvertSelection));
[75136]1051 m_pToolBar->addSeparator();
[76177]1052 m_pToolBar->addAction(m_pActionPool->action(UIActionIndex_M_FileManager_S_Guest_ShowProperties));
1053 m_selectionDependentActions.insert(m_pActionPool->action(UIActionIndex_M_FileManager_S_Guest_Delete));
1054 m_selectionDependentActions.insert(m_pActionPool->action(UIActionIndex_M_FileManager_S_Guest_Rename));
1055 m_selectionDependentActions.insert(m_pActionPool->action(UIActionIndex_M_FileManager_S_Guest_Copy));
1056 m_selectionDependentActions.insert(m_pActionPool->action(UIActionIndex_M_FileManager_S_Guest_Cut));
1057 m_selectionDependentActions.insert(m_pActionPool->action(UIActionIndex_M_FileManager_S_Guest_ShowProperties));
[75907]1058
1059 /* Hide these actions for now until we have a suitable guest-to-guest copy function: */
[76177]1060 m_pActionPool->action(UIActionIndex_M_FileManager_S_Guest_Copy)->setVisible(false);
1061 m_pActionPool->action(UIActionIndex_M_FileManager_S_Guest_Cut)->setVisible(false);
1062 m_pActionPool->action(UIActionIndex_M_FileManager_S_Guest_Paste)->setVisible(false);
[92765]1063
1064 m_pToolBar->addSeparator();
1065 m_pToolBar->addAction(m_pActionPool->action(UIActionIndex_M_FileManager_T_GuestSession));
[75136]1066 }
[92754]1067
[75162]1068 setSelectionDependentActionsEnabled(false);
[75760]1069 setPasteActionEnabled(false);
[75136]1070}
1071
[76177]1072void UIFileManagerGuestTable::createFileViewContextMenu(const QWidget *pWidget, const QPoint &point)
[75202]1073{
1074 if (!pWidget)
1075 return;
1076
[75686]1077 QMenu menu;
[100302]1078 menu.addAction(m_pActionPool->action(UIActionIndex_M_FileManager_S_Guest_GoBackward));
1079 menu.addAction(m_pActionPool->action(UIActionIndex_M_FileManager_S_Guest_GoForward));
[76177]1080 menu.addAction(m_pActionPool->action(UIActionIndex_M_FileManager_S_Guest_GoUp));
[75686]1081
[76177]1082 menu.addAction(m_pActionPool->action(UIActionIndex_M_FileManager_S_Guest_GoHome));
1083 menu.addAction(m_pActionPool->action(UIActionIndex_M_FileManager_S_Guest_Refresh));
[75686]1084 menu.addSeparator();
[76177]1085 menu.addAction(m_pActionPool->action(UIActionIndex_M_FileManager_S_Guest_Delete));
1086 menu.addAction(m_pActionPool->action(UIActionIndex_M_FileManager_S_Guest_Rename));
1087 menu.addAction(m_pActionPool->action(UIActionIndex_M_FileManager_S_Guest_CreateNewDirectory));
[75686]1088 menu.addSeparator();
[76177]1089 menu.addAction(m_pActionPool->action(UIActionIndex_M_FileManager_S_Guest_Copy));
1090 menu.addAction(m_pActionPool->action(UIActionIndex_M_FileManager_S_Guest_Cut));
1091 menu.addAction(m_pActionPool->action(UIActionIndex_M_FileManager_S_Guest_Paste));
[75686]1092 menu.addSeparator();
[76177]1093 menu.addAction(m_pActionPool->action(UIActionIndex_M_FileManager_S_Guest_SelectAll));
1094 menu.addAction(m_pActionPool->action(UIActionIndex_M_FileManager_S_Guest_InvertSelection));
[75686]1095 menu.addSeparator();
[76177]1096 menu.addAction(m_pActionPool->action(UIActionIndex_M_FileManager_S_Guest_ShowProperties));
[75686]1097 menu.exec(pWidget->mapToGlobal(point));
[75202]1098}
1099
[76177]1100void UIFileManagerGuestTable::setPasteActionEnabled(bool fEnabled)
[75760]1101{
[76177]1102 m_pActionPool->action(UIActionIndex_M_FileManager_S_Guest_Paste)->setEnabled(fEnabled);
[75760]1103}
1104
[76177]1105void UIFileManagerGuestTable::pasteCutCopiedObjects()
[75760]1106{
1107}
1108
[92979]1109void UIFileManagerGuestTable::manageConnection(bool fConnect, QAction *pAction, void (UIFileManagerGuestTable::*fptr)(void))
1110{
1111 if (!pAction || !fptr)
1112 return;
1113 if (fConnect)
1114 connect(pAction, &QAction::triggered, this, fptr);
1115 else
1116 disconnect(pAction, 0, this, 0);
1117}
1118
[76177]1119void UIFileManagerGuestTable::prepareActionConnections()
[75184]1120{
[92711]1121 if (m_pActionPool->action(UIActionIndex_M_FileManager_T_GuestSession))
[92979]1122 {
1123 if (m_fIsCurrent)
1124 connect(m_pActionPool->action(UIActionIndex_M_FileManager_T_GuestSession), &QAction::toggled,
1125 this, &UIFileManagerGuestTable::sltGuestSessionPanelToggled);
1126 else
1127 disconnect(m_pActionPool->action(UIActionIndex_M_FileManager_T_GuestSession), 0, this, 0);
1128 }
[92711]1129
[92979]1130 manageConnection(m_fIsCurrent, m_pActionPool->action(UIActionIndex_M_FileManager_S_Guest_GoUp), &UIFileManagerTable::sltGoUp);
1131 manageConnection(m_fIsCurrent, m_pActionPool->action(UIActionIndex_M_FileManager_S_Guest_GoHome), &UIFileManagerTable::sltGoHome);
[100304]1132 manageConnection(m_fIsCurrent, m_pActionPool->action(UIActionIndex_M_FileManager_S_Guest_GoBackward), &UIFileManagerTable::sltGoBackward);
1133 manageConnection(m_fIsCurrent, m_pActionPool->action(UIActionIndex_M_FileManager_S_Guest_GoForward), &UIFileManagerTable::sltGoForward);
[92979]1134 manageConnection(m_fIsCurrent, m_pActionPool->action(UIActionIndex_M_FileManager_S_Guest_Refresh), &UIFileManagerTable::sltRefresh);
1135 manageConnection(m_fIsCurrent, m_pActionPool->action(UIActionIndex_M_FileManager_S_Guest_Delete), &UIFileManagerTable::sltDelete);
1136 manageConnection(m_fIsCurrent, m_pActionPool->action(UIActionIndex_M_FileManager_S_Guest_Rename), &UIFileManagerTable::sltRename);
1137 manageConnection(m_fIsCurrent, m_pActionPool->action(UIActionIndex_M_FileManager_S_Guest_Copy), &UIFileManagerTable::sltCopy);
1138 manageConnection(m_fIsCurrent, m_pActionPool->action(UIActionIndex_M_FileManager_S_Guest_Cut), &UIFileManagerTable::sltCut);
1139 manageConnection(m_fIsCurrent, m_pActionPool->action(UIActionIndex_M_FileManager_S_Guest_Paste), &UIFileManagerTable::sltPaste);
1140 manageConnection(m_fIsCurrent, m_pActionPool->action(UIActionIndex_M_FileManager_S_Guest_SelectAll), &UIFileManagerTable::sltSelectAll);
1141 manageConnection(m_fIsCurrent, m_pActionPool->action(UIActionIndex_M_FileManager_S_Guest_InvertSelection), &UIFileManagerTable::sltInvertSelection);
1142 manageConnection(m_fIsCurrent, m_pActionPool->action(UIActionIndex_M_FileManager_S_Guest_ShowProperties), &UIFileManagerTable::sltShowProperties);
1143 manageConnection(m_fIsCurrent, m_pActionPool->action(UIActionIndex_M_FileManager_S_Guest_CreateNewDirectory), &UIFileManagerTable::sltCreateNewDirectory);
[100302]1144
1145 /* Also disable/enable go forward/backward actions: */
1146 toggleForwardBackwardActions();
[75184]1147}
1148
[92710]1149void UIFileManagerGuestTable::prepareGuestSessionPanel()
1150{
1151 if (m_pMainLayout)
1152 {
[93697]1153 m_pGuestSessionWidget = new UIGuestSessionWidget;
[93682]1154 if (m_pGuestSessionWidget)
[92711]1155 {
[93682]1156 m_pMainLayout->addWidget(m_pGuestSessionWidget, m_pMainLayout->rowCount(), 0, 1, m_pMainLayout->columnCount());
1157 m_pGuestSessionWidget->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Maximum);
[93697]1158 connect(m_pGuestSessionWidget, &UIGuestSessionWidget::sigOpenSession,
1159 this, &UIFileManagerGuestTable::sltOpenGuestSession);
1160 connect(m_pGuestSessionWidget, &UIGuestSessionWidget::sigCloseSession,
[92753]1161 this, &UIFileManagerGuestTable::sltHandleCloseSessionRequest);
[92711]1162 }
[92710]1163 }
1164}
1165
[76177]1166bool UIFileManagerGuestTable::checkGuestSession()
[75732]1167{
1168 if (!m_comGuestSession.isOk())
1169 {
[92733]1170 emit sigLogOutput(UIErrorString::formatErrorInfo(m_comGuestSession), m_strTableName, FileManagerLogType_Error);
[75732]1171 return false;
1172 }
1173 return true;
1174}
[75941]1175
[76177]1176QString UIFileManagerGuestTable::permissionString(const CFsObjInfo &fsInfo)
[75941]1177{
1178 /* Attributes: */
1179 QString strAttributes = fsInfo.GetFileAttributes();
1180
1181 if (strAttributes.isEmpty())
1182 return strAttributes;
1183
1184 int offSpace = strAttributes.indexOf(' ');
1185 if (offSpace < 0)
1186 offSpace = strAttributes.length();
1187 return strAttributes.left(offSpace);
1188}
1189
[76626]1190bool UIFileManagerGuestTable::isFileObjectHidden(const CFsObjInfo &fsInfo)
1191{
1192 QString strAttributes = fsInfo.GetFileAttributes();
1193
1194 if (strAttributes.isEmpty())
1195 return false;
1196
1197 int offSpace = strAttributes.indexOf(' ');
1198 if (offSpace < 0)
1199 offSpace = strAttributes.length();
1200 QString strRight(strAttributes.mid(offSpace + 1).trimmed());
1201
1202 if (strRight.indexOf('H', Qt::CaseSensitive) == -1)
1203 return false;
1204 return true;
1205}
1206
[92711]1207void UIFileManagerGuestTable::sltGuestSessionPanelToggled(bool fChecked)
1208{
[93682]1209 if (m_pGuestSessionWidget)
1210 m_pGuestSessionWidget->setVisible(fChecked);
[92711]1211}
1212
[92790]1213void UIFileManagerGuestTable::sltMachineStateChange(const QUuid &uMachineId, const KMachineState enmMachineState)
[92765]1214{
1215 if (uMachineId.isNull() || m_comMachine.isNull() || uMachineId != m_comMachine.GetId())
1216 return;
[92790]1217
1218 if (enmMachineState == KMachineState_Running)
1219 openMachineSession();
[93726]1220 else if (enmMachineState != KMachineState_Paused)
[92790]1221 cleanAll();
[92860]1222 setStateAndEnableWidgets();
[92765]1223}
1224
[92790]1225bool UIFileManagerGuestTable::closeMachineSession()
[92688]1226{
[92790]1227 if (!m_comGuest.isNull())
1228 m_comGuest.detach();
1229
1230 if (!m_comConsole.isNull())
1231 m_comConsole.detach();
1232
[92814]1233 if (!m_comSession.isNull())
1234 {
1235 m_comSession.UnlockMachine();
1236 m_comSession.detach();
1237 }
[92790]1238 return true;
1239}
1240
1241bool UIFileManagerGuestTable::openMachineSession()
1242{
[92688]1243 if (m_comMachine.isNull())
1244 {
[92733]1245 emit sigLogOutput("Invalid machine reference", m_strTableName, FileManagerLogType_Error);
[92688]1246 return false;
1247 }
[105081]1248 m_comSession = openSession(m_comMachine.GetId(), KLockType_Shared);
[92688]1249 if (m_comSession.isNull())
1250 {
[92733]1251 emit sigLogOutput("Could not open machine session", m_strTableName, FileManagerLogType_Error);
[92688]1252 return false;
1253 }
1254
[92790]1255 m_comConsole = m_comSession.GetConsole();
1256 if (m_comConsole.isNull())
[92688]1257 {
[92790]1258 emit sigLogOutput("Machine console is invalid", m_strTableName, FileManagerLogType_Error);
[92688]1259 return false;
1260 }
1261
[92790]1262 m_comGuest = m_comConsole.GetGuest();
1263 if (m_comGuest.isNull())
[92688]1264 {
[92790]1265 emit sigLogOutput("Guest reference is invalid", m_strTableName, FileManagerLogType_Error);
[92688]1266 return false;
1267 }
1268
[92790]1269 /* Prepare guest listener for guest session related events: */
1270 {
1271 QVector<KVBoxEventType> eventTypes;
1272 eventTypes << KVBoxEventType_OnGuestSessionRegistered;
1273 prepareListener(m_pQtGuestListener, m_comGuestListener, m_comGuest.GetEventSource(), eventTypes);
1274 connect(m_pQtGuestListener->getWrapped(), &UIMainEventListener::sigGuestSessionUnregistered,
1275 this, &UIFileManagerGuestTable::sltGuestSessionUnregistered);
1276 connect(m_pQtGuestListener->getWrapped(), &UIMainEventListener::sigGuestSessionRegistered,
1277 this, &UIFileManagerGuestTable::sltGuestSessionRegistered);
1278 }
[92688]1279
[92790]1280 /* Prepare console listener for guest additions state change events: */
1281 {
1282 QVector<KVBoxEventType> eventTypes;
1283 eventTypes << KVBoxEventType_OnAdditionsStateChanged;
1284 prepareListener(m_pQtConsoleListener, m_comConsoleListener, m_comConsole.GetEventSource(), eventTypes);
1285 connect(m_pQtConsoleListener->getWrapped(), &UIMainEventListener::sigAdditionsChange,
1286 this, &UIFileManagerGuestTable::sltAdditionsStateChange);
1287 }
1288 emit sigLogOutput("Shared machine session opened", m_strTableName, FileManagerLogType_Info);
[92688]1289 return true;
1290}
1291
[100174]1292int UIFileManagerGuestTable::isGuestAdditionsAvailable(const char* pszMinimumVersion)
[92688]1293{
[100174]1294 if (m_comGuest.isNull() || !pszMinimumVersion)
1295 return 0;
[100245]1296
1297 /* Guest control stuff is in userland: */
1298 if (!m_comGuest.GetAdditionsStatus(KAdditionsRunLevelType_Userland))
1299 return 0;
1300
1301 if (!m_comGuest.isOk())
1302 return 0;
1303
1304 /* Check the related GA facility: */
1305 LONG64 iLastUpdatedIgnored;
1306 if (m_comGuest.GetFacilityStatus(KAdditionsFacilityType_VBoxService, iLastUpdatedIgnored) != KAdditionsFacilityStatus_Active)
1307 return 0;
1308
1309 if (!m_comGuest.isOk())
1310 return 0;
1311
1312 /* Check if GA is new enough to have the goodies: */
1313 QString strGAVersion = m_comGuest.GetAdditionsVersion();
1314 int iCode = RTStrVersionCompare(strGAVersion.toUtf8().constData(), pszMinimumVersion);
1315 if (iCode >= 0)
1316 return 1;
1317 else
1318 return -1;
1319
[100174]1320 return 0;
[92688]1321}
1322
[92790]1323void UIFileManagerGuestTable::cleanupGuestListener()
[92765]1324{
[92790]1325 if (!m_pQtGuestListener.isNull())
1326 {
[92814]1327 m_pQtGuestListener->getWrapped()->disconnect();
[92790]1328 if (!m_comGuest.isNull())
1329 cleanupListener(m_pQtGuestListener, m_comGuestListener, m_comGuest.GetEventSource());
1330 }
[92765]1331}
[92733]1332
[92790]1333void UIFileManagerGuestTable::cleanupGuestSessionListener()
[92688]1334{
[92790]1335 if (!m_pQtSessionListener.isNull())
1336 {
[92814]1337 m_pQtSessionListener->getWrapped()->disconnect();
[92790]1338 if (!m_comGuestSession.isNull())
1339 cleanupListener(m_pQtSessionListener, m_comSessionListener, m_comGuestSession.GetEventSource());
1340 }
[92733]1341}
1342
[92790]1343void UIFileManagerGuestTable::cleanupConsoleListener()
[92753]1344{
[92790]1345 if (!m_pQtConsoleListener.isNull())
1346 {
[92814]1347 m_pQtConsoleListener->getWrapped()->disconnect();
[92790]1348 if (!m_comConsole.isNull())
1349 cleanupListener(m_pQtConsoleListener, m_comConsoleListener, m_comConsole.GetEventSource());
1350 }
[92753]1351}
[92733]1352
1353void UIFileManagerGuestTable::prepareListener(ComObjPtr<UIMainEventListenerImpl> &QtListener,
1354 CEventListener &comEventListener,
1355 CEventSource comEventSource, QVector<KVBoxEventType>& eventTypes)
1356{
[92688]1357 if (!comEventSource.isOk())
1358 return;
1359 /* Create event listener instance: */
1360 QtListener.createObject();
1361 QtListener->init(new UIMainEventListener, this);
1362 comEventListener = CEventListener(QtListener);
1363
1364 /* Register event listener for CProgress event source: */
1365 comEventSource.RegisterListener(comEventListener, eventTypes, FALSE /* active? */);
1366
1367 /* Register event sources in their listeners as well: */
1368 QtListener->getWrapped()->registerSource(comEventSource, comEventListener);
1369}
1370
[92790]1371void UIFileManagerGuestTable::cleanupListener(ComObjPtr<UIMainEventListenerImpl> &QtListener,
1372 CEventListener &comEventListener,
1373 CEventSource comEventSource)
1374{
1375 if (!comEventSource.isOk())
1376 return;
1377 /* Unregister everything: */
1378 QtListener->getWrapped()->unregisterSources();
[92860]1379 QtListener.setNull();
[92790]1380 /* Make sure VBoxSVC is available: */
[103771]1381 if (!gpGlobalSession->isVBoxSVCAvailable())
[92790]1382 return;
1383
1384 /* Unregister event listener for CProgress event source: */
1385 comEventSource.UnregisterListener(comEventListener);
1386}
1387
[92733]1388void UIFileManagerGuestTable::sltGuestSessionUnregistered(CGuestSession guestSession)
[92688]1389{
[92733]1390 if (guestSession.isNull())
1391 return;
1392 if (guestSession == m_comGuestSession && !m_comGuestSession.isNull())
1393 {
1394 m_comGuestSession.detach();
1395 emit sigLogOutput("Guest session unregistered", m_strTableName, FileManagerLogType_Info);
1396 }
1397}
1398
1399void UIFileManagerGuestTable::sltGuestSessionRegistered(CGuestSession guestSession)
1400{
1401 if (guestSession == m_comGuestSession && !m_comGuestSession.isNull())
1402 emit sigLogOutput("Guest session registered", m_strTableName, FileManagerLogType_Info);
1403}
1404
1405void UIFileManagerGuestTable::sltGuestSessionStateChanged(const CGuestSessionStateChangedEvent &cEvent)
1406{
1407 if (cEvent.isOk())
1408 {
1409 CVirtualBoxErrorInfo cErrorInfo = cEvent.GetError();
[92896]1410 if (cErrorInfo.GetResultDetail() < VINF_SUCCESS)
[92733]1411 emit sigLogOutput(cErrorInfo.GetText(), m_strTableName, FileManagerLogType_Error);
[92896]1412
[93682]1413 if (m_pGuestSessionWidget)
1414 m_pGuestSessionWidget->markForError(cErrorInfo.GetResultDetail() == VERR_AUTHENTICATION_FAILURE);
[92733]1415 }
[95711]1416
1417 setStateAndEnableWidgets();
1418
[100174]1419 if (m_comGuestSession.isNull())
1420 emit sigLogOutput("Guest session is invalid!", m_strTableName, FileManagerLogType_Error);
1421 else
[92733]1422 {
[100174]1423 if (m_comGuestSession.isOk())
1424 {
1425 emit sigLogOutput(QString("%1: %2").arg("Guest session status has changed").arg(gpConverter->toString(m_comGuestSession.GetStatus())),
1426 m_strTableName, FileManagerLogType_Info);
[92884]1427
[100174]1428 switch (m_comGuestSession.GetStatus())
[95317]1429 {
[100174]1430 case KGuestSessionStatus_Started:
1431 {
1432 initFileTable();
1433 break;
1434 }
1435 case KGuestSessionStatus_Terminating:
1436 case KGuestSessionStatus_Terminated:
1437 case KGuestSessionStatus_TimedOutKilled:
1438 case KGuestSessionStatus_TimedOutAbnormally:
1439 case KGuestSessionStatus_Down:
1440 case KGuestSessionStatus_Error:
1441 {
1442 cleanupGuestSessionListener();
1443 closeGuestSession();
1444 break;
1445 }
1446 case KGuestSessionStatus_Undefined:
1447 case KGuestSessionStatus_Starting:
1448 case KGuestSessionStatus_Max:
1449 default:
1450 break;
[95317]1451 }
[92884]1452 }
[100174]1453 else
1454 emit sigLogOutput(UIErrorString::formatErrorInfo(m_comGuestSession), m_strTableName, FileManagerLogType_Error);
[92733]1455 }
1456}
1457
[93697]1458void UIFileManagerGuestTable::sltOpenGuestSession(QString strUserName, QString strPassword)
[92741]1459{
1460 if (strUserName.isEmpty())
1461 {
1462 emit sigLogOutput("No user name is given", m_strTableName, FileManagerLogType_Error);
[93682]1463 if (m_pGuestSessionWidget)
1464 m_pGuestSessionWidget->markForError(true);
[92741]1465 return;
1466 }
[92894]1467 openGuestSession(strUserName, strPassword);
[92741]1468}
1469
[100301]1470void UIFileManagerGuestTable::toggleForwardBackwardActions()
1471{
[100324]1472 if (!m_pNavigationWidget)
1473 return;
[100302]1474 if (m_pActionPool->action(UIActionIndex_M_FileManager_S_Guest_GoForward))
[100324]1475 m_pActionPool->action(UIActionIndex_M_FileManager_S_Guest_GoForward)->setEnabled(m_pNavigationWidget->canGoForward());
[100302]1476 if (m_pActionPool->action(UIActionIndex_M_FileManager_S_Guest_GoBackward))
[100324]1477 m_pActionPool->action(UIActionIndex_M_FileManager_S_Guest_GoBackward)->setEnabled(m_pNavigationWidget->canGoBackward());
[100301]1478}
1479
[92860]1480void UIFileManagerGuestTable::setState()
[92753]1481{
1482 if (m_comMachine.isNull())
[92765]1483 {
[92860]1484 m_enmState = State_InvalidMachineReference;
1485 return;
[92765]1486 }
[93726]1487 if (m_comMachine.GetState() == KMachineState_Paused)
1488 {
1489 m_enmState = State_MachinePaused;
1490 return;
1491 }
[92753]1492 if (m_comMachine.GetState() != KMachineState_Running)
[92765]1493 {
[92860]1494 m_enmState = State_MachineNotRunning;
1495 return;
[92765]1496 }
[100174]1497
1498 int iGADetectCode = isGuestAdditionsAvailable(pszMinimumGuestAdditionVersion);
1499 if (iGADetectCode == 0)
[92765]1500 {
[92860]1501 m_enmState = State_NoGuestAdditions;
1502 return;
[92765]1503 }
[100174]1504 else if (iGADetectCode == -1)
1505 {
1506 m_enmState = State_GuestAdditionsTooOld;
1507 return;
1508 }
1509
[92860]1510 if (!m_comGuestSession.isNull() && m_comGuestSession.GetStatus() == KGuestSessionStatus_Started)
1511 {
1512 m_enmState = State_SessionRunning;
1513 return;
1514 }
[95711]1515 if (!m_comGuestSession.isNull() && m_comGuestSession.GetStatus() == KGuestSessionStatus_Error)
1516 {
1517 m_enmState = State_SessionError;
1518 return;
1519 }
[92860]1520 m_enmState = State_SessionPossible;
[92753]1521}
1522
[92860]1523void UIFileManagerGuestTable::setStateAndEnableWidgets()
1524{
1525 setState();
1526 setSessionDependentWidgetsEnabled();
[104228]1527 sltRetranslateUI();
[92860]1528}
1529
[92753]1530void UIFileManagerGuestTable::sltHandleCloseSessionRequest()
1531{
[92884]1532 cleanupGuestSessionListener();
[92790]1533 closeGuestSession();
[92894]1534 setStateAndEnableWidgets();
[92753]1535}
1536
[92787]1537void UIFileManagerGuestTable::sltCommitDataSignalReceived()
1538{
[92790]1539 cleanAll();
1540 if (!m_comMachine.isNull())
1541 m_comMachine.detach();
[92787]1542}
1543
[92790]1544void UIFileManagerGuestTable::sltAdditionsStateChange()
[92787]1545{
[92860]1546 setStateAndEnableWidgets();
[92787]1547}
1548
[92860]1549void UIFileManagerGuestTable::setSessionDependentWidgetsEnabled()
[92765]1550{
[93476]1551 /* Disable menu actions if guest session is not running: */
1552 UIMenu *pGuestSubmenu = m_pActionPool->action(UIActionIndex_M_FileManager_M_GuestSubmenu)->menu();
1553 if (pGuestSubmenu)
1554 pGuestSubmenu->setEnabled(m_enmState == State_SessionRunning);
1555 UIMenu *pHostSubmenu = m_pActionPool->action(UIActionIndex_M_FileManager_M_HostSubmenu)->menu();
1556 if (pHostSubmenu)
1557 pHostSubmenu->setEnabled(m_enmState == State_SessionRunning);
1558
1559 /*Manage the guest session (login) widget: */
[93682]1560 if (m_pGuestSessionWidget)
[92860]1561 {
[95711]1562 m_pGuestSessionWidget->setLoginWidgetsEnabled(m_enmState == State_SessionPossible ||
1563 m_enmState == State_SessionRunning ||
1564 m_enmState == State_SessionError);
[93682]1565 if (m_enmState == State_SessionPossible)
[93697]1566 m_pGuestSessionWidget->switchSessionOpenMode();
[93682]1567 else if (m_enmState == State_SessionRunning)
1568 m_pGuestSessionWidget->switchSessionCloseMode();
[92860]1569 }
[93476]1570 /* Call to parent: */
1571 setSessionWidgetsEnabled(m_enmState == State_SessionRunning);
1572
[93180]1573 emit sigStateChanged(m_enmState == State_SessionRunning);
[92765]1574}
[92753]1575
[102378]1576bool UIFileManagerGuestTable::isWindowsFileSystem() const
[102363]1577{
[102378]1578 if (!m_comMachine.isOk())
[102363]1579 return false;
[102378]1580 return m_comMachine.GetOSTypeId().contains("windows", Qt::CaseInsensitive);
[102363]1581}
1582
[92790]1583bool UIFileManagerGuestTable::openGuestSession(const QString &strUserName, const QString &strPassword)
[92787]1584{
[92790]1585 if (m_comGuest.isNull())
1586 {
1587 emit sigLogOutput("Guest reference is invalid", m_strTableName, FileManagerLogType_Error);
1588 return false;
1589 }
[92787]1590
[100174]1591 int iGADetectCode = isGuestAdditionsAvailable(pszMinimumGuestAdditionVersion);
1592 if (iGADetectCode == 0)
[92790]1593 {
[100174]1594 emit sigLogOutput("Could not find Guest Additions",
1595 m_strTableName, FileManagerLogType_Error);
[93682]1596 if (m_pGuestSessionWidget)
1597 m_pGuestSessionWidget->markForError(true);
[92790]1598 return false;
1599 }
[100174]1600 else if (iGADetectCode == -1)
1601 {
1602 emit sigLogOutput(QString("%1 %2").arg("The Guest Additions are older than ").arg(pszMinimumGuestAdditionVersion),
1603 m_strTableName, FileManagerLogType_Error);
1604 if (m_pGuestSessionWidget)
1605 m_pGuestSessionWidget->markForError(true);
1606 return false;
1607 }
[92787]1608
[92790]1609 m_comGuestSession = m_comGuest.CreateSession(strUserName, strPassword,
1610 QString() /* Domain */, "File Manager Session");
1611 if (m_comGuestSession.isNull())
1612 {
1613 emit sigLogOutput("Could not create guest session", m_strTableName, FileManagerLogType_Error);
1614 return false;
1615 }
[92787]1616
[92790]1617 if (!m_comGuestSession.isOk())
1618 {
1619 emit sigLogOutput(UIErrorString::formatErrorInfo(m_comGuestSession), m_strTableName, FileManagerLogType_Error);
1620 return false;
1621 }
[92787]1622
[92790]1623 QVector<KVBoxEventType> eventTypes(QVector<KVBoxEventType>() << KVBoxEventType_OnGuestSessionStateChanged);
1624 prepareListener(m_pQtSessionListener, m_comSessionListener, m_comGuestSession.GetEventSource(), eventTypes);
1625 qRegisterMetaType<CGuestSessionStateChangedEvent>();
1626 connect(m_pQtSessionListener->getWrapped(), &UIMainEventListener::sigGuestSessionStatedChanged,
1627 this, &UIFileManagerGuestTable::sltGuestSessionStateChanged);
1628
1629 return true;
[92787]1630}
1631
[92790]1632void UIFileManagerGuestTable::closeGuestSession()
1633{
1634 if (!m_comGuestSession.isNull())
[92884]1635 {
[92790]1636 m_comGuestSession.Close();
[92884]1637 m_comGuestSession.detach();
1638 emit sigLogOutput("Guest session is closed", m_strTableName, FileManagerLogType_Info);
1639 }
1640 reset();
[92688]1641}
1642
[92790]1643void UIFileManagerGuestTable::cleanAll()
[92688]1644{
[92790]1645 cleanupConsoleListener();
1646 cleanupGuestListener();
1647 cleanupGuestSessionListener();
[92688]1648
[92790]1649 closeGuestSession();
1650 closeMachineSession();
[92688]1651}
1652
[76177]1653#include "UIFileManagerGuestTable.moc"
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle
ContactPrivacy/Do Not Sell My InfoTerms of Use