2016-09-09 15:18:56 +01:00
|
|
|
/**
|
2020-08-17 10:48:10 +01:00
|
|
|
* SPDX-FileCopyrightText: 2016 Albert Vaca <albertvaka@gmail.com>
|
2016-09-09 15:18:56 +01:00
|
|
|
*
|
2020-08-17 10:48:10 +01:00
|
|
|
* SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
|
2016-09-09 15:18:56 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef CLIPBOARDLISTENER_H
|
|
|
|
#define CLIPBOARDLISTENER_H
|
|
|
|
|
|
|
|
#include <QObject>
|
|
|
|
#include <QClipboard>
|
2021-12-13 15:06:25 +00:00
|
|
|
|
|
|
|
#ifdef Q_OS_MAC
|
|
|
|
#include <QTimer>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
class KSystemClipboard;
|
2016-09-09 15:18:56 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Wrapper around QClipboard, which emits clipboardChanged only when it really changed
|
|
|
|
*/
|
2021-03-03 14:24:24 +00:00
|
|
|
|
2019-07-23 15:21:39 +01:00
|
|
|
class ClipboardListener : public QObject
|
2016-09-09 15:18:56 +01:00
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
|
2021-03-03 14:24:24 +00:00
|
|
|
protected:
|
2016-11-26 14:55:27 +00:00
|
|
|
ClipboardListener();
|
2021-03-03 14:24:24 +00:00
|
|
|
void refreshContent(const QString &content);
|
2019-07-23 15:21:39 +01:00
|
|
|
QString m_currentContent;
|
2021-03-03 14:24:24 +00:00
|
|
|
|
|
|
|
private:
|
2019-07-23 15:21:39 +01:00
|
|
|
qint64 m_updateTimestamp = 0;
|
2016-09-09 15:18:56 +01:00
|
|
|
|
|
|
|
public:
|
2021-03-03 14:24:24 +00:00
|
|
|
static ClipboardListener* instance();
|
2016-09-09 15:18:56 +01:00
|
|
|
|
2021-12-13 15:06:25 +00:00
|
|
|
void setText(const QString& content);
|
2016-09-09 15:18:56 +01:00
|
|
|
|
2019-07-23 15:21:39 +01:00
|
|
|
QString currentContent();
|
|
|
|
qint64 updateTimestamp();
|
|
|
|
|
2016-09-09 15:18:56 +01:00
|
|
|
Q_SIGNALS:
|
|
|
|
void clipboardChanged(const QString& content);
|
2021-03-03 14:24:24 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
void updateClipboard(QClipboard::Mode mode);
|
|
|
|
|
2021-12-13 15:06:25 +00:00
|
|
|
#ifdef Q_OS_MAC
|
|
|
|
QTimer *m_clipboardMonitorTimer;
|
|
|
|
#endif
|
|
|
|
KSystemClipboard *clipboard;
|
2021-03-03 14:24:24 +00:00
|
|
|
};
|
|
|
|
|
2016-09-09 15:18:56 +01:00
|
|
|
#endif
|