diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -61,4 +61,4 @@ add_subdirectory(plugins) add_subdirectory(quick) add_subdirectory(widgets) - +add_subdirectory(fileitemactionplugin) diff --git a/src/fileitemactionplugin/CMakeLists.txt b/src/fileitemactionplugin/CMakeLists.txt new file mode 100644 --- /dev/null +++ b/src/fileitemactionplugin/CMakeLists.txt @@ -0,0 +1,13 @@ +find_package(KF5 REQUIRED COMPONENTS KIO) + +add_definitions(-DTRANSLATION_DOMAIN="purpose-fileitemaction") +include_directories(${CMAKE_SOURCE_DIR}) + +add_library(purposefileitemaction MODULE sendfileitemaction.cpp) +target_link_libraries(purposefileitemaction + KF5::KIOWidgets + KF5::I18n + KF5PurposeWidgets +) +install(TARGETS purposefileitemaction DESTINATION ${PLUGIN_INSTALL_DIR}) +install(FILES purposesendfile.desktop DESTINATION ${SERVICES_INSTALL_DIR}) diff --git a/src/fileitemactionplugin/Messages.sh b/src/fileitemactionplugin/Messages.sh new file mode 100644 --- /dev/null +++ b/src/fileitemactionplugin/Messages.sh @@ -0,0 +1,3 @@ +#!/usr/bin/env bash + +$XGETTEXT `find . -name '*.cpp'` -o $podir/purpose-fileitemaction.pot diff --git a/src/fileitemactionplugin/purposesendfile.desktop b/src/fileitemactionplugin/purposesendfile.desktop new file mode 100644 --- /dev/null +++ b/src/fileitemactionplugin/purposesendfile.desktop @@ -0,0 +1,7 @@ +[Desktop Entry] +Type=Service +Name=Share +X-KDE-Library=purposefileitemaction +Icon=document-share +ServiceTypes=KFileItemAction/Plugin +MimeType=application/octet-stream diff --git a/src/fileitemactionplugin/sendfileitemaction.h b/src/fileitemactionplugin/sendfileitemaction.h new file mode 100644 --- /dev/null +++ b/src/fileitemactionplugin/sendfileitemaction.h @@ -0,0 +1,50 @@ +/* + * Copyright (C) 2011 Alejandro Fiestas Olivares + * Copyright (C) 2014 Aleix Pol Gonzalez + * Copyright (C) 2018 Nicolas Fella + * + * 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; + +namespace Purpose +{ +class Menu; +} + +Q_DECLARE_LOGGING_CATEGORY(PURPOSE_FILEITEMACTION) +class SendFileItemAction : public KAbstractFileItemActionPlugin +{ +Q_OBJECT +public: + SendFileItemAction(QObject* parent, const QVariantList& args); + QList< QAction* > actions(const KFileItemListProperties& fileItemInfos, QWidget* parentWidget) override; + +private: + Purpose::Menu* m_menu; +}; + +#endif // SENDFILEITEMACTION_H diff --git a/src/fileitemactionplugin/sendfileitemaction.cpp b/src/fileitemactionplugin/sendfileitemaction.cpp new file mode 100644 --- /dev/null +++ b/src/fileitemactionplugin/sendfileitemaction.cpp @@ -0,0 +1,72 @@ +/* + * Copyright (C) 2011 Alejandro Fiestas Olivares + * Copyright (C) 2014 Aleix Pol Gonzalez + * Copyright (C) 2018 Nicolas Fella + + * 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 "menu.h" +#include "alternativesmodel.h" + +K_PLUGIN_FACTORY(SendFileItemActionFactory, registerPlugin();) + +Q_LOGGING_CATEGORY(PURPOSE_FILEITEMACTION, "purpose.fileitemaction") + +SendFileItemAction::SendFileItemAction(QObject* parent, const QVariantList& ) + : KAbstractFileItemActionPlugin(parent), + m_menu(new Purpose::Menu()) +{ + m_menu->setTitle(i18n("Share")); + m_menu->setIcon(QIcon::fromTheme(QStringLiteral("document-share"))); + m_menu->model()->setPluginType(QStringLiteral("Export")); + +} + +QList SendFileItemAction::actions(const KFileItemListProperties& fileItemInfos, QWidget* parentWidget) +{ + Q_UNUSED(parentWidget); + + QJsonArray urlsJson; + + for (const QUrl& url : fileItemInfos.urlList()) { + urlsJson.append(url.toString()); + } + + m_menu->model()->setInputData(QJsonObject{ + { QStringLiteral("mimeType"), QJsonValue{!fileItemInfos.mimeType().isEmpty() ? fileItemInfos.mimeType() : QStringLiteral("*/*")} }, + { QStringLiteral("urls"), urlsJson } + }); + m_menu->reload(); + + return {m_menu->menuAction()}; +} + +#include "sendfileitemaction.moc"