/**
 * File:	clients/inst_fam.ycp
 * Package:	installation
 * Summary:	Configure FAM according to control file and defauls WM
 * Authors:	Jiri Srain <jsrain@suse.cz>
 *
 * $Id: inst_fam.ycp 22553 2005-03-15 08:44:53Z jsrain $
 *
 */

{
    textdomain "installation";

    import "ProductFeatures";
    import "ProductControl";
    import "Mode";
    import "Service";
    import "GetInstArgs";

    /**
     * Is GNOME installed?
     * @return true if it is
     */
    boolean GnomeInstalled () {
	return Pkg::IsProvided ("gnome-session");
    }

    /**
     * Is KDE installed?
     * @return true if it is
     */
    boolean KdeInstalled () {
	return Pkg::IsProvided ("kdebase3");
    }

    /* Called backwards */
    if(GetInstArgs::going_back())
	return `auto;

    if ( !Mode::update () )
    {
	string default_wm = (string)
	    SCR::Read (.sysconfig.windowmanager.DEFAULT_WM);
	if (SCR::Read (.target.size, ("/etc/sysconfig/fam")) != -1)
	{
	    y2milestone ("Default WM: %1", default_wm);
	    string local_only = ProductFeatures::fam_local_only;
	    y2milestone ("Fam activation: %1", local_only);
	    if (local_only == "always"
		|| local_only == default_wm
		|| (local_only == "gnome" && GnomeInstalled ())
		|| (local_only == "kde" && KdeInstalled ()))
	    {
		y2milestone ("Setting fam to local_only");
		SCR::Write (.sysconfig.fam.FAM_LOCAL_ONLY, "yes");
		SCR::Write (.sysconfig.fam, nil);
		Service::Enable ("fam");
	    }
	}

	// FIXME IT IS NOT YAST's TASK TO CREATE ENVIRONMENT FOR DESKTOPS THIS
	// WAY. See bug 72018.
	if (Pkg::IsProvided ("netapplet"))
	{
	    if (default_wm == "gnome")
	    {
		Service::Enable ("netdaemon");
	    }
	}
    }

    return `auto;
}
