diff --git a/CMakeLists.txt b/CMakeLists.txt --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -72,7 +72,6 @@ ) find_package(KF5 ${KF5_MIN_VERSION} OPTIONAL_COMPONENTS Activities - Purpose ) if (KF5ConfigWidgets_VERSION VERSION_GREATER "5.56.0" AND ${Phonon4Qt5_VERSION} VERSION_GREATER "4.10.59") diff --git a/app/CMakeLists.txt b/app/CMakeLists.txt --- a/app/CMakeLists.txt +++ b/app/CMakeLists.txt @@ -87,10 +87,6 @@ target_link_libraries(gwenview KF5::Activities) endif() -if (KF5Purpose_FOUND) - target_link_libraries(gwenview KF5::PurposeWidgets) -endif() - target_link_libraries(gwenview LINK_INTERFACE_LIBRARIES KF5::KIOCore Qt5::Core) if (KF5Kipi_FOUND) diff --git a/app/mainwindow.cpp b/app/mainwindow.cpp --- a/app/mainwindow.cpp +++ b/app/mainwindow.cpp @@ -42,13 +42,17 @@ #include // KDE +#include #include #include #include #include +#include #include #include +#include #include +#include #include #include #include @@ -60,10 +64,6 @@ #include #include #include -#ifdef KF5Purpose_FOUND -#include -#include -#endif // Local #include "configdialog.h" @@ -202,10 +202,7 @@ QAction * mToggleSlideShowAction; KToggleAction* mShowMenuBarAction; KToggleAction* mShowStatusBarAction; -#ifdef KF5Purpose_FOUND - Purpose::Menu* mShareMenu; KToolBarPopupAction* mShareAction; -#endif #ifdef KIPI_FOUND KIPIExportAction* mKIPIExportAction; #endif @@ -517,13 +514,10 @@ mKIPIExportAction = new KIPIExportAction(q); #endif -#ifdef KF5Purpose_FOUND mShareAction = new KToolBarPopupAction(QIcon::fromTheme("document-share"), i18nc("@action Share images", "Share"), q); mShareAction->setDelayed(false); + mShareAction->setVisible(false); actionCollection->addAction("share", mShareAction); - mShareMenu = new Purpose::Menu(q); - mShareAction->setMenu(mShareMenu); -#endif } void setupUndoActions() @@ -727,19 +721,54 @@ actionCollection->action("file_save_as")->setEnabled(canSave); actionCollection->action("file_print")->setEnabled(isRasterImage); -#ifdef KF5Purpose_FOUND if (url.isEmpty()) { mShareAction->setEnabled(false); - } else { - mShareAction->setEnabled(true); - mShareMenu->model()->setInputData(QJsonObject{ - { QStringLiteral("mimeType"), MimeTypeUtils::urlMimeType(url) }, - { QStringLiteral("urls"), QJsonArray{url.toString()} } - }); - mShareMenu->model()->setPluginType( QStringLiteral("Export") ); - mShareMenu->reload(); + return; } -#endif + + const QVector plugins = KPluginLoader::findPluginsById(QStringLiteral("kf5/kfileitemaction"), "sharefileitemaction"); + if (plugins.isEmpty()) { + mShareAction->setVisible(false); + return; + } + + if (plugins.count() != 1) { + qWarning() << "Invalid plugin number of Share file plugins (colliding IDs)"; + for (const KPluginMetaData &metadata : plugins) { + qDebug() << metadata.fileName(); + } + + mShareAction->setVisible(false); + + return; + } + + KPluginFactory *factory = KPluginLoader(plugins[0].fileName()).factory(); + if (!factory) { + qWarning() << "Can't load Share files plugin"; + mShareAction->setVisible(false); + return; + } + KAbstractFileItemActionPlugin* abstractPlugin = factory->create(); + if (!abstractPlugin) { + qWarning() << "Can't instantiate Share files plugin"; + mShareAction->setVisible(false); + return; + } + abstractPlugin->setParent(q); + + const KFileItemListProperties fileProperties(KFileItemList({KFileItem(url)})); + + QList actions = abstractPlugin->actions(fileProperties, q); + if (actions.count() != 1) { + qWarning() << "Invalid number of actions returned from Share files plugin"; + mShareAction->setVisible(false); + return; + } + + mShareAction->setMenu(actions[0]->menu()); + mShareAction->setEnabled(true); + mShareAction->setVisible(true); } bool sideBarVisibility() const diff --git a/config-gwenview.h.cmake b/config-gwenview.h.cmake --- a/config-gwenview.h.cmake +++ b/config-gwenview.h.cmake @@ -7,4 +7,3 @@ #cmakedefine HAVE_FITS ${HAVE_FITS} #cmakedefine HAVE_QTDBUS ${HAVE_QTDBUS} #cmakedefine KF5Activities_FOUND 1 -#cmakedefine KF5Purpose_FOUND 1