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,15 @@ +find_package(KF5 REQUIRED COMPONENTS KIO) + +add_definitions(-DTRANSLATION_DOMAIN="purpose-fileitemaction") +include_directories(${CMAKE_SOURCE_DIR}) + +kcoreaddons_add_plugin(sharefileitemaction + SOURCES sharefileitemaction.cpp + JSON sharefileitemaction.json + INSTALL_NAMESPACE "kf5/kfileitemaction") + +target_link_libraries(sharefileitemaction + KF5::KIOWidgets + KF5::I18n + KF5PurposeWidgets +) 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/sharefileitemaction.h b/src/fileitemactionplugin/sharefileitemaction.h new file mode 100644 --- /dev/null +++ b/src/fileitemactionplugin/sharefileitemaction.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 SHAREFILEITEMACTION_H +#define SHAREFILEITEMACTION_H + +#include +#include +#include + +class QAction; +class KFileItemListProperties; +class QWidget; + +namespace Purpose +{ +class Menu; +} + +Q_DECLARE_LOGGING_CATEGORY(PURPOSE_FILEITEMACTION) +class ShareFileItemAction : public KAbstractFileItemActionPlugin +{ +Q_OBJECT +public: + ShareFileItemAction(QObject* parent, const QVariantList& args); + QList< QAction* > actions(const KFileItemListProperties& fileItemInfos, QWidget* parentWidget) override; + +private: + Purpose::Menu* m_menu; +}; + +#endif // SHAREFILEITEMACTION_H diff --git a/src/fileitemactionplugin/sharefileitemaction.cpp b/src/fileitemactionplugin/sharefileitemaction.cpp new file mode 100644 --- /dev/null +++ b/src/fileitemactionplugin/sharefileitemaction.cpp @@ -0,0 +1,71 @@ +/* + * 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 "sharefileitemaction.h" + +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include + +#include "menu.h" +#include "alternativesmodel.h" + +K_PLUGIN_FACTORY_WITH_JSON(ShareFileItemActionFactory, "sharefileitemaction.json", registerPlugin();) + +Q_LOGGING_CATEGORY(PURPOSE_FILEITEMACTION, "purpose.fileitemaction") + +ShareFileItemAction::ShareFileItemAction(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 ShareFileItemAction::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 "sharefileitemaction.moc" diff --git a/src/fileitemactionplugin/sharefileitemaction.json b/src/fileitemactionplugin/sharefileitemaction.json new file mode 100644 --- /dev/null +++ b/src/fileitemactionplugin/sharefileitemaction.json @@ -0,0 +1,21 @@ +{ + "KPlugin": { + "Authors": [ + { + "Name": "Nicolas Fella", + "Name[x-test]": "xxNicolas Fellaxx" + } + ], + "MimeTypes": [ + "application/octet-stream" + ], + "ServiceTypes": [ + "KFileItemAction/Plugin" + ], + "Category": "Utilities", + "Description": "Share using Purpose", + "Icon": "document-share", + "License": "GPL", + "Name": "Share" + } +}