Make some frameworks optional so okular can be built on Android

Summary:
Disables KWallet integration if there's no KWallet, KJS if there's no
KJS and KDocTools.
Here's a list of frameworks that don't work on Android:
https://cgit.kde.org/sysadmin/ci-tooling.git/tree/local-metadata/project-ignore-rules.yaml

Test Plan: Still works locally, ran Okular and Okular Mobile on Android.

Reviewers: #okular, aacid

Subscribers: aacid

Tags: #okular

Differential Revision: https://phabricator.kde.org/D12177
This commit is contained in:
Aleix Pol 2018-04-16 22:35:40 +02:00 committed by Albert Astals Cid
parent 5f8f84d53c
commit c325b342f3
7 changed files with 78 additions and 31 deletions

View file

@ -46,6 +46,13 @@ if(NOT CMAKE_VERSION VERSION_LESS "3.10.0")
list(APPEND CMAKE_AUTOMOC_MACRO_NAMES "OKULAR_EXPORT_PLUGIN")
endif()
set(optionalComponents)
if (ANDROID)
# we want to make sure that generally all components are found
set(optionalComponents "OPTIONAL_COMPONENTS")
endif()
find_package(KF5 ${KF5_REQUIRED_VERSION} REQUIRED COMPONENTS
Archive
Bookmarks
@ -54,15 +61,24 @@ find_package(KF5 ${KF5_REQUIRED_VERSION} REQUIRED COMPONENTS
ConfigWidgets
CoreAddons
Crash
DocTools
IconThemes
JS
KIO
Parts
ThreadWeaver
Wallet
WindowSystem
${optionalComponents}
DocTools
JS
Wallet
)
if(KF5Wallet_FOUND)
add_definitions(-DWITH_KWALLET=1)
endif()
if(KF5JS_FOUND)
add_definitions(-DWITH_KJS=1)
endif()
if(NOT WIN32 AND NOT ANDROID)
find_package(KF5 ${KF5_REQUIRED_VERSION} REQUIRED COMPONENTS
Activities
@ -128,7 +144,9 @@ add_subdirectory( generators )
add_subdirectory( autotests )
add_subdirectory( conf/autotests )
add_subdirectory(doc)
if(KF5DocTools_FOUND)
add_subdirectory(doc)
endif()
include(OkularConfigureChecks.cmake)
@ -173,20 +191,9 @@ set(okularcore_SRCS
core/view.cpp
core/fileprinter.cpp
core/script/event.cpp
core/script/executor_kjs.cpp
core/script/kjs_app.cpp
core/script/kjs_console.cpp
core/script/kjs_data.cpp
core/script/kjs_document.cpp
core/script/kjs_event.cpp
core/script/kjs_fullscreen.cpp
core/script/kjs_field.cpp
core/script/kjs_spell.cpp
core/script/kjs_util.cpp
core/synctex/synctex_parser.c
core/synctex/synctex_parser_utils.c
)
qt5_add_resources(okularcore_SRCS
core/script/builtin.qrc
)
@ -253,13 +260,10 @@ PRIVATE
${OKULAR_IOKIT}
${SHLWAPI}
KF5::Archive
KF5::JS
KF5::JSApi
KF5::KIOCore
KF5::KIOWidgets
KF5::I18n
KF5::ThreadWeaver
KF5::Wallet
KF5::Bookmarks
Phonon::phonon4qt5
${MATH_LIB}
@ -272,6 +276,27 @@ PUBLIC # these are included from the installed headers
Qt5::Widgets
)
if (KF5Wallet_FOUND)
target_link_libraries(okularcore PRIVATE KF5::Wallet)
endif()
if (KF5JS_FOUND)
target_sources(okularcore PRIVATE
core/script/executor_kjs.cpp
core/script/kjs_app.cpp
core/script/kjs_console.cpp
core/script/kjs_data.cpp
core/script/kjs_document.cpp
core/script/kjs_field.cpp
core/script/kjs_fullscreen.cpp
core/script/kjs_field.cpp
core/script/kjs_spell.cpp
core/script/kjs_util.cpp
core/script/kjs_event.cpp
)
target_link_libraries(okularcore PRIVATE KF5::JS KF5::JSApi)
endif()
set_target_properties(okularcore PROPERTIES VERSION 9.0.0 SOVERSION 9 OUTPUT_NAME Okular5Core EXPORT_NAME Core)
install(TARGETS okularcore EXPORT Okular5Targets ${KDE_INSTALL_TARGETS_DEFAULT_ARGS})
@ -378,10 +403,13 @@ target_link_libraries(okularpart okularcore
KF5::KIOWidgets
KF5::Parts
KF5::Solid
KF5::Wallet
KF5::WindowSystem
)
if(KF5Wallet_FOUND)
target_link_libraries(okularpart KF5::Wallet)
endif()
if (KDEExperimentalPurpose_FOUND)
target_link_libraries(okularpart KDEExperimental::PurposeWidgets)
endif()

View file

@ -64,7 +64,7 @@ ecm_add_test(calculatetexttest.cpp
LINK_LIBRARIES Qt5::Widgets Qt5::Test okularcore
)
if(NOT WIN32)
if(KF5Activities_FOUND)
ecm_add_test(mainshelltest.cpp ../shell/okular_main.cpp ../shell/shellutils.cpp ../shell/shell.cpp
TEST_NAME "mainshelltest"
LINK_LIBRARIES Qt5::Test KF5::Activities okularpart okularcore

View file

@ -24,7 +24,10 @@
#include <QMimeDatabase>
#include <QTimer>
#include <KLocalizedString>
#ifdef WITH_KWALLET
#include <kwallet.h>
#endif
#include "document.h"
#include "document_p.h"
@ -411,9 +414,11 @@ bool Generator::exportTo( const QString&, const ExportFormat& )
void Generator::walletDataForFile( const QString &fileName, QString *walletName, QString *walletFolder, QString *walletKey ) const
{
#ifdef WITH_KWALLET
*walletKey = fileName.section( QLatin1Char('/'), -1, -1);
*walletName = KWallet::Wallet::NetworkWallet();
*walletFolder = QStringLiteral("KPdf");
#endif
}
bool Generator::hasFeature( GeneratorFeature feature ) const

View file

@ -21,17 +21,18 @@ class Okular::ScripterPrivate
{
public:
ScripterPrivate( DocumentPrivate *doc )
: m_doc( doc ), m_kjs( nullptr ), m_event( nullptr )
: m_doc( doc )
#ifdef WITH_KJS
, m_kjs( nullptr )
#endif
, m_event( nullptr )
{
}
~ScripterPrivate()
{
delete m_kjs;
}
DocumentPrivate *m_doc;
ExecutorKJS *m_kjs;
#ifdef WITH_KJS
QScopedPointer<ExecutorKJS> m_kjs;
#endif
Event *m_event;
};
@ -48,6 +49,7 @@ Scripter::~Scripter()
QString Scripter::execute( ScriptType type, const QString &script )
{
qCDebug(OkularCoreDebug) << "executing the script:";
#ifdef WITH_KJS
#if 0
if ( script.length() < 1000 )
qDebug() << script;
@ -74,11 +76,12 @@ QString Scripter::execute( ScriptType type, const QString &script )
case JavaScript:
if ( !d->m_kjs )
{
d->m_kjs = new ExecutorKJS( d->m_doc );
d->m_kjs.reset(new ExecutorKJS( d->m_doc ));
}
d->m_kjs->execute( builtInScript + script, d->m_event );
break;
}
#endif
return QString();
}

View file

@ -29,9 +29,12 @@ set(okularGenerator_ooo_PART_SRCS
okular_add_generator(okularGenerator_ooo ${okularGenerator_ooo_PART_SRCS})
target_link_libraries(okularGenerator_ooo okularcore KF5::KIOCore KF5::Archive KF5::I18n KF5::Wallet ${MATH_LIB} Qt5::Xml)
target_link_libraries(okularGenerator_ooo okularcore KF5::KIOCore KF5::Archive KF5::I18n ${MATH_LIB} Qt5::Xml)
if (Qca-qt5_FOUND)
target_link_libraries(okularGenerator_ooo okularcore qca-qt5)
target_link_libraries(okularGenerator_ooo qca-qt5)
endif ()
if (KF5Wallet_FOUND)
target_link_libraries(okularGenerator_ooo KF5::Wallet)
endif ()
########### install files ###############

View file

@ -14,7 +14,9 @@
#include <KAboutData>
#include <KLocalizedString>
#include <kconfigdialog.h>
#include <kwallet.h>
#ifdef WITH_KWALLET
# include <kwallet.h>
#endif
OKULAR_EXPORT_PLUGIN(KOOOGenerator, "libokularGenerator_ooo.json")
@ -33,7 +35,9 @@ void KOOOGenerator::addPages( KConfigDialog* dlg )
void KOOOGenerator::walletDataForFile( const QString &fileName, QString *walletName, QString *walletFolder, QString *walletKey ) const
{
*walletKey = fileName + QStringLiteral("/opendocument");
#ifdef WITH_KWALLET
*walletName = KWallet::Wallet::LocalWallet();
*walletFolder = KWallet::Wallet::PasswordFolder();
#endif
}
#include "generator_ooo.moc"

View file

@ -68,7 +68,9 @@
#include <KStandardShortcut>
#include <KToggleAction>
#include <KToggleFullScreenAction>
#ifdef WITH_KWALLET
#include <KWallet>
#endif
#include <KXMLGUIClient>
#include <KXMLGUIFactory>
@ -1385,6 +1387,7 @@ Document::OpenResult Part::doOpenFile( const QMimeType &mimeA, const QString &fi
}
m_documentOpenWithPassword = false;
#ifdef WITH_KWALLET
// if the file didn't open correctly it might be encrypted, so ask for a pass
QString walletName, walletFolder, walletKey;
m_document->walletDataForFile(fileNameToOpen, &walletName, &walletFolder, &walletKey);
@ -1459,6 +1462,7 @@ Document::OpenResult Part::doOpenFile( const QMimeType &mimeA, const QString &fi
}
}
}
#endif
}
if ( openResult == Document::OpenSuccess )