package printer::printerdrake;
# $Id$
use strict;
use common;
use modules;
use network::network;
use log;
use interactive;
use printer::main;
use printer::services;
use printer::detect;
use printer::default;
use printer::data;
my $companyname = "Mandrakesoft";
my $distroname = "Mandrakelinux";
my $shortdistroname = "Mandrakelinux";
my $domainname = "mandrakesoft.com";
my $hp1000fwtext = N("The HP LaserJet 1000 needs its firmware to be uploaded after being turned on. Download the Windows driver package from the HP web site (the firmware on the printer's CD does not work) and extract the firmware file from it by uncompresing the self-extracting '.exe' file with the 'unzip' utility and searching for the 'sihp1000.img' file. Copy this file into the '/etc/printer' directory. There it will be found by the automatic uploader script and uploaded whenever the printer is connected and turned on.
");
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;
#- hack to handle cups remote server printing,
#- first read /etc/cups/cupsd.conf for variable BrowsePoll address:port
# 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
@{$printer->{cupsconfig}{cupsd_conf}} =
printer::main::read_cupsd_conf();
printer::main::read_cups_config($printer);
# Read state of japanese text printing mode
my $jap_textmode = printer::main::get_jap_textmode();
# Read state for auto-correction of cupsd.conf
$printer->{cupsconfig}{autocorrection} =
printer::main::get_cups_autoconf();
my $oldautocorr = $printer->{cupsconfig}{autocorrection};
# Human-readable strings for hosts onto which the local printers
# are shared
my $maindone;
while (!$maindone) {
my $sharehosts = printer::main::makesharehostlist($printer);
my $browsepoll = printer::main::makebrowsepolllist($printer);
my $buttonclicked;
#- Show dialog
if ($in->ask_from(
{
title => N("CUPS printer configuration"),
messages => N("Here you can choose whether the printers connected to this machine should be accessible by remote machines and by which remote machines.") .
N("You can also decide here whether printers on remote machines should be automatically made available on this machine."),
},
[
{ text => N("The printers on this machine are available to other computers"), type => 'bool',
val => \$printer->{cupsconfig}{localprintersshared} },
{ text => N("Automatically find available printers on remote machines"), type => 'bool',
val => \$printer->{cupsconfig}{remotebroadcastsaccepted} },
{ val => N("Printer sharing on hosts/networks: ") .
($printer->{cupsconfig}{customsharingsetup} ?
N("Custom configuration") :
($#{$sharehosts->{list}} >= 0 ?
($#{$sharehosts->{list}} > 1 ?
join(", ", @{$sharehosts->{list}}[0,1]) . " ..." :
join(", ", @{$sharehosts->{list}})) :
N("No remote machines"))),
type => 'button',
clicked_may_quit => sub {
$buttonclicked = "sharehosts";
1;
},
disabled => sub {
(!$printer->{cupsconfig}{localprintersshared} &&
!$printer->{cupsconfig}{remotebroadcastsaccepted});
} },
{ val => N("Additional CUPS servers: ") .
($#{$browsepoll->{list}} >= 0 ?
($#{$browsepoll->{list}} > 1 ?
join(", ", @{$browsepoll->{list}}[0,1]) . " ..." :
join(", ", @{$browsepoll->{list}})) :
N("None")),
type => 'button',
help => N("To get access to printers on remote CUPS servers in your local network you only need to turn on the \"Automatically find available printers on remote machines\" option; 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. If your CUPS server(s) is/are not in your local network, you have to enter the IP address(es) and optionally the port number(s) here to get the printer information from the server(s)."),
clicked_may_quit => sub {
$buttonclicked = "browsepoll";
1;
} },
{ text => N("Japanese text printing mode"),
help => N("Turning on this allows to print plain text files in japanese language. Only use this function if you really want to print text in japanese, if it is activated you cannot print accentuated characters in latin fonts any more and you will not be able to adjust the margins, the character size, etc. This setting only affects printers defined on this machine. If you want to print japanese text on a printer set up on a remote machine, you have to activate this function on that remote machine."),
type => 'bool',
val => \$jap_textmode },
if_($printer->{expert},
{ text => N("Automatic correction of CUPS configuration"),
type => 'bool',
help => N("When this option is turned on, on every startup of CUPS it is automatically made sure that
- if LPD/LPRng is installed, /etc/printcap will not be overwritten by CUPS
- if /etc/cups/cupsd.conf is missing, it will be created
- when printer information is broadcasted, it does not contain \"localhost\" as the server name.
If some of these measures lead to problems for you, turn this option off, but then you have to take care of these points."),
val => \$printer->{cupsconfig}{autocorrection} }),
]
)
) {
if ($buttonclicked eq "sharehosts") {
# Show dialog to add hosts to share printers to
my $subdone = 0;
my $choice;
while (!$subdone) {
# Entry should be edited when double-clicked
$buttonclicked = "edit";
$in->ask_from(
{ title => N("Sharing of local printers"),
messages => N("These are the machines and networks on which the locally connected printer(s) should be available:"),
ok => "",
cancel => "",
},
# List the hosts
[ { val => \$choice, format => \&translate,
sort => 0, separator => "####",
tree_expanded => 1,
quit_if_double_click => 1,
allow_empty_list => 1,
list => $sharehosts->{list} },
{ val => N("Add host/network"),
type => 'button',
clicked_may_quit => sub {
$buttonclicked = "add";
1;
} },
{ val => N("Edit selected host/network"),
type => 'button',
clicked_may_quit => sub {
$buttonclicked = "edit";
1;
},
disabled => sub {
return $#{$sharehosts->{list}} < 0;
} },
{ val => N("Remove selected host/network"),
type => 'button',
clicked_may_quit => sub {
$buttonclicked = "remove";
1;
},
disabled => sub {
return $#{$sharehosts->{list}} < 0;
} },
{ val => N("Done"),
type => 'button',
clicked_may_quit => sub {
$buttonclicked = "";
$subdone = 1;
1;
} },
]
);
if ($buttonclicked eq "add" ||
$buttonclicked eq "edit") {
my ($hostchoice, $ip);
if ($buttonclicked eq "add") {
# Use first entry as default for a new entry
$hostchoice = N("Local network(s)");
} else {
if ($sharehosts->{invhash}{$choice} =~ /^\@/) {
# Entry to edit is not an IP address
$hostchoice = $choice;
} else {
# Entry is an IP address
$hostchoice =
N("IP address of host/network:");
$ip = $sharehosts->{invhash}{$choice};
}
}
my @menu = N("Local network(s)");
my @interfaces =
printer::detect::getNetworkInterfaces();
foreach my $interface (@interfaces) {
push @menu, N("Interface \"%s\"", $interface);
}
push @menu, N("IP address of host/network:");
# Show the dialog
my $address;
my $oldaddress =
($buttonclicked eq "edit" ?
$sharehosts->{invhash}{$choice} : "");
if ($in->ask_from(
{ title => N("Sharing of local printers"),
messages => N("Choose the network or host on which the local printers should be made available:"),
callbacks => {
complete => sub {
if ($hostchoice eq
N("IP address of host/network:") &&
$ip =~ /^\s*$/) {
$in->ask_warn(N("Error"), N("Host/network IP address missing."));
return 1, 1;
}
if ($hostchoice eq
N("IP address of host/network:") &&
!printer::main::is_network_ip($ip)) {
$in->ask_warn(N("Error"),
N("The entered host/network IP is not correct.\n") .
N("Examples for correct IPs:\n") .
"192.168.100.194\n" .
"10.0.0.*\n" .
"10.1.*\n" .
"192.168.100.0/24\n" .
"192.168.100.0/255.255.255.0\n"
);
return 1, 1;
}
if ($hostchoice eq $menu[0]) {
$address = '@LOCAL';
} elsif ($hostchoice eq $menu[-1]) {
$address = $ip;
} else {
($address) =
grep { $hostchoice =~ /$_/ }
@interfaces;
$address = "\@IF($address)";
}
# Check whether item is duplicate
if ($address ne $oldaddress &&
member($address,
@{$printer->{cupsconfig}{clientnetworks}})) {
$in->ask_warn(N("Error"),
|