diff options
author | Till Kamppeter <tkamppeter@mandriva.com> | 2002-01-23 18:13:38 +0000 |
---|---|---|
committer | Till Kamppeter <tkamppeter@mandriva.com> | 2002-01-23 18:13:38 +0000 |
commit | 6ca87c063341cb82e73331f869e8f0815d9dd803 (patch) | |
tree | b20019c6ff5cda491761e380de64cdacf6cbb782 | |
parent | 0e89c143f28b2c22d20feba456392ddaa8dbff37 (diff) | |
download | drakx-6ca87c063341cb82e73331f869e8f0815d9dd803.tar drakx-6ca87c063341cb82e73331f869e8f0815d9dd803.tar.gz drakx-6ca87c063341cb82e73331f869e8f0815d9dd803.tar.bz2 drakx-6ca87c063341cb82e73331f869e8f0815d9dd803.tar.xz drakx-6ca87c063341cb82e73331f869e8f0815d9dd803.zip |
New user interface in main window
More printer info in printer modification window
Better support for remote CUPS printers
-rw-r--r-- | perl-install/printer.pm | 85 | ||||
-rw-r--r-- | perl-install/printerdrake.pm | 248 |
2 files changed, 245 insertions, 88 deletions
diff --git a/perl-install/printer.pm b/perl-install/printer.pm index 3274627be..906d8550e 100644 --- a/perl-install/printer.pm +++ b/perl-install/printer.pm @@ -437,9 +437,57 @@ sub read_configured_queues($) { } @{$printer->{configured}{$QUEUES[$i]->{'queuedata'}{'queue'}}{'queuedata'}{options}} = @options; } + # Construct an entry line for tree view in main window of + # printerdrake + make_menuentry($printer, $QUEUES[$i]->{'queuedata'}{'queue'}); } } +sub make_menuentry { + my ($printer, $queue) = @_; + my $spooler = $shortspooler_inv{$printer->{SPOOLER}}; + my $connect = $printer->{configured}{$queue}{'queuedata'}{'connect'}; + my $localremote; + if ($connect =~ m!^file:!) { + $localremote = _("Local Printers"); + } else { + $localremote = _("Remote Printers"); + } + my $queue = $printer->{configured}{$queue}{'queuedata'}{'queue'}; + my $make = $printer->{configured}{$queue}{'queuedata'}{'make'}; + my $model = $printer->{configured}{$queue}{'queuedata'}{'model'}; + my $connection; + if ($connect =~ m!^file:/dev/lp(\d+)$!) { + my $number = $1; + $connection = _(" on parallel port \#%s", $number); + } elsif ($connect =~ m!^file:/dev/usb/lp(\d+)$!) { + my $number = $1; + $connection = _(", USB printer \#%s", $number); + } elsif ($connect =~ m!^file:(.+)$!) { + $connection = _(", printing to %s", $1); + } elsif ($connect =~ m!^lpd://([^/]+)/([^/]+)/?$!) { + $connection = _("on LPD server \"%s\", printer \"%s\"", $2, $1); + } elsif ($connect =~ m!^socket://([^/:]+):([^/:]+)/?$!) { + $connection = _(", TCP/IP host \"%s\", port \"%s\"", $1, $2); + } elsif (($connect =~ m!^smb://([^/\@]+)/([^/\@]+)/?$!) || + ($connect =~ m!^smb://.*/([^/\@]+)/([^/\@]+)/?$!) || + ($connect =~ m!^smb://.*\@([^/\@]+)/([^/\@]+)/?$!)) { + $connection = _("on Windows server \"%s\", share \"%s\"", $1, $2); + } elsif (($connect =~ m!^ncp://([^/\@]+)/([^/\@]+)/?$!) || + ($connect =~ m!^ncp://.*/([^/\@]+)/([^/\@]+)/?$!) || + ($connect =~ m!^ncp://.*\@([^/\@]+)/([^/\@]+)/?$!)) { + $connection = _("on Novell server \"%s\", printer \"%s\"", $1, $2); + } elsif ($connect =~ m!^postpipe:(.+)$!) { + $connection = _(", using command %s", $1); + } else { + $connection = ""; + } + my $sep = "!"; + $printer->{configured}{$queue}{'queuedata'}{'menuentry'} = + ($::expert ? "$spooler$sep" : "") . + "$localremote$sep$queue: $make $model$connection"; +} + sub read_printer_db(;$) { my $spooler = $_[0]; @@ -684,6 +732,7 @@ sub read_cups_options ($) { #------------------------------------------------------------------------------ sub read_cups_printer_list { + my ($printer) = $_[0]; # This function reads in a list of all printers which the local CUPS # daemon currently knows, including remote ones. local *F; @@ -695,7 +744,8 @@ sub read_cups_printer_list { if ($line =~ m/^\s*device\s+for\s+([^:\s]+):\s*(\S+)\s*$/) { my $queuename = $1; my $comment = ""; - if ($2 =~ m!^ipp://([^/:]+)[:/]!) { + if (($2 =~ m!^ipp://([^/:]+)[:/]!) && + (!$printer->{configured}{$queuename})) { $comment = _("(on %s)", $1); } else { $comment = _("(on this machine)"); @@ -707,6 +757,36 @@ sub read_cups_printer_list { return @printerlist; } +sub get_cups_remote_queues { + my ($printer) = $_[0]; + # This function reads in a list of all remote printers which the local + # CUPS daemon knows due to broadcasting of remote servers or + # "BrowsePoll" entries in the local /etc/cups/cupsd.conf/ + local *F; + open F, ($::testing ? "$prefix" : "chroot $prefix/ ") . + "lpstat -v |" || return (); + my @printerlist = (); + my $line; + while ($line = <F>) { + if ($line =~ m/^\s*device\s+for\s+([^:\s]+):\s*(\S+)\s*$/) { + my $queuename = $1; + my $comment = ""; + if (($2 =~ m!^ipp://([^/:]+)[:/]!) && + (!$printer->{configured}{$queuename})) { + $comment = _("On CUPS server \"%s\"", $1); + my $sep = "!"; + push (@printerlist, + ($::expert ? _("CUPS") . $sep : "") . + _("Remote Printers") . "$sep$queuename: $comment" + . ($queuename eq $printer->{DEFAULT} ? + _(" (Default)") : ())); + } + } + } + close F; + return @printerlist; +} + sub set_cups_autoconf { my $autoconf = $_[0]; @@ -1147,6 +1227,9 @@ sub lphelp_output { open F, ($::testing ? "$prefix" : "chroot $prefix/ ") . "$lphelp $queue |"; $helptext = join("", <F>); close F; + if (!$helptext || ($helptext eq "")) { + $helptext = "Option list not available!\n"; + } return $helptext; } diff --git a/perl-install/printerdrake.pm b/perl-install/printerdrake.pm index 4b26b87dd..3d2dda521 100644 --- a/perl-install/printerdrake.pm +++ b/perl-install/printerdrake.pm @@ -56,7 +56,7 @@ sub setup_remote_cups_server { } $server =~ /([^:]*):(.*)/ and ($server, $port) = ($1, $2); # Read printer list - my @queuelist = printer::read_cups_printer_list(); + my @queuelist = printer::read_cups_printer_list($printer); if ($#queuelist >=0) { if ($printer->{DEFAULT} eq '') { $default = printer::get_default_printer($printer); @@ -1196,7 +1196,8 @@ sub print_testpages { Note: the photo test page can take a rather long time to get printed and on laser printers with too low memory it can even not come out. In most cases it is enough to print the standard test page."), - cancel => ($printer->{configured}{$printer->{OLD_QUEUE}} ? + cancel => ((($printer->{configured}{$printer->{OLD_QUEUE}}) || + (!$printer->{configured}{$printer->{QUEUE}})) ? _("Cancel") : _("No test pages")), ok => _("Print")}, [ @@ -1265,11 +1266,16 @@ sub printer_help { my $queue = $printer->{QUEUE}; my $default = $printer->{DEFAULT}; my $raw = 0; - if (($printer->{configured}{$queue}{'queuedata'}{'model'} eq - _("Unknown model")) || - ($printer->{configured}{$queue}{'queuedata'}{'model'} eq - _("Raw printer"))) { - $raw = 1; + my $cupsremote = 0; + if ($printer->{configured}{$queue}) { + if (($printer->{configured}{$queue}{'queuedata'}{'model'} eq + _("Unknown model")) || + ($printer->{configured}{$queue}{'queuedata'}{'model'} eq + _("Raw printer"))) { + $raw = 1; + } + } else { + $cupsremote = 1; } #my $foomatic = $printer->{configured}{$queue}{queuedata}{foomatic}; #my $ppd = $printer->{configured}{$queue}{queuedata}{ppd}; @@ -1283,9 +1289,13 @@ _("These commands you can also use in the \"Printing command\" field of the prin (!$raw ? _(" The \"%s\" command also allows to modify the option settings for a particular printing job. Simply add the desired settings to the command line, e. g. \"%s <file>\". ", "lpr", ($queue ne $default ? "lpr -P $queue -o option=setting -o switch" : "lpr -o option=setting -o switch")) . -_("To get a list of the options available for the current printer read either the list shown below or click on the \"Print option list\" button. +(!$cupsremote ? + _("To get a list of the options available for the current printer read either the list shown below or click on the \"Print option list\" button. -") . printer::lphelp_output($printer) : ""); +") . printer::lphelp_output($printer) : + _("Here is a list of the available options for the current printer: + +") . printer::lphelp_output($printer)) : ""); } elsif ($spooler eq "lprng") { $dialogtext = _("To print a file from the command line (terminal window) use the command \"%s <file>\". @@ -1327,7 +1337,7 @@ _("To get a list of the options available for the current printer read either th ") . printer::pdqhelp_output($printer) : ""); } - if (!$raw) { + if (!$raw && !$cupsremote) { my $choice; while ($choice ne _("Close")) { $choice = $in->ask_from_list_ @@ -1341,7 +1351,8 @@ _("To get a list of the options available for the current printer read either th } } } else { - $in->ask_warn('',$dialogtext); + $in->ask_warn(_("Printing on the printer \"%s\"", $queue), + $dialogtext); } } @@ -1846,7 +1857,7 @@ sub main { } # Control variables for the main loop - my ($queue, $continue, $newqueue, $editqueue, $expertswitch, $menushown) = ('', 1, 0, 0, 0, 0); + my ($menuchoice, $cursorpos, $queue, $continue, $newqueue, $editqueue, $expertswitch, $menushown) = ('', '', $defaultprname, 1, 0, 0, 0, 0); # Cursor position in queue modification window my $modify = _("Printer options"); while ($continue) { @@ -1885,11 +1896,11 @@ sub main { %{$printer->{configured} || {}} == ()) { $in->set_help('doYouWantToPrint') if $::isInstall; $newqueue = 1; - $queue = $printer->{want} || + $menuchoice = $printer->{want} || $in->ask_yesorno(_("Printer"), _("Would you like to configure printing?"), - 0) ? $defaultprname : _("Done"); - if ($queue ne _("Done")) { + 0) ? "\@addprinter" : "\@quit"; + if ($menuchoice ne "\@quit") { $printer->{SPOOLER} ||= setup_default_spooler ($printer, $in) || return; @@ -1917,80 +1928,118 @@ sub main { # on the question is not asked any more but the menu # is shown directly after having done an operation. $menushown = 1; - # $expertwitch gets one when the "Expert mode"/ - # "Standard mode" button is clicked. - $expertswitch = !$in->ask_from_( - {messages => - _("The following printers are configured. -Click on one of them to modify it or -to get information about it or on -\"Add Printer\" to add a new printer."), + # Position the cursor where it were before (in case + # a button was pressed). + $menuchoice = $cursorpos; + # Show the main dialog + $in->ask_from_( + {title => _("Printerdrake"), + messages => + _("The following printers are configured. Double-click on one of them to modify it, to set it as default, or to get information about it."), cancel => ($::isInstall ? ('') : ($::expert ? _("Normal Mode") : _("Expert Mode"))), + ok => (""), }, # List the queues - [ { val => \$queue, format => \&translate, - sort => 0, - list => [ (sort(map {"$_" . ($_ eq $printer->{DEFAULT} ? - _(" (Default)") : ())} - keys(%{$printer->{configured} || {}}))), + [ { val => \$menuchoice, format => \&translate, + sort => 0, separator => "!", tree_expanded => 1, + quit_if_double_click => 1, + list => [ (sort((map {$printer->{configured}{$_}{'queuedata'}{'menuentry'} + . ($_ eq $printer->{DEFAULT} ? + _(" (Default)") : ())} + keys(%{$printer->{configured} + || {}})), + ($printer->{SPOOLER} eq "cups" ? + printer::get_cups_remote_queues($printer) + : ()))), # CUPS makes available remote printers automatically - ($printer->{SPOOLER} eq "cups" ? - ($::expert ? _("Printer(s) on remote CUPS server(s)"): - _("Printer(s) on remote server(s)")) : ()), + #($printer->{SPOOLER} eq "cups" ? + # ($::expert ? _("Printer(s) on remote CUPS server(s)"): + # _("Printer(s) on remote server(s)")) : ()), # Button to add a new queue - _("Add printer"), + #_("Add printer"), # In expert mode we can change the spooler - ($::expert ? - ( $spoolerentry . - $printer::spooler_inv{$printer->{SPOOLER}} ) : ()), + #($::expert ? + # ( $spoolerentry . + # $printer::spooler_inv{$printer->{SPOOLER}} ) : ()), # Bored by configuring your printers, get out of here! - _("Done") ] } ] + #_("Done") + ] }, + { clicked_may_quit => + sub { $menuchoice = "\@addprinter"; 1; }, + val => _("Add a new printer") }, + ( $printer->{SPOOLER} eq "cups" ? + { clicked_may_quit => + sub { $menuchoice = "\@refresh"; 1; }, + val => _("Refresh printer list (to get all remote CUPS printers visible)") } : ()), + ( $::expert ? + { clicked_may_quit => + sub { $menuchoice = "\@spooler"; 1; }, + val => _("Configure printing system") } : + ()), + ( !$::isInstall ? + { clicked_may_quit => + sub { $menuchoice = "\@usermode"; 1; }, + val => ($::expert ? _("Normal Mode") : + _("Expert Mode")) } : ()), + { clicked_may_quit => + sub { $menuchoice = _("\@quit"); 1; }, + val => _("Quit") }, + ] ); # Toggle expert mode and standard mode - if ($expertswitch) { - $expertswitch = 0; + if ($menuchoice eq "\@usermode") { $::expert = !$::expert; # Read printer database for the new user mode %printer::thedb = (); #my $w = $in->wait_message('', _("Reading printer database ...")); #printer::read_printer_db($printer->{SPOOLER}); + # Re-read printer queues to switch the tree + # structure between expert/normal mode. + my $w = $in->wait_message('', _("Reading printer data ...")); + printer::read_configured_queues($printer); next; } } else { #- as there are no printer already configured, Add one #- automatically. - $queue = _("Add printer"); - } + $menuchoice = "\@addprinter"; + } + # Refresh printer list + if ($menuchoice eq "\@refresh") { + next; + } # Determine a default name for a new printer queue - if ($queue eq _("Add printer")) { + if ($menuchoice eq "\@addprinter") { $newqueue = 1; my %queues; @queues{map { split '\|', $_ } keys %{$printer->{configured}}} = (); - my $i = ''; while ($i < 100) { last unless exists $queues{"$defaultprname$i"}; ++$i; } + my $i = ''; while ($i < 150) { last unless exists $queues{"$defaultprname$i"}; ++$i; } $queue = "$defaultprname$i"; } # Function to switch to another spooler chosen - if ($queue =~ /^$spoolerentry/) { + if ($menuchoice eq "\@spooler") { $printer->{SPOOLER} = setup_default_spooler ($printer, $in) || $printer->{SPOOLER}; next; } # Make available printers on remote CUPS servers (CUPS only). - if (($queue eq _("Printer(s) on remote CUPS server(s)")) || - ($queue eq _("Printer(s) on remote server(s)"))) { - setup_remote_cups_server($printer, $in); - next; - } - # Rip off the " (Default)" tag from the queue name - if ($queue =~ /^\s*(\S+)\s+/) { + #if (($queue eq _("Printer(s) on remote CUPS server(s)")) || + # ($queue eq _("Printer(s) on remote server(s)"))) { + # setup_remote_cups_server($printer, $in); + # next; + #} + # Rip the queue name out of the chosen menu entry + if ($menuchoice =~ /!([^\s!:]+):[^!]*$/) { $queue = $1; + # Save the cursor position + $cursorpos = $menuchoice; } } # Save the default spooler printer::set_default_spooler($printer); #- Close printerdrake - $queue eq _("Done") and last; + $menuchoice eq "\@quit" and last; } if ($newqueue) { $printer->{NEW} = 1; @@ -2013,7 +2062,7 @@ to get information about it or on $printer->{OLD_QUEUE} = $printer->{QUEUE} = $queue; #- When we are back on the main menu the cursor should be #- on "Add printer" - $queue = _("Add printer"); + #$menuchoice = "\@addprinter"; #- Do all the configuration steps for a new queue choose_printer_type($printer, $in) or next; if ($printer->{TYPE} eq 'CUPS') { @@ -2044,63 +2093,88 @@ to get information about it or on $printer->{NEW} = 0; # Modify a queue, ask which part should be modified $in->set_help('modifyPrinterMenu') if $::isInstall; + # Get some info to display + my $infoline; + if ($printer->{configured}{$queue}) { + # Here we must regenerate the menu entry, because the + # parameters can be changed. + printer::make_menuentry($printer,$queue); + $printer->{configured}{$queue}{'queuedata'}{menuentry} =~ + /!([^!]+)$/; + $infoline = $1 . + ($queue eq $printer->{DEFAULT} ? _(" (Default)") : ()) . + ($printer->{configured}{$queue}{'queuedata'}{'desc'} ? + ", Descr.: $printer->{configured}{$queue}{'queuedata'}{'desc'}" : ()) . + ($printer->{configured}{$queue}{'queuedata'}{'loc'} ? + ", Loc.: $printer->{configured}{$queue}{'queuedata'}{'loc'}" : ()) . + ($::expert ? + ", Driver: $printer->{configured}{$queue}{'queuedata'}{'driver'}" : ()); + } else { + # The parameters of a remote CUPS queue cannot be changed, + # so we can simply take the menu entry. + $menuchoice =~ /!([^!]+)$/; + $infoline = $1; + } if ($in->ask_from_ ({ title => _("Modify printer configuration"), - messages => _("Printer %s: %s %s + messages => + _("Printer %s What do you want to modify on this printer?", - $queue, - $printer->{configured}{$queue}{'queuedata'}{'make'}, - $printer->{configured}{$queue}{'queuedata'}{'model'} . - ($queue eq $printer->{DEFAULT} ? - _(" (Default)") : ())), + $infoline), cancel => _("Close"), ok => _("Do it!") }, [ { val => \$modify, format => \&translate, - list => [ _("Printer connection type"), - _("Printer name, description, location"), - ($::expert ? - _("Printer manufacturer, model, driver") : - _("Printer manufacturer, model")), - (($printer->{configured}{$queue}{'queuedata'}{'make'} ne - "") && - (($printer->{configured}{$queue}{'queuedata'}{'model'} ne - _("Unknown model")) && - ($printer->{configured}{$queue}{'queuedata'}{'model'} ne - _("Raw printer"))) ? - _("Printer options") : ()), - (($queue ne $printer->{DEFAULT}) ? - _("Set this printer as the default") : ()), - _("Print test pages"), - _("Know how to print with this printer"), - _("Remove printer") ] } ] ) ) { + list => [ ($printer->{configured}{$queue} ? + (_("Printer connection type"), + _("Printer name, description, location"), + ($::expert ? + _("Printer manufacturer, model, driver") : + _("Printer manufacturer, model")), + (($printer->{configured}{$queue}{'queuedata'}{'make'} ne + "") && + (($printer->{configured}{$queue}{'queuedata'}{'model'} ne + _("Unknown model")) && + ($printer->{configured}{$queue}{'queuedata'}{'model'} ne + _("Raw printer"))) ? + _("Printer options") : ())) : ()), + (($queue ne $printer->{DEFAULT}) ? + _("Set this printer as the default") : ()), + _("Print test pages"), + _("Know how to print with this printer"), + ($printer->{configured}{$queue} ? + _("Remove printer") : ()) ] } ] ) ) { # Stay in the queue edit window until the user clicks "Close" # or deletes the queue $editqueue = 1; #- Copy the queue data and work on the copy $printer->{currentqueue} = {}; + my $driver; if ($printer->{configured}{$queue}) { printer::copy_printer_params($printer->{configured}{$queue}{'queuedata'}, $printer->{currentqueue}); + #- Keep in mind the printer driver which was used, so it + #- can be determined whether the driver is only + #- available in expert and so for setting the options + #- for the driver in recommended mode a special + #- treatment has to be applied. + $driver = $printer->{currentqueue}{driver}; } - #- Keep in mind the printer driver which was used, so it can - #- be determined whether the driver is only available in expert - #- and so for setting the options for the driver in - #- recommended mode a special treatment has to be applied. - my $driver = $printer->{currentqueue}{driver}; #- keep in mind old name of queue (in case of changing) $printer->{OLD_QUEUE} = $printer->{QUEUE} = $queue; #- Reset some variables $printer->{OLD_CHOICE} = undef; $printer->{DBENTRY} = undef; - #- Which printer type did we have before (check beginning of + #- Which printer type did we have before (check beginning of #- URI) my $type; - for $type (qw(file lpd socket smb ncp postpipe)) { - if ($printer->{currentqueue}{'connect'} - =~ /^$type:/) { - $printer->{TYPE} = - ($type eq 'file' ? 'LOCAL' : uc($type)); - last; + if ($printer->{configured}{$queue}) { + for $type (qw(file lpd socket smb ncp postpipe)) { + if ($printer->{currentqueue}{'connect'} + =~ /^$type:/) { + $printer->{TYPE} = + ($type eq 'file' ? 'LOCAL' : uc($type)); + last; + } } } # Do the chosen task |