VirtualBox

source: vbox/trunk/src/VBox/Frontends/VirtualBox/src/guestctrl/UIFileManagerTable.h@ 103982

Last change on this file since 103982 was 103977, checked in by vboxsync, 9 months ago

Apply RT_OVERRIDE/NS_OVERRIDE where required to shut up clang.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 13.4 KB
Line 
1/* $Id: UIFileManagerTable.h 103977 2024-03-21 02:04:52Z vboxsync $ */
2/** @file
3 * VBox Qt GUI - UIFileManagerTable class declaration.
4 */
5
6/*
7 * Copyright (C) 2016-2023 Oracle and/or its affiliates.
8 *
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
26 */
27
28#ifndef FEQT_INCLUDED_SRC_guestctrl_UIFileManagerTable_h
29#define FEQT_INCLUDED_SRC_guestctrl_UIFileManagerTable_h
30#ifndef RT_WITHOUT_PRAGMA_ONCE
31# pragma once
32#endif
33
34/* Qt includes: */
35#include <QItemSelectionModel>
36#include <QMutex>
37#include <QThread>
38#include <QWidget>
39
40/* COM includes: */
41#include "CGuestSession.h"
42#include "KFsObjType.h"
43
44/* GUI includes: */
45#include "QIDialog.h"
46#include "QITableView.h"
47#include "QIWithRetranslateUI.h"
48#include "UIGuestControlDefs.h"
49
50/* Forward declarations: */
51class QAction;
52class QFileInfo;
53class QILabel;
54class QILineEdit;
55class QGridLayout;
56class QSortFilterProxyModel;
57class QTextEdit;
58class QHBoxLayout;
59class QVBoxLayout;
60class UIActionPool;
61class UIFileSystemItem;
62class UIFileSystemModel;
63class UIFileSystemProxyModel;
64class UIFileTableNavigationWidget;
65class UIGuestControlFileView;
66class QIToolBar;
67
68/** A simple struck to store some statictics for a directory. Mainly used by UIDirectoryDiskUsageComputer instances. */
69class UIDirectoryStatistics
70{
71public:
72 UIDirectoryStatistics();
73 ULONG64 m_totalSize;
74 unsigned m_uFileCount;
75 unsigned m_uDirectoryCount;
76 unsigned m_uSymlinkCount;
77};
78
79Q_DECLARE_METATYPE(UIDirectoryStatistics);
80
81
82/** Examines the paths in @p strStartPath and collects some staticstics from them recursively (in case directories)
83 * Runs on a worker thread to avoid GUI freezes. UIGuestFileTable and UIHostFileTable uses specialized children
84 * of this class since the calls made on file objects are different. */
85class UIDirectoryDiskUsageComputer : public QThread
86{
87 Q_OBJECT;
88
89signals:
90
91 void sigResultUpdated(UIDirectoryStatistics);
92
93public:
94
95 UIDirectoryDiskUsageComputer(QObject *parent, QStringList strStartPath);
96 /** Sets the m_fOkToContinue to false. This results an early termination
97 * of the directoryStatisticsRecursive member function. */
98 void stopRecursion();
99
100protected:
101
102 /** Read the directory with the path @p path recursively and collect #of objects and total size */
103 virtual void directoryStatisticsRecursive(const QString &path, UIDirectoryStatistics &statistics) = 0;
104 virtual void run() RT_OVERRIDE;
105 /** Returns the m_fOkToContinue flag */
106 bool isOkToContinue() const;
107
108 /** Stores a list of paths whose statistics are accumulated, can be file, directory etc: */
109 QStringList m_pathList;
110 UIDirectoryStatistics m_resultStatistics;
111 QMutex m_mutex;
112
113private:
114
115 bool m_fOkToContinue;
116};
117
118/** A QIDialog child to display properties of a file object */
119class UIPropertiesDialog : public QIDialog
120{
121
122 Q_OBJECT;
123
124public:
125
126 UIPropertiesDialog(QWidget *pParent = 0, Qt::WindowFlags enmFlags = Qt::WindowFlags());
127 void setPropertyText(const QString &strProperty);
128 void addDirectoryStatistics(UIDirectoryStatistics statictics);
129
130private:
131
132 QVBoxLayout *m_pMainLayout;
133 QTextEdit *m_pInfoEdit;
134 QString m_strProperty;
135};
136
137/** This class serves a base class for file table. Currently a guest version
138 * and a host version are derived from this base. Each of these children
139 * populates the UIFileSystemModel by scanning the file system
140 * differently. The file structure kept in this class as a tree. */
141class UIFileManagerTable : public QIWithRetranslateUI<QWidget>
142{
143 Q_OBJECT;
144
145signals:
146
147 void sigLogOutput(QString strLog, const QString &strMachineName, FileManagerLogType eLogType);
148 void sigDeleteConfirmationOptionChanged();
149 void sigSelectionChanged(bool fHasSelection);
150 void sigAltDoubleClick();
151
152public:
153
154 UIFileManagerTable(UIActionPool *pActionPool, QWidget *pParent = 0);
155 virtual ~UIFileManagerTable();
156 /** Deletes all the tree nodes */
157 void reset();
158 /** Returns the path of the rootIndex */
159 QString currentDirectoryPath() const;
160 /** Returns the paths of the selected items (if any) as a list */
161 QStringList selectedItemPathList();
162 virtual void refresh();
163 static const unsigned m_iKiloByte;
164 static QString humanReadableSize(ULONG64 size);
165 /** Peroforms whatever is necessary after a UIFileManagerOptions change. */
166 void optionsUpdated();
167 bool hasSelection() const;
168 void setDragDropMode(QAbstractItemView::DragDropMode behavior);
169 virtual bool isWindowsFileSystem() const = 0;
170
171public slots:
172
173 void sltReceiveDirectoryStatistics(UIDirectoryStatistics statictics);
174 void sltCreateNewDirectory();
175 /* index is passed by the item view and represents the double clicked object's 'proxy' model index */
176 void sltItemDoubleClicked(const QModelIndex &index);
177 void sltItemClicked(const QModelIndex &index);
178 void sltAltDoubleClick();
179 void sltGoUp();
180 void sltGoHome();
181 void sltGoForward();
182 void sltGoBackward();
183 void sltRefresh();
184 void sltDelete();
185 /** Calls the edit on the data item over m_pView. This causes setData(..) call on the model. After setting
186 * user entered text as the name of the item m_pModel signals. This signal is handled by sltHandleItemRenameAttempt which
187 * tries to rename the corresponding file object by calling renameItem(...). If this rename fails the old name of the
188 * model item is restored and view is refreshed by sltHandleItemRenameAttempt. */
189 void sltRename();
190 void sltCopy();
191 void sltCut();
192 void sltPaste();
193 void sltShowProperties();
194 void sltSelectAll();
195 void sltInvertSelection();
196
197protected:
198
199 /** This enum is used when performing a gueest-to-guest or host-to-host
200 * file operations. Paths of source file objects are kept in a single buffer
201 * and a flag to determine if it is a cut or copy operation is needed */
202 enum FileOperationType
203 {
204 FileOperationType_Copy,
205 FileOperationType_Cut,
206 FileOperationType_None,
207 FileOperationType_Max
208 };
209
210 void retranslateUi() RT_OVERRIDE;
211 void updateCurrentLocationEdit(const QString& strLocation);
212 /* @p index is for model not for 'proxy' model */
213 void changeLocation(const QModelIndex &index);
214 void initializeFileTree();
215 void checkDotDot(QMap<QString,UIFileSystemItem*> &map, UIFileSystemItem *parent, bool isStartDir);
216
217 virtual bool readDirectory(const QString& strPath, UIFileSystemItem *parent, bool isStartDir = false) = 0;
218 virtual void deleteByItem(UIFileSystemItem *item) = 0;
219 virtual void goToHomeDirectory() = 0;
220 virtual bool renameItem(UIFileSystemItem *item, const QString &strOldPath) = 0;
221 virtual bool createDirectory(const QString &path, const QString &directoryName) = 0;
222 virtual QString fsObjectPropertyString() = 0;
223 virtual void showProperties() = 0;
224 /** For non-windows system does nothing and for windows systems populates m_driveLetterList with
225 * drive letters */
226 virtual void determineDriveLetters() = 0;
227 virtual void determinePathSeparator() = 0;
228 virtual void prepareToolbar() = 0;
229 virtual void createFileViewContextMenu(const QWidget *pWidget, const QPoint &point) = 0;
230 virtual void toggleForwardBackwardActions() = 0;
231 virtual bool event(QEvent *pEvent) RT_OVERRIDE;
232
233 /** @name Copy/Cut guest-to-guest (host-to-host) stuff.
234 * @{ */
235 /** Disable/enable paste action depending on the m_eFileOperationType. */
236 virtual void setPasteActionEnabled(bool fEnabled) = 0;
237 virtual void pasteCutCopiedObjects() = 0;
238 /** stores the type of the pending guest-to-guest (host-to-host) file operation. */
239 FileOperationType m_eFileOperationType;
240 /** @} */
241
242 QString fileTypeString(KFsObjType type);
243 /* @p item index is item location in model not in 'proxy' model */
244 void goIntoDirectory(const QModelIndex &itemIndex);
245 /** Follows the path trail, opens directories as it descends */
246 void goIntoDirectory(const QStringList &pathTrail);
247 /** Goes into directory pointed by the @p item */
248 void goIntoDirectory(UIFileSystemItem *item);
249 UIFileSystemItem* indexData(const QModelIndex &index) const;
250 bool eventFilter(QObject *pObject, QEvent *pEvent) RT_OVERRIDE;
251 CGuestFsObjInfo guestFsObjectInfo(const QString& path, CGuestSession &comGuestSession) const;
252 void setSelectionDependentActionsEnabled(bool fIsEnabled);
253 UIFileSystemItem* rootItem();
254 void setPathSeparator(const QChar &separator);
255 QHBoxLayout* toolBarLayout();
256 void setSessionWidgetsEnabled(bool fEnabled);
257 void setModelFileSystem(bool fIsWindowsFileSystem);
258
259 QILabel *m_pLocationLabel;
260 UIPropertiesDialog *m_pPropertiesDialog;
261 UIActionPool *m_pActionPool;
262 QIToolBar *m_pToolBar;
263 QGridLayout *m_pMainLayout;
264 /** Stores the drive letters the file system has (for windows system). For non-windows
265 * systems this is empty and for windows system it should at least contain C:/ */
266 QStringList m_driveLetterList;
267 /** The set of actions which need some selection to work on. Like cut, copy etc. */
268 QSet<QAction*> m_selectionDependentActions;
269 /** The absolute path list of the file objects which user has chosen to cut/copy. this
270 * list will be cleaned after a paste operation or overwritten by a subsequent cut/copy.
271 * Currently only used by the guest side. */
272 QStringList m_copyCutBuffer;
273 /** This name is appended to the log messages which are shown in the log panel. */
274 QString m_strTableName;
275 /** Contains m_pBreadCrumbsWidget and m_pLocationComboBox. */
276 UIFileTableNavigationWidget *m_pNavigationWidget;
277
278private slots:
279
280 void sltCreateFileViewContextMenu(const QPoint &point);
281 void sltSelectionChanged(const QItemSelection & selected, const QItemSelection & deselected);
282 void sltSearchTextChanged(const QString &strText);
283 /** m_pModel signals when an tree item is renamed. we try to apply this rename to the file system.
284 * if the file system rename fails we restore the old name of the item. See the comment of
285 * sltRename() for more details. Note that when this slot is called item->path() has also changed. Thus strOldPath. */
286 void sltHandleItemRenameAttempt(UIFileSystemItem *pItem, const QString &strOldPath,
287 const QString &strOldName, const QString &strNewName);
288 void sltHandleNavigationWidgetPathChange(const QString& strPath);
289 void sltHandleNavigationWidgetHistoryListChanged();
290
291private:
292
293 void relist();
294 void prepareObjects();
295 /** @p itemIndex is assumed to be 'model' index not 'proxy model' index */
296 void deleteByIndex(const QModelIndex &itemIndex);
297 /** Returns the UIFileSystemItem for path / which is a direct (and single) child of m_pRootItem */
298 UIFileSystemItem *getStartDirectoryItem();
299 void deSelectUpDirectoryItem();
300 void setSelectionForAll(QItemSelectionModel::SelectionFlags flags);
301 void setSelection(const QModelIndex &indexInProxyModel);
302 /** The start directory requires a special attention since on file systems with drive letters
303 * drive letter are direct children of the start directory. On other systems start directory is '/' */
304 void populateStartDirectory(UIFileSystemItem *startItem);
305 /** Root index of the m_pModel */
306 QModelIndex currentRootIndex() const;
307 /* Searches the content of m_pSearchLineEdit within the current items' names and selects the item if found. */
308 void performSelectionSearch(const QString &strSearchText);
309 /** Clears the m_pSearchLineEdit and hides it. */
310 void disableSelectionSearch();
311 /** Checks if delete confirmation dialog is shown and users choice. Returns true
312 * if deletion can continue */
313 bool checkIfDeleteOK();
314 /** Marks/umarks the search line edit to signal that there are no matches for the current search.
315 * uses m_searchLineUnmarkColor and m_searchLineMarkColor. */
316 void markUnmarkSearchLineEdit(bool fMark);
317 QStringList currentDirectoryListing() const;
318 UIFileSystemModel *m_pModel;
319 UIGuestControlFileView *m_pView;
320 UIFileSystemProxyModel *m_pProxyModel;
321
322 QILineEdit *m_pSearchLineEdit;
323 QColor m_searchLineUnmarkColor;
324 QColor m_searchLineMarkColor;
325 QChar m_pathSeparator;
326 QHBoxLayout *m_pToolBarLayout;
327 QVector<QWidget*> m_sessionWidgets;
328 friend class UIFileSystemModel;
329};
330
331#endif /* !FEQT_INCLUDED_SRC_guestctrl_UIFileManagerTable_h */
Note: See TracBrowser for help on using the repository browser.

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