summaryrefslogtreecommitdiffstats
path: root/perl-install/standalone/scannerdrake
blob: bf77172572db215081f4886f76701a18c0447d37 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
#!/usr/bin/perl

# scannerdrake $Id$
# Yves Duret <yduret at mandrakesoft.com>
# Copyright (C) 2001-2002 MandrakeSoft
# 
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2, or (at your option)
# any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.

use lib qw(/usr/lib/libDrakX);

use standalone;     #- warning, standalone must be loaded very first, for 'explanations'

use interactive;
use common;
use scanner;

foreach (@ARGV) {
    /^--update-usbtable$/ and do { scanner::updateScannerDBfromUsbtable(); exit };
    /^--update-sane=(.*)$/ and do { scanner::updateScannerDBfromSane($1); exit };
    /^--manual$/ and $::Manual=1;
    /^--dynamic=(.*)$/ and do { dynamic($1); exit };
}

$in = 'interactive'->vnew('su', 'default');
$in->do_pkgs->install('sane-backends', 'xsane', if_($in->do_pkgs->is_installed('gimp'),'xsane-gimp'));
if ($::Manual) { manual(); quit() }
my $wait = $in->wait_message(N("Test ports"), N("Detecting devices ..."));
@f = scanner::detect();
$wait = undef;
(@f) ? auto() : manual();
quit();

sub removeverticalbar {
    my ($s) = @_;
    $s =~ s/\|/ /g;
    return $s; 
}

sub auto {
    #use Data::Dumper;
    #print Dumper (@f);
    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;
	    }
	    if ($in->ask_yesorno('scannerdrake',N("%s found on %s, configure it automatically?",removeverticalbar($name),$_->{port}),1)) {
		tryConfScanner($name, $_->{port}) or manual();
	    } else {
		manual();
	    }
	} else {
	    $in->ask_yesorno('scannerdrake',N("%s is not in the scanner database, configure it manually?", removeverticalbar($_->{val}{DESCRIPTION})),1) and manual();
	}
    }
}

sub manual {
    my $s = $in->ask_from_treelist('scannerdrake', N("Select a scanner"), '|', [' None', keys %$scanner::scannerDB], '') or return;
    return 1 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 1;
    }
    return tryConfScanner($s);
}

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});
	} 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 = '/dev/usb/scanner0';
	$in->ask_from('scannerdrake',
		      N("Scannerdrake was not able to detect your %s.\nPlease select the device where your scanner 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'], 
			 not_edit => 0, sort => 1 },
		       ],
		      ) or manual();
    }
    if ($scanner::scannerDB->{$model}{server} =~ /(printerdrake|hpoj)/) {
     	$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);
}