/* vim: ts=4 sw=4 expandtab cindent
 *
 * BEGIN FLOCK GPL
 * 
 * Copyright Flock Inc. 2005-2006
 * http://flock.com
 * 
 * This file may be used under the terms of of the
 * GNU General Public License Version 2 or later (the "GPL"),
 * http://www.gnu.org/licenses/gpl.html
 * 
 * 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.
 * 
 * END FLOCK GPL
 */

#include "nsISupports.idl"

#include "nsISimpleEnumerator.idl"
#include "nsIRDFDataSource.idl"
#include "nsIArray.idl"
#include "flockIFavoritesWebService.idl"
#include "flockIFavoriteProperties.idl"
#include "nsISimpleEnumerator.idl"

[scriptable, uuid(77f4e736-9402-42d9-a051-212e71751c1b)]
interface flockIFavoritesServiceProgressListener : nsISupports {
    void onSyncUp (in boolean aSuccess, in AString aMessage);
    void onSyncDown (in boolean aSuccess, in AString aMessage);
    void onCreate (in AString aURL, in boolean aSuccess, in AString aMessage);
    void onUpdate (in AString aURL, in boolean aSuccess, in AString aMessage);
    void onRemove (in AString aURL, in boolean aSuccess, in AString aMessage);

    void onSyncUpStart ();
    void onSyncDownStart ();
    void onCreateStart (in AString aURL);
    void onUpdateStart (in AString aURL);
    void onRemoveStart (in AString aURL);
};

/**
 * flockIFavoritesService is the interface that the flock favorites service exposes to
 * allow the rest of the browser and extensions to interact with favorites data.
 */
[scriptable, uuid(2ef98743-1714-4de1-88f2-7771c63dcde8)]
interface flockIFavoritesService : nsIRDFDataSource {
    /** create a favorite with the supplied url @aURL and properties @aProperties */
    void createFavorite (in AString aURL, in flockIFavoriteProperties aProperties);
    /** remove the favorite @aURL from the favorites system */
    void removeFavorite (in AString aURL);
    /** update the properties on @aURL with the values in @aProperties */
    void updateFavorite (in AString aURL, in flockIFavoriteProperties aProperties);
    /** returns true if the supplied URL @aURL is stored as a favorite in the favorites
     *  service or false if it is not
     */
    boolean isFavorite (in AString aURL);
    /** returns the properties of the favorite @aURL */
    flockIFavoriteProperties getFavoriteProperties (in AString aURL);
    nsISimpleEnumerator getAllFavorites ();

    /** return true if the supplied resource @aCollection refers to a favorites
     *  collection and false if it does not.
     */
    boolean isCollectionResource (in nsIRDFResource aCollection);
    /** returns true if a collection exists with the name @aCollectionName or false
     *  if no collection exists with that name.
     */
    boolean isCollection (in AString aCollectionName);
    /** creates a collection named @aCollectionName. If there is already a collection of
     *  that name it returns false, otherwise it returns true.
     */
    boolean createCollection (in AString aCollectionName);
    /** removes the collectoin named @aCollectionName. If that succeeded true is returned,
     *  if it fails then false is returned.
     */
    boolean removeCollection (in AString aCollectionName);
    /** renames a collection from @aCollectionName to @aNewName. The return value
     *  indicates success.
     */
    boolean renameCollection (in AString aCollectionName, in AString aNewName);
    /** returns the name of the collection pointed to by @aCollection or null if no such
     *  collection exists.
     */
    AString getCollectionName (in nsIRDFResource aCollection);
    /** returns the resource for the collection named @aCollectionName or null if no such
     *  collection exists. 
     */
    nsIRDFResource getCollectionResource (in AString aCollectionName);
   
    /* adds the favorite @aFavoritesURL to the collection @aCollectionName */ 
    void addFavoriteToCollection (in AString aFavoriteURL, in AString aCollectionName);
    /* removes the favorite @aFavoriteURL from the collection @aCollectionName. */
    void removeFavoriteFromCollection (in AString aFavoriteURL, in AString aCollectionName);
    /** reorders the collection @aCollectionName so the favorite @aFavoriteURL is at 
     *  position @aIndex.
     */
    void orderFavoriteInCollection (in AString aFavoriteURL, in AString aCollectionName, in PRUint32 aIndex);
    /** returns the index of @aFavoriteURL in the collection aCollectionName */
    PRUint32 getFavoriteOrderInCollection (in AString aFavoriteURL, in AString aCollectionName);
    /** returns true if the favorite @aFavoriteURL is in the collection @aCollection, or
     *  false if it is not.
     */
    boolean isFavoriteInCollection (in aString aFavoriteURL, in AString aCollection);
    /** returns all the favorites in @aCollection as an enumerator of nsIRDFResource */
    nsISimpleEnumerator getCollectionFavorites (in AString aCollection);

    /* FIXME: I want these methods to go away. They should be in a pref or something */
    void setToolbarCollection(in nsIRDFResource aCollection);
    nsIRDFResource getToolbarCollection();

    /** returns an enumerator that contains resources referring to all the collections
     *  that the favorite @aFavoriteURL is in.
     */
    nsISimpleEnumerator getFavoriteCollections (in AString aFavoriteURL);
    /** sets the collections that a favorite exists in
      */
    void setFavoriteCollections (in AString aFavoriteURL, in nsISimpleEnumerator aCollections);
    /** returns all collections as nsIRDFResources */
    nsISimpleEnumerator getAllCollections ();

    /** returns true if @aFeedURL refers to a feed or false if it does not. */
    boolean isFeed (in AString aFeedURL);
    /** returns true if @aFeed refers to a feed or false if it does not. */
    boolean isFeedResource (in nsIRDFResource aFeed);
    /** creates a feed resource with the url @aFeedURL and the properties @aFeedProperties
     *  thats associated with the favorite @aFavoriteURL.
     */
    void createFeedInFavorite (in AString aFeedURL, in flockIFavoriteProperties aFavoriteProperties, in AString aFavoriteURL);
    /** removes the feed @aFeedURL from the favorite @aFavoriteURL. */
    void removeFeedFromFavorite (in AString aFeedURL, in AString aFavoriteURL);
    /** returns true if the feed @aFeedURL is associated with the favorite @aFavoriteURL
     *  or false if it is not.
     */
    boolean isFeedInFavorite (in AString aFeedURL, in AString aFavoriteURL);
    /** gets the list of feeds associated with the favorite @aFavoriteURL. */
    void getFeedsInFavorite (in AString aFavoriteURL, out PRUint32 count, [array, size_is(count), retval] out wstring array);
    /** returns all the feeds in the system */
    nsISimpleEnumerator getAllFeeds ();
    /** get the properties of a feed */
    flockIFavoriteProperties getFeedProperties (in AString aFeedURL);
    /** updates the properties of a feed */
    void setFeedProperties (in AString aFeedURL, in flockIFavoriteProperties aFeedProperties);


    readonly attribute flockIFavoritesWebService webService;
    nsISimpleEnumerator getWebServices ();
    void authenticationFailed ();

    /* FIXME: should this be a public method? */
    /** request a resynchronization with the currently activice favorites web service */
    void synchronize ();

    /* FIXME: these need reworking */
    void addProgressListener (in flockIFavoritesServiceProgressListener aListener);
    void removeProgressListener (in flockIFavoritesServiceProgressListener aListener);


    /* flush to disk */
    void Flush ();

    /* disable hasFeeds updating */
    void disableHasFeeds ();
    /* enable and update hasFeeds code */
    void enableHasFeeds ();
};

