/*
 * 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
 *
 */

#include "pkgdeinstallengine.h"

#include <unixprocess.h>

#define PKGDEINSTALL_CMD	"/usr/local/sbin/pkg_deinstall"

PkgDeinstallEngine::PkgDeinstallEngine()
	:	force(false),
		rmEmptyDirs(false)
{
}



/** Returns a QProcess that applies the
  * specified actions on the given list
  * of packages or NULL if not packages
  * for upgrading were specified.
  *
  * The returned QProcess must be deleted after use.
  */
UnixProcess * PkgDeinstallEngine::getProcess() {
	if(packages.isEmpty())
		return  NULL;

	UnixProcess  *process = new UnixProcess(QString(PKGDEINSTALL_CMD));

	if(force)
		process->addArgument("-f");

	if(rmEmptyDirs)
		process->addArgument("-d");

	Package  *pkg = packages.first();
	while(pkg != NULL) {
		process->addArgument(pkg->getID());

		pkg = packages.next();
	}

	return  process;
}

