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

QString PackageSettings::getUpdateServer() {
	return readEntry("/packages/update_server", readEntry("/packages/cvsup_server"));
}


bool PackageSettings::setUpdateServer(const QString & server) {
	return writeEntry("/packages/update_server", server);
}


QString PackageSettings::getSupFile() {
	return readEntry("/packages/supfile", "/usr/share/examples/cvsup/ports-supfile");
}


bool PackageSettings::setSupFile(const QString & supFile) {
	return writeEntry("/packages/supfile", supFile);
}


bool PackageSettings::getUpwardRecursive() {
	return readBoolEntry("/packages/upward_recursive", false);
}


bool PackageSettings::setUpwardRecursive(bool urec) {
	return writeEntry("/packages/upward_recursive", urec);
}


bool PackageSettings::getRecursive() {
	return readBoolEntry("/packages/recursive", false);
}


bool PackageSettings::setRecursive(bool rec) {
	return writeEntry("/packages/recursive", rec);
}


bool PackageSettings::getKDialogOptions() {
	return readBoolEntry("/packages/kdialog_options", true);
}


bool PackageSettings::setKDialogOptions(bool kdOptions) {
	return writeEntry("/packages/kdialog_options", kdOptions);
}


bool PackageSettings::getKeepGoing() {
	return readBoolEntry("/packages/keep_going", false);
}


bool PackageSettings::setKeepGoing(bool kg) {
	return writeEntry("/packages/keep_going", kg);
}


int PackageSettings::getPackageUse() {
	return readNumEntry("/packages/package_use", 1);
}


bool PackageSettings::setPackageUse(int pu) {
	return writeEntry("/packages/package_use", pu);
}


QStringList PackageSettings::getMakeArguments() {
	return readListEntry("/packages/make_args");
}


bool PackageSettings::setMakeArguments(const QStringList & args) {
	return writeEntry("/packages/make_args", args);
}


QStringList PackageSettings::getMakeEnvironment() {
	return readListEntry("/packages/make_env");
}


bool PackageSettings::setMakeEnvironment(const QStringList & env) {
	return writeEntry("/packages/make_env", env);
}


QString PackageSettings::getPackageDirectory() {
	return readEntry("/packages/package_directory");
}


bool PackageSettings::setPackageDirectory(const QString & pd) {
	return writeEntry("/packages/package_directory", pd);
}


bool PackageSettings::isFirstRun() {
	return readBoolEntry("/packages/first_run", true);
}


bool PackageSettings::setFirstRun(bool fr) {
	return writeEntry("/packages/first_run", fr);
}

/**
  * Returns the preferred update method for ports.
  * 
  * @see PackageSettings::PortsUpdateMethod
  */
int PackageSettings::getPortsUpdateMethod() {
	/* cvsup is the default for compatibility reasons */
	return readNumEntry("/packages/update_method", CvsUp);
}

/** @see PackageSettings::getPortsUpdateMethod() */
bool PackageSettings::setPortsUpdateMethod(int method) {
	return writeEntry("/packages/update_method", method);
}

QString PackageSettings::getPortsnapWorkingDirectory() {
	return readEntry("/packages/portsnap_workdir");
}

/** @see PackageSettings::getPortsUpdateMethod() */
bool PackageSettings::setPortsnapWorkingDirectory(const QString & wd) {
	return writeEntry("/packages/portsnap_workdir", wd);
}

/**
  * Returns the preferred grouping of installed packages.
  * 
  * @see PackageSettings::InstalledPkgsGroupBy
  */
int PackageSettings::getInstalledPkgsGroupBy()
{
	return readNumEntry("/packages/installed_groupby", Category);
}

bool PackageSettings::setInstalledPkgsGroupBy(int groupby)
{
	return writeEntry("/packages/installed_groupby", groupby);
}

/**
  * Returns a bitfield indicating which notifications are enabled.
  *
  * Default: all enabled
  *
  * @see PackageSettings::Notifications
  */
int PackageSettings::getNotifications()
{
	return readNumEntry("/packages/notifications", INT_MAX);
}


/**
  * Set the bitfield indicating which notifications are enabled.
  * 
  * @see PackageSettings::getNotifications()
  */
bool PackageSettings::setNotifications(int n)
{
	return writeEntry("/packages/notifications", n);
}

/**
  * Returns the timeout in milliseconds after which package manager
  * notifications disappear. Default: 6000 = 6 seconds.
  *
  */
int PackageSettings::getNotificationTimeout()
{
	return readNumEntry("/packages/notification_timeout", 6000);
}

bool PackageSettings::setNotificationTimeout(int timeout)
{
	return writeEntry("/packages/notification_timeout", timeout);
}

/**
  * Incremental search for available packages (also known
  * as Find As You Type)
  */
bool PackageSettings::getIncrementalPackageFind()
{
	return readBoolEntry("/packages/incremental_find", true);
}

bool PackageSettings::setIncrementalPackageFind(bool v)
{
	return writeEntry("/packages/incremental_find", v);
}
