mirror of
https://invent.kde.org/graphics/okular
synced 2024-10-02 14:14:10 +00:00
Add a "share" menu to Okular
Summary: This is implemented using the Purpose framework. BUG: 173896 Reviewers: aacid Subscribers: #okular Tags: #okular Differential Revision: https://phabricator.kde.org/D8244
This commit is contained in:
parent
a78d2da440
commit
a5da013a4d
|
@ -68,6 +68,17 @@ set_package_properties(KF5Kirigami2 PROPERTIES
|
|||
TYPE RUNTIME
|
||||
)
|
||||
find_package(Phonon4Qt5 CONFIG REQUIRED)
|
||||
find_package(KDEExperimentalPurpose)
|
||||
set_package_properties(KDEExperimentalPurpose PROPERTIES
|
||||
DESCRIPTION "A framework for services and actions integration"
|
||||
PURPOSE "Required for enabling the share menu in Okular"
|
||||
TYPE OPTIONAL
|
||||
)
|
||||
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 +358,10 @@ target_link_libraries(okularpart okularcore
|
|||
KF5::WindowSystem
|
||||
)
|
||||
|
||||
if (KDEExperimentalPurpose_FOUND)
|
||||
target_link_libraries(okularpart KDEExperimental::PurposeWidgets)
|
||||
endif()
|
||||
|
||||
set_target_properties(okularpart PROPERTIES PREFIX "")
|
||||
|
||||
if (Qt5TextToSpeech_FOUND)
|
||||
|
|
|
@ -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}
|
||||
|
||||
|
|
65
part.cpp
65
part.cpp
|
@ -69,6 +69,12 @@
|
|||
#include <KXMLGUIClient>
|
||||
#include <KXMLGUIFactory>
|
||||
|
||||
|
||||
#if PURPOSE_FOUND
|
||||
#include <Purpose/AlternativesModel>
|
||||
#include <PurposeWidgets/Menu>
|
||||
#endif
|
||||
|
||||
#if 0
|
||||
#include <knewstuff2/engine.h>
|
||||
#endif
|
||||
|
@ -739,6 +745,12 @@ void Part::setupViewerActions()
|
|||
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 @@ void Part::setupActions()
|
|||
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 @@ Part::~Part()
|
|||
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 @@ bool Part::openFile()
|
|||
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 @@ bool Part::openFile()
|
|||
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 @@ bool Part::closeUrl(bool promptToSave)
|
|||
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 @@ void Part::resetStartArguments()
|
|||
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: <a href=\"%1\">%1</a>", url),
|
||||
i18n("Share"), QString(),
|
||||
KMessageBox::Notify | KMessageBox::AllowLink);
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
void Part::setReadWrite(bool readwrite)
|
||||
{
|
||||
m_document->setAnnotationEditingEnabled( readwrite );
|
||||
|
|
17
part.h
17
part.h
|
@ -36,6 +36,8 @@
|
|||
|
||||
#include "okularpart_export.h"
|
||||
|
||||
#include <config-okular.h>
|
||||
|
||||
class QAction;
|
||||
class QWidget;
|
||||
class QPrinter;
|
||||
|
@ -50,6 +52,7 @@ class KSelectAction;
|
|||
class KAboutData;
|
||||
class QTemporaryFile;
|
||||
class QAction;
|
||||
class QJsonObject;
|
||||
namespace KParts { class GUIActivateEvent; }
|
||||
|
||||
class FindBar;
|
||||
|
@ -69,6 +72,10 @@ class BookmarkList;
|
|||
class DrawingToolActions;
|
||||
class Layers;
|
||||
|
||||
#if PURPOSE_FOUND
|
||||
namespace Purpose { class Menu; }
|
||||
#endif
|
||||
|
||||
namespace Okular
|
||||
{
|
||||
|
||||
|
@ -260,6 +267,10 @@ class OKULARPART_EXPORT Part : public KParts::ReadWritePart, public Okular::Docu
|
|||
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,6 +342,9 @@ class OKULARPART_EXPORT Part : public KParts::ReadWritePart, public Okular::Docu
|
|||
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;
|
||||
|
@ -339,6 +353,9 @@ class OKULARPART_EXPORT Part : public KParts::ReadWritePart, public Okular::Docu
|
|||
QAction *m_aboutBackend;
|
||||
QAction *m_reload;
|
||||
QMenu *m_exportAsMenu;
|
||||
#if PURPOSE_FOUND
|
||||
Purpose::Menu *m_shareMenu;
|
||||
#endif
|
||||
QAction *m_closeFindBar;
|
||||
DrawingToolActions *m_presentationDrawingActions;
|
||||
|
||||
|
|
1
part.rc
1
part.rc
|
@ -12,6 +12,7 @@
|
|||
<Action name="properties" group="file_print"/>
|
||||
<Action name="embedded_files" group="file_print"/>
|
||||
<Action name="file_export_as" group="file_print"/>
|
||||
<Action name="file_share" group="file_print"/>
|
||||
</Menu>
|
||||
<Menu name="edit"><text>&Edit</text>
|
||||
<Action name="edit_undo"/>
|
||||
|
|
Loading…
Reference in a new issue