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;
36class Pass;
37} // namespace Ui
38
39class Pass;
41class QProgressDialog;
42class QTreeWidgetItem;
43class QtPass;
45class TrayIcon;
46
59class MainWindow : public QMainWindow {
60 Q_OBJECT
61
62public:
68 explicit MainWindow(const QString &searchText = QString(),
69 QWidget *parent = nullptr);
74 ~MainWindow() override;
75
79 void restoreWindow();
80
90 auto config() -> bool;
91
96 void setUiElementsEnabled(bool state);
97
104 void flashText(const QString &text, const bool isError,
105 const bool isHtml = false);
106
111 auto getCurrentTreeViewIndex() -> QModelIndex;
112
122 auto initSucceeded() const -> bool { return m_initSucceeded; }
123
124protected:
129 void closeEvent(QCloseEvent *event) override;
134 void keyPressEvent(QKeyEvent *event) override;
139 void changeEvent(QEvent *event) override;
147 auto event(QEvent *event) -> bool override;
153 void showEvent(QShowEvent *event) override;
160 auto eventFilter(QObject *obj, QEvent *event) -> bool override;
161
162public slots:
166 void deselect();
167
172 void messageAvailable(const QString &message);
173
181 void onProcessOutput(const QString &output, bool isError,
183
189 void critical(const QString &title, const QString &msg);
190
195
201 void showStatusMessage(const QString &msg, int timeout = 2000);
202
212 void passShowHandler(const QString &output, const QString &file = QString());
213
220 void otpFromFileToClipboard(const QString &output, const QString &file);
221
229 void passwordFromFileToClipboard(const QString &text, const QString &file);
230
238 void cancelOtpRequest();
248 void onOperationError();
249
255
260 void onGrepFinished(const QList<QPair<QString, QStringList>> &results);
261
265 void onPush();
266
271 void on_treeView_clicked(const QModelIndex &index);
272
280 void startReencryptPath();
281
287 void reencryptProgress(int current, int total);
288
292 void endReencryptPath();
293
294private slots:
299 void updateProfileBox();
312 void on_grepButton_toggled(bool checked);
321 void on_grepResultsList_itemClicked(QTreeWidgetItem *item, int column);
324 void addPassword();
330 void addFolder();
333 void onEdit();
340 void onDelete();
346 void onOtp();
352 void onUpdate(bool block = false);
357 void onUsers();
359 void onConfig();
363 void showAbout();
369 void on_treeView_doubleClicked(const QModelIndex &index);
376 void clearPanel(bool notify = true);
382 void on_lineEdit_textChanged(const QString &arg1);
396 void on_profileBox_currentTextChanged(const QString &name);
403 void showContextMenu(const QPoint &pos);
411 void addShareMenu(QMenu &contextMenu, const AppSettings &s);
419 auto confirmDeletion(const QString &file, bool isDir) -> bool;
426 auto confirmLinkRemoval(const QString &file) -> bool;
432 void showBrowserContextMenu(const QPoint &pos);
435 void openFolder();
440 void renameFolder();
447 void editPassword(const QString &file);
453 void renamePassword();
460 void focusInput();
472 void onTimeoutSearch();
473
474private:
481 QScopedPointer<Ui::MainWindow> ui;
498 bool m_themeSwitched = false;
503 QString m_shownFile;
520 StoreTree *m_tree = nullptr;
531 static constexpr int UiWatchdogMs = 30000;
534 QPointer<QProgressDialog> m_reencryptProgress;
539 bool m_reencryptRunning = false;
542 bool m_uiEnabled = true;
550 bool m_initSucceeded = false;
553 bool m_freshStart = true;
554
557 void initToolBarButtons();
559 void initStatusBar();
562 void connectBackends();
564 void initTextBrowser();
566 void initDisplayPanel();
569 void initTimers();
572 void initProcessOutput();
579 void connectPassSignals(Pass *pass);
580
582 void selectFirstFile();
588 auto firstFile(QModelIndex parentIndex) -> QModelIndex;
596 auto getFile(const QModelIndex &index, bool forPass) -> QString;
604 void setPassword(const QString &file, bool isNew = true);
612 auto confirmPathInStore(const QString &candidate) -> bool;
613
618 void initTrayIcon();
620 void destroyTrayIcon();
627 void reencryptPath(const QString &dir);
633 void exportPublicKey();
639 void addRecipient(const QString &dir);
647 auto refuseLinkedFolder(const QString &dir) -> bool;
649 void showShareHelp();
650
659 void saveWindowState();
660
666 void updateGitButtonVisibility(bool uiEnabled = true);
672 void updateOtpButtonVisibility(bool uiEnabled = true);
680 void enableGitButtons(const bool &state);
681
685};
686
687#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:483
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.
bool m_uiEnabled
Definition mainwindow.h:542
void renameFolder()
Context menu "Rename folder": ask for a new name and Move the current folder, refusing a target outsi...
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.
void onConfig()
Toolbar "Config": config(), ignoring its result.
void saveWindowState()
void initToolBarButtons()
void endReencryptPath()
Finish a re-encryption pass on the current path.
QTimer m_uiWatchdog
Definition mainwindow.h:529
void onGrepFinished(const QList< QPair< QString, QStringList > > &results)
Handle results from a completed grep search.
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...
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:488
QTimer searchTimer
Definition mainwindow.h:523
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:534
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()
ProcessOutputPanel * m_processOutput
Definition mainwindow.h:518
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:520
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:553
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.
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:498
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:511
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:523
void selectFirstFile()
Make the first entry (depth first) under the store root current.
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...
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 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 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.
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:493
void onEdit()
Toolbar "Edit" or a double-click: editPassword() on the current entry.
void restoreWindow()
Restore window geometry and state from saved settings.
QString m_otpRequestFile
Definition mainwindow.h:507
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:481
auto eventFilter(QObject *obj, QEvent *event) -> bool override
Filter events from watched objects.
void showAbout()
Show the About box: version, project link, licence.
static constexpr int UiWatchdogMs
Interval of m_uiWatchdog in milliseconds.
Definition mainwindow.h:531
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...
QString m_shownFile
Definition mainwindow.h:503
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:122
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:550
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:546
QtPass * m_qtPass
The UI-neutral glue to the backends (output, status, clipboard, QR codes); created in the constructor...
Definition mainwindow.h:479
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,...
bool m_reencryptRunning
Definition mainwindow.h:539
Abstract base class for password store operations.
Definition pass.h:75
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:28
The password store as shown in the tree: the QFileSystemModel, the StoreModel proxy on top of it and ...
Definition storetree.h:33
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