diff --git a/CMakeLists.txt b/CMakeLists.txt --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -68,6 +68,12 @@ TYPE RUNTIME ) find_package(Phonon4Qt5 CONFIG REQUIRED) +find_package(KDEExperimentalPurpose) +if (KDEExperimentalPurpose_FOUND) + set(PURPOSE_FOUND 1) +else() + set(PURPOSE_FOUND 0) +endif() set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_SOURCE_DIR}/cmake/modules) @@ -347,6 +353,10 @@ KF5::WindowSystem ) +if (KDEExperimentalPurpose_FOUND) + target_link_libraries(okularpart KDEExperimental::PurposeWidgets) +endif() + set_target_properties(okularpart PROPERTIES PREFIX "") if (Qt5TextToSpeech_FOUND) diff --git a/config-okular.h.cmake b/config-okular.h.cmake --- a/config-okular.h.cmake +++ b/config-okular.h.cmake @@ -1,3 +1,6 @@ /* Defines if force the use DRM in okular */ #define OKULAR_FORCE_DRM ${_OKULAR_FORCE_DRM} +/* Defines if the purpose framework is available */ +#define PURPOSE_FOUND ${PURPOSE_FOUND} + diff --git a/part.h b/part.h --- a/part.h +++ b/part.h @@ -36,6 +36,8 @@ #include "okularpart_export.h" +#include + class QAction; class QWidget; class QPrinter; @@ -50,6 +52,7 @@ class KAboutData; class QTemporaryFile; class QAction; +class QJsonObject; namespace KParts { class GUIActivateEvent; } class FindBar; @@ -69,6 +72,10 @@ class DrawingToolActions; class Layers; +#if PURPOSE_FOUND +namespace Purpose { class Menu; } +#endif + namespace Okular { @@ -260,6 +267,10 @@ void slotRemoveBookmark( const DocumentViewport &viewport ); void resetStartArguments(); +#if PURPOSE_FOUND + void slotShareActionFinished(const QJsonObject &output, int error, const QString &message); +#endif + static int numberOfParts; QTemporaryFile *m_tempfile; @@ -331,14 +342,20 @@ QAction *m_exportAs; QAction *m_exportAsText; QAction *m_exportAsDocArchive; +#if PURPOSE_FOUND + QAction *m_share; +#endif QAction *m_showPresentation; KToggleAction* m_showMenuBarAction; KToggleAction* m_showLeftPanel; KToggleAction* m_showBottomBar; KToggleFullScreenAction* m_showFullScreenAction; QAction *m_aboutBackend; QAction *m_reload; QMenu *m_exportAsMenu; +#if PURPOSE_FOUND + Purpose::Menu *m_shareMenu; +#endif QAction *m_closeFindBar; DrawingToolActions *m_presentationDrawingActions; diff --git a/part.cpp b/part.cpp --- a/part.cpp +++ b/part.cpp @@ -69,6 +69,12 @@ #include #include + +#if PURPOSE_FOUND +#include +#include +#endif + #if 0 #include #endif @@ -739,6 +745,12 @@ m_exportAsMenu = nullptr; m_exportAsText = nullptr; m_exportAsDocArchive = nullptr; + +#if PURPOSE_FOUND + m_share = nullptr; + m_shareMenu = nullptr; +#endif + m_presentationDrawingActions = nullptr; m_aboutBackend = ac->addAction(QStringLiteral("help_about_backend")); @@ -841,6 +853,16 @@ m_exportAsMenu->addAction( m_exportAsDocArchive ); m_exportAsDocArchive->setEnabled( false ); +#if PURPOSE_FOUND + m_share = ac->addAction( QStringLiteral("file_share") ); + m_share->setText( i18n("S&hare") ); + m_share->setIcon( QIcon::fromTheme( QStringLiteral("document-share") ) ); + m_share->setEnabled( false ); + m_shareMenu = new Purpose::Menu(); + connect(m_shareMenu, &Purpose::Menu::finished, this, &Part::slotShareActionFinished); + m_share->setMenu( m_shareMenu ); +#endif + m_showPresentation = ac->addAction(QStringLiteral("presentation")); m_showPresentation->setText(i18n("P&resentation")); m_showPresentation->setIcon( QIcon::fromTheme( QStringLiteral("view-presentation") ) ); @@ -915,6 +937,9 @@ qDeleteAll( m_bookmarkActions ); delete m_exportAsMenu; +#if PURPOSE_FOUND + delete m_shareMenu; +#endif #ifdef OKULAR_KEEP_FILE_OPEN delete m_keeper; @@ -1470,6 +1495,17 @@ menu->addAction( actionForExportFormat( *it ) ); } } +#if PURPOSE_FOUND + if ( m_share ) + { + m_shareMenu->model()->setInputData(QJsonObject{ + { QStringLiteral("mimeType"), mime.name() }, + { QStringLiteral("urls"), QJsonArray{ url().toString() } } + }); + m_shareMenu->model()->setPluginType( QStringLiteral("Export") ); + m_shareMenu->reload(); + } +#endif if ( isCompressedFile ) { m_realUrl = url(); @@ -1482,6 +1518,9 @@ if ( m_exportAsText ) m_exportAsText->setEnabled( ok && m_document->canExportToText() ); if ( m_exportAsDocArchive ) m_exportAsDocArchive->setEnabled( ok ); if ( m_exportAs ) m_exportAs->setEnabled( ok ); +#if PURPOSE_FOUND + if ( m_share ) m_share->setEnabled( ok ); +#endif // update viewing actions updateViewActions(); @@ -1646,6 +1685,13 @@ delete acts.at(i); } } +#if PURPOSE_FOUND + if ( m_share ) + { + m_share->setEnabled(false); + m_shareMenu->clear(); + } +#endif if ( m_showPresentation ) m_showPresentation->setEnabled( false ); emit setWindowCaption(QLatin1String("")); emit enablePrintAction(false); @@ -3108,6 +3154,25 @@ m_cliPrint = false; } +#if PURPOSE_FOUND +void Part::slotShareActionFinished(const QJsonObject &output, int error, const QString &message) +{ + if (error) { + KMessageBox::error(widget(), i18n("There was a problem sharing the document: %1", message), + i18n("Share")); + } else { + const QString url = output["url"].toString(); + if (url.isEmpty()) { + m_pageView->displayMessage(i18n("Document shared successfully")); + } else { + KMessageBox::information(widget(), i18n("You can find the shared document at: %1", url), + i18n("Share"), QString(), + KMessageBox::Notify | KMessageBox::AllowLink); + } + } +} +#endif + void Part::setReadWrite(bool readwrite) { m_document->setAnnotationEditingEnabled( readwrite ); diff --git a/part.rc b/part.rc --- a/part.rc +++ b/part.rc @@ -12,6 +12,7 @@ + &Edit