/*
 * This file is part of DesktopBSD, see the README file.
 *
 * Author: Peter Hofer <ph@desktopbsd.net>
 *         (C) 2004, 2005
 *
 * Copyright: BSD, see the COPYING file included in this distribution
 *
 */

#ifndef __PORTSUPDATEENGINE_H
#define __PORTSUPDATEENGINE_H

#include <qstring.h>

class UnixProcess;

/**
  * @brief Updates the ports tree.
  *
  * This class creates a QProcess that updates
  * the ports tree and/or the INDEX-5 file (in
  * this order).
  *
  * The default is to update the ports tree using
  * cvsup and fetch a new INDEX-5 file afterwards.
  *
  * Comments like [index] show the
  * corresponding make targets in /usr/ports.
  */
class PortsUpdateEngine {
public:
	enum UpdateMethod {
		NoUpdate = 0,
		Cvsup = 1,		/**< [update SUP_UPDATE=yes] */
		Portsnap = 2	/**< [update PORTSNAP_UPDATE=yes] */
	};

	enum IndexUpdateMethod {
	    None,
	    FetchIndex,	/**< [fetchindex] */
	    RebuildIndex	/**< [index     ] */
	};

	PortsUpdateEngine();

	UnixProcess * getProcess();

	void  readSettings();

	/** Specifies how the index file should be updated.
	  *
	  * @see IndexUpdateMethod
	  */
	void	setUpdateIndex(IndexUpdateMethod  method) { indexMethod = method; }

	/**
	  * Specifies what method should be used to update the
	  * ports tree. UpdateMethod::Portsnap overrides a
	  * specified IndexUpdateMethod because it handles updating
	  * the INDEX file itself.
	  */
	void	setUpdatePorts(UpdateMethod method) { updateMethod = method; }

private:
	QString				updateServer;
	QString				supFile;
	IndexUpdateMethod	indexMethod;
	UpdateMethod		updateMethod;
};

#endif /* __PORTSUPDATEENGINE_H */
