summaryrefslogtreecommitdiffstats
path: root/perl-install/printer/main.pm
diff options
context:
space:
mode:
authorTill Kamppeter <tkamppeter@mandriva.com>2005-08-17 17:22:47 +0000
committerTill Kamppeter <tkamppeter@mandriva.com>2005-08-17 17:22:47 +0000
commitc48abb8d2652741431532fa3fe8901f1a6316933 (patch)
tree3ca6a75d930cca32c69f53d7cbca9e77f73d4a3a /perl-install/printer/main.pm
parentd30b53791fb5e20fe6cafebb5d0c51e4d2e961db (diff)
downloaddrakx-c48abb8d2652741431532fa3fe8901f1a6316933.tar
drakx-c48abb8d2652741431532fa3fe8901f1a6316933.tar.gz
drakx-c48abb8d2652741431532fa3fe8901f1a6316933.tar.bz2
drakx-c48abb8d2652741431532fa3fe8901f1a6316933.tar.xz
drakx-c48abb8d2652741431532fa3fe8901f1a6316933.zip
- Added automatic setup of Ethernet-connected HP printers with HPLIP.
- Taken into account that HPLIP sometimes uses model names with "HP" in the beginning and sometimes not. - Fixed problem of cursor in printer model list pointing to random, completely unrelated printer when no model name was auto-detected. - For setting the cursor onto the correct model in the printer model list also taken into account a model name detected only by HPLIP. - When one chooses "Printer Connection Type" in the "Edit" menu of an Ethernet-connected printer which is under the control of HPLIP or HPOJ, "LOCAL" was pre-selected as connection type and not "SOCKET". Fixed. - Replaced "Windows 95/98/NT" by simply "Windows" in the connection type menu. There are many more Windows versions than 95, 98, and NT currently. - Made matching of detected printer model name with HPLIP database more reliable.
Diffstat (limited to 'perl-install/printer/main.pm')
-rw-r--r--perl-install/printer/main.pm69
1 files changed, 51 insertions, 18 deletions
diff --git a/perl-install/printer/main.pm b/perl-install/printer/main.pm
index 808c8f6e5..ea9bbcb0e 100644
--- a/perl-install/printer/main.pm
+++ b/perl-install/printer/main.pm
@@ -29,7 +29,7 @@ our %printer_type = (
N("Printer on remote CUPS server") => "CUPS",
N("Printer on remote lpd server") => "LPD",
N("Network printer (TCP/Socket)") => "SOCKET",
- N("Printer on SMB/Windows 95/98/NT server") => "SMB",
+ N("Printer on SMB/Windows server") => "SMB",
N("Printer on NetWare server") => "NCP",
N("Enter a printer device URI") => "URI",
N("Pipe job into a command") => "POSTPIPE"
@@ -2472,6 +2472,8 @@ sub hplip_simple_model {
my ($model) = @_;
my $simplemodel = $model;
$simplemodel =~ s/[^A-Za-z0-9]//g;
+ $simplemodel =~ s/HewlettPackard/HP/gi;
+ $simplemodel =~ s/HP//gi;
$simplemodel =~ s/(DeskJet\d+C?)([a-z]*?)/$1/gi;
$simplemodel =~ s/((LaserJet|OfficeJet|PhotoSmart|PSC)\d+)([a-z]*?)/$1/gi;
$simplemodel =~ s/DeskJet/DJ/gi;
@@ -2486,8 +2488,8 @@ sub hplip_simple_model {
sub hplip_device_entry {
my ($device, @autodetected) = @_;
- # Currently, only devices on USB work
- return undef if $device !~ /usb/i;
+ # Currently, only devices on USB or TCP/Socket work
+ return undef if ($device !~ /usb/i) && ($device !~ m!^socket://!i);
if (!$hplipdevicesdb) {
# Read the HPLIP device database if not done already
@@ -2505,6 +2507,11 @@ sub hplip_device_entry {
# Exact match
return $entry;
}
+ my $hpmodelstr = "HP_" . $modelstr;
+ if ($entry = $hplipdevicesdb->{$hpmodelstr}) {
+ # Exact match
+ return $entry;
+ }
# More 'fuzzy' matching
my $simplemodel = hplip_simple_model($modelstr);
foreach my $key (keys %{$hplipdevicesdb}) {
@@ -2517,7 +2524,7 @@ sub hplip_device_entry {
$simplekey =~ s/(\d\d\d)0(C?)$/$1\\d$2/;
$simplekey =~ s/(\d\d)0(\dC?)$/$1\\d$2/;
return $hplipdevicesdb->{$key} if
- $simplemodel =~ m/^$simplekey$/;
+ $simplemodel =~ m/^$simplekey$/i;
}
# Device not supported
return undef;
@@ -2558,6 +2565,8 @@ sub start_hplip {
$device =~ m!/dev/lp! ||
$device =~ /printers/) {
$bus = "par";
+ } elsif ($device =~ m!^socket://!) {
+ $bus = "net";
} else {
return undef;
}
@@ -2566,26 +2575,50 @@ sub start_hplip {
printer::services::start_not_running_service("hplip");
# Determine HPLIP device URI for the CUPS queue
- foreach my $a (@autodetected) {
- $device eq $a->{port} or next;
+ if ($bus eq "net") {
+ $device =~ m!^socket://([^:]+)(|:\d+)$!;
+ my $host = $1;
+ my $ip;
+ if ($host !~ m!^\d+\.\d+\.\d+\.\d+$!) {
+ my $addr = gethostbyname("$host");
+ my ($a,$b,$c,$d) = unpack('C4',$addr);
+ $ip = sprintf("%d.%d.%d.%d", $a, $b, $c, $d);
+ } else {
+ $ip = $host;
+ }
open(my $F, ($::testing ? $::prefix : "chroot $::prefix/ ") .
- '/bin/sh -c "export LC_ALL=C; /usr/lib/cups/backend/hp" |') or
- die 'Could not run "/usr/lib/cups/backend/hp"!';
+ "/bin/sh -c \"export LC_ALL=C; /usr/bin/hp-makeuri $ip\" |") or
+ die "Could not run \"/usr/bin/hp-makeuri $ip\"!";
while (my $line = <$F>) {
- if (($line =~ m!^direct\s+(hp:/$bus/(\S+)\?serial=(\S+))\s+!) ||
- ($line =~ m!^direct\s+(hp:/$bus/(\S+))\s+!)) {
+ if ($line =~ m!(hp:/net/\S+)!) {
my $uri = $1;
- my $modelstr = $2;
- my $serial = $3;
- if ((uc($modelstr) eq uc($hplipentry->{model})) &&
- (!$serial ||
- (uc($serial) eq uc($a->{val}{SERIALNUMBER})))) {
- close $F;
- return $uri;
- }
+ close $F;
+ return $uri;
}
}
close $F;
+ } else {
+ foreach my $a (@autodetected) {
+ $device eq $a->{port} or next;
+ open(my $F, ($::testing ? $::prefix : "chroot $::prefix/ ") .
+ '/bin/sh -c "export LC_ALL=C; /usr/lib/cups/backend/hp" |') or
+ die 'Could not run "/usr/lib/cups/backend/hp"!';
+ while (my $line = <$F>) {
+ if (($line =~ m!^direct\s+(hp:/$bus/(\S+)\?serial=(\S+))\s+!) ||
+ ($line =~ m!^direct\s+(hp:/$bus/(\S+))\s+!)) {
+ my $uri = $1;
+ my $modelstr = $2;
+ my $serial = $3;
+ if ((uc($modelstr) eq uc($hplipentry->{model})) &&
+ (!$serial ||
+ (uc($serial) eq uc($a->{val}{SERIALNUMBER})))) {
+ close $F;
+ return $uri;
+ }
+ }
+ }
+ close $F;
+ }
last;
}
# HPLIP URI not found