/* -*- Mode: idl; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/* ***** BEGIN LICENSE BLOCK *****
 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
 *
 * The contents of this file are subject to the Mozilla Public License Version
 * 1.1 (the "License"); you may not use this file except in compliance with
 * the License. You may obtain a copy of the License at
 * http://www.mozilla.org/MPL/
 *
 * Software distributed under the License is distributed on an "AS IS" basis,
 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
 * for the specific language governing rights and limitations under the
 * License.
 *
 * The Original Code is mozilla calendar code.
 *
 * The Initial Developer of the Original Code is
 *   Michiel van Leeuwen <mvl@exedo.nl>.
 * Portions created by the Initial Developer are Copyright (C) 2006
 * the Initial Developer. All Rights Reserved.
 *
 * Contributor(s):
 *   Daniel Boelzle <mozilla@boelzle.org>
 *
 * Alternatively, the contents of this file may be used under the terms of
 * either the GNU General Public License Version 2 or later (the "GPL"), or
 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
 * in which case the provisions of the GPL or the LGPL are applicable instead
 * of those above. If you wish to allow use of your version of this file only
 * under the terms of either the GPL or the LGPL, and not to allow others to
 * use your version of this file under the terms of the MPL, indicate your
 * decision by deleting the provisions above and replace them with the notice
 * and other provisions required by the GPL or the LGPL. If you do not delete
 * the provisions above, a recipient may use your version of this file under
 * the terms of any one of the MPL, the GPL or the LGPL.
 *
 * ***** END LICENSE BLOCK ***** */

#include "nsISupports.idl"

interface calIIcalProperty;
interface calIIcalComponent;
interface calIItemBase;
interface nsIInputStream;
interface calITimezoneProvider;
interface calIIcsParser;

/**
 * Listener being called once asynchronous parsing is done.
 */
[scriptable, uuid(d22527da-b0e2-41b7-b6f4-ee9c243cd285)]
interface calIIcsParsingListener : nsISupports
{
    void onParsingComplete(in nsresult rc, in calIIcsParser parser);
};

/**
 * An interface for parsing an ics string or stream into its items.
 * Note that this is not a service. A new instance must be created for every new
 * string or stream to be parsed.
 */
[scriptable, uuid(83e9befe-5e9e-49de-8bc2-d882f464f7e7)]
interface calIIcsParser : nsISupports
{
  /**
   * Parse an ics string into its items, and store top-level properties and
   * components that are not interpreted.
   *
   * @param aICSString
   *    The ICS string to parse
   * @param optional aTzProvider
   *    The timezone provider used to resolve timezones not contained in the
   *    parent VCALENDAR or null (falls back to timezone service)
   * @param optional aAsyncParsing
   *    If non-null, parsing will be performed on a worker thread,
   *    and the passed listener is called when it's done
   */
  void parseString(in AString aICSString,
                   [optional] in calITimezoneProvider aTzProvider,
                   [optional] in calIIcsParsingListener aAsyncParsing);

  /**
   * Parse an input stream.
   *
   * @see parseString
   * @param aICSString
   *    The stream to parse
   * @param optional aTzProvider
   *    The timezone provider used to resolve timezones not contained in the
   *    parent VCALENDAR or null (falls back to timezone service)
   * @param optional aAsyncParsing
   *    If non-null, parsing will be performed on a worker thread,
   *    and the passed listener is called when it's done
   */
  void parseFromStream(in nsIInputStream aStream,
                       [optional] in calITimezoneProvider aTzProvider,
                       [optional] in calIIcsParsingListener aAsyncParsing);

  /**
   * Get the items that were in the string or stream. In case an item represents a
   * recurring series, the (unexpanded) parent item is returned only.
   * Please keep in mind that any parentless items (see below) are not contained
   * in the returned set of items.
   *
   * @param aCount
   *    Will hold the number of items that were parsed
   * @param aItems
   *    The items
   */
  void getItems(out PRUint32 aCount,
                [array,size_is(aCount),retval] out calIItemBase aItems);

  /**
   * Get the parentless items that may have occurred, i.e. overridden items of a
   * recurring series (having a RECURRENCE-ID) missing their parent item in the
   * parsed content.
   *
   * @param aCount
   *    Will hold the number of items that were parsed
   * @param aItems
   *    The items
   */
  void getParentlessItems(out PRUint32 aCount,
                          [array,size_is(aCount),retval] out calIItemBase aItems);

  /**
   * Get the top-level properties that were not interpreted as anything special
   * @param aCount
   *    Will hold the number of properties that were found
   * @param aProperties
   *    The properties
   */
  void getProperties(out PRUint32 aCount,
                     [array,size_is(aCount),retval] out calIIcalProperty aProperties);

  /**
   * Get the top-level components that were not interpreted as anything special
   * @param aCount
   *    Will hold the number of components that were found
   * @param aComponents
   *    The components
   */
  void getComponents(out PRUint32 aCount,
                     [array,size_is(aCount),retval] out calIIcalComponent aComponents);
};
