Commit 3eb6ecaa authored by Albert Vaca Cintora's avatar Albert Vaca Cintora

Implemented batterypackageinterface

Fixed CMake macro
parent 43932a43
......@@ -33,17 +33,35 @@ target_link_libraries(kded_kdeconnect
${QJSON_LIBRARY}
)
macro (generate_and_install_dbus_interface project_main_target header_file output_xml_file) #OPTIONS qdbus_options
QT4_EXTRACT_OPTIONS(extra_files_ignore qdbus_options ${ARGN})
qt4_generate_dbus_interface(${header_file} ${output_xml_file} OPTIONS ${qdbus_options})
add_dependencies(${project_main_target} ${output_xml_file})
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/${output_xml_file} DESTINATION ${DBUS_INTERFACES_INSTALL_DIR})
macro (generate_and_install_dbus_interface main_project_target header_file output_xml_file) #OPTIONS qdbus_options
QT4_EXTRACT_OPTIONS(
extra_files_ignore
qdbus_options
${ARGN}
)
qt4_generate_dbus_interface(
${header_file}
${output_xml_file}
OPTIONS ${qdbus_options}
)
add_custom_target(
${output_xml_file}
SOURCES ${CMAKE_CURRENT_BINARY_DIR}/${output_xml_file}
)
install(
FILES ${CMAKE_CURRENT_BINARY_DIR}/${output_xml_file}
DESTINATION ${DBUS_INTERFACES_INSTALL_DIR}
)
add_dependencies(
${main_project_target}
${output_xml_file}
)
endmacro (generate_and_install_dbus_interface)
generate_and_install_dbus_interface(
kded_kdeconnect
daemon.h
org.kde.kdeconnect.xml
org.kde.kdeconnect.daemon.xml
OPTIONS -a
)
......@@ -61,6 +79,13 @@ generate_and_install_dbus_interface(
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)
......@@ -64,7 +64,7 @@ Daemon::Daemon(QObject *parent, const QList<QVariant>&)
mPackageInterfaces.push_back(new NotificationPackageInterface());
mPackageInterfaces.push_back(new PauseMusicPackageInterface());
mPackageInterfaces.push_back(new ClipboardPackageInterface());
mPackageInterfaces.push_back(new BatteryPackageInterface());
mPackageInterfaces.push_back(new BatteryPackageInterface(this));
//TODO: Do not hardcode the load of the device locators
//use: https://techbase.kde.org/Development/Tutorials/Services/Plugins
......
......@@ -77,6 +77,11 @@ void Device::addLink(DeviceLink* link)
connect(link, SIGNAL(receivedPackage(NetworkPackage)), this, SLOT(privateReceivedPackage(NetworkPackage)));
qSort(m_deviceLinks.begin(),m_deviceLinks.end(),lessThan);
if (m_deviceLinks.size() == 1) {
emit reachableStatusChanged();
}
}
void Device::linkDestroyed(QObject* o)
......@@ -87,9 +92,13 @@ void Device::linkDestroyed(QObject* o)
void Device::removeLink(DeviceLink* link)
{
qDebug() << "RemoveLink";
//disconnect(link, SIGNAL(receivedPackage(NetworkPackage)), this, SLOT(privateReceivedPackage(NetworkPackage)));
m_deviceLinks.removeOne(link);
qDebug() << "RemoveLink"<< m_deviceLinks.size() << "links remaining";
if (m_deviceLinks.empty()) {
emit reachableStatusChanged();
}
}
bool Device::sendPackage(const NetworkPackage& np)
......
......@@ -29,7 +29,8 @@
class DeviceLink;
class Device : public QObject
class Device
: public QObject
{
Q_OBJECT
Q_CLASSINFO("D-Bus Interface", "org.kde.kdeconnect.device")
......@@ -55,6 +56,7 @@ public:
void addLink(DeviceLink*);
void removeLink(DeviceLink*);
//Send and receive
Q_SIGNALS:
void receivedPackage(const Device& device, const NetworkPackage& np);
......@@ -69,6 +71,9 @@ public Q_SLOTS:
Q_SCRIPTABLE void setPair(bool b);
Q_SCRIPTABLE void sendPing();
Q_SIGNALS:
void reachableStatusChanged();
private Q_SLOTS:
void linkDestroyed(QObject* o = 0);
void privateReceivedPackage(const NetworkPackage& np);
......
......@@ -24,9 +24,17 @@
#include <kicon.h>
BatteryPackageInterface::BatteryPackageInterface()
BatteryPackageInterface::BatteryPackageInterface(QObject* parent)
: PackageInterface(parent)
{
//TODO: Get initial state of all devices
QDBusConnection::sessionBus().registerObject("/modules/kdeconnect/plugins/battery", this, QDBusConnection::ExportScriptableContents);
//The solid backend watches for this service to become available, because it is not possible to watch for a path
QDBusConnection::sessionBus().registerService("org.kde.kdeconnect.battery");
qDebug() << "BatteryPackageInterface registered in dbus";
}
bool BatteryPackageInterface::receivePackage(const Device& device, const NetworkPackage& np)
......@@ -35,23 +43,42 @@ bool BatteryPackageInterface::receivePackage(const Device& device, const Network
QString id = device.id();
if (!devices.contains(id)) {
if (!mDevices.contains(id)) {
//TODO: Avoid ugly const_cast
DeviceBatteryInformation* deviceInfo = new DeviceBatteryInformation(const_cast<Device*>(&device));
devices[id] = deviceInfo;
mDevices[id] = deviceInfo;
emit batteryDeviceAdded(device.id());
connect(&device, SIGNAL(reachableStatusChanged()), this, SLOT(deviceReachableStatusChange()));
qDebug() << "Added battery info to device" << id;
}
bool isCharging = np.get<bool>("isCharging");
devices[id]->setCharging(isCharging);
mDevices[id]->setCharging(isCharging);
int currentCharge = np.get<int>("currentCharge");
devices[id]->setCharge(currentCharge);
mDevices[id]->setCharge(currentCharge);
return true;
}
QStringList BatteryPackageInterface::getBatteryReportingDevices()
{
return mDevices.keys();
}
void BatteryPackageInterface::deviceReachableStatusChange()
{
Device* device = static_cast<Device*>(sender());
if (!device->reachable()) {
mDevices.remove(device->id());
emit batteryDeviceLost(device->id());
disconnect(device, SIGNAL(reachableStatusChanged()), this, SLOT(deviceReachableStatusChange()));
}
}
......@@ -24,20 +24,32 @@
#include <knotification.h>
#include "packageinterface.h"
#include <QDBusAbstractAdaptor>
#include "devicebatteryinformation_p.h"
class BatteryPackageInterface
: public PackageInterface
{
Q_OBJECT
Q_CLASSINFO("D-Bus Interface", "org.kde.kdeconnect.battery")
public:
BatteryPackageInterface();
BatteryPackageInterface(QObject* parent);
virtual bool receivePackage(const Device&, const NetworkPackage& np);
private:
QHash<QString,DeviceBatteryInformation*> devices;
QHash<QString,DeviceBatteryInformation*> mDevices;
public Q_SLOTS:
Q_SCRIPTABLE QStringList getBatteryReportingDevices();
Q_SIGNALS:
Q_SCRIPTABLE void batteryDeviceAdded(const QString& id);
Q_SCRIPTABLE void batteryDeviceLost(const QString& id);
public slots:
void deviceReachableStatusChange();
};
#endif
......@@ -28,24 +28,24 @@ class DeviceBatteryInformation
: public QDBusAbstractAdaptor
{
Q_OBJECT
Q_CLASSINFO("D-Bus Interface", "org.kde.kdeconnect.battery")
Q_PROPERTY( int charge READ charge )
Q_CLASSINFO("D-Bus Interface", "org.kde.kdeconnect.device.battery")
Q_PROPERTY( int charge READ charge NOTIFY chargingChange )
Q_PROPERTY( bool isCharging READ isCharging NOTIFY chargingChange )
public:
DeviceBatteryInformation(QObject* parent = 0);
int charge() { return mCharge; }
void setCharge(int charge) { mCharge = charge; }
void setCharge(int charge) { mCharge = charge; emit chargingChange(); }
bool isCharging() { return mIsCharging; }
void setCharging(bool isCharging) { mIsCharging = isCharging; }
void setCharging(bool isCharging) { mIsCharging = isCharging; emit chargingChange(); }
private:
bool mIsCharging;
int mCharge;
Q_SIGNALS:
Q_SCRIPTABLE void chargingChange(bool charging);
Q_SCRIPTABLE void chargingChange();
};
......
......@@ -20,7 +20,8 @@
#include "packageinterface.h"
PackageInterface::PackageInterface()
PackageInterface::PackageInterface(QObject* parent)
: QObject(parent)
{
//gcc complains if we don't add something to compile on a class with virtual functions
}
......@@ -32,7 +32,7 @@ class PackageInterface
Q_OBJECT
public:
PackageInterface();
PackageInterface(QObject* parent = 0);
virtual ~PackageInterface() { }
public Q_SLOTS:
......
......@@ -7,7 +7,7 @@ set(kcm_SRCS devicesmodel.cpp
qt4_add_dbus_interface(
kcm_SRCS
${CMAKE_BINARY_DIR}/daemon/org.kde.kdeconnect.xml
${CMAKE_BINARY_DIR}/daemon/org.kde.kdeconnect.daemon.xml
daemoninterface
)
......@@ -29,9 +29,8 @@ target_link_libraries(kcm_kdeconnect
)
add_dependencies(kcm_kdeconnect
org.kde.kdeconnect.xml
org.kde.kdeconnect.daemon.xml
org.kde.kdeconnect.device.xml
org.kde.kdeconnect.device.battery.xml
)
install(TARGETS kcm_kdeconnect DESTINATION ${PLUGIN_INSTALL_DIR})
......
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