diff --git a/src/plugins/CMakeLists.txt b/src/plugins/CMakeLists.txt --- a/src/plugins/CMakeLists.txt +++ b/src/plugins/CMakeLists.txt @@ -52,3 +52,4 @@ add_subdirectory(phabricator) add_subdirectory(email) add_subdirectory(telegram) +add_subdirectory(bluetooth) diff --git a/src/plugins/bluetooth/CMakeLists.txt b/src/plugins/bluetooth/CMakeLists.txt new file mode 100644 --- /dev/null +++ b/src/plugins/bluetooth/CMakeLists.txt @@ -0,0 +1 @@ +add_share_plugin(bluetoothplugin bluetoothplugin.cpp) diff --git a/src/plugins/bluetooth/Messages.sh b/src/plugins/bluetooth/Messages.sh new file mode 100644 --- /dev/null +++ b/src/plugins/bluetooth/Messages.sh @@ -0,0 +1,4 @@ +#!/bin/sh +$EXTRACTRC `find . -name \*.rc` `find . -name \*.ui` >> rc.cpp +$XGETTEXT `find . -not -path \*/tests/\* -name \*.cpp -o -name \*.cc -o -name \*.h` -o $podir/purpose_bluetooth.pot +rm -f rc.cpp diff --git a/src/plugins/bluetooth/bluetoothplugin.cpp b/src/plugins/bluetooth/bluetoothplugin.cpp new file mode 100644 --- /dev/null +++ b/src/plugins/bluetooth/bluetoothplugin.cpp @@ -0,0 +1,95 @@ +/* + Copyright 2014 Aleix Pol Gonzalez + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library 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 + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library. If not, see . +*/ + +#include +#include +#include +#include +#include + +EXPORT_SHARE_VERSION + +class BluetoothJob : public Purpose::Job +{ + Q_OBJECT + public: + BluetoothJob(QObject* parent) + : Purpose::Job(parent) + {} + + QStringList arrayToList(const QJsonArray& array) + { + QStringList ret; + foreach(const QJsonValue& val, array) { + QUrl url(val.toString()); + if(url.isLocalFile()) { + ret += url.toLocalFile(); + } + } + return ret; + } + + void start() override + { + QProcess* process = new QProcess(this); + process->setProgram(QStringLiteral("bluedevil-sendfile")); + QJsonArray urlsJson = data().value(QStringLiteral("urls")).toArray(); + process->setArguments(QStringList(QStringLiteral("-u")) << data().value(QStringLiteral("device")).toString() << QStringLiteral("-f") << arrayToList(urlsJson)); + connect(process, &QProcess::errorOccurred, this, &BluetoothJob::processError); + connect(process, QOverload::of(&QProcess::finished), this, &BluetoothJob::jobFinished); + connect(process, &QProcess::readyRead, this, [process](){ qDebug() << "bluedevil-sendfile output:" << process->readAll(); }); + + process->start(); + } + + void processError(QProcess::ProcessError error) + { + QProcess* process = qobject_cast(sender()); + qWarning() << "bluetooth share error:" << error << process->errorString(); + setError(1 + error); + setErrorText(process->errorString()); + emitResult(); + } + + void jobFinished(int code, QProcess::ExitStatus status) + { + if (status != QProcess::NormalExit) + qWarning() << "bluedevil-sendfile crashed"; + + setError(code); + setOutput( {{ QStringLiteral("url"), QString() }}); + emitResult(); + } + + private: +}; + +class Q_DECL_EXPORT BluetoothPlugin : public Purpose::PluginBase +{ + Q_OBJECT + public: + BluetoothPlugin(QObject* p, const QVariantList& ) : Purpose::PluginBase(p) {} + + Purpose::Job* createJob() const override + { + return new BluetoothJob(nullptr); + } +}; + +K_PLUGIN_FACTORY_WITH_JSON(Bluetooth, "bluetoothplugin.json", registerPlugin();) + +#include "bluetoothplugin.moc" diff --git a/src/plugins/bluetooth/bluetoothplugin.json b/src/plugins/bluetooth/bluetoothplugin.json new file mode 100644 --- /dev/null +++ b/src/plugins/bluetooth/bluetoothplugin.json @@ -0,0 +1,23 @@ +{ + "KPlugin": { + "Authors": [ + { + "Name": "Nicolas Fella", + "Name[x-test]": "xxNicolas Fellaxx" + } + ], + "Category": "Utilities", + "Description": "Send via Bluetooth", + "Icon": "preferences-system-bluetooth", + "License": "GPL", + "Name": "Send via Bluetooth..." + }, + "X-Purpose-Configuration": [ + "device" + ], + "X-Purpose-Constraints": [ + ], + "X-Purpose-PluginTypes": [ + "Export" + ] +} diff --git a/src/plugins/bluetooth/bluetoothplugin_config.qml b/src/plugins/bluetooth/bluetoothplugin_config.qml new file mode 100644 --- /dev/null +++ b/src/plugins/bluetooth/bluetoothplugin_config.qml @@ -0,0 +1,51 @@ +/* + Copyright 2014 Aleix Pol Gonzalez + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library 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 + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library. If not, see . +*/ + +import QtQuick 2.1 +import QtQuick.Layouts 1.1 +import QtQuick.Controls 2.1 + +import org.kde.bluezqt 1.0 as BluezQt + +ListView { + id: root + property string device: "" + Layout.fillWidth: true + Layout.fillHeight: true + + header: Label { + text: i18n("Choose a device to send to:") + visible: root.count !== 0 + } + model: BluezQt.DevicesModel { } + + delegate: ItemDelegate { + width: parent.width + text: Name + onClicked: root.device = Ubi + checked: root.device === Ubi + highlighted: root.device === Ubi + } + + Label { + anchors.fill: parent + verticalAlignment: Qt.AlignVCenter + horizontalAlignment: Qt.AlignHCenter + visible: root.count === 0 + text: i18n("No devices found") + } +}