QtPass 2.0.0
Developer documentation
Loading...
Searching...
No Matches
clipboardmanager.h
Go to the documentation of this file.
1// SPDX-FileCopyrightText: 2026 Anne Jan Brouwer
2// SPDX-License-Identifier: GPL-3.0-or-later
8#ifndef SRC_CLIPBOARDMANAGER_H_
9#define SRC_CLIPBOARDMANAGER_H_
10
11#include <QMimeData>
12#include <QObject>
13#include <QString>
14#include <QStringList>
15#include <QTimer>
16#include <optional>
17
24auto buildClipboardMimeData(const QString &text) -> QMimeData *;
25
31static inline auto dwordBytes(quint32 value) -> QByteArray {
32 return {reinterpret_cast<const char *>(&value), sizeof(value)};
33}
34
47class ClipboardManager : public QObject {
48 Q_OBJECT
49
50public:
56 explicit ClipboardManager(QObject *parent = nullptr);
57
61 void setAutoclearTimer();
62
73 void copyIfAlways(const QString &text, const QString &p_output = QString());
74
79 [[nodiscard]] auto trackedText() const -> QString { return m_clippedText; }
80
81public slots:
87 void copyText(const QString &text);
88
99 void trackCopied(const QString &text);
100
105 void clear();
106
107signals:
112 void statusMessage(const QString &message);
113
114private:
128 std::optional<QString> m_previousClipboard;
130 std::optional<QString> m_previousSelection;
136 void forgetIfSaved(const QString &text);
137 QStringList m_otherCopies;
138};
139
140#endif // SRC_CLIPBOARDMANAGER_H_
auto trackedText() const -> QString
The text this manager last put on the clipboard and still tracks.
void trackCopied(const QString &text)
Track text that got onto the clipboard some other way.
QStringList m_otherCopies
trackCopied() texts, cleared with the rest
void copyIfAlways(const QString &text, const QString &p_output=QString())
Handle clipboard copying for a shown entry.
void setAutoclearTimer()
Re-read the autoclear delay from the settings.
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...
void copyText(const QString &text)
Copy text into the system clipboard (or the X11 primary selection when configured) and arm the autocl...
QTimer m_clearTimer
Single-shot autoclear timer; started by copyText() when the autoclear setting is on,...
void clear()
Remove the tracked text from the clipboard if it is still there. Silent no-op when nothing is tracked...
std::optional< QString > m_previousSelection
As m_previousClipboard, for the X11 primary selection.
QString m_clippedText
The secret copyText() last put on the clipboard; clear() removes the clipboard content only while it ...
void statusMessage(const QString &message)
Something worth showing in the status bar happened.
ClipboardManager(QObject *parent=nullptr)
Construct a manager that also clears its text when the application quits.
std::optional< QString > m_previousClipboard
auto buildClipboardMimeData(const QString &text) -> QMimeData *
Build clipboard MIME data with platform-specific security hints.
static auto dwordBytes(quint32 value) -> QByteArray
Convert quint32 to byte array for Windows clipboard formats.