16 m_fs.setNameFilters(QStringList() << QStringLiteral(
"*.gpg"));
17 m_fs.setNameFilterDisables(
false);
20 m_view->setHeaderHidden(
true);
21 m_view->setIndentation(15);
22 m_view->setHorizontalScrollBarPolicy(Qt::ScrollBarAsNeeded);
23 m_view->setContextMenuPolicy(Qt::CustomContextMenu);
28 const QModelIndex rootDir =
m_fs.setRootPath(path);
29 m_fs.fetchMore(rootDir);
30 if (
m_proxy.sourceModel() ==
nullptr) {
35 m_view->setColumnHidden(1,
true);
36 m_view->setColumnHidden(2,
true);
37 m_view->setColumnHidden(3,
true);
38 m_view->header()->setSectionResizeMode(0, QHeaderView::Stretch);
39 m_view->sortByColumn(0, Qt::AscendingOrder);
43 m_proxy.setFilterRegularExpression(QRegularExpression());
50 m_proxy.setFilterRegularExpression(pattern);
57 const QString abspath = QDir(
m_store).absolutePath() + QDir::separator();
58 if (!index.isValid()) {
59 return forPass ? QString() : abspath;
61 const QFileInfo info =
m_fs.fileInfo(
m_proxy.mapToSource(index));
63 info.isFile() ? info.absolutePath() : info.absoluteFilePath();
65 filePath = QDir(abspath).relativeFilePath(filePath);
67 filePath += QDir::separator();
77 if (!index.isValid() || !
m_fs.fileInfo(
m_proxy.mapToSource(index)).isFile()) {
80 QString filePath =
m_fs.filePath(
m_proxy.mapToSource(index));
82 filePath = QDir(
m_store).relativeFilePath(filePath);
97 const QModelIndex src =
m_fs.index(path);
98 return src.isValid() ?
m_proxy.mapFromSource(src) : QModelIndex();
106 return m_view->currentIndex();
Abstract base class for password store operations.
void setModelAndStore(QFileSystemModel *sourceModel, const QString &passStore)
Initialize model with source model and store path.
void setStore(const QString &passStore)
Update the store path used for filtering without changing the source model.
void setPass(Pass *pass)
Inject the Pass backend for drag-and-drop Move/Copy operations.
auto rootIndexFor(const QString &path) -> QModelIndex
Set the source filesystem root and map it to a proxy index.
QString m_store
Absolute store directory last passed to setStore().
auto dirFor(const QModelIndex &index, bool forPass) const -> QString
The folder an index stands for.
auto fileInfo(const QModelIndex &index) const -> QFileInfo
File system information for a view index.
auto rootIndex() -> QModelIndex
The proxy's root index for the current store.
auto currentIndex() const -> QModelIndex
The view's current index.
auto currentFile(bool forPass) const -> QString
fileFor() applied to the view's current index.
QTreeView * m_view
The tree view this object drives; owned by the main window.
auto fileFor(const QModelIndex &index, bool forPass) const -> QString
The entry an index stands for.
void setFilter(const QRegularExpression &pattern)
Filter the visible entries.
StoreTree(QTreeView *view, QObject *parent=nullptr)
Attach the proxy model to the view and set its look: hidden header, indentation, scroll bars,...
auto view() const -> QTreeView *
QFileSystemModel m_fs
Source model over the store directory, filtered to *.gpg; re-rooted by setStore().
void setStore(const QString &path)
Point everything at path: file system root, proxy store and view root index. Also drops a search filt...
StoreModel m_proxy
Proxy the view shows: hides .git, strips .gpg, applies the search filter and handles drag and drop.
auto indexFor(const QString &path) const -> QModelIndex
The view index for an absolute path, or invalid when the file system model does not (yet) know it.
void setPass(Pass *pass)
Hand the proxy the backend it drops onto.
auto currentDir(bool forPass) const -> QString
dirFor() applied to the view's current index.
static auto endsWithGpg() -> const QRegularExpression &
Returns a regex to match .gpg file extensions.
StoreTree: owns the QFileSystemModel and StoreModel behind the password tree view and maps view index...
Util: static helpers for the process environment, binary discovery, store paths, URL safety and the l...