
//  Copyright (C) 2009 by Arnaud Dupuis
//  a.dupuis@infinityperl.org
//  http://www.infinityperl.org
// 
//  This program is free software; you can redistribute it and/or modify
//  it under the terms of the GNU General Public License as published by
//  the Free Software Foundation; either version 3 of the License, or
//  (at your option) any later version.
// 
//  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.
// 
//  You should have received a copy of the GNU General Public License
//  along with this program; if not, write to the
//  Free Software Foundation, Inc.,
//  59 Temple Place - Suite 330, Boston, MA  02111-1307, USA

#ifdef ASSUMA_WITH_UPDATER

#ifndef UPDATEHANDLER_H
#define UPDATEHANDLER_H

#include "assuma_updatedialog.h"
#include <QXmlDefaultHandler>
class QString;
class QListWidget;
class QListWidgetItem;
/*! \class UpdateHandler
* \brief the XML handler for the update list.
*
* This class is the XML handler for update description file. This file is stored on updates servers.
*/
class UpdateHandler : public QXmlDefaultHandler
{
	public:
		/*!
		Constructs a new handler.
		*/
		UpdateHandler( AssumaUpdateDialog* );
		/*!
		The reader calls this function when it has parsed a start element tag.

		There is a corresponding endElement() call when the corresponding end element tag is read. The startElement() and endElement() calls are always nested correctly. Empty element tags (e.g. <x/>) cause a startElement() call to be immediately followed by an endElement() call.

		The attribute list provided only contains attributes with explicit values. The attribute list contains attributes used for namespace declaration (i.e. attributes starting with xmlns) only if the namespace-prefix property of the reader is true.

		The argument namespaceURI is the namespace URI, or an empty string if the element has no namespace URI or if no namespace processing is done. localName is the local name (without prefix), or an empty string if no namespace processing is done, qName is the qualified name (with prefix) and atts are the attributes attached to the element. If there are no attributes, atts is an empty attributes object.

		If this function returns false the reader stops parsing and reports an error. The reader uses the function errorString() to get the error message.
		\sa endElement
		*/
		bool startElement( const QString &namespaceURI, const QString &localName, const QString &qName, const QXmlAttributes &attributes );
		/*!
		The reader calls this function when it has parsed an end element tag with the qualified name qName, the local name localName and the namespace URI namespaceURI.

		If this function returns false the reader stops parsing and reports an error. The reader uses the function errorString() to get the error message.
		*/
		bool endElement( const QString &namespaceURI, const QString &localName, const QString &qName );
		/*!
		The reader calls this function when it has parsed a chunk of character data (either normal character data or character data inside a CDATA section; if you need to distinguish between those two types you must use QXmlLexicalHandler::startCDATA() and QXmlLexicalHandler::endCDATA()). The character data is reported in ch.

		If this function returns false the reader stops parsing and reports an error. The reader uses the function errorString() to get the error message.
		*/
		bool characters(const QString &str);
		/*!
		A reader must use this function to report a non-recoverable error. Details of the error are stored in exception.

		If this function returns true the reader might try to go on parsing and reporting further errors, but no regular parsing events are reported.
		*/
		bool fatalError(const QXmlParseException &exception);
	private:
		QString currentText;
		AssumaUpdateDialog *updateDialog;
		QListWidgetItem *currentItem;
};

#endif //UPDATEHANDLER_H
#endif //ASSUMA_WITH_UPDATER
