VirtualBox

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

Last change on this file since 104586 was 104228, checked in by vboxsync, 8 months ago

FE/Qt. bugref:10622. Using new UITranslationEventListener in file manager table class(es).

  • 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 104228 2024-04-08 12:40:22Z 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 "UIGuestControlDefs.h"
48
49/* Forward declarations: */
50class QAction;
51class QFileInfo;
52class QILabel;
53class QILineEdit;
54class QGridLayout;
55class QSortFilterProxyModel;
56class QTextEdit;
57class QHBoxLayout;
58class QVBoxLayout;
59class UIActionPool;
60class UIFileSystemItem;
61class UIFileSystemModel;
62class UIFileSystemProxyModel;
63class UIFileTableNavigationWidget;
64class UIGuestControlFileView;
65class QIToolBar;
66
67/** A simple struck to store some statictics for a directory. Mainly used by UIDirectoryDiskUsageComputer instances. */
68class UIDirectoryStatistics
69{
70public:
71 UIDirectoryStatistics();
72 ULONG64 m_totalSize;
73 unsigned m_uFileCount;
74 unsigned m_uDirectoryCount;
75 unsigned m_uSymlinkCount;
76};
77
78Q_DECLARE_METATYPE(UIDirectoryStatistics);
79
80
81/** Examines the paths in @p strStartPath and collects some staticstics from them recursively (in case directories)
82 * Runs on a worker thread to avoid GUI freezes. UIGuestFileTable and UIHostFileTable uses specialized children
83 * of this class since the calls made on file objects are different. */
84class UIDirectoryDiskUsageComputer : public QThread
85{
86 Q_OBJECT;
87
88signals:
89
90 void sigResultUpdated(UIDirectoryStatistics);
91
92public:
93
94 UIDirectoryDiskUsageComputer(QObject *parent, QStringList strStartPath);
95 /** Sets the m_fOkToContinue to false. This results an early termination
96 * of the directoryStatisticsRecursive member function. */
97 void stopRecursion();
98
99protected:
100
101 /** Read the directory with the path @p path recursively and collect #of objects and total size */
102 virtual void directoryStatisticsRecursive(const QString &path, UIDirectoryStatistics &statistics) = 0;
103 virtual void run() RT_OVERRIDE;
104 /** Returns the m_fOkToContinue flag */
105 bool isOkToContinue() const;
106
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 UIFileSystemModel by scanning the file system
139 * differently. The file structure kept in this class as a tree. */
140class UIFileManagerTable : public 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 void sigAltDoubleClick();
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 virtual bool isWindowsFileSystem() const = 0;
169
170public slots:
171
172 void sltReceiveDirectoryStatistics(UIDirectoryStatistics statictics);
173 void sltCreateNewDirectory();
174 /* index is passed by the item view and represents the double clicked object's 'proxy' model index */
175 void sltItemDoubleClicked(const QModelIndex &index);
176 void sltItemClicked(const QModelIndex &index);
177 void sltAltDoubleClick();
178 void sltGoUp();
179 void sltGoHome();
180 void sltGoForward();
181 void sltGoBackward();
182 void sltRefresh();
183 void sltDelete();
184 /** Calls the edit on the data item over m_pView. This causes setData(..) call on the model. After setting
185 * user entered text as the name of the item m_pModel signals. This signal is handled by sltHandleItemRenameAttempt which
186 * tries to rename the corresponding file object by calling renameItem(...). If this rename fails the old name of the
187 * model item is restored and view is refreshed by sltHandleItemRenameAttempt. */
188 void sltRename();
189 void sltCopy();
190 void sltCut();
191 void sltPaste();
192 void sltShowProperties();
193 void sltSelectAll();
194 void sltInvertSelection();
195
196protected:
197
198 /** This enum is used when performing a gueest-to-guest or host-to-host
199 * file operations. Paths of source file objects are kept in a single buffer
200 * and a flag to determine if it is a cut or copy operation is needed */
201 enum FileOperationType
202 {
203 FileOperationType_Copy,
204 FileOperationType_Cut,
205 FileOperationType_None,
206 FileOperationType_Max
207 };
208
209 void updateCurrentLocationEdit(const QString& strLocation);
210 /* @p index is for model not for 'proxy' model */
211 void changeLocation(const QModelIndex &index);
212 void initializeFileTree();
213 void checkDotDot(QMap<QString,UIFileSystemItem*> &map, UIFileSystemItem *parent, bool isStartDir);
214
215 virtual bool readDirectory(const QString& strPath, UIFileSystemItem *parent, bool isStartDir = false) = 0;
216 virtual void deleteByItem(UIFileSystemItem *item) = 0;
217 virtual void goToHomeDirectory() = 0;
218 virtual bool renameItem(UIFileSystemItem *item, const QString &strOldPath) = 0;
219 virtual bool createDirectory(const QString &path, const QString &directoryName) = 0;
220 virtual QString fsObjectPropertyString() = 0;
221 virtual void showProperties() = 0;
222 /** For non-windows system does nothing and for windows systems populates m_driveLetterList with
223 * drive letters */
224 virtual void determineDriveLetters() = 0;
225 virtual void determinePathSeparator() = 0;
226 virtual void prepareToolbar() = 0;
227 virtual void createFileViewContextMenu(const QWidget *pWidget, const QPoint &point) = 0;
228 virtual void toggleForwardBackwardActions() = 0;
229 virtual bool event(QEvent *pEvent) RT_OVERRIDE;
230
231 /** @name Copy/Cut guest-to-guest (host-to-host) stuff.
232 * @{ */
233 /** Disable/enable paste action depending on the m_eFileOperationType. */
234 virtual void setPasteActionEnabled(bool fEnabled) = 0;
235 virtual void pasteCutCopiedObjects() = 0;
236 /** stores the type of the pending guest-to-guest (host-to-host) file operation. */
237 FileOperationType m_eFileOperationType;
238 /** @} */
239
240 QString fileTypeString(KFsObjType type);
241 /* @p item index is item location in model not in 'proxy' model */
242 void goIntoDirectory(const QModelIndex &itemIndex);
243 /** Follows the path trail, opens directories as it descends */
244 void goIntoDirectory(const QStringList &pathTrail);
245 /** Goes into directory pointed by the @p item */
246 void goIntoDirectory(UIFileSystemItem *item);
247 UIFileSystemItem* indexData(const QModelIndex &index) const;
248 bool eventFilter(QObject *pObject, QEvent *pEvent) RT_OVERRIDE;
249 CGuestFsObjInfo guestFsObjectInfo(const QString& path, CGuestSession &comGuestSession) const;
250 void setSelectionDependentActionsEnabled(bool fIsEnabled);
251 UIFileSystemItem* rootItem();
252 void setPathSeparator(const QChar &separator);
253 QHBoxLayout* toolBarLayout();
254 void setSessionWidgetsEnabled(bool fEnabled);
255 void setModelFileSystem(bool fIsWindowsFileSystem);
256
257 QILabel *m_pLocationLabel;
258 UIPropertiesDialog *m_pPropertiesDialog;
259 UIActionPool *m_pActionPool;
260 QIToolBar *m_pToolBar;
261 QGridLayout *m_pMainLayout;
262 /** Stores the drive letters the file system has (for windows system). For non-windows
263 * systems this is empty and for windows system it should at least contain C:/ */
264 QStringList m_driveLetterList;
265 /** The set of actions which need some selection to work on. Like cut, copy etc. */
266 QSet<QAction*> m_selectionDependentActions;
267 /** The absolute path list of the file objects which user has chosen to cut/copy. this
268 * list will be cleaned after a paste operation or overwritten by a subsequent cut/copy.
269 * Currently only used by the guest side. */
270 QStringList m_copyCutBuffer;
271 /** This name is appended to the log messages which are shown in the log panel. */
272 QString m_strTableName;
273 /** Contains m_pBreadCrumbsWidget and m_pLocationComboBox. */
274 UIFileTableNavigationWidget *m_pNavigationWidget;
275
276protected slots:
277
278 virtual void sltRetranslateUI();
279
280private slots:
281
282 void sltCreateFileViewContextMenu(const QPoint &point);
283 void sltSelectionChanged(const QItemSelection & selected, const QItemSelection & deselected);
284 void sltSearchTextChanged(const QString &strText);
285 /** m_pModel signals when an tree item is renamed. we try to apply this rename to the file system.
286 * if the file system rename fails we restore the old name of the item. See the comment of
287 * sltRename() for more details. Note that when this slot is called item->path() has also changed. Thus strOldPath. */
288 void sltHandleItemRenameAttempt(UIFileSystemItem *pItem, const QString &strOldPath,
289 const QString &strOldName, const QString &strNewName);
290 void sltHandleNavigationWidgetPathChange(const QString& strPath);
291 void sltHandleNavigationWidgetHistoryListChanged();
292
293private:
294
295 void relist();
296 void prepareObjects();
297 /** @p itemIndex is assumed to be 'model' index not 'proxy model' index */
298 void deleteByIndex(const QModelIndex &itemIndex);
299 /** Returns the UIFileSystemItem for path / which is a direct (and single) child of m_pRootItem */
300 UIFileSystemItem *getStartDirectoryItem();
301 void deSelectUpDirectoryItem();
302 void setSelectionForAll(QItemSelectionModel::SelectionFlags flags);
303 void setSelection(const QModelIndex &indexInProxyModel);
304 /** The start directory requires a special attention since on file systems with drive letters
305 * drive letter are direct children of the start directory. On other systems start directory is '/' */
306 void populateStartDirectory(UIFileSystemItem *startItem);
307 /** Root index of the m_pModel */
308 QModelIndex currentRootIndex() const;
309 /* Searches the content of m_pSearchLineEdit within the current items' names and selects the item if found. */
310 void performSelectionSearch(const QString &strSearchText);
311 /** Clears the m_pSearchLineEdit and hides it. */
312 void disableSelectionSearch();
313 /** Checks if delete confirmation dialog is shown and users choice. Returns true
314 * if deletion can continue */
315 bool checkIfDeleteOK();
316 /** Marks/umarks the search line edit to signal that there are no matches for the current search.
317 * uses m_searchLineUnmarkColor and m_searchLineMarkColor. */
318 void markUnmarkSearchLineEdit(bool fMark);
319 QStringList currentDirectoryListing() const;
320 UIFileSystemModel *m_pModel;
321 UIGuestControlFileView *m_pView;
322 UIFileSystemProxyModel *m_pProxyModel;
323
324 QILineEdit *m_pSearchLineEdit;
325 QColor m_searchLineUnmarkColor;
326 QColor m_searchLineMarkColor;
327 QChar m_pathSeparator;
328 QHBoxLayout *m_pToolBarLayout;
329 QVector<QWidget*> m_sessionWidgets;
330 friend class UIFileSystemModel;
331};
332
333#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