QtPass Developer documentation
QtPass test coverage
Current view: top level - src/mainwindow.h Coverage Total Hit
Test: QtPass Lines: 100.0 % 1 1
Test Date: 2026-12-03 23:34:20 Functions: - 0 0

            Line data    Source code
       1              : // SPDX-FileCopyrightText: 2014 Anne Jan Brouwer
       2              : // SPDX-License-Identifier: GPL-3.0-or-later
       3              : /**
       4              :  * @file
       5              :  * @brief MainWindow: the main application window (tree, toolbar, search,
       6              :  *        status bar, process output dock) and the glue between the password
       7              :  *        store backends and the widgets.
       8              :  */
       9              : #ifndef SRC_MAINWINDOW_H_
      10              : #define SRC_MAINWINDOW_H_
      11              : 
      12              : #include "appsettings.h"
      13              : #include "enums.h"
      14              : #include "grepsearchcontroller.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__
      24              : /**
      25              :  * @brief Qt-internal switch, declared here because Qt does not export it in
      26              :  *        a header: enables the automatic `&` mnemonics in menu titles that
      27              :  *        are off by default on macOS. Called once in the constructor.
      28              :  * @param b true to enable auto-mnemonics.
      29              :  * @see https://doc.qt.io/qt-6/qkeysequence.html#qt_set_sequence_auto_mnemonic
      30              :  */
      31              : void qt_set_sequence_auto_mnemonic(bool b);
      32              : #endif
      33              : 
      34              : namespace Ui {
      35              : class MainWindow;
      36              : } // namespace Ui
      37              : 
      38              : class Pass;
      39              : class ProcessOutputPanel;
      40              : class QPushButton;
      41              : class QProgressDialog;
      42              : class QTreeWidgetItem;
      43              : class QtPass;
      44              : class PasswordDisplayPanel;
      45              : class TrayIcon;
      46              : 
      47              : /**
      48              :  * @class MainWindow
      49              :  * @ingroup ui
      50              :  * @brief Main application window orchestrating UI, user interactions, and
      51              :  * external process handlers.
      52              :  *
      53              :  * Provides the central interface for managing items, folders, passwords, and
      54              :  * OTPs; coordinates UI components (toolbars, panels, dialogs, status/tray),
      55              :  * selection and navigation in the underlying file/store models, and lifecycle
      56              :  * interactions with external handlers (e.g., pass, Git, GPG key generation,
      57              :  * OTP).
      58              :  */
      59              : class MainWindow : public QMainWindow {
      60         1100 :   Q_OBJECT
      61              :   /// Drives exportPublicKey(), which only a context menu reaches.
      62              :   friend class tst_mainwindow;
      63              : 
      64              : public:
      65              :   /**
      66              :    * @brief Construct the main window.
      67              :    * @param searchText Initial search text to populate the search field.
      68              :    * @param parent Optional parent widget.
      69              :    */
      70              :   explicit MainWindow(const QString &searchText = QString(),
      71              :                       QWidget *parent = nullptr);
      72              :   /**
      73              :    * @brief Save the window state (a quit from the tray menu or a SIGTERM
      74              :    *        never delivers closeEvent()) and delete the QtPass glue.
      75              :    */
      76              :   ~MainWindow() override;
      77              : 
      78              :   /**
      79              :    * @brief Restore window geometry and state from saved settings.
      80              :    */
      81              :   void restoreWindow();
      82              : 
      83              :   /**
      84              :    * @brief Open the configuration dialog.
      85              :    *
      86              :    * On a fresh start the first-run wizard runs before the dialog is shown.
      87              :    * Accepting the dialog does not guarantee a usable configuration: the OK
      88              :    * button is not gated on Util::configIsValid(), so QtPass::init() uses the
      89              :    * return value to decide whether to ask again or to give up.
      90              :    * @return true when the dialog was accepted, false when it was cancelled.
      91              :    */
      92              :   auto config() -> bool;
      93              : 
      94              :   /**
      95              :    * @brief Enable or disable the main UI elements.
      96              :    * @param state true to enable, false to disable.
      97              :    */
      98              :   void setUiElementsEnabled(bool state);
      99              : 
     100              :   /**
     101              :    * @brief Display a transient message in the text panel.
     102              :    *
     103              :    * HTML is appended to what the panel shows (command output, one message
     104              :    * after another). What was shown before is then trimmed from the front,
     105              :    * at a paragraph, until the panel holds at most kMaxFlashCharacters, so a
     106              :    * long session of Git and gpg output cannot grow it, and the re-parse
     107              :    * each message costs, without bound (scan ANT-2026-VQGRD45V). The new
     108              :    * message is never cut: an entry shown this way stays whole.
     109              :    * @param text Message text to display.
     110              :    * @param isError true to style the message as an error.
     111              :    * @param isHtml true if text contains HTML markup.
     112              :    */
     113              :   void flashText(const QString &text, const bool isError,
     114              :                  const bool isHtml = false);
     115              :   /** @brief Most characters the text panel keeps of appended output. */
     116              :   static constexpr int kMaxFlashCharacters = 64 * 1024;
     117              : 
     118              :   /**
     119              :    * @brief Return the currently selected index in the tree view.
     120              :    * @return Current QModelIndex.
     121              :    */
     122              :   auto getCurrentTreeViewIndex() -> QModelIndex;
     123              : 
     124              :   /**
     125              :    * @brief Return whether startup configuration succeeded.
     126              :    *
     127              :    * Reflects the result of the initial configuration check performed in the
     128              :    * constructor (QtPass::init()). When it is false the application cannot be
     129              :    * used (e.g. the user cancelled the first-run wizard), and main() should
     130              :    * exit before ever showing the window.
     131              :    * @return true when QtPass::init() reported a working configuration.
     132              :    */
     133              :   auto initSucceeded() const -> bool { return m_initSucceeded; }
     134              : 
     135              : protected:
     136              :   /**
     137              :    * @brief Save window state and geometry on close.
     138              :    * @param event The close event.
     139              :    */
     140              :   void closeEvent(QCloseEvent *event) override;
     141              :   /**
     142              :    * @brief Handle keyboard shortcuts.
     143              :    * @param event The key press event.
     144              :    */
     145              :   void keyPressEvent(QKeyEvent *event) override;
     146              :   /**
     147              :    * @brief React to language or window state changes.
     148              :    * @param event The change event.
     149              :    */
     150              :   void changeEvent(QEvent *event) override;
     151              :   /**
     152              :    * @brief Notice an application palette change, the theme switch that
     153              :    *        makes a style-imposed bar palette suspect; see
     154              :    *        dropStaleToolsAreaPalettes().
     155              :    * @param event The event.
     156              :    * @return true if the event was consumed.
     157              :    */
     158              :   auto event(QEvent *event) -> bool override;
     159              :   /**
     160              :    * @brief First-show hook used to focus the search input once the window
     161              :    *        is actually mapped (avoids races with timers fired before show).
     162              :    * @param event The show event.
     163              :    */
     164              :   void showEvent(QShowEvent *event) override;
     165              :   /**
     166              :    * @brief Filter events from watched objects.
     167              :    * @param obj The object that received the event.
     168              :    * @param event The event to filter.
     169              :    * @return true if the event was consumed.
     170              :    */
     171              :   auto eventFilter(QObject *obj, QEvent *event) -> bool override;
     172              : 
     173              : public slots:
     174              :   /**
     175              :    * @brief Clear the current tree view selection.
     176              :    */
     177              :   void deselect();
     178              : 
     179              :   /**
     180              :    * @brief Handle an incoming inter-process message (single-instance mode).
     181              :    * @param message Message string received from another instance.
     182              :    */
     183              :   void messageAvailable(const QString &message);
     184              : 
     185              :   /**
     186              :    * @brief Handle generic process output for display in output panel.
     187              :    * @param output Process output text.
     188              :    * @param isError true if output should be styled as error (red).
     189              :    * @param pid Identifier of the originating subprocess (for the label
     190              :    *            prefix); defaults to Enums::INVALID for unlabelled output.
     191              :    */
     192              :   void onProcessOutput(const QString &output, bool isError,
     193              :                        Enums::PROCESS pid = Enums::INVALID);
     194              : 
     195              :   /**
     196              :    * @brief Display a critical error dialog.
     197              :    * @param title Dialog title.
     198              :    * @param msg Error message body.
     199              :    */
     200              :   void critical(const QString &title, const QString &msg);
     201              : 
     202              :   /**
     203              :    * @brief Slot called when an external process wrapper has started.
     204              :    */
     205              :   void executeWrapperStarted();
     206              : 
     207              :   /**
     208              :    * @brief Show a message in the status bar for the given duration.
     209              :    * @param msg Message to display.
     210              :    * @param timeout Duration in milliseconds (default 2000).
     211              :    */
     212              :   void showStatusMessage(const QString &msg, int timeout = 2000);
     213              : 
     214              :   /**
     215              :    * @brief Render a decrypted entry: fields into the display panel, the rest
     216              :    *        into the text browser, and the password onto the clipboard when
     217              :    *        "Always copy" is set. Decrypts of any entry but the one the panel
     218              :    *        last asked to show (m_shownFile) are dropped.
     219              :    * @param output Decrypted password file content.
     220              :    * @param file Entry the content belongs to; empty for legacy callers that
     221              :    *        do not name it, which always repaints.
     222              :    */
     223              :   void passShowHandler(const QString &output, const QString &file = QString());
     224              : 
     225              :   /**
     226              :    * @brief Generate a one-time password from decrypted content and copy it.
     227              :    *        Ignores decrypts of anything but the entry onOtp() asked for.
     228              :    * @param output Decrypted entry content.
     229              :    * @param file Entry the content belongs to.
     230              :    */
     231              :   void otpFromFileToClipboard(const QString &output, const QString &file);
     232              : 
     233              :   /**
     234              :    * @brief Copy the first line of a decrypted entry (Ctrl+C). Ignores
     235              :    *        decrypts of anything but the entry copyPasswordFromTreeview()
     236              :    *        asked for; an otpauth:// first line is refused.
     237              :    * @param text Decrypted entry content.
     238              :    * @param file Entry the content belongs to.
     239              :    */
     240              :   void passwordFromFileToClipboard(const QString &text, const QString &file);
     241              : 
     242              :   /**
     243              :    * @brief Forget the pending OTP and copy requests.
     244              :    *
     245              :    * A failed decrypt never emits Pass::finishedShow; without this a later
     246              :    * decrypt of the same entry (the user retrying) would be taken as the
     247              :    * answer to a request the user has long given up on.
     248              :    */
     249              :   void cancelOtpRequest();
     250              :   /**
     251              :    * @brief An operation ended in an error before or instead of a result:
     252              :    * forget the pending requests and what the panel was about to show.
     253              :    *
     254              :    * Connected to Pass::processErrorExit. A Show that never ran (a linked
     255              :    * entry refused at the store boundary) leaves the previous entry's fields
     256              :    * on the panel under the new name otherwise, and onOtp()'s fast path would
     257              :    * take that entry's code for the refused one.
     258              :    */
     259              :   void onOperationError();
     260              : 
     261              :   /**
     262              :    * @brief Drop a style-imposed menu bar or toolbar palette that belongs to
     263              :    * the other theme (Breeze header palette after a light/dark switch).
     264              :    */
     265              :   void dropStaleToolsAreaPalettes();
     266              : 
     267              :   /**
     268              :    * @brief Hand the display panel what a template marks secret, in the
     269              :    * settings or the store's .templates, when "Hide password" is on. Read
     270              :    * each time, so an edit there counts at once.
     271              :    * @param s The settings in use.
     272              :    */
     273              :   void refreshMarkedSecrets(const AppSettings &s);
     274              : 
     275              :   /**
     276              :    * @brief Handle results from a completed grep search.
     277              :    * @param results List of file/match pairs from the grep operation.
     278              :    */
     279              :   void onGrepFinished(const QList<QPair<QString, QStringList>> &results);
     280              : 
     281              :   /**
     282              :    * @brief Trigger a git push operation.
     283              :    */
     284              :   void onPush();
     285              :   /**
     286              :    * @brief Trigger the automatic git push after a change
     287              :    *        (QtPass::pushRequested()); see Pass::GitPushAutomatic().
     288              :    */
     289              :   void onAutoPush();
     290              : 
     291              :   /**
     292              :    * @brief Handle a click on an item in the tree view.
     293              :    * @param index The model index that was clicked.
     294              :    */
     295              :   void on_treeView_clicked(const QModelIndex &index);
     296              : 
     297              :   /**
     298              :    * @brief Begin a re-encryption pass on the current path.
     299              :    *
     300              :    * Disables the UI, shows a cancellable progress dialog and keeps both in
     301              :    * place until endReencryptPath(): while the worker runs, unrelated
     302              :    * completions must not re-enable the interface (see setUiElementsEnabled).
     303              :    */
     304              :   void startReencryptPath();
     305              : 
     306              :   /**
     307              :    * @brief Update the re-encryption progress dialog.
     308              :    * @param current Files checked so far.
     309              :    * @param total Files found under the re-encrypted folder.
     310              :    */
     311              :   void reencryptProgress(int current, int total);
     312              : 
     313              :   /**
     314              :    * @brief Finish a re-encryption pass on the current path.
     315              :    */
     316              :   void endReencryptPath();
     317              : 
     318              :   /**
     319              :    * @brief Ask whether entries a re-encryption left alone, being encrypted
     320              :    * to other keys than their folder had, are to be re-encrypted after all
     321              :    * (ImitatePass::unexpectedRecipients()). They may have been copied in
     322              :    * from a folder this folder's recipients cannot read.
     323              :    * @param dir The folder of the run.
     324              :    * @param files The entries, absolute.
     325              :    * @param details For each, who would gain it.
     326              :    */
     327              :   void askReencryptUnexpected(const QString &dir, const QStringList &files,
     328              :                               const QStringList &details);
     329              : 
     330              : private slots:
     331              :   /**
     332              :    * @brief Fill the profile box from the settings, the active profile
     333              :    * selected, without switching profiles while doing so.
     334              :    */
     335              :   void updateProfileBox();
     336              :   /**
     337              :    * @brief Enable the profile box only when there is more than one profile,
     338              :    * the interface is enabled and the backend is idle.
     339              :    */
     340              :   void updateProfileBoxEnabled();
     341              :   /**
     342              :    * @brief The content-search toggle changed: switch the search box between
     343              :    *        name filtering and regex content search, clearing the query, the
     344              :    *        tree filter and any results; leaving while a search runs cancels
     345              :    *        it.
     346              :    * @param checked true when content search was switched on.
     347              :    */
     348              :   void on_grepButton_toggled(bool checked);
     349              :   /**
     350              :    * @brief A content-search result was clicked: select the entry in the
     351              :    *        tree, show it, and go back to the tree (clearing the results when
     352              :    *        content is hidden or the panel autoclears).
     353              :    * @param item The clicked entry or match line; its UserRole holds the
     354              :    *        entry name.
     355              :    * @param column Unused.
     356              :    */
     357              :   void on_grepResultsList_itemClicked(QTreeWidgetItem *item, int column);
     358              :   /** @brief Toolbar/context-menu "Add password": open PasswordDialog for a
     359              :    *         new entry in the current folder. */
     360              :   void addPassword();
     361              :   /**
     362              :    * @brief Toolbar/context-menu "Add folder": ask for a name, create the
     363              :    *        folder under the current one (refusing paths that escape the
     364              :    *        store) and seed its `.gpg-id` from the parent when configured.
     365              :    */
     366              :   void addFolder();
     367              :   /** @brief Toolbar "Edit" or a double-click: editPassword() on the current
     368              :    *         entry. */
     369              :   void onEdit();
     370              :   /**
     371              :    * @brief Toolbar "Delete" or the Delete key: confirm, then remove the
     372              :    *        current entry or folder. Nothing selected is a no-op (#556); a
     373              :    *        linked folder only loses its link, a folder behind a link is
     374              :    *        refused.
     375              :    */
     376              :   void onDelete();
     377              :   /**
     378              :    * @brief Toolbar "OTP": copy the current entry's one-time code. Uses the
     379              :    *        code the panel already shows for this entry; otherwise decrypts
     380              :    *        once and lets otpFromFileToClipboard() finish.
     381              :    */
     382              :   void onOtp();
     383              :   /**
     384              :    * @brief Toolbar "Update": git pull.
     385              :    * @param block true to pull synchronously (before opening an edit dialog
     386              :    *        with auto-pull on).
     387              :    */
     388              :   void onUpdate(bool block = false);
     389              :   /**
     390              :    * @brief Toolbar/context-menu "Users": open UsersDialog for the current
     391              :    *        folder, unless it lies behind a link.
     392              :    */
     393              :   void onUsers();
     394              :   /**
     395              :    * @brief Toolbar "Config": config(), ignoring its result; refused while
     396              :    *        a backend still runs or waits, as a profile switch is.
     397              :    */
     398              :   void onConfig();
     399              :   /**
     400              :    * @brief Show the About box: version, project link, licence.
     401              :    */
     402              :   void showAbout();
     403              :   /**
     404              :    * @brief A double-click on a tree entry opens it for editing; folders are
     405              :    *        left to the view.
     406              :    * @param index The double-clicked proxy index.
     407              :    */
     408              :   void on_treeView_doubleClicked(const QModelIndex &index);
     409              :   /**
     410              :    * @brief Empty the display panel and the text browser, and leave content
     411              :    *        search if its results were showing.
     412              :    * @param notify true to show "Password and content hidden" in the browser,
     413              :    *        false to leave it blank.
     414              :    */
     415              :   void clearPanel(bool notify = true);
     416              :   /**
     417              :    * @brief Empty the display panel and the text browser and close the QR
     418              :    *        code: the shown entry only. Runs on clearPanelTimer.
     419              :    * @param notify true to show "Password and content hidden" in the browser,
     420              :    *        false to leave it blank.
     421              :    */
     422              :   void clearShownEntry(bool notify);
     423              :   /**
     424              :    * @brief Empty the content search results and, if they were showing, put
     425              :    *        the tree back and leave content search. Runs on clearResultsTimer.
     426              :    */
     427              :   void clearContentResults();
     428              :   /**
     429              :    * @brief The search box changed (name filtering only): drop the pending
     430              :    *        decrypt and the panel, expand the tree and restart searchTimer.
     431              :    * @param arg1 The new text.
     432              :    */
     433              :   void on_lineEdit_textChanged(const QString &arg1);
     434              :   /**
     435              :    * @brief Enter in the search box: in content-search mode start (or, for an
     436              :    *        empty query, cancel) the grep; otherwise select and show the first
     437              :    *        matching entry.
     438              :    */
     439              :   void on_lineEdit_returnPressed();
     440              :   /**
     441              :    * @brief The user picked another profile: save its store, key and Git
     442              :    *        flags as the active settings, re-root the tree and clear the
     443              :    *        selection. Ignored during the fresh start and reverted while an
     444              :    *        operation runs.
     445              :    * @param name The chosen profile name.
     446              :    */
     447              :   void on_profileBox_currentTextChanged(const QString &name);
     448              :   /**
     449              :    * @brief Build and show the tree's context menu for the item under the
     450              :    *        cursor: folder actions (open, add, users, rename, Share) or entry
     451              :    *        actions (edit, rename), plus Delete.
     452              :    * @param pos Viewport position of the right-click.
     453              :    */
     454              :   void showContextMenu(const QPoint &pos);
     455              :   /**
     456              :    * @brief Make the entry a tree menu was opened on current again, for the
     457              :    *        action picked from it: the current index may have moved on while
     458              :    *        the menu was open.
     459              :    * @param openedOn Absolute path of that entry; empty for a menu opened
     460              :    *        beside the entries.
     461              :    * @return false when the entry is gone or no longer listed: the action
     462              :    *         must not run, and the status bar says why.
     463              :    */
     464              :   auto backOnMenuEntry(const QString &openedOn) -> bool;
     465              :   /**
     466              :    * @brief Add the Share submenu for the folder under the cursor: the
     467              :    * entries are enabled only where a recipient list and a usable gpg or
     468              :    * pass make them work.
     469              :    * @param contextMenu The menu being built, which owns the submenu.
     470              :    * @param s The settings the executables and the store come from.
     471              :    */
     472              :   void addShareMenu(QMenu &contextMenu, const AppSettings &s);
     473              :   /**
     474              :    * @brief Ask before deleting an entry or a folder, naming what goes and
     475              :    * warning when the folder holds anything but entries.
     476              :    * @param file Store-relative path being deleted.
     477              :    * @param isDir Whether it is a folder.
     478              :    * @return Whether the user said yes.
     479              :    */
     480              :   auto confirmDeletion(const QString &file, bool isDir) -> bool;
     481              :   /**
     482              :    * @brief Ask before removing a folder that is a link, which takes the link
     483              :    * and leaves what it points to.
     484              :    * @param file Store-relative path of the link.
     485              :    * @return Whether the user said yes.
     486              :    */
     487              :   auto confirmLinkRemoval(const QString &file) -> bool;
     488              :   /**
     489              :    * @brief Show the text browser's standard context menu, reparented to the
     490              :    *        window so the browser's stylesheet does not bleed into it.
     491              :    * @param pos Viewport position of the right-click.
     492              :    */
     493              :   void showBrowserContextMenu(const QPoint &pos);
     494              :   /**
     495              :    * @brief The text browser's standard context menu, with "Copy Link
     496              :    *        Location" copying through ClipboardManager.
     497              :    *
     498              :    * Qt's own action puts the link on the clipboard as bare text, without
     499              :    * the secret hint, the autoclear, or a copied() report; the link can be
     500              :    * the entry's URL with a token in it.
     501              :    * @param pos Viewport position of the right-click.
     502              :    * @return A new menu, parented to the window; the caller deletes it.
     503              :    */
     504              :   auto browserContextMenu(const QPoint &pos) -> QMenu *;
     505              :   /** @brief Context menu "Open folder with file manager" on the current
     506              :    *         folder. */
     507              :   void openFolder();
     508              :   /**
     509              :    * @brief Context menu "Rename folder": ask for a new name and Move the
     510              :    *        current folder, refusing a target outside the store.
     511              :    */
     512              :   void renameFolder();
     513              :   /**
     514              :    * @brief Open PasswordDialog on an existing entry, after a blocking pull
     515              :    *        when auto-pull is on. Releases the panel's claim on the next
     516              :    *        decrypt so the dialog's own Show does not repaint or copy.
     517              :    * @param file Store-relative entry name; empty is a no-op.
     518              :    */
     519              :   void editPassword(const QString &file);
     520              :   /**
     521              :    * @brief Context menu "Rename password": ask for a new name and Move the
     522              :    *        current entry within its folder, refusing a target outside the
     523              :    *        store.
     524              :    */
     525              :   void renamePassword();
     526              :   /**
     527              :    * @brief Select-all and focus the search box once the window is visible;
     528              :    *        sets m_firstShowCompleted only on success so showEvent() retries.
     529              :    *        Looks the widget up by name because setWindowFlags() can rebuild
     530              :    *        it under `ui->lineEdit` (Qt 6.11).
     531              :    */
     532              :   void focusInput();
     533              :   /**
     534              :    * @brief Ctrl+C on the tree: decrypt the current entry and let
     535              :    *        passwordFromFileToClipboard() copy its first line. The newest
     536              :    *        request wins (m_copyRequestFile). Does nothing while content
     537              :    *        search results hide the tree.
     538              :    */
     539              :   void copyPasswordFromTreeview();
     540              :   /**
     541              :    * @brief Ctrl+C anywhere in the window: the selected text when the focus
     542              :    *        is in a text view or a selectable label with a selection (the
     543              :    *        shown entry, its field values, the OTP code, the process output),
     544              :    *        otherwise the password (copyPasswordFromTreeview()).
     545              :    *
     546              :    * The shortcut is window-wide, and read-only text views and labels do not
     547              :    * take Ctrl+C for themselves (line edits, the hidden password included,
     548              :    * do), so a selected login or note was answered with the password.
     549              :    */
     550              :   void copySelectionOrPassword();
     551              :   /**
     552              :    * @brief searchTimer fired: filter the tree on the typed words (matched
     553              :    *        literally, in order, case-insensitively) and select the first
     554              :    *        match; an empty query collapses the tree and deselects.
     555              :    */
     556              :   void onTimeoutSearch();
     557              : 
     558              : private:
     559              :   /**
     560              :    * @brief A content search match as the results list shows it, by the
     561              :    * display panel's rules: a one-time password secret never, the password
     562              :    * and a hidden field (PasswordDisplayPanel::hides()) without their value.
     563              :    * @param line A match from NativeGrep::matchFile().
     564              :    * @param s The settings in use.
     565              :    * @return The text to show.
     566              :    */
     567              :   [[nodiscard]] auto grepLineForDisplay(const QString &line,
     568              :                                         const AppSettings &s) const -> QString;
     569              : 
     570              :   /**
     571              :    * @brief The UI-neutral glue to the backends (output, status, clipboard,
     572              :    *        QR codes); created in the constructor, deleted in the destructor.
     573              :    */
     574              :   QtPass *m_qtPass;
     575              :   /** @brief The widgets generated from mainwindow.ui. */
     576              :   QScopedPointer<Ui::MainWindow> ui;
     577              :   /** @brief Mode/busy/cancelled state of the content search. */
     578              :   GrepSearchController m_grep;
     579              :   /**
     580              :    * @brief Renders decrypted fields into the grid; created in
     581              :    *        initDisplayPanel(), parented to this window.
     582              :    */
     583              :   PasswordDisplayPanel *m_displayPanel = nullptr;
     584              :   /**
     585              :    * @brief Set once focusInput() has actually focused the search box, so
     586              :    *        later show events leave the focus alone.
     587              :    */
     588              :   bool m_firstShowCompleted = false;
     589              :   /// Whether the application palette changed in this window's lifetime. A
     590              :   /// header palette a style stamps on the bars is only suspect after that:
     591              :   /// at startup the style's colours are fresh, however far from the window
     592              :   /// colour a scheme puts its header.
     593              :   bool m_themeSwitched = false;
     594              :   /// Entry the display panel is currently rendering. The tree's currentIndex
     595              :   /// can move without a repaint (arrow keys and right-click do not emit
     596              :   /// QTreeView::clicked), so onOtp() must not assume the visible code belongs
     597              :   /// to the selected entry.
     598              :   QString m_shownFile;
     599              :   /// Entry whose fields the display panel's rows show; empty while the panel
     600              :   /// is empty. Unlike m_shownFile it is not dropped when Edit opens, and only
     601              :   /// a rendered entry sets it, so a double-click on a row edits that entry.
     602              :   QString m_panelEntry;
     603              :   /// Entry a save's refresh will show once the push queued with it is done;
     604              :   /// empty when none waits. Started behind the push, the refresh would empty
     605              :   /// the browser before a failed push's error was painted.
     606              :   QString m_refreshAfterPush;
     607              :   /// The backend whose push m_refreshAfterPush waits for: only its pushes
     608              :   /// end the wait, and the refresh runs on it.
     609              :   QPointer<Pass> m_refreshAfterPushOwner;
     610              :   /// Entry the in-flight OTP request asked for; empty when none. finishedShow
     611              :   /// names its file, so otpFromFileToClipboard() simply ignores everything
     612              :   /// else and passShowHandler() skips the password copy for this one.
     613              :   QString m_otpRequestFile;
     614              :   /// Entry the in-flight Ctrl+C request asked for; empty when none. Each
     615              :   /// finishedShow is matched to it by file, so a second Ctrl+C on another
     616              :   /// entry just replaces the request instead of racing it.
     617              :   QString m_copyRequestFile;
     618              :   /// The process output console, a QDockWidget at the bottom dock area
     619              :   /// created in initProcessOutput(). It isn't part of the .ui because uic
     620              :   /// places its QMainWindow children in centralWidget / statusBar / menuBar /
     621              :   /// toolBars / dock-widget slots only — a sibling widget at the QMainWindow
     622              :   /// level isn't laid out and ends up obscuring the centralWidget. See #1192
     623              :   /// for the symptom.
     624              :   ProcessOutputPanel *m_processOutput = nullptr;
     625              :   /// The store as shown in the tree: models, view setup, path mapping.
     626              :   StoreTree *m_tree = nullptr;
     627              :   /// Single-shot timer that runs clearShownEntry() "Autoclear panel" seconds
     628              :   /// after an entry was shown.
     629              :   QTimer clearPanelTimer, searchTimer; ///< searchTimer: single-shot 350 ms
     630              :                                        ///< debounce between typing in the
     631              :                                        ///< search box and onTimeoutSearch().
     632              :   /// Single-shot timer that runs clearContentResults() "Autoclear panel"
     633              :   /// seconds after content search results were listed. Their own deadline:
     634              :   /// an operation that starts or an entry shown meanwhile does not move it.
     635              :   QTimer clearResultsTimer;
     636              :   /// Re-enables the UI if a backend operation disables it but never reports
     637              :   /// completion (see setUiElementsEnabled); armed whenever the UI is
     638              :   /// disabled, stopped when it is enabled again.
     639              :   QTimer m_uiWatchdog;
     640              :   /// Shown in the status bar once the watchdog fired while a run still
     641              :   /// goes: stops it (Pass::stopRunning()).
     642              :   QPushButton *m_stopButton = nullptr;
     643              :   /// Interval of m_uiWatchdog in milliseconds.
     644              :   static constexpr int UiWatchdogMs = 30000;
     645              :   /// Progress/cancel dialog shown between startReencryptPath() and
     646              :   /// endReencryptPath(); QPointer so a closed dialog reads back as null.
     647              :   QPointer<QProgressDialog> m_reencryptProgress;
     648              :   /// True while reencryptProgress() is inside the dialog's setValue(), which
     649              :   /// runs processEvents() on a modal dialog: endReencryptPath() then only
     650              :   /// hides the dialog and leaves the delete to reencryptProgress(). A
     651              :   /// nested event loop (the worker's error box) would otherwise delete it
     652              :   /// with setValue() still on the stack.
     653              :   bool m_inProgressUpdate = false;
     654              :   /// Set by endReencryptPath() during m_inProgressUpdate: the dialog to
     655              :   /// delete once setValue() has returned.
     656              :   QPointer<QProgressDialog> m_progressToDelete;
     657              :   /// The open applySearchText() waits to make until the tree has loaded the
     658              :   /// entry; QPointer so an ended or cancelled wait reads back as null.
     659              :   QPointer<QObject> m_pendingOpen;
     660              :   /// True between startReencryptPath() and endReencryptPath(). While set,
     661              :   /// setUiElementsEnabled(true) is ignored so the git completions queued by
     662              :   /// Init/Move/Copy (or the UI watchdog) cannot re-enable the interface
     663              :   /// while the re-encryption worker is still rewriting files.
     664              :   bool m_reencryptRunning = false;
     665              :   /// What setUiElementsEnabled() last set: updateProfileBox() keeps the
     666              :   /// profile box disabled while an operation runs.
     667              :   bool m_uiEnabled = true;
     668              :   /// The system tray icon; null until initTrayIcon() creates it when the
     669              :   /// setting is on, deleted again by destroyTrayIcon() when it is turned off
     670              :   /// or no tray is available.
     671              :   TrayIcon *m_tray{};
     672              :   /// Whether the constructor ended with a usable configuration; main()
     673              :   /// consults it via initSucceeded() to decide whether the application should
     674              :   /// start at all.
     675              :   bool m_initSucceeded = false;
     676              :   /// No usable configuration has been accepted yet: config() runs the
     677              :   /// first-run wizard and defaults to pass when it is installed.
     678              :   bool m_freshStart = true;
     679              : 
     680              :   /// Wire the toolbar and menu actions to their slots, set their icons, and
     681              :   /// set up the "Show menu bar" toggle with its MenuBarPeek (not on macOS).
     682              :   void initToolBarButtons();
     683              :   /// Welcome message and the permanent logo in the status bar.
     684              :   void initStatusBar();
     685              :   /// Connect QtPass's and both backends' signals (the active backend can
     686              :   /// change through the configuration dialog without a restart).
     687              :   void connectBackends();
     688              :   /// Font, wrapping and link handling of the text browser, per the settings.
     689              :   void initTextBrowser();
     690              :   /// The grid of decrypted fields and what its buttons ask for.
     691              :   void initDisplayPanel();
     692              :   /// The panel-clear and search timers, and the watchdog that re-enables
     693              :   /// the UI when an operation never signals its end.
     694              :   void initTimers();
     695              :   /// The Process Output dock, its Settings-menu toggle, and the feed of
     696              :   /// non-secret process output into it.
     697              :   void initProcessOutput();
     698              :   /**
     699              :    * @brief Connect the signals of one backend that the window answers
     700              :    *        itself: errors, critical messages, wrapper start, idle, status,
     701              :    *        finishedShow (panel, OTP and Ctrl+C handlers) and finishedGrep.
     702              :    * @param pass The backend; both are connected, see connectBackends().
     703              :    */
     704              :   void connectPassSignals(Pass *pass);
     705              : 
     706              :   /// Make the entry named exactly as searched current, or else the first
     707              :   /// entry (depth first) under the store root.
     708              :   void selectFirstFile();
     709              : 
     710              :   /**
     711              :    * @brief Show the content search results in place of the tree, or the tree
     712              :    *        again.
     713              :    * @param shown True to show the results. Delete, Edit and OTP are off while
     714              :    *        they hide the tree; showing the tree enables them again only for
     715              :    *        a selected entry.
     716              :    */
     717              :   void showContentResults(bool shown);
     718              : 
     719              :   /// Stop a running content search on both backends (the active one may have
     720              :   /// changed since it started). It runs outside the process queue, so only
     721              :   /// this ends its walk and the gpg it is running; the result it still
     722              :   /// delivers is discarded by onGrepFinished().
     723              :   void cancelContentSearch();
     724              :   /**
     725              :    * @brief The entry whose name is exactly the search text, if the filtered
     726              :    * tree shows it: `team/bank` for "team/bank", not a folder of that name.
     727              :    * @return Its proxy index, or invalid when no entry is named so.
     728              :    */
     729              :   auto exactMatch() -> QModelIndex;
     730              :   /**
     731              :    * @brief The entry file named exactly as the search text, spaces around
     732              :    * the text included; failing that, named as the text without them.
     733              :    * @return Its path, or empty when no such file is in the store.
     734              :    */
     735              :   auto exactMatchPath() -> QString;
     736              :   /**
     737              :    * @brief Searches for @p text as qtpass(1) promises for the command line
     738              :    * and for text handed over by another qtpass: the tree is filtered to it
     739              :    * at once, and an entry named exactly so is opened.
     740              :    * @param text The search text.
     741              :    */
     742              :   void applySearchText(const QString &text);
     743              :   /**
     744              :    * @brief Makes @p index current and opens it, as a click on it would.
     745              :    * @param index Proxy index of the entry exactMatch() found.
     746              :    */
     747              :   void openExactMatch(const QModelIndex &index);
     748              :   /**
     749              :    * @brief Depth-first search for the first entry under a folder.
     750              :    * @param parentIndex Proxy index of the folder to search.
     751              :    * @return Proxy index of the first file, or invalid when there is none.
     752              :    */
     753              :   auto firstFile(QModelIndex parentIndex) -> QModelIndex;
     754              :   /**
     755              :    * @brief StoreTree::fileFor() on the tree.
     756              :    * @param index Proxy index.
     757              :    * @param forPass true for the store-relative entry name, false for the
     758              :    *        absolute .gpg path.
     759              :    * @return Entry name or path; empty for a folder or invalid index.
     760              :    */
     761              :   auto getFile(const QModelIndex &index, bool forPass) -> QString;
     762              :   /**
     763              :    * @brief Run PasswordDialog for a new or existing entry. For a new one the
     764              :    *        dialog gets the store's real folders (current one preselected) and
     765              :    *        the `.templates`, if any.
     766              :    * @param file Store-relative entry name; empty when creating.
     767              :    * @param isNew true to create, false to edit @p file.
     768              :    */
     769              :   void setPassword(const QString &file, bool isNew = true);
     770              :   /**
     771              :    * @brief Guard the input dialogs (create, move, rename) against names like
     772              :    *        `../../etc/passwd` or absolute paths escaping the store root; warns
     773              :    *        the user when refusing.
     774              :    * @param candidate Path the user asked for.
     775              :    * @return true when it resolves inside the store.
     776              :    */
     777              :   auto confirmPathInStore(const QString &candidate) -> bool;
     778              : 
     779              :   /**
     780              :    * @brief Create m_tray and add the menu bar toggle to its menu; gives up
     781              :    *        (m_tray stays null) when no system tray is available.
     782              :    */
     783              :   void initTrayIcon();
     784              :   /// Delete m_tray and reset it to null.
     785              :   void destroyTrayIcon();
     786              :   /**
     787              :    * @brief Share menu "Re-encrypt all passwords": confirm, lock the UI via
     788              :    *        startReencryptPath() and have ImitatePass rewrite every entry
     789              :    *        under @p dir for the recipients in its `.gpg-id`.
     790              :    * @param dir Absolute folder; refused when missing or behind a link.
     791              :    */
     792              :   void reencryptPath(const QString &dir);
     793              :   /**
     794              :    * @brief Share menu "Export my public key": run `gpg --armor --export` for
     795              :    *        the configured signing key and show the result in
     796              :    *        ExportPublicKeyDialog; explains what to do when no key is set.
     797              :    */
     798              :   void exportPublicKey();
     799              :   /**
     800              :    * @brief Share menu "Add recipient": open UsersDialog for @p dir (keys
     801              :    *        already in the keyring only).
     802              :    * @param dir Absolute folder; refused when behind a link.
     803              :    */
     804              :   void addRecipient(const QString &dir);
     805              :   /**
     806              :    * @brief Refuse, with a message, a tree-picked folder that is or lies
     807              :    *        behind a symlink or junction: what it points to is not part of the
     808              :    *        store. The store root itself may be a link.
     809              :    * @param dir Absolute folder path.
     810              :    * @return true when the folder was refused and the caller must stop.
     811              :    */
     812              :   auto refuseLinkedFolder(const QString &dir) -> bool;
     813              :   /// Share menu "What is this?": the explanation of sharing with GPG.
     814              :   void showShareHelp();
     815              : 
     816              :   /// Re-apply the monospace and line-wrapping settings to the text browser
     817              :   /// after the configuration dialog.
     818              :   void applyTextBrowserSettings();
     819              :   /// Toggle Qt::WindowStaysOnTopHint to match the "always on top" setting,
     820              :   /// skipping the native-window rebuild when nothing changes.
     821              :   void applyWindowFlagsSettings();
     822              :   /// Store geometry and dock/toolbar state in the settings; idempotent,
     823              :   /// called from closeEvent() and the destructor.
     824              :   void saveWindowState();
     825              : 
     826              :   /**
     827              :    * @brief Show Push and Pull only when Git is in use; enable them only while
     828              :    *        the interface is.
     829              :    * @param uiEnabled false while an operation runs
     830              :    */
     831              :   void updateGitButtonVisibility(bool uiEnabled = true);
     832              :   /**
     833              :    * @brief Refresh the OTP toolbar action from settings.
     834              :    * @param uiEnabled false while a backend operation is in flight, so the
     835              :    *        action is disabled along with the rest of the UI.
     836              :    */
     837              :   void updateOtpButtonVisibility(bool uiEnabled = true);
     838              :   /// Show the content-search buttons only when the setting is on; turning
     839              :   /// it off while in content-search mode leaves that mode.
     840              :   void updateGrepButtonVisibility();
     841              :   /**
     842              :    * @brief Enable or disable the Push and Pull actions together.
     843              :    * @param state true to enable.
     844              :    */
     845              :   void enableGitButtons(const bool &state);
     846              : 
     847              :   /// Sync the Process Output dock and its menu toggle with the setting
     848              :   /// after the configuration dialog.
     849              :   void updateProcessOutputVisibility();
     850              : };
     851              : 
     852              : #endif // SRC_MAINWINDOW_H_
        

Generated by: LCOV version 2.0-1