QtPass 2.0.0
Developer documentation
Loading...
Searching...
No Matches
mainwindow.h
Go to the documentation of this file.
1// SPDX-FileCopyrightText: 2014 Anne Jan Brouwer
2// SPDX-License-Identifier: GPL-3.0-or-later
9#ifndef SRC_MAINWINDOW_H_
10#define SRC_MAINWINDOW_H_
11
12#include "appsettings.h"
13#include "enums.h"
15#include "storetree.h"
16
17#include <QDialog>
18#include <QMainWindow>
19#include <QPointer>
20#include <QProcess>
21#include <QTimer>
22
23#ifdef __APPLE__
31void qt_set_sequence_auto_mnemonic(bool b);
32#endif
33
34namespace Ui {
35class MainWindow;
36} // namespace Ui
37
38class Pass;
40class QPushButton;
41class QProgressDialog;
42class QTreeWidgetItem;
43class QtPass;
45class TrayIcon;
46
59class MainWindow : public QMainWindow {
60 Q_OBJECT
62 friend class tst_mainwindow;
63
64public:
70 explicit MainWindow(const QString &searchText = QString(),
71 QWidget *parent = nullptr);
76 ~MainWindow() override;
77
81 void restoreWindow();
82
92 auto config() -> bool;
93
98 void setUiElementsEnabled(bool state);
99
113 void flashText(const QString &text, const bool isError,
114 const bool isHtml = false);
116 static constexpr int kMaxFlashCharacters = 64 * 1024;
117
122 auto getCurrentTreeViewIndex() -> QModelIndex;
123
133 auto initSucceeded() const -> bool { return m_initSucceeded; }
134
135protected:
140 void closeEvent(QCloseEvent *event) override;
145 void keyPressEvent(QKeyEvent *event) override;
150 void changeEvent(QEvent *event) override;
158 auto event(QEvent *event) -> bool override;
164 void showEvent(QShowEvent *event) override;
171 auto eventFilter(QObject *obj, QEvent *event) -> bool override;
172
173public slots:
177 void deselect();
178
183 void messageAvailable(const QString &message);
184
192 void onProcessOutput(const QString &output, bool isError,
194
200 void critical(const QString &title, const QString &msg);
201
206
212 void showStatusMessage(const QString &msg, int timeout = 2000);
213
223 void passShowHandler(const QString &output, const QString &file = QString());
224
231 void otpFromFileToClipboard(const QString &output, const QString &file);
232
240 void passwordFromFileToClipboard(const QString &text, const QString &file);
241
249 void cancelOtpRequest();
259 void onOperationError();
260
266
273 void refreshMarkedSecrets(const AppSettings &s);
274
279 void onGrepFinished(const QList<QPair<QString, QStringList>> &results);
280
284 void onPush();
289 void onAutoPush();
290
295 void on_treeView_clicked(const QModelIndex &index);
296
304 void startReencryptPath();
305
311 void reencryptProgress(int current, int total);
312
316 void endReencryptPath();
317
327 void askReencryptUnexpected(const QString &dir, const QStringList &files,
328 const QStringList &details);
329
330private slots:
335 void updateProfileBox();
348 void on_grepButton_toggled(bool checked);
357 void on_grepResultsList_itemClicked(QTreeWidgetItem *item, int column);
360 void addPassword();
366 void addFolder();
369 void onEdit();
376 void onDelete();
382 void onOtp();
388 void onUpdate(bool block = false);
393 void onUsers();
398 void onConfig();
402 void showAbout();
408 void on_treeView_doubleClicked(const QModelIndex &index);
415 void clearPanel(bool notify = true);
422 void clearShownEntry(bool notify);
427 void clearContentResults();
433 void on_lineEdit_textChanged(const QString &arg1);
447 void on_profileBox_currentTextChanged(const QString &name);
454 void showContextMenu(const QPoint &pos);
464 auto backOnMenuEntry(const QString &openedOn) -> bool;
472 void addShareMenu(QMenu &contextMenu, const AppSettings &s);
480 auto confirmDeletion(const QString &file, bool isDir) -> bool;
487 auto confirmLinkRemoval(const QString &file) -> bool;
493 void showBrowserContextMenu(const QPoint &pos);
504 auto browserContextMenu(const QPoint &pos) -> QMenu *;
507 void openFolder();
512 void renameFolder();
519 void editPassword(const QString &file);
525 void renamePassword();
532 void focusInput();
556 void onTimeoutSearch();
557
558private:
567 [[nodiscard]] auto grepLineForDisplay(const QString &line,
568 const AppSettings &s) const -> QString;
569
576 QScopedPointer<Ui::MainWindow> ui;
593 bool m_themeSwitched = false;
598 QString m_shownFile;
626 StoreTree *m_tree = nullptr;
642 QPushButton *m_stopButton = nullptr;
644 static constexpr int UiWatchdogMs = 30000;
647 QPointer<QProgressDialog> m_reencryptProgress;
653 bool m_inProgressUpdate = false;
656 QPointer<QProgressDialog> m_progressToDelete;
659 QPointer<QObject> m_pendingOpen;
664 bool m_reencryptRunning = false;
667 bool m_uiEnabled = true;
675 bool m_initSucceeded = false;
678 bool m_freshStart = true;
679
682 void initToolBarButtons();
684 void initStatusBar();
687 void connectBackends();
689 void initTextBrowser();
691 void initDisplayPanel();
694 void initTimers();
697 void initProcessOutput();
704 void connectPassSignals(Pass *pass);
705
708 void selectFirstFile();
709
717 void showContentResults(bool shown);
718
723 void cancelContentSearch();
729 auto exactMatch() -> QModelIndex;
735 auto exactMatchPath() -> QString;
742 void applySearchText(const QString &text);
747 void openExactMatch(const QModelIndex &index);
753 auto firstFile(QModelIndex parentIndex) -> QModelIndex;
761 auto getFile(const QModelIndex &index, bool forPass) -> QString;
769 void setPassword(const QString &file, bool isNew = true);
777 auto confirmPathInStore(const QString &candidate) -> bool;
778
783 void initTrayIcon();
785 void destroyTrayIcon();
792 void reencryptPath(const QString &dir);
798 void exportPublicKey();
804 void addRecipient(const QString &dir);
812 auto refuseLinkedFolder(const QString &dir) -> bool;
814 void showShareHelp();
815
824 void saveWindowState();
825
831 void updateGitButtonVisibility(bool uiEnabled = true);
837 void updateOtpButtonVisibility(bool uiEnabled = true);
845 void enableGitButtons(const bool &state);
846
850};
851
852#endif // SRC_MAINWINDOW_H_
AppSettings, the value object holding every flat QtPass setting.
State machine for MainWindow's content-search (grep) mode.
GrepSearchController m_grep
Mode/busy/cancelled state of the content search.
Definition mainwindow.h:578
void dropStaleToolsAreaPalettes()
Drop a style-imposed menu bar or toolbar palette that belongs to the other theme (Breeze header palet...
void startReencryptPath()
Begin a re-encryption pass on the current path.
void addPassword()
Toolbar/context-menu "Add password": open PasswordDialog for a new entry in the current folder.
void closeEvent(QCloseEvent *event) override
Save window state and geometry on close.
void cancelOtpRequest()
Forget the pending OTP and copy requests.
void showContentResults(bool shown)
Show the content search results in place of the tree, or the tree again.
bool m_uiEnabled
Definition mainwindow.h:667
void renameFolder()
Context menu "Rename folder": ask for a new name and Move the current folder, refusing a target outsi...
QString m_panelEntry
Definition mainwindow.h:602
void askReencryptUnexpected(const QString &dir, const QStringList &files, const QStringList &details)
Ask whether entries a re-encryption left alone, being encrypted to other keys than their folder had,...
void initTextBrowser()
Font, wrapping and link handling of the text browser, per the settings.
void enableGitButtons(const bool &state)
Enable or disable the Push and Pull actions together.
QPointer< Pass > m_refreshAfterPushOwner
Definition mainwindow.h:609
void onConfig()
Toolbar "Config": config(), ignoring its result; refused while a backend still runs or waits,...
void saveWindowState()
void initToolBarButtons()
void endReencryptPath()
Finish a re-encryption pass on the current path.
QTimer m_uiWatchdog
Definition mainwindow.h:639
void onGrepFinished(const QList< QPair< QString, QStringList > > &results)
Handle results from a completed grep search.
void applySearchText(const QString &text)
Searches for text as qtpass(1) promises for the command line and for text handed over by another qtpa...
void setPassword(const QString &file, bool isNew=true)
Run PasswordDialog for a new or existing entry. For a new one the dialog gets the store's real folder...
QPointer< QObject > m_pendingOpen
Definition mainwindow.h:659
void refreshMarkedSecrets(const AppSettings &s)
Hand the display panel what a template marks secret, in the settings or the store's ....
void executeWrapperStarted()
Slot called when an external process wrapper has started.
PasswordDisplayPanel * m_displayPanel
Renders decrypted fields into the grid; created in initDisplayPanel(), parented to this window.
Definition mainwindow.h:583
QTimer searchTimer
Definition mainwindow.h:629
void clearShownEntry(bool notify)
Empty the display panel and the text browser and close the QR code: the shown entry only....
void updateGitButtonVisibility(bool uiEnabled=true)
Show Push and Pull only when Git is in use; enable them only while the interface is.
void onDelete()
Toolbar "Delete" or the Delete key: confirm, then remove the current entry or folder....
void showEvent(QShowEvent *event) override
First-show hook used to focus the search input once the window is actually mapped (avoids races with ...
void editPassword(const QString &file)
Open PasswordDialog on an existing entry, after a blocking pull when auto-pull is on....
void changeEvent(QEvent *event) override
React to language or window state changes.
QPointer< QProgressDialog > m_reencryptProgress
Definition mainwindow.h:647
void on_profileBox_currentTextChanged(const QString &name)
The user picked another profile: save its store, key and Git flags as the active settings,...
void addFolder()
Toolbar/context-menu "Add folder": ask for a name, create the folder under the current one (refusing ...
void updateGrepButtonVisibility()
friend class tst_mainwindow
Drives exportPublicKey(), which only a context menu reaches.
Definition mainwindow.h:62
auto grepLineForDisplay(const QString &line, const AppSettings &s) const -> QString
A content search match as the results list shows it, by the display panel's rules: a one-time passwor...
ProcessOutputPanel * m_processOutput
Definition mainwindow.h:624
void messageAvailable(const QString &message)
Handle an incoming inter-process message (single-instance mode).
MainWindow(const QString &searchText=QString(), QWidget *parent=nullptr)
Construct the main window.
void copyPasswordFromTreeview()
Ctrl+C on the tree: decrypt the current entry and let passwordFromFileToClipboard() copy its first li...
void connectPassSignals(Pass *pass)
Connect the signals of one backend that the window answers itself: errors, critical messages,...
StoreTree * m_tree
The store as shown in the tree: models, view setup, path mapping.
Definition mainwindow.h:626
void reencryptProgress(int current, int total)
Update the re-encryption progress dialog.
void keyPressEvent(QKeyEvent *event) override
Handle keyboard shortcuts.
bool m_freshStart
Definition mainwindow.h:678
void addShareMenu(QMenu &contextMenu, const AppSettings &s)
Add the Share submenu for the folder under the cursor: the entries are enabled only where a recipient...
void on_treeView_doubleClicked(const QModelIndex &index)
A double-click on a tree entry opens it for editing; folders are left to the view.
void showShareHelp()
Share menu "What is this?": the explanation of sharing with GPG.
QTimer clearResultsTimer
Definition mainwindow.h:635
auto exactMatch() -> QModelIndex
The entry whose name is exactly the search text, if the filtered tree shows it: team/bank for "team/b...
void onTimeoutSearch()
searchTimer fired: filter the tree on the typed words (matched literally, in order,...
void onPush()
Trigger a git push operation.
void showStatusMessage(const QString &msg, int timeout=2000)
Show a message in the status bar for the given duration.
void focusInput()
Select-all and focus the search box once the window is visible; sets m_firstShowCompleted only on suc...
bool m_themeSwitched
Definition mainwindow.h:593
void on_lineEdit_returnPressed()
Enter in the search box: in content-search mode start (or, for an empty query, cancel) the grep; othe...
auto refuseLinkedFolder(const QString &dir) -> bool
Refuse, with a message, a tree-picked folder that is or lies behind a symlink or junction: what it po...
QString m_copyRequestFile
Definition mainwindow.h:617
void on_grepButton_toggled(bool checked)
The content-search toggle changed: switch the search box between name filtering and regex content sea...
QTimer clearPanelTimer
Definition mainwindow.h:629
void selectFirstFile()
auto confirmDeletion(const QString &file, bool isDir) -> bool
Ask before deleting an entry or a folder, naming what goes and warning when the folder holds anything...
void onOperationError()
An operation ended in an error before or instead of a result: forget the pending requests and what th...
static constexpr int kMaxFlashCharacters
Most characters the text panel keeps of appended output.
Definition mainwindow.h:116
void updateProcessOutputVisibility()
void on_grepResultsList_itemClicked(QTreeWidgetItem *item, int column)
A content-search result was clicked: select the entry in the tree, show it, and go back to the tree (...
void reencryptPath(const QString &dir)
Share menu "Re-encrypt all passwords": confirm, lock the UI via startReencryptPath() and have Imitate...
void passwordFromFileToClipboard(const QString &text, const QString &file)
Copy the first line of a decrypted entry (Ctrl+C). Ignores decrypts of anything but the entry copyPas...
auto confirmPathInStore(const QString &candidate) -> bool
Guard the input dialogs (create, move, rename) against names like ../../etc/passwd or absolute paths ...
void onAutoPush()
Trigger the automatic git push after a change (QtPass::pushRequested()); see Pass::GitPushAutomatic()...
auto backOnMenuEntry(const QString &openedOn) -> bool
Make the entry a tree menu was opened on current again, for the action picked from it: the current in...
void showContextMenu(const QPoint &pos)
Build and show the tree's context menu for the item under the cursor: folder actions (open,...
void updateProfileBoxEnabled()
Enable the profile box only when there is more than one profile, the interface is enabled and the bac...
void critical(const QString &title, const QString &msg)
Display a critical error dialog.
void clearContentResults()
Empty the content search results and, if they were showing, put the tree back and leave content searc...
void applyWindowFlagsSettings()
void updateProfileBox()
Fill the profile box from the settings, the active profile selected, without switching profiles while...
void updateOtpButtonVisibility(bool uiEnabled=true)
Refresh the OTP toolbar action from settings.
QString m_refreshAfterPush
Definition mainwindow.h:606
void addRecipient(const QString &dir)
Share menu "Add recipient": open UsersDialog for dir (keys already in the keyring only).
bool m_firstShowCompleted
Set once focusInput() has actually focused the search box, so later show events leave the focus alone...
Definition mainwindow.h:588
void onEdit()
Toolbar "Edit" or a double-click: editPassword() on the current entry.
void restoreWindow()
Restore window geometry and state from saved settings.
auto exactMatchPath() -> QString
The entry file named exactly as the search text, spaces around the text included; failing that,...
QString m_otpRequestFile
Definition mainwindow.h:613
void onOtp()
Toolbar "OTP": copy the current entry's one-time code. Uses the code the panel already shows for this...
auto confirmLinkRemoval(const QString &file) -> bool
Ask before removing a folder that is a link, which takes the link and leaves what it points to.
void showBrowserContextMenu(const QPoint &pos)
Show the text browser's standard context menu, reparented to the window so the browser's stylesheet d...
QScopedPointer< Ui::MainWindow > ui
The widgets generated from mainwindow.ui.
Definition mainwindow.h:576
auto eventFilter(QObject *obj, QEvent *event) -> bool override
Filter events from watched objects.
auto browserContextMenu(const QPoint &pos) -> QMenu *
The text browser's standard context menu, with "Copy Link Location" copying through ClipboardMa...
QPushButton * m_stopButton
Definition mainwindow.h:642
void showAbout()
Show the About box: version, project link, licence.
static constexpr int UiWatchdogMs
Interval of m_uiWatchdog in milliseconds.
Definition mainwindow.h:644
void openFolder()
Context menu "Open folder with file manager" on the current folder.
void exportPublicKey()
Share menu "Export my public key": run gpg --armor --export for the configured signing key and show t...
void openExactMatch(const QModelIndex &index)
Makes index current and opens it, as a click on it would.
QString m_shownFile
Definition mainwindow.h:598
QPointer< QProgressDialog > m_progressToDelete
Definition mainwindow.h:656
void initTrayIcon()
Create m_tray and add the menu bar toggle to its menu; gives up (m_tray stays null) when no system tr...
void flashText(const QString &text, const bool isError, const bool isHtml=false)
Display a transient message in the text panel.
void connectBackends()
void initStatusBar()
Welcome message and the permanent logo in the status bar.
void initDisplayPanel()
The grid of decrypted fields and what its buttons ask for.
void otpFromFileToClipboard(const QString &output, const QString &file)
Generate a one-time password from decrypted content and copy it. Ignores decrypts of anything but the...
void clearPanel(bool notify=true)
Empty the display panel and the text browser, and leave content search if its results were showing.
void setUiElementsEnabled(bool state)
Enable or disable the main UI elements.
auto event(QEvent *event) -> bool override
Notice an application palette change, the theme switch that makes a style-imposed bar palette suspect...
auto initSucceeded() const -> bool
Return whether startup configuration succeeded.
Definition mainwindow.h:133
bool m_inProgressUpdate
Definition mainwindow.h:653
void applyTextBrowserSettings()
auto config() -> bool
Open the configuration dialog.
auto getCurrentTreeViewIndex() -> QModelIndex
Return the currently selected index in the tree view.
bool m_initSucceeded
Definition mainwindow.h:675
void cancelContentSearch()
void onUpdate(bool block=false)
Toolbar "Update": git pull.
void initTimers()
void deselect()
Clear the current tree view selection.
auto getFile(const QModelIndex &index, bool forPass) -> QString
StoreTree::fileFor() on the tree.
void onProcessOutput(const QString &output, bool isError, Enums::PROCESS pid=Enums::INVALID)
Handle generic process output for display in output panel.
void passShowHandler(const QString &output, const QString &file=QString())
Render a decrypted entry: fields into the display panel, the rest into the text browser,...
void on_treeView_clicked(const QModelIndex &index)
Handle a click on an item in the tree view.
void initProcessOutput()
void onUsers()
Toolbar/context-menu "Users": open UsersDialog for the current folder, unless it lies behind a link.
void destroyTrayIcon()
Delete m_tray and reset it to null.
TrayIcon * m_tray
Definition mainwindow.h:671
QtPass * m_qtPass
The UI-neutral glue to the backends (output, status, clipboard, QR codes); created in the constructor...
Definition mainwindow.h:574
auto firstFile(QModelIndex parentIndex) -> QModelIndex
Depth-first search for the first entry under a folder.
void renamePassword()
Context menu "Rename password": ask for a new name and Move the current entry within its folder,...
void on_lineEdit_textChanged(const QString &arg1)
The search box changed (name filtering only): drop the pending decrypt and the panel,...
void copySelectionOrPassword()
Ctrl+C anywhere in the window: the selected text when the focus is in a text view or a selectable lab...
bool m_reencryptRunning
Definition mainwindow.h:664
Abstract base class for password store operations.
Definition pass.h:77
Renders decrypted password-file fields into MainWindow's grid.
The dockable "Process output" console: numbered, colour-coded lines of git/pass/gpg output with a lin...
Application-level glue between the pass backends and whatever shows their results: turns the backends...
Definition qtpass.h:29
The password store as shown in the tree: the QFileSystemModel, the StoreModel proxy on top of it and ...
Definition storetree.h:46
Handles the system tray icon and menu.
Definition trayicon.h:28
The Enums namespace: clipboard behaviour and the identifiers of the subprocess kinds QtPass queues.
GrepSearchController: the mode/busy/cancelled state machine behind MainWindow's content search.
PROCESS
Identifies different subprocess operations used in QtPass.
Definition enums.h:43
@ INVALID
Definition enums.h:63
StoreTree: owns the QFileSystemModel and StoreModel behind the password tree view and maps view index...
Plain value-object holding all flat QtPass configuration.
Definition appsettings.h:36