ACC SHELL

Path : /usr/share/YaST2/include/autoinstall/
File Upload :
Current File : //usr/share/YaST2/include/autoinstall/VolgroupDialog.ycp

/**
 * File:
 *	VolgroupDialog.ycp
 *
 * Module:
 *	Partitioning
 *
 * Summary:
 *	Display and handle volume group dialog.
 *
 * Authors:
 *	Sven Schober (sschober@suse.de)
 *
 * $Id: VolgroupDialog.ycp 2812 2008-06-05 12:49:30Z sschober $
 */
{
  textdomain "autoinst";

  include "autoinstall/common.ycp";
  include "autoinstall/types.ycp";

  import "AutoinstPartPlan";
  import "AutoinstDrive";

  /**
   * INTERNAL STUFF
   */

  /* local copy of current device the user wants to
   * edit using this dialog
   */
  define DriveT currentVolgroup = $[];
  define integer currentVolgroupIdx = 999;

  define list<string> volgroupTypes = [ "LVM" ];
  define string volgroupTypePrefix = "CT_";

  define string volgroupPrefix = "/dev/";
  define string newVolgroupName = "NewVg";

  define string volgroupDialogTitle = _("Edit Volume Group");

  /**
   * SYNCING GUI <-> DATA
   */

  define symbol VolgroupAddTypePrefix( symbol s ){
    return string2symbol( addPrefix( symbol2string( s ), volgroupTypePrefix));
  }
  define symbol VolgroupRemoveTypePrefix( symbol s ){
    return string2symbol( removePrefix( symbol2string( s ), volgroupTypePrefix));
  }
  define void VolgroupUpdateGUI( string d ){
    UI::ChangeWidget( `id(`vgDevice), `Value, removePrefix(
			    currentVolgroup["device"]:"<not-set>", volgroupPrefix)) ;
//    symbol vgType = VolgroupRemoveTypePrefix( currentVolgroup["type"]:`CT_LVM );
//    UI::ChangeWidget( `id(`vgType), `Value, vgType);
  }

  define DriveT VolgroupUpdateData( DriveT vg ){
      /* TODO: device name constraints */
      vg = AutoinstDrive::set(vg, "device", addPrefix( (string)UI::QueryWidget(`id(`vgDevice), `Value),
						      volgroupPrefix ));
 //     symbol vgType = VolgroupAddTypePrefix( (symbol)UI::QueryWidget(`id(`vgType), `Value) );
//      vg = AutoinstDrive::set(vg, "type", vgType );
      return vg;
  }

  /**
   * GENERAL DIALOG IFACE
   */
  define DriveT VolgroupLoad( integer drive ){
    DriveT vg = AutoinstPartPlan::getDrive( drive );
    y2milestone("loaded drive('%1'): '%2'", drive, vg );
    return vg;
  }

  define void VolgroupStore(){
    currentVolgroup = VolgroupUpdateData( currentVolgroup );
    AutoinstPartPlan::updateDrive( currentVolgroup );
    y2milestone("updated drive('%1'): '%2'", currentVolgroup["device"]:"", currentVolgroup );
  }

  define void VolgroupCheck(){
    currentVolgroup = VolgroupUpdateData( currentVolgroup );
    DriveT storedVolgroup = AutoinstPartPlan::getDrive( currentVolgroupIdx );
    if( ! AutoinstDrive::areEqual( currentVolgroup, storedVolgroup ) ){
      if( Popup::YesNo( _("Store unsaved changes to volume group?") ) ){
	AutoinstPartPlan::updateDrive( currentVolgroup );
      }
    }
    y2milestone("updated drive('%1'): '%2'", currentVolgroup["device"]:"", currentVolgroup );
  }

  define void VolgroupDisplay(){
    string drive = stack[`which]:"";
    y2milestone( "VolgroupDisplay('%1')", drive );
    currentVolgroupIdx = tointeger( drive );
    currentVolgroup = VolgroupLoad( currentVolgroupIdx );

    term contents =
      `VBox(
	  `Heading( volgroupDialogTitle),
	  `HVCenter(
	    `HVSquash(
	      `VBox(
		`TextEntry(`id(`vgDevice),_("Volgroup device name")),
		//`ComboBox( `id(`vgType), _("Type"), toItemList(volgroupTypes)),
		`VSpacing(2),
		`PushButton( `id(`apply),_("Apply"))
	      )))
	  );
    UI::ReplaceWidget(`id(replacement_point), contents );
    VolgroupUpdateGUI( drive );
  }

  define void VolgroupEventHandler(){
    y2milestone( "VolgroupEventHandler(): current event: '%1'", currentEvent);
  }

  define void VolgroupDelete(){
    string drive = stack[`which]:"";
    y2milestone("VolgroupDelete('%1')", drive );
    AutoinstPartPlan::removeDrive( tointeger( drive ) );
  }

  define void VolgroupNew(){
    string defaultDevice = volgroupPrefix + newVolgroupName;
    DriveT newDrive = AutoinstPartPlan::addDrive(AutoinstDrive::new(defaultDevice, `CT_LVM));
    selectTreeItem(AutoinstDrive::getNodeReference(newDrive));
    stack[`which] = tostring(newDrive["_id"]:999);
    VolgroupDisplay();
  }

  /**
   * INITIALIZE DIALOG
   */
  string volgroupType = "volgroup";
  DialogT volgroupDialog = $[
    `type	  :	    volgroupType,
    `display	  :	    ``(VolgroupDisplay()),
    `eventHandler :	    ``(VolgroupEventHandler()),
    `store	  :	    ``(VolgroupStore()),
    `new	  :	    ``(VolgroupNew()),
    `delete	  :	    ``(VolgroupDelete()),
    `check	  :	    ``(VolgroupCheck())
      ];
  y2milestone("adding volgroup dialog to dialog list.");
  addDialog(volgroupType, volgroupDialog);
}


ACC SHELL 2018