summaryrefslogtreecommitdiffstats
path: root/perl-install/standalone/scannerdrake
blob: b3b4dd4024b771f0ef731d58df51ca3c29cf2c82 (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
#!/usr/bin/perl

# scannerdrake $Id$
# Yves Duret <yduret at mandrakesoft.com>
# Copyright (C) 2001 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;

$::isEmbedded = ($::XID, $::CCPID) = "@ARGV" =~ /--embedded (\w+) (\w+)/;
for (@ARGV) {
    /^--version$/ and die 'version: $Id$ '."\n";
    /^--help$/ and die 'logdrake [--version] [--help] [--manual] [--device=dev] [--update-sane=sane_desc_dir] [--update-usbtable] [--dynamic=dev]';
    /^--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(_("Test ports"), _("Detecting devices ..."));
@f = scanner::findScannerUsbport();
$wait=undef;
(@f) ? auto() : manual();
quit();

sub auto {
    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
	    $in->ask_yesorno('scannerdrake',_("%s found on %s, configure it ?",$name,$_->{port}),1) or manual();
	    tryConfScanner($name, $_->{port});
	}
    }
}

sub manual {
    my $s = $in->ask_from_treelist('scannerdrake', _("Select a scanner"), '|', [' None', keys %$scanner::scannerDB], '' ) or return;
    return if $s eq ' None';
    tryConfScanner($s);
}

sub dynamic {
    @f = scanner::findScannerUsbport();
    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
	    scanner::confScanner($name, $_->{port}) unless($scanner::scannerDB->{$model}{flags}{unsupported});
	}
    }
}

sub tryConfScanner {
    # take care if interactive ouptut is needed (unsupported, parallel..)
    my ($model, $port) = @_;
    if ($scanner::scannerDB->{$model}{flags}{unsupported}) {
	$in->ask_warn('scannerdrake', _("This %s scanner is unsupported", $model));
	return;
    }
    # if ($scanner::scannerDB->{$model}{driver} =~ /Parport/) {
    # 	$in->ask_warn('scannerdrake', _("This %s scanner uses parallel port, which is unsupported for the moment", $model));
    # 	return;
    #     }
    if ($scanner::scannerDB->{$model}{driver} =~ /SCSI/) {
     	#$in->ask_warn('scannerdrake', _("This %s scanner uses parallel port, which is unsupported for the moment", $model));
     	#return;
    }
    if ($scanner::scannerDB->{$model}{ask} =~ /DEVICE/) {
	$port='/dev/sg0';
	$in->ask_from('scannerdrake',
		      _("Scannerdrake was not able to detect your %s scanner.\nPlease select the device where your scanner is plugged", $model),
		      [
		       { label => _("choose device"), val => \$port, list => ['/dev/sg0', '/dev/sg1', '/dev/sg2', '/dev/sg3', '/dev/sg4' ], not_edit => 0, sort => 1},
		      ],
		     ) or manual();
    }

    if ($scanner::scannerDB->{$model}{server} =~ /printerdrake/) {
     	$in->ask_warn('scannerdrake', _("This %s scanner must be configured by printerdrake.\nYou can launch printerdrake from the Mandrake Control Center in Hardware section.", $model));
     	return;
    }
    scanner::confScanner($model,$port);
    $in->ask_warn(_("Congratulations!"),
		  _("Your %s scanner has been configured.\nYou may now scan documents using ``XSane'' from Multimedia/Graphics in the applications menu.", $model));
    
}

sub quit {
    $::isEmbedded ? kill(USR1, $::CCPID) : $in->exit(0);
}

#-----------------------------------------------
# $Log$
# Revision 1.11  2002/03/11 06:43:36  yduret
# re-re-re-re-re-re-uncomment the pkgs check line.
#
# Revision 1.10  2002/03/10 15:25:10  yduret
# added ASK DEVICE support
#
# Revision 1.9  2002/03/09 14:23:48  yduret
# added sum up at the end
#
# Revision 1.8  2002/03/09 00:58:36  yduret
# uncomment line that checks if sane rpm is installed or not (thx gc).
# i sux,
#
# Revision 1.7  2002/02/18 17:32:42  yduret
# HP OfficeJet support
#
# Revision 1.6  2002/02/18 16:12:07  yduret
# scsi/parport preliminary support
#
# Revision 1.5  2002/01/18 20:16:48  gc
# - move 'use standalone' up to comply to 'explanations'
# - fix a small english problem
#
# Revision 1.4  2001/11/19 17:39:03  pablo
# Corrected English errors
#
# Revision 1.3  2001/11/19 10:50:37  yduret
# added dynamic support
#
# Revision 1.2  2001/11/12 15:19:54  yduret
# update
#