From a7759e59f17339920553a03e31230dbc20c68d1c Mon Sep 17 00:00:00 2001 From: Till Kamppeter Date: Fri, 14 Feb 2003 23:48:59 +0000 Subject: Improved manual scanner configuration, bug fixes. --- perl-install/scanner.pm | 44 ++++++- perl-install/standalone/scannerdrake | 218 +++++++++++++++++++++-------------- 2 files changed, 175 insertions(+), 87 deletions(-) (limited to 'perl-install') diff --git a/perl-install/scanner.pm b/perl-install/scanner.pm index b0a6fef1e..30a033d93 100755 --- a/perl-install/scanner.pm +++ b/perl-install/scanner.pm @@ -204,6 +204,40 @@ sub detect { return @res; } +sub get_usb_ids_for_port { + my ($port) = @_; + my $vendorid; + my $productid; + if ($port =~ /^\s*libusb:(\d+):(\d+)\s*$/) { + # Use "lsusb" to find the USB IDs + open DETECT, "LC_ALL=C lsusb -s $1:$2 |"; + while (my $line = ) { + if ($line =~ /ID\s+([0-9a-f]+):(0x[0-9a-f]+)($|\s+)/) { + # Scanner connected via scanner.o kernel module + $vendorid = "0x$1"; + $productid = "0x$2"; + last; + } + } + close DETECT; + } else { + # Run "sane-find-scanner" on the port + open DETECT, "LC_ALL=C sane-find-scanner -q $port |"; + while (my $line = ) { + if ($line =~ /^\s*found\s+USB\s+scanner/i) { + if ($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; + last; + } + } + } + close DETECT; + } + return ($vendorid, $productid); +} + sub readScannerDB { my ($file) = @_; my ($card, %cards); @@ -306,7 +340,13 @@ sub updateScannerDBfromSane { } } - foreach my $f (glob_("$_sanesrcdir/*.desc")) { + my @descfiles; + push (@descfiles, + glob_("$_sanesrcdir/doc/descriptions/*.desc")); + push (@descfiles, + glob_("$_sanesrcdir/doc/descriptions-external/*.desc")); + + foreach my $f (@descfiles) { my $F = common::openFileMaybeCompressed($f); $to_add .= "\n# from $f"; my ($lineno, $cmd, $val) = 0; @@ -321,7 +361,7 @@ sub updateScannerDBfromSane { if (0 && member($name, keys %$scanner::scannerDB)) { print "#[$name] already in ScannerDB!\n"; } else { - # SANE bug "snapscan" calls itself "SnapScan" + # SANE bug: "snapscan" calls itself "SnapScan" $backend =~ s/SnapScan/snapscan/g; $to_add .= "\nNAME $name\nSERVER $backend\nDRIVER $intf\n"; # Go through the configuration lines of diff --git a/perl-install/standalone/scannerdrake b/perl-install/standalone/scannerdrake index 99b045148..2901644c0 100755 --- a/perl-install/standalone/scannerdrake +++ b/perl-install/standalone/scannerdrake @@ -74,8 +74,6 @@ sub removeverticalbar { } sub auto { - #use Data::Dumper; - #print Dumper (@f); my $changed = 0; foreach (@f) { if (member($_->{val}{DESCRIPTION}, keys %$scanner::scannerDB)) { @@ -86,26 +84,153 @@ sub auto { next; } if ($in->ask_yesorno('Scannerdrake',N("%s found on %s, configure it automatically?",removeverticalbar($name),$_->{port}),1)) { - $changed ||= (tryConfScanner($name, $_->{port}) or - manual()); + $changed ||= (tryConfScanner($name, $_->{port}, + $_->{val}{vendor}, + $_->{val}{id}) or + manual($_->{port}, $_->{val}{vendor}, + $_->{val}{id}, $name)); } else { - $changed ||= manual(); + $changed ||= manual($_->{port}, $_->{val}{vendor}, + $_->{val}{id}, $name); } } else { - $in->ask_yesorno('Scannerdrake',N("%s is not in the scanner database, configure it manually?", removeverticalbar($_->{val}{DESCRIPTION})),1) and manual(); + $in->ask_yesorno('Scannerdrake', + N("%s is not in the scanner database, configure it manually?", + removeverticalbar($_->{val}{DESCRIPTION})),1) + and ($changed ||= + manual($_->{port}, $_->{val}{vendor}, $_->{val}{id}, + $_->{val}{DESCRIPTION})); } } return $changed; } sub manual { - my $s = $in->ask_from_treelist('Scannerdrake', N("Select a scanner"), '|', [' None', keys %$scanner::scannerDB], '') or return 0; + my ($port, $vendor, $product, $name) = @_; + my $s = + $in->ask_from_treelist('Scannerdrake', + N("Select a scanner model") . + if_($port || $name, N(" (")) . + if_($name, N("Detected model: %s", + removeverticalbar($name))) . + if_($port && $name, N(", ")) . + if_($port, N("Port: %s", $port)) . + if_($port || $name, N(")")), + '|', [' None', keys %$scanner::scannerDB], + '') or return 0; return 0 if $s eq ' None'; if ($scanner::scannerDB->{$s}{flags}{unsupported}) { $in->ask_warn('Scannerdrake', N("The %s is not supported by this version of Mandrake Linux.", removeverticalbar($s))); return 0; } - return tryConfScanner($s); + return tryConfScanner($s, $port, $vendor, $product); +} + +sub dynamic { + @f = scanner::detect(); + foreach (@f) { + if (member($_->{val}{DESCRIPTION}, keys %$scanner::scannerDB)) { + my $name = $_->{val}{DESCRIPTION}; + $name =~ s/\s$//; #some HP entry have a trailing space, i will correct usbtable asap + if ($scanner::scannerDB->{$name}{flags}{unsupported}) { + $in->ask_warn('Scannerdrake', N("The %s is not supported by this version of Mandrake Linux.", removeverticalbar($name))); + next; + } + scanner::confScanner($name, $_->{port}, + $_->{val}{vendor}, $_->{val}{id}); + } else { + $in->ask_warn('Scannerdrake', N("The %s is not known by this version of Scannerdrake.", removeverticalbar($name))); + } + } +} + +sub tryConfScanner { + # take care if interactive output is needed (unsupported, parallel..) + my ($model, $port, $vendor, $product) = @_; + if ($scanner::scannerDB->{$model}{flags}{unsupported}) { + $in->ask_warn('Scannerdrake', N("The %s is unsupported", + removeverticalbar($model))); + return 0; + } + if (($scanner::scannerDB->{$model}{ask} =~ /DEVICE/) || (!$port)){ + $port ||= N("Auto-detect available ports"); + $in->ask_from('Scannerdrake', + N("Please select the device where your %s is attached", removeverticalbar($model)) . " " . + N("(Note: Parallel ports cannot be auto-detected)"), + [ + { label => N("choose device"), + val => \$port, + list => [N("Auto-detect available ports"), + '/dev/scanner', + '/dev/usb/scanner0', + '/dev/usb/scanner1', + '/dev/usb/scanner2', + 'libusb:001:001', + 'libusb:001:002', + 'libusb:001:003', + 'libusb:001:004', + 'libusb:001:005', + 'libusb:001:006', + 'libusb:001:007', + 'libusb:001:008', + 'libusb:001:009', + 'libusb:001:010', + '/dev/sg0', + '/dev/sg1', + '/dev/sg2', + '/dev/sg3', + '/dev/sg4', + '/dev/parport0', + '/dev/parport1', + '/dev/parport2', + '/dev/pt_drv', + '/dev/ttyS0', + '/dev/ttyS1', + '/dev/ttyS2'], + not_edit => 0, sort => 0 }, + ], + ) or return 0; + if ($port eq N("Auto-detect available ports")) { + $wait = $in->wait_message(N("Scannerdrake"), + N("Searching for scanners ...")); + my @d = scanner::detect(); + undef $wait; + my @list = map { + $_->{port} . " (" . + removeverticalbar($_->{val}{DESCRIPTION}) . ")"; + } @d; + $port ||= $list[0]; + $in->ask_from('Scannerdrake', + N("Please select the device where your %s is attached", removeverticalbar($model)), + [ + { label => N("choose device"), + val => \$port, + list => \@list, + not_edit => 1, sort => 0 }, + ], + ) or return 0; + $port =~ s/^\s*([^\(\s]*)\s*\(.*$/$1/; + foreach (@d) { + next if $_->{port} ne $port; + $vendor = $_->{val}{vendor}; + $product = $_->{val}{id}; + last; + } + } + } + ($vendor, $product) = scanner::get_usb_ids_for_port($port); + if ($scanner::scannerDB->{$model}{server} =~ /(printerdrake|hpoj)/i) { + $in->ask_warn('Scannerdrake', N("The %s must be configured by printerdrake.\nYou can launch printerdrake from the Mandrake Control Center in Hardware section.", removeverticalbar($model))); + return 0; + } + scanner::confScanner($model, $port, $vendor, $product); + $in->ask_warn(N("Congratulations!"), + N("Your %s has been configured.\nYou may now scan documents using \"XSane\" from Multimedia/Graphics in the applications menu.", removeverticalbar($model))); + return 1; +} + +sub quit { + $::isEmbedded ? kill('USR1', $::CCPID) : $in->exit(0); } sub mainwindow { @@ -210,83 +335,6 @@ sub mainwindow { } } -sub dynamic { - @f = scanner::detect(); - foreach (@f) { - if (member($_->{val}{DESCRIPTION}, keys %$scanner::scannerDB)) { - my $name = $_->{val}{DESCRIPTION}; - $name =~ s/\s$//; #some HP entry have a trailing space, i will correct usbtable asap - if ($scanner::scannerDB->{$name}{flags}{unsupported}) { - $in->ask_warn('Scannerdrake', N("The %s is not supported by this version of Mandrake Linux.", removeverticalbar($name))); - next; - } - scanner::confScanner($name, $_->{port}, - $_->{val}{vendor}, $_->{val}{id}); - } else { - $in->ask_warn('Scannerdrake', N("The %s is not known by this version of Scannerdrake.", removeverticalbar($name))); - } - } -} - -sub tryConfScanner { - # take care if interactive output is needed (unsupported, parallel..) - my ($model, $port) = @_; - if ($scanner::scannerDB->{$model}{flags}{unsupported}) { - $in->ask_warn('Scannerdrake', N("The %s is unsupported", - removeverticalbar($model))); - return 0; - } - if (($scanner::scannerDB->{$model}{ask} =~ /DEVICE/) || (!$port)){ - $port = '/dev/usb/scanner0'; - $in->ask_from('Scannerdrake', - N("Please select the device where your %s is attached", removeverticalbar($model)), - [ - { label => N("choose device"), - val => \$port, - list => ['/dev/scanner', - '/dev/usb/scanner0', - '/dev/usb/scanner1', - '/dev/usb/scanner2', - 'libusb:001:001', - 'libusb:001:002', - 'libusb:001:003', - 'libusb:001:004', - 'libusb:001:005', - 'libusb:001:006', - 'libusb:001:007', - 'libusb:001:008', - 'libusb:001:009', - 'libusb:001:010', - '/dev/sg0', - '/dev/sg1', - '/dev/sg2', - '/dev/sg3', - '/dev/sg4', - '/dev/parport0', - '/dev/parport1', - '/dev/parport2', - '/dev/pt_drv', - '/dev/ttyS0', - '/dev/ttyS1', - '/dev/ttyS2'], - not_edit => 0, sort => 0 }, - ], - ) or return 0; - } - if ($scanner::scannerDB->{$model}{server} =~ /(printerdrake|hpoj)/i) { - $in->ask_warn('Scannerdrake', N("The %s must be configured by printerdrake.\nYou can launch printerdrake from the Mandrake Control Center in Hardware section.", removeverticalbar($model))); - return 0; - } - scanner::confScanner($model,$port); - $in->ask_warn(N("Congratulations!"), - N("Your %s has been configured.\nYou may now scan documents using \"XSane\" from Multimedia/Graphics in the applications menu.", removeverticalbar($model))); - return 1; -} - -sub quit { - $::isEmbedded ? kill('USR1', $::CCPID) : $in->exit(0); -} - sub makeexportmenues { my @exports = @_; my %menuexports = map { -- cgit v1.2.1