diff --git a/src/fileitemactionplugin/CMakeLists.txt b/src/fileitemactionplugin/CMakeLists.txt --- a/src/fileitemactionplugin/CMakeLists.txt +++ b/src/fileitemactionplugin/CMakeLists.txt @@ -1,4 +1,9 @@ -find_package(KF5 REQUIRED COMPONENTS KIO) +find_package(KF5KIO COMPONENTS) +find_package(KF5Notifications COMPONENTS) +if (NOT KF5KIO_FOUND OR NOT KF5Notifications_FOUND) + return() +endif() + add_definitions(-DTRANSLATION_DOMAIN="purpose-fileitemaction") include_directories(${CMAKE_SOURCE_DIR}) @@ -14,5 +19,6 @@ target_link_libraries(sharefileitemaction KF5::KIOWidgets KF5::I18n + KF5::Notifications KF5PurposeWidgets ) diff --git a/src/fileitemactionplugin/sharefileitemaction.cpp b/src/fileitemactionplugin/sharefileitemaction.cpp --- a/src/fileitemactionplugin/sharefileitemaction.cpp +++ b/src/fileitemactionplugin/sharefileitemaction.cpp @@ -28,10 +28,12 @@ #include #include #include +#include #include #include #include +#include #include "menu.h" #include "alternativesmodel.h" @@ -47,6 +49,16 @@ m_menu->setTitle(i18n("Share")); m_menu->setIcon(QIcon::fromTheme(QStringLiteral("document-share"))); m_menu->model()->setPluginType(QStringLiteral("Export")); + + QObject::connect(m_menu, &Purpose::Menu::finished, [](const QJsonObject &output, int error, const QString &errorMessage) { + if (error == 0) { + if (output.contains(QLatin1String("url"))) + QDesktopServices::openUrl(QUrl(output.value(QLatin1String("url")).toString())); + } else { + KNotification::event(KNotification::Error, i18n("Error sharing"), errorMessage); + qWarning() << "job failed with error" << error << errorMessage << output; + } + }); } QList ShareFileItemAction::actions(const KFileItemListProperties& fileItemInfos, QWidget* parentWidget) diff --git a/src/widgets/menu.h b/src/widgets/menu.h --- a/src/widgets/menu.h +++ b/src/widgets/menu.h @@ -46,7 +46,16 @@ void reload(); Q_SIGNALS: - void finished(const QJsonObject &output, int error, const QString &message); + /** + * Emitted when a triggered job finishes + * + * @p output contains the information offered by the plugin. The information offered will depend on the plugin type. + * @p error will be 0 if the execution was successful, otherwise it will provide an error message + * @p errorMessage the error message + * + * @see Purpose::Job + */ + void finished(const QJsonObject &output, int error, const QString &errorMessage); private: Q_DECLARE_PRIVATE(Menu) diff --git a/src/widgets/menu.cpp b/src/widgets/menu.cpp --- a/src/widgets/menu.cpp +++ b/src/widgets/menu.cpp @@ -81,6 +81,7 @@ Q_D(Menu); d->trigger(action->property("row").toInt()); }); + connect(this, &Menu::finished, this, [this]{ qDebug() << "omgomgomg" << this; }); } void Menu::reload()