VirtualBox

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

Last change on this file since 102493 was 102485, checked in by vboxsync, 9 months ago

FE/Qt: bugref:10561. Some refactoring.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 13.3 KB
Line 
1/* $Id: UIFileManagerTable.h 102485 2023-12-05 17:37:02Z 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 "COMEnums.h"
42#include "CGuestSession.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
151public:
152
153 UIFileManagerTable(UIActionPool *pActionPool, QWidget *pParent = 0);
154 virtual ~UIFileManagerTable();
155 /** Deletes all the tree nodes */
156 void reset();
157 /** Returns the path of the rootIndex */
158 QString currentDirectoryPath() const;
159 /** Returns the paths of the selected items (if any) as a list */
160 QStringList selectedItemPathList();
161 virtual void refresh();
162 static const unsigned m_iKiloByte;
163 static QString humanReadableSize(ULONG64 size);
164 /** Peroforms whatever is necessary after a UIFileManagerOptions change. */
165 void optionsUpdated();
166 bool hasSelection() const;
167 void setDragDropMode(QAbstractItemView::DragDropMode behavior);
168
169public slots:
170
171 void sltReceiveDirectoryStatistics(UIDirectoryStatistics statictics);
172 void sltCreateNewDirectory();
173 /* index is passed by the item view and represents the double clicked object's 'proxy' model index */
174 void sltItemDoubleClicked(const QModelIndex &index);
175 void sltItemClicked(const QModelIndex &index);
176 void sltGoUp();
177 void sltGoHome();
178 void sltGoForward();
179 void sltGoBackward();
180 void sltRefresh();
181 void sltDelete();
182 /** Calls the edit on the data item over m_pView. This causes setData(..) call on the model. After setting
183 * user entered text as the name of the item m_pModel signals. This signal is handled by sltHandleItemRenameAttempt which
184 * tries to rename the corresponding file object by calling renameItem(...). If this rename fails the old name of the
185 * model item is restored and view is refreshed by sltHandleItemRenameAttempt. */
186 void sltRename();
187 void sltCopy();
188 void sltCut();
189 void sltPaste();
190 void sltShowProperties();
191 void sltSelectAll();
192 void sltInvertSelection();
193
194protected:
195
196 /** This enum is used when performing a gueest-to-guest or host-to-host
197 * file operations. Paths of source file objects are kept in a single buffer
198 * and a flag to determine if it is a cut or copy operation is needed */
199 enum FileOperationType
200 {
201 FileOperationType_Copy,
202 FileOperationType_Cut,
203 FileOperationType_None,
204 FileOperationType_Max
205 };
206
207 void retranslateUi();
208 void updateCurrentLocationEdit(const QString& strLocation);
209 /* @p index is for model not for 'proxy' model */
210 void changeLocation(const QModelIndex &index);
211 void initializeFileTree();
212 void checkDotDot(QMap<QString,UIFileSystemItem*> &map, UIFileSystemItem *parent, bool isStartDir);
213
214 virtual bool readDirectory(const QString& strPath, UIFileSystemItem *parent, bool isStartDir = false) = 0;
215 virtual void deleteByItem(UIFileSystemItem *item) = 0;
216 virtual void goToHomeDirectory() = 0;
217 virtual bool renameItem(UIFileSystemItem *item, const QString &strOldPath) = 0;
218 virtual bool createDirectory(const QString &path, const QString &directoryName) = 0;
219 virtual QString fsObjectPropertyString() = 0;
220 virtual void showProperties() = 0;
221 /** For non-windows system does nothing and for windows systems populates m_driveLetterList with
222 * drive letters */
223 virtual void determineDriveLetters() = 0;
224 virtual void determinePathSeparator() = 0;
225 virtual void prepareToolbar() = 0;
226 virtual void createFileViewContextMenu(const QWidget *pWidget, const QPoint &point) = 0;
227 virtual void toggleForwardBackwardActions() = 0;
228 virtual bool event(QEvent *pEvent) RT_OVERRIDE;
229 virtual bool isWindowsFileSystem() const = 0;
230 /** @name Copy/Cut guest-to-guest (host-to-host) stuff.
231 * @{ */
232 /** Disable/enable paste action depending on the m_eFileOperationType. */
233 virtual void setPasteActionEnabled(bool fEnabled) = 0;
234 virtual void pasteCutCopiedObjects() = 0;
235 /** stores the type of the pending guest-to-guest (host-to-host) file operation. */
236 FileOperationType m_eFileOperationType;
237 /** @} */
238
239 QString fileTypeString(KFsObjType type);
240 /* @p item index is item location in model not in 'proxy' model */
241 void goIntoDirectory(const QModelIndex &itemIndex);
242 /** Follows the path trail, opens directories as it descends */
243 void goIntoDirectory(const QStringList &pathTrail);
244 /** Goes into directory pointed by the @p item */
245 void goIntoDirectory(UIFileSystemItem *item);
246 UIFileSystemItem* indexData(const QModelIndex &index) const;
247 bool eventFilter(QObject *pObject, QEvent *pEvent) RT_OVERRIDE;
248 CGuestFsObjInfo guestFsObjectInfo(const QString& path, CGuestSession &comGuestSession) const;
249 void setSelectionDependentActionsEnabled(bool fIsEnabled);
250 UIFileSystemItem* rootItem();
251 void setPathSeparator(const QChar &separator);
252 QHBoxLayout* toolBarLayout();
253 void setSessionWidgetsEnabled(bool fEnabled);
254 void setModelFileSystem(bool fIsWindowsFileSystem);
255
256 QILabel *m_pLocationLabel;
257 UIPropertiesDialog *m_pPropertiesDialog;
258 UIActionPool *m_pActionPool;
259 QIToolBar *m_pToolBar;
260 QGridLayout *m_pMainLayout;
261 /** Stores the drive letters the file system has (for windows system). For non-windows
262 * systems this is empty and for windows system it should at least contain C:/ */
263 QStringList m_driveLetterList;
264 /** The set of actions which need some selection to work on. Like cut, copy etc. */
265 QSet<QAction*> m_selectionDependentActions;
266 /** The absolute path list of the file objects which user has chosen to cut/copy. this
267 * list will be cleaned after a paste operation or overwritten by a subsequent cut/copy.
268 * Currently only used by the guest side. */
269 QStringList m_copyCutBuffer;
270 /** This name is appended to the log messages which are shown in the log panel. */
271 QString m_strTableName;
272 /** Contains m_pBreadCrumbsWidget and m_pLocationComboBox. */
273 UIFileTableNavigationWidget *m_pNavigationWidget;
274
275private slots:
276
277 void sltCreateFileViewContextMenu(const QPoint &point);
278 void sltSelectionChanged(const QItemSelection & selected, const QItemSelection & deselected);
279 void sltSearchTextChanged(const QString &strText);
280 /** m_pModel signals when an tree item is renamed. we try to apply this rename to the file system.
281 * if the file system rename fails we restore the old name of the item. See the comment of
282 * sltRename() for more details. Note that when this slot is called item->path() has also changed. Thus strOldPath. */
283 void sltHandleItemRenameAttempt(UIFileSystemItem *pItem, const QString &strOldPath,
284 const QString &strOldName, const QString &strNewName);
285 void sltHandleNavigationWidgetPathChange(const QString& strPath);
286 void sltHandleNavigationWidgetHistoryListChanged();
287
288private:
289
290 void relist();
291 void prepareObjects();
292 /** @p itemIndex is assumed to be 'model' index not 'proxy model' index */
293 void deleteByIndex(const QModelIndex &itemIndex);
294 /** Returns the UIFileSystemItem for path / which is a direct (and single) child of m_pRootItem */
295 UIFileSystemItem *getStartDirectoryItem();
296 void deSelectUpDirectoryItem();
297 void setSelectionForAll(QItemSelectionModel::SelectionFlags flags);
298 void setSelection(const QModelIndex &indexInProxyModel);
299 /** The start directory requires a special attention since on file systems with drive letters
300 * drive letter are direct children of the start directory. On other systems start directory is '/' */
301 void populateStartDirectory(UIFileSystemItem *startItem);
302 /** Root index of the m_pModel */
303 QModelIndex currentRootIndex() const;
304 /* Searches the content of m_pSearchLineEdit within the current items' names and selects the item if found. */
305 void performSelectionSearch(const QString &strSearchText);
306 /** Clears the m_pSearchLineEdit and hides it. */
307 void disableSelectionSearch();
308 /** Checks if delete confirmation dialog is shown and users choice. Returns true
309 * if deletion can continue */
310 bool checkIfDeleteOK();
311 /** Marks/umarks the search line edit to signal that there are no matches for the current search.
312 * uses m_searchLineUnmarkColor and m_searchLineMarkColor. */
313 void markUnmarkSearchLineEdit(bool fMark);
314 QStringList currentDirectoryListing() const;
315 UIFileSystemModel *m_pModel;
316 UIGuestControlFileView *m_pView;
317 UIFileSystemProxyModel *m_pProxyModel;
318
319 QILineEdit *m_pSearchLineEdit;
320 QColor m_searchLineUnmarkColor;
321 QColor m_searchLineMarkColor;
322 QChar m_pathSeparator;
323 QHBoxLayout *m_pToolBarLayout;
324 QVector<QWidget*> m_sessionWidgets;
325 friend class UIFileSystemModel;
326};
327
328#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