Commit 238d81a4 authored by Albert Vaca Cintora's avatar Albert Vaca Cintora

Changing dbus interface to improve communication with kcm and the solid backend

parent 8481a910
include(KDE4Defaults)
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)
...@@ -29,30 +29,7 @@ target_link_libraries(kded_kdeconnect ...@@ -29,30 +29,7 @@ target_link_libraries(kded_kdeconnect
${QT_QTNETWORK_LIBRARY} ${QT_QTNETWORK_LIBRARY}
) )
macro (generate_and_install_dbus_interface main_project_target header_file output_xml_file) #OPTIONS qdbus_options include(../cmakemacros.txt)
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( generate_and_install_dbus_interface(
kded_kdeconnect kded_kdeconnect
......
...@@ -67,7 +67,9 @@ Daemon::Daemon(QObject *parent, const QList<QVariant>&) ...@@ -67,7 +67,9 @@ Daemon::Daemon(QObject *parent, const QList<QVariant>&)
const KConfigGroup& data = known.group(id); const KConfigGroup& data = known.group(id);
const QString& name = data.readEntry<QString>("name", defaultName); const QString& name = data.readEntry<QString>("name", defaultName);
Device* device = new Device(id, name); Device* device = new Device(id, name);
connect(device, SIGNAL(reachableStatusChanged()), this, SLOT(onDeviceReachableStatusChanged()));
mDevices[id] = device; mDevices[id] = device;
Q_EMIT deviceAdded(id);
} }
QNetworkSession* network = new QNetworkSession(QNetworkConfigurationManager().defaultConfiguration()); QNetworkSession* network = new QNetworkSession(QNetworkConfigurationManager().defaultConfiguration());
...@@ -103,6 +105,17 @@ void Daemon::forceOnNetworkChange() ...@@ -103,6 +105,17 @@ void Daemon::forceOnNetworkChange()
} }
} }
QStringList Daemon::visibleDevices()
{
QStringList ret;
Q_FOREACH(Device* device, mDevices) {
if (device->reachable()) {
ret.append(device->id());
}
}
return ret;
}
QStringList Daemon::devices() QStringList Daemon::devices()
{ {
return mDevices.keys(); return mDevices.keys();
...@@ -120,16 +133,7 @@ void Daemon::onNewDeviceLink(const NetworkPackage& identityPackage, DeviceLink* ...@@ -120,16 +133,7 @@ void Daemon::onNewDeviceLink(const NetworkPackage& identityPackage, DeviceLink*
Device* device = mDevices[id]; Device* device = mDevices[id];
device->addLink(dl); device->addLink(dl);
/*if (device->paired()) { Q_EMIT deviceVisibilityChanged(id, true);
KNotification* notification = new KNotification("pingReceived"); //KNotification::Persistent
notification->setPixmap(KIcon("dialog-ok").pixmap(48, 48));
notification->setComponentData(KComponentData("kdeconnect", "kdeconnect"));
notification->setTitle(device->name());
notification->setText("Succesfully connected");
notification->sendEvent();
}*/
Q_EMIT deviceStatusChanged(id);
} else { } else {
qDebug() << "It is a new device"; qDebug() << "It is a new device";
...@@ -137,9 +141,31 @@ void Daemon::onNewDeviceLink(const NetworkPackage& identityPackage, DeviceLink* ...@@ -137,9 +141,31 @@ void Daemon::onNewDeviceLink(const NetworkPackage& identityPackage, DeviceLink*
const QString& name = identityPackage.get<QString>("deviceName"); const QString& name = identityPackage.get<QString>("deviceName");
Device* device = new Device(id, name, dl); Device* device = new Device(id, name, dl);
connect(device, SIGNAL(reachableStatusChanged()), this, SLOT(onDeviceReachableStatusChanged()));
mDevices[id] = device; mDevices[id] = device;
Q_EMIT newDeviceAdded(id); Q_EMIT deviceAdded(id);
Q_EMIT deviceVisibilityChanged(id, true);
}
}
void Daemon::onDeviceReachableStatusChanged()
{
Device* device = (Device*)sender();
QString id = device->id();
if (!device->reachable()) {
Q_EMIT deviceVisibilityChanged(id, false);
if (!device->paired()) {
Q_EMIT deviceRemoved(id);
mDevices.remove(id);
device->deleteLater();
}
} }
} }
......
...@@ -62,15 +62,17 @@ public Q_SLOTS: ...@@ -62,15 +62,17 @@ public Q_SLOTS:
Q_SCRIPTABLE void forceOnNetworkChange(); Q_SCRIPTABLE void forceOnNetworkChange();
//Returns a list of ids. The respective devices can be manipulated using the dbus path: "/modules/kdeconnect/Devices/"+id //Returns a list of ids. The respective devices can be manipulated using the dbus path: "/modules/kdeconnect/Devices/"+id
Q_SCRIPTABLE QStringList devices(); Q_SCRIPTABLE QStringList devices(); //All known devices
Q_SCRIPTABLE QStringList visibleDevices(); //Only visible devices
Q_SIGNALS: Q_SIGNALS:
Q_SCRIPTABLE void newDeviceAdded(const QString& id); Q_SCRIPTABLE void deviceAdded(const QString& id);
Q_SCRIPTABLE void deviceStatusChanged(const QString& id); Q_SCRIPTABLE void deviceRemoved(const QString& id); //Note that paired devices will never be removed
Q_SCRIPTABLE void deviceVisibilityChanged(const QString& id, bool isVisible);
private Q_SLOTS: private Q_SLOTS:
void onNewDeviceLink(const NetworkPackage& identityPackage, DeviceLink* dl); void onNewDeviceLink(const NetworkPackage& identityPackage, DeviceLink* dl);
void onDeviceReachableStatusChanged();
private: private:
......
...@@ -24,7 +24,7 @@ Device::Device(const QString& id, const QString& name) ...@@ -24,7 +24,7 @@ Device::Device(const QString& id, const QString& name)
m_knownIdentiy = true; m_knownIdentiy = true;
//Register in bus //Register in bus
QDBusConnection::sessionBus().registerObject("/modules/kdeconnect/devices/"+id, this, QDBusConnection::ExportScriptableContents | QDBusConnection::ExportAdaptors); QDBusConnection::sessionBus().registerObject("/modules/kdeconnect/devices/"+id, this, QDBusConnection::ExportScriptableContents | QDBusConnection::ExportAdaptors | QDBusConnection::ExportChildObjects);
reloadPlugins(); reloadPlugins();
} }
...@@ -37,7 +37,7 @@ Device::Device(const QString& id, const QString& name, DeviceLink* link) ...@@ -37,7 +37,7 @@ Device::Device(const QString& id, const QString& name, DeviceLink* link)
m_knownIdentiy = true; m_knownIdentiy = true;
//Register in bus //Register in bus
QDBusConnection::sessionBus().registerObject("/modules/kdeconnect/devices/"+id, this, QDBusConnection::ExportScriptableContents | QDBusConnection::ExportAdaptors); QDBusConnection::sessionBus().registerObject("/modules/kdeconnect/devices/"+id, this, QDBusConnection::ExportScriptableContents | QDBusConnection::ExportAdaptors | QDBusConnection::ExportChildObjects);
addLink(link); addLink(link);
...@@ -61,6 +61,11 @@ Device::Device(const QString& id, const QString& name, DeviceLink* link) ...@@ -61,6 +61,11 @@ Device::Device(const QString& id, const QString& name, DeviceLink* link)
} }
*/ */
bool Device::hasPlugin(const QString& name)
{
return m_plugins.contains(name);
}
void Device::reloadPlugins() void Device::reloadPlugins()
{ {
...@@ -86,14 +91,15 @@ void Device::reloadPlugins() ...@@ -86,14 +91,15 @@ void Device::reloadPlugins()
connect(this, SIGNAL(receivedPackage(const NetworkPackage&)), connect(this, SIGNAL(receivedPackage(const NetworkPackage&)),
plugin, SLOT(receivePackage(const NetworkPackage&))); plugin, SLOT(receivePackage(const NetworkPackage&)));
// connect(packageInterface, SIGNAL(sendPackage(const NetworkPackage&)), // connect(plugin, SIGNAL(sendPackage(const NetworkPackage&)),
// device, SLOT(sendPackage(const NetworkPackage&))); // device, SLOT(sendPackage(const NetworkPackage&)));
m_plugins.append(plugin); m_plugins[pluginName] = plugin;
} }
} }
Q_EMIT pluginsChanged();
} }
...@@ -125,15 +131,16 @@ void Device::addLink(DeviceLink* link) ...@@ -125,15 +131,16 @@ void Device::addLink(DeviceLink* link)
m_deviceLinks.append(link); m_deviceLinks.append(link);
//TODO: Somehow destroy previous device links from the same provider, //Theoretically we will never add two links from the same provider (the provider should destroy
//but if we do it here, the provider will keep a broken ref! //the old one before this is called), so we do not have to worry about destroying old links.
//Actually, we should not destroy them or the provider will store an invalid ref!
connect(link, SIGNAL(receivedPackage(NetworkPackage)), this, SLOT(privateReceivedPackage(NetworkPackage))); connect(link, SIGNAL(receivedPackage(NetworkPackage)), this, SLOT(privateReceivedPackage(NetworkPackage)));
qSort(m_deviceLinks.begin(),m_deviceLinks.end(),lessThan); qSort(m_deviceLinks.begin(),m_deviceLinks.end(),lessThan);
if (m_deviceLinks.size() == 1) { if (m_deviceLinks.size() == 1) {
emit reachableStatusChanged(); Q_EMIT reachableStatusChanged();
} }
} }
...@@ -150,7 +157,7 @@ void Device::removeLink(DeviceLink* link) ...@@ -150,7 +157,7 @@ void Device::removeLink(DeviceLink* link)
qDebug() << "RemoveLink"<< m_deviceLinks.size() << "links remaining"; qDebug() << "RemoveLink"<< m_deviceLinks.size() << "links remaining";
if (m_deviceLinks.empty()) { if (m_deviceLinks.empty()) {
emit reachableStatusChanged(); Q_EMIT reachableStatusChanged();
} }
} }
...@@ -162,8 +169,8 @@ bool Device::sendPackage(const NetworkPackage& np) const ...@@ -162,8 +169,8 @@ bool Device::sendPackage(const NetworkPackage& np) const
} }
Q_FOREACH(DeviceLink* dl, m_deviceLinks) { Q_FOREACH(DeviceLink* dl, m_deviceLinks) {
//TODO: Actually detect if a package is received or not, now when have TCP //TODO: Actually detect if a package is received or not, now we keep TCP
//"ESTABLISHED" connections that look legit and return true when we use them, //"ESTABLISHED" connections that look legit (return true when we use them),
//but that are actually broken //but that are actually broken
if (dl->sendPackage(np)) return true; if (dl->sendPackage(np)) return true;
} }
......
...@@ -24,7 +24,7 @@ ...@@ -24,7 +24,7 @@
#include <QObject> #include <QObject>
#include <QDBusConnection> #include <QDBusConnection>
#include <QString> #include <QString>
#include <qvector.h> #include <QMap>
#include "networkpackage.h" #include "networkpackage.h"
...@@ -61,6 +61,7 @@ public: ...@@ -61,6 +61,7 @@ public:
Q_SCRIPTABLE bool trusted() const { return m_paired; } Q_SCRIPTABLE bool trusted() const { return m_paired; }
Q_SCRIPTABLE bool paired() const { return m_paired; } Q_SCRIPTABLE bool paired() const { return m_paired; }
Q_SCRIPTABLE bool reachable() const { return !m_deviceLinks.empty(); } Q_SCRIPTABLE bool reachable() const { return !m_deviceLinks.empty(); }
Q_SCRIPTABLE bool hasPlugin(const QString& name);
//Send and receive //Send and receive
Q_SIGNALS: Q_SIGNALS:
...@@ -74,22 +75,22 @@ public Q_SLOTS: ...@@ -74,22 +75,22 @@ public Q_SLOTS:
Q_SCRIPTABLE void reloadPlugins(); Q_SCRIPTABLE void reloadPlugins();
Q_SCRIPTABLE void sendPing(); Q_SCRIPTABLE void sendPing();
Q_SIGNALS:
void reachableStatusChanged();
private Q_SLOTS: private Q_SLOTS:
void linkDestroyed(QObject* o = 0); void linkDestroyed(QObject* o = 0);
void privateReceivedPackage(const NetworkPackage& np); void privateReceivedPackage(const NetworkPackage& np);
Q_SIGNALS:
void reachableStatusChanged();
void pluginsChanged();
private: private:
bool m_paired; bool m_paired;
QString m_deviceId; QString m_deviceId;
QString m_deviceName; QString m_deviceName;
QList<DeviceLink*> m_deviceLinks; QList<DeviceLink*> m_deviceLinks;
QList<KdeConnectPlugin*> m_plugins; QMap<QString, KdeConnectPlugin*> m_plugins;
bool m_knownIdentiy; bool m_knownIdentiy;
}; };
Q_DECLARE_METATYPE(Device*) Q_DECLARE_METATYPE(Device*)
......
/**
* 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 "devicebatteryinformation_p.h"
DeviceBatteryInformation::DeviceBatteryInformation(QObject* parent)
: QDBusAbstractAdaptor(parent)
{
}
/**
* 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 DEVICEBATTERYINFORMATION_H
#define DEVICEBATTERYINFORMATION_H
#include <QObject>
#include <QDBusAbstractAdaptor>
class DeviceBatteryInformation
: public QDBusAbstractAdaptor
{
Q_OBJECT
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; emit chargingChange(); }
bool isCharging() { return mIsCharging; }
void setCharging(bool isCharging) { mIsCharging = isCharging; emit chargingChange(); }
private:
bool mIsCharging;
int mCharge;
Q_SIGNALS:
Q_SCRIPTABLE void chargingChange();
};
#endif //DEVICEBATTERYINFORMATION_H
\ No newline at end of file
...@@ -18,8 +18,8 @@ ...@@ -18,8 +18,8 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#ifndef PACKAGEINTERFACELOADER_H #ifndef PLUGINLOADER_H
#define PACKAGEINTERFACELOADER_H #define PLUGINLOADER_H
#include <QObject> #include <QObject>
#include <QMap> #include <QMap>
......
...@@ -33,23 +33,17 @@ DevicesModel::DevicesModel(QObject *parent) ...@@ -33,23 +33,17 @@ DevicesModel::DevicesModel(QObject *parent)
, m_dbusInterface(new DaemonDbusInterface(this)) , m_dbusInterface(new DaemonDbusInterface(this))
{ {
QList<QString> deviceIds = m_dbusInterface->devices(); QList<QString> deviceIds = m_dbusInterface->devices();
connect(m_dbusInterface,SIGNAL(newDeviceAdded(QString)),this,SLOT(deviceAdded(QString)));
Q_FOREACH(const QString& id, deviceIds) { Q_FOREACH(const QString& id, deviceIds) {
deviceAdded(id); deviceAdded(id);
} }
connect(m_dbusInterface,SIGNAL(deviceStatusChanged(QString)),this,SLOT(deviceStatusChanged(QString)));
//connect(m_dbusInterface,SIGNAL(deviceRemoved(QString)),this,SLOT(deviceRemoved(QString));
}
DevicesModel::~DevicesModel() connect(m_dbusInterface,SIGNAL(deviceAdded(QString)),this,SLOT(deviceAdded(QString)));
{ connect(m_dbusInterface,SIGNAL(deviceVisibilityChanged(QString,bool)),this,SLOT(deviceStatusChanged(QString)));
connect(m_dbusInterface,SIGNAL(deviceRemoved(QString)),this,SLOT(deviceRemoved(QString)));
} }
void DevicesModel::deviceStatusChanged(const QString& id) DevicesModel::~DevicesModel()
{ {
Q_UNUSED(id);
qDebug() << "deviceStatusChanged";
emit dataChanged(index(0),index(rowCount()));
} }
void DevicesModel::deviceAdded(const QString& id) void DevicesModel::deviceAdded(const QString& id)
...@@ -60,8 +54,26 @@ void DevicesModel::deviceAdded(const QString& id) ...@@ -60,8 +54,26 @@ void DevicesModel::deviceAdded(const QString& id)
endInsertRows(); endInsertRows();
*/ */
//Full refresh
Q_UNUSED(id); Q_UNUSED(id);
refreshDeviceList();
}
void DevicesModel::deviceRemoved(const QString& id)
{
Q_UNUSED(id);
refreshDeviceList();
}
void DevicesModel::deviceStatusChanged(const QString& id)
{
Q_UNUSED(id);
emit dataChanged(index(0),index(rowCount()));
}
void DevicesModel::refreshDeviceList()
{
if (m_deviceList.count() > 0) { if (m_deviceList.count() > 0) {
beginRemoveRows(QModelIndex(), 0, m_deviceList.count() - 1); beginRemoveRows(QModelIndex(), 0, m_deviceList.count() - 1);
m_deviceList.clear(); m_deviceList.clear();
...@@ -75,7 +87,6 @@ void DevicesModel::deviceAdded(const QString& id) ...@@ -75,7 +87,6 @@ void DevicesModel::deviceAdded(const QString& id)
} }
} }
/* /*
bool DevicesModel::insertRows(int row, int count, const QModelIndex &parent) bool DevicesModel::insertRows(int row, int count, const QModelIndex &parent)
{ {
......
...@@ -56,6 +56,8 @@ public Q_SLOTS: ...@@ -56,6 +56,8 @@ public Q_SLOTS:
private Q_SLOTS: private Q_SLOTS:
void deviceAdded(const QString& id); void deviceAdded(const QString& id);
void deviceRemoved(const QString& id);
void refreshDeviceList();
private: private:
DaemonDbusInterface* m_dbusInterface; DaemonDbusInterface* m_dbusInterface;
......
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