/*	XPreferences.h
 *
 *		This defines the classes which are used to encapsulate
 *	the storage of preferences data.
 *
 *		Preferences are stored on the Macintosh in a
 *	preferences file named after the application, in the
 *	system's preferences folder. On Windows, preferences data
 *	is stored in the system registry. On Unix, preferences
 *	are written to an invisible file in the user's home
 */

/**********************************************************************

  YAAF is Copyright 1997-1999 by William Woody.

  Redistribution and use in source and binary forms, with or without 
  modification, are permitted provided that the following conditions 
  are met:

  Redistributions of source code must retain the above copyright notice, 
  this list of conditions and the following disclaimer.

  Neither the name of the copyright holder or other contributors may
  be used to promote products derived from this software without
  specific written prior permission.

  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 
  EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 
  OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 
  NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS 
  BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN 
  ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 
  CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 
  SOFTWARE.
  
  Contact:   woody@alumni.caltech.edu
  Web page:  http://www.pandawave.com/yaaf/

**********************************************************************/

#ifndef PandaWave_XPREFERENCES
#define PandaWave_XPREFERENCES

#include <XConfig.h>
#include <XString.h>
#include <XHandle.h>

/************************************************************************/
/*																		*/
/*	Classes																*/
/*																		*/
/************************************************************************/

/*$	XGPreferences
 *
 *		The preference record. This is generally a stack-based object
 *	which, on creation, opens either a preference file (on Unix or the
 *	Macintosh), or a registry key in the system registry (on Windows).
 *
 *		This permits the storage of simple "preference keys", which is
 *	a mechanism for storing simple "variable" = "value" keys.
 */

class XGPreferences {
	public:
#if OPT_MACOS
								XGPreferences(const char *name, long creator);
#endif

#if OPT_WINOS
								XGPreferences(const char *comp, const char *prod, const char *vers);
#endif

#if OPT_XWIN
								XGPreferences(const char *name);
#endif

		virtual					~XGPreferences();
		
		/*
		 *	Get values
		 */
		
		bool					GetBoolean(const char *key, bool deflt = false);
		long					GetInteger(const char *key, long deflt = 0);
		void					GetString(const char *key, char *value, const char *deflt = 0);
		
		/*
		 *	Set values
		 */
		
		void					SetBoolean(const char *key, bool value);
		void					SetInteger(const char *key, long value);
		void					SetString(const char *key, const char *value);
		
		/*
		 *	Delete values
		 */
		
		void					DeleteValue(const char *key);

	private:
	
#if OPT_MACOS
		long					fType;
#endif

#if OPT_MACOS || OPT_XWIN
		void					ReadData(void);
		void					WriteData(void);

		bool					fDirty;
		XGString				fFile;
		
		XGStringList			fDataKey;
		XGStringList			fDataValue;
#endif

#if OPT_WINOS
		HKEY					fKey;
#endif
};

#endif // PandaWave_XPREFERENCES
