Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import at.bitfire.synctools.exception.InvalidICalendarException
import net.fortuna.ical4j.model.Component
import net.fortuna.ical4j.model.ComponentContainer
import net.fortuna.ical4j.model.ComponentList
import net.fortuna.ical4j.model.Parameter
import net.fortuna.ical4j.model.Property
import net.fortuna.ical4j.model.PropertyContainer
import net.fortuna.ical4j.model.PropertyList
Expand Down Expand Up @@ -62,6 +63,10 @@ operator fun PropertyList.plusAssign(property: Property) {
add(property)
}

operator fun Property.plusAssign(parameter: Parameter) {
add<Property>(parameter)
}

operator fun <T : Component> ComponentContainer<T>.plusAssign(component: T) {
add<ComponentContainer<T>>(component)
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ package at.bitfire.synctools.mapping.calendar
import android.content.ContentValues
import android.provider.CalendarContract
import android.provider.CalendarContract.Attendees
import at.bitfire.synctools.icalendar.plusAssign
import net.fortuna.ical4j.model.Parameter
import net.fortuna.ical4j.model.parameter.CuType
import net.fortuna.ical4j.model.parameter.Email
Expand Down Expand Up @@ -81,11 +82,10 @@ object AttendeeMappings {

}

TODO("ical4j 4.x")
/*if (cuType != null && cuType != CuType.INDIVIDUAL)
attendee.parameters.add(cuType)
if (cuType != null && cuType != CuType.INDIVIDUAL)
attendee += cuType
if (role != null && role != Role.REQ_PARTICIPANT)
attendee.parameters.add(role)*/
attendee += role
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ package at.bitfire.synctools.mapping.calendar.handler
import android.content.ContentValues
import android.content.Entity
import android.provider.CalendarContract.Attendees
import at.bitfire.synctools.icalendar.plusAssign
import at.bitfire.synctools.mapping.calendar.AttendeeMappings
import net.fortuna.ical4j.model.component.VEvent
import net.fortuna.ical4j.model.parameter.Cn
Expand All @@ -34,8 +35,7 @@ class AttendeesHandler: AndroidEventFieldHandler {
private fun populateAttendee(row: ContentValues, to: VEvent) {
logger.log(Level.FINE, "Read event attendee from calendar provider", row)

TODO("ical4j 4.x")
/*try {
try {
val attendee: Attendee
val email = row.getAsString(Attendees.ATTENDEE_EMAIL)
val idNS = row.getAsString(Attendees.ATTENDEE_ID_NAMESPACE)
Expand All @@ -44,33 +44,32 @@ class AttendeesHandler: AndroidEventFieldHandler {
if (idNS != null || id != null) {
// attendee identified by namespace and ID
attendee = Attendee(URI(idNS, id, null))
email?.let { attendee.parameters.add(Email(it)) }
email?.let { attendee += Email(it) }
} else
// attendee identified by email address
attendee = Attendee(URI("mailto", email, null))
val params = attendee.parameters

// always add RSVP (offer attendees to accept/decline)
params.add(Rsvp.TRUE)
attendee += Rsvp.TRUE

row.getAsString(Attendees.ATTENDEE_NAME)?.let { cn -> params.add(Cn(cn)) }
row.getAsString(Attendees.ATTENDEE_NAME)?.let { cn -> attendee += Cn(cn) }

// type/relation mapping is complex and thus outsourced to AttendeeMappings
AttendeeMappings.androidToICalendar(row, attendee)

// status
when (row.getAsInteger(Attendees.ATTENDEE_STATUS)) {
Attendees.ATTENDEE_STATUS_INVITED -> params.add(PartStat.NEEDS_ACTION)
Attendees.ATTENDEE_STATUS_ACCEPTED -> params.add(PartStat.ACCEPTED)
Attendees.ATTENDEE_STATUS_DECLINED -> params.add(PartStat.DECLINED)
Attendees.ATTENDEE_STATUS_TENTATIVE -> params.add(PartStat.TENTATIVE)
Attendees.ATTENDEE_STATUS_INVITED -> attendee += PartStat.NEEDS_ACTION
Attendees.ATTENDEE_STATUS_ACCEPTED -> attendee += PartStat.ACCEPTED
Attendees.ATTENDEE_STATUS_DECLINED -> attendee += PartStat.DECLINED
Attendees.ATTENDEE_STATUS_TENTATIVE -> attendee += PartStat.TENTATIVE
Attendees.ATTENDEE_STATUS_NONE -> { /* no information, don't add PARTSTAT */ }
}

to.properties += attendee
to += attendee
} catch (e: URISyntaxException) {
logger.log(Level.WARNING, "Couldn't parse attendee information, ignoring", e)
}*/
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -8,23 +8,24 @@ package at.bitfire.synctools.mapping.calendar.handler

import android.content.Entity
import android.provider.CalendarContract.Events
import at.bitfire.synctools.icalendar.plusAssign
import net.fortuna.ical4j.model.component.VEvent
import net.fortuna.ical4j.model.property.Transp
import net.fortuna.ical4j.model.property.immutable.ImmutableTransp

class AvailabilityHandler: AndroidEventFieldHandler {

override fun process(from: Entity, main: Entity, to: VEvent) {
TODO("ical4j 4.x")
/*val transp: Transp = when (from.entityValues.getAsInteger(Events.AVAILABILITY)) {
val transp: Transp = when (from.entityValues.getAsInteger(Events.AVAILABILITY)) {
Events.AVAILABILITY_FREE ->
Transp.TRANSPARENT
ImmutableTransp.TRANSPARENT

/* Events.AVAILABILITY_BUSY, Events.AVAILABILITY_TENTATIVE */
else ->
Transp.OPAQUE
ImmutableTransp.OPAQUE
}
if (transp != Transp.OPAQUE) // iCalendar default value is OPAQUE
to.properties += transp*/
if (transp != ImmutableTransp.OPAQUE) // iCalendar default value is OPAQUE
to += transp
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ package at.bitfire.synctools.mapping.calendar.handler

import android.content.Entity
import android.provider.CalendarContract.ExtendedProperties
import at.bitfire.synctools.icalendar.plusAssign
import at.bitfire.synctools.storage.calendar.EventsContract
import net.fortuna.ical4j.model.TextList
import net.fortuna.ical4j.model.component.VEvent
Expand All @@ -20,10 +21,9 @@ class CategoriesHandler: AndroidEventFieldHandler {
val categories = extended.firstOrNull { it.getAsString(ExtendedProperties.NAME) == EventsContract.EXTNAME_CATEGORIES }
val listValue = categories?.getAsString(ExtendedProperties.VALUE)
if (listValue != null) {
TODO("ical4j 4.x")
/*to.properties += Categories(TextList(
listValue.split(EventsContract.CATEGORIES_SEPARATOR).toTypedArray()
))*/
to += Categories(TextList(
listValue.split(EventsContract.CATEGORIES_SEPARATOR)
))
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ package at.bitfire.synctools.mapping.calendar.handler
import android.content.Entity
import android.provider.CalendarContract.Attendees
import android.provider.CalendarContract.Events
import at.bitfire.synctools.icalendar.plusAssign
import net.fortuna.ical4j.model.component.VEvent
import net.fortuna.ical4j.model.property.Organizer
import java.net.URI
Expand All @@ -30,8 +31,7 @@ class OrganizerHandler: AndroidEventFieldHandler {
val hasAttendees = from.subValues.any { it.uri == Attendees.CONTENT_URI }
if (hasAttendees && mainValues.containsKey(Events.ORGANIZER))
try {
TODO("ical4j 4.x")
//to.properties += Organizer(URI("mailto", mainValues.getAsString(Events.ORGANIZER), null))
to += Organizer(URI("mailto", mainValues.getAsString(Events.ORGANIZER), null))
} catch (e: URISyntaxException) {
logger.log(Level.WARNING, "Error when creating ORGANIZER mailto URI, ignoring", e)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,14 @@ import android.content.Entity
import android.provider.CalendarContract.Events
import android.provider.CalendarContract.Reminders
import android.util.Patterns
import at.bitfire.synctools.icalendar.plusAssign
import net.fortuna.ical4j.model.component.VAlarm
import net.fortuna.ical4j.model.component.VEvent
import net.fortuna.ical4j.model.property.Action
import net.fortuna.ical4j.model.property.Attendee
import net.fortuna.ical4j.model.property.Description
import net.fortuna.ical4j.model.property.Summary
import net.fortuna.ical4j.model.property.immutable.ImmutableAction
import java.net.URI
import java.time.Duration
import java.util.logging.Level
Expand All @@ -40,32 +42,30 @@ class RemindersHandler(
val eventTitle = event.entityValues.getAsString(Events.TITLE) ?: "Calendar Event Reminder"

val alarm = VAlarm(Duration.ofMinutes(-row.getAsLong(Reminders.MINUTES)))
TODO("ical4j 4.x")
/*val props = alarm.properties
when (row.getAsInteger(Reminders.METHOD)) {
Reminders.METHOD_EMAIL -> {
if (Patterns.EMAIL_ADDRESS.matcher(accountName).matches()) {
props += Action.EMAIL
alarm += ImmutableAction.EMAIL
// ACTION:EMAIL requires SUMMARY, DESCRIPTION, ATTENDEE
props += Summary(eventTitle)
props += Description(eventTitle)
alarm += Summary(eventTitle)
alarm += Description(eventTitle)
// Android doesn't allow to save email reminder recipients, so we always use the
// account name (should be account owner's email address)
props += Attendee(URI("mailto", accountName, null))
alarm += Attendee(URI("mailto", accountName, null))
} else {
logger.warning("Account name is not an email address; changing EMAIL reminder to DISPLAY")
props += Action.DISPLAY
props += Description(eventTitle)
alarm += ImmutableAction.DISPLAY
alarm += Description(eventTitle)
}
}

// default: set ACTION:DISPLAY (requires DESCRIPTION)
else -> {
props += Action.DISPLAY
props += Description(eventTitle)
alarm += ImmutableAction.DISPLAY
alarm += Description(eventTitle)
}
}
to.components += alarm*/
to += alarm
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
package at.bitfire.synctools.mapping.calendar.handler

import android.content.Entity
import at.bitfire.synctools.icalendar.plusAssign
import at.bitfire.synctools.storage.calendar.EventsContract
import net.fortuna.ical4j.model.component.VEvent
import net.fortuna.ical4j.model.property.Sequence
Expand All @@ -15,9 +16,8 @@ class SequenceHandler: AndroidEventFieldHandler {

override fun process(from: Entity, main: Entity, to: VEvent) {
val seqNo = from.entityValues.getAsInteger(EventsContract.COLUMN_SEQUENCE)
TODO("ical4j 4.x")
/*if (seqNo != null && seqNo > 0)
to.properties += Sequence(seqNo)*/
if (seqNo != null && seqNo > 0)
to += Sequence(seqNo)
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -8,28 +8,28 @@ package at.bitfire.synctools.mapping.calendar.handler

import android.content.Entity
import android.provider.CalendarContract.Events
import at.bitfire.synctools.icalendar.plusAssign
import net.fortuna.ical4j.model.component.VEvent
import net.fortuna.ical4j.model.property.Status
import net.fortuna.ical4j.model.property.immutable.ImmutableStatus

class StatusHandler: AndroidEventFieldHandler {

override fun process(from: Entity, main: Entity, to: VEvent) {
TODO("ical4j 4.x")
/*val status = when (from.entityValues.getAsInteger(Events.STATUS)) {
val status = when (from.entityValues.getAsInteger(Events.STATUS)) {
Events.STATUS_CONFIRMED ->
Status.VEVENT_CONFIRMED
ImmutableStatus.VEVENT_CONFIRMED

Events.STATUS_TENTATIVE ->
Status.VEVENT_TENTATIVE
ImmutableStatus.VEVENT_TENTATIVE

Events.STATUS_CANCELED ->
Status.VEVENT_CANCELLED
ImmutableStatus.VEVENT_CANCELLED

else ->
null
}
if (status != null)
to.properties += status*/
to += status
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ package at.bitfire.synctools.mapping.calendar.handler
import android.content.Entity
import android.provider.CalendarContract.ExtendedProperties
import at.bitfire.ical4android.UnknownProperty
import at.bitfire.synctools.icalendar.plusAssign
import net.fortuna.ical4j.model.Property
import net.fortuna.ical4j.model.component.VEvent
import org.json.JSONException
Expand All @@ -27,9 +28,8 @@ class UnknownPropertiesHandler: AndroidEventFieldHandler {
for (json in jsonProperties)
try {
val prop = UnknownProperty.fromJsonString(json)
TODO("ical4j 4.x")
/*if (!EXCLUDED.contains(prop.name))
to.properties += prop*/
if (!EXCLUDED.contains(prop.name))
to += prop
} catch (e: JSONException) {
logger.log(Level.WARNING, "Couldn't parse unknown properties", e)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ package at.bitfire.synctools.mapping.calendar.handler

import android.content.Entity
import android.provider.CalendarContract.ExtendedProperties
import at.bitfire.synctools.icalendar.plusAssign
import at.bitfire.synctools.storage.calendar.EventsContract
import net.fortuna.ical4j.model.component.VEvent
import net.fortuna.ical4j.model.property.Url
Expand All @@ -26,9 +27,8 @@ class UrlHandler: AndroidEventFieldHandler {
} catch (_: URISyntaxException) {
null
}
TODO("ical4j 4.x")
/*if (uri != null)
to.properties += Url(uri)*/
if (uri != null)
to += Url(uri)
}
}

Expand Down
Loading