QtPass 2.0.0
Developer documentation
Loading...
Searching...
No Matches
ClipboardManager Class Reference

Puts secrets on the system clipboard and takes them off again. More...

#include <clipboardmanager.h>

Inheritance diagram for ClipboardManager:
Collaboration diagram for ClipboardManager:

Public Slots

void copyText (const QString &text)
 Copy text into the system clipboard (or the X11 primary selection when configured) and arm the autoclear timer when enabled.
void trackCopied (const QString &text)
 Track text that got onto the clipboard some other way.
void clear ()
 Remove the tracked text from the clipboard if it is still there. Silent no-op when nothing is tracked.

Signals

void statusMessage (const QString &message)
 Something worth showing in the status bar happened.

Public Member Functions

 ClipboardManager (QObject *parent=nullptr)
 Construct a manager that also clears its text when the application quits.
void setAutoclearTimer ()
 Re-read the autoclear delay from the settings.
void copyIfAlways (const QString &text, const QString &p_output=QString())
 Handle clipboard copying for a shown entry.
auto trackedText () const -> QString
 The text this manager last put on the clipboard and still tracks.

Private Member Functions

void forgetIfSaved (const QString &text)
 Empty a saved previous text equal to text, now copied as a secret, so clear() does not put the secret back.

Private Attributes

QTimer m_clearTimer
 Single-shot autoclear timer; started by copyText() when the autoclear setting is on, and calls clear() when it fires.
QString m_clippedText
 The secret copyText() last put on the clipboard; clear() removes the clipboard content only while it still equals this.
std::optional< QString > m_previousClipboard
std::optional< QString > m_previousSelection
 As m_previousClipboard, for the X11 primary selection.
QStringList m_otherCopies
 trackCopied() texts, cleared with the rest

Detailed Description

Puts secrets on the system clipboard and takes them off again.

Remembers what it copied so the autoclear timer (and the quit handler) only remove that text, never something the user copied in the meantime. Settings (selection vs. clipboard, autoclear on/off, delay) are read from QtPassSettings; call setAutoclearTimer() after they change. Status text for the main window's status bar is emitted, not shown, so this class has no UI dependency and is unit-testable.

Definition at line 47 of file clipboardmanager.h.

Constructor & Destructor Documentation

◆ ClipboardManager()

ClipboardManager::ClipboardManager ( QObject * parent = nullptr)
explicit

Construct a manager that also clears its text when the application quits.

Parameters
parentOwner.

Definition at line 15 of file clipboardmanager.cpp.

Here is the call graph for this function:

Member Function Documentation

◆ clear

void ClipboardManager::clear ( )
slot

Remove the tracked text from the clipboard if it is still there. Silent no-op when nothing is tracked.

Definition at line 137 of file clipboardmanager.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ copyIfAlways()

void ClipboardManager::copyIfAlways ( const QString & text,
const QString & p_output = QString() )

Handle clipboard copying for a shown entry.

In "always copy" mode (and only then) this copies text via copyText(), which also arms the autoclear timer and records the clipboard contents. In other modes it does nothing, leaving any pending autoclear tracking intact.

Parameters
textPassword (or value) of the entry being shown.
p_outputFull decrypted output; copying is skipped when it is empty.

Definition at line 28 of file clipboardmanager.cpp.

Here is the call graph for this function:

◆ copyText

void ClipboardManager::copyText ( const QString & text)
slot

Copy text into the system clipboard (or the X11 primary selection when configured) and arm the autoclear timer when enabled.

Parameters
textText to copy.

Definition at line 42 of file clipboardmanager.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ forgetIfSaved()

void ClipboardManager::forgetIfSaved ( const QString & text)
private

Empty a saved previous text equal to text, now copied as a secret, so clear() does not put the secret back.

Parameters
textThe text that has just been copied as a secret.

Definition at line 81 of file clipboardmanager.cpp.

Here is the caller graph for this function:

◆ setAutoclearTimer()

void ClipboardManager::setAutoclearTimer ( )

Re-read the autoclear delay from the settings.

Definition at line 23 of file clipboardmanager.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ statusMessage

void ClipboardManager::statusMessage ( const QString & message)
signal

Something worth showing in the status bar happened.

Parameters
messageTranslated text.
Here is the caller graph for this function:

◆ trackCopied

void ClipboardManager::trackCopied ( const QString & text)
slot

Track text that got onto the clipboard some other way.

For a copy QtPass did not make through copyText(): text selected and copied from a widget showing a secret (Ctrl+C, the context menu, a drag, or the X11 primary selection that a mouse selection fills). The text is cleared with the rest when the autoclear timer runs; what copyText() tracks stays tracked too.

Parameters
textThe copied text; nothing happens when it is empty.

Definition at line 93 of file clipboardmanager.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ trackedText()

auto ClipboardManager::trackedText ( ) const -> QString
inlinenodiscard

The text this manager last put on the clipboard and still tracks.

Returns
Tracked text, empty once cleared.

Definition at line 79 of file clipboardmanager.h.

Member Data Documentation

◆ m_clearTimer

QTimer ClipboardManager::m_clearTimer
private

Single-shot autoclear timer; started by copyText() when the autoclear setting is on, and calls clear() when it fires.

Definition at line 119 of file clipboardmanager.h.

◆ m_clippedText

QString ClipboardManager::m_clippedText
private

The secret copyText() last put on the clipboard; clear() removes the clipboard content only while it still equals this.

Definition at line 124 of file clipboardmanager.h.

◆ m_otherCopies

QStringList ClipboardManager::m_otherCopies
private

trackCopied() texts, cleared with the rest

Definition at line 137 of file clipboardmanager.h.

◆ m_previousClipboard

std::optional<QString> ClipboardManager::m_previousClipboard
private

What was on the clipboard and in the selection before copyText() first put a secret there, for clear() to put back (restoreClipboard). Text only, as pass -c keeps it; absent when nothing was saved.

Definition at line 128 of file clipboardmanager.h.

◆ m_previousSelection

std::optional<QString> ClipboardManager::m_previousSelection
private

As m_previousClipboard, for the X11 primary selection.

Definition at line 130 of file clipboardmanager.h.


The documentation for this class was generated from the following files: