~fnux/pisk

0d327b176453eb2775222f22ddb2c8d577a8e85f — Timothée Floure 2 years ago 58b55c1
Improve Swapspace support, allow to swapon/swapoff
1 files changed, 45 insertions(+), 4 deletions(-)

M disks.pl
M disks.pl => disks.pl +45 -4
@@ 187,19 187,41 @@ sub dbus_introspect {
}

sub mount_filesystem {
	my ($filesystem) = @_;
	my ($device) = @_;

	my $filesystem = $device->as_interface('org.freedesktop.UDisks2.Filesystem');
	my $mountpoint = $filesystem->Mount({});

	return $mountpoint;
}

sub unmount_filesystem {
	my ($filesystem) = @_;
	my ($device) = @_;

	my $filesystem = $device->as_interface('org.freedesktop.UDisks2.Filesystem');
	$filesystem->Unmount({});

	return;
}

sub active_swapspace {
	my ($device) = @_;

	my $swapspace = $device->as_interface('org.freedesktop.UDisks2.Swapspace');
	$swapspace->Start({});

	return;
}

sub disable_swapspace {
	my ($device) = @_;

	my $swapspace = $device->as_interface('org.freedesktop.UDisks2.Swapspace');
	$swapspace->Stop({});

	return;
}

### UI

sub define_curses_windows {


@@ 314,6 336,25 @@ sub handle_listbox_event {
			$dialog_content .= 'Partition Table: ' . $device->Type . "\n";
		}

		if (implements_udisks2_interface($device, 'Swapspace')) {
			my $swapspace = $device->as_interface('org.freedesktop.UDisks2.Swapspace');
			if ($swapspace->Active) {
				$dialog_content .= 'This swap space is active.';

				push @dialog_buttons,{
					-label => '< Swapoff >',
					-value => 'swapoff',
				}
			} else {
				$dialog_content .= 'This swap space is unused.';

				push @dialog_buttons,{
					-label => '< Swapon >',
					-value => 'swapon',
				}
			}
		}

		if (implements_udisks2_interface($device, 'Filesystem')) {
			$dialog_content .= 'Mountable filsystem: ' . $device->IdType . "\n";
			$dialog_content .= 'Mountpoints: ' . list_filesystem_mountpoints($device) . "\n";


@@ 322,14 363,12 @@ sub handle_listbox_event {
				push @dialog_buttons,{
					-label => '< Unmount >',
					-value => 'unmount',
					-shortcut => 1
				}
			}
			else {
				push @dialog_buttons,{
					-label => '< Mount >',
					-value => 'mount',
					-shortcut => 1
				}
			}
		}


@@ 367,6 406,8 @@ sub handle_listbox_event {
			unmount_filesystem($device);
			refresh_listbox_content($udisks2, $listbox_values, $listbox_labels);
		}
		when (/^swapon$/) { active_swapspace($device); }
		when (/^swapoff$/) { disable_swapspace($device); }
	}

	# Refresh focus and selection