From d1243bef373614cc6e4edd1488595100abcc1c49 Mon Sep 17 00:00:00 2001 From: "mvl%exedo.nl" Date: Mon, 22 Aug 2005 17:43:01 +0000 Subject: [PATCH] Actually use new publish interfaces for publishing. bug 285016, r=jminta --- calendar/resources/content/calendar.js | 62 --- calendar/resources/content/publish.js | 397 ++++++++------------ calendar/resources/content/publishDialog.js | 26 +- 3 files changed, 173 insertions(+), 312 deletions(-) diff --git a/calendar/resources/content/calendar.js b/calendar/resources/content/calendar.js index d6f1a5dff7c5..8aed6c3de7e5 100644 --- a/calendar/resources/content/calendar.js +++ b/calendar/resources/content/calendar.js @@ -1023,68 +1023,6 @@ function print() window.openDialog("chrome://calendar/content/printDialog.xul","printdialog","chrome",args); } - -function publishEntireCalendar() -{ - var args = new Object(); - - args.onOk = self.publishEntireCalendarDialogResponse; - - var remotePath = ""; // get a remote path as a pref of the calendar - - if (remotePath != "" && remotePath != null) { - var publishObject = new Object( ); - publishObject.remotePath = remotePath; - args.publishObject = publishObject; - } - - openDialog("chrome://calendar/content/publishDialog.xul", "caPublishEvents", "chrome,titlebar,modal", args ); -} - -function publishEntireCalendarDialogResponse( CalendarPublishObject ) -{ - var icsURL = makeURL(CalendarPublishObject.remotePath); - - var oldCalendar = getDefaultCalendar(); // get the currently selected calendar - - // create an ICS calendar, but don't register it - var calManager = getCalendarManager(); - try { - var newCalendar = calManager.createCalendar("ics", icsURL); - } catch (ex) { - dump(ex); - return; - } - - var getListener = { - onOperationComplete: function(aCalendar, aStatus, aOperationType, aId, aDetail) - { - // delete the new calendar now that we're done with it - calManager.deleteCalendar(newCalendar); - } - }; - - appendCalendars(newCalendar, [oldCalendar], getListener); -} - -function publishCalendarData() -{ - var args = new Object(); - - args.onOk = self.publishCalendarDataDialogResponse; - - openDialog("chrome://calendar/content/publishDialog.xul", "caPublishEvents", "chrome,titlebar,modal", args ); -} - -function publishCalendarDataDialogResponse( CalendarPublishObject ) -{ - var calendarString = eventArrayToICalString( gCalendarWindow.EventSelection.selectedEvents ); - - calendarPublish(calendarString, CalendarPublishObject.remotePath, "text/calendar"); -} - - - function getCharPref (prefObj, prefName, defaultValue) { try { diff --git a/calendar/resources/content/publish.js b/calendar/resources/content/publish.js index cb6bfb52ee47..0f4850a484e9 100644 --- a/calendar/resources/content/publish.js +++ b/calendar/resources/content/publish.js @@ -36,279 +36,192 @@ * * ***** END LICENSE BLOCK ***** */ -// Original code: -// http://lxr.mozilla.org/mozilla/source/editor/ui/composer/content/publish.js -// TODO Implement uploadfile with: -//void setUploadFile(in nsIFile file, in string contentType, in long contentLength); - -var gPublishHandler = null; - - -/* Create an instance of the given ContractID, with given interface */ -function createInstance(contractId, intf) { - return Components.classes[contractId].createInstance(Components.interfaces[intf]); +function publishCalendarData() +{ + var args = new Object(); + + args.onOk = self.publishCalendarDataDialogResponse; + + openDialog("chrome://calendar/content/publishDialog.xul", "caPublishEvents", "chrome,titlebar,modal", args ); } - -var gPublishIOService; -function GetIOService() +function publishCalendarDataDialogResponse(CalendarPublishObject, aProgressDialog) { - if (gPublishIOService) - return gPublishIOService; - - gPublishIOService = Components.classes["@mozilla.org/network/io-service;1"].getService(Components.interfaces.nsIIOService); - if (!gPublishIOService) - dump("failed to get io service\n"); - - return gPublishIOService; + publishItemArray(gCalendarWindow.EventSelection.selectedEvents, + CalendarPublishObject.remotePath, aProgressDialog); } - -/** - * This is the entry point into the file from calendar.js - * contentType is always text/calendar - */ - -function calendarPublish(aDataString, newLocation, contentType) +function publishEntireCalendar() { - try - { - var protocolChannel = get_destination_channel(newLocation); - if (!protocolChannel) - { - dump("failed to get a destination channel\n"); - return; + var args = new Object(); + var publishObject = new Object( ); + + args.onOk = self.publishEntireCalendarDialogResponse; + + // get the currently selected calendar + var cal = getDefaultCalendar(); + publishObject.calendar = cal; + + // get a remote path as a pref of the calendar + var remotePath = getCalendarManager().getCalendarPref(cal, "publishpath"); + if (remotePath && remotePath != "") { + publishObject.remotePath = remotePath; } - output_string_to_channel(protocolChannel, aDataString, contentType); - protocolChannel.asyncOpen(gPublishingListener, null); - } - catch (e) - { - alert("an error occurred in calendarPublish: " + e + "\n"); - } + + args.publishObject = publishObject; + openDialog("chrome://calendar/content/publishDialog.xul", "caPublishEvents", "chrome,titlebar,modal", args ); } -function calendarUploadFile(aSourceFilename, newLocation, contentType) +function publishEntireCalendarDialogResponse(CalendarPublishObject, aProgressDialog) { - try - { - var protocolChannel = get_destination_channel(newLocation); - if (!protocolChannel) - { - dump("failed to get a destination channel\n"); - return; - } - output_file_to_channel(protocolChannel, aSourceFilename, contentType); - protocolChannel.asyncOpen(gPublishingListener, protocolChannel); + var itemArray = []; + var getListener = { + onOperationComplete: function(aCalendar, aStatus, aOperationType, aId, aDetail) + { + publishItemArray(itemArray, CalendarPublishObject.remotePath, aProgressDialog); + }, + onGetResult: function(aCalendar, aStatus, aItemType, aDetail, aCount, aItems) + { + if (!Components.isSuccessCode(aStatus)) { + aborted = true; + return; + } + if (aCount) { + for (var i=0; i