X-Git-Url: https://code.delx.au/comingnext/blobdiff_plain/4cf257bd306ac4dc3220530c33874720488c8436..7462eb0578c84056fb0934aa0cbd1acb4873a993:/comingNext/index.html diff --git a/comingNext/index.html b/comingNext/index.html index e02a484..f30cb7d 100644 --- a/comingNext/index.html +++ b/comingNext/index.html @@ -83,11 +83,12 @@ var config = { // Nothing of interest from here on... //------------------------------------------------------- var panelNum = 0; // use 1 for second panel -var version = "1.33"; +var version = "1.37"; var versionURL = "http://comingnext.sourceforge.net/version.xml"; var calendarService = null; var cacheEntriesHtml = []; var months_translated = []; +var weekdays_translated = []; var orientation = ''; var now = new Date(); var mode = 0; // 0 = homescreen, 1 = fullscreen, 2 = settings, 3 = about, 4 = check for update @@ -104,6 +105,9 @@ 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; var entryLists = null; // stores all fetched calendar entries until data is refreshed +var statupSuccessful = false; // indicates if everything started up wihtout errors. If we detect an error after that, it might just be a temporary problem e.g. by a backup process. +var use12hoursTimeFormat = false; // defines how time should be formated: 19:00 or 07:00 pm +var timeFormatSeparator = ":"; // format time 19:00 or 19.00 depending on system setting // vars for daylight saving time var summertime = false; // true, if current date is in summer, false if in winter @@ -240,7 +244,27 @@ function collectLocales() try { var result = calendarService.IDataSource.Add(criteria); if (result.ErrorCode) - error(result.ErrorMessage); + throw(result.ErrorMessage); + } catch (e) { + error("collectLocales: " + e + ', line ' + e.line); + } + } + for (weekday = 0; weekday < 7; weekday++) { + var startDate = new Date(2000, 0, 2 + weekday); // date that we know for sure is a sunday + + var item = new Object(); + item.Type = "DayEvent"; + item.StartTime = startDate; + item.Summary = "__weekday_temp" + weekday; + + var criteria = new Object(); + criteria.Type = "CalendarEntry"; + criteria.Item = item; + + try { + var result = calendarService.IDataSource.Add(criteria); + if (result.ErrorCode) + throw(result.ErrorMessage); } catch (e) { error("collectLocales: " + e + ', line ' + e.line); } @@ -262,7 +286,7 @@ function collectLocales() throw(result.ErrorMessage); var list = result.ReturnValue; } catch(e) { - error(e + ', line ' + e.line); + error("collectLocales: " + e + ', line ' + e.line); return; } var ids = new Array(); @@ -294,7 +318,44 @@ function collectLocales() counter++; } } catch(e) { - error(e + ', line ' + e.line); + error("collectLocales: " + e + ', line ' + e.line); + return; + } + try { + var startTime = new Date(2000,0,2); + var endTime = new Date(2000,0,9); + var listFiltering = { + Type:'CalendarEntry', + Filter:{ + StartRange: startTime, + EndRange: endTime, + SearchText: '__weekday_temp', + Type: 'DayEvent' + } + } + var result = calendarService.IDataSource.GetList(listFiltering); + if (result.ErrorCode) + throw(result.ErrorMessage); + var weekdaylist = result.ReturnValue; + } catch(e) { + error("collectLocales: " + e + ', line ' + e.line); + return; + } + try { + var entry; + var counter2 = 0; + var curWeekday = ""; + + while (weekdaylist && (entry = weekdaylist.getNext()) != undefined) { + detectTimeFormat(entry.StartTime + ''); + curWeekday = (entry.StartTime + '').split(',')[0]; + log(entry.StartTime + ' -> ' + curWeekday + ' ' + counter2); + ids[counter + counter2] = entry.id; + weekdays_translated[counter2] = curWeekday; + counter2++; + } + } catch(e) { + error("collectLocales: " + e + ', line ' + e.line); return; } log(ids); @@ -314,6 +375,19 @@ function collectLocales() } } +function stringEndsWith(str, suffix) +{ + return str.indexOf(suffix, str.length - suffix.length) !== -1; +} + +// detects the system's current time format by parsing a native calendar timestamp (this is the only reliable formating across all devices and firmwares) +function detectTimeFormat(localeTimeString) +{ + localeTimeString = localeTimeString.toLowerCase(); + use12hoursTimeFormat = stringEndsWith(localeTimeString, "am") || stringEndsWith(localeTimeString, "pm"); + timeFormatSeparator = localeTimeString.indexOf(":") != -1 ? ":" : "."; +} + function requestNotification() { var criteria = new Object(); @@ -456,6 +530,14 @@ function parseDate(dateString) return result; } +function getWeekdayLocalized(date) { + var localizedString = date.toLocaleDateString(); + if (localizedString.indexOf(",") == -1) { + return weekdays_translated[date.getDay()]; + } else + return localizedString.split(',')[0]; +} + // returns a short date as string ("31.12" or "12.31") based on the format string which should look like "Wednesday, 26 August, 2009 12:00:00 am" function formatDate(date, format) { @@ -522,12 +604,35 @@ function formatDate(date, format) function formatTime(date) { // date is a Date() object - date.setSeconds(0); // we don't care about seconds - var time = date.toLocaleTimeString().replace(/[\.:]00/, ''); // remove seconds from string - if (time.replace(/\./, ':').split(':')[0].length < 2) - time = '0' + time; + var hour = date.getHours(); + var minute = date.getMinutes(); + + // don't use Date().toLocaleTimeString() as it is utterly broken on newer firmwares + if (use12hoursTimeFormat) { + var ap = "AM"; + if (hour > 11) + ap = "PM"; + if (hour > 12) + hour = hour - 12; + if (hour == 0) + hour = 12; + if (hour < 10) + hour = "0" + hour; + if (minute < 10) + minute = "0" + minute; + time = hour + timeFormatSeparator + minute + " " + ap; + } + else { + if (hour < 10) + hour = "0" + hour; + if (minute < 10) + minute = "0" + minute; + time = hour + timeFormatSeparator + minute; + } + if (config['showNowAsText'].Value && date.getTime() == now.getTime()) time = '' + config['nowText'].Value + ''; + log("formatTime(): " + time + ", use12hoursTimeFormat=" + use12hoursTimeFormat + ", timeFormatSeparator=" + timeFormatSeparator + ", date.toLocateTimeString(): " + date.toLocaleTimeString()); return time; } @@ -540,6 +645,16 @@ function updateData() // check if we got additional or less calendars since our last update var newCalendarList = listCalendars(); + if (newCalendarList == null) { + // Something went wrong fetching the calendars list. + // This usually happens when a backup is being made. + // Retry the next time updateData() is called by + // resetting errorOccured + log('updateData(): listCalendars() failed, trying again later...'); + cacheEntriesHtml = ''; // make sure we replace the currently shown error message on the next update + errorOccured = false; + return; + } if (newCalendarList.length != calendarList.length) { calendarList = newCalendarList; updateCalendarColors(); @@ -619,23 +734,26 @@ function updateData() var entryDate = ''; var dateArr = []; var fontsize = 'normal'; + var lineheight = 'normal'; if (mode == 0) { + fontsize = parseInt(72 / config['eventsPerWidget'].Value) + 'px'; + lineheight = parseInt(82 / config['eventsPerWidget'].Value) + 'px'; + if (config['eventsPerWidget'].Value == 3) { - fontsize = '17pt'; changeCssClass('.icon', 'width:20px; height:20px'); } else if (config['eventsPerWidget'].Value == 5) { - fontsize = '10pt'; changeCssClass('.icon', 'width:10px; height:10px'); } else if (config['eventsPerWidget'].Value == 6) { - fontsize = '8pt'; changeCssClass('.icon', 'width:8px; height:8px'); } } else changeCssClass('.icon', config['cssStyle_icon'].Value); - var entriesHtml = ''; + var entriesHtml = '
'; + if (mode == 0) + entriesHtml = '
' + entriesHtml; // this is needed to center the actual content vertically var eventIds = []; var max; if (mode == 0) @@ -706,6 +824,14 @@ function updateData() log('date: ' + date); var endDate = ((entryEndTime == null) ? null : parseDate(entryEndTime)); log('endDate: ' + endDate); + + // check if Meeting is actually a DayEvent. Bug introduced by "Anna" updates to various Symbian^3 devices. + // Note that this workaround is not 100% save! It might missinterpret some meetings as dayevents of starting and ending on 00:00 + if (entry.Type == 'Meeting' && date.getHours() == 0 && date.getMinutes() == 0 && + endDate != null && endDate.getHours() == 0 && endDate.getMinutes() == 0) { + log('fixing event type: changed from "Meeting" to "DayEvent".'); + entry.Type = 'DayEvent'; + } // check if meeting event has already passed if (entry.Type == 'Meeting') { @@ -776,7 +902,9 @@ function updateData() // some languages have very strange locale date formats, can't parse all those. Also some todos don't have dates at all. entriesHtml += '' + entryDate + ' '; } else { - var weekDay = date.toLocaleDateString().substr(0,config['weekDayLength'].Value); + var weekDay = getWeekdayLocalized(date).substr(0,config['weekDayLength'].Value); + log('date.toLocaleDateString(): ' + date.toLocaleDateString()); + log('weekDay: ' + weekDay); var time = formatTime(date); var dateStr = formatDate(date, entryDate); if (entry.Type == 'ToDo' && overdue && config['markOverdueTodos'].Value) { @@ -807,10 +935,13 @@ function updateData() } } entriesHtml += '
'; + if (mode == 0) + entriesHtml = entriesHtml + ''; if (config['showNothingText'].Value && entriesHtml == '
') { var text = config['nothingText'].Value.replace(/%d/, config['monthRange'].Value); entriesHtml = '
' + text + '
'; } + log("output: " + entriesHtml); if (cacheEntriesHtml != entriesHtml) { if (mode == 0) document.getElementById('calendarList').innerHTML = entriesHtml; @@ -829,16 +960,21 @@ function updateData() // called by handleOnShow() and onResize events function updateScreen() { - log('updateScreen()'); + log('updateScreen(): mode=' + mode + ', window.innerHeight=' + window.innerHeight); // check if opening fullscreen - if( window.innerHeight > 91 && mode == 0) { + + // Note: according to Nokia's documentation, an innerHeight of >91 is an indicator for fullscreen view. + // However a bug in E6's firmware causes different window widths and heights (disabled compatibility scaling). + // So far, values of 104 and 115 for window.innerHeight were reported, we use a safty margin here and check + // for 150 instead. + if( window.innerHeight > 150 && mode == 0) { mode = 1; cacheEntriesHtml = ''; document.getElementById('body').style.backgroundImage = ""; showFullscreen(); } - else if (window.innerHeight <= 91 && mode != 0) { + else if (window.innerHeight <= 150 && mode != 0) { mode = 0; cacheEntriesHtml = ''; showHomescreen(); @@ -914,6 +1050,8 @@ function init() window.widget.onshow = handleOnShow; log("init(): finished..."); + if (!errorOccured) + statupSuccessful = true; } function checkOrientation() @@ -1086,9 +1224,14 @@ function getSettingsCalEntryId() Type: 'DayEvent' } } - var result = calendarService.IDataSource.GetList(listFiltering); - if (result.ErrorCode) { - error(result.ErrorMessage); + var result = null; + try { + result = calendarService.IDataSource.GetList(listFiltering); + if (result.ErrorCode) + throw(result.ErrorMessage); + } + catch (e) { + error("getSettingsCalEntryId: GetList() failed: " + e + ', line ' + e.line); return; } var list = result.ReturnValue; @@ -1110,7 +1253,7 @@ function getSettingsCalEntryId() try { var result = calendarService.IDataSource.Add(criteria); if (result.ErrorCode) - error(result.ErrorMessage); + throw(result.ErrorMessage); } catch (e) { error("getSettingsCalEntryId: " + e + ', line ' + e.line); } @@ -1135,9 +1278,14 @@ function loadSettings() LocalId: settingsCalEntryId } } - var result = calendarService.IDataSource.GetList(listFiltering); - if (result.ErrorCode) { - error(result.ErrorMessage); + var result = null; + try { + result = calendarService.IDataSource.GetList(listFiltering); + if (result.ErrorCode) + throw(result.ErrorMessage); + } + catch (e) { + error("loadSettings: GetList() failed: " + e + ', line ' + e.line); return; } var entry = result.ReturnValue.getNext(); @@ -1157,7 +1305,7 @@ function loadSettings() log('Warning: unknown or invalid setting: ' + stringlist[i]); continue; } - log('stringlist: ' + key + '=\'' + value + '\''); + log('stringlist[' + i + ']: ' + key + '=\'' + value + '\''); if (config[key].Type == 'Int') { config[key].Value = Number(value); if (isNaN(config[key].Value)) @@ -1226,7 +1374,7 @@ function saveSettings() try { var result = calendarService.IDataSource.Add(criteria); if (result.ErrorCode) - error(result.ErrorMessage); + throw(result.ErrorMessage); } catch (e) { error("saveSettings: " + e + ', line ' + e.line); } @@ -1249,7 +1397,7 @@ function printHintBox(text) { uniqueId++; return '' + getLocalizedText('settings.help') + ''+ - '
' + text + '
'; + ''; } function showAbout() @@ -1589,15 +1737,15 @@ function log(message)