Changeset View
Changeset View
Standalone View
Standalone View
plugins/clipboard/clipboardlistener.h
Show All 15 Lines | |||||
16 | * | 16 | * | ||
17 | * You should have received a copy of the GNU General Public License | 17 | * You should have received a copy of the GNU General Public License | ||
18 | * along with this program. If not, see <https://www.gnu.org/licenses/>. | 18 | * along with this program. If not, see <https://www.gnu.org/licenses/>. | ||
19 | */ | 19 | */ | ||
20 | 20 | | |||
21 | #ifndef CLIPBOARDLISTENER_H | 21 | #ifndef CLIPBOARDLISTENER_H | ||
22 | #define CLIPBOARDLISTENER_H | 22 | #define CLIPBOARDLISTENER_H | ||
23 | 23 | | |||
24 | #include <QDateTime> | ||||
24 | #include <QTimer> | 25 | #include <QTimer> | ||
25 | #include <QObject> | 26 | #include <QObject> | ||
26 | #include <QClipboard> | 27 | #include <QClipboard> | ||
27 | #include <QGuiApplication> | 28 | #include <QGuiApplication> | ||
28 | 29 | | |||
29 | /** | 30 | /** | ||
30 | * Wrapper around QClipboard, which emits clipboardChanged only when it really changed | 31 | * Wrapper around QClipboard, which emits clipboardChanged only when it really changed | ||
31 | */ | 32 | */ | ||
32 | class ClipboardListener : public QObject | 33 | class ClipboardListener : public QObject | ||
33 | { | 34 | { | ||
34 | Q_OBJECT | 35 | Q_OBJECT | ||
35 | 36 | | |||
36 | private: | 37 | private: | ||
37 | ClipboardListener(); | 38 | ClipboardListener(); | ||
38 | QString currentContent; | 39 | QString m_currentContent; | ||
40 | qint64 m_updateTimestamp = 0; | ||||
sredman: Typically local variables are prefixed with `m_<varname>`, so like `m_updateTimestamp`. Of… | |||||
39 | QClipboard* clipboard; | 41 | QClipboard* clipboard; | ||
40 | #ifdef Q_OS_MAC | 42 | #ifdef Q_OS_MAC | ||
41 | QTimer m_clipboardMonitorTimer; | 43 | QTimer m_clipboardMonitorTimer; | ||
42 | #endif | 44 | #endif | ||
43 | 45 | | |||
44 | public: | 46 | public: | ||
45 | 47 | | |||
46 | static ClipboardListener* instance() | 48 | static ClipboardListener* instance() | ||
47 | { | 49 | { | ||
48 | static ClipboardListener* me = nullptr; | 50 | static ClipboardListener* me = nullptr; | ||
49 | if (!me) { | 51 | if (!me) { | ||
50 | me = new ClipboardListener(); | 52 | me = new ClipboardListener(); | ||
51 | } | 53 | } | ||
52 | return me; | 54 | return me; | ||
53 | } | 55 | } | ||
54 | 56 | | |||
55 | void updateClipboard(QClipboard::Mode mode); | 57 | void updateClipboard(QClipboard::Mode mode); | ||
56 | 58 | | |||
57 | void setText(const QString& content); | 59 | void setText(const QString& content); | ||
58 | 60 | | |||
61 | QString currentContent(); | ||||
62 | qint64 updateTimestamp(); | ||||
sredman: Usually getters are just named `<varname>`, so like `qint64 updateTimestamp()` | |||||
63 | | ||||
59 | Q_SIGNALS: | 64 | Q_SIGNALS: | ||
60 | void clipboardChanged(const QString& content); | 65 | void clipboardChanged(const QString& content); | ||
61 | }; | 66 | }; | ||
62 | 67 | | |||
63 | #endif | 68 | #endif |
Typically local variables are prefixed with m_<varname>, so like m_updateTimestamp. Of course, this should apply to currentContent as well...