Added clipboard sync
Merged "package emitters" and "package receivers" in "package interfaces"
This commit is contained in:
parent
7ef29fdd69
commit
30b920b9a1
15 changed files with 129 additions and 10 deletions
|
@ -10,10 +10,11 @@ set(kded_kdeconnect_SRCS
|
|||
devicelinks/udpdevicelink.cpp
|
||||
devicelinks/tcpdevicelink.cpp
|
||||
|
||||
packagereceivers/packagereceiver.cpp
|
||||
packagereceivers/pingpackagereceiver.cpp
|
||||
packagereceivers/notificationpackagereceiver.cpp
|
||||
packagereceivers/pausemusicpackagereceiver.cpp
|
||||
packageinterfaces/packagereceiver.cpp
|
||||
packageinterfaces/pingpackagereceiver.cpp
|
||||
packageinterfaces/notificationpackagereceiver.cpp
|
||||
packageinterfaces/pausemusicpackagereceiver.cpp
|
||||
packageinterfaces/clipboardpackageinterface.cpp
|
||||
|
||||
networkpackage.cpp
|
||||
daemon.cpp
|
||||
|
|
|
@ -20,9 +20,10 @@
|
|||
|
||||
#include "daemon.h"
|
||||
#include "networkpackage.h"
|
||||
#include "packagereceivers/pingpackagereceiver.h"
|
||||
#include "packagereceivers/notificationpackagereceiver.h"
|
||||
#include "packagereceivers/pausemusicpackagereceiver.h"
|
||||
#include "packageinterfaces/pingpackagereceiver.h"
|
||||
#include "packageinterfaces/notificationpackagereceiver.h"
|
||||
#include "packageinterfaces/pausemusicpackagereceiver.h"
|
||||
#include "packageinterfaces/clipboardpackageinterface.h"
|
||||
#include "announcers/avahiannouncer.h"
|
||||
#include "announcers/avahitcpannouncer.h"
|
||||
#include "announcers/fakeannouncer.h"
|
||||
|
@ -61,6 +62,7 @@ Daemon::Daemon(QObject *parent, const QList<QVariant>&)
|
|||
packageReceivers.push_back(new PingPackageReceiver());
|
||||
packageReceivers.push_back(new NotificationPackageReceiver());
|
||||
packageReceivers.push_back(new PauseMusicPackageReceiver());
|
||||
packageReceivers.push_back(new ClipboardPackageInterface());
|
||||
|
||||
//TODO: Do not hardcode the load of the device locators
|
||||
//use: https://techbase.kde.org/Development/Tutorials/Services/Plugins
|
||||
|
@ -82,6 +84,8 @@ Daemon::Daemon(QObject *parent, const QList<QVariant>&)
|
|||
Q_FOREACH (PackageReceiver* pr, packageReceivers) {
|
||||
connect(device,SIGNAL(receivedPackage(const Device&, const NetworkPackage&)),
|
||||
pr,SLOT(receivePackage(const Device&, const NetworkPackage&)));
|
||||
connect(pr,SIGNAL(sendPackage(const NetworkPackage&)),
|
||||
device,SLOT(sendPackage(const NetworkPackage&)));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -142,6 +146,8 @@ void Daemon::onNewDeviceLink(const NetworkPackage& identityPackage, DeviceLink*
|
|||
Q_FOREACH (PackageReceiver* pr, packageReceivers) {
|
||||
connect(device,SIGNAL(receivedPackage(const Device&, const NetworkPackage&)),
|
||||
pr,SLOT(receivePackage(const Device&, const NetworkPackage&)));
|
||||
connect(pr,SIGNAL(sendPackage(const NetworkPackage&)),
|
||||
device,SLOT(sendPackage(const NetworkPackage&)));
|
||||
}
|
||||
emit newDeviceAdded(id);
|
||||
}
|
||||
|
|
|
@ -39,7 +39,7 @@
|
|||
#include <KConfig>
|
||||
|
||||
#include "device.h"
|
||||
#include "packagereceivers/packagereceiver.h"
|
||||
#include "packageinterfaces/packagereceiver.h"
|
||||
#include "devicelinks/devicelink.h"
|
||||
#include "announcers/announcer.h"
|
||||
|
||||
|
|
|
@ -51,12 +51,13 @@ public:
|
|||
void removeLink(DeviceLink*);
|
||||
|
||||
//Send and receive
|
||||
bool sendPackage(const NetworkPackage& np);
|
||||
Q_SIGNALS:
|
||||
void receivedPackage(const Device& device, const NetworkPackage& np);
|
||||
|
||||
public Q_SLOTS:
|
||||
bool sendPackage(const NetworkPackage& np);
|
||||
|
||||
//Public dbus interface
|
||||
public Q_SLOTS:
|
||||
Q_SCRIPTABLE QString id() const{ return m_deviceId; }
|
||||
Q_SCRIPTABLE QString name() const { return m_deviceName; }
|
||||
Q_SCRIPTABLE QStringList availableLinks() const;
|
||||
|
|
|
@ -25,6 +25,8 @@
|
|||
#define PACKAGE_TYPE_PING QString("kdeconnect.ping")
|
||||
#define PACKAGE_TYPE_NOTIFICATION QString("kdeconnect.notification")
|
||||
#define PACKAGE_TYPE_CALL QString("kdeconnect.call")
|
||||
#define PACKAGE_TYPE_CLIPBOARD QString("kdeconnect.clipboard")
|
||||
|
||||
|
||||
|
||||
#endif // NETWORKPACKAGETYPES_H
|
||||
|
|
55
daemon/packageinterfaces/clipboardpackageinterface.cpp
Normal file
55
daemon/packageinterfaces/clipboardpackageinterface.cpp
Normal file
|
@ -0,0 +1,55 @@
|
|||
/**
|
||||
* Copyright 2013 Albert Vaca <albertvaka@gmail.com>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License as
|
||||
* published by the Free Software Foundation; either version 2 of
|
||||
* the License or (at your option) version 3 or any later version
|
||||
* accepted by the membership of KDE e.V. (or its successor approved
|
||||
* by the membership of KDE e.V.), which shall act as a proxy
|
||||
* defined in Section 14 of version 3 of the license.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "clipboardpackageinterface.h"
|
||||
|
||||
#include <QClipboard>
|
||||
#include <KDebug>
|
||||
#include <QApplication>
|
||||
|
||||
ClipboardPackageInterface::ClipboardPackageInterface() {
|
||||
qDebug() << "ClipboardPackageInterface";
|
||||
clipboard = QApplication::clipboard();
|
||||
ignore_next_clipboard_change = false;
|
||||
connect(clipboard,SIGNAL(changed(QClipboard::Mode)),this,SLOT(clipboardChanged()));
|
||||
}
|
||||
|
||||
void ClipboardPackageInterface::clipboardChanged()
|
||||
{
|
||||
if (ignore_next_clipboard_change) {
|
||||
ignore_next_clipboard_change = false;
|
||||
return;
|
||||
}
|
||||
qDebug() << "ClipboardChanged";
|
||||
NetworkPackage np(PACKAGE_TYPE_CLIPBOARD);
|
||||
np.set("content",clipboard->text());
|
||||
emit sendPackage(np);
|
||||
}
|
||||
|
||||
bool ClipboardPackageInterface::receivePackage(const Device& device, const NetworkPackage& np)
|
||||
{
|
||||
Q_UNUSED(device);
|
||||
if (np.type() == PACKAGE_TYPE_CLIPBOARD) {
|
||||
ignore_next_clipboard_change = true;
|
||||
clipboard->setText(np.get<QString>("content"));
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
51
daemon/packageinterfaces/clipboardpackageinterface.h
Normal file
51
daemon/packageinterfaces/clipboardpackageinterface.h
Normal file
|
@ -0,0 +1,51 @@
|
|||
/**
|
||||
* Copyright 2013 Albert Vaca <albertvaka@gmail.com>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License as
|
||||
* published by the Free Software Foundation; either version 2 of
|
||||
* the License or (at your option) version 3 or any later version
|
||||
* accepted by the membership of KDE e.V. (or its successor approved
|
||||
* by the membership of KDE e.V.), which shall act as a proxy
|
||||
* defined in Section 14 of version 3 of the license.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef CLIPBOARDPACKAGEINTERFACE_H
|
||||
#define CLIPBOARDPACKAGEINTERFACE_H
|
||||
|
||||
#include <QObject>
|
||||
#include <QClipboard>
|
||||
|
||||
#include "networkpackage.h"
|
||||
#include "device.h"
|
||||
#include "packagereceiver.h"
|
||||
|
||||
class ClipboardPackageInterface
|
||||
: public PackageReceiver
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
ClipboardPackageInterface();
|
||||
virtual ~ClipboardPackageInterface() { }
|
||||
|
||||
public Q_SLOTS:
|
||||
virtual bool receivePackage(const Device& device, const NetworkPackage& np);
|
||||
|
||||
private Q_SLOTS:
|
||||
void clipboardChanged();
|
||||
|
||||
private:
|
||||
bool ignore_next_clipboard_change;
|
||||
QClipboard *clipboard;
|
||||
};
|
||||
|
||||
#endif
|
|
@ -38,6 +38,9 @@ public:
|
|||
public Q_SLOTS:
|
||||
//Returns true if it has handled the package in some way
|
||||
virtual bool receivePackage(const Device& device, const NetworkPackage& np) = 0;
|
||||
|
||||
Q_SIGNALS:
|
||||
void sendPackage(const NetworkPackage& np);
|
||||
};
|
||||
|
||||
#endif // PACKAGERECEIVER_H
|
Loading…
Reference in a new issue