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
|
|
|
|
|
2019-07-23 15:21:39 +01:00
|
|
|
#include <QDateTime>
|
2019-07-18 12:54:41 +01:00
|
|
|
#include <QTimer>
|
2016-09-09 15:18:56 +01:00
|
|
|
#include <QObject>
|
|
|
|
#include <QClipboard>
|
|
|
|
#include <QGuiApplication>
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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-03-03 14:24:24 +00:00
|
|
|
virtual void setText(const QString& content) = 0;
|
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
|
|
|
class QClipboardListener : public ClipboardListener
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
QClipboardListener();
|
|
|
|
|
|
|
|
void setText(const QString & content) override;
|
|
|
|
|
|
|
|
private:
|
|
|
|
#ifdef Q_OS_MAC
|
|
|
|
QTimer m_clipboardMonitorTimer;
|
|
|
|
#endif
|
|
|
|
void updateClipboard(QClipboard::Mode mode);
|
|
|
|
QClipboard* clipboard;
|
|
|
|
};
|
|
|
|
|
|
|
|
class DataControl;
|
|
|
|
|
|
|
|
class WaylandClipboardListener : public ClipboardListener
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
WaylandClipboardListener();
|
|
|
|
|
|
|
|
void setText(const QString & content) override;
|
|
|
|
|
|
|
|
private:
|
|
|
|
void refresh(const QMimeData *mime);
|
|
|
|
|
|
|
|
DataControl *m_dataControl;
|
|
|
|
};
|
|
|
|
|
2016-09-09 15:18:56 +01:00
|
|
|
#endif
|