1. SolusOS
  2. Untitled project
  3. installer

Source

installer / src / pages / disks / disks.vala

using Gtk;
using Installer.Widgets;

namespace Installer {

public class DisksPage : InstallerPage {

   private Gtk.VBox display;
   private string title;
   private string short_title;
   private bool already_init = false;

   private List<Device> devices;
   private SegmentedBar currentDisk;
   private DiskChooser disk_chooser;

   // Somewhere to display partitioning schemes
   private Gtk.VBox schemes;

   static construct {

	message ("DisksPage init");
   }

   static ~DisksPage() {
	message ("DisksPage destroyed");
   }

   private Installer.Widgets.Color random_color ( ) {
	double red = Random.double_range (0.0, 1.0);
	double green = Random.double_range (0.0, 1.0);
	double blue = Random.double_range (0.0, 1.0);

	return new Installer.Widgets.Color (red, green, blue);
   }

   private void set_bar_from_disk (Disk disk) {
	currentDisk.remove_all ();
	currentDisk.disk_size = 0;
	foreach (Partition part in disk.partitions) {
		if ( ! part.active ) continue;
		currentDisk.add_segment (part.path, part.size, random_color () );
	}
   }

   /** Init this page instance */
   public override void init_page () {

	GETTEXT_INIT ();

	short_title = _("Disks");
	title = _("Please select where you wish to install %s").printf (Config["Branding"]["Name"]);

	// We are init'd anytime a show happens
	if (already_init) {
		// Stuff to do before showing
		if (devices == null) {
			devices = DeviceManager.get_all_devices ();
			if (devices.length () >= 1) {
				set_bar_from_disk (devices.nth_data(0).disk);
				foreach (unowned Device d in devices) {
					//Disk d = devices.nth_data(0).disk;
					disk_chooser.add_disk (d.disk);
				}
			}
		}
		navigate_update (NavigationState.ENABLE, NavigationDirection.FORWARD);
		return;
	} else {
		already_init = true;
	}

	display = new Gtk.VBox (false, 10);
	disk_chooser = new DiskChooser ();
	disk_chooser.disk_selected.connect ( (d) => { set_bar_from_disk (d); } );
	display.pack_start (disk_chooser, false, false, 10);

	currentDisk = new SegmentedBar ();

	display.pack_start (currentDisk, false, false, 10);

	// So we can actually display available partitioning schemes
	schemes = new Gtk.VBox (false, 10);
	display.pack_start (schemes, true, true, 0);

	navigate_update (NavigationState.ENABLE, NavigationDirection.FORWARD);
   }

   public override string get_title () { return title; }

   public override string get_short_title () { return short_title; }

   public override Gtk.Widget get_display () { return display; }

   public override string get_section () { return _("Preparation"); }

   /** We are a standard Data Collection page */
   public override PageType get_page_type () { return PageType.DATA; }
}

[ModuleInit]
Type module_init (GLib.TypeModule type_module) {
	message ("Attempt creation of module");
	return typeof (DisksPage);
}

} // End namespace