/*
 * matecomponent-persist.idl: MateComponent::Persist interfaces
 *
 * Copyright (C) 1999, 2000  Helix Code, Inc.
 *
 * Authors:
 *    Miguel de Icaza (miguel@gnu.org)
 *    Dan Winship     (danw@helixcode.com)
 */

#ifndef MATECOMPONENT_PERSIST_IDL
#define MATECOMPONENT_PERSIST_IDL

#include "MateComponent_Unknown.idl"
#include "MateComponent_Storage.idl"
#include "MateComponent_Exception.idl"

module MateComponent {

	interface Persist : Unknown {
		enum Status {
			SAVE_OK,
			SAVE_CANCEL,
			SAVE_FAILED
		};

		exception WrongDataType {};
		exception FileNotFound {};

		typedef string                ContentType;
		typedef sequence<ContentType> ContentTypeList;
		
		/**
		 * getContentTypes:
		 *
		 *  Gets a list of supported mime types that this
		 * persistor can save its data in. The default /
		 * preferred type being the first element.
		 */
		ContentTypeList getContentTypes ();

		typedef string                IID;
		
		/**
		 * getIId:
		 *
		 * Get the IID necessary to recreate the object whose
		 * internal state this interface represents
		 */
		IID getIId ();

		/**
		 * isDirty:
		 * 
		 * Indicates if a save is necessary.
		 */
		boolean isDirty ();
	
		void unImplemented1 ();
		void unImplemented2 ();
	};
	
	/*
	 * The PersistFile interface is somewhat mis-named it
	 * should be PersistURI.
	 *
	 * This allows applications to load and save documents
	 * via the Mate VFS.
	 */
	interface PersistFile : Persist {

	        exception NoCurrentName {
			string extension;
		};

		/**
		 * load:
		 * @uri: URI to load from
		 * 
		 * Loads the document object from the file
		 * pointed in by @path
		 */
		void load (in string uri)
			raises (IOError, NotSupported,
				WrongDataType, FileNotFound);

		/**
		 * save:
		 * @uri: the URI to save to
		 * saves the document object to the file 
		 * pointed in by @path
		 */
		void save (in string uri)
			raises (IOError, NotSupported);
	
		/**
		 * getCurrentFile:
		 * 
		 * Returns the URI of the current file. 
		 */
		string getCurrentFile ()
			raises (NoCurrentName);

		void unImplemented3 ();
		void unImplemented4 ();
	};

	/*
	 * PersistStorage is implemented by MateComponentObjects.
	 * 
	 * The methods are used by MateComponent and the container
	 * applications to manipulate the storage of a componet
	 */
	interface PersistStorage : Persist {
		
		/**
		 * load:
		 * @storage: The storage to load the state from
		 *
		 * The matecomponent_object should load its state from the
		 * @storage provided
		 */
		void load (in MateComponent::Storage storage)
			raises (IOError, NotSupported,
				WrongDataType);

		/**
		 * save:
		 * @storage: The storage in which to save the state
		 * of the matecomponent_object
		 * @same_as_loaded: if TRUE, this means the object
		 * is being saved to the same source used to load the object
		 *
		 * MateComponentObjects should save their sate in the @storage
		 */
		void save (in MateComponent::Storage storage,
			   in boolean same_as_loaded)
			raises (IOError, NotSupported);
	};
	
	/*
	 * This interface is used by items which only need to store 
	 * information in a Stream ( monikers are the primary
	 * users of this ).  
	 *
	 * Unlike PersistStorage, the Stream passed is only valid
	 * during these calls (ie, you should not incref these
	 * and used them after this).
	 */
	interface PersistStream : Persist {
		
		/**
		 * load:
		 * @stream: Where to load the state from
		 * @type: the MIME content type of the data, or ""
		 * if it is unknown.
		 *
		 * Loads the status of the object from @stream
		 */
		void load (in MateComponent::Stream stream, in ContentType type)
			raises (IOError, NotSupported,
				WrongDataType);

		/**
		 * save:
		 * @stream: Where to save the state to.
		 * @type: the MIME content type to save the data in,
		 * or "" if any type is acceptable.
		 *
		 * If no exception was thrown the data in the stream has
		 * the requested content type; if no type was requested
		 * the first entry from getContentTypes is returned.
		 * Hence no return value is needed.
		 * 
		 * Saves the state of the object to the @stream
		 */
		void save (in MateComponent::Stream stream, in ContentType type)
			raises (IOError, NotSupported,
				WrongDataType);

		void unImplemented3 ();
		void unImplemented4 ();
	};
};

#endif /* MATECOMPONENT_PERSIST_IDL */
