From 4d3fe4406fda810b2924cbc7c413cf0492233343 Mon Sep 17 00:00:00 2001 From: Albert Vaca Date: Thu, 6 Jun 2013 05:57:06 +0200 Subject: [PATCH] Initial commit --- .gitignore | 9 +++ CMakeLists.txt | 8 +++ letsgo.sh | 25 ++++++++ src/CMakeLists.txt | 17 +++++ src/androidshine.desktop | 13 ++++ src/androidshine.notifyrc | 94 ++++++++++++++++++++++++++++ src/bonjourdevicelocator.cpp | 52 ++++++++++++++++ src/bonjourdevicelocator.h | 44 +++++++++++++ src/daemon.cpp | 91 +++++++++++++++++++++++++++ src/daemon.h | 71 +++++++++++++++++++++ src/device.h | 45 +++++++++++++ src/devicelink.cpp | 25 ++++++++ src/devicelink.h | 43 +++++++++++++ src/devicelocator.cpp | 25 ++++++++ src/devicelocator.h | 53 ++++++++++++++++ src/echodevicelink.cpp | 21 +++++++ src/echodevicelink.h | 36 +++++++++++ src/fakedevicelocator.cpp | 49 +++++++++++++++ src/fakedevicelocator.h | 37 +++++++++++ src/networkpackage.cpp | 66 ++++++++++++++++++++ src/networkpackage.h | 51 +++++++++++++++ src/notificationpackagereceiver.cpp | 97 +++++++++++++++++++++++++++++ src/notificationpackagereceiver.h | 41 ++++++++++++ src/packagereceiver.cpp | 25 ++++++++ src/packagereceiver.h | 42 +++++++++++++ src/pausemusicpackagereceiver.cpp | 44 +++++++++++++ src/pausemusicpackagereceiver.h | 38 +++++++++++ src/udpdevicelink.cpp | 52 ++++++++++++++++ src/udpdevicelink.h | 52 ++++++++++++++++ test/CMakeLists.txt | 0 test/backendtests.cpp | 44 +++++++++++++ test/backendtests.h | 36 +++++++++++ 32 files changed, 1346 insertions(+) create mode 100644 .gitignore create mode 100644 CMakeLists.txt create mode 100755 letsgo.sh create mode 100644 src/CMakeLists.txt create mode 100644 src/androidshine.desktop create mode 100644 src/androidshine.notifyrc create mode 100644 src/bonjourdevicelocator.cpp create mode 100644 src/bonjourdevicelocator.h create mode 100644 src/daemon.cpp create mode 100644 src/daemon.h create mode 100644 src/device.h create mode 100644 src/devicelink.cpp create mode 100644 src/devicelink.h create mode 100644 src/devicelocator.cpp create mode 100644 src/devicelocator.h create mode 100644 src/echodevicelink.cpp create mode 100644 src/echodevicelink.h create mode 100644 src/fakedevicelocator.cpp create mode 100644 src/fakedevicelocator.h create mode 100644 src/networkpackage.cpp create mode 100644 src/networkpackage.h create mode 100644 src/notificationpackagereceiver.cpp create mode 100644 src/notificationpackagereceiver.h create mode 100644 src/packagereceiver.cpp create mode 100644 src/packagereceiver.h create mode 100644 src/pausemusicpackagereceiver.cpp create mode 100644 src/pausemusicpackagereceiver.h create mode 100644 src/udpdevicelink.cpp create mode 100644 src/udpdevicelink.h create mode 100644 test/CMakeLists.txt create mode 100644 test/backendtests.cpp create mode 100644 test/backendtests.h diff --git a/.gitignore b/.gitignore new file mode 100644 index 000000000..506dca6d3 --- /dev/null +++ b/.gitignore @@ -0,0 +1,9 @@ +build +android-shine.kdev4 +Makefile +lib +src/Makefile +src/*_automoc.cpp* +src/moc_*.cpp +CMakeTmp +CMakeFiles diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 000000000..a2bf84983 --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,8 @@ +project(androidshine) + +find_package(KDE4 REQUIRED) + +include(KDE4Defaults) +include_directories(${KDE4_INCLUDES}) + +add_subdirectory(src) diff --git a/letsgo.sh b/letsgo.sh new file mode 100755 index 000000000..d09127e44 --- /dev/null +++ b/letsgo.sh @@ -0,0 +1,25 @@ +#!/bin/sh + +. ~/.bashrc + +KDE_BUILD_CONFIRMATION=false + +cs android-connect + +if kdebuild; then + + + killall kded4 + while killall -9 kded4; do + true + done + + #qdbus org.kde.kded /kded unloadModule androidshine + #qdbus org.kde.kded /kded loadModule androidshine + kded4 2>&1 | grep -v "^kded(" & + + echo "" + +fi + + diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt new file mode 100644 index 000000000..6498c92b1 --- /dev/null +++ b/src/CMakeLists.txt @@ -0,0 +1,17 @@ +set(kded_androidshine_SRCS fakedevicelocator.cpp echodevicelink.cpp udpdevicelink.cpp bonjourdevicelocator.cpp pausemusicpackagereceiver.cpp notificationpackagereceiver.cpp networkpackage.cpp + daemon.cpp devicelink.cpp devicelocator.cpp packagereceiver.cpp +) + +kde4_add_plugin(kded_androidshine + ${kded_androidshine_SRCS} +) + +target_link_libraries(kded_androidshine + ${KDE4_KDECORE_LIBS} + ${KDE4_KDEUI_LIBS} + ${QT_QTNETWORK_LIBRARY} +) + +install(TARGETS kded_androidshine DESTINATION ${PLUGIN_INSTALL_DIR}) +install(FILES androidshine.desktop DESTINATION ${SERVICES_INSTALL_DIR}/kded) +install(FILES androidshine.notifyrc DESTINATION ${DATA_INSTALL_DIR}/androidshine) \ No newline at end of file diff --git a/src/androidshine.desktop b/src/androidshine.desktop new file mode 100644 index 000000000..985c5f07e --- /dev/null +++ b/src/androidshine.desktop @@ -0,0 +1,13 @@ +[Desktop Entry] +Type=Service +Icon=preferences-system-power-management +X-KDE-ServiceTypes=KDEDModule +X-KDE-Library=androidshine +X-KDE-DBus-ModuleName=androidshine +X-KDE-Kded-autoload=true +X-KDE-Kded-load-on-demand=false +X-KDE-Kded-phase=1 + +Name=Android shine + +Comment=Android shiny backend diff --git a/src/androidshine.notifyrc b/src/androidshine.notifyrc new file mode 100644 index 000000000..942e3d340 --- /dev/null +++ b/src/androidshine.notifyrc @@ -0,0 +1,94 @@ +[Global] +IconName=pda +Name=Android Shine +Comment=Android Shine + +[Event/callReceived] +Name=Calling +Comment=Someone is calling you +Action=Popup + +[Event/missedCall] +Name=Missed +Comment=You have a missed call +Action=Popup + +[Event/smsReceived] +Name=SMS +Comment=Someone sent you a SMS +Action=Popup + +[Event/mmsReceived] +Name=MMS +Comment=Someone sent you a MMS +Action=Popup + +[Event/batteryLow] +Name=Battery +Comment=Your battery is in low state (Discharging) +Action=Popup + +[Event/batteryCaution] +Name=Battery +Comment=Your battery is in caution state (Discharging) +Action=Popup + +[Event/battery040] +Name=Battery +Comment=Your battery is at 40% (Discharging) +Action=Popup + +[Event/battery060] +Name=Battery +Comment=Your battery is at 60% (Discharging) +Action=Popup + +[Event/battery080] +Name=Battery +Comment=Your battery is at 80% (Discharging) +Action=Popup + +[Event/battery100] +Name=Battery +Comment=Your battery is at 100% (Discharging) +Action=Popup + +[Event/batteryChargingLow] +Name=Battery +Comment=Your battery is in low state (Charging) +Action=Popup + +[Event/batteryChargingCaution] +Name=Battery +Comment=Your battery is in caution state (Charging) +Action=Popup + +[Event/batteryCharging040] +Name=Battery +Comment=Your battery is at 40% (Charging) +Action=Popup + +[Event/batteryCharging060] +Name=Battery +Comment=Your battery is at 60% (Charging) +Action=Popup + +[Event/batteryCharging080] +Name=Battery +Comment=Your battery is at 80% (Charging) +Action=Popup + +[Event/batteryCharging100] +Name=Battery +Comment=Your battery is at 100% (Charging) +Action=Popup + +[Event/pingReceived] +Name=Ping +Comment=Ping received +Action=Popup + +[Event/unknownEvent] +Name=Unknown +Comment=Something unknown happened +Action=Popup diff --git a/src/bonjourdevicelocator.cpp b/src/bonjourdevicelocator.cpp new file mode 100644 index 000000000..64d371dd2 --- /dev/null +++ b/src/bonjourdevicelocator.cpp @@ -0,0 +1,52 @@ +/** + * Copyright 2013 Albert Vaca + * + * 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 . + */ + +#include "bonjourdevicelocator.h" + +#include "udpdevicelink.h" + +BonjourDeviceLocator::BonjourDeviceLocator() +{ + +/* + //http://api.kde.org/4.x-api/kdelibs-apidocs/dnssd/html/index.html + DNSSD::ServiceBrowser* browser = new DNSSD::ServiceBrowser("_http._tcp"); + connect(browser, SIGNAL(serviceAdded(RemoteService::Ptr)), + this, SLOT(addService(RemoteService::Ptr))); + connect(browser, SIGNAL(serviceRemoved(RemoteService::Ptr)), + this, SLOT(delService(RemoteService::Ptr))); + browser->startBrowse(); + In above example addService() will +*/ +} + +DeviceLink* BonjourDeviceLocator::link(Device* d) { + DeviceLink* dl = new UdpDeviceLink("192.168.1.48"); + return dl; +} + +bool BonjourDeviceLocator::pair(Device* d) { + return true; +} + +QVector BonjourDeviceLocator::discover() { + QVector devices; + return devices; +} diff --git a/src/bonjourdevicelocator.h b/src/bonjourdevicelocator.h new file mode 100644 index 000000000..dfc1a44ea --- /dev/null +++ b/src/bonjourdevicelocator.h @@ -0,0 +1,44 @@ +/** + * Copyright 2013 Albert Vaca + * + * 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 . + */ + +#ifndef BONJOURDEVICELOCATOR_H +#define BONJOURDEVICELOCATOR_H + +#include + +#include "devicelocator.h" + +class BonjourDeviceLocator + : public DeviceLocator +{ + Q_OBJECT + +public: + BonjourDeviceLocator(); + + Priority getPriority() { return PRIORITY_HIGH; } + bool canLink(Device* d) { return true; } + DeviceLink* link(Device* d); + bool pair(Device* d); + QVector discover(); + +}; + +#endif // BONJOURDEVICELOCATOR_H diff --git a/src/daemon.cpp b/src/daemon.cpp new file mode 100644 index 000000000..2ccd97178 --- /dev/null +++ b/src/daemon.cpp @@ -0,0 +1,91 @@ +/** + * Copyright 2013 Albert Vaca + * + * 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 . + */ + +#include "daemon.h" +#include "networkpackage.h" +#include "notificationpackagereceiver.h" +#include "pausemusicpackagereceiver.h" +#include "bonjourdevicelocator.h" +#include "fakedevicelocator.h" + +#include +#include + +#include + +#include + +K_PLUGIN_FACTORY(AndroidShineFactory, + registerPlugin();) +K_EXPORT_PLUGIN(AndroidShineFactory("androidshine", "androidshine")) + + +Daemon::Daemon(QObject *parent, const QList&) + : KDEDModule(parent) +{ + + qDebug() << "GO GO GO!"; + + + //TODO: Do not hardcode the load of the package receivers + packageReceivers.push_back(new NotificationPackageReceiver()); + packageReceivers.push_back(new PauseMusicPackageReceiver()); + + //TODO: Do not hardcode the load of the device locators + deviceLocators.insert(new BonjourDeviceLocator()); + deviceLocators.insert(new FakeDeviceLocator()); + + //TODO: Read paired devices from config + pairedDevices.push_back(new Device("MyAndroid","MyAndroid")); + + + //Try to link to all paired devices + foreach (Device* device, pairedDevices) { + + DeviceLink* link = NULL; + + foreach (DeviceLocator* locator, deviceLocators) { + + if (locator->canLink(device)) { + link = locator->link(device); + if (link != NULL) break; + } + + } + + if (link != NULL) linkedDevices.append(link); + else qDebug() << "Could not link " + device->name(); + + } + + foreach (DeviceLink* ld, linkedDevices) { + foreach (PackageReceiver* pr, packageReceivers) { + QObject::connect(ld,SIGNAL(receivedPackage(const NetworkPackage&)), + pr,SLOT(receivePackage(const NetworkPackage&))); + } + } + +} + +Daemon::~Daemon() +{ + qDebug() << "SAYONARA BABY"; + +} diff --git a/src/daemon.h b/src/daemon.h new file mode 100644 index 000000000..e83a39c99 --- /dev/null +++ b/src/daemon.h @@ -0,0 +1,71 @@ +/** + * Copyright 2013 Albert Vaca + * + * 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 . + */ + + +#ifndef DAEMON_H +#define DAEMON_H + +#include +#include +#include + +#include +#include + +#include "networkpackage.h" +#include +#include +#include + +#include + +#include "device.h" +#include "packagereceiver.h" +#include "devicelink.h" +#include "devicelocator.h" + +class QUdpSocket; + +class Daemon + : public KDEDModule +{ + Q_OBJECT + +public: + Daemon(QObject *parent, const QList&); + ~Daemon(); + +private: + + //All known devices (read from/stored to settings) + QVector pairedDevices; + + //Currently connected devices + QVector linkedDevices; + + //Different ways to find new devices and connect to them, ordered by priority + QSet deviceLocators; + + //Everybody who wants to be notified about a new package + QVector packageReceivers; + +}; + +#endif // UDP_WIRELESS_H diff --git a/src/device.h b/src/device.h new file mode 100644 index 000000000..4f812b887 --- /dev/null +++ b/src/device.h @@ -0,0 +1,45 @@ +/** + * Copyright 2013 Albert Vaca + * + * 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 . + */ + +#ifndef DEVICE_H +#define DEVICE_H + +#include + +class Device +{ +public: + Device(QString id, QString name) { + mDeviceId = id; + mDeviceName = name; + } + + QString id() { return mDeviceId; } + QString name() { return mDeviceName; } + bool paired() { return mPaired; } + void pair() { mPaired = true; } + +private: + bool mPaired; + QString mDeviceId; + QString mDeviceName; +}; + +#endif // DEVICE_H diff --git a/src/devicelink.cpp b/src/devicelink.cpp new file mode 100644 index 000000000..8d00c081c --- /dev/null +++ b/src/devicelink.cpp @@ -0,0 +1,25 @@ +/** + * Copyright 2013 Albert Vaca + * + * 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 . + */ + +#include "devicelink.h" + +DeviceLink::DeviceLink() { + //gcc complains if we don't add something to compile on a class with virtual functions +} \ No newline at end of file diff --git a/src/devicelink.h b/src/devicelink.h new file mode 100644 index 000000000..ed2a06d4a --- /dev/null +++ b/src/devicelink.h @@ -0,0 +1,43 @@ +/** + * Copyright 2013 Albert Vaca + * + * 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 . + */ + +#ifndef DEVICELINK_H +#define DEVICELINK_H + +#include + +#include "networkpackage.h" + +class DeviceLink + : public QObject +{ + Q_OBJECT + +public: + DeviceLink(); + + virtual void sendPackage(const NetworkPackage& np) = 0; + +signals: + void receivedPackage(const NetworkPackage& np); + +}; + +#endif // DEVICELINK_H diff --git a/src/devicelocator.cpp b/src/devicelocator.cpp new file mode 100644 index 000000000..5f1d45c4e --- /dev/null +++ b/src/devicelocator.cpp @@ -0,0 +1,25 @@ +/** + * Copyright 2013 Albert Vaca + * + * 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 . + */ + +#include "devicelocator.h" + +DeviceLocator::DeviceLocator() { + //gcc complains if we don't add something to compile on a class with virtual functions +} \ No newline at end of file diff --git a/src/devicelocator.h b/src/devicelocator.h new file mode 100644 index 000000000..dc7a81671 --- /dev/null +++ b/src/devicelocator.h @@ -0,0 +1,53 @@ +/** + * Copyright 2013 Albert Vaca + * + * 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 . + */ + +#ifndef DEVICELOCATOR_H +#define DEVICELOCATOR_H + +#include +#include + +#include "devicelink.h" +#include "device.h" + +class DeviceLocator + : public QObject +{ + Q_OBJECT + +public: + DeviceLocator(); + virtual ~DeviceLocator() { } + + enum Priority { + PRIORITY_LOW = 0, //ie: 3g + PRIORITY_MEDIUM = 50, //ie: internet + PRIORITY_HIGH = 100 //ie: lan + }; + + virtual Priority getPriority() = 0; + virtual bool canLink(Device* d) = 0; + virtual DeviceLink* link(Device* d) = 0; + virtual bool pair(Device* d) = 0; + virtual QVector discover() = 0; + +}; + +#endif // DEVICELOCATOR_H diff --git a/src/echodevicelink.cpp b/src/echodevicelink.cpp new file mode 100644 index 000000000..e12b8c0b7 --- /dev/null +++ b/src/echodevicelink.cpp @@ -0,0 +1,21 @@ +/** + * Copyright 2013 Albert Vaca + * + * 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 . + */ + +#include "echodevicelink.h" diff --git a/src/echodevicelink.h b/src/echodevicelink.h new file mode 100644 index 000000000..6f832b026 --- /dev/null +++ b/src/echodevicelink.h @@ -0,0 +1,36 @@ +/** + * Copyright 2013 Albert Vaca + * + * 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 . + */ + +#ifndef ECHODEVICELINK_H +#define ECHODEVICELINK_H +#include "devicelink.h" + +class EchoDeviceLink + : public DeviceLink +{ + +public: + void sendPackage(const NetworkPackage& np) { + emit receivedPackage(np); + } + +}; + +#endif // ECHODEVICELINK_H diff --git a/src/fakedevicelocator.cpp b/src/fakedevicelocator.cpp new file mode 100644 index 000000000..91501f5e6 --- /dev/null +++ b/src/fakedevicelocator.cpp @@ -0,0 +1,49 @@ +/** + * Copyright 2013 Albert Vaca + * + * 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 . + */ + +#include "fakedevicelocator.h" +#include "echodevicelink.h" + +bool FakeDeviceLocator::canLink(Device* d) { + return d->name() == "fake"; +} + +DeviceLink* FakeDeviceLocator::link(Device* d) { + if (d->name() == "fake") { + return new EchoDeviceLink(); + } else { + return NULL; + } +} + +bool FakeDeviceLocator::pair(Device* d) { + if (d->name() != "fake") { + return false; + } else { + d->pair(); + return true; + } +} + +QVector FakeDeviceLocator::discover() { + QVector devices; + devices.append(new Device("fake","Fake device")); + return devices; +} diff --git a/src/fakedevicelocator.h b/src/fakedevicelocator.h new file mode 100644 index 000000000..4210bc689 --- /dev/null +++ b/src/fakedevicelocator.h @@ -0,0 +1,37 @@ +/** + * Copyright 2013 Albert Vaca + * + * 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 . + */ + +#ifndef FAKEDEVICELOCATOR_H +#define FAKEDEVICELOCATOR_H +#include "devicelocator.h" + +class FakeDeviceLocator + : public DeviceLocator +{ +public: + + Priority getPriority() { return PRIORITY_LOW; } + bool canLink(Device* d); + DeviceLink* link(Device* d); + bool pair(Device* d); + QVector discover(); +}; + +#endif // FAKEDEVICELOCATOR_H diff --git a/src/networkpackage.cpp b/src/networkpackage.cpp new file mode 100644 index 000000000..634819647 --- /dev/null +++ b/src/networkpackage.cpp @@ -0,0 +1,66 @@ +/** + * Copyright 2013 Albert Vaca + * + * 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 . + */ + +#include "networkpackage.h" +#include +#include +#include +#include +#include +#include + +NetworkPackage NetworkPackage::fromString(QByteArray s) +{ + + NetworkPackage pp; + + //FIXME: How can I do this using Qt? + std::string stds(std::string(s.data())); + std::cout << stds << std::endl; + + std::stringstream ss(stds); + + ss >> pp.mId; + std::cout << pp.mId << std::endl; + + ss >> pp.mDeviceId; + qDebug() << pp.mDeviceId; + + ss >> pp.mTime; + + std::string type; + ss >> type; + pp.mType = QString::fromStdString(type); + + int bodyLenght; + ss >> bodyLenght; + char c[bodyLenght]; + ss.get(); //Skip ws + ss.read(c,bodyLenght); + pp.mBody = QString::fromAscii(c,bodyLenght); + qDebug() << pp.mBody; + + ss >> pp.mIsCancel; + + return pp; + +} + + diff --git a/src/networkpackage.h b/src/networkpackage.h new file mode 100644 index 000000000..a8bd15214 --- /dev/null +++ b/src/networkpackage.h @@ -0,0 +1,51 @@ +/** + * Copyright 2013 Albert Vaca + * + * 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 . + */ + +#ifndef NETWORKPACKAGE_H +#define NETWORKPACKAGE_H + +#include +#include + +class NetworkPackage +{ + +public: + + static NetworkPackage fromString(QByteArray); + + QString type() const { return mType; } + QString body() const { return mBody; } + long id() const { return mId; } + bool isCancel() const { return mIsCancel; } + +private: + + long mId; + long mDeviceId; + long mTime; + QString mType; + QString mBody; + QVariant mExtra; + bool mIsCancel; + +}; + +#endif // NETWORKPACKAGE_H diff --git a/src/notificationpackagereceiver.cpp b/src/notificationpackagereceiver.cpp new file mode 100644 index 000000000..22b035be5 --- /dev/null +++ b/src/notificationpackagereceiver.cpp @@ -0,0 +1,97 @@ +/** + * Copyright 2013 Albert Vaca + * + * 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 . + */ + +#include "notificationpackagereceiver.h" + +#include + +KNotification* NotificationPackageReceiver::createNotification(const NetworkPackage& np) { + + QString title, type, icon; + + if (np.type() == "RINGING") { + title = "Incoming call"; + type = "callReceived"; + icon = "call-start"; + } else if (np.type() == "MISSED") { + title = "Missed call"; + type = "callMissed"; + icon = "call-start"; + } else if (np.type() == "SMS") { + title = "SMS Received"; + type = "smsReceived"; + icon = "mail-receive"; + } else if (np.type() == "BATTERY") { + title = "Battery status"; + type = "battery100"; + icon = "battery-100"; // Here we need to take all different cases into account. All + // possible steps on battery charge level and state (discharging + // or charging) + } else if (np.type() == "NOTIFY") { + title = "Notification"; + type = "pingReceived"; + icon = "dialog-ok"; + } else if (np.type() == "PING") { + title = "Ping!"; + type = "pingReceived"; + icon = "dialog-ok"; + } else { + //TODO: return if !debug + title = "Unknown"; + type = "unknownEvent"; + icon = "pda"; + } + + + KNotification* notification = new KNotification(type); //KNotification::Persistent + notification->setPixmap(KIcon(icon).pixmap(48, 48)); + notification->setComponentData(KComponentData("androidshine", "androidshine")); + notification->setTitle(title); + notification->setText(np.body()); + + return notification; + +} + +bool NotificationPackageReceiver::receivePackage(const NetworkPackage& np) { + + if (np.isCancel()) { + + //system("qdbus org.mpris.MediaPlayer2.spotify /org/mpris/MediaPlayer2 org.mpris.MediaPlayer2.Player.PlayPause"); + + //It would be awesome to remove the old notification from the system tray here, but there is no way to do it :( + //Now I realize why at the end of the day I have hundreds of notifications from facebook messages that I HAVE ALREADY READ, + //...it's just because the telepathy client has no way to remove them! even when it knows that I have read those messages lol + //Here we have our awesome KDE notifications system, unusable and meant to fuck the user. + + } else { + + KNotification* n = createNotification(np); + n->sendEvent(); + + //system("qdbus org.mpris.MediaPlayer2.spotify /org/mpris/MediaPlayer2 org.mpris.MediaPlayer2.Player.Pause"); + + + } + + return true; + + +} diff --git a/src/notificationpackagereceiver.h b/src/notificationpackagereceiver.h new file mode 100644 index 000000000..cb1117ce6 --- /dev/null +++ b/src/notificationpackagereceiver.h @@ -0,0 +1,41 @@ +/** + * Copyright 2013 Albert Vaca + * + * 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 . + */ + +#ifndef NOTIFICATIONPACKAGERECEIVER_H +#define NOTIFICATIONPACKAGERECEIVER_H + +#include + +#include "packagereceiver.h" + +class NotificationPackageReceiver + : public PackageReceiver +{ + +public: + virtual bool receivePackage(const NetworkPackage& np); + +private: + static KNotification* createNotification(const NetworkPackage& np); + + +}; + +#endif // NOTIFICATIONPACKAGERECEIVER_H diff --git a/src/packagereceiver.cpp b/src/packagereceiver.cpp new file mode 100644 index 000000000..082460f81 --- /dev/null +++ b/src/packagereceiver.cpp @@ -0,0 +1,25 @@ +/** + * Copyright 2013 Albert Vaca + * + * 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 . + */ + +#include "packagereceiver.h" + +PackageReceiver::PackageReceiver() { + //gcc complains if we don't add something to compile on a class with virtual functions +} diff --git a/src/packagereceiver.h b/src/packagereceiver.h new file mode 100644 index 000000000..525b6f448 --- /dev/null +++ b/src/packagereceiver.h @@ -0,0 +1,42 @@ +/** + * Copyright 2013 Albert Vaca + * + * 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 . + */ + +#ifndef PACKAGERECEIVER_H +#define PACKAGERECEIVER_H + +#include + +#include "networkpackage.h" + +class PackageReceiver + : public QObject +{ + Q_OBJECT + +public: + PackageReceiver(); + virtual ~PackageReceiver() { } + +public Q_SLOTS: + //Returns true if it has handled the package in some way + virtual bool receivePackage(const NetworkPackage& np) = 0; +}; + +#endif // PACKAGERECEIVER_H diff --git a/src/pausemusicpackagereceiver.cpp b/src/pausemusicpackagereceiver.cpp new file mode 100644 index 000000000..74fa80059 --- /dev/null +++ b/src/pausemusicpackagereceiver.cpp @@ -0,0 +1,44 @@ +/** + * Copyright 2013 Albert Vaca + * + * 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 . + */ + +#include "pausemusicpackagereceiver.h" + +PauseMusicPackageReceiver::PauseMusicPackageReceiver() +{ + + pauseOnlyAfterAnswering = false; + +} + +bool PauseMusicPackageReceiver::receivePackage ( const NetworkPackage& np ) +{ + + if (np.type() != "RINGING") return false; //TODO: Consider pauseOnlyAfterAnswering + + //TODO: Use KDE DBUS API + if (np.isCancel()) { + system("qdbus org.mpris.MediaPlayer2.spotify /org/mpris/MediaPlayer2 org.mpris.MediaPlayer2.Player.PlayPause"); + } else { + system("qdbus org.mpris.MediaPlayer2.spotify /org/mpris/MediaPlayer2 org.mpris.MediaPlayer2.Player.Pause"); + } + + return true; + +} diff --git a/src/pausemusicpackagereceiver.h b/src/pausemusicpackagereceiver.h new file mode 100644 index 000000000..1f1ff2da0 --- /dev/null +++ b/src/pausemusicpackagereceiver.h @@ -0,0 +1,38 @@ +/** + * Copyright 2013 Albert Vaca + * + * 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 . + */ + +#ifndef PAUSEMUSICPACKAGERECEIVER_H +#define PAUSEMUSICPACKAGERECEIVER_H + +#include "packagereceiver.h" + +class PauseMusicPackageReceiver + : public PackageReceiver +{ +public: + PauseMusicPackageReceiver(); + virtual bool receivePackage(const NetworkPackage& np); + +private: + bool pauseOnlyAfterAnswering; //if set to false it will pause when ringing too + +}; + +#endif // PAUSEMUSICPACKAGERECEIVER_H diff --git a/src/udpdevicelink.cpp b/src/udpdevicelink.cpp new file mode 100644 index 000000000..76dda0829 --- /dev/null +++ b/src/udpdevicelink.cpp @@ -0,0 +1,52 @@ +/** + * Copyright 2013 Albert Vaca + * + * 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 . + */ + +#include "udpdevicelink.h" + + +UdpDeviceLink::UdpDeviceLink(QString ip) +{ + + m_udpSocket = new QUdpSocket(); + m_udpSocket->bind(10600); + connect(m_udpSocket, SIGNAL(readyRead()), this, SLOT(readPendingNotifications())); + +} + +void UdpDeviceLink::readPendingNotifications() +{ + + while (m_udpSocket->hasPendingDatagrams()) { + + QByteArray datagram; + datagram.resize(m_udpSocket->pendingDatagramSize()); + QHostAddress sender; + quint16 senderPort; + m_udpSocket->readDatagram(datagram.data(), datagram.size(), &sender, &senderPort); + + //log.write(datagram); + qDebug() << datagram; + + NetworkPackage np = NetworkPackage::fromString(datagram); + + emit receivedPackage(np); + } + +} diff --git a/src/udpdevicelink.h b/src/udpdevicelink.h new file mode 100644 index 000000000..f41f76865 --- /dev/null +++ b/src/udpdevicelink.h @@ -0,0 +1,52 @@ +/** + * Copyright 2013 Albert Vaca + * + * 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 . + */ + +#ifndef UDPDEVICELINK_H +#define UDPDEVICELINK_H + +#include +#include + +#include "devicelink.h" +#include + +class UdpDeviceLink + : public DeviceLink +{ + Q_OBJECT + +public: + UdpDeviceLink(QString ip); + + void sendPackage(const NetworkPackage& np) { + //TODO: Not implemented + } + + + +private Q_SLOTS: + void readPendingNotifications(); + +private: + QUdpSocket* m_udpSocket; + +}; + +#endif // UDPDEVICELINK_H diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt new file mode 100644 index 000000000..e69de29bb diff --git a/test/backendtests.cpp b/test/backendtests.cpp new file mode 100644 index 000000000..49fdf747b --- /dev/null +++ b/test/backendtests.cpp @@ -0,0 +1,44 @@ +/* + * Copyright 2013 + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +#include "backendtests.h" + +#include + +QTEST_KDEMAIN(BackendTests, NoGUI); + +void BackendTests::initTestCase() +{ + // Called before the first testfunction is executed +} + +void BackendTests::cleanupTestCase() +{ + // Called after the last testfunction was executed +} + +void BackendTests::init() +{ + // Called before each testfunction is executed +} + +void BackendTests::cleanup() +{ + // Called after every testfunction +} + +#include "backendtests.moc" diff --git a/test/backendtests.h b/test/backendtests.h new file mode 100644 index 000000000..92d9eac4a --- /dev/null +++ b/test/backendtests.h @@ -0,0 +1,36 @@ +/* + * Copyright 2013 + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +#ifndef BACKENDTESTS_H +#define BACKENDTESTS_H + +#include + +class BackendTests : public QObject +{ + Q_OBJECT + +private Q_SLOTS: + void initTestCase(); + void cleanupTestCase(); + + void init(); + void cleanup(); + +}; + +#endif // BACKENDTESTS_H