Commit 9b7eecc6 authored by Albert Vaca Cintora's avatar Albert Vaca Cintora

Moved plugins into separate folders and added KServiceTypeTrader

parent 9022823a
......@@ -2,49 +2,31 @@ set(kded_kdeconnect_SRCS
linkproviders/linkprovider.cpp
linkproviders/loopbacklinkprovider.cpp
linkproviders/avahitcplinkprovider.cpp
#linkproviders/avahitcplinkprovider.cpp
linkproviders/broadcasttcplinkprovider.cpp
devicelinks/devicelink.cpp
devicelinks/echodevicelink.cpp
devicelinks/tcpdevicelink.cpp
packageinterfaces/packageinterface.cpp
packageinterfaces/pingpackageinterface.cpp
packageinterfaces/notificationpackageinterface.cpp
packageinterfaces/pausemusicpackageinterface.cpp
packageinterfaces/clipboardpackageinterface.cpp
packageinterfaces/batterypackageinterface.cpp
packageinterfaces/mpriscontrolpackageinterface.cpp
packageinterfaces/devicebatteryinformation_p.cpp
plugins/packageinterface.cpp
plugins/pluginloader.cpp
networkpackage.cpp
daemon.cpp
device.cpp
)
add_subdirectory(plugins)
qt4_add_dbus_interface(
kded_kdeconnect_SRCS
packageinterfaces/mprisdbusinterface.xml
mprisdbusinterface
)
qt4_add_dbus_interface(
kded_kdeconnect_SRCS
packageinterfaces/propertiesInterface.xml
propertiesdbusinterface
)
kde4_add_plugin(kded_kdeconnect ${kded_kdeconnect_SRCS})
target_link_libraries(kded_kdeconnect
${KDE4_KDECORE_LIBS}
${KDE4_KDEUI_LIBS}
kdnssd
#kdnssd
qjson
${QT_QTNETWORK_LIBRARY}
${QJSON_LIBRARIES}
${QJSON_LIBRARY}
)
macro (generate_and_install_dbus_interface main_project_target header_file output_xml_file) #OPTIONS qdbus_options
......@@ -86,20 +68,6 @@ generate_and_install_dbus_interface(
OPTIONS -a
)
generate_and_install_dbus_interface(
kded_kdeconnect
packageinterfaces/devicebatteryinformation_p.h
org.kde.kdeconnect.device.battery.xml
OPTIONS -a
)
generate_and_install_dbus_interface(
kded_kdeconnect
packageinterfaces/batterypackageinterface.h
org.kde.kdeconnect.battery.xml
OPTIONS -a
)
install(TARGETS kded_kdeconnect DESTINATION ${PLUGIN_INSTALL_DIR})
install(FILES kdeconnect.desktop DESTINATION ${SERVICES_INSTALL_DIR}/kded)
install(FILES kdeconnect.notifyrc DESTINATION ${DATA_INSTALL_DIR}/kdeconnect)
......@@ -22,12 +22,8 @@
#include "networkpackage.h"
#include "packageinterfaces/pingpackageinterface.h"
#include "packageinterfaces/notificationpackageinterface.h"
#include "packageinterfaces/pausemusicpackageinterface.h"
#include "packageinterfaces/clipboardpackageinterface.h"
#include "packageinterfaces/batterypackageinterface.h"
#include "packageinterfaces/mpriscontrolpackageinterface.h"
#include "plugins/packageinterface.h"
#include "plugins/pluginloader.h"
#include "linkproviders/broadcasttcplinkprovider.h"
#include "linkproviders/avahitcplinkprovider.h"
......@@ -51,25 +47,22 @@ Daemon::Daemon(QObject *parent, const QList<QVariant>&)
KSharedConfigPtr config = KSharedConfig::openConfig("kdeconnectrc");
if (!config->group("myself").hasKey("id")) {
QString uid = QUuid::createUuid().toString();
uid = uid.mid(1,uid.length()-2).replace("-","_");
config->group("myself").writeEntry("id",uid);
qDebug() << uid;
QString uuid = QUuid::createUuid().toString();
//uuids contain charcaters that are not exportable in dbus paths
uuid = uuid.mid(1, uuid.length() - 2).replace("-", "_");
config->group("myself").writeEntry("id", uuid);
qDebug() << "My id:" << uuid;
}
//Debugging
qDebug() << "Starting KdeConnect daemon";
//TODO: Do not hardcode the load of the package interfaces
//use: https://techbase.kde.org/Development/Tutorials/Services/Plugins
mPackageInterfaces.push_back(new PingPackageInterface());
mPackageInterfaces.push_back(new NotificationPackageInterface());
mPackageInterfaces.push_back(new PauseMusicPackageInterface());
mPackageInterfaces.push_back(new ClipboardPackageInterface());
mPackageInterfaces.push_back(new BatteryPackageInterface(this));
mPackageInterfaces.push_back(new MprisControlPackageInterface());
//TODO: Do not hardcode the load of the device locators
//Load plugins
PluginLoader *loader = new PluginLoader(this);
connect(loader, SIGNAL(pluginLoaded(PackageInterface*)), this, SLOT(pluginLoaded(PackageInterface*)));
loader->loadAllPlugins();
//Load backends (hardcoded by now)
//use: https://techbase.kde.org/Development/Tutorials/Services/Plugins
mLinkProviders.insert(new BroadcastTcpLinkProvider());
//mLinkProviders.insert(new AvahiTcpLinkProvider());
......@@ -81,14 +74,14 @@ Daemon::Daemon(QObject *parent, const QList<QVariant>&)
const QString defaultName("unnamed");
Q_FOREACH(const QString& id, list) {
const KConfigGroup& data = known.group(id);
const QString& name = data.readEntry<QString>("name",defaultName);
Device* device = new Device(id,name);
const QString& name = data.readEntry<QString>("name", defaultName);
Device* device = new Device(id, name);
mDevices[id] = device;
Q_FOREACH (PackageInterface* pr, mPackageInterfaces) {
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&)));
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&)));
}
}
......@@ -98,8 +91,8 @@ Daemon::Daemon(QObject *parent, const QList<QVariant>&)
Q_FOREACH (LinkProvider* a, mLinkProviders) {
connect(network, SIGNAL(stateChanged(QNetworkSession::State)),
a, SLOT(onNetworkChange(QNetworkSession::State)));
connect(a,SIGNAL(onConnectionReceived(NetworkPackage,DeviceLink*)),
this,SLOT(onNewDeviceLink(NetworkPackage,DeviceLink*)));
connect(a, SIGNAL(onConnectionReceived(NetworkPackage, DeviceLink*)),
this, SLOT(onNewDeviceLink(NetworkPackage, DeviceLink*)));
}
QDBusConnection::sessionBus().registerService("org.kde.kdeconnect");
......@@ -130,6 +123,19 @@ QStringList Daemon::devices()
return mDevices.keys();
}
void Daemon::pluginLoaded(PackageInterface* packageInterface)
{
qDebug() << "PLUUUUUUUUUUUUUUUUGINLOADEEEEEEEEEEEEEEEEEEEEEEED";
mPackageInterfaces.append(packageInterface);
Q_FOREACH(Device* device, mDevices) {
connect(device, SIGNAL(receivedPackage(const Device&, const NetworkPackage&)),
packageInterface, SLOT(receivePackage(const Device&, const NetworkPackage&)));
connect(packageInterface, SIGNAL(sendPackage(const NetworkPackage&)),
device, SLOT(sendPackage(const NetworkPackage&)));
}
}
void Daemon::onNewDeviceLink(const NetworkPackage& identityPackage, DeviceLink* dl)
{
const QString& id = identityPackage.get<QString>("deviceId");
......@@ -158,11 +164,11 @@ void Daemon::onNewDeviceLink(const NetworkPackage& identityPackage, DeviceLink*
const QString& name = identityPackage.get<QString>("deviceName");
Device* device = new Device(id,name,dl);
Device* device = new Device(id, name, dl);
mDevices[id] = device;
Q_FOREACH (PackageInterface* pr, mPackageInterfaces) {
connect(device,SIGNAL(receivedPackage(const Device&, const NetworkPackage&)),
pr,SLOT(receivePackage(const Device&, const NetworkPackage&)));
connect(device, SIGNAL(receivedPackage(const Device&, const NetworkPackage&)),
pr, SLOT(receivePackage(const Device&, const NetworkPackage&)));
}
Q_EMIT newDeviceAdded(id);
}
......
......@@ -39,7 +39,7 @@
#include <KConfig>
#include "device.h"
#include "packageinterfaces/packageinterface.h"
#include "plugins/packageinterface.h"
#include "devicelinks/devicelink.h"
#include "linkproviders/linkprovider.h"
......@@ -72,6 +72,7 @@ Q_SIGNALS:
private Q_SLOTS:
void onNewDeviceLink(const NetworkPackage& identityPackage, DeviceLink* dl);
void pluginLoaded(PackageInterface*);
private:
......
#include "device.h"
#include <ksharedptr.h>
#include <ksharedconfig.h>
#include "devicelinks/devicelink.h"
#include "linkproviders/linkprovider.h"
#include "packageinterfaces/devicebatteryinformation_p.h"
#include <KSharedPtr>
#include <KSharedConfig>
#include <KConfigGroup>
#include <QDebug>
#include "devicelinks/devicelink.h"
#include "linkproviders/linkprovider.h"
#include "networkpackage.h"
Device::Device(const QString& id, const QString& name)
{
m_deviceId = id;
......@@ -107,6 +109,9 @@ void Device::removeLink(DeviceLink* link)
bool Device::sendPackage(const NetworkPackage& np) const
{
Q_FOREACH(DeviceLink* dl, m_deviceLinks) {
//TODO: Actually detect if a package is received or not, now when have TCP
//"ESTABLISHED" connections that look legit and return true when we use them,
//but that are actually broken
if (dl->sendPackage(np)) return true;
}
return false;
......
......@@ -23,8 +23,8 @@
#include <QObject>
#include "networkpackage.h"
class NetworkPackage;
class Device;
class LinkProvider;
......
......@@ -19,14 +19,18 @@
*/
#include "tcpdevicelink.h"
#include "linkproviders/linkprovider.h"
#include "networkpackage.h"
TcpDeviceLink::TcpDeviceLink(const QString& d, LinkProvider* a, QTcpSocket* socket)
: DeviceLink(d, a)
{
mSocket = socket;
connect(mSocket, SIGNAL(disconnected()), this, SLOT(deleteLater()));
connect(mSocket, SIGNAL(readyRead()), this, SLOT(dataReceived()));
connect(mSocket, SIGNAL(disconnected()),
this, SLOT(deleteLater()));
connect(mSocket, SIGNAL(readyRead()),
this, SLOT(dataReceived()));
}
bool TcpDeviceLink::sendPackage(const NetworkPackage& np) const
......@@ -46,7 +50,7 @@ void TcpDeviceLink::dataReceived()
if (package.length() < 3) continue;
NetworkPackage np("");
NetworkPackage::unserialize(package,&np);
NetworkPackage::unserialize(package, &np);
emit receivedPackage(np);
......
......@@ -20,12 +20,13 @@
#include "broadcasttcplinkprovider.h"
#include "devicelinks/tcpdevicelink.h"
#include <QHostInfo>
#include <QTcpServer>
#include <QUdpSocket>
#include "devicelinks/tcpdevicelink.h"
#include "networkpackage.h"
BroadcastTcpLinkProvider::BroadcastTcpLinkProvider()
{
......
add_subdirectory(ping)
generate_and_install_dbus_interface(
kded_kdeconnect
packageinterfaces/devicebatteryinformation_p.h
org.kde.kdeconnect.device.battery.xml
OPTIONS -a
)
generate_and_install_dbus_interface(
kded_kdeconnect
packageinterfaces/batterypackageinterface.h
org.kde.kdeconnect.battery.xml
OPTIONS -a
)
qt4_add_dbus_interface(
kded_kdeconnect_SRCS
packageinterfaces/mprisdbusinterface.xml
mprisdbusinterface
)
qt4_add_dbus_interface(
kded_kdeconnect_SRCS
packageinterfaces/propertiesInterface.xml
propertiesdbusinterface
)
......@@ -23,10 +23,18 @@
#include <QObject>
#include "networkpackage.h"
#include "device.h"
#include <kdemacros.h>
#include <KPluginFactory>
#include <KPluginLoader>
class PackageInterface
#include "../networkpackage.h"
#include "../device.h"
#define KDECONNECT_PLUGIN_EXPORT( c ) \
K_PLUGIN_FACTORY( KdeConnectFactory, registerPlugin< c >(); ) \
K_EXPORT_PLUGIN( KdeConnectFactory("c") )
class KDE_EXPORT PackageInterface
: public QObject
{
Q_OBJECT
......@@ -37,9 +45,11 @@ public:
public Q_SLOTS:
//Returns true if it has handled the package in some way
//device.sendPackage can be used to send an answer back to the device
virtual bool receivePackage(const Device& device, const NetworkPackage& np) = 0;
Q_SIGNALS:
//Sends a package to *all* connected devices
void sendPackage(const NetworkPackage& np);
};
......
find_package(KDE4 REQUIRED)
include (KDE4Defaults)
include_directories(${KDE4_INCLUDES})
set(kdeconnect_ping_SRCS
pingpackageinterface.cpp
../packageinterface.cpp
)
kde4_add_plugin(kdeconnect_ping ${kdeconnect_ping_SRCS})
target_link_libraries(kdeconnect_ping
${KDE4_KDECORE_LIBS}
${KDE4_KDEUI_LIBS}
${QT_QTNETWORK_LIBRARY}
qjson
)
install(TARGETS kdeconnect_ping DESTINATION ${PLUGIN_INSTALL_DIR} )
install(FILES kdeconnect_ping.desktop DESTINATION ${SERVICES_INSTALL_DIR} )
[Desktop Entry]
Encoding=UTF-8
Type=Service
ServiceTypes=KdeConnect/Plugin
X-KDE-Library=kdeconnect_ping
X-KDE-PluginInfo-Author=Albert Vaca
X-KDE-PluginInfo-Email=albertvaka@gmail.com
X-KDE-PluginInfo-Name=kdeconnect_ping
X-KDE-PluginInfo-Version=0.1
X-KDE-PluginInfo-Website=http://albertvaka.wordpress.com
X-KDE-PluginInfo-Category=Network
X-KDE-PluginInfo-Depends=
X-KDE-PluginInfo-License=GPL
X-KDE-PluginInfo-EnabledByDefault=true
X-KDE-ParentApp=kdeconnect
X-KDE-Version=4.0
Name=Ping
Comment=Send and receive pings
......@@ -23,6 +23,15 @@
#include <KDebug>
#include <kicon.h>
K_PLUGIN_FACTORY( KdeConnectPluginFactory, registerPlugin< PingPackageInterface >(); )
K_EXPORT_PLUGIN( KdeConnectPluginFactory("kdeconnect_ping", "kdeconnect_ping") )
PingPackageInterface::PingPackageInterface(QObject* parent, const QVariantList& args)
: PackageInterface(parent)
{
Q_UNUSED(args);
}
bool PingPackageInterface::receivePackage(const Device& device, const NetworkPackage& np)
{
......
......@@ -23,13 +23,16 @@
#include <knotification.h>
#include "packageinterface.h"
#include "../packageinterface.h"
class PingPackageInterface
class KDE_EXPORT PingPackageInterface
: public PackageInterface
{
Q_OBJECT
public:
explicit PingPackageInterface(QObject *parent, const QVariantList &args);
virtual bool receivePackage(const Device& device, const NetworkPackage& np);
};
......
/**
* 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 "pluginloader.h"
#include "packageinterface.h"
#include <KServiceTypeTrader>
#include <KDebug>
PluginLoader::PluginLoader(QObject * parent)
: QObject(parent)
{
}
PluginLoader::~PluginLoader()
{
}
void PluginLoader::loadAllPlugins()
{
kDebug() << "Load all plugins";
KService::List offers = KServiceTypeTrader::self()->query("KdeConnect/Plugin");
qDebug() << "LO TRAIGO DE OFERTA CHACHO" << offers;
KService::List::const_iterator iter;
for(iter = offers.begin(); iter < offers.end(); ++iter)
{
QString error;
KService::Ptr service = *iter;
KPluginFactory *factory = KPluginLoader(service->library()).factory();
if (!factory)
{
//KMessageBox::error(0, i18n("<html><p>KPluginFactory could not load the plugin:<br /><i>%1</i></p></html>",
// service->library()));
kError(5001) << "KPluginFactory could not load the plugin:" << service->library();
continue;
}
PackageInterface *plugin = factory->create<PackageInterface>(this);
if (plugin) {
kDebug() << "Load plugin:" << service->name();
emit pluginLoaded(plugin);
} else {
kDebug() << error;
}
}
}
\ No newline at end of file
/**
* 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 PACKAGEINTERFACELOADER_H
#define PACKAGEINTERFACELOADER_H
#include <QObject>
#include "packageinterface.h"
class PluginLoader : public QObject
{
Q_OBJECT
public:
PluginLoader(QObject * parent);
virtual ~PluginLoader();
void loadAllPlugins();
signals:
void pluginLoaded(PackageInterface * plugin);
};
#endif
......@@ -9,6 +9,10 @@ export VERBOSE=1
if kdebuild; then
echo "--------BUILD DONE--------------"
kbuildsycoca4
killall kded4 2> /dev/null
while killall -9 kded4 2> /dev/null; do
true
......@@ -17,6 +21,8 @@ if kdebuild; then
#qdbus org.kde.kded /kded unloadModule kdeconnect
#qdbus org.kde.kded /kded loadModule kdeconnect
echo "--------STARTING KDED--------------"
kded4 --nofork # 2>&1 | grep -v "^kded(" &
fi
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment