File indexing completed on 2024-04-14 04:51:45

0001 /**
0002  * SPDX-FileCopyrightText: 2013 Albert Vaca <albertvaka@gmail.com>
0003  *
0004  * SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
0005  */
0006 
0007 #pragma once
0008 
0009 #include <QClipboard>
0010 #include <QObject>
0011 #include <core/kdeconnectplugin.h>
0012 
0013 #include "clipboardlistener.h"
0014 
0015 /**
0016  * Packet containing just clipboard contents, sent when a device updates its clipboard.
0017  * <p>
0018  * The body should look like so:
0019  * {
0020  * "content": "password"
0021  * }
0022  */
0023 #define PACKET_TYPE_CLIPBOARD QStringLiteral("kdeconnect.clipboard")
0024 
0025 /**
0026  * Packet containing clipboard contents and a timestamp that the contents were last updated, sent
0027  * on first connection
0028  * <p>
0029  * The timestamp is milliseconds since epoch. It can be 0, which indicates that the clipboard
0030  * update time is currently unknown.
0031  * <p>
0032  * The body should look like so:
0033  * {
0034  * "timestamp": 542904563213,
0035  * "content": "password"
0036  * }
0037  */
0038 #define PACKET_TYPE_CLIPBOARD_CONNECT QStringLiteral("kdeconnect.clipboard.connect")
0039 
0040 class ClipboardPlugin : public KdeConnectPlugin
0041 {
0042     Q_OBJECT
0043     Q_CLASSINFO("D-Bus Interface", "org.kde.kdeconnect.device.clipboard")
0044     Q_PROPERTY(bool isAutoShareDisabled READ isAutoShareDisabled NOTIFY autoShareDisabledChanged)
0045 public:
0046     explicit ClipboardPlugin(QObject *parent, const QVariantList &args);
0047 
0048     Q_SCRIPTABLE void sendClipboard();
0049     Q_SCRIPTABLE void sendClipboard(const QString &content);
0050     QString dbusPath() const override;
0051 
0052     void receivePacket(const NetworkPacket &np) override;
0053     void connected() override;
0054     bool isAutoShareDisabled();
0055 
0056 Q_SIGNALS:
0057     Q_SCRIPTABLE void autoShareDisabledChanged(bool b);
0058 
0059 private Q_SLOTS:
0060     void clipboardChanged(const QString &content, ClipboardListener::ClipboardContentType contentType);
0061     void sendConnectPacket();
0062     void configChanged();
0063 
0064 private:
0065     bool autoShare;
0066     bool sharePasswords;
0067 };