|
QtPass 2.0.0
Developer documentation
|
The password store as shown in the tree: the QFileSystemModel, the StoreModel proxy on top of it and the QTreeView they drive, with the path questions the main window keeps asking. More...
#include <storetree.h>
Signals | |
| void | directoryLoaded (const QString &path) |
| The file system model the view shows finished listing a folder; also once for the store root after reload() swapped models. | |
| void | currentEntryLost (const QString &path) |
| After a reload() the current entry or folder could not be shown again: it was removed or renamed, or its folder was not listed yet. Nothing is current then, so currentDir() gives the store root, and a menu opened on that entry must not act on the root instead. One that still exists is made current again if it shows once the listings still under way at the swap are in. | |
Public Member Functions | |
| StoreTree (QTreeView *view, QObject *parent=nullptr) | |
| Attach the proxy model to the view and set its look: hidden header, indentation, scroll bars, context-menu policy. Column hiding and sorting need a source model and happen in setStore(). | |
| void | setStore (const QString &path) |
Point everything at path: file system root, proxy store and view root index. Also drops a search filter. | |
| void | reload () |
| List the store again in a fresh file system model and swap it in once the store root and every folder listed before (expanded or not, so a search still sees inside it) are listed again, keeping the expanded folders, the current entry and the scroll position. Runs by itself a moment after a listed folder changed. | |
| void | setPass (Pass *pass) |
| Hand the proxy the backend it drops onto. | |
| void | setFilter (const QRegularExpression &pattern) |
| Filter the visible entries. | |
| auto | dirFor (const QModelIndex &index, bool forPass) const -> QString |
| The folder an index stands for. | |
| auto | currentDir (bool forPass) const -> QString |
| dirFor() applied to the view's current index. | |
| auto | fileFor (const QModelIndex &index, bool forPass) const -> QString |
| The entry an index stands for. | |
| auto | currentFile (bool forPass) const -> QString |
| fileFor() applied to the view's current index. | |
| auto | fileInfo (const QModelIndex &index) const -> QFileInfo |
| File system information for a view index. | |
| 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. | |
| auto | rootIndex () -> QModelIndex |
| The proxy's root index for the current store. | |
| auto | currentIndex () const -> QModelIndex |
| The view's current index. | |
| auto | store () const -> QString |
| auto | proxy () -> StoreModel & |
| auto | fileSystem () -> QFileSystemModel & |
| auto | view () const -> QTreeView * |
Private Member Functions | |
| auto | makeModel () -> std::unique_ptr< QFileSystemModel > |
| A file system model as the tree uses it: *.gpg only, and not watching (see the class description). | |
| void | setUpColumns () |
| Hide the size, type and date columns and sort by name, once a source model is attached. | |
| void | watchDir (const QString &dir) |
Watch dir from now on, as the shown model has listed it. | |
| void | swapInFresh () |
| Swap in the model reload() built, restoring the view. | |
| auto | expandedDirs () const -> QStringList |
| The watched folders the view shows expanded, for swapInFresh(). | |
| void | unwatchGoneDirs () |
| Stop watching the folders that no longer exist. | |
| 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 listings a swap did not wait for are done. | |
| void | restoreCurrent () |
| Make the entry a swap could not show current again, once it shows. The wait ends when the listings the swap did not wait for are in, or when another entry is made current, even one deselected since. | |
Private Attributes | |
| QTreeView * | m_view |
| The tree view this object drives; owned by the main window. | |
| std::unique_ptr< QFileSystemModel > | m_fs |
| Source model over the store directory, filtered to *.gpg; replaced by setStore() and reload(). | |
| std::unique_ptr< QFileSystemModel > | m_retired |
| The model reload() replaced, kept until the next one: a caller still holding it reads stale rows instead of freed memory. | |
| std::unique_ptr< QFileSystemModel > | m_fresh |
| The model reload() is building, until it is swapped in. | |
| QSet< QString > | m_freshPending |
| Folders m_fresh still has to list before the swap. | |
| QSet< QString > | m_stillListing |
| Folders still being listed when m_fresh was swapped in. | |
| QString | m_restoreCurrent |
| The current entry a swap could not show yet. | |
| bool | m_reloadAgain = false |
| A reload() came while m_fresh was built: run one after it. | |
| QTimer | m_freshDeadline |
| Ends the wait for m_fresh: it is swapped in as it is. | |
| QFileSystemWatcher | m_watcher |
| The folders the shown model has listed; reload() lists all of them again. | |
| QTimer | m_reloadTimer |
| Waits for the watched folders to be quiet, then reload(). | |
| StoreModel | m_proxy |
| Proxy the view shows: hides .git, strips .gpg, applies the search filter and handles drag and drop. | |
| QString | m_store |
| Absolute store directory last passed to setStore(). | |
Friends | |
| class | tst_storetree |
| class | tst_mainwindow |
The password store as shown in the tree: the QFileSystemModel, the StoreModel proxy on top of it and the QTreeView they drive, with the path questions the main window keeps asking.
Owns the two models. setStore() is the one place that re-roots the file system model, the proxy and the view together (this sequence used to be spelled out five times); dirFor()/fileFor() are the two path mappings that were duplicated across MainWindow and Util.
The file system model does not watch the store itself: when files in a folder it lists change, Qt finds each changed row by a linear search, so a pulled commit that rewrote N entries of one folder froze the window for on the order of N² comparisons (half a minute for 20000). StoreTree watches the folders the model has listed instead and, once they have been quiet for a moment, builds a fresh model (reload()), which costs time linear in what it lists.
Definition at line 46 of file storetree.h.
|
explicit |
Attach the proxy model to the view and set its look: hidden header, indentation, scroll bars, context-menu policy. Column hiding and sorting need a source model and happen in setStore().
| view | The tree view to drive. |
| parent | Owner. |
Definition at line 16 of file storetree.cpp.
|
nodiscard |
dirFor() applied to the view's current index.
| forPass | As in dirFor(). |
Definition at line 313 of file storetree.cpp.
|
signal |
After a reload() the current entry or folder could not be shown again: it was removed or renamed, or its folder was not listed yet. Nothing is current then, so currentDir() gives the store root, and a menu opened on that entry must not act on the root instead. One that still exists is made current again if it shows once the listings still under way at the swap are in.
| path | Absolute path the current entry had. |
|
nodiscard |
fileFor() applied to the view's current index.
| forPass | As in fileFor(). |
Definition at line 331 of file storetree.cpp.
|
nodiscard |
The view's current index.
Definition at line 348 of file storetree.cpp.
|
signal |
The file system model the view shows finished listing a folder; also once for the store root after reload() swapped models.
| path | Absolute folder path. |
|
nodiscard |
The folder an index stands for.
| index | View index; a file maps to its folder, an invalid index to the store root. |
| forPass | true for a store-relative path ("" for the root), false for an absolute one. |
Definition at line 297 of file storetree.cpp.
|
nodiscardprivate |
The watched folders the view shows expanded, for swapInFresh().
Definition at line 169 of file storetree.cpp.
|
nodiscard |
The entry an index stands for.
| index | View index; folders and invalid indexes yield an empty string. |
| forPass | true for the pass name (store-relative, no .gpg), false for the absolute .gpg path. |
index is not a file. Definition at line 317 of file storetree.cpp.
|
nodiscard |
File system information for a view index.
| index | View index. |
Definition at line 335 of file storetree.cpp.
|
inlinenodiscard |
Definition at line 156 of file storetree.h.
|
nodiscard |
The view index for an absolute path, or invalid when the file system model does not (yet) know it.
| path | Absolute path inside the store. |
Definition at line 339 of file storetree.cpp.
|
private |
A file system model as the tree uses it: *.gpg only, and not watching (see the class description).
Definition at line 51 of file storetree.cpp.
|
inlinenodiscard |
Definition at line 154 of file storetree.h.
| void StoreTree::reload | ( | ) |
List the store again in a fresh file system model and swap it in once the store root and every folder listed before (expanded or not, so a search still sees inside it) are listed again, keeping the expanded folders, the current entry and the scroll position. Runs by itself a moment after a listed folder changed.
Definition at line 138 of file storetree.cpp.
|
private |
Make the entry a swap could not show current again, once it shows. The wait ends when the listings the swap did not wait for are in, or when another entry is made current, even one deselected since.
Definition at line 119 of file storetree.cpp.
|
nodiscard |
The proxy's root index for the current store.
Definition at line 344 of file storetree.cpp.
| void StoreTree::setFilter | ( | const QRegularExpression & | pattern | ) |
Filter the visible entries.
| pattern | Regular expression matched against entry names; an invalid or empty one shows everything. |
Definition at line 290 of file storetree.cpp.
| void StoreTree::setPass | ( | Pass * | pass | ) |
Hand the proxy the backend it drops onto.
| pass | Active backend (not owned). |
Definition at line 288 of file storetree.cpp.
| void StoreTree::setStore | ( | const QString & | path | ) |
Point everything at path: file system root, proxy store and view root index. Also drops a search filter.
| path | Password store directory. |
Definition at line 256 of file storetree.cpp.
|
private |
Hide the size, type and date columns and sort by name, once a source model is attached.
Definition at line 72 of file storetree.cpp.
|
private |
The shown model listed path: watch it, list it in a model being built too, and filter again once the listings a swap did not wait for are done.
| path | Absolute folder path. |
Definition at line 90 of file storetree.cpp.
|
inlinenodiscard |
Definition at line 152 of file storetree.h.
|
private |
Swap in the model reload() built, restoring the view.
Definition at line 198 of file storetree.cpp.
|
private |
Stop watching the folders that no longer exist.
Definition at line 185 of file storetree.cpp.
|
inlinenodiscard |
Definition at line 158 of file storetree.h.
|
private |
Watch dir from now on, as the shown model has listed it.
| dir | Absolute folder path. |
Definition at line 83 of file storetree.cpp.
|
friend |
Definition at line 180 of file storetree.h.
|
friend |
Definition at line 179 of file storetree.h.
|
private |
The model reload() is building, until it is swapped in.
Definition at line 239 of file storetree.h.
|
private |
Ends the wait for m_fresh: it is swapped in as it is.
Definition at line 249 of file storetree.h.
|
private |
Folders m_fresh still has to list before the swap.
Definition at line 241 of file storetree.h.
|
private |
Source model over the store directory, filtered to *.gpg; replaced by setStore() and reload().
Definition at line 232 of file storetree.h.
|
private |
Proxy the view shows: hides .git, strips .gpg, applies the search filter and handles drag and drop.
Definition at line 261 of file storetree.h.
|
private |
A reload() came while m_fresh was built: run one after it.
Definition at line 247 of file storetree.h.
|
private |
Waits for the watched folders to be quiet, then reload().
Definition at line 256 of file storetree.h.
|
private |
The current entry a swap could not show yet.
Definition at line 245 of file storetree.h.
|
private |
The model reload() replaced, kept until the next one: a caller still holding it reads stale rows instead of freed memory.
Definition at line 237 of file storetree.h.
|
private |
Folders still being listed when m_fresh was swapped in.
Definition at line 243 of file storetree.h.
|
private |
Absolute store directory last passed to setStore().
Definition at line 263 of file storetree.h.
|
private |
The tree view this object drives; owned by the main window.
Definition at line 227 of file storetree.h.
|
private |
The folders the shown model has listed; reload() lists all of them again.
Definition at line 254 of file storetree.h.