From 356229a74fa7ce88c33d09e336c7c2ddcc9b4b44 Mon Sep 17 00:00:00 2001 From: Aleix Pol Date: Thu, 17 May 2018 19:52:01 +0200 Subject: [PATCH] Kirigami/Android: Try to get all android-specific code together Create a separate android file for such code --- mobile/app/CMakeLists.txt | 4 ++++ mobile/app/android.cpp | 30 ++++++++++++++++++++++++++ mobile/app/android.h | 45 +++++++++++++++++++++++++++++++++++++++ mobile/app/main.cpp | 27 +---------------------- 4 files changed, 80 insertions(+), 26 deletions(-) create mode 100644 mobile/app/android.cpp create mode 100644 mobile/app/android.h diff --git a/mobile/app/CMakeLists.txt b/mobile/app/CMakeLists.txt index da7d23ba5..f4f06ef88 100644 --- a/mobile/app/CMakeLists.txt +++ b/mobile/app/CMakeLists.txt @@ -1,6 +1,10 @@ set(CMAKE_AUTORCC ON) add_executable(okularkirigami main.cpp app.qrc) target_link_libraries(okularkirigami Qt5::Widgets Qt5::Qml KF5::I18n) +if (ANDROID) + target_sources(okularkirigami PRIVATE android.cpp) +endif() + install(TARGETS okularkirigami ${KDE_INSTALL_TARGETS_DEFAULT_ARGS}) install(FILES package/metadata.desktop DESTINATION ${XDG_APPS_INSTALL_DIR} RENAME org.kde.okular.kirigami.desktop) diff --git a/mobile/app/android.cpp b/mobile/app/android.cpp new file mode 100644 index 000000000..40afc3982 --- /dev/null +++ b/mobile/app/android.cpp @@ -0,0 +1,30 @@ +/************************************************************************************* + * Copyright (C) 2018 by Aleix Pol * + * * + * This program is free software; you can redistribute it and/or * + * modify it under the terms of the GNU General Public License * + * as published by the Free Software Foundation; either version 2 * + * of the License, or (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the Free Software * + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA * + *************************************************************************************/ + +#include "android.h" + +void Java_org_kde_something_FileClass_openUri(JNIEnv *env, + jobject /*obj*/, + jstring uri) +{ + jboolean isCopy = false; + const char* utf = env->GetStringUTFChars(uri, &isCopy); + handler.openUri(QString::fromUtf8(utf)); + env->ReleaseStringUTFChars(uri, utf); + +} diff --git a/mobile/app/android.h b/mobile/app/android.h new file mode 100644 index 000000000..358c70f0e --- /dev/null +++ b/mobile/app/android.h @@ -0,0 +1,45 @@ +/************************************************************************************* + * Copyright (C) 2018 by Aleix Pol * + * * + * This program is free software; you can redistribute it and/or * + * modify it under the terms of the GNU General Public License * + * as published by the Free Software Foundation; either version 2 * + * of the License, or (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the Free Software * + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA * + *************************************************************************************/ + +#ifndef ANDROID_H +#define ANDROID_H + +#include +#include + +class URIHandler { +public: + void openUri(const QString &uri) { + m_lastUrl = uri; + } + + QString m_lastUrl; +}; + +static URIHandler handler; + +extern "C" { + +JNIEXPORT void JNICALL + Java_org_kde_something_FileClass_openUri(JNIEnv *env, + jobject /*obj*/, + jstring uri); + +} + +#endif diff --git a/mobile/app/main.cpp b/mobile/app/main.cpp index dd4c5fd13..139c587b2 100644 --- a/mobile/app/main.cpp +++ b/mobile/app/main.cpp @@ -31,32 +31,7 @@ #include #ifdef __ANDROID__ -#include - -class URIHandler : public QObject { -public: - void openUri(const QString &uri) { - m_lastUrl = uri; - } - - QString m_lastUrl; -} handler; - -extern "C" { - -JNIEXPORT void JNICALL - Java_org_kde_something_FileClass_openUri(JNIEnv *env, - jobject /*obj*/, - jstring uri) -{ - jboolean isCopy = false; - const char* utf = env->GetStringUTFChars(uri, &isCopy); - handler.openUri(QString::fromUtf8(utf)); - env->ReleaseStringUTFChars(uri, utf); - -} - -} +#include "android.h" Q_DECL_EXPORT #endif