Commit 0f6845d0 authored by Volker Krause's avatar Volker Krause

Implement scanning the Android calendar for itinerary data added by KMail

As this isn't standardized we assume the serialization format of DavDroid
for now.

This doesn't have any effect yet, the communication back to C++ is still
missing.
parent 276367e5
......@@ -57,6 +57,7 @@
<supports-screens android:largeScreens="true" android:normalScreens="true" android:anyDensity="true" android:smallScreens="true"/>
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.READ_CALENDAR"/>
<!-- %%INSERT_PERMISSIONS -->
<!-- %%INSERT_FEATURES -->
......
......@@ -279,3 +279,13 @@ void ApplicationController::importLocalFile(const QUrl &url)
m_resMgr->importReservation(url);
}
}
void ApplicationController::checkCalendar()
{
#ifdef Q_OS_ANDROID
const auto activity = QtAndroid::androidActivity();
if (activity.isValid()) {
activity.callMethod<void>("checkCalendar");
}
#endif
}
......@@ -50,6 +50,8 @@ public:
#endif
void importLocalFile(const QUrl &url);
Q_INVOKABLE void checkCalendar();
private:
ReservationManager *m_resMgr = nullptr;
PkPassManager *m_pkPassMgr = nullptr;
......
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.2.3'
}
}
allprojects {
repositories {
jcenter()
}
}
apply plugin: 'com.android.application'
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'org.mnode.ical4j:ical4j:2.2.0'
}
android {
/*******************************************************
* The following variables:
* - androidBuildToolsVersion,
* - androidCompileSdkVersion
* - qt5AndroidDir - holds the path to qt android files
* needed to build any Qt application
* on Android.
*
* are defined in gradle.properties file. This file is
* updated by QtCreator and androiddeployqt tools.
* Changing them manually might break the compilation!
*******************************************************/
compileSdkVersion androidCompileSdkVersion.toInteger()
buildToolsVersion androidBuildToolsVersion
sourceSets {
main {
manifest.srcFile 'AndroidManifest.xml'
java.srcDirs = [qt5AndroidDir + '/src', 'src', 'java']
aidl.srcDirs = [qt5AndroidDir + '/src', 'src', 'aidl']
res.srcDirs = [qt5AndroidDir + '/res', 'res']
resources.srcDirs = ['src']
renderscript.srcDirs = ['src']
assets.srcDirs = ['assets']
jniLibs.srcDirs = ['libs']
}
}
lintOptions {
abortOnError false
}
}
......@@ -46,6 +46,12 @@ Kirigami.ApplicationWindow {
iconName: "document-open"
onTriggered: importDialog.importPass()
},
Kirigami.Action {
text: i18n("Check Calendar")
iconName: "view-calendar-day"
onTriggered: _appController.checkCalendar()
visible: Qt.platform.os == "android"
},
Kirigami.Action {
text: i18n("Check for Updates")
iconName: "view-refresh"
......
......@@ -19,12 +19,17 @@ package org.kde.itinerary;
import org.qtproject.qt5.android.bindings.QtActivity;
import net.fortuna.ical4j.model.property.XProperty;
import android.content.ContentResolver;
import android.content.Intent;
import android.database.Cursor;
import android.net.Uri;
import android.provider.CalendarContract;
import android.util.Log;
import java.io.*;
import java.util.*;
public class Activity extends QtActivity
......@@ -65,4 +70,49 @@ public class Activity extends QtActivity
Intent mapIntent = new Intent(Intent.ACTION_VIEW, mapIntentUri);
startActivity(mapIntent);
}
/** 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() + " ))";
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) + ")";
Cursor propCursor = getContentResolver().query(CalendarContract.ExtendedProperties.CONTENT_URI, propColumns, propSelection, null, null);
while (propCursor.moveToNext()) {
if (propCursor.getString(0) == null || !propCursor.getString(0).equals("unknown-property") || propCursor.getString(1) == null) {
continue;
}
ByteArrayInputStream bis = new ByteArrayInputStream(android.util.Base64.decode(propCursor.getString(1), android.util.Base64.NO_WRAP));
try {
ObjectInputStream ois = new ObjectInputStream(bis);
Object prop = ois.readObject();
if (prop instanceof XProperty) {
// TODO send this back to the C++ side
Log.i(TAG, ((XProperty)prop).getValue());
}
} catch (Exception e) {
Log.i(TAG, e.toString());
continue;
}
}
}
}
}
Markdown is supported
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