From c8b51fb33944cd757a52355fa43f2ef895338d58 Mon Sep 17 00:00:00 2001 From: Albert Vaca Cintora Date: Mon, 15 Apr 2019 22:36:34 +0200 Subject: [PATCH] Restore FileItemActionPlugin The alternative using puropose is less mature than this and some of us were missing the good old dolphin plugin. This reverts commit a19713fbebe73f6a627a8898ff3738a7dfb36e73. # Conflicts: # CMakeLists.txt --- CMakeLists.txt | 1 + fileitemactionplugin/CMakeLists.txt | 11 +++ fileitemactionplugin/Messages.sh | 3 + .../kdeconnectsendfile.desktop | 88 +++++++++++++++++ fileitemactionplugin/sendfileitemaction.cpp | 99 +++++++++++++++++++ fileitemactionplugin/sendfileitemaction.h | 45 +++++++++ 6 files changed, 247 insertions(+) create mode 100644 fileitemactionplugin/CMakeLists.txt create mode 100644 fileitemactionplugin/Messages.sh create mode 100644 fileitemactionplugin/kdeconnectsendfile.desktop create mode 100644 fileitemactionplugin/sendfileitemaction.cpp create mode 100644 fileitemactionplugin/sendfileitemaction.h diff --git a/CMakeLists.txt b/CMakeLists.txt index f679fe963..f29cc00f6 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -112,6 +112,7 @@ if (NOT SAILFISHOS) add_subdirectory(indicator) add_subdirectory(urlhandler) add_subdirectory(nautilus-extension) + add_subdirectory(fileitemactionplugin) else() add_subdirectory(sfos) endif() diff --git a/fileitemactionplugin/CMakeLists.txt b/fileitemactionplugin/CMakeLists.txt new file mode 100644 index 000000000..d4af2952c --- /dev/null +++ b/fileitemactionplugin/CMakeLists.txt @@ -0,0 +1,11 @@ +add_definitions(-DTRANSLATION_DOMAIN="kdeconnect-fileitemaction") +include_directories(${CMAKE_SOURCE_DIR}) + +add_library(kdeconnectfileitemaction MODULE sendfileitemaction.cpp) +target_link_libraries(kdeconnectfileitemaction + KF5::KIOWidgets + KF5::I18n + kdeconnectinterfaces +) +install(TARGETS kdeconnectfileitemaction DESTINATION ${PLUGIN_INSTALL_DIR}) +install(FILES kdeconnectsendfile.desktop DESTINATION ${SERVICES_INSTALL_DIR}) diff --git a/fileitemactionplugin/Messages.sh b/fileitemactionplugin/Messages.sh new file mode 100644 index 000000000..ad6cb7605 --- /dev/null +++ b/fileitemactionplugin/Messages.sh @@ -0,0 +1,3 @@ +#!/usr/bin/env bash + +$XGETTEXT `find . -name '*.cpp'` -o $podir/kdeconnect-fileitemaction.pot diff --git a/fileitemactionplugin/kdeconnectsendfile.desktop b/fileitemactionplugin/kdeconnectsendfile.desktop new file mode 100644 index 000000000..51c0ced17 --- /dev/null +++ b/fileitemactionplugin/kdeconnectsendfile.desktop @@ -0,0 +1,88 @@ +[Desktop Entry] +Type=Service +Name=Send file via KDE Connect service +Name[ar]=أرسل ملفًّا عبر خدمة «كدي المتّصل» +Name[ast]=Unviar ficheru pel serviciu de KDE Connect +Name[bg]=Изпращане на файл през услугата KDE Connect +Name[bs]=Pošalji datoteku putem KDE Connect servisa +Name[ca]=Envia un fitxer a través del servei KDE Connect +Name[ca@valencia]=Envia un fitxer a través del servei KDE Connect +Name[cs]=Poslat soubor přes službu KDE Connect +Name[da]=Send fil via KDE Connect-tjeneste +Name[de]=Datei mit KDE-Connect -Dienst versenden +Name[el]=Αποστολή αρχείου μέσω της υπηρεσίας KDE Connect +Name[en_GB]=Send file via KDE Connect service +Name[es]=Enviar archivo usando el servicio KDE Connect +Name[et]=Faili saatmine KDE Connecti teenuse kaudu +Name[eu]=Bidali fitxategia KDE Connect zerbitzuaren bidez +Name[fi]=Lähetä tiedosto KDE Connect -palvelulla +Name[fr]=Envoyer un fichier via le service KDE Connect +Name[gl]=Enviar un ficheiro mediante o servizo de KDE Connect +Name[he]=שלח קובץ דרך שירות KDE Connect +Name[hu]=Fájl küldése a KDE csatlakozás szolgáltatáson keresztül +Name[id]=Kirim file via layanan KDE Connect +Name[it]=Invia un file tramite il servizio KDE Connect +Name[ko]=KDE Connect 서비스로 파일 보내기 +Name[nl]=Bestand via de service KDE Connect versturen +Name[nn]=Send fil med KDE Connect-tenesta +Name[pl]=Wyślij plik przez usługę KDE Connect +Name[pt]=Enviar um ficheiro pelo serviço KDE Connect +Name[pt_BR]=Enviar arquivo pelo serviço KDE Connect +Name[ru]=Отправить файл через KDE Connect +Name[sk]=Poslať súbor cez službu KDE Connect +Name[sr]=Шаљи фајл преко КДЕ‑конекцијиног сервиса +Name[sr@ijekavian]=Шаљи фајл преко КДЕ‑конекцијиног сервиса +Name[sr@ijekavianlatin]=Šalji fajl preko KDE‑konekcijinog servisa +Name[sr@latin]=Šalji fajl preko KDE‑konekcijinog servisa +Name[sv]=Skicka fil via KDE:s anslutningstjänst +Name[tr]=KDE Connect servisi ile dosya gönderin +Name[uk]=Надсилання файла за допомогою служби з’єднання KDE +Name[x-test]=xxSend file via KDE Connect servicexx +Name[zh_CN]=通过 KDE Connect 服务发送文件 +Name[zh_TW]=以已經連結到KDE之服務或裝置來傳送檔案 +X-KDE-Library=kdeconnectfileitemaction +X-KDE-Submenu=Connect +X-KDE-Submenu[ar]=اتّصل,اتصل +X-KDE-Submenu[ast]=Coneutar +X-KDE-Submenu[bg]=Свързване +X-KDE-Submenu[bs]=Uspostavi vezu +X-KDE-Submenu[ca]=Connecta +X-KDE-Submenu[ca@valencia]=Connecta +X-KDE-Submenu[cs]=Připojit +X-KDE-Submenu[da]=Forbind +X-KDE-Submenu[de]=Verbinden +X-KDE-Submenu[el]=Σύνδεση +X-KDE-Submenu[en_GB]=Connect +X-KDE-Submenu[es]=Conectar +X-KDE-Submenu[et]=Ühendus +X-KDE-Submenu[eu]=Konektatu +X-KDE-Submenu[fi]=Yhdistä +X-KDE-Submenu[fr]=Connecter +X-KDE-Submenu[gl]=Conectar +X-KDE-Submenu[he]=חיבור +X-KDE-Submenu[hu]=Csatlakozás +X-KDE-Submenu[ia]=Connecte +X-KDE-Submenu[id]=Connect +X-KDE-Submenu[it]=Connetti +X-KDE-Submenu[ko]=연결 +X-KDE-Submenu[nl]=Verbinden +X-KDE-Submenu[nn]=Kopla til +X-KDE-Submenu[pl]=Połącz +X-KDE-Submenu[pt]=Ligar +X-KDE-Submenu[pt_BR]=Conectar +X-KDE-Submenu[ru]=KDE Connect +X-KDE-Submenu[sk]=Pripojiť +X-KDE-Submenu[sr]=Повежи се +X-KDE-Submenu[sr@ijekavian]=Повежи се +X-KDE-Submenu[sr@ijekavianlatin]=Poveži se +X-KDE-Submenu[sr@latin]=Poveži se +X-KDE-Submenu[sv]=Anslut +X-KDE-Submenu[tr]=Bağlan +X-KDE-Submenu[uk]=З’єднання +X-KDE-Submenu[x-test]=xxConnectxx +X-KDE-Submenu[zh_CN]=连接 +X-KDE-Submenu[zh_TW]=連線 + +Icon=preferences-system-network +ServiceTypes=KFileItemAction/Plugin +MimeType=application/octet-stream diff --git a/fileitemactionplugin/sendfileitemaction.cpp b/fileitemactionplugin/sendfileitemaction.cpp new file mode 100644 index 000000000..4b2136187 --- /dev/null +++ b/fileitemactionplugin/sendfileitemaction.cpp @@ -0,0 +1,99 @@ +/* + * Copyright (C) 2011 Alejandro Fiestas Olivares + * Copyright (C) 2014 Aleix Pol Gonzalez + * + * 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) any later version. + * + * 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 Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#include "sendfileitemaction.h" + +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include + +#include +#include + +K_PLUGIN_FACTORY(SendFileItemActionFactory, registerPlugin();) + +Q_LOGGING_CATEGORY(KDECONNECT_FILEITEMACTION, "kdeconnect.fileitemaction") + +SendFileItemAction::SendFileItemAction(QObject* parent, const QVariantList& ): KAbstractFileItemActionPlugin(parent) +{ +} + +QList SendFileItemAction::actions(const KFileItemListProperties& fileItemInfos, QWidget* parentWidget) +{ + QList actions; + + DaemonDbusInterface iface; + if (!iface.isValid()) { + return actions; + } + + QDBusPendingReply reply = iface.devices(true, true); + reply.waitForFinished(); + const QStringList devices = reply.value(); + for (const QString& id : devices) { + DeviceDbusInterface deviceIface(id); + if (!deviceIface.isValid()) { + continue; + } + if (!deviceIface.hasPlugin(QStringLiteral("kdeconnect_share"))) { + continue; + } + QAction* action = new QAction(QIcon::fromTheme(deviceIface.iconName()), deviceIface.name(), parentWidget); + action->setProperty("id", id); + action->setProperty("urls", QVariant::fromValue(fileItemInfos.urlList())); + action->setProperty("parentWidget", QVariant::fromValue(parentWidget)); + connect(action, &QAction::triggered, this, &SendFileItemAction::sendFile); + actions += action; + } + + if (actions.count() > 1) { + QAction* menuAction = new QAction(QIcon::fromTheme(QStringLiteral("kdeconnect")), i18n("Send via KDE Connect"), parentWidget); + QMenu* menu = new QMenu(parentWidget); + menu->addActions(actions); + menuAction->setMenu(menu); + return QList() << menuAction; + } else { + if(actions.count() == 1) { + actions.first()->setText(i18n("Send to '%1' via KDE Connect", actions.first()->text())); + } + return actions; + } +} + +void SendFileItemAction::sendFile() +{ + const QList urls = sender()->property("urls").value>(); + QString id = sender()->property("id").toString(); + for (const QUrl& url : urls) { + QDBusMessage msg = QDBusMessage::createMethodCall(QStringLiteral("org.kde.kdeconnect"), "/modules/kdeconnect/devices/"+id+"/share", QStringLiteral("org.kde.kdeconnect.device.share"), QStringLiteral("shareUrl")); + msg.setArguments(QVariantList() << url.toString()); + QDBusConnection::sessionBus().call(msg); + } +} + +#include "sendfileitemaction.moc" diff --git a/fileitemactionplugin/sendfileitemaction.h b/fileitemactionplugin/sendfileitemaction.h new file mode 100644 index 000000000..6020a23db --- /dev/null +++ b/fileitemactionplugin/sendfileitemaction.h @@ -0,0 +1,45 @@ +/* + * Copyright (C) 2011 Alejandro Fiestas Olivares + * Copyright (C) 2014 Aleix Pol Gonzalez + * + * 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) any later version. + * + * 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 Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#ifndef SENDFILEITEMACTION_H +#define SENDFILEITEMACTION_H + +#include +#include +#include + +class QAction; +class KFileItemListProperties; +class QWidget; + +Q_DECLARE_LOGGING_CATEGORY(KDECONNECT_FILEITEMACTION) +class SendFileItemAction : public KAbstractFileItemActionPlugin +{ +Q_OBJECT +public: + SendFileItemAction(QObject* parent, const QVariantList& args); + QList< QAction* > actions(const KFileItemListProperties& fileItemInfos, QWidget* parentWidget) override; + +private Q_SLOTS: + void sendFile(); + +}; + +#endif // SENDFILEITEMACTION_H