2013-06-06 04:57:06 +01:00
|
|
|
/**
|
|
|
|
* 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"
|
2013-06-17 11:23:08 +01:00
|
|
|
#include "avahidevicelocator.h"
|
2013-06-06 04:57:06 +01:00
|
|
|
#include "fakedevicelocator.h"
|
|
|
|
|
|
|
|
#include <QtNetwork/QUdpSocket>
|
|
|
|
#include <QFile>
|
|
|
|
|
|
|
|
#include <KDE/KIcon>
|
|
|
|
|
2013-06-17 11:23:08 +01:00
|
|
|
#include <sstream>
|
|
|
|
#include <iomanip>
|
2013-06-06 04:57:06 +01:00
|
|
|
#include <iostream>
|
|
|
|
|
2013-06-17 11:23:08 +01:00
|
|
|
K_PLUGIN_FACTORY(AndroidShineFactory, registerPlugin<Daemon>();)
|
2013-06-06 04:57:06 +01:00
|
|
|
K_EXPORT_PLUGIN(AndroidShineFactory("androidshine", "androidshine"))
|
|
|
|
|
2013-06-17 11:23:08 +01:00
|
|
|
DeviceLink* Daemon::linkTo(QString id) {
|
|
|
|
|
|
|
|
DeviceLink* link = NULL;
|
|
|
|
|
|
|
|
Q_FOREACH (DeviceLocator* locator, deviceLocators) {
|
|
|
|
if (locator->canLink(id)) {
|
|
|
|
link = locator->link(id);
|
|
|
|
if (link != NULL) break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (link != NULL) {
|
|
|
|
|
|
|
|
linkedDevices.append(link);
|
|
|
|
|
|
|
|
Q_FOREACH (PackageReceiver* pr, packageReceivers) {
|
|
|
|
QObject::connect(link,SIGNAL(receivedPackage(const NetworkPackage&)),
|
|
|
|
pr,SLOT(receivePackage(const NetworkPackage&)));
|
|
|
|
}
|
|
|
|
|
|
|
|
} else {
|
|
|
|
qDebug() << "Could not link device id " + id;
|
|
|
|
}
|
|
|
|
|
|
|
|
return link;
|
|
|
|
|
|
|
|
}
|
2013-06-06 04:57:06 +01:00
|
|
|
|
|
|
|
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
|
2013-06-17 11:23:08 +01:00
|
|
|
deviceLocators.insert(new AvahiDeviceLocator());
|
2013-06-06 04:57:06 +01:00
|
|
|
deviceLocators.insert(new FakeDeviceLocator());
|
|
|
|
|
|
|
|
//TODO: Read paired devices from config
|
|
|
|
pairedDevices.push_back(new Device("MyAndroid","MyAndroid"));
|
|
|
|
|
2013-06-17 11:23:08 +01:00
|
|
|
//At boot time, try to link to all paired devices
|
|
|
|
Q_FOREACH (Device* device, pairedDevices) {
|
|
|
|
linkTo(device->id());
|
|
|
|
}
|
2013-06-06 04:57:06 +01:00
|
|
|
|
2013-06-17 11:23:08 +01:00
|
|
|
}
|
2013-06-06 04:57:06 +01:00
|
|
|
|
|
|
|
|
2013-06-17 11:23:08 +01:00
|
|
|
QString Daemon::listVisibleDevices()
|
|
|
|
{
|
2013-06-06 04:57:06 +01:00
|
|
|
|
2013-06-17 11:23:08 +01:00
|
|
|
std::stringstream ret;
|
2013-06-06 04:57:06 +01:00
|
|
|
|
2013-06-17 11:23:08 +01:00
|
|
|
ret << std::setw(20) << "ID";
|
|
|
|
ret << std::setw(20) << "Name";
|
|
|
|
ret << std::setw(20) << "Source";
|
|
|
|
ret << std::endl;
|
2013-06-06 04:57:06 +01:00
|
|
|
|
2013-06-17 11:23:08 +01:00
|
|
|
QList<Device*> visibleDevices;
|
2013-06-06 04:57:06 +01:00
|
|
|
|
2013-06-17 11:23:08 +01:00
|
|
|
foreach (DeviceLocator* dl, deviceLocators) {
|
|
|
|
foreach (Device* d, dl->discover()) {
|
|
|
|
ret << std::setw(20) << d->id().toStdString();
|
|
|
|
ret << std::setw(20) << d->name().toStdString();
|
|
|
|
ret << std::setw(20) << dl->getName().toStdString();
|
|
|
|
ret << std::endl;
|
2013-06-06 04:57:06 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-06-17 11:23:08 +01:00
|
|
|
return QString::fromStdString(ret.str());
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Daemon::linkDevice(QString id)
|
|
|
|
{
|
|
|
|
|
|
|
|
return linkTo(id);
|
|
|
|
|
2013-06-06 04:57:06 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
Daemon::~Daemon()
|
|
|
|
{
|
|
|
|
qDebug() << "SAYONARA BABY";
|
|
|
|
|
|
|
|
}
|
2013-06-17 11:23:08 +01:00
|
|
|
|