From: Michael Prager Date: Mon, 15 Nov 2010 09:11:31 +0000 (+0100) Subject: fixed notifications not working for calendars other than default calendar X-Git-Url: https://code.delx.au/comingnext/commitdiff_plain/32b1c2f4a166147927720ce7f92e1f9011693b1a fixed notifications not working for calendars other than default calendar --- diff --git a/comingNext/index.html b/comingNext/index.html index d66fd29..1afd1a0 100644 --- a/comingNext/index.html +++ b/comingNext/index.html @@ -79,8 +79,7 @@ var mode = 0; // 0 = homescreen, 1 = fullscreen, 2 = settings, 3 = about, 4 = ch var reqV = null; var settingsCalEntryId = null; var settingsCache = null; -var notificationRequest1; -var notificationRequest2; +var notificationRequests = new Array(); var calendarList = []; // vars for daylight saving time @@ -298,13 +297,17 @@ function requestNotification() { var criteria = new Object(); criteria.Type = "CalendarEntry"; - - try { - notificationRequest1 = calendarService.IDataSource.RequestNotification(criteria, callback); - if (notificationRequest1.ErrorCode) - error('requestNotification failed with error code ' + notificationRequest1.ErrorCode); - } catch (e) { - error("requestNotification: " + e + ', line ' + e.line); + criteria.Filter = new Object(); + for(var i=0; i < calendarList.length; i++) { + criteria.Filter.CalendarName = calendarList[i]; + try { + var notificationRequest = calendarService.IDataSource.RequestNotification(criteria, callback); + if (notificationRequest.ErrorCode) + error('requestNotification failed with error code ' + notificationRequest.ErrorCode); + notificationRequests.push(notificationRequest); + } catch (e) { + error("requestNotification: " + e + ', line ' + e.line); + } } var criteria2 = new Object(); @@ -312,16 +315,29 @@ function requestNotification() criteria2.Filter = new Object(); criteria2.Filter.LocalIdList = new Array(); criteria2.Filter.LocalIdList[0] = settingsCalEntryId; - try { - notificationRequest2 = calendarService.IDataSource.RequestNotification(criteria2, settingsCallback); - if (notificationRequest2.ErrorCode) - error('requestNotification failed with error code ' + notificationRequest2.ErrorCode); + var notificationRequest = calendarService.IDataSource.RequestNotification(criteria2, settingsCallback); + if (notificationRequest.ErrorCode) + error('requestNotification failed with error code ' + notificationRequest.ErrorCode); + notificationRequests.push(notificationRequest); } catch (e) { error("requestNotification: " + e + ', line ' + e.line); } } +function cancelNotification() +{ + for(var i=0; i < notificationRequests.length; i++) { + try { + var result = calendarService.IDataSource.Cancel(notificationRequests[i]); + if (result.ErrorCode) + error('requestNotification failed with error code ' + result.ErrorCode); + } catch (e) { + error("requestNotification: " + e + ', line ' + e.line); + } + } +} + function callback(transId, eventCode, result) { console.info("callback(): panelNum: %d transId: %d eventCode: %d result.ErrorCode: %d", panelNum, transId, eventCode, result.ErrorCode); @@ -480,6 +496,15 @@ function formatTime(date) function updateData() { console.info('updateData()'); + + // check if we got additional or less calendars since our last update + var newCalendarList = listCalendars(); + if (newCalendarList.length != calendarList.length) { + calendarList = newCalendarList; + cancelNotification(); + requestNotification(); + } + try { // meetings have time // note: anniveraries have a start time of 12:00am. So since we want to include them, we have to query the whole day and check if events have passed later