8#ifndef SRC_STORETREE_H_
9#define SRC_STORETREE_H_
13#include <QFileSystemModel>
14#include <QFileSystemWatcher>
57 explicit StoreTree(QTreeView *
view, QObject *parent =
nullptr);
86 void setFilter(
const QRegularExpression &pattern);
96 [[nodiscard]]
auto dirFor(
const QModelIndex &index,
bool forPass)
const
104 [[nodiscard]]
auto currentDir(
bool forPass)
const -> QString;
114 [[nodiscard]]
auto fileFor(
const QModelIndex &index,
bool forPass)
const
122 [[nodiscard]]
auto currentFile(
bool forPass)
const -> QString;
129 [[nodiscard]]
auto fileInfo(
const QModelIndex &index)
const -> QFileInfo;
137 [[nodiscard]]
auto indexFor(
const QString &path)
const -> QModelIndex;
143 [[nodiscard]]
auto rootIndex() -> QModelIndex;
158 [[nodiscard]]
auto view() const -> QTreeView * {
return m_view; }
179 friend class tst_storetree;
180 friend class tst_mainwindow;
187 auto makeModel() -> std::unique_ptr<QFileSystemModel>;
232 std::unique_ptr<QFileSystemModel>
m_fs;
Abstract base class for password store operations.
QSortFilterProxyModel for filtering and displaying password store.
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.
std::unique_ptr< QFileSystemModel > m_fs
Source model over the store directory, filtered to *.gpg; replaced by setStore() and reload().
void shownListed(const QString &path)
The shown model listed path: watch it, list it in a model being built too, and filter again once the ...
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.
void swapInFresh()
Swap in the model reload() built, restoring the view.
QString m_restoreCurrent
The current entry a swap could not show yet.
auto currentIndex() const -> QModelIndex
The view's current index.
QTimer m_freshDeadline
Ends the wait for m_fresh: it is swapped in as it is.
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.
auto store() const -> QString
void setFilter(const QRegularExpression &pattern)
Filter the visible entries.
std::unique_ptr< QFileSystemModel > m_retired
The model reload() replaced, kept until the next one: a caller still holding it reads stale rows inst...
void directoryLoaded(const QString &path)
The file system model the view shows finished listing a folder; also once for the store root after re...
void restoreCurrent()
Make the entry a swap could not show current again, once it shows. The wait ends when the listings th...
void unwatchGoneDirs()
Stop watching the folders that no longer exist.
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 *
void setStore(const QString &path)
Point everything at path: file system root, proxy store and view root index. Also drops a search filt...
QSet< QString > m_freshPending
Folders m_fresh still has to list before the swap.
StoreModel m_proxy
Proxy the view shows: hides .git, strips .gpg, applies the search filter and handles drag and drop.
auto fileSystem() -> QFileSystemModel &
void watchDir(const QString &dir)
Watch dir from now on, as the shown model has listed it.
auto makeModel() -> std::unique_ptr< QFileSystemModel >
A file system model as the tree uses it: *.gpg only, and not watching (see the class description).
auto expandedDirs() const -> QStringList
The watched folders the view shows expanded, for swapInFresh().
QTimer m_reloadTimer
Waits for the watched folders to be quiet, then reload().
void reload()
List the store again in a fresh file system model and swap it in once the store root and every folder...
bool m_reloadAgain
A reload() came while m_fresh was built: run one after it.
void setUpColumns()
Hide the size, type and date columns and sort by name, once a source model is attached.
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 currentEntryLost(const QString &path)
After a reload() the current entry or folder could not be shown again: it was removed or renamed,...
std::unique_ptr< QFileSystemModel > m_fresh
The model reload() is building, until it is swapped in.
QSet< QString > m_stillListing
Folders still being listed when m_fresh was swapped in.
auto proxy() -> StoreModel &
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.
QFileSystemWatcher m_watcher
The folders the shown model has listed; reload() lists all of them again.
StoreModel, the filtering/sorting proxy over the store's QFileSystemModel, and StoreDragItem,...