1 | /* $Id: UICustomFileSystemModel.h 77868 2019-03-25 09:27:48Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * VBox Qt GUI - UICustomFileSystemModel class declaration.
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2016-2019 Oracle Corporation
|
---|
8 | *
|
---|
9 | * This file is part of VirtualBox Open Source Edition (OSE), as
|
---|
10 | * available from http://www.virtualbox.org. This file is free software;
|
---|
11 | * you can redistribute it and/or modify it under the terms of the GNU
|
---|
12 | * General Public License (GPL) as published by the Free Software
|
---|
13 | * Foundation, in version 2 as it comes in the "COPYING" file of the
|
---|
14 | * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
|
---|
15 | * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
|
---|
16 | */
|
---|
17 |
|
---|
18 | #ifndef FEQT_INCLUDED_SRC_globals_UICustomFileSystemModel_h
|
---|
19 | #define FEQT_INCLUDED_SRC_globals_UICustomFileSystemModel_h
|
---|
20 | #ifndef RT_WITHOUT_PRAGMA_ONCE
|
---|
21 | # pragma once
|
---|
22 | #endif
|
---|
23 |
|
---|
24 | /* Qt includes: */
|
---|
25 | #include <QAbstractItemModel>
|
---|
26 | #include <QSortFilterProxyModel>
|
---|
27 |
|
---|
28 | #include "UILibraryDefs.h"
|
---|
29 |
|
---|
30 | /* COM includes: */
|
---|
31 | #include "COMEnums.h"
|
---|
32 |
|
---|
33 | enum UICustomFileSystemModelColumn
|
---|
34 | {
|
---|
35 | UICustomFileSystemModelColumn_Name = 0,
|
---|
36 | UICustomFileSystemModelColumn_Size,
|
---|
37 | UICustomFileSystemModelColumn_ChangeTime,
|
---|
38 | UICustomFileSystemModelColumn_Owner,
|
---|
39 | UICustomFileSystemModelColumn_Permissions,
|
---|
40 | UICustomFileSystemModelColumn_Path,
|
---|
41 | UICustomFileSystemModelColumn_LocalPath,
|
---|
42 | UICustomFileSystemModelColumn_Max
|
---|
43 | };
|
---|
44 |
|
---|
45 | /** A UICustomFileSystemItem instance is a tree node representing a file object (file, directory, etc). The tree contructed
|
---|
46 | by these instances is the data source for the UICustomFileSystemModel. */
|
---|
47 | class SHARED_LIBRARY_STUFF UICustomFileSystemItem
|
---|
48 | {
|
---|
49 | public:
|
---|
50 |
|
---|
51 | /** @p strName contains file object name which is assumed to be unique among a parent object's children. */
|
---|
52 | UICustomFileSystemItem(const QString &strName, UICustomFileSystemItem *parentItem, KFsObjType type);
|
---|
53 | virtual ~UICustomFileSystemItem();
|
---|
54 |
|
---|
55 | void reset();
|
---|
56 | virtual UICustomFileSystemItem *child(int row) const;
|
---|
57 | /** Searches for the child by path and returns it if found. */
|
---|
58 | UICustomFileSystemItem *child(const QString &path) const;
|
---|
59 | int childCount() const;
|
---|
60 | QList<UICustomFileSystemItem*> children() const;
|
---|
61 | /** Removes the item from the list of children and !!DELETES!! the item. */
|
---|
62 | void removeChild(UICustomFileSystemItem *pItem);
|
---|
63 | void removeChildren();
|
---|
64 | int columnCount() const;
|
---|
65 | QVariant data(int column) const;
|
---|
66 | void setData(const QVariant &data, int index);
|
---|
67 | void setData(const QVariant &data, UICustomFileSystemModelColumn enmColumn);
|
---|
68 | int row() const;
|
---|
69 | UICustomFileSystemItem *parentItem();
|
---|
70 |
|
---|
71 | bool isDirectory() const;
|
---|
72 | bool isSymLink() const;
|
---|
73 | bool isFile() const;
|
---|
74 |
|
---|
75 | bool isOpened() const;
|
---|
76 | void setIsOpened(bool flag);
|
---|
77 |
|
---|
78 | /** Full absolute path of the item. With or without the trailing '/' */
|
---|
79 | QString path(bool fRemoveTrailingDelimiters = false) const;
|
---|
80 | void setPath(const QString &path);
|
---|
81 |
|
---|
82 | /** Returns true if this is directory and name is ".." */
|
---|
83 | bool isUpDirectory() const;
|
---|
84 | void clearChildren();
|
---|
85 |
|
---|
86 | KFsObjType type() const;
|
---|
87 |
|
---|
88 | const QString &targetPath() const;
|
---|
89 | void setTargetPath(const QString &path);
|
---|
90 |
|
---|
91 | bool isSymLinkToADirectory() const;
|
---|
92 | void setIsSymLinkToADirectory(bool flag);
|
---|
93 |
|
---|
94 | bool isSymLinkToAFile() const;
|
---|
95 |
|
---|
96 | const QString &owner() const;
|
---|
97 | void setOwner(const QString &owner);
|
---|
98 |
|
---|
99 | QString name() const;
|
---|
100 |
|
---|
101 | void setIsDriveItem(bool flag);
|
---|
102 | bool isDriveItem() const;
|
---|
103 |
|
---|
104 | void setIsHidden(bool flag);
|
---|
105 | bool isHidden() const;
|
---|
106 |
|
---|
107 | private:
|
---|
108 | void appendChild(UICustomFileSystemItem *child);
|
---|
109 |
|
---|
110 | QList<UICustomFileSystemItem*> m_childItems;
|
---|
111 | /** Used to find children by name */
|
---|
112 | QMap<QString, UICustomFileSystemItem*> m_childMap;
|
---|
113 | QMap<UICustomFileSystemModelColumn, QVariant> m_itemData;
|
---|
114 | UICustomFileSystemItem *m_parentItem;
|
---|
115 | bool m_bIsOpened;
|
---|
116 | /** If this is a symlink m_targetPath keeps the absolute path of the target */
|
---|
117 | QString m_strTargetPath;
|
---|
118 | /** True if this is a symlink and the target is a directory */
|
---|
119 | bool m_fIsTargetADirectory;
|
---|
120 | KFsObjType m_type;
|
---|
121 | /** True if only this item represents a DOS style drive letter item */
|
---|
122 | bool m_fIsDriveItem;
|
---|
123 | /** True if the file object is hidden in the file system. */
|
---|
124 | bool m_fIsHidden;
|
---|
125 | };
|
---|
126 |
|
---|
127 | /** A QSortFilterProxyModel extension used in file tables. Modifies some
|
---|
128 | * of the base class behavior like lessThan(..) */
|
---|
129 | class SHARED_LIBRARY_STUFF UICustomFileSystemProxyModel : public QSortFilterProxyModel
|
---|
130 | {
|
---|
131 |
|
---|
132 | Q_OBJECT;
|
---|
133 |
|
---|
134 | public:
|
---|
135 |
|
---|
136 | UICustomFileSystemProxyModel(QObject *parent = 0);
|
---|
137 |
|
---|
138 | void setListDirectoriesOnTop(bool fListDirectoriesOnTop);
|
---|
139 | bool listDirectoriesOnTop() const;
|
---|
140 |
|
---|
141 | void setShowHiddenObjects(bool fShowHiddenObjects);
|
---|
142 | bool showHiddenObjects() const;
|
---|
143 |
|
---|
144 | protected:
|
---|
145 |
|
---|
146 | virtual bool lessThan(const QModelIndex &left, const QModelIndex &right) const /* override */;
|
---|
147 | /** Currently filters out hidden objects if options is set to "not showing them". */
|
---|
148 | virtual bool filterAcceptsRow(int iSourceRow, const QModelIndex &sourceParent) const /* override */;
|
---|
149 |
|
---|
150 | private:
|
---|
151 |
|
---|
152 | bool m_fListDirectoriesOnTop;
|
---|
153 | bool m_fShowHiddenObjects;
|
---|
154 | };
|
---|
155 |
|
---|
156 | /** UICustomFileSystemModel serves as the model for a file structure.
|
---|
157 | * it supports a tree level hierarchy which can be displayed with
|
---|
158 | * QTableView and/or QTreeView.*/
|
---|
159 | class SHARED_LIBRARY_STUFF UICustomFileSystemModel : public QAbstractItemModel
|
---|
160 | {
|
---|
161 |
|
---|
162 | Q_OBJECT;
|
---|
163 |
|
---|
164 | signals:
|
---|
165 |
|
---|
166 | void sigItemRenamed(UICustomFileSystemItem *pItem, QString strOldName, QString strNewName);
|
---|
167 |
|
---|
168 | public:
|
---|
169 |
|
---|
170 | explicit UICustomFileSystemModel(QObject *parent = 0);
|
---|
171 | ~UICustomFileSystemModel();
|
---|
172 |
|
---|
173 | QVariant data(const QModelIndex &index, int role) const /* override */;
|
---|
174 | bool setData(const QModelIndex &index, const QVariant &value, int role);
|
---|
175 |
|
---|
176 | Qt::ItemFlags flags(const QModelIndex &index) const /* override */;
|
---|
177 | QVariant headerData(int section, Qt::Orientation orientation,
|
---|
178 | int role = Qt::DisplayRole) const /* override */;
|
---|
179 | QModelIndex index(int row, int column,
|
---|
180 | const QModelIndex &parent = QModelIndex()) const /* override */;
|
---|
181 | QModelIndex index(UICustomFileSystemItem* item);
|
---|
182 | QModelIndex parent(const QModelIndex &index) const /* override */;
|
---|
183 | int rowCount(const QModelIndex &parent = QModelIndex()) const /* override */;
|
---|
184 | int columnCount(const QModelIndex &parent = QModelIndex()) const /* override */;
|
---|
185 | void signalUpdate();
|
---|
186 | QModelIndex rootIndex() const;
|
---|
187 | void beginReset();
|
---|
188 | void endReset();
|
---|
189 | void reset();
|
---|
190 |
|
---|
191 | void setShowHumanReadableSizes(bool fShowHumanReadableSizes);
|
---|
192 | bool showHumanReadableSizes() const;
|
---|
193 | void deleteItem(UICustomFileSystemItem* pItem);
|
---|
194 | UICustomFileSystemItem* rootItem();
|
---|
195 | const UICustomFileSystemItem* rootItem() const;
|
---|
196 |
|
---|
197 | static const char* strUpDirectoryString;
|
---|
198 |
|
---|
199 | private:
|
---|
200 | void initializeTree();
|
---|
201 | UICustomFileSystemItem *m_pRootItem;
|
---|
202 | void setupModelData(const QStringList &lines, UICustomFileSystemItem *parent);
|
---|
203 | bool m_fShowHumanReadableSizes;
|
---|
204 | };
|
---|
205 |
|
---|
206 |
|
---|
207 | #endif /* !FEQT_INCLUDED_SRC_globals_UICustomFileSystemModel_h */
|
---|