ACC SHELL

Path : /usr/share/YaST2/modules/
File Upload :
Current File : //usr/share/YaST2/modules/OnlineUpdateDialogs.ycp

/**
   Summary: YOU dialogs
   Authors: Cornelius Schumacher <cschum@suse.de>
*/

{
    module "OnlineUpdateDialogs";

    textdomain "online-update";

    import "Label";
    import "Mode";
    import "Package";
    import "Popup";
    import "Wizard";


    define any ErrorPopupGeneric( string message, string details,
				  symbol type )
	``{

	if ( size( details ) == 0 ) details = _("No details available.");

	string detailsStringOn = _("&Details <<");
	string detailsStringOff = _("&Details >>");

	term detailsButton = `PushButton( `id( `details ), detailsStringOff );

	string heading = _("Error");

	term buttons = nil;
	if ( type == `skip ) {
	    buttons = `HBox(
			    detailsButton,
			    `PushButton( `id( `tryagain ), _("Try again") ),
			    `PushButton( `id( `skip ), _("Skip Patch") ),
			    `PushButton( `id( `all ), _("Skip All") ),
			    `PushButton( `id( `abort ), _("Abort Update") )
			    );
	} else if ( type == `ignore ) {
	    buttons = `HBox(
			    detailsButton,
			    `PushButton( `id( `ok ), Label::IgnoreButton() ),
			    `PushButton( `id( `abort ), _("Abort Update") )
			    );
	} else if ( type == `ignorewarning ) {
	    heading = _("Warning");
	    buttons = `HBox(
			    detailsButton,
			    `PushButton( `id( `retry ), Label::RetryButton() ),
			    `PushButton( `id( `ok ), Label::IgnoreButton() ),
			    `PushButton( `id( `abort ), _("Abort Update") )
			    );
	} else {
	    buttons = `HBox(
			    detailsButton,
			    `PushButton( `id( `ok ), Label::OKButton() )
			    );
	}

	UI::OpenDialog( `opt( `decorated ),
			`VBox(
			      `HBox( `HSpacing( 0.5 ), `Left( `Heading( heading ) ) ),
			      `VSpacing( 0.2 ),
			      `Label( message ),
			      `ReplacePoint( `id( `rp ), `HBox(`HSpacing(0)) ),
			      buttons
			      )
			);

	any ret = nil;
	boolean showDetails = false;

	while( ret != `ok && ret != `tryagain && ret != `all &&
	       ret != `abort && ret != `skip && ret != `retry ) {
	    ret = UI::UserInput();

	    if ( ret == `details ) {
		if ( showDetails ) {
		    UI::ReplaceWidget( `id( `rp ), `VSpacing(0) );
		    UI::ChangeWidget( `id( `details ), `Label, detailsStringOff );
		} else {
		    UI::ReplaceWidget( `id( `rp ), `HBox( `HSpacing( 0.5 ),
							  `HWeight( 1, `RichText(`opt(`plainText), details ) ),
							  `HSpacing( 0.5 ) )
				       );
		    UI::ChangeWidget( `id( `details ), `Label, detailsStringOn );
		}
		showDetails = !showDetails;
	    }
	}

	UI::CloseDialog();

	if ( type != `plain ) {
	    return ret;
	} else {
	    if ( ret ==  `ok ) return true;
	    else return false;
	}
    }

    global define symbol IgnoreWarningPopup( string message, string details )
	``{
	return (symbol)ErrorPopupGeneric( message, details, `ignorewarning );
    }

    global define symbol IgnorePopup( string message, string details )
	``{
	return (symbol)ErrorPopupGeneric( message, details, `ignore );
    }

    global define symbol SkipPopup( string message, string details )
	``{
	return (symbol)ErrorPopupGeneric( message, details, `skip );
    }

    global define symbol ErrorPopup( string message, string details )
	``{
	return (symbol)ErrorPopupGeneric( message, details, `plain );
    }

    //  ConfirmAbortUpdate has same layout as/but different text than ConfirmAbort
    global define boolean ConfirmAbortUpdate( symbol how_to )
	``{
	string what_will_happen = "";

	if ( how_to == `painless )
	{
	    // Warning text for aborting the update before a patch is installed
	    what_will_happen = _("If you abort the installation now, no patch will be installed.
Your installation will remain untouched.
");
	}
	else if ( how_to == `incomplete )
	{
	    // Warning text for aborting if some patches are installed, some not
	    what_will_happen = _("Patch download and installation in progress.
If you abort the installation now, the update is incomplete.
Repeat the update, including the download, if desired.
");
	}
	else if ( how_to == `unusable )
	{
	    // Warning text for aborting an installation during the install process
	    what_will_happen = _("If you abort the installation now,
at least one patch is not installed correctly.
You will need to do the update again.");
	}
	else if ( how_to == `suseconfig )
	{
	    // Warning text for aborting an installation without running SuSEconfig
	    what_will_happen = _("If you abort the installation now, SuSEconfig will
not be run. The patches have been installed
correctly, but without running SuSEconfig
some of them might not work as expected.");
	}
	else
	{
	    y2warning("Unknown symbol for what will happen when aborting - please correct in calling module" );
	}

	UI::OpenDialog(
		       `opt(`decorated),
		       `HBox(
			     `HSpacing(1),
			     `VBox(
				   `VSpacing(0.2),
				   `HCenter(
					    `HSquash(
						     `VBox(
							   // Confirm user request to abort installation
							   `Left( `Label( _("Really abort YaST Online Update?") ) ),
							   `Left( `Label( what_will_happen ) )
							   )
						     )
					    ),
				   `HBox(
					 // Button that will really abort the installation
					 `PushButton(`id(`really_abort), _("&Abort Update") ),
					 `HStretch(),

					 // Button that will continue with the installation
					 `PushButton(`id(`continue), `opt(`default), _("&Continue Update") )
					 ),
				   `VSpacing(0.2)
				   ),
			     `HSpacing(1)
			     )
		       );

	any ret = UI::UserInput();
	UI::CloseDialog();

	return (ret == `really_abort);
    };

    global define boolean DisplayMsgYou( string message, string header, string yes_button, string no_button )
	``{
	UI::OpenDialog(
		       `opt(`decorated),
		       `HBox(
			     `HSpacing(1),
			     `VBox(
				   `Left(`Heading( header)),
				   `VSpacing(0.2),
				   `Label(message),
				   `HBox(`PushButton(`id(`yes), yes_button ),
					 `PushButton(`id(`no), `opt(`default), no_button )),
				   `VSpacing(0.2)
				   ),
			     `HSpacing(1)
			     )
		       );
	any ret = UI::UserInput();
	UI::CloseDialog();
	return (ret == `yes);
    };


    global define boolean DisplayMsgYouOk( string message, string header, string ok_button )
	``{
	UI::OpenDialog(
		       `opt(`decorated),
		       `HBox(
			     `HSpacing(1),
			     `VBox(
				   `Left(`Heading( header)),
				   `VSpacing(0.2),
				   `Label(message),
				   `HBox(`PushButton(`id(`ok), `opt(`default), ok_button )),
				   `VSpacing(0.2)
				   ),
			     `HSpacing(1)
			     )
		       );
	any ret = UI::UserInput();
	UI::CloseDialog();
	return (ret == `ok);
    };

    global define boolean MessagePopup( list<map> patches, boolean pre )
	``{
	string message = "";
	string details = "";

	integer i = 0;
	while ( i < size( patches ) ) {

	    map patch = patches[ i ]:$[];

	    string name = patch[ "name" ]:"";
	    string summary = patch[ "summary" ]:"";

	    string info = "";
	    if ( pre ) info = patch[ "preinformation" ]:"";
	    else info = patch[ "postinformation" ]:"";

	    string header = sformat( _("<b>Patch:</b> %1<br>"), name );
	    header = header + sformat( _("<b>Summary:</b> %1<br>"), summary );

	    message = message + header;
	    message = message + "<pre>" + info + "</pre>";
	    
	    list<string> packages = patch[ "packages" ]:[];

	    if( size( packages ) > 0 )
	    {
		details = details + header;

		details = details + _("<b>Packages:</b>");

		details = details + "<ul>";

		foreach( string p, packages, ``{ details = details + "<li>" + p + "</li>"; } );

		details = details + "</ul>";
	    }
	    
	    i = i + 1;
	}

	string detailsStringOn = _("Patch &Details <<");
	string detailsStringOff = _("Patch &Details >>");

	term detailsButton = `PushButton( `id( `details ), detailsStringOff );

	term detailsTerm = 
	    `HBox( `HSpacing( 0.5 ),
		   `HWeight( 1, `RichText( `opt(`plainText), details ) ),
		   `HSpacing( 0.5 )
		   );
       
	term buttons = nil;
	if ( pre ) {
	    buttons = `HBox(
			    details == "" ? `VSpacing(0) : detailsButton,
			    `PushButton( `id( `ok ), _("Install Patch") ),
			    `PushButton( `id( `skip ), _("Skip Patch") )
			    );
	} else {
	    buttons = `HBox(
			    details == "" ? `VSpacing(0) : detailsButton,
			    `PushButton( `id( `ok ), Label::OKButton() )
			    );
	}

	integer w = 20;
	integer h = 5;
      
	if ( size( message ) > 100 ) {
	    w = 60;
	    h = 15;
	}

	y2milestone( "Going to open the message dialog" );

	UI::OpenDialog( `opt( `decorated ),
			`VBox(
			      `HSpacing( w ),
			      `VSpacing( 0.2 ),
			      `HBox(
				    `VSpacing( h ),
				    `RichText( message )
				    ),
			      `ReplacePoint( `id( `rp ), `VSpacing(0) ),
			      buttons
			      )
			);

	y2milestone( "Dialog opened");

	symbol ret = nil;
	boolean showDetails = false;

	while( ret != `ok && ret != `skip ) {
	    ret = (symbol)UI::UserInput();

	    if ( ret == `details ) {
		if ( showDetails ) {
		    UI::ReplaceWidget( `id( `rp ), `HSpacing(0) );
		    UI::ChangeWidget( `id( `details ), `Label, detailsStringOff );
		} else {
		    UI::ReplaceWidget( `id( `rp ), `HBox( `HSpacing( 0.5 ),
							  `HWeight( 1, `RichText( details ) ),
							  `HSpacing( 0.5 ) )
				       );
		    UI::ChangeWidget( `id( `details ), `Label, detailsStringOn );
		}
		showDetails = !showDetails;
	    }
	}

	UI::CloseDialog();

	if ( ret ==  `ok ) return true;
	else return false;
    }

}

ACC SHELL 2018