diff --git a/calendar/resources/content/calendar.js b/calendar/resources/content/calendar.js index dd34d9524e2e..98fb24bfe2f8 100644 --- a/calendar/resources/content/calendar.js +++ b/calendar/resources/content/calendar.js @@ -131,6 +131,50 @@ function calendarInit() document.getElementById("view-deck") .addEventListener("dayselect", observeViewDaySelect, false); + + // Handle commandline args + for (var i=0; i < window.arguments.length; i++) { + try { + var cl = window.arguments[i].QueryInterface(Components.interfaces.nsICommandLine); + } catch(ex) { + dump("unknown argument passed to main window\n"); + continue; + } + handleCommandLine(cl); + } +} + +function handleCommandLine(aComLine) { + var calurl; + try { + calurl = aComLine.handleFlagWithParam("subscribe", false); + } catch(ex) {} + if (calurl) { + var uri = makeURL(calurl); + var cal = getCalendarManager().createCalendar('ics', uri); + getCalendarManager().registerCalendar(cal); + + // Strip ".ics" from filename for use as calendar name, taken from + // calendarCreation.js + var fullPathRegex = new RegExp("([^/:]+)[.]ics$"); + var prettyName = calurl.match(fullPathRegex); + var name; + + if (prettyName && prettyName.length >= 1) { + name = decodeURIComponent(prettyName[1]); + } else { + name = calGetString("calendar", "untitledCalendarName"); + } + cal.name = name; + } + + var date; + try { + date = aComLine.handleFlagWithParam("showdate", false); + } catch(ex) {} + if (date) { + currentView().goToDay(jsDateToDateTime(new Date(date))); + } } /* Called at midnight to tell us to update the views and other ui bits */ diff --git a/calendar/resources/content/calendarService.js b/calendar/resources/content/calendarService.js index 4c1d74122c53..41c3ef3cf1d1 100644 --- a/calendar/resources/content/calendarService.js +++ b/calendar/resources/content/calendarService.js @@ -123,16 +123,18 @@ CLineService.prototype = { /* nsICommandLineHandler */ handle : function service_handle(cmdLine) { - if (cmdLine.handleFlag("calendar", false)) { - wwatch = Components.classes[WINDOWWATCHER_CONTRACTID] - .getService(nsIWindowWatcher); - wwatch.openWindow(null, "chrome://calendar/content/", + // just pass all arguments on to the Sunbird window + wwatch = Components.classes[WINDOWWATCHER_CONTRACTID] + .getService(nsIWindowWatcher); + wwatch.openWindow(null, "chrome://calendar/content/", "_blank", "chrome,dialog=no,all", cmdLine); - cmdLine.preventDefault = true; - } + cmdLine.preventDefault = true; }, - helpInfo : " -calendar Start with the calendar.\n" + helpInfo : " -subscribe Pass in a path pointing to a calendar\n" + + " to subscribe to.\n" + + " -showdate Pass in a value for a javascript date\n" + + " to show this date on startup.\n" }; /* factory for command line handler service (CLineService) */