/**
 * File:	modules/ProductFetures.ycp
 * Package:	installation
 * Summary:	Product features
 * Authors:	Anas Nashif <nashif@suse.de>
 *
 * $Id: ProductFeatures.ycp 21507 2005-02-10 16:01:58Z mvidner $
 */

{
    module "ProductFeatures";
    textdomain "base";

    import "Misc";
    import "Mode";
    import "Stage";

    map features = $[];

    /*********************************************************************
      *   Those are variables from the content file, we can override them
      *   in the control file
     *********************************************************************/

    /**
     * url of release notes (downloaded during internet test)
     */
    global string relnotesurl	= "";

    /**
     *  Run YOU during the Internet connection test.
     */
    global boolean run_you	= true;

    /**
     * list of flags from content file
     */
    global list flags		= [];


    /*********************************************************************
      *   Packages and Selections
     *********************************************************************/

    /**
     *  Control how the base selection is chosen:
     *    `fixed - the base selection is fixed (see fixed_base_selection below)
     *    `auto  - a base selection is automatically choosen (depending on disk
     *             space)
     */
    global symbol base_selection_choice		= `auto;

    /**
     *  Name of the fixed base selection.
     */
    global string fixed_base_selection		= "";

    /**
     * List of additional kernel dependent packages to add
     */
    global list<string> kernel_packages = [];

    /**
     * List of additional packages to add
     */
    global list<string> packages = [];

    /**
     *  If non-empty it will be called with WFM::CallFunction
     *	from Packages::ComputeSystemPackageList. Gets a list of packages
     *  as the one and only argument and must return a list of packages
     *  again.
     */
    global string packages_transmogrify		= "";


    /***
      * On some products, this can be turned on to prevent old
      * RPMs from being deleted (#35235)
      */
    global boolean delete_old_packages          = true;


    /**
     *  Should the software proposal inform about the fact that the user wants
     *  to install e.g. i386 on amd64.
     */
    global boolean inform_about_suboptimal_distribution = false;



    // Only an update, NOT an upgrade
    global boolean onlyUpdateInstalled = false;


    // How is the software proposal handled? What is it based on?
    // Possible values are: desktop|selection
    // Default is "selection"

    global string software_proposal = "selection";


    // Additional addon selections
    global list addon_selections = [];

    /*********************************************************************
      *   Partitioning
     *********************************************************************/

    /**
     * Flexible partitioning
     */
    global boolean flexible_partitioning = false;

    /**
     * EVMS config in YaST2
     */
    global boolean evms_config = false;

    /**
     * Flexible partitioning map
     */
    global map FlexiblePartitioning = $[];

    /*********************************************************************
      *   Network
      *
     *********************************************************************/

    /**
     * For OES, do not propose DHCP, #50524
     */
    global boolean force_static_ip = false;


    /*********************************************************************
      *   Misc. Features
      *
     *********************************************************************/


    /**
     * Warn about Incomplete Translations (#100197)
     */
    global string incomplete_translation_treshold = "95";

    /**
     * autologin is enabled by default.
     */
    global boolean enable_autologin = true;

    /**
     * Runlevel
     */
    global string runlevel = "";

    /**
     * Language
     */
    global string language = "";

    /**
     * Skip first Language if user has selected a langauge using
     * syslinux or selected the language using linuxrc.
     */
    global boolean skip_language_dialog = false;

    /**
     * Keyboard
     */
    global string keyboard = "";

    /**
     * Timezone
     */
    global string timezone = "";

    /**
     * Additional kernel parameters to be set by bootloader
     */
    global string additional_kernel_parameters = "";

    /**
     * Value of FAM_LOCAL_ONLY in /etc/sysconfig/fam
     * One of "kde", "gnome", "always", "never" (default)
     * Adds according to the default window manager
     * No need to save in the system
     */
    global string fam_local_only = "never";

    /**
     * UI mode
     * possible values: "simple" or "expert"
     */
    global string ui_mode = "expert";

    /**
     * True if firewall should be enabled by default during the installation
     * proposal
     * No need to save in the system
     */
    global boolean enable_firewall  = true;

    /**
     * True if SSH port should be open by default during the installation
     * proposal
     * No need to save in the system
     */
    global boolean firewall_enable_ssh = false;



    /**
     * Set a feature section
     */
    global void SetSection(string section_name, map section_map) {

        y2debug("Setting section: %1", section_name);
        features[section_name] = section_map;
        return;
    }

    /**
     * Get a complete section for evaluation
     */
    global map GetSection(string section_name) {
        return features[section_name]:$[];
    }


    /**
     * Get Feature properties
     * @param feature for example "globals/<feature name>"
     * @return any 
     */
    global any GetFeatureProperties(string feature) {
        list<string> p = [];
        if (issubstring(feature, "/")) {
            p = splitstring(feature, "/");
            return features[p[0]:"no", p[1]:"feature"]:nil;
        } else {
            return features[feature]:nil;
        }
    }


    /**
     * Check if a feature is enabled
     * 
     * Use for boolean properties
     * @example IsFeatureEnabled("globals/firewall_enable_ssh");
     */
    global boolean IsFeatureEnabled(string feature) {
        return (boolean)GetFeatureProperties(feature);
    }
    

    /**
     * Save product features
     */
    global void Save()
    {
        SCR::Write(.product.features.UI_MODE, 
                (string)GetFeatureProperties("globals/ui_mode") );

        SCR::Write(.product.features.ENABLE_AUTOLOGIN,
                (IsFeatureEnabled("globals/enable_autologin")) ? "yes" : "no" );
        
        SCR::Write(.product.features.EVMS_CONFIG,
                (IsFeatureEnabled("partitioning/evms_config")) ?  "yes" : "no" );

        SCR::Write(.product.features.INCOMPLETE_TRANSLATION_TRESHOLD,
                (string)GetFeatureProperties("globals/incomplete_translation_treshold"));
        
        SCR::Write (.product.features, nil );     // flush
        return;

    }


    void ReadBoolFeature(string sysconfig, string feature, string default )
    {
        path ps = .product.features;
        ps=add(ps, topath(sysconfig));

	any val = Misc::SysconfigRead( ps, default);
        list<string> p = [];
        string section = "";
        string key = "";
        if (issubstring(feature, "/")) {
            p = splitstring(feature, "/");
            section = p[0]:"";
            key = p[1]:"";
            if (!haskey(features, section))
                features[section]=$[];
            features[section, key] = (val == "yes");
        } else {
            key = feature;
            features[ key] = (val == "yes" );
        }
        return;
    }

    void ReadStrFeature(string sysconfig, string feature, string default )
    {
        path ps = .product.features;
        ps=add(ps, topath(sysconfig));

	any val = Misc::SysconfigRead( ps, default);
        list<string> p = [];
        string section = "";
        string key = "";
        if (issubstring(feature, "/")) {
            p = splitstring(feature, "/");
            section = p[0]:"";
            key = p[1]:"";
            if (!haskey(features, section))
                features[section]=$[];
            features[section, key] = val;
        } else {
            key = feature;
            features[ key] = val;
        }
        return;
    }

    /**
     * Restore product features in running system
     */
    global void Restore()
    {
        ReadStrFeature("UI_MODE", "globals/ui_mode", "expert");
        ReadBoolFeature("ENABLE_AUTOLOGIN", "globals/enable_autologin", "yes");
        ReadBoolFeature("EVMS_CONFIG", "partitioning/evms_config", "no");
        ReadStrFeature("INCOMPLETE_TRANSLATION_TRESHOLD",
                "globals/incomplete_translation_treshold", "95");

	ui_mode = Misc::SysconfigRead(
		.product.features.UI_MODE, "expert");
        
        enable_autologin = Misc::SysconfigRead(
                .product.features.ENABLE_AUTOLOGIN, "yes") == "yes";
        
        evms_config = Misc::SysconfigRead(
                .product.features.EVMS_CONFIG, "no") == "yes";

        incomplete_translation_treshold = Misc::SysconfigRead(
                .product.features.INCOMPLETE_TRANSLATION_TRESHOLD, "95");

        return;
    }


    // -----------------------------------------------
    /**
     * Constructor
     */
    global define void ProductFeatures () {

        if (Stage::normal () || Stage::firstboot())
        {
            Restore();
        }
        return;
    }

/* EOF */
}
