VirtualBox

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

Last change on this file since 100347 was 100302, checked in by vboxsync, 19 months ago

FE/Qt: bugref:6699. Adding forward and backward navigation actions.

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