Commit be8c44be authored by Volker Krause's avatar Volker Krause
Browse files

Adapt solidextras to build with Qt6 as well

parent 95e93d48
Pipeline #185615 passed with stage
in 1 minute and 39 seconds
......@@ -39,7 +39,9 @@ target_include_directories(SolidExtras PUBLIC "$<BUILD_INTERFACE:${CMAKE_CURRENT
target_link_libraries(SolidExtras PUBLIC Qt::Core)
if (ANDROID)
target_link_libraries(SolidExtras PRIVATE Qt::AndroidExtras)
if (QT_MAJOR_VERSION EQUAL "5")
target_link_libraries(SolidExtras PRIVATE Qt::AndroidExtras)
endif()
else ()
target_link_libraries(SolidExtras PRIVATE Qt::DBus)
if (TARGET KF5::NetworkManagerQt)
......
......@@ -10,7 +10,7 @@ buildscript {
}
dependencies {
classpath 'com.android.tools.build:gradle:3.6.4'
classpath 'com.android.tools.build:gradle:@Gradle_ANDROID_GRADLE_PLUGIN_VERSION@'
}
}
......
......@@ -7,8 +7,15 @@
#include "androidbrightnessbackend.h"
#include <QDebug>
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
#include <QtAndroid>
#include <QAndroidJniObject>
#else
#include <QCoreApplication>
#include <QJniObject>
using QAndroidJniObject = QJniObject;
#endif
AndroidBrightnessBackend::AndroidBrightnessBackend(QObject *parent)
: BrightnessBackend(parent)
......@@ -21,12 +28,22 @@ AndroidBrightnessBackend::~AndroidBrightnessBackend()
float AndroidBrightnessBackend::brightness() const
{
return QAndroidJniObject::callStaticMethod<jfloat>("org.kde.solidextras.Solid", "getBrightness", "(Landroid/app/Activity;)F", QtAndroid::androidActivity().object());
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
const auto activity = QtAndroid::androidActivity();
#else
const QJniObject activity = QNativeInterface::QAndroidApplication::context();
#endif
return QAndroidJniObject::callStaticMethod<jfloat>("org.kde.solidextras.Solid", "getBrightness", "(Landroid/app/Activity;)F", activity.object());
}
void AndroidBrightnessBackend::setBrightness(float brightness)
{
QAndroidJniObject::callStaticMethod<void>("org.kde.solidextras.Solid", "setBrightness", "(Landroid/app/Activity;F)V", QtAndroid::androidActivity().object(), brightness);
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
const auto activity = QtAndroid::androidActivity();
#else
const QJniObject activity = QNativeInterface::QAndroidApplication::context();
#endif
QAndroidJniObject::callStaticMethod<void>("org.kde.solidextras.Solid", "setBrightness", "(Landroid/app/Activity;F)V", activity.object(), brightness);
}
float AndroidBrightnessBackend::maxBrightness() const
......
......@@ -7,8 +7,15 @@
#include "androidlockbackend.h"
#include <QDebug>
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
#include <QtAndroid>
#include <QAndroidJniObject>
#else
#include <QCoreApplication>
#include <QJniObject>
using QAndroidJniObject = QJniObject;
#endif
AndroidLockBackend::AndroidLockBackend(QObject *parent)
: LockBackend(parent)
......@@ -21,11 +28,21 @@ AndroidLockBackend::~AndroidLockBackend()
void AndroidLockBackend::setInhibitionOff()
{
QAndroidJniObject::callStaticMethod<void>("org.kde.solidextras.Solid", "setLockInhibitionOff", "(Landroid/app/Activity;)V", QtAndroid::androidActivity().object());
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
const auto activity = QtAndroid::androidActivity();
#else
const QJniObject activity = QNativeInterface::QAndroidApplication::context();
#endif
QAndroidJniObject::callStaticMethod<void>("org.kde.solidextras.Solid", "setLockInhibitionOff", "(Landroid/app/Activity;)V", activity.object());
}
void AndroidLockBackend::setInhibitionOn(const QString &explanation)
{
Q_UNUSED(explanation)
QAndroidJniObject::callStaticMethod<void>("org.kde.solidextras.Solid", "setLockInhibitionOn", "(Landroid/app/Activity;)V", QtAndroid::androidActivity().object());
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
const auto activity = QtAndroid::androidActivity();
#else
const QJniObject activity = QNativeInterface::QAndroidApplication::context();
#endif
QAndroidJniObject::callStaticMethod<void>("org.kde.solidextras.Solid", "setLockInhibitionOn", "(Landroid/app/Activity;)V", activity.object());
}
......@@ -6,9 +6,17 @@
#include "networkstatus.h"
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
#include <QtAndroid>
#include <QAndroidJniEnvironment>
#include <QAndroidJniObject>
#else
#include <QCoreApplication>
#include <QJniEnvironment>
#include <QJniObject>
using QAndroidJniEnvironment = QJniEnvironment;
using QAndroidJniObject = QJniObject;
#endif
using namespace SolidExtras;
......@@ -42,7 +50,12 @@ NetworkStatusBackend::NetworkStatusBackend(QObject *parent)
static JNINativeMethod methods = {"networkStatusChanged", "()V", reinterpret_cast<void *>(networkStatusChangedCallback)};
env->RegisterNatives(cls, &methods, sizeof(methods) / sizeof(JNINativeMethod));
m_obj = QAndroidJniObject("org/kde/solidextras/NetworkStatus", "(Landroid/content/Context;)V", QtAndroid::androidContext().object());
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
const auto context = QtAndroid::androidContext();
#else
const QJniObject context = QNativeInterface::QAndroidApplication::context();
#endif
m_obj = QAndroidJniObject("org/kde/solidextras/NetworkStatus", "(Landroid/content/Context;)V", context.object());
}
NetworkStatusBackend* NetworkStatusBackend::instance()
......@@ -53,12 +66,22 @@ NetworkStatusBackend* NetworkStatusBackend::instance()
bool NetworkStatusBackend::connectivity() const
{
return m_obj.callMethod<jboolean>("connectivity", "(Landroid/content/Context;)Z", QtAndroid::androidContext().object());
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
const auto context = QtAndroid::androidContext();
#else
const QJniObject context = QNativeInterface::QAndroidApplication::context();
#endif
return m_obj.callMethod<jboolean>("connectivity", "(Landroid/content/Context;)Z", context.object());
}
bool NetworkStatusBackend::metered() const
{
return m_obj.callMethod<jboolean>("metered", "(Landroid/content/Context;)Z", QtAndroid::androidContext().object());
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
const auto context = QtAndroid::androidContext();
#else
const QJniObject context = QNativeInterface::QAndroidApplication::context();
#endif
return m_obj.callMethod<jboolean>("metered", "(Landroid/content/Context;)Z", context.object());
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment