Commit 060d78c4 authored by Volker Krause's avatar Volker Krause
Browse files

Remove the old Android-only calendar import code

parent 47d7daf6
Pipeline #196687 passed with stage
in 4 minutes and 59 seconds
......@@ -25,7 +25,6 @@ JNI_TYPE(org, kde, itinerary, Activity)
class ItineraryActivity {
JNI_UNMANAGED_OBJECT(ItineraryActivity, org::kde::itinerary::Activity)
public:
JNI_METHOD(void, checkCalendar)
JNI_METHOD(KAndroidExtras::Jni::Array<KAndroidExtras::java::lang::String>, attachmentsForIntent, KAndroidExtras::android::content::Intent)
JNI_METHOD(KAndroidExtras::android::net::Uri, openDocument, KAndroidExtras::java::lang::String)
private:
......
......@@ -25,51 +25,8 @@ public class Activity extends QtActivity
{
private static final String TAG = "org.kde.itinerary";
public native void importDavDroidJson(String data);
public native void importFromIntent(Intent data);
/** Check the calendar for with JSON-LD data.
* This assumes the custom property serialization format used by DavDroid.
*/
public void checkCalendar()
{
Calendar startTime = Calendar.getInstance();
startTime.add(Calendar.DAY_OF_YEAR, -5);
Calendar endTime = Calendar.getInstance();
endTime.add(Calendar.MONTH, 6);
String[] eventColumns = new String[] { "uid2445", "title", "_id" };
String[] propColumns = new String[] { "name", "value" };
String eventSelection = "(( " + CalendarContract.Events.DTSTART + " >= " + startTime.getTimeInMillis()
+ " ) AND ( " + CalendarContract.Events.DTSTART + " <= " + endTime.getTimeInMillis() + " ))";
try (Cursor cursor = getContentResolver().query(CalendarContract.Events.CONTENT_URI, eventColumns, eventSelection, null, null)) {
while (cursor.moveToNext()) {
if (cursor.getString(0) == null || !cursor.getString(0).startsWith("KIT-")) {
continue;
}
Log.i(TAG, cursor.getString(1));
String propSelection = "(event_id == " + cursor.getInt(2) + ")";
try (Cursor propCursor = getContentResolver().query(CalendarContract.ExtendedProperties.CONTENT_URI, propColumns, propSelection, null, null)) {
while (propCursor.moveToNext()) {
String propName = propCursor.getString(0);
String propValue = propCursor.getString(1);
if (propName == null || propValue == null) {
continue;
}
Log.i(TAG, propName);
if (propName.equals("unknown-property.v2") || propName.contains("vnd.ical4android.unknown-property")) {
importDavDroidJson(propValue);
}
}
}
}
}
}
@Override
protected void onNewIntent(Intent intent) {
super.onNewIntent(intent);
......
......@@ -74,14 +74,7 @@
#include <kandroidextras/jniarray.h>
#include <kandroidextras/jnisignature.h>
#include <kandroidextras/jnitypes.h>
#include <kandroidextras/manifestpermission.h>
#include <kandroidextras/uri.h>
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
#include <QtAndroid>
#else
#include <private/qandroidextras_p.h>
#endif
#endif
#include <memory>
......@@ -90,25 +83,6 @@ using namespace KItinerary;
#ifdef Q_OS_ANDROID
static void importDavDroidJson(JNIEnv *env, jobject that, jstring data)
{
Q_UNUSED(that)
const char *str = env->GetStringUTFChars(data, nullptr);
const auto doc = QJsonDocument::fromJson(str);
env->ReleaseStringUTFChars(data, str);
const auto array = doc.array();
if (array.size() < 2 || array.at(0).toString() != QLatin1String("X-KDE-KITINERARY-RESERVATION")) {
return;
}
auto propValue = array.at(1).toString().toUtf8();
// work around ical/JSON mis-encoding with newer DAVx⁵ versions
propValue.replace("\\,", ",");
ApplicationController::instance()->importData(propValue);
}
static void importFromIntent(JNIEnv *env, jobject that, jobject data)
{
Q_UNUSED(that)
......@@ -118,7 +92,6 @@ static void importFromIntent(JNIEnv *env, jobject that, jobject data)
static const JNINativeMethod methods[] = {
{"importFromIntent", "(Landroid/content/Intent;)V", (void*)importFromIntent},
{"importDavDroidJson", "(Ljava/lang/String;)V", (void*)importDavDroidJson}
};
Q_DECL_EXPORT jint JNICALL JNI_OnLoad(JavaVM *vm, void*)
......@@ -504,32 +477,6 @@ bool ApplicationController::importGenericPkPass(const KItinerary::ExtractorDocum
return res;
}
void ApplicationController::checkCalendar()
{
#ifdef Q_OS_ANDROID
using namespace KAndroidExtras;
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
if (QtAndroid::checkPermission(ManifestPermission::READ_CALENDAR) == QtAndroid::PermissionResult::Granted) {
ItineraryActivity activity;
activity.checkCalendar();
} else {
QtAndroid::requestPermissions({ManifestPermission::READ_CALENDAR}, [this] (const QtAndroid::PermissionResultMap &result){
if (result[ManifestPermission::READ_CALENDAR] == QtAndroid::PermissionResult::Granted) {
checkCalendar();
}
});
}
#else
if (QtAndroidPrivate::checkPermission(ManifestPermission::READ_CALENDAR).result() == QtAndroidPrivate::PermissionResult::Authorized) {
ItineraryActivity activity;
activity.checkCalendar();
} else if (QtAndroidPrivate::requestPermission(ManifestPermission::READ_CALENDAR).result() == QtAndroidPrivate::PermissionResult::Authorized) {
checkCalendar();
}
#endif
#endif
}
bool ApplicationController::hasClipboardContent() const
{
const auto md = QGuiApplication::clipboard()->mimeData();
......
......@@ -62,8 +62,6 @@ public:
Q_INVOKABLE bool importData(const QByteArray &data, const QString &fileName = {});
Q_INVOKABLE bool importText(const QString &text);
Q_INVOKABLE void checkCalendar();
static ApplicationController* instance();
// data export
......
......@@ -59,12 +59,6 @@ Kirigami.ApplicationWindow {
onTriggered: ApplicationController.importFromClipboard()
enabled: ApplicationController.hasClipboardContent
},
Kirigami.Action {
text: i18n("Check Calendar")
iconName: "view-calendar-day"
onTriggered: ApplicationController.checkCalendar()
visible: Qt.platform.os == "android"
},
Kirigami.Action {
text: i18n("Check for Updates")
iconName: "view-refresh"
......
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