App-USBKeyCopyCon

 view release on metacpan or  search on metacpan

lib/App/USBKeyCopyCon.pm  view on Meta::CPAN

        ? ($current_keys->{$_}->{pid} => $_)
        : ();
    } keys %$current_keys;

    my $done = 0;
    foreach my $pid (keys %$exit_status) {
        my $status = delete $exit_status->{$pid};
        my $udi = $pid_to_udi{$pid} or next;
        if($status == 0) {
            $self->update_key_progress($udi, 10);
        }
        else {
            $self->update_key_progress($udi, -1);
            my $key_info = $current_keys->{$udi};
            my $output = $key_info->{output};
            $output =~ s/^{\d+\/\d+}\n//mg;
            $self->say("Copy to $key_info->{dev} failed:\n$output\n\n");
        }
        $done++;
    }

    if($done) {
        foreach my $key_info (values %$current_keys) {
            if($key_info->{status} >= 0 and $key_info->{status}  < 10) {
                $done = 0;
                last;
            }
        }
        $self->play_sound_file if $done;
    }
    return TRUE;
}


sub set_temp_root {
    my($self, $new_temp) = @_;

    $self->clean_temp_dir;

    $self->temp_root($new_temp);
    my $temp_dir = "$new_temp/usb-copy.$$";

    my $path = "$temp_dir/master";
    $self->master_root($path);
    mkpath($path, { mode => 0700 }) if not -d $path;

    $path = "$temp_dir/mount";
    $self->mount_dir($path);
    mkpath($path, { mode => 0700 }) if not -d $path;

    return;
}


sub clean_temp_dir {
    my $self = shift;

    my $path = $self->master_root or return;
    $path =~ s{/master$}{};
    if(-d $path and $self->sudo_path and $self->current_state ne 'MASTER-WAIT') {
        my $command = $self->sudo_wrap("chown -R $< $path");
        system($command);
    }
    rmtree($path) if -d $path;
}


sub run {
    my $self = shift;

    # Arrange to catch exit status of child processes
    my $exit_status = $self->exit_status;
    $SIG{CHLD} = sub {
        my $pid;
        do {
            $pid = waitpid(-1, WNOHANG);
            $exit_status->{$pid} = $? if $pid > 0;
        } while $pid > 0;
    };
    Glib::Timeout->add(500, sub { $self->tick });

    Gtk2->main;

    $self->restore_automount;
    $self->clean_temp_dir;
}


1;

__END__

=head1 ATTRIBUTES

The application object has the following attributes (with correspondingly named
accessor methods):

=over 4

=item app_win

The main Gtk2::Window object.

=item automount_state

Stores the enabled state ('true' or 'false') of the GNOME/Nautilus media
automount option.  The function will be disabled on startup and this value will
be restored on exit.

=item capacity_combo

The Gtk2::ComboBox object for the device filter 'Capacity' drop-down menu.

=item capacity_entry

The Gtk2::Entry object for the device filter 'Capacity' text entry box.

=item console

The Gtk2::TextView object used for writing output messages.



( run in 0.744 second using v1.01-cache-2.11-cpan-92ad3014f07 )