Kirigami/Android: Try to get all android-specific code together

Create a separate android file for such code
This commit is contained in:
Aleix Pol 2018-05-17 19:52:01 +02:00
parent 600e72100b
commit 356229a74f
4 changed files with 80 additions and 26 deletions

View file

@ -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)

30
mobile/app/android.cpp Normal file
View file

@ -0,0 +1,30 @@
/*************************************************************************************
* Copyright (C) 2018 by Aleix Pol <aleixpol@kde.org> *
* *
* 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);
}

45
mobile/app/android.h Normal file
View file

@ -0,0 +1,45 @@
/*************************************************************************************
* Copyright (C) 2018 by Aleix Pol <aleixpol@kde.org> *
* *
* 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 <QString>
#include <jni.h>
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

View file

@ -31,32 +31,7 @@
#include <QTimer>
#ifdef __ANDROID__
#include <jni.h>
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