Initial commit
This commit is contained in:
commit
4d3fe4406f
32 changed files with 1346 additions and 0 deletions
9
.gitignore
vendored
Normal file
9
.gitignore
vendored
Normal file
|
@ -0,0 +1,9 @@
|
||||||
|
build
|
||||||
|
android-shine.kdev4
|
||||||
|
Makefile
|
||||||
|
lib
|
||||||
|
src/Makefile
|
||||||
|
src/*_automoc.cpp*
|
||||||
|
src/moc_*.cpp
|
||||||
|
CMakeTmp
|
||||||
|
CMakeFiles
|
8
CMakeLists.txt
Normal file
8
CMakeLists.txt
Normal file
|
@ -0,0 +1,8 @@
|
||||||
|
project(androidshine)
|
||||||
|
|
||||||
|
find_package(KDE4 REQUIRED)
|
||||||
|
|
||||||
|
include(KDE4Defaults)
|
||||||
|
include_directories(${KDE4_INCLUDES})
|
||||||
|
|
||||||
|
add_subdirectory(src)
|
25
letsgo.sh
Executable file
25
letsgo.sh
Executable file
|
@ -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
|
||||||
|
|
||||||
|
|
17
src/CMakeLists.txt
Normal file
17
src/CMakeLists.txt
Normal file
|
@ -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)
|
13
src/androidshine.desktop
Normal file
13
src/androidshine.desktop
Normal file
|
@ -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
|
94
src/androidshine.notifyrc
Normal file
94
src/androidshine.notifyrc
Normal file
|
@ -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
|
52
src/bonjourdevicelocator.cpp
Normal file
52
src/bonjourdevicelocator.cpp
Normal file
|
@ -0,0 +1,52 @@
|
||||||
|
/**
|
||||||
|
* 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 "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<Device*> BonjourDeviceLocator::discover() {
|
||||||
|
QVector<Device*> devices;
|
||||||
|
return devices;
|
||||||
|
}
|
44
src/bonjourdevicelocator.h
Normal file
44
src/bonjourdevicelocator.h
Normal file
|
@ -0,0 +1,44 @@
|
||||||
|
/**
|
||||||
|
* 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 BONJOURDEVICELOCATOR_H
|
||||||
|
#define BONJOURDEVICELOCATOR_H
|
||||||
|
|
||||||
|
#include <QObject>
|
||||||
|
|
||||||
|
#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<Device*> discover();
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // BONJOURDEVICELOCATOR_H
|
91
src/daemon.cpp
Normal file
91
src/daemon.cpp
Normal file
|
@ -0,0 +1,91 @@
|
||||||
|
/**
|
||||||
|
* 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 "daemon.h"
|
||||||
|
#include "networkpackage.h"
|
||||||
|
#include "notificationpackagereceiver.h"
|
||||||
|
#include "pausemusicpackagereceiver.h"
|
||||||
|
#include "bonjourdevicelocator.h"
|
||||||
|
#include "fakedevicelocator.h"
|
||||||
|
|
||||||
|
#include <QtNetwork/QUdpSocket>
|
||||||
|
#include <QFile>
|
||||||
|
|
||||||
|
#include <KDE/KIcon>
|
||||||
|
|
||||||
|
#include <iostream>
|
||||||
|
|
||||||
|
K_PLUGIN_FACTORY(AndroidShineFactory,
|
||||||
|
registerPlugin<Daemon>();)
|
||||||
|
K_EXPORT_PLUGIN(AndroidShineFactory("androidshine", "androidshine"))
|
||||||
|
|
||||||
|
|
||||||
|
Daemon::Daemon(QObject *parent, const QList<QVariant>&)
|
||||||
|
: 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";
|
||||||
|
|
||||||
|
}
|
71
src/daemon.h
Normal file
71
src/daemon.h
Normal file
|
@ -0,0 +1,71 @@
|
||||||
|
/**
|
||||||
|
* 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 DAEMON_H
|
||||||
|
#define DAEMON_H
|
||||||
|
|
||||||
|
#include <QObject>
|
||||||
|
#include <QRegExp>
|
||||||
|
#include <map>
|
||||||
|
|
||||||
|
#include <KDE/KDEDModule>
|
||||||
|
#include <KDE/KNotification>
|
||||||
|
|
||||||
|
#include "networkpackage.h"
|
||||||
|
#include <KDE/KPluginFactory>
|
||||||
|
#include <QFile>
|
||||||
|
#include <qtextstream.h>
|
||||||
|
|
||||||
|
#include <QSet>
|
||||||
|
|
||||||
|
#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<QVariant>&);
|
||||||
|
~Daemon();
|
||||||
|
|
||||||
|
private:
|
||||||
|
|
||||||
|
//All known devices (read from/stored to settings)
|
||||||
|
QVector<Device*> pairedDevices;
|
||||||
|
|
||||||
|
//Currently connected devices
|
||||||
|
QVector<DeviceLink*> linkedDevices;
|
||||||
|
|
||||||
|
//Different ways to find new devices and connect to them, ordered by priority
|
||||||
|
QSet<DeviceLocator*> deviceLocators;
|
||||||
|
|
||||||
|
//Everybody who wants to be notified about a new package
|
||||||
|
QVector<PackageReceiver*> packageReceivers;
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // UDP_WIRELESS_H
|
45
src/device.h
Normal file
45
src/device.h
Normal file
|
@ -0,0 +1,45 @@
|
||||||
|
/**
|
||||||
|
* 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 DEVICE_H
|
||||||
|
#define DEVICE_H
|
||||||
|
|
||||||
|
#include <QString>
|
||||||
|
|
||||||
|
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
|
25
src/devicelink.cpp
Normal file
25
src/devicelink.cpp
Normal file
|
@ -0,0 +1,25 @@
|
||||||
|
/**
|
||||||
|
* 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 "devicelink.h"
|
||||||
|
|
||||||
|
DeviceLink::DeviceLink() {
|
||||||
|
//gcc complains if we don't add something to compile on a class with virtual functions
|
||||||
|
}
|
43
src/devicelink.h
Normal file
43
src/devicelink.h
Normal file
|
@ -0,0 +1,43 @@
|
||||||
|
/**
|
||||||
|
* 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 DEVICELINK_H
|
||||||
|
#define DEVICELINK_H
|
||||||
|
|
||||||
|
#include <QObject>
|
||||||
|
|
||||||
|
#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
|
25
src/devicelocator.cpp
Normal file
25
src/devicelocator.cpp
Normal file
|
@ -0,0 +1,25 @@
|
||||||
|
/**
|
||||||
|
* 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 "devicelocator.h"
|
||||||
|
|
||||||
|
DeviceLocator::DeviceLocator() {
|
||||||
|
//gcc complains if we don't add something to compile on a class with virtual functions
|
||||||
|
}
|
53
src/devicelocator.h
Normal file
53
src/devicelocator.h
Normal file
|
@ -0,0 +1,53 @@
|
||||||
|
/**
|
||||||
|
* 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 DEVICELOCATOR_H
|
||||||
|
#define DEVICELOCATOR_H
|
||||||
|
|
||||||
|
#include <qvector.h>
|
||||||
|
#include <QObject>
|
||||||
|
|
||||||
|
#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<Device*> discover() = 0;
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // DEVICELOCATOR_H
|
21
src/echodevicelink.cpp
Normal file
21
src/echodevicelink.cpp
Normal file
|
@ -0,0 +1,21 @@
|
||||||
|
/**
|
||||||
|
* 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 "echodevicelink.h"
|
36
src/echodevicelink.h
Normal file
36
src/echodevicelink.h
Normal file
|
@ -0,0 +1,36 @@
|
||||||
|
/**
|
||||||
|
* 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 ECHODEVICELINK_H
|
||||||
|
#define ECHODEVICELINK_H
|
||||||
|
#include "devicelink.h"
|
||||||
|
|
||||||
|
class EchoDeviceLink
|
||||||
|
: public DeviceLink
|
||||||
|
{
|
||||||
|
|
||||||
|
public:
|
||||||
|
void sendPackage(const NetworkPackage& np) {
|
||||||
|
emit receivedPackage(np);
|
||||||
|
}
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // ECHODEVICELINK_H
|
49
src/fakedevicelocator.cpp
Normal file
49
src/fakedevicelocator.cpp
Normal file
|
@ -0,0 +1,49 @@
|
||||||
|
/**
|
||||||
|
* 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 "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<Device*> FakeDeviceLocator::discover() {
|
||||||
|
QVector<Device*> devices;
|
||||||
|
devices.append(new Device("fake","Fake device"));
|
||||||
|
return devices;
|
||||||
|
}
|
37
src/fakedevicelocator.h
Normal file
37
src/fakedevicelocator.h
Normal file
|
@ -0,0 +1,37 @@
|
||||||
|
/**
|
||||||
|
* 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 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<Device*> discover();
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // FAKEDEVICELOCATOR_H
|
66
src/networkpackage.cpp
Normal file
66
src/networkpackage.cpp
Normal file
|
@ -0,0 +1,66 @@
|
||||||
|
/**
|
||||||
|
* 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 "networkpackage.h"
|
||||||
|
#include <qbytearray.h>
|
||||||
|
#include <qdatastream.h>
|
||||||
|
#include <QDebug>
|
||||||
|
#include <sstream>
|
||||||
|
#include <string>
|
||||||
|
#include <iostream>
|
||||||
|
|
||||||
|
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;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
51
src/networkpackage.h
Normal file
51
src/networkpackage.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 NETWORKPACKAGE_H
|
||||||
|
#define NETWORKPACKAGE_H
|
||||||
|
|
||||||
|
#include <QString>
|
||||||
|
#include <QVariant>
|
||||||
|
|
||||||
|
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
|
97
src/notificationpackagereceiver.cpp
Normal file
97
src/notificationpackagereceiver.cpp
Normal file
|
@ -0,0 +1,97 @@
|
||||||
|
/**
|
||||||
|
* 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 "notificationpackagereceiver.h"
|
||||||
|
|
||||||
|
#include <kicon.h>
|
||||||
|
|
||||||
|
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;
|
||||||
|
|
||||||
|
|
||||||
|
}
|
41
src/notificationpackagereceiver.h
Normal file
41
src/notificationpackagereceiver.h
Normal file
|
@ -0,0 +1,41 @@
|
||||||
|
/**
|
||||||
|
* 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 NOTIFICATIONPACKAGERECEIVER_H
|
||||||
|
#define NOTIFICATIONPACKAGERECEIVER_H
|
||||||
|
|
||||||
|
#include <knotification.h>
|
||||||
|
|
||||||
|
#include "packagereceiver.h"
|
||||||
|
|
||||||
|
class NotificationPackageReceiver
|
||||||
|
: public PackageReceiver
|
||||||
|
{
|
||||||
|
|
||||||
|
public:
|
||||||
|
virtual bool receivePackage(const NetworkPackage& np);
|
||||||
|
|
||||||
|
private:
|
||||||
|
static KNotification* createNotification(const NetworkPackage& np);
|
||||||
|
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // NOTIFICATIONPACKAGERECEIVER_H
|
25
src/packagereceiver.cpp
Normal file
25
src/packagereceiver.cpp
Normal file
|
@ -0,0 +1,25 @@
|
||||||
|
/**
|
||||||
|
* 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 "packagereceiver.h"
|
||||||
|
|
||||||
|
PackageReceiver::PackageReceiver() {
|
||||||
|
//gcc complains if we don't add something to compile on a class with virtual functions
|
||||||
|
}
|
42
src/packagereceiver.h
Normal file
42
src/packagereceiver.h
Normal file
|
@ -0,0 +1,42 @@
|
||||||
|
/**
|
||||||
|
* 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 PACKAGERECEIVER_H
|
||||||
|
#define PACKAGERECEIVER_H
|
||||||
|
|
||||||
|
#include <QObject>
|
||||||
|
|
||||||
|
#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
|
44
src/pausemusicpackagereceiver.cpp
Normal file
44
src/pausemusicpackagereceiver.cpp
Normal file
|
@ -0,0 +1,44 @@
|
||||||
|
/**
|
||||||
|
* 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 "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;
|
||||||
|
|
||||||
|
}
|
38
src/pausemusicpackagereceiver.h
Normal file
38
src/pausemusicpackagereceiver.h
Normal file
|
@ -0,0 +1,38 @@
|
||||||
|
/**
|
||||||
|
* 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 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
|
52
src/udpdevicelink.cpp
Normal file
52
src/udpdevicelink.cpp
Normal file
|
@ -0,0 +1,52 @@
|
||||||
|
/**
|
||||||
|
* 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 "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);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
52
src/udpdevicelink.h
Normal file
52
src/udpdevicelink.h
Normal file
|
@ -0,0 +1,52 @@
|
||||||
|
/**
|
||||||
|
* 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 UDPDEVICELINK_H
|
||||||
|
#define UDPDEVICELINK_H
|
||||||
|
|
||||||
|
#include <QObject>
|
||||||
|
#include <QString>
|
||||||
|
|
||||||
|
#include "devicelink.h"
|
||||||
|
#include <qudpsocket.h>
|
||||||
|
|
||||||
|
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
|
0
test/CMakeLists.txt
Normal file
0
test/CMakeLists.txt
Normal file
44
test/backendtests.cpp
Normal file
44
test/backendtests.cpp
Normal file
|
@ -0,0 +1,44 @@
|
||||||
|
/*
|
||||||
|
* Copyright 2013 <copyright holder> <email>
|
||||||
|
*
|
||||||
|
* 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_kde.h>
|
||||||
|
|
||||||
|
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"
|
36
test/backendtests.h
Normal file
36
test/backendtests.h
Normal file
|
@ -0,0 +1,36 @@
|
||||||
|
/*
|
||||||
|
* Copyright 2013 <copyright holder> <email>
|
||||||
|
*
|
||||||
|
* 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 <QObject>
|
||||||
|
|
||||||
|
class BackendTests : public QObject
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
|
||||||
|
private Q_SLOTS:
|
||||||
|
void initTestCase();
|
||||||
|
void cleanupTestCase();
|
||||||
|
|
||||||
|
void init();
|
||||||
|
void cleanup();
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // BACKENDTESTS_H
|
Loading…
Reference in a new issue