]> code.delx.au - comingnext/blobdiff - comingNext/index.html
show "loading..." text when adding homescreen widget and data is still being loaded
[comingnext] / comingNext / index.html
index e8a48400f9dd05b38f3c9cee1437871ab484c19b..3bc8f369ad7230488387562cd0a35b2978e40936 100644 (file)
@@ -7,23 +7,29 @@
 \r
 <style type="text/css">\r
 /* The following classes can be modified by widget settings */\r
-.background { }\r
-.backgroundFullscreen { }\r
+.background { color:#ffffff; background-color:#000000 }
+.backgroundFullscreen { color:#ffffff; background-color:#000000 }
 .weekDay { }\r
 .date { }\r
-.today { }\r
-.tomorrow { }\r
+.today { color:#ff0000 }
+.tomorrow { color:#0000ff }
 .time { }\r
-.now { }\r
+.now { color:#ff00ff }
 .description { }\r
-.icon { }\r
-.overdue {}\r
+.icon { width:15px; height:15px }
+.overdue { color:#ffff00 }
+.calendar1 { background-color:#0757cf }
+.calendar2 { background-color:#579f37 }
+.calendar3 { background-color:#ff9f07 }
+.calendar4 { background-color:#af8fef }
+.calendar5 { background-color:#57afbf }
+.calendar6 { background-color:#9fdf57 }
 </style>\r
 \r
 <script type="text/javascript" src="localizedTextStrings.js" charset="utf-8" />\r
 \r
 <script>\r
-// valid types for the config object are 'Int', 'Bool', 'String', 'Enum', 'UID'\r
+// valid types for the config object are 'Int', 'Bool', 'String', 'Enum', 'UID', 'Array'\r
 var config = {\r
        monthRange: { Type: 'Int', Default: 2, Value: 2,},\r
        includeTodos: { Type: 'Bool', Default: true, Value: true,},\r
@@ -50,6 +56,8 @@ var config = {
        daylightSavingOffset: { Type: 'Int', Default: 1, Value: 1,},\r
        hideWidgetOnCalendarOpen: { Type: 'Bool', Default: false, Value: false,},\r
        showCalendarIndicator: { Type: 'Bool', Default: true, Value: true,},\r
+       excludedCalendars: { Type: 'Array', Default: [], Value: [],},\r
+       enableLogging: { Type: 'Bool', Default: false, Value: false,},
        cssStyle_background: { Type: 'String', Default: 'color:#ffffff; background-color:#000000', Value: 'color:#ffffff; background-color:#000000',},\r
        cssStyle_backgroundFullscreen: { Type: 'String', Default: 'color:#ffffff; background-color:#000000', Value: 'color:#ffffff; background-color:#000000',},\r
        cssStyle_weekDay: { Type: 'String', Default: '', Value: '',},\r
@@ -61,12 +69,12 @@ var config = {
        cssStyle_description: { Type: 'String', Default: '', Value: '',},\r
        cssStyle_icon: { Type: 'String', Default: 'width:15px; height:15px', Value: 'width:15px; height:15px',},\r
        cssStyle_overdue: { Type: 'String', Default: 'color:#ffff00', Value: 'color:#ffff00',},\r
-       cssStyle_calendar1: { Type: 'String', Default: 'background-color:#800000', Value: 'background-color:#800000',},\r
-       cssStyle_calendar2: { Type: 'String', Default: 'background-color:#ff0000', Value: 'background-color:#ff0000',},\r
-       cssStyle_calendar3: { Type: 'String', Default: 'background-color:#808000', Value: 'background-color:#808000',},\r
-       cssStyle_calendar4: { Type: 'String', Default: 'background-color:#ffff00', Value: 'background-color:#ffff00',},\r
-       cssStyle_calendar5: { Type: 'String', Default: 'background-color:#008000', Value: 'background-color:#008000',},\r
-       cssStyle_calendar6: { Type: 'String', Default: 'background-color:#008080', Value: 'background-color:#008080',},\r
+       cssStyle_calendar1: { Type: 'String', Default: 'background-color:#0757cf', Value: 'background-color:#0757cf',},\r
+       cssStyle_calendar2: { Type: 'String', Default: 'background-color:#579f37', Value: 'background-color:#579f37',},\r
+       cssStyle_calendar3: { Type: 'String', Default: 'background-color:#ff9f07', Value: 'background-color:#ff9f07',},\r
+       cssStyle_calendar4: { Type: 'String', Default: 'background-color:#af8fef', Value: 'background-color:#af8fef',},\r
+       cssStyle_calendar5: { Type: 'String', Default: 'background-color:#57afbf', Value: 'background-color:#57afbf',},\r
+       cssStyle_calendar6: { Type: 'String', Default: 'background-color:#9fdf57', Value: 'background-color:#9fdf57',},\r
 }\r
 \r
 \r
@@ -75,7 +83,7 @@ var config = {
 // Nothing of interest from here on...\r
 //-------------------------------------------------------\r
 var panelNum = 0; // use 1 for second panel\r
-var version = "1.29";\r
+var version = "1.32";
 var versionURL = "http://comingnext.sourceforge.net/version.xml";\r
 var calendarService = null;\r
 var cacheEntriesHtml = [];\r
@@ -89,6 +97,13 @@ var settingsCache = null;
 var notificationRequests = new Array();\r
 var calendarList = [];\r
 var calendarColors = [];\r
+var updateTimer = null;\r
+var screenRotationTimer = null;\r
+var lastUpdateTime = now; // last time we updated the display
+var lastReloadTime = null; // last time we fetched calendar data
+var reloadInterval = 6 * 60 * 60 * 1000; // = 6 hours; time interval for reloading calendar data
+var errorOccured = false;\r
+var entryLists = null; // stores all fetched calendar entries until data is refreshed
 \r
 // vars for daylight saving time\r
 var summertime = false; // true, if current date is in summer, false if in winter\r
@@ -108,17 +123,13 @@ var entryFields = [
        "InstanceEndTime"\r
 ];\r
 \r
-window.onload = init;\r
-window.onresize = updateScreen;\r
-window.onshow = updateScreen;\r
-\r
 function isLeapYear( year ) {\r
        if (( year % 4 == 0 && year % 100 != 0 ) || year % 400 == 0 )\r
                return true;\r
        else\r
                return false;\r
 }\r
-         \r
+
 function calcLeapYear(year, days)\r
 {\r
        if (isLeapYear(year))\r
@@ -183,6 +194,9 @@ function error(message)
 {\r
        console.info('Error: ' + message);\r
        document.getElementById("calendarList").innerHTML = 'Error: ' + message;\r
+       document.getElementById("fullscreenCalendarList").innerHTML = 'Error: ' + message;\r
+       errorOccured = true;\r
+       document.onclick = null;\r
 }\r
 \r
 function areDatesEqual(date1, date2)\r
@@ -276,7 +290,7 @@ function collectLocales()
                                month = tmp;\r
                        }\r
 \r
-                       console.info(entry.StartTime + ' -> ' + month + ' ' + counter);\r
+                       log(entry.StartTime + ' -> ' + month + ' ' + counter);
                        ids[counter] = entry.id;\r
                        months_translated[month] = counter + 1;\r
                        counter++;\r
@@ -285,7 +299,7 @@ function collectLocales()
                error(e + ', line ' + e.line);\r
                return;\r
        }\r
-       console.info(ids);\r
+       log(ids);
        try {\r
                var criteria = new Object();\r
                criteria.Type = "CalendarEntry";\r
@@ -349,13 +363,14 @@ function cancelNotification()
 \r
 function callback(transId, eventCode, result)\r
 {\r
-       console.info("callback(): panelNum: %d  transId: %d  eventCode: %d result.ErrorCode: %d", panelNum, transId, eventCode, result.ErrorCode);\r
+       log("callback(): panelNum: " + panelNum + "  transId: " + transId + "  eventCode: " + eventCode + " result.ErrorCode: " + result.ErrorCode);
+       lastReloadTime = null; // force calendar data reload on next update
        updateData();\r
 }\r
 \r
 function settingsCallback(transId, eventCode, result)\r
 {\r
-       console.info("settingsCallback(): panelNum: %d  transId: %d  eventCode: %d result.ErrorCode: %d", panelNum, transId, eventCode, result.ErrorCode);\r
+       log("settingsCallback(): panelNum: " + panelNum + "  transId: " + transId + "  eventCode: " + eventCode + " result.ErrorCode: " + result.ErrorCode);
        loadSettings();\r
 }\r
 \r
@@ -423,11 +438,11 @@ function parseDate(dateString)
                // work around bug in Nokias calendar api resulting in dates within a different DST to be off by 1 hour\r
                if (summertime && !dateSummerTime) {\r
                        result = new Date(result.getTime() - 1000 * 60 * 60 * config['daylightSavingOffset'].Value); // -1 hour\r
-                       console.info('parseDate(): fixing time -1h: ' + result);\r
+                       log('parseDate(): fixing time -1h: ' + result);
                }\r
                else if (!summertime && dateSummerTime) {\r
                        result = new Date(result.getTime() + 1000 * 60 * 60 * config['daylightSavingOffset'].Value); // +1 hour\r
-                       console.info('parseDate(): fixing time +1h: ' + result);\r
+                       log('parseDate(): fixing time +1h: ' + result);
                }\r
        }\r
 \r
@@ -504,7 +519,10 @@ function formatTime(date)
 \r
 function updateData()\r
 {\r
-       console.info('updateData()');\r
+       log('updateData()');
+       if (errorOccured) {\r
+               return;\r
+       }\r
 \r
        // check if we got additional or less calendars since our last update\r
        var newCalendarList = listCalendars();\r
@@ -513,59 +531,72 @@ function updateData()
                updateCalendarColors();\r
                cancelNotification();\r
                requestNotification();\r
+               lastReloadTime = null; // force calendar data reload on this update
        }\r
-       \r
-       try {\r
-               // meetings have time\r
-               // 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\r
-               now = new Date();\r
-               summertime = isSummertime(now); // cache summer time info for today\r
-               var meetingList = [];\r
-               for(var i=0; i < calendarList.length; i++) {\r
-                       var meetingListFiltering = {\r
-                               Type:'CalendarEntry',\r
-                               Filter:{\r
-                                       CalendarName: calendarList[i],\r
-                                       StartRange: (new Date(now.getFullYear(), now.getMonth(), now.getDate(), 0, 0, 0)),\r
-                                       EndRange: (new Date(now.getFullYear(), now.getMonth() + config['monthRange'].Value, now.getDate(), 0, 0, 0))\r
-                               }\r
-                       }\r
-                       var meetingResult = calendarService.IDataSource.GetList(meetingListFiltering);\r
-                       if (meetingResult.ErrorCode != 0)\r
-                               throw("Error fetching calendar data: " + meetingResult.ErrorCode + ': ' + meetingResult.ErrorMessage);\r
-                       var list = meetingResult.ReturnValue;\r
-                       meetingList = meetingList.concat(listToArray(list));\r
-               }\r
-               console.info("updateData(): meetingList.sort()");\r
-               meetingList.sort(sortCalendarEntries);\r
 \r
-               // todos don't, they start on 00:00 hrs., but should be visible anyway\r
-               // this will generate a list of passed todos. We have to check if they have been marked as "done" yet\r
-               if (config['includeTodos'].Value) {\r
-                       var todayTodoList = [];\r
+       now = new Date();
+       
+       // only reload calendar data every 6 hours, visual updates occure more often
+       if (!lastReloadTime || now.getTime() - lastReloadTime.getTime() > reloadInterval) {
+               log('updateData(): reloading calendar data');
+               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
+                       summertime = isSummertime(now); // cache summer time info for today
+                       var meetingList = [];
                        for(var i=0; i < calendarList.length; i++) {\r
-                               var todayTodoListFiltering = {\r
+                               // ignore excluded calendars\r
+                               if (config['excludedCalendars'].Value.indexOf(calendarList[i]) != -1)\r
+                                       continue;\r
+                               var meetingListFiltering = {
                                        Type:'CalendarEntry',\r
                                        Filter:{\r
                                                CalendarName: calendarList[i],\r
-                                               Type: 'ToDo',\r
-                                               StartRange: (new Date(now.getFullYear() - 1, now.getMonth(), now.getDate(), 0, 0, 0)),\r
-                                               EndRange: (new Date(now.getFullYear(), now.getMonth(), now.getDate(), 0, 0, 1))\r
+                                               StartRange: (new Date(now.getFullYear(), now.getMonth(), now.getDate(), 0, 0, 0)),
+                                               EndRange: (new Date(now.getFullYear(), now.getMonth() + config['monthRange'].Value, now.getDate(), 0, 0, 0))
+                                       }
+                               }
+                               var meetingResult = calendarService.IDataSource.GetList(meetingListFiltering);
+                               if (meetingResult.ErrorCode != 0)
+                                       throw("Error fetching calendar data: " + meetingResult.ErrorCode + ': ' + meetingResult.ErrorMessage);
+                               var list = meetingResult.ReturnValue;
+                               meetingList = meetingList.concat(listToArray(list, calendarList[i]));
+                       }
+                       log("updateData(): meetingList.sort()");
+                       meetingList.sort(sortCalendarEntries);
+
+                       // todos don't, they start on 00:00 hrs., but should be visible anyway
+                       // this will generate a list of passed todos. We have to check if they have been marked as "done" yet
+                       if (config['includeTodos'].Value) {
+                               var todayTodoList = [];
+                               for(var i=0; i < calendarList.length; i++) {
+                                       // ignore excluded calendars
+                                       if (config['excludedCalendars'].Value.indexOf(calendarList[i]) != -1)
+                                               continue;
+                                       var todayTodoListFiltering = {
+                                               Type:'CalendarEntry',
+                                               Filter:{
+                                                       CalendarName: calendarList[i],
+                                                       Type: 'ToDo',
+                                                       StartRange: (new Date(now.getFullYear() - 1, now.getMonth(), now.getDate(), 0, 0, 0)),
+                                                       EndRange: (new Date(now.getFullYear(), now.getMonth(), now.getDate(), 0, 0, 1))
+                                               }
                                        }\r
+                                       var todayTodoResult = calendarService.IDataSource.GetList(todayTodoListFiltering);
+                                       var list = todayTodoResult.ReturnValue;
+                                       todayTodoList = todayTodoList.concat(listToArray(list, calendarList[i]));
                                }\r
-                               var todayTodoResult = calendarService.IDataSource.GetList(todayTodoListFiltering);\r
-                               var list = todayTodoResult.ReturnValue;\r
-                               todayTodoList = todayTodoList.concat(listToArray(list));\r
+                               log("updateData(): todayTodoList.sort()");
+                               todayTodoList.sort(sortCalendarEntries);
+                               entryLists = [todayTodoList, meetingList];
+                       } else {
+                               entryLists = [meetingList];
                        }\r
-                       console.info("updateData(): todayTodoList.sort()");\r
-                       todayTodoList.sort(sortCalendarEntries);\r
-                       var entryLists = [todayTodoList, meetingList];\r
-               } else {\r
-                       var entryLists = [meetingList];\r
+                       lastReloadTime = new Date();
+               } catch(e) {
+                       error('loading Calendar items list:' + e + ', line ' + e.line);
+                       return;
                }\r
-       } catch(e) {\r
-               error('loading Calendar items list:' + e + ', line ' + e.line);\r
-               return;\r
        }\r
 \r
        try {\r
@@ -598,16 +629,18 @@ function updateData()
                else\r
                        max = 30; // we can display a lot more events in fullscreen mode\r
 \r
-               var listinfo = "";\r
-               for (var i=0; i < entryLists.length; i++) {\r
-                       listinfo = listinfo + " " + entryLists[i].length;\r
-                       var entrieslist = "";\r
-                       for (var j=0; j < entryLists[i].length; j++) {\r
-                               entrieslist += entryLists[i][j].Summary + ", ";\r
+               if (config['enableLogging'].Value) {
+                       var listinfo = "";
+                       for (var i=0; i < entryLists.length; i++) {
+                               listinfo = listinfo + " " + entryLists[i].length;
+                               var entrieslist = "";
+                               for (var j=0; j < entryLists[i].length; j++) {
+                                       entrieslist += entryLists[i][j].Summary + ", ";
+                               }
+                               log("updateData(): entrieslist: " + entrieslist);
                        }\r
-                       console.info("updateData(): entrieslist: " + entrieslist);\r
+                       log("updateData(): inner loop, " + entryLists.length + " lists, [" + listinfo + "] entries");
                }\r
-               console.info("updateData(): inner loop, " + entryLists.length + " lists, [" + listinfo + "] entries");\r
                \r
                // the first outer loop iteration is for passed ToDos, the second loop is for all upcomming events (may also include ToDos)\r
                for (var i=0; counter < max && i < entryLists.length; i++) {\r
@@ -622,18 +655,18 @@ function updateData()
                                                entryInfo += entryFields[k] + "=" + entry[entryFields[k]] + ",";\r
                                        }\r
                                }\r
-                               console.info(entryInfo);\r
+                               log(entryInfo);
 \r
                                // we don't want ToDos when includeTodos == false or when they are completed\r
                                if (entry.Type == 'ToDo' && (entry.Status == "TodoCompleted" || !config['includeTodos'].Value)) {\r
-                                       console.info('skipping ' + entry.id );\r
+                                       log('skipping ' + entry.id );
                                        counter--;\r
                                        continue;\r
                                }\r
 \r
                                // make sure that we don't include an event twice (useful for ToDos that might come up twice)\r
                                if (eventIds[entry.id] == 1 && entry.Type == 'ToDo') {\r
-                                       console.info('skipped (already included) ' + entry.id);\r
+                                       log('skipped (already included) ' + entry.id);
                                        counter--;\r
                                        continue;\r
                                } else\r
@@ -656,15 +689,15 @@ function updateData()
 \r
                                // Convert date/time string to Date object\r
                                var date = parseDate(entryDate);\r
-                               console.info('date: ' + date);\r
+                               log('date: ' + date);
                                var endDate = ((entryEndTime == null) ? null : parseDate(entryEndTime));\r
-                               console.info('endDate: ' + endDate);\r
+                               log('endDate: ' + endDate);
 \r
                                // check if meeting event has already passed\r
                                if (entry.Type == 'Meeting') {\r
                                        var compareTime = ((endDate == null) ? date.getTime() : endDate.getTime());\r
                                        if (now.getTime() > compareTime) {\r
-                                               console.info('skipping Meeting (already passed) ' + entry.id);\r
+                                               log('skipping Meeting (already passed) ' + entry.id);
                                                counter--;\r
                                                eventIds[entry.id] = 0;\r
                                                continue;\r
@@ -675,7 +708,7 @@ function updateData()
                                if (entry.Type == 'Anniversary') {\r
                                        var tmp = new Date(now.getFullYear(), now.getMonth(), now.getDate(), 0,0,0);\r
                                        if (date.getTime() < tmp.getTime()) {\r
-                                               console.info('skipping Anniversary (already passed) ' + entry.id);\r
+                                               log('skipping Anniversary (already passed) ' + entry.id);
                                                counter--;\r
                                                eventIds[entry.id] = 0;\r
                                                continue;\r
@@ -685,9 +718,9 @@ function updateData()
                                // fix DayEvents end time. End times are off by 1 Second. It's possible that the event has already passed\r
                                if (entry.Type == 'DayEvent' && endDate != null) {\r
                                        endDate.setMinutes(endDate.getMinutes() - 1);\r
-                                       console.info('fixing DayEvent endDate: ' + endDate);\r
+                                       log('fixing DayEvent endDate: ' + endDate);
                                        if (now.getTime() > endDate.getTime()) {\r
-                                               console.info('event already passed ' + entry.id);\r
+                                               log('event already passed ' + entry.id);
                                                counter--;\r
                                                eventIds[entry.id] = 0;\r
                                                continue;\r
@@ -699,13 +732,13 @@ function updateData()
                                        // check if we are between start and endtime\r
                                        if ((date.getTime() < now.getTime()) && (now.getTime() < endDate.getTime())) {\r
                                                date = now; // change appointment date/time to now\r
-                                               console.info('event is currently taking place: ' + date);\r
+                                               log('event is currently taking place: ' + date);
                                        }\r
                                }\r
 \r
                                // skip events for the first panel in case this is the second one and we're not in fullscreen mode\r
                                if (mode == 0 && panelNum > 0 && counter < panelNum * config['eventsPerWidget'].Value + 1) {\r
-                                       console.info('skipping (already in first widget) ' + entry.id);\r
+                                       log('skipping (already in first widget) ' + entry.id);
                                        continue;\r
                                }\r
                                \r
@@ -721,8 +754,8 @@ function updateData()
 \r
                                // generate html output\r
                                entriesHtml += '<tr>';\r
-                               if (config['showCalendarIndicator'].Value && calendarList.length > 1) {\r
-                                       entriesHtml += '<td class="calendar' + calendarColors[entry.CalendarName] + '">&nbsp;</td>';\r
+                               if (config['showCalendarIndicator'].Value && calendarList.length - config['excludedCalendars'].Value.length > 1) {\r
+                                       entriesHtml += '<td><span class="calendar' + calendarColors[entry.CalendarName] + '">&nbsp;</span></td>';\r
                                }\r
                                entriesHtml += '<td><img class="icon" src="' + entry.Type + '.png" /></td>';\r
                                if(date == null) {\r
@@ -771,14 +804,19 @@ function updateData()
                                document.getElementById('fullscreenCalendarList').innerHTML = entriesHtml;\r
                        cacheEntriesHtml = entriesHtml;\r
                }\r
+               \r
+               lastUpdateTime = new Date();\r
        } catch(e) {\r
                error('displaying list:' + e + ', line ' + e.line);\r
                return;\r
        }\r
 }\r
 \r
+// called by handleOnShow() and onResize events
 function updateScreen()\r
 {\r
+       log('updateScreen()');
+
        // check if opening fullscreen\r
        if( window.innerHeight > 91 && mode == 0) {\r
                mode = 1;\r
@@ -793,9 +831,22 @@ function updateScreen()
        }\r
        \r
        if (mode == 0)\r
-               updateHomescreen();\r
+               updateHomescreen(); // check for screen rotation
        else if (mode == 1)\r
                updateFullscreen();\r
+}
+
+function handleOnShow()
+{
+       updateScreen();
+
+       var time = new Date();\r
+       if (time.getTime() - lastUpdateTime.getTime() > config['updateDataInterval'].Value * 60 * 1000) {\r
+               log('updateScreen(): force updateData() because last update was too long ago (' + (time.getTime() - lastUpdateTime.getTime()) / 1000 + 's)');
+               clearUpdateTimer();\r
+               updateData();\r
+               setUpdateTimer(); // reinitialize update timer\r
+       }\r
 }\r
 \r
 function launchCalendar()\r
@@ -812,7 +863,7 @@ function launchCalendar()
 \r
 function init()\r
 {\r
-       console.info('New widget instance starting up...');\r
+       log('New widget instance starting up...');
        \r
        try {\r
                // call calendar service\r
@@ -821,8 +872,8 @@ function init()
                else\r
                        throw('device object does not exist');\r
        } catch(e) {\r
-               error('loading Calendar service: ' + e + ', line ' + e.line);\r
-               return;\r
+               error('loading Calendar service: ' + e + ', line ' + e.line + '<br /><a onclick="widget.openURL(\'http://comingnext.sf.net/help\'); return false;" href="http://comingnext.sf.net/help">' + getLocalizedText('menu.help') + '</a>');\r
+               //return;\r
        }\r
 \r
        calendarList = listCalendars();\r
@@ -831,21 +882,47 @@ function init()
        collectLocales();\r
        //updateData();\r
        requestNotification();\r
-       window.setInterval('updateData()', 1000 * 60 * config['updateDataInterval'].Value);\r
        document.getElementById("settingsTitle").innerHTML = getLocalizedText('menu.settings');\r
-\r
+       setUpdateTimer();\r
        if (window.innerHeight > 91) {\r
                mode = 0; // we're starting fullscreen, we set mode to homescreen in order to let updateScreen() do all the work for us\r
        }\r
        else {\r
                mode = 1;\r
        }\r
-       console.info("init(): updateScreen()");\r
+       log("init(): updateScreen()");
        updateScreen();\r
        if (config['useBackgroundImage'].Value)\r
                // check for screen rotation every 1 secs\r
-               window.setInterval('updateScreen()', 1000 * 1);\r
-       console.info("init(): finished...");\r
+               screenRotationTimer = window.setInterval('checkOrientation()', 1000 * 1);
+       
+       // call updateScreen() when widget changes from background to forground
+       window.widget.onshow = handleOnShow;
+
+       log("init(): finished...");
+}\r
+\r
+function checkOrientation()
+{
+       //updateScreen();
+       if (mode == 0)
+               updateHomescreen(); // check for screen rotation
+}
+
+function setUpdateTimer()\r
+{\r
+       updateTimer = window.setInterval('updateTimerCallback()', 1000 * 60 * config['updateDataInterval'].Value);\r
+}\r
+\r
+function clearUpdateTimer() \r
+{\r
+       window.clearInterval(updateTimer);\r
+}\r
+\r
+function updateTimerCallback()\r
+{\r
+       log("updateTimerCallback()");
+       updateData();\r
 }\r
 \r
 function createMenu()\r
@@ -855,15 +932,18 @@ function createMenu()
        var id = 0;\r
        var menuSettings = new MenuItem(getLocalizedText('menu.settings'), id++);\r
        var menuCallApp = new MenuItem(getLocalizedText('menu.openCalendarApp'), id++);\r
+       var menuHelp = new MenuItem(getLocalizedText('menu.help'), id++);\r
        var menuUpdate = new MenuItem(getLocalizedText('menu.update'), id++);\r
        var menuAbout = new MenuItem(getLocalizedText('menu.about'), id++);\r
        menuSettings.onSelect = showSettings;\r
        menuAbout.onSelect = showAbout;\r
        menuCallApp.onSelect = launchCalendar;\r
        menuUpdate.onSelect = showUpdate;\r
+       menuHelp.onSelect = showHelp;\r
        window.menu.clear();\r
        window.menu.append(menuCallApp);\r
        window.menu.append(menuSettings);\r
+       window.menu.append(menuHelp);\r
        window.menu.append(menuUpdate);\r
        window.menu.append(menuAbout);  \r
 }\r
@@ -882,18 +962,31 @@ function showSettings()
                                config[key].Value = document.forms[0].elements["settings." + key].value;\r
                        else if (config[key].Type == 'Int') {\r
                                config[key].Value = parseInt(document.forms[0].elements["settings." + key].value);\r
-                               if (config[key].Value < 0)\r
+                               if (config[key].Value < 0 || isNaN(config[key].Value))
                                        config[key].Value = config[key].Default;\r
                        }\r
                        else if (config[key].Type == 'Bool')\r
                                config[key].Value = document.forms[0].elements["settings." + key].checked;\r
-                       else if (config[key].Type == 'UID')\r
+                       else if (config[key].Type == 'UID') {
                                config[key].Value = parseInt(document.forms[0].elements["settings." + key].value);\r
+                               if (isNaN(config[key].Value))
+                                       config[key].Value = config[key].Default;
+                       }
                        else if (config[key].Type == 'Enum') {\r
                                config[key].Value = document.forms[0].elements["settings." + key].value;\r
                                if (config[key].ValidValues.indexOf(config[key].Value) == -1)\r
                                        config[key].Value = config[key].Default;\r
                        }\r
+                       else if (config[key].Type == 'Array') {\r
+                               if (key == 'excludedCalendars') {\r
+                                       config[key].Value = new Array();\r
+                                       for(var i=0; i < calendarList.length; i++) {\r
+                                               var element = document.forms[0].elements["settings." + key + "." + calendarList[i]];\r
+                                               if (element != null && element.checked == false)\r
+                                                       config[key].Value.push(calendarList[i]);\r
+                                       }\r
+                               }\r
+                       }\r
                }\r
                                \r
                updateCssClasses();\r
@@ -929,6 +1022,18 @@ function showSettings()
                                settingsHtml += '<option value="' + config[key].ValidValues[i] + '"' + (config[key].Value == config[key].ValidValues[i] ? ' selected="selected"' : '') + '>' + getLocalizedText('settings.validValues.' + key + '.' + config[key].ValidValues[i]) + '</option>';\r
                        settingsHtml += '</select></div></td>' + printHintBox(getLocalizedText('settings.info.' + key)) + '<hr />';\r
                }\r
+               else if (config[key].Type == 'Array') {\r
+                       settingsHtml += '<table><tr><td>' + getLocalizedText('settings.name.' + key) + '<br />';\r
+                       if (key == 'excludedCalendars') {\r
+                               for(var i=0; i < calendarList.length; i++) {\r
+                                       var checked = 'checked="checked"';\r
+                                       if (config[key].Value.indexOf(calendarList[i]) != -1)\r
+                                               checked = '';\r
+                                       settingsHtml += '<input name="settings.' + key + '.' + calendarList[i] + '" type="checkbox" value="' + calendarList[i] + '" ' + checked + '/> ' + calendarList[i] + '<br />';\r
+                               }\r
+                       }\r
+                       settingsHtml += '</td>' + printHintBox(getLocalizedText('settings.info.' + key)) + '<hr />';\r
+               }\r
        }\r
        settingsHtml += '<input name="reset" type="button" value="' + getLocalizedText('settings.restoreDefaults') + '" onclick="javascript:restoreDefaultSettings();showSettings();" />';\r
        settingsHtml += '</form>';\r
@@ -976,7 +1081,7 @@ function getSettingsCalEntryId()
                var entry = list.getNext();\r
                if (entry != undefined) {\r
                        settingsCalEntryId = entry.LocalId;\r
-                       console.info("settingsCalEntryId=" + settingsCalEntryId);\r
+                       log("settingsCalEntryId=" + settingsCalEntryId);
                }\r
                else { // create settings item\r
                        var item = new Object();\r
@@ -1023,7 +1128,7 @@ function loadSettings()
        }\r
        var entry = result.ReturnValue.getNext();\r
        if (entry != undefined) {\r
-               console.info("Loading Settings...");\r
+               log("Loading Settings...");
                // only reload settings if they chanced since the last reload\r
                if (settingsCache != entry.Summary)\r
                {\r
@@ -1034,23 +1139,35 @@ function loadSettings()
                                var pair = stringlist[i].split('=');\r
                                var key = pair[0];\r
                                var value = pair[1];\r
-                               console.info('stringlist: ' + key + '=\'' + value + '\'');\r
-                               if (config[key].Type == 'Int')\r
+                               log('stringlist: ' + key + '=\'' + value + '\'');\r
+                               if (config[key].Type == 'Int') {
                                        config[key].Value = Number(value);\r
+                                       if (isNaN(config[key].Value))
+                                               config[key].Value = config[key].Default;
+                               }
                                else if (config[key].Type == 'String')\r
                                        config[key].Value = value;\r
                                else if (config[key].Type == 'Bool')\r
                                        config[key].Value = (value == 'true')\r
                                else if (config[key].Type == 'Enum')\r
                                        config[key].Value = value;\r
-                               else if (config[key].Type == 'UID')\r
+                               else if (config[key].Type == 'UID') {
                                        config[key].Value = Number(value);\r
+                                       if (isNaN(config[key].Value))
+                                               config[key].Value = config[key].Default;
+                               }
+                               else if (config[key].Type == 'Array') {\r
+                                       config[key].Value = value.split("^");\r
+                                       if (config[key].Value.length == 1 && config[key].Value[0] == "") {\r
+                                               config[key].Value = [];\r
+                                       }\r
+                               }\r
                        }\r
                        settingsCache = entry.Summary;\r
                        updateCssClasses();\r
                }\r
                else {\r
-                       console.info("Settings already cached and did not change");\r
+                       log("Settings already cached and did not change");
                }\r
        }\r
        else {\r
@@ -1078,6 +1195,8 @@ function saveSettings()
                        item.Summary += key + "=" + config[key].Value + "|";\r
                else if (config[key].Type == 'UID')\r
                        item.Summary += key + "=" + config[key].Value.toString() + "|";\r
+               else if (config[key].Type == 'Array')\r
+                       item.Summary += key + "=" + config[key].Value.join("^") + "|";\r
        }\r
        settingsCache = item.Summary;\r
        \r
@@ -1085,7 +1204,7 @@ function saveSettings()
        criteria.Type = "CalendarEntry";\r
        criteria.Item = item;\r
 \r
-       console.info("Saving settings to calendar entry: " + item.Summary);\r
+       log("Saving settings to calendar entry: " + item.Summary);
        try {\r
                var result = calendarService.IDataSource.Add(criteria);\r
                if (result.ErrorCode)\r
@@ -1093,6 +1212,10 @@ function saveSettings()
        } catch (e) {\r
                error("saveSettings: " + e + ', line ' + e.line);\r
        }\r
+       \r
+       lastReloadTime = null; // force calendar data reload on next update
+       clearUpdateTimer();\r
+       setUpdateTimer();\r
 }\r
 \r
 function toggleVisibility(elementId)\r
@@ -1129,23 +1252,30 @@ function showAbout()
        document.getElementById("name").innerHTML = "Coming Next " + version;\r
 }\r
 \r
+function showHelp() {\r
+       widget.openURL('http://comingnext.sf.net/help');\r
+}\r
+\r
 function updateFullscreen()\r
 {\r
 }\r
 \r
 function showFullscreen()\r
 {\r
-       console.info("showFullscreen()");\r
+       log("showFullscreen()");
        hideViews();\r
        document.getElementById("fullscreenView").style.display = "block";\r
        document.getElementById('body').className = "backgroundFullscreen";\r
-       document.onclick = launchCalendar;\r
+       if (!errorOccured)\r
+               document.onclick = launchCalendar;\r
        createMenu();\r
        updateData();\r
 }\r
 \r
 function getBackgroundImage()\r
 {\r
+       if (errorOccured)\r
+               return '';\r
        var bgImage;\r
        if (config['backgroundImageLocation'].Value == config['backgroundImageLocation'].ValidValues[0]) // internal\r
                bgImage = 'background_' + orientation + '.png';\r
@@ -1180,7 +1310,7 @@ function updateHomescreen()
 \r
 function showHomescreen()\r
 {\r
-       console.info("showHomescreen()");\r
+       log("showHomescreen()");
        hideViews();\r
        document.getElementById("homescreenView").style.display = "block";\r
        document.getElementById('body').className = "background";\r
@@ -1263,6 +1393,10 @@ function hideViews()
 \r
 function listCalendars()\r
 {\r
+       if (errorOccured) {\r
+               return null;\r
+       }\r
+\r
        try {\r
                var criteria = {\r
                        Type:'Calendar', \r
@@ -1282,7 +1416,7 @@ function listCalendars()
                while (( item = calendarListIterator.getNext()) != undefined ) {\r
                        calendars[count++] = item;\r
                }\r
-               console.info("Available Calendars: " + calendars.join(", "));\r
+               log("Available Calendars: " + calendars.join(", "));
                return calendars;\r
        } catch(e) {\r
                error('listing calendars:' + e + ', line ' + e.line);\r
@@ -1291,7 +1425,8 @@ function listCalendars()
 }\r
 \r
 // Copies all objects and their properties to an array. Data is copied so nothing gets lost when the reference is removed\r
-function listToArray(list)\r
+// Note: this will also set the "CalendarName" property of every entry to the name specified by the calendarName parameter if it has not been defined already\r
+function listToArray(list, calendarName)\r
 {\r
        var array = new Array();\r
        var item;\r
@@ -1301,17 +1436,21 @@ function listToArray(list)
                for(var i=0; i < entryFields.length; i++) {\r
                        itemCopy[entryFields[i]] = item[entryFields[i]];\r
                }\r
+               // for some reason, the CalendarName property is never correctly queried, so we assign it manually here\r
+               if (!itemCopy['CalendarName']) {\r
+                       itemCopy['CalendarName'] = calendarName;\r
+               }\r
                array.push(itemCopy);\r
                txt += array[array.length - 1].Summary + ", ";\r
        }\r
-       console.info("listToArray(): " + txt);\r
+       log("listToArray(): " + txt);
        return array;\r
 }\r
 \r
 function sortCalendarEntries(a, b)\r
 {\r
        var atime, btime;\r
-       console.info("sortCalendarEntries(" + a.Summary + "," + b.Summary + ")");\r
+       log("sortCalendarEntries(" + a.Summary + "," + b.Summary + ")");
        \r
        if (a.InstanceStartTime != null) {\r
                atime = a.InstanceStartTime;\r
@@ -1370,24 +1509,59 @@ function sortCalendarEntries(a, b)
                        }\r
                }\r
        }\r
+       // NOTE: events my have no date information at all. In that case, we list events without date first\r
+       else if (atime && !btime) {\r
+               return 1;\r
+       }\r
+       else if (!atime && btime) {\r
+               return -1;\r
+       }\r
+       else if (!atime && !btime) {\r
+               // sort by type\r
+               if (a.Type != b.Type) {\r
+                       if (a.Type < b.Type) {\r
+                               return -1;\r
+                       }\r
+                       else if (a.Type > b.Type) {\r
+                               return 1;\r
+                       }\r
+               }\r
+               // sort by description\r
+               else if (a.Summary && b.Summary && a.Summary != b.Summary) {\r
+                       if (a.Summary < b.Summary) {\r
+                               return -1;\r
+                       }\r
+                       else if (a.Summary > b.Summary) {\r
+                               return 1;\r
+                       }\r
+               }\r
+       }\r
 \r
        return 0;\r
 }\r
 \r
 function updateCalendarColors()\r
 {\r
+       var maxColors = 6;\r
        calendarColors = [];\r
-       if (calendarList.length > 6) {\r
-               console.info("updateCalendarColors(): Warning: more calendars than available indicator colors");\r
+       if (calendarList.length > maxColors) {\r
+               log("updateCalendarColors(): Warning: more calendars than available indicator colors");
        }\r
        for(var i=0; i < calendarList.length; i++) {\r
-               calendarColors[calendarList[i]] = (i % 6) + 1;\r
+               calendarColors[calendarList[i]] = (i % maxColors) + 1;\r
        }\r
 }\r
 \r
+function log(message) {
+       if (config['enableLogging'].Value) {
+               console.info(message);
+       }
+}
+
 </script>\r
 \r
 <style type="text/css">\r
+a { color:#aaccff }\r
 table { margin:0px; padding:0px; border-spacing:0px; }\r
 td { padding:0px 5px 0px 0px; white-space:nowrap; overflow:hidden; }\r
 hr { color:#ffffff; background-color:#ffffff; height:1px; text-align:left; border-style:none; }\r
@@ -1396,7 +1570,7 @@ hr { color:#ffffff; background-color:#ffffff; height:1px; text-align:left; borde
 .textInput { width:90%; }\r
 .credits { margin-left:40px; text-indent: -20px; margin-bottom:0px; }\r
 #homescreenView { width: 315px; height:91px; overflow:hidden; }\r
-#calendarList { position:absolute; left:10px; top:4px; width:295px; height:75px; overflow:hidden; }\r
+#calendarList { position:absolute; left:5px; top:4px; width:295px; height:75px; overflow:hidden; }\r
 #name { text-align:center; }\r
 #appicon { display: block; margin-left: auto; margin-right: auto; margin-top: 10px; }\r
 #smallappicon { width:22px; height:22px; margin-right:10px; float:left; }\r
@@ -1404,9 +1578,9 @@ hr { color:#ffffff; background-color:#ffffff; height:1px; text-align:left; borde
 \r
 </head>\r
 \r
-<body id="body" class="background">\r
+<body onload="javascript:setTimeout('init()', 10)" onresize="javascript:updateScreen()" id="body" class="background">
 <div id="homescreenView">\r
-       <div id="calendarList"></div>\r
+       <div id="calendarList">loading...</div>\r
 </div>\r
 <div id="fullscreenView" style="display:none;">\r
        <img src="Icon.png" id="smallappicon">\r
@@ -1431,8 +1605,10 @@ hr { color:#ffffff; background-color:#ffffff; height:1px; text-align:left; borde
                <p class="credits">Christophe Milsent (translation support & french translation)</p>\r
                <p class="credits">Flavio Nathan (portuguese-brazilian translation)</p>\r
                <p class="credits">Tokeda (russian translation)</p>\r
+               <p class="credits">Marcella Ferrari (italian translation)</p>\r
+               <p class="credits">Venos (italian translation)</p>\r
        <p>This software is open source and licensed under the GPLv3.</p>\r
-       <p>Visit <a href="http://sourceforge.net/projects/comingnext">sourceforge.net/projects/comingnext</a> for free updates.</p>\r
+       <p>Visit <a onclick="widget.openURL('http://comingnext.sf.net/'); return false;" href="http://comingnext.sf.net/">comingnext.sf.net</a> for free updates.</p>\r
        <hr />\r
 </div>\r
 <div id="updateView" style="display:none">\r