#ifndef __SETTINGS_H__
#define __SETTINGS_H__

#include <util/settings.h>
#include <util/string.h>
#include <util/message.h>

/** \brief Stores the user's settings for the app.
 * This is used to create a settings file for the app. See os::Settings.
 *
 */
class AppSettings : public os::Settings
{
public:

	/** \brief Return if the connection is passive.
	 * Returns the value for the setting 'passive' or true if it isn't found.
	 */
	os::String GetHost()
	{
		return( GetString( "host", m_zHost.c_str() ) );
	}

	/** \brief Set the value for passive.
	 * \param bPassive Whether or not this is a passive connection.
	 */
	status_t SetHost( os::String zHost )
	{
		m_zHost = zHost;
		return( AddString( "host", m_zHost ) );
	}

	/** \brief Return the maximum number of connections.
	 * This returns the maximum number of allowable connections or 2 by default.
	 */
	os::String GetPort()
	{
		return( GetString( "port", m_zPort.c_str() ) );
	}

	/** \brief Set the maximum number of connections.
	 *
	 * \param nMax The maximum number of connections to allow at one time.
	 */
	status_t SetPort( os::String zPort )
	{
		m_zPort = zPort;
		return( AddString( "port", m_zPort ) );
	}

	os::String GetPassword()
	{
		return( GetString( "password", m_zPassword.c_str() ) );
	}

	/** \brief Set the value for the 'Remember passwords' option.
	 *
	 * \param bSave The new value for the 'Remember passwords' option.
	 */
	status_t SetPassword( os::String zPassword )
	{
		m_zPassword = zPassword;
		return( SetString( "password", m_zPassword ) );
	}

	os::String GetUsername()
	{
		return( GetString( "username", m_zUsername.c_str() ) );
	}

	status_t SetUsername( os::String zUsername )
	{
		m_zUsername = zUsername;
		return( AddString( "username", m_zUsername ) );
	}

	os::String GetRealname()
	{
		return( GetString( "realname", m_zRealname.c_str() ) );
	}

	status_t SetRealname( os::String zRealname )
	{
		m_zRealname = zRealname;
		return( AddString( "realname", m_zRealname ) );
	}

	os::String GetNickname()
	{
		return( GetString( "nickname", m_zNickname.c_str() ) );
	}

	status_t SetNickname( os::String zNickname )
	{
		m_zNickname = zNickname;
		return( AddString( "nickname", m_zNickname ) );
	}

	os::String GetChannel()
	{
		return( GetString( "channel", m_zChannel.c_str() ) );
	}

	status_t SetChannel( os::String zChannel )
	{
		m_zChannel = zChannel;
		return( AddString( "channel", m_zChannel ) );
	}

	/** \brief Save the server address & login details to the history.
	 *
	 * \param zHost, zPort, zUser, zPassword The host, etc of the server to save.
	 */
	status_t AddHistory( const os::String& zHost, const os::String& zPort, const os::String& zUsername, const os::String& zPassword, const os::String& zRealname, const os::String& zNickname, const os::String& zChannel )
	{
		os::Message cMsg;
		cMsg.AddString( "host", zHost );
		cMsg.AddString( "port", zPort );
		cMsg.AddString( "username", zUsername );
		cMsg.AddString( "password", zPassword );
		cMsg.AddString( "realname", zRealname );
		cMsg.AddString( "nickname", zNickname );
		cMsg.AddString( "channel", zChannel );
		return( SetMessage( "history", cMsg ) );
	}

	/** \brief Load the most-recently used server address & login details from the history.
	 *
	 * \param pzHost, pzPort, pzUser, pzPassword - pointers to locations in which the corresponding data should be stored.
	 */
	status_t LoadHistory( os::String* pzHost, os::String* pzPort, os::String* pzUsername, os::String* pzPassword, os::String* pzRealname, os::String* pzNickname, os::String* pzChannel )
	{
		os::Message cMsg;
		status_t nResult = FindMessage( "history", &cMsg );
		cMsg.FindString( "host", pzHost );
		cMsg.FindString( "port", pzPort );
		cMsg.FindString( "username", pzUsername );
		cMsg.FindString( "password", pzPassword );
		cMsg.FindString( "realname", pzRealname );
		cMsg.FindString( "nickname", pzNickname );
		cMsg.FindString( "channel", pzChannel );
		return( nResult );
	}

	/** \brief Get the saved main window position.
	 * Returns the saved size & position of the main window, if any; returns Rect(0,0,0,0) if no position is saved.
	 */
	os::Rect GetMainWindowFrame()
	{
		return( GetRect( "main_frame", os::Rect(0,0,0,0) ) );
	}

	/** \brief Save the main window position.
	 * Saves the size & position of the main window.
	 */
	status_t SetMainWindowFrame( const os::Rect& cFrame )
	{
		return( SetRect( "main_frame", cFrame ) );
	}

	/** \brief Get debug mode setting.
	 * If true, we should print extra information for debugging, and set libcurl to use verbose mode.
	 */
	bool GetDebugMode()
	{
		return( GetBool( "debug", false ) );
	}

	/** \brief Set debug mode setting.
	 * See GetDebugMode().
	 */
	status_t SetDebugMode( bool bDebug )
	{
		return( SetBool( "debug", bDebug ) );
	}

private:

	os::String m_zHost;
	os::String m_zPort;
	os::String m_zUsername;
	os::String m_zPassword;
	os::String m_zRealname;
	os::String m_zNickname;
	os::String m_zChannel;
};


#endif	/* __SETTINGS_H__ */