/*
 *  Copyright (C) 2007-2008 CMM Sigma Andrzej Chmielowiec <cmmsigma@cmmsigma.eu>
 *
 *  This program is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License version 3
 *  as published by the Free Software Foundation.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 */

// AdminOptions.cpp: implementation of the AdminOptions class.
//
//////////////////////////////////////////////////////////////////////

#include "AdminOptions.h"

AdminOptions::AdminOptions()
{
}

AdminOptions::~AdminOptions()
{
}

void
AdminOptions::serialize(QIODevice &dev)
{
	QXmlStreamWriter xml(&dev);
	xml.setAutoFormatting(true);

	xml.writeStartDocument();
	xml.writeStartElement("ADMIN_XML_CONFIG");

	mailConfig.serialize(xml);

	xml.writeEndElement();
	xml.writeEndDocument();
}

bool
AdminOptions::deserialize(QIODevice &dev)
{
	bool result = false;

	QXmlStreamReader xml(&dev);
	QString xname;
	
	while (!xml.atEnd())
	{
		xml.readNext();
		xname = xml.name().toString();

		if(xml.isStartElement())
		{
			if(xname == "ADMIN_XML_CONFIG" && !result)
			{
				result = true;
			}
			else if(result)
			{
				if(xname == "MAIL_CONFIG")
					mailConfig.deserialize(xml);
			}
		}
		else if(xml.isEndElement() && xname == "ADMIN_XML_CONFIG")
			break;
	}
	if (xml.hasError())
	{
		result = false;
	}

	return result;
}

