1 | /* $Id: UICustomFileSystemModel.h 100298 2023-06-27 13:35:12Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * VBox Qt GUI - UICustomFileSystemModel 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_UICustomFileSystemModel_h
|
---|
29 | #define FEQT_INCLUDED_SRC_globals_UICustomFileSystemModel_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 "COMEnums.h"
|
---|
42 |
|
---|
43 | enum UICustomFileSystemModelData
|
---|
44 | {
|
---|
45 | UICustomFileSystemModelData_Name = 0,
|
---|
46 | UICustomFileSystemModelData_Size,
|
---|
47 | UICustomFileSystemModelData_ChangeTime,
|
---|
48 | UICustomFileSystemModelData_Owner,
|
---|
49 | UICustomFileSystemModelData_Permissions,
|
---|
50 | UICustomFileSystemModelData_VISOPath,
|
---|
51 | UICustomFileSystemModelData_LocalPath,
|
---|
52 | UICustomFileSystemModelData_ISOFilePath, /* in case of import-iso this contains full path of the container iso file. */
|
---|
53 | UICustomFileSystemModelData_Max
|
---|
54 | };
|
---|
55 |
|
---|
56 | /** A UICustomFileSystemItem instance is a tree node representing a file object (file, directory, etc). The tree contructed
|
---|
57 | by these instances is the data source for the UICustomFileSystemModel. */
|
---|
58 | class SHARED_LIBRARY_STUFF UICustomFileSystemItem
|
---|
59 | {
|
---|
60 | public:
|
---|
61 |
|
---|
62 | /** @p strName contains file object name which is assumed to be unique among a parent object's children. */
|
---|
63 | UICustomFileSystemItem(const QString &strName, UICustomFileSystemItem *parentItem, KFsObjType type);
|
---|
64 | virtual ~UICustomFileSystemItem();
|
---|
65 |
|
---|
66 | void reset();
|
---|
67 | virtual UICustomFileSystemItem *child(int row) const;
|
---|
68 | /** Searches for the child by name and returns it if found. */
|
---|
69 | UICustomFileSystemItem *child(const QString &name) const;
|
---|
70 | int childCount() const;
|
---|
71 | QList<UICustomFileSystemItem*> children() const;
|
---|
72 | /** Removes the item from the list of children and !!DELETES!! the item. */
|
---|
73 | void removeChild(UICustomFileSystemItem *pItem);
|
---|
74 | void removeChildren();
|
---|
75 | int columnCount() const;
|
---|
76 | QVariant data(int column) const;
|
---|
77 | void setData(const QVariant &data, int index);
|
---|
78 | void setData(const QVariant &data, UICustomFileSystemModelData enmColumn);
|
---|
79 | int row() const;
|
---|
80 | UICustomFileSystemItem *parentItem();
|
---|
81 |
|
---|
82 | bool isDirectory() const;
|
---|
83 | bool isSymLink() const;
|
---|
84 | bool isFile() const;
|
---|
85 |
|
---|
86 | bool isOpened() const;
|
---|
87 | void setIsOpened(bool flag);
|
---|
88 |
|
---|
89 | /** Full absolute path of the item. With or without the trailing '/' */
|
---|
90 | QString path(bool fRemoveTrailingDelimiters = false) const;
|
---|
91 | void setPath(const QString &path);
|
---|
92 |
|
---|
93 | /** Returns true if this is directory and name is ".." */
|
---|
94 | bool isUpDirectory() const;
|
---|
95 | void clearChildren();
|
---|
96 |
|
---|
97 | KFsObjType type() const;
|
---|
98 |
|
---|
99 | const QString &targetPath() const;
|
---|
100 | void setTargetPath(const QString &path);
|
---|
101 |
|
---|
102 | bool isSymLinkToADirectory() const;
|
---|
103 | void setIsSymLinkToADirectory(bool flag);
|
---|
104 |
|
---|
105 | bool isSymLinkToAFile() const;
|
---|
106 |
|
---|
107 | const QString &owner() const;
|
---|
108 | void setOwner(const QString &owner);
|
---|
109 |
|
---|
110 | QString name() const;
|
---|
111 |
|
---|
112 | void setIsDriveItem(bool flag);
|
---|
113 | bool isDriveItem() const;
|
---|
114 |
|
---|
115 | void setIsHidden(bool flag);
|
---|
116 | bool isHidden() const;
|
---|
117 |
|
---|
118 | private:
|
---|
119 | void appendChild(UICustomFileSystemItem *child);
|
---|
120 |
|
---|
121 | QList<UICustomFileSystemItem*> m_childItems;
|
---|
122 | /** Used to find children by name */
|
---|
123 | QMap<QString, UICustomFileSystemItem*> m_childMap;
|
---|
124 | QMap<UICustomFileSystemModelData, QVariant> m_itemData;
|
---|
125 | UICustomFileSystemItem *m_parentItem;
|
---|
126 | bool m_bIsOpened;
|
---|
127 | /** If this is a symlink m_targetPath keeps the absolute path of the target */
|
---|
128 | QString m_strTargetPath;
|
---|
129 | /** True if this is a symlink and the target is a directory */
|
---|
130 | bool m_fIsTargetADirectory;
|
---|
131 | KFsObjType m_type;
|
---|
132 | /** True if only this item represents a DOS style drive letter item */
|
---|
133 | bool m_fIsDriveItem;
|
---|
134 | /** True if the file object is hidden in the file system. */
|
---|
135 | bool m_fIsHidden;
|
---|
136 | };
|
---|
137 |
|
---|
138 | /** A QSortFilterProxyModel extension used in file tables. Modifies some
|
---|
139 | * of the base class behavior like lessThan(..) */
|
---|
140 | class SHARED_LIBRARY_STUFF UICustomFileSystemProxyModel : public QSortFilterProxyModel
|
---|
141 | {
|
---|
142 |
|
---|
143 | Q_OBJECT;
|
---|
144 |
|
---|
145 | public:
|
---|
146 |
|
---|
147 | UICustomFileSystemProxyModel(QObject *parent = 0);
|
---|
148 |
|
---|
149 | void setListDirectoriesOnTop(bool fListDirectoriesOnTop);
|
---|
150 | bool listDirectoriesOnTop() const;
|
---|
151 |
|
---|
152 | void setShowHiddenObjects(bool fShowHiddenObjects);
|
---|
153 | bool showHiddenObjects() const;
|
---|
154 |
|
---|
155 | protected:
|
---|
156 |
|
---|
157 | virtual bool lessThan(const QModelIndex &left, const QModelIndex &right) const RT_OVERRIDE;
|
---|
158 | /** Currently filters out hidden objects if options is set to "not showing them". */
|
---|
159 | virtual bool filterAcceptsRow(int iSourceRow, const QModelIndex &sourceParent) const RT_OVERRIDE;
|
---|
160 |
|
---|
161 | private:
|
---|
162 |
|
---|
163 | bool m_fListDirectoriesOnTop;
|
---|
164 | bool m_fShowHiddenObjects;
|
---|
165 | };
|
---|
166 |
|
---|
167 | /** UICustomFileSystemModel serves as the model for a file structure.
|
---|
168 | * it supports a tree level hierarchy which can be displayed with
|
---|
169 | * QTableView and/or QTreeView.*/
|
---|
170 | class SHARED_LIBRARY_STUFF UICustomFileSystemModel : public QAbstractItemModel
|
---|
171 | {
|
---|
172 |
|
---|
173 | Q_OBJECT;
|
---|
174 |
|
---|
175 | signals:
|
---|
176 |
|
---|
177 | void sigItemRenamed(UICustomFileSystemItem *pItem, QString strOldName, QString strNewName);
|
---|
178 |
|
---|
179 | public:
|
---|
180 |
|
---|
181 | explicit UICustomFileSystemModel(QObject *parent = 0);
|
---|
182 | ~UICustomFileSystemModel();
|
---|
183 |
|
---|
184 | QVariant data(const QModelIndex &index, int role) const RT_OVERRIDE;
|
---|
185 | bool setData(const QModelIndex &index, const QVariant &value, int role);
|
---|
186 |
|
---|
187 | Qt::ItemFlags flags(const QModelIndex &index) const RT_OVERRIDE;
|
---|
188 | QVariant headerData(int section, Qt::Orientation orientation,
|
---|
189 | int role = Qt::DisplayRole) const RT_OVERRIDE;
|
---|
190 | QModelIndex index(int row, int column,
|
---|
191 | const QModelIndex &parent = QModelIndex()) const RT_OVERRIDE;
|
---|
192 | QModelIndex index(const UICustomFileSystemItem* item);
|
---|
193 | QModelIndex parent(const QModelIndex &index) const RT_OVERRIDE;
|
---|
194 | int rowCount(const QModelIndex &parent = QModelIndex()) const RT_OVERRIDE;
|
---|
195 | int columnCount(const QModelIndex &parent = QModelIndex()) const RT_OVERRIDE;
|
---|
196 | void signalUpdate();
|
---|
197 | QModelIndex rootIndex() const;
|
---|
198 | void beginReset();
|
---|
199 | void endReset();
|
---|
200 | void reset();
|
---|
201 |
|
---|
202 | void setShowHumanReadableSizes(bool fShowHumanReadableSizes);
|
---|
203 | bool showHumanReadableSizes() const;
|
---|
204 | void deleteItem(UICustomFileSystemItem* pItem);
|
---|
205 | UICustomFileSystemItem* rootItem();
|
---|
206 | const UICustomFileSystemItem* rootItem() const;
|
---|
207 |
|
---|
208 | static const char* strUpDirectoryString;
|
---|
209 |
|
---|
210 | private:
|
---|
211 | void initializeTree();
|
---|
212 | UICustomFileSystemItem *m_pRootItem;
|
---|
213 | void setupModelData(const QStringList &lines, UICustomFileSystemItem *parent);
|
---|
214 | bool m_fShowHumanReadableSizes;
|
---|
215 | };
|
---|
216 |
|
---|
217 |
|
---|
218 | #endif /* !FEQT_INCLUDED_SRC_globals_UICustomFileSystemModel_h */
|
---|