ACC SHELL

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

/**
 * File:	ep-raid.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";

    include "partitioning/ep-raid-dialogs.ycp";
    include "partitioning/ep-raid-lib.ycp";


    void EpContextMenuRaid(string device)
    {
	symbol widget = ContextMenu::Simple([ `item(`id(`edit), _("Edit")),
					      `item(`id(`resize), _("Resize")),
					      `item(`id(`delete), _("Delete")) ]);

	switch (widget)
	{
	    case `edit:
		EpEditRaid(device);
		break;

	    case `resize:
		EpResizeRaid(device);
		break;

	    case `delete:
		EpDeleteRaid(device);
		break;
	}
    }

    term RaidButtonBox()
    {
	return `HBox(
	// push button text
	    `PushButton(`id(`edit), `opt(`key_F4), _("Edit...")),
	    // push button text
	    `PushButton(`id(`resize), `opt(`key_F6), _("Resize...")),
	    // push button text
	    `PushButton(`id(`delete), `opt(`key_F5), _("Delete..."))
	);
    }

    void HandleRaidButtons( string device, map event )
    {

	switch (Event::IsWidgetActivated(event))
	{
	    case `add:
		EpCreateRaid();
		break;
	    case `edit:
		EpEditRaid(device);
		break;

	    case `resize:
		EpResizeRaid(device);
		break;

	    case `delete:
		EpDeleteRaid(device);
		break;
	}

    }

    void CreateRaidMainPanel(any user_data)
    {
	symbol Predicate(map disk, map partition)
	{
	    return StorageFields::PredicateDiskType(disk, partition, [`CT_MD]);
	}

	list<symbol> fields = StorageSettings::FilterTable([ `device, `size, `format, `encrypted, `type,
							     `fs_type, `label, `mount_point, `mount_by,
							     `used_by, `raid_type, `chunk_size ]);

	map<string, map> target_map = Storage::GetTargetMap();

	term table_header = StorageFields::TableHeader(fields);
	list<term> table_contents = StorageFields::TableContents(fields, target_map, Predicate);

	UI::ReplaceWidget(`tree_panel,
			  Greasemonkey::Transform(
			      `VBox(
				  `HStretch(),
				  // heading
				  `IconAndHeading(_("RAID"), StorageIcons::raid_icon),
				  `Table(`id(`table), `opt(`keepSorting, `notify, `notifyContextMenu),
					 table_header, table_contents),
				  `HBox(
				      // push button text
				      `PushButton(`id(`add), `opt(`key_F3), _("Add RAID...")),
				       RaidButtonBox(),
				      `HStretch()
				      )
				  )
			      )
	    );

	// helptext
	string helptext = _("<p>This view shows all RAIDs except of BIOS RAIDs.</p>");

	Wizard::RestoreHelp(helptext + StorageFields::TableHelptext(fields));
    }


    void HandleRaidMainPanel(any user_data, map event)
    {
	string device = (string) UI::QueryWidget(`id(`table), `CurrentItem);

	HandleRaidButtons(device, event);

	switch (Event::IsWidgetContextMenuActivated(event))
	{
	    case `table:
		EpContextMenuDevice(device);
		break;
	}

	UI::SetFocus(`id(`table));
    }


    void CreateRaidOverviewTab(any user_data)
    {
	string part_device = (string) user_data;

	map<string, map> target_map = Storage::GetTargetMap();

	list<symbol> fields = StorageSettings::FilterOverview([ `heading_device, `device, `size, `encrypted, `udev_id,
								`used_by, `heading_md, `raid_type, `chunk_size,
								`parity_algorithm, `heading_filesystem,
								`fs_type, `mount_point, `mount_by, `uuid,
								`label ]);

	UI::ReplaceWidget(`tab_panel,
			  `VBox(
			      `HStretch(),
			      StorageFields::Overview(fields, target_map, part_device),
			      `Left( RaidButtonBox() )
			      )
	    );

	// helptext
	string helptext = _("<p>This view shows detailed information about the
selected RAID.</p>");

	Wizard::RestoreHelp(helptext + StorageFields::OverviewHelptext(fields));
    }


    void HandleRaidOverviewTab(any user_data, map event)
    {

        HandleRaidButtons( (string) user_data, event);

	UI::SetFocus(`id(`text));
    }


    void CreateRaidDevicesTab(any user_data)
    {
	string part_device = (string) user_data;

	symbol Predicate(map disk, map partition)
	{
	    return StorageFields::PredicateUsedByDevice(disk, partition, [ part_device ]);
	}

	list<symbol> fields = StorageSettings::FilterTable([ `device, `udev_path, `udev_id, `size,
							     `format, `encrypted, `type, `used_by ]);

	map<string, map> target_map = Storage::GetTargetMap();

	term table_header = StorageFields::TableHeader(fields);
	list<term> table_contents = StorageFields::TableContents(fields, target_map, Predicate);

	UI::ReplaceWidget(`tab_panel,
			  `VBox(
			      `Table(`id(`table), `opt(`keepSorting, `notify),
				     table_header, table_contents)
			      )
	    );

	// helptext
	string helptext = _("<p>This view shows all devices used by the
selected RAID.</p>");

	Wizard::RestoreHelp(helptext + StorageFields::TableHelptext(fields));
    }


    void CreateRaidPanel(any user_data)
    {
	string device = (string) user_data;

	map<symbol, map> data = $[ `overview : $[ `create : CreateRaidOverviewTab, `handle : HandleRaidOverviewTab, `user_data : user_data ],
				   `devices : $[ `create : CreateRaidDevicesTab, `user_data : user_data ] ];

	UI::ReplaceWidget(`tree_panel,
			  Greasemonkey::Transform(
			      `VBox(
				  // heading
				  `IconAndHeading(sformat(_("RAID: %1"), device), StorageIcons::raid_icon),
				  `DumbTab(`id(`tab), [
					       // push button text
					       `item(`id(`overview), _("&Overview")),
					       // push button text
					       `item(`id(`devices), _("&Used Devices"))
					       ],
					   `ReplacePoint(`id(`tab_panel), TabPanel::empty_panel)
				      )
				  )
			      )
	    );

	TabPanel::Init(data, `overview);
    }


    void HandleRaidPanel(any user_data, map event)
    {
	TabPanel::Handle(event);
    }
}

ACC SHELL 2018