/*
 * 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 "fastestcvsupengine.h"

#include <pkgconstants.h>

#include <qlocale.h>
#include <qprocess.h>

/**
  * Returns a process that writes the name of the
  * fastest cvsup server in the user's country to
  * the standard output.
  *
  */
QProcess * FastestCVSUpEngine::getProcess() {
	QProcess *p = new QProcess(QString(FASTEST_CVSUP_CMD));
	
	/* Be very quiet */
	p->addArgument("-Q");
	
	/* Use locale */
	p->addArgument("-c"); p->addArgument(getLocale());
	
	return p;
}


/**
  * Extracts the country code from the locale environment variable.
  *
  */
QString FastestCVSUpEngine::getLocale() {
	QString cvsupLocale;

	const QString localeName = QLocale().name();
	if(localeName == "C")
		/* No locale defined; use the top-level domain */
		cvsupLocale = "TLD";
	else
		/* Use the country from the locale variable */
		cvsupLocale = localeName.section('_', 1);
		
	return cvsupLocale;
}

