ACC SHELL

Path : /usr/share/YaST2/include/partitioning/
File Upload :
Current File : //usr/share/YaST2/include/partitioning/ep-settings.ycp

/**
 * File:	ep-settings.ycp
 * Package:	yast2-storage
 * Summary:	Expert Partitioner
 * Authors:	Arvin Schnell <aschnell@suse.de>
 *
 * This file must only be included in other Expert Partitioner files ("ep-*.ycp").
 */
{
    textdomain "storage";


    void DestroySettingsPanel(any user_data);


    list< map<symbol, any> > visible_fields = [
	// list entry
	$[ `label : _("Label"), `fields : [ `label ] ],
	// list entry
	$[ `label : _("UUID"), `fields : [ `uuid ] ],
	// list entry
	$[ `label : _("Mount by"), `fields : [ `mount_by ] ],
	// list entry
	$[ `label : _("Used by"), `fields : [ `used_by ] ],
	// list entry
	$[ `label : _("BIOS ID"), `fields : [ `bios_id ] ],
	// list entry
	$[ `label : _("Cylinder information"), `fields : toset([ `start_cyl, `end_cyl, `num_cyl, `cyl_size ]) ],
	// list entry
	$[ `label : _("Fibre Channel information"), `fields : toset([ `fc_wwpn, `fc_fcp_lun, `fc_port_id ]) ],
	// list entry
	$[ `label : _("Encryption"), `fields : [ `encrypted ] ]
    ];

    map<symbol, string> mount_bys = $[
	// combo box entry
	`device : _("Device Name"),
	// combo box entry
	`label : _("Volume Label"),
	// combo box entry
	`uuid : _("UUID"),
	// combo box entry
	`id : _("Device ID"),
	// combo box entry
	`path : _("Device Path")
    ];


    void CreateSettingsPanel(any user_data)
    {
	list <term> PreselectVisibleFields()
	{
	    list<symbol> hidden_fields = StorageSettings::GetHiddenFields();
	    return maplist(integer i, Integer::Range(size(visible_fields)), {
		string label = visible_fields[i, `label]:"";
		list<symbol> fields = visible_fields[i, `fields]:[];
		boolean selected = !multiset::includes(hidden_fields, fields);
		return `item(`id(i), label, selected);
	    });
	}

	list <term> mount_by_items = maplist( symbol item_id, string label, mount_bys, {
	    return `item(`id(item_id), label);
	});

	list<symbol> filesystems = filter(symbol fs, [ `ext2, `ext3, `ext4, `reiser, `xfs ], {
		return FileSystems::IsSupported(fs) && !FileSystems::IsUnsupported(fs);
	});

	list<term> filesystem_items = maplist(symbol fs, filesystems, {
	    return `item(`id(fs), FileSystems::GetName(fs, "Error"));
	});

	list<term> partalign_items = maplist(symbol pal, [ `align_optimal, `align_cylinder ], {
	    return `item(`id(pal), substring( sformat( "%1", pal ), 7 ));
	});


	UI::ReplaceWidget(`tree_panel,
			  Greasemonkey::Transform(
			      `VBox(
				  // dialog heading
				  `IconAndHeading(_("Settings"), StorageIcons::settings_icon),
				  `VBox(
				      `Left(`ComboBoxSelected(`id(`default_mountby),`opt(`notify),
							      // combo box label
							      _("Default Mount by"),
							      mount_by_items,
							      `id(Storage::GetDefaultMountBy()))),
				      `Left(`ComboBoxSelected(`id(`default_fs),`opt(`notify),
							      // combo box label
							      _("Default File System"),
							      filesystem_items,
							      `id(Partitions::DefaultFs()))),
				      `Left(`ComboBoxSelected(`id(`part_align),`opt(`notify),
							      // combo box label
							      _("Alignment of Newly Created Partitions"),
							      partalign_items,
							      `id(Storage::GetPartitionAlignment()))),
				      `VSpacing(1),
				      `Left(`ComboBoxSelected(`id(`display_name), `opt(`notify),
							      // combo box label
							      _("Show Storage Devices by"),
							      [
								  // combo box entry
								  `item(`id(`device), _("Device Name")),
								  // combo box entry
								  `item(`id(`id), _("Device ID")),
								  // combo box entry
								  `item(`id(`path), _("Device Path"))
							      ],
							      `id(StorageSettings::GetDisplayName()))),
				      //This looks extremely ugly, but obviously there are few other means how
				      //to make MultiSelection widget smaller, yet still readable
				      `Left(`HBox(
						`MultiSelectionBox(`id(`visible_fields), `opt(`shrinkable, `notify),
								   // multi selection box label
							           _("Visible Information On Storage Devices"),
								   PreselectVisibleFields()),
				                `HStretch()
						))
				      ),
				  `VStretch()
				  )));


	// helptext
	string helptext = _("<p>This view shows general storage
settings:</p>");

	// helptext
	helptext = helptext + _("<p><b>Default Mount by</b> gives the mount by
method for newly created file systems.</p>");

	// helptext
	helptext = helptext + _("<p><b>Default File System</b> gives the file
system type for newly created file file systems.</p>");

	// helptext
	helptext = helptext + _("<p><b>Show Storage Devices by</b> controls
the name displayed for hard disks in the navigation tree.</p>");

	// helptext
	helptext = helptext + _("<p><b>Visible Information On Storage
Devices</b> allows to hide information in the tables and overview.</p>");

	Wizard::RestoreHelp(helptext);
    }


    void HandleSettingsPanel(any user_data, map event)
    {
	switch (Event::IsWidgetValueChanged(event))
	{
	    case `display_name:
		StorageSettings::SetDisplayName((symbol) UI::QueryWidget(`id(`display_name), `Value));
		UpdateNavigationTree(nil);
		break;
	}

	switch (Event::IsWidgetActivated(event))
	{
	    case `next:
		DestroySettingsPanel(user_data);
		break;
	}

	if (!StorageSettings::GetModified())
	{
	    StorageSettings::SetModified();
	    Wizard::SetNextButton(`next, Label::NextButton());
	}
    }


    void DestroySettingsPanel(any user_data)
    {
        list<integer> selected = (list<integer>) UI::QueryWidget(`id(`visible_fields), `SelectedItems);
	list<string> selected_labels = [];

	foreach(integer i, selected, {
	    selected_labels= add(selected_labels, visible_fields[i, `label]:"");
	});

	symbol default_mount = (symbol) UI::QueryWidget(`id(`default_mountby), `Value);
	symbol default_fs = (symbol) UI::QueryWidget(`id(`default_fs), `Value);
	symbol part_align = (symbol) UI::QueryWidget(`id(`part_align), `Value);

	Storage::SetDefaultMountBy( default_mount );
	Partitions::SetDefaultFs( default_fs );
	Storage::SetPartitionAlignment( part_align );
	StorageSettings::InvertVisibleFields(visible_fields, selected);
    }
}

ACC SHELL 2018