ACC SHELL

Path : /usr/share/YaST2/clients/
File Upload :
Current File : //usr/share/YaST2/clients/inst_complex_welcome.ycp

/**
 * File:
 *	inst_complex_welcome.ycp
 *
 * Module:
 *	Installation
 *
 * Authors:
 *	Klaus   Kämpf <kkaempf@suse.de>
 *	Michael Hager <mike@suse.de>
 *	Stefan  Hundhammer <sh@suse.de>
 *	Thomas Roelz <tom@suse.de>
 *	Jiri Suchomel <jsuchome@suse.cz>
 *	Lukas Ocilka <locilka@suse.cz>
 *
 * Summary:
 *	This client shows main dialog for choosing the language,
 *	keyboard and accepting the license.
 *
 * Attention:
 *	This is still work in progress ...
 *
 * $Id: inst_complex_welcome.ycp 60766 2010-02-09 13:58:04Z locilka $
 *
 */
{
    textdomain "installation";

    import "Console";
    import "GetInstArgs";
    import "Keyboard";
    import "Label";
    import "Language";
    import "Mode";
    import "Popup";
    import "ProductFeatures";
    import "Report";
    import "Stage";
    import "Timezone";
    import "Wizard";
    import "Icon";
    import "InstData";
    import "ProductLicense";

    // ------------------------------------- main part of the client -----------

    map argmap = GetInstArgs::argmap();

    string language = Language::language;

    // language preselected in /etc/install.inf
    string preselected = Language::preselected;

    boolean text_mode	= Language::GetTextMode ();

    integer license_id = Pkg::SourceGetCurrent(true)[0]:0;
    string license_ui_id  = tostring (license_id);

   /* ----------------------------------------------------------------------
    * Build dialog
    * ----------------------------------------------------------------------*/
    // heading text
    string heading_text = _("Welcome");

    term languagesel = `ComboBox (
	`id (`language),
	`opt (`notify, `hstretch),
	// combo box label
	_("&Language"), Language::GetLanguageItems (`first_screen)
    );

    term keyboardsel = `ComboBox (
	`id (`keyboard),
	`opt (`notify, `hstretch),
	// combo box label
	_("&Keyboard Layout"),
	Keyboard::GetKeyboardItems ()
    );

    // BNC #448598
    // License sometimes doesn't need to be manually accepted
    term license_agreement_checkbox = `Left (`CheckBox (
	// bnc #359456
	// TRANSLATORS: check-box
	`id (`license_agreement), `opt (`notify), _("I &Agree to the License Terms."), InstData::product_license_accepted
    ));

    // this type of contents will be shown only for initial installation dialog
    term contents = `VBox (
	`VWeight (1, `VStretch()),
	`Left(`HSquash (`VBox (
	    `HBox (
		`HSquash (Icon::Simple ("yast-language")),
		(text_mode == true ? `Empty() : `HSpacing (2)),
		`Left (languagesel)
	    ),
	    `VSpacing (1),
	    `HBox (
		`HSquash (Icon::Simple ("yast-keyboard")),
		(text_mode == true ? `Empty() : `HSpacing (2)),
		`Left (keyboardsel)
	    ),
	    `VSpacing (1)
	))),
	`VWeight (1, `VStretch()),
	`VWeight (20, `Left (`HSquash (
	    `VBox (
		`Left (`Label (`opt(`boldFont), _("License Agreement"))),
		// bnc #438100
		`HSquash(`MinWidth (
		    85,
		    `Left (`ReplacePoint (`id (`base_license_rp), `Empty()))
		)),
		`VSpacing (text_mode ? 0.1 : 0.5),
		`MinHeight (1, `HBox (
		    // Will be replaced with license checkbox if required
		    `ReplacePoint (`id (`license_checkbox_rp), `Empty()),
		    `VSpacing (1),
		    // TRANSLATORS: button label
		    // ID: #ICW_B1 button
		    `Right (`PushButton (`id (`show_fulscreen_license), _("License &Translations...")))
		))
	    )
	))),
	`VWeight (1, `VStretch())
    );

    term AllLicensesDialog () {
	// As long as possible
	// bnc #385257
	return `HBox (
	    `VSpacing (text_mode ? 21 : 25),
	    `VBox (
		`Left (`HBox (
		    Icon::Simple ("yast-license"),
		    // TRANSLATORS: dialog caption
		    `Heading (_("License Agreement"))
		)),
		`VSpacing (text_mode ? 0.1 : 0.5),
		`HSpacing (82),
		`HBox (
		    `VStretch (),
		    `ReplacePoint (`id (`full_screen_license_rp), `opt (`vstretch), `Empty())
		),
		`ButtonBox (
		    `PushButton (`id (`close), `opt (`okButton, `default, `key_F10), Label::OKButton())
		)
	    )
	);
    }

    // help text for initial (first time) language screen
    string help_text = _("<p>
Choose the <b>Language</b> and the <b>Keyboard layout</b> to be used during
installation and for the installed system.
</p>
") +

    // help text, continued
    // Describes the #ICW_B1 button
    _("<p>
License has to be accepted before continuing the installation.
Use <b>License Translations...</b> to show the license in all available translations.
</p>") +

    // help text, continued
    _("<p>
Click <b>Next</b> to proceed to the next dialog.
</p>
") +

    // help text, continued
    _("<p>
Nothing will happen to your computer until you confirm
all your settings in the last installation dialog.
</p>
") +

    // help text, continued
    _("<p>
Select <b>Abort</b> to abort the
installation process at any time.
</p>
");

    // Screen title for the first interactive dialog

    Wizard::SetContents (heading_text, contents, help_text,
	argmap["enable_back"]:true , argmap["enable_next"]:true);
    Wizard::EnableAbortButton ();

    UI::ChangeWidget (`id (`language), `Value, language);

    if (Keyboard::user_decision == true) {
	UI::ChangeWidget (`id (`keyboard), `Value, Keyboard::current_kbd);
    } else {
	string kbd = Keyboard::GetKeyboardForLanguage (language, "english-us");
	UI::ChangeWidget (`id (`keyboard), `Value, kbd);
    }

    Wizard::SetTitleIcon ("suse");

    // Get the user input.
    //
    any ret = nil;

    UI::SetFocus(`id(`language));

    string keyboard = "";
    boolean license_acc = nil;

    boolean LicenseAccepted () {
	if (license_acc == true) {
	    return true;
	} else {
	    UI::SetFocus (`id (`license_agreement));
	    Report::Message (_("License needs to be accepted"));
	    return false;
	}    
    }


    void ReadCurrentUIState () {
	language = (string) UI::QueryWidget (`id (`language), `Value);
	keyboard = (string) UI::QueryWidget (`id (`keyboard), `Value);

	if (ProductLicense::AcceptanceNeeded (license_ui_id)) {
	    license_acc = (boolean) UI::QueryWidget (`id (`license_agreement), `Value);
	} else {
	    license_acc = true;
	}
    }

    // Returns true if the dialog needs redrawing
    boolean SetLanguageIfChanged (any ret) {

	if (language != Language::language) {
	    y2milestone ("Language changed from %1 to %2", Language::language, language);
	    Timezone::ResetZonemap ();

	    // Set it in the Language module.
	    Language::Set (language);
	}
	// Check and set CJK languages
	if (Stage::initial () || Stage::firstboot ()) {
	    if (ret == `language && Language::SwitchToEnglishIfNeeded (true))
	    {
		y2debug ("UI switched to en_US");
	    }
	    else if (ret == `language)
	    {
		Console::SelectFont (language);
		// no yast translation for nn_NO, use nb_NO as a backup
		if (language == "nn_NO")
		{
		    y2milestone ("Nynorsk not translated, using Bokmål");
		    Language::WfmSetGivenLanguage ("nb_NO");
		}
		else
		    Language::WfmSetLanguage ();
	    }
	}

	if (ret == `language) {
	    // Display newly translated dialog.
	    Wizard::SetFocusToNextButton();
	    return true;
	}

	if (ret == `next) {
	    Keyboard::Set (keyboard);

	    // Language has been set already.
	    // On first run store users decision as default.
	    y2milestone("Resetting to default language");
	    Language::SetDefault();

	    Timezone::SetTimezoneForLanguage (language);

	    if (!Stage::initial () && !Mode::update ()) {
		// save settings (rest is saved in LanguageWrite)
		Keyboard::Save ();
		Timezone::Save ();
	    }

	    // Bugzilla #354133
	    y2milestone ("Adjusting package and text locale to %1", language);
	    Pkg::SetPackageLocale (language);
	    Pkg::SetTextLocale (language);

	    y2milestone ("Language: '%1', system encoding '%2'", language, WFM::GetEncoding());
	}

	return false;
    }

    ProductLicense::ShowLicenseInInstallation (`base_license_rp, license_id);

    // bugzilla #206706
    if (Mode::autoinst()) {
	return `auto;
    }

    // If accepting the license is required, show the check-box
    y2milestone ("Acceptance needed: %1 => %2", license_ui_id, ProductLicense::AcceptanceNeeded (license_ui_id));
    if (ProductLicense::AcceptanceNeeded (license_ui_id)) {
	UI::ReplaceWidget (`license_checkbox_rp, license_agreement_checkbox);
    }

    while (true) {
	ret = UI::UserInput();
	y2milestone ("UserInput() returned %1", ret);

	if (ret == `back) {
	    break;

	} else if (ret == `abort && Popup::ConfirmAbort (`painless)) {
	    Wizard::RestoreNextButton();
	    ret = `abort;
	    break;

	} else if (ret == `keyboard) {
	    Keyboard::user_decision = true;

	} else if (ret == `license_agreement) {
	    InstData::product_license_accepted = (boolean) UI::QueryWidget (`id (`license_agreement), `Value);

	} else if (ret == `next || (ret == `language && ! Mode::config ())) {
	    ReadCurrentUIState();

	    if (ret == `next ) {
		// BNC #448598
		// Check whether the license has been accepted only if required
		if (ProductLicense::AcceptanceNeeded (license_ui_id) && ! LicenseAccepted ())
		    continue;

		if (!Language::CheckIncompleteTranslation (language))
		    continue;

		if (Stage::initial())
		    Language::CheckLanguagesSupport (language);
	    }

	    if (SetLanguageIfChanged (ret)) {
		ret = `again;
		break;
	    }

	    if (ret == `next) break;
	} else if (ret == `show_fulscreen_license) {
	    UI::OpenDialog (AllLicensesDialog());
	    ProductLicense::ShowFullScreenLicenseInInstallation (`full_screen_license_rp, license_id);
	    UI::CloseDialog();
	}
    }

    return (symbol) ret;
}

ACC SHELL 2018