/***************************************************************************
     dcfilelistdecompressor.h  -  Valknut Filelist Processing Thread
                             -------------------
    begin                : Thu Jul 3 2008
    copyright            : (C) 2008 by Edward Sheldrake
    email                : ejs1920@yahoo.co.uk
 ***************************************************************************/

/***************************************************************************
 *                                                                         *
 *   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 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 ***************************************************************************/

#ifndef DCFILELISTDECOMPRESSOR_H
#define DCFILELISTDECOMPRESSOR_H

/**
 * @author Edward Sheldrake
 *
 * This is a QThread that processes a filelist.
 * DCFileBrowser will respond to QThread's finished signal.
 *
 * It does the bzip2/he3 decompression, and for old valknut
 * filelists, removes the header and creates a bzip2 compressed version
 * to support saving to a new file.
 *
 * Produces an already parsed CXml object for xml filelists.
 */

#include <QThread>

#include <dclib/core/cstring.h>

class CByteArray;
class CXml;

class DCFilelistDecompressor : public QThread {
Q_OBJECT

public:
	/**
	 * Constructor. Empty filename opens own list.
	 */
	DCFilelistDecompressor( QObject * parent, CString filename );
	/** destructor */
	virtual ~DCFilelistDecompressor();
	
	/** the method that runs in the thread */
	virtual void run();
	
	/**
	 * Gets the CXml object containing the parsed xml filelist document,
	 * and removes it from this object.
	 *
	 * Returns NULL if not available, for text lists or invalid files.
	 */
	CXml * takeXml();
	/**
	 * Gets the text list data, and removes the data from this
	 * object.
	 *
	 * Returns NULL if not available, for xml lists or invalid files.
	 */
	CString * takeText();
	/**
	 * Gets the compressed data of the filelist, and removes it from
	 * this object.
	 *
	 * Returns NULL if not available (invalid file).
	 */
	CByteArray * takeCompressed();
	/**
	 * Get file name for filelist, may be changed if loading own list or
	 * loading an uncompressed filelist.
	 */
	CString getFileName();

private:
	/** */
	bool LoadOldValknutList( CByteArray * dest );
	
	/** file name */
	CString filename;
	
	/** Pointer to CXml object containing document of xml list */
	CXml * xmllist;
	/** Text list data */
	CString * textlist;
	/** Compressed filelist data */
	CByteArray * compressed;
};

#endif // DCFILELISTDECOMPRESSOR_H
