diff options
author | Till Kamppeter <tkamppeter@mandriva.com> | 2003-02-12 18:42:36 +0000 |
---|---|---|
committer | Till Kamppeter <tkamppeter@mandriva.com> | 2003-02-12 18:42:36 +0000 |
commit | e291b2dcb1ff3e8b37364e020afac3c76c251721 (patch) | |
tree | cce9ac069345b52388d0c60238594b697860bd94 /perl-install/scanner.pm | |
parent | 9aa6a9ea2d92709c2fc9174984d48f75c375436b (diff) | |
download | drakx-e291b2dcb1ff3e8b37364e020afac3c76c251721.tar drakx-e291b2dcb1ff3e8b37364e020afac3c76c251721.tar.gz drakx-e291b2dcb1ff3e8b37364e020afac3c76c251721.tar.bz2 drakx-e291b2dcb1ff3e8b37364e020afac3c76c251721.tar.xz drakx-e291b2dcb1ff3e8b37364e020afac3c76c251721.zip |
Scannerdrake vastly improved
- Use auto-detection methods of SANE
- Do not ask the user to configure scanners which are already configured
- Handle systems with more than one scanner correctly
- Added ports of newer scanners (libusb, parallel, ...) to the port selector
in manual setup
- Main dialog showing all configured scanners
- Full support for scanner sharing via SANE (server/client)
- Support for USB scanner access via libusb
Diffstat (limited to 'perl-install/scanner.pm')
-rwxr-xr-x | perl-install/scanner.pm | 153 |
1 files changed, 129 insertions, 24 deletions
diff --git a/perl-install/scanner.pm b/perl-install/scanner.pm index 3fe56b01f..6a5dbdacb 100755 --- a/perl-install/scanner.pm +++ b/perl-install/scanner.pm @@ -32,7 +32,7 @@ use handle_configs; my $_sanedir = "$::prefix/etc/sane.d"; my $_scannerDBdir = "$::prefix$ENV{SHARE_PATH}/ldetect-lst"; -my $scannerDB = readScannerDB("$_scannerDBdir/ScannerDB"); +$scannerDB = readScannerDB("$_scannerDBdir/ScannerDB"); sub confScanner { my ($model, $port) = @_; @@ -54,34 +54,139 @@ sub add2dll { output("$_sanedir/dll.conf", @dllconf); } +sub configured { + my @res = (); + # Run "scanimage -L", to find the scanners which are already working + open LIST, "LC_ALL=C scanimage -L |"; + while (my $line = <LIST>) { + if ($line =~ /^\s*device\s*\`([^\`\']+)\'\s+is\s+a\s+(\S.*)$/) { + # Extract port and description + my $port = $1; + my $description = $2; + # Remove duplicate scanners appearing through saned and the + # "net" backend + next if $port =~ /^net:(localhost|127.0.0.1):/; + # Store collected data + push @res, { + port => $port, + val => { + DESCRIPTION => $description, + } + }; + } + } + close LIST; + return @res; +} + sub detect { - my ($i, @res) = 0; - foreach (grep { $_->{driver} =~ /scanner/ } detect_devices::usb_probe()) { - use Data::Dumper; - print Dumper($_); - #my ($manufacturer, $model) = split '\|', $_->{description}; - #$_->{description} =~ s/Hewlett[-\s_]Packard/HP/; - $_->{description} =~ s/Seiko\s+Epson/Epson/i; - push @res, { port => "/dev/usb/scanner$i", val => { CLASS => 'SCANNER', - MODEL => $model, - MANUFACTURER => $manufacturer, - DESCRIPTION => $_->{description}, - id => $_->{id}, - vendor => $_->{vendor}, - } }; - ++$i; + my @configured = @_; + my @res = (); + # Run "sane-find-scanner", this also detects USB scanners which only + # work with libusb. + open DETECT, "LC_ALL=C sane-find-scanner -q |"; + while (my $line = <DETECT>) { + my $vendorid = undef; + my $productid = undef; + my $make = undef; + my $model = undef; + my $description = undef; + my $port = undef; + if ($line =~ /^\s*found\s+USB\s+scanner/i) { + # Found an USB scanner + if ($line =~ /vendor=(0x[0-9a-f]+)[^0-9a-f\[]+[^\[]*\[([^\[\]]+)\].*prod(|uct)=(0x[0-9a-f]+)[^0-9a-f\[]+[^\[]*\[([^\[\]]+)\]/) { + # Scanner connected via libusb + $vendorid = $1; + $make = $2; + $productid = $4; + $model = $5; + $description = "$make|$model"; + } elsif ($line =~ /vendor=(0x[0-9a-f]+)[^0-9a-f]+.*prod(|uct)=(0x[0-9a-f]+)[^0-9a-f]+/) { + # Scanner connected via scanner.o kernel module + $vendorid = $1; + $productid = $3; + } + if ($vendorid and $productid) { + # We have vendor and product ID, look up the scanner in + # the usbtable + foreach $entry (cat_("$_scannerDBdir/usbtable")) { + if ($entry =~ + /^\s*$vendorid\s+$productid\s+.*\"([^\"]+)\"\s*$/) { + $description = $1; + $description =~ s/Seiko\s+Epson/Epson/i; + if ($description =~ /^([^\|]+)\|(.*)$/) { + $make = $1; + $model = $2; + } + last; + } + } + } + } elsif ($line =~ /^\s*found\s+SCSI/i) { + # SCSI scanner + if ($line =~ /\"([^\"\s]+)\s+([^\"]+?)\s+([^\"\s]+)\"/) { + $make = $1; + $model = $2; + $description = "$make|$model"; + } + } else { + # Comment line in output of "sane-find-scanner" + next; + } + # Extract port + $line =~ /\s+(\S+)\s*$/; + $port = $1; + # Check for duplicate (scanner.o/libusb) + if ($port =~ /^libusb/) { + my $duplicate = 0; + foreach (@res) { + if (($_->{val}{vendor} eq $vendorid) && + ($_->{val}{id} eq $productid) && + ($_->{port} =~ /dev.*usb.*scanner/) && + (!defined($_->{port2}))) { + # Duplicate entry found, merge the entries + $_->{port2} = $port; + $_->{val}{MANUFACTURER} ||= $make; + $_->{val}{MODEL} ||= $model; + $_->{val}{DESCRIPTION} ||= $description; + $duplicate = 1; + last; + } + } + next if $duplicate; + } + # Store collected data + push @res, { + port => $port, + val => { + CLASS => 'SCANNER', + MODEL => $model, + MANUFACTURER => $make, + DESCRIPTION => $description, + id => $productid, + vendor => $vendorid, + } + }; } - foreach (grep { $_->{media_type} =~ /scanner/ } detect_devices::getSCSI()) { - $_->{info} =~ s/Seiko\s+Epson/Epson/i; - push @res, { port => "/dev/sg", - val => { DESCRIPTION => $_->{info} }, - }; - ++$i; + close DETECT; + if (@configured) { + # Remove scanners which are already working + foreach my $d (@res) { + my $searchport1 = handle_configs::searchstr($d->{port}); + my $searchport2 = handle_configs::searchstr($d->{port2}); + foreach my $c (@configured) { + if (($c->{port} =~ /$searchport1$/) || + ($c->{port} =~ /$searchport2$/)) { + $d->{configured} = 1; + last; + } + } + } + @res = map { $_->{configured} ? () : $_; } @res; } - @res; + return @res; } - sub readScannerDB { my ($file) = @_; my ($card, %cards); |