/**
 * File:	modules/Irda.ycp
 * Package:	Configuration of irda
 * Summary:	Irda settings, input and output functions
 * Authors:	Jiri Suchomel <jsuchome@suse.cz>
 *
 * $Id: Irda.ycp 20387 2004-11-23 15:18:29Z jsuchome $
 *
 * Representation of the IrDA configuration.
 * Input and output routines.
 */

{

module "Irda";
textdomain "irda";

import "Progress";
import "Service";

/**
 * Data was modified?
 */
global boolean modified = false;

/**
 * Should irda be started?
 */
global boolean start	= false;

/**
 * serial port used for irda
 */
global string port	= "";

/**
 * Maximum baud rate for the IrDA serial port
 */
global string max_baud_rate	= "0";

/**
 * If link to /ev/pilot should be created
 */
global boolean link_pilot	= false;

/**
 * Read irda settings from /etc/sysconfig/irda
 * @return true when file exists
 */
global define boolean ReadSysconfig () {


    if (SCR::Read (.target.size, "/etc/sysconfig/irda") != -1)
    {
	port = (string) SCR::Read (.sysconfig.irda.IRDA_PORT);
	if (port == nil)
	    port = "";

	max_baud_rate = (string) SCR::Read (.sysconfig.irda.IRDA_MAX_BAUD_RATE);
	if (max_baud_rate == nil)
	    max_baud_rate = "0";
	return true;
    }
    return false;
}

/**
 * Read all irda settings
 * @return true on success
 */
global define boolean Read () {

    ReadSysconfig ();

    start = (Service::Status ("irda") == 0);

    return true;
}

/**
 * Write all irda settings
 * @return true on success
 */
global define boolean Write () {

    if (!modified)
	return true;

    /* Irda read dialog caption */
    string caption	= _("Saving IrDA Configuration");
    integer steps	= 2;

    Progress::New (caption, " ", steps, [
	    /* Progress stage 1/2 */
	    _("Write the settings"),
	    /* Progress stage 2/2 */
	    _("Restart the service")
	], [
	    /* Progress step 1/2 */
	    _("Writing the settings..."),
	    /* Progress step 2/2 */
	    _("Restarting service..."),
	    /* Progress finished */
	    _("Finished")
	],
	""
    );

    Progress::NextStage();

    if (port != "")
    {
	SCR::Write (.sysconfig.irda.IRDA_PORT, port);
	SCR::Write (.sysconfig.irda, nil);
    }

    Progress::NextStage ();

    Service::Stop ("irda");
    if (start)
    {
	Service::Start ("irda");
	Service::Enable ("irda");
    }
    else
    {
	Service::Disable ("irda");
    }

    // create symlink to /dev/pilot (#47804)
    if (link_pilot)
    {
	if ((boolean)SCR::Execute (.target.symlink,"/dev/ircomm0","/dev/pilot"))
	{
	    SCR::Execute (.target.bash, "/sbin/resmgr add /dev/pilot desktop");
	}
    }

    Progress::NextStage();

    return true;
}

/* EOF */
}
