if (!showCalendarSettings(settings)) {
return false;
}
}
GoogleService myService = new GoogleService("cl", "tvbrowser-tvbrowsercalenderplugin-" + CalendarExportPlugin.getInstance().getInfo().getVersion().toString());
myService.setUserCredentials(settings.getExporterProperty(USERNAME).trim(), mPassword);
URL postUrl =
new URL("http://www.google.com/calendar/feeds/" + settings.getExporterProperty(SELECTED_CALENDAR) + "/private/full");
SimpleDateFormat formatDay = new SimpleDateFormat("yyyy-MM-dd");
formatDay.setTimeZone(TimeZone.getTimeZone("GMT"));
SimpleDateFormat formatTime = new SimpleDateFormat("HH:mm:ss");
formatTime.setTimeZone(TimeZone.getTimeZone("GMT"));
ParamParser parser = new ParamParser();
for (Program program : programs) {
final String title = parser.analyse(formatting.getTitleValue(), program);
// First step: search for event in calendar
boolean createEvent = true;
CalendarEventEntry entry = findEntryForProgram(myService, postUrl, title, program);
if (entry != null) {
int ret = JOptionPane.showConfirmDialog(null, mLocalizer.msg("alreadyAvailable", "already available", program.getTitle()), mLocalizer.msg("title", "Add event?"), JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE);
if (ret != JOptionPane.YES_OPTION) {
createEvent = false;
}
}
// add event to calendar
if (createEvent) {
EventEntry myEntry = new EventEntry();
myEntry.setTitle(new PlainTextConstruct(title));
String desc = parser.analyse(formatting.getContentValue(), program);
myEntry.setContent(new PlainTextConstruct(desc));
Calendar c = CalendarToolbox.getStartAsCalendar(program);
DateTime startTime = new DateTime(c.getTime(), c.getTimeZone());
c = CalendarToolbox.getEndAsCalendar(program);
DateTime endTime = new DateTime(c.getTime(), c.getTimeZone());
When eventTimes = new When();
eventTimes.setStartTime(startTime);
eventTimes.setEndTime(endTime);
myEntry.addTime(eventTimes);
if (settings.getExporterProperty(REMINDER, false)) {
int reminderMinutes = 0;
try {
reminderMinutes = settings.getExporterProperty(REMINDER_MINUTES, 0);
} catch (NumberFormatException e) {
e.printStackTrace();
}
if (settings.getExporterProperty(REMINDER_ALERT, false)) {
addReminder(myEntry, reminderMinutes, Reminder.Method.ALERT);
}
if (settings.getExporterProperty(REMINDER_EMAIL, false)) {
addReminder(myEntry, reminderMinutes, Reminder.Method.EMAIL);
}
if (settings.getExporterProperty(REMINDER_SMS, false)) {
addReminder(myEntry, reminderMinutes, Reminder.Method.SMS);
}
}
if (settings.isShowBusy()) {
myEntry.setTransparency(BaseEventEntry.Transparency.OPAQUE);
}
else {
myEntry.setTransparency(BaseEventEntry.Transparency.TRANSPARENT);
}
// Send the request and receive the response:
myService.insert(postUrl, myEntry);
uploadedItems = true;
}
}
if (uploadedItems) {