package printerdrake;
# $Id$
use diagnostics;
use strict;
use common;
use detect_devices;
use modules;
use network;
use log;
use printer;
1;
sub choose_printer_type {
my ($printer, $in) = @_;
$in->set_help('configurePrinterConnected') if $::isInstall;
my $queue = $printer->{OLD_QUEUE};
$printer->{str_type} = $printer::printer_type_inv{$printer->{TYPE}};
my $autodetect = 0;
$autodetect = 1 if $printer->{AUTODETECT};
my @printertypes = printer::printer_type($printer);
$in->ask_from_(
{ title => N("Select Printer Connection"),
messages => N("How is the printer connected?") .
($printer->{SPOOLER} eq "cups" ?
N("
Printers on remote CUPS servers you do not have to configure here; these printers will be automatically detected.") : ())
},
[
{ val => \$printer->{str_type},
list => \@printertypes,
not_edit => 1, sort => 0,
type => 'list' },
{ text => N("Printer auto-detection (Local, TCP/Socket, and SMB printers)"),
type => 'bool', val => \$autodetect }
]
) or return 0;
if ($autodetect) {
$printer->{AUTODETECT} = 1;
} else {
undef $printer->{AUTODETECT};
}
$printer->{TYPE} = $printer::printer_type{$printer->{str_type}};
1;
}
sub config_cups {
my ($printer, $in, $upNetwork) = @_;
local $::isWizard = 0;
# Check whether the network functionality is configured and
# running
if (!check_network($printer, $in, $upNetwork, 0)) { return 0 };
$in->set_help('configureRemoteCUPSServer') if $::isInstall;
my $queue = $printer->{OLD_QUEUE};
#- hack to handle cups remote server printing,
#- first read /etc/cups/cupsd.conf for variable BrowsePoll address:port
my ($server, $port, $default, $autoconf);
# Return value: 0 when nothing was changed ("Apply" never pressed), 1
# when "Apply" was at least pressed once.
my $retvalue = 0;
# Read CUPS config file
my @cupsd_conf = printer::read_cupsd_conf();
foreach (@cupsd_conf) {
/^\s*BrowsePoll\s+(\S+)/ and $server = $1, last;
}
$server =~ /([^:]*):(.*)/ and ($server, $port) = ($1, $2);
#- Did we have automatic or manual configuration mode for CUPS
$autoconf = printer::get_cups_autoconf();
#- Remember the server/port/autoconf settings to check whether the user
#- has changed them.
my $oldserver = $server;
my $oldport = $port;
my $oldautoconf = $autoconf;
#- then ask user for this combination and rewrite /etc/cups/cupsd.conf
#- according to new settings. There are no other point where such
#- information is written in this file.
if ($in->ask_from_
({ title => ($::expert ? N("CUPS configuration") :
N("Specify CUPS server")),
messages => N("To get access to printers on remote CUPS servers in your local network you do not have to configure anything; the CUPS servers inform your machine automatically about their printers. All printers currently known to your machine are listed in the \"Remote printers\" section in the main window of Printerdrake. When your CUPS server is not in your local network, you have to enter the CUPS server IP address and optionally the port number to get the printer information from the server, otherwise leave these fields blank.") .
($::expert ? "\n" . N("
Normally, CUPS is automatically configured according to your network environment, so that you can access the printers on the CUPS servers in your local network. If this does not work correctly, turn off \"Automatic CUPS configuration\" and edit your file /etc/cups/cupsd.conf manually. Do not forget to restart CUPS afterwards (command: \"service cups restart\").") : ()),
callbacks => { complete => sub {
if ($server && !network::is_ip($server)) {
$in->ask_warn('', N("The IP address should look like 192.168.1.20"));
return (1,0);
}
if ($port !~ /^\d*$/) {
$in->ask_warn('', N("The port number should be an integer!"));
return (1,1);
}
return 0;
} }
},
[
{ label => N("CUPS server IP"), val => \$server },
{ label => N("Port"), val => \$port },
($::expert ?
{ text => N("Automatic CUPS configuration"), type => 'bool',
val => \$autoconf } : ()),
]
)) {
# We have clicked "OK"
$retvalue = 1;
# Set BrowsePoll line
if (($server ne $oldserver) || ($port ne $oldport)) {
$server && $port and $server = "$server:$port";
if ($server) {
@cupsd_conf =
map { $server and
s/^\s*BrowsePoll\s+(\S+)/BrowsePoll $server/ and
$server = '';
$_ } @cupsd_conf;
$server and push @cupsd_conf, "\nBrowsePoll $server\n";
} else {
@cupsd_conf =
map { s/^\s*BrowsePoll\s+(\S+)/\#BrowsePoll $1/;
$_ } @cupsd_conf;
}
printer::write_cupsd_conf(@cupsd_conf);
}
# Set auto-configuration state
if ($autoconf != $oldautoconf) {
printer::set_cups_autoconf($autoconf);
}
# Save user settings for auto-install
$printer->{BROWSEPOLLADDR} = $server;
$printer->{BROWSEPOLLPORT} = $port;
$printer->{MANUALCUPSCONFIG} = 1 - $autoconf;
}
return $retvalue;
}
sub setup_printer_connection {
my ($printer, $in, $upNetwork) = @_;
# Choose the appropriate connection config dialog
my $done = 1;
foreach ($printer->{TYPE}) {
/LOCAL/ and setup_local_autoscan ($printer, $in, $upNetwork)
and last;
/LPD/ and setup_lpd ($printer, $in, $upNetwork) and last;
/SOCKET/ and setup_socket ($printer, $in, $upNetwork) and last;
/SMB/ and setup_smb ($printer, $in, $upNetwork) and last;
|