VirtualBox

source: vbox/trunk/src/VBox/Frontends/VirtualBox/src/globals/UIFileSystemModel.h@ 103977

Last change on this file since 103977 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: 8.0 KB
Line 
1/* $Id: UIFileSystemModel.h 103977 2024-03-21 02:04:52Z vboxsync $ */
2/** @file
3 * VBox Qt GUI - UIFileSystemModel 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_globals_UIFileSystemModel_h
29#define FEQT_INCLUDED_SRC_globals_UIFileSystemModel_h
30#ifndef RT_WITHOUT_PRAGMA_ONCE
31# pragma once
32#endif
33
34/* Qt includes: */
35#include <QAbstractItemModel>
36#include <QSortFilterProxyModel>
37
38#include "UILibraryDefs.h"
39
40/* COM includes: */
41#include "KFsObjType.h"
42
43class QMimeData;
44class UIFileSystemModel;
45
46enum UIFileSystemModelData
47{
48 UIFileSystemModelData_Name = 0,
49 UIFileSystemModelData_Size,
50 UIFileSystemModelData_ChangeTime,
51 UIFileSystemModelData_Owner,
52 UIFileSystemModelData_Permissions,
53 UIFileSystemModelData_LocalPath,
54 UIFileSystemModelData_ISOFilePath, /* in case of import-iso this contains full path of the container iso file. */
55 UIFileSystemModelData_RemovedFromVISO,
56 UIFileSystemModelData_DescendantRemovedFromVISO,
57 UIFileSystemModelData_Max
58};
59
60/** A UIFileSystemItem instance is a tree node representing a file object (file, directory, etc). The tree contructed
61 by these instances is the data source for the UIFileSystemModel. */
62class SHARED_LIBRARY_STUFF UIFileSystemItem
63{
64
65public:
66
67 /** @p strName contains file object name which is assumed to be unique among a parent object's children. */
68 UIFileSystemItem(const QString &strFileObjectName, UIFileSystemItem *parentItem, KFsObjType type);
69 virtual ~UIFileSystemItem();
70
71 void reset();
72 virtual UIFileSystemItem *child(int row) const;
73 /** Searches for the child by file object name and returns it if found. */
74 UIFileSystemItem *child(const QString &strFileObjectName) const;
75 int childCount() const;
76 QList<UIFileSystemItem*> children() const;
77 /** Removes the item from the list of children and !!DELETES!! the item. */
78 void removeChild(UIFileSystemItem *pItem);
79 void removeChildren();
80 int columnCount() const;
81 QVariant data(int column) const;
82 void setData(const QVariant &data, int index);
83 void setData(const QVariant &data, UIFileSystemModelData enmColumn);
84 int row() const;
85 UIFileSystemItem *parentItem();
86 UIFileSystemItem *parentItem() const;
87
88 bool isDirectory() const;
89 bool isSymLink() const;
90 bool isFile() const;
91
92 bool isOpened() const;
93 void setIsOpened(bool flag);
94
95 QString path() const;
96
97 /** Returns true if this is directory and file object name is ".." */
98 bool isUpDirectory() const;
99 void clearChildren();
100
101 KFsObjType type() const;
102
103 const QString &targetPath() const;
104 void setTargetPath(const QString &path);
105
106 bool isSymLinkToADirectory() const;
107 void setIsSymLinkToADirectory(bool flag);
108
109 bool isSymLinkToAFile() const;
110
111 const QString &owner() const;
112 void setOwner(const QString &owner);
113
114 QString fileObjectName() const;
115
116 void setIsDriveItem(bool flag);
117 bool isDriveItem() const;
118
119 void setIsHidden(bool flag);
120 bool isHidden() const;
121
122 void setRemovedFromViso(bool fRemoved);
123 bool isRemovedFromViso() const;
124
125 void setToolTip(const QString &strToolTip);
126 const QString &toolTip() const;
127
128private:
129
130 void appendChild(UIFileSystemItem *child);
131 void setParentModel(UIFileSystemModel *pModel);
132 UIFileSystemModel *parentModel();
133
134 QList<UIFileSystemItem*> m_childItems;
135 QMap<UIFileSystemModelData, QVariant> m_itemData;
136 UIFileSystemItem *m_parentItem;
137 bool m_bIsOpened;
138 /** If this is a symlink m_targetPath keeps the absolute path of the target */
139 QString m_strTargetPath;
140 /** True if this is a symlink and the target is a directory */
141 bool m_fIsTargetADirectory;
142 KFsObjType m_type;
143 /** True if only this item represents a DOS style drive letter item */
144 bool m_fIsDriveItem;
145 /** True if the file object is hidden in the file system. */
146 bool m_fIsHidden;
147 QString m_strToolTip;
148 /** Pointer to the parent model. */
149 UIFileSystemModel *m_pParentModel;
150 friend UIFileSystemModel;
151};
152
153/** A QSortFilterProxyModel extension used in file tables. Modifies some
154 * of the base class behavior like lessThan(..) */
155class SHARED_LIBRARY_STUFF UIFileSystemProxyModel : public QSortFilterProxyModel
156{
157
158 Q_OBJECT;
159
160public:
161
162 UIFileSystemProxyModel(QObject *parent = 0);
163
164 void setListDirectoriesOnTop(bool fListDirectoriesOnTop);
165 bool listDirectoriesOnTop() const;
166
167 void setShowHiddenObjects(bool fShowHiddenObjects);
168 bool showHiddenObjects() const;
169
170protected:
171
172 virtual bool lessThan(const QModelIndex &left, const QModelIndex &right) const RT_OVERRIDE;
173 /** Currently filters out hidden objects if options is set to "not showing them". */
174 virtual bool filterAcceptsRow(int iSourceRow, const QModelIndex &sourceParent) const RT_OVERRIDE;
175
176private:
177
178 bool m_fListDirectoriesOnTop;
179 bool m_fShowHiddenObjects;
180};
181
182/** UIFileSystemModel serves as the model for a file structure.
183 * it supports a tree level hierarchy which can be displayed with
184 * QTableView and/or QTreeView.*/
185class SHARED_LIBRARY_STUFF UIFileSystemModel : public QAbstractItemModel
186{
187
188 Q_OBJECT;
189
190signals:
191
192 void sigItemRenamed(UIFileSystemItem *pItem, const QString &strOldPath,
193 const QString &strOldName, const QString &strNewName);
194
195public:
196
197 explicit UIFileSystemModel(QObject *parent = 0);
198 ~UIFileSystemModel();
199
200 QVariant data(const QModelIndex &index, int role) const RT_OVERRIDE;
201 bool setData(const QModelIndex &index, const QVariant &value, int role) RT_OVERRIDE;
202
203 Qt::ItemFlags flags(const QModelIndex &index) const RT_OVERRIDE;
204 QVariant headerData(int section, Qt::Orientation orientation,
205 int role = Qt::DisplayRole) const RT_OVERRIDE;
206 QModelIndex index(int row, int column,
207 const QModelIndex &parent = QModelIndex()) const RT_OVERRIDE;
208 QModelIndex index(const UIFileSystemItem* item);
209 QModelIndex parent(const QModelIndex &index) const RT_OVERRIDE;
210 int rowCount(const QModelIndex &parent = QModelIndex()) const RT_OVERRIDE;
211 int columnCount(const QModelIndex &parent = QModelIndex()) const RT_OVERRIDE;
212 void signalUpdate();
213 QModelIndex rootIndex() const;
214 void beginReset();
215 void endReset();
216 void reset();
217
218 void setShowHumanReadableSizes(bool fShowHumanReadableSizes);
219 bool showHumanReadableSizes() const;
220 void deleteItem(UIFileSystemItem* pItem);
221 UIFileSystemItem* rootItem();
222 const UIFileSystemItem* rootItem() const;
223
224 void setIsWindowsFileSystem(bool fIsWindowsFileSystem);
225 bool isWindowsFileSystem() const;
226
227 virtual QStringList mimeTypes() const RT_OVERRIDE;
228 /** Prepares the mime data as a list of text consisting of dragged objects full file path. */
229 QMimeData *mimeData(const QModelIndexList &indexes) const RT_OVERRIDE;
230
231 static const char* strUpDirectoryString;
232
233private:
234
235 UIFileSystemItem *m_pRootItem;
236 void setupModelData(const QStringList &lines, UIFileSystemItem *parent);
237 bool m_fShowHumanReadableSizes;
238 bool m_fIsWindowFileSystemModel;
239};
240
241
242#endif /* !FEQT_INCLUDED_SRC_globals_UIFileSystemModel_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