ACC SHELL

Path : /usr/share/doc/packages/yast2-samba-server/autodocs/
File Upload :
Current File : //usr/share/doc/packages/yast2-samba-server/autodocs/SambaPrinters.html

<?xml version="1.0" ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>SambaPrinters</title>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<link rev="made" href="mailto:feedback@suse.de" />
</head>

<body style="background-color: white">


<!-- INDEX BEGIN -->
<div name="index">
<p><a name="__index__"></a></p>


</div>
<!-- INDEX END -->

<p>module &quot;SambaPrinters&quot;;
textdomain &quot;samba-server&quot;;</p>
<p>import &quot;SambaConfig&quot;;</p>
<p>import &quot;Spooler&quot;;</p>
<p>/**
 * list of all system printers
 */
list&lt;string&gt; system_printers = [];</p>
<p>/**
 * default settings for [printers]
 */
map&lt;string, any&gt; default_printers = $[
   &quot;comment&quot;: &quot;All Printers&quot;,
   &quot;path&quot;: &quot;/var/tmp&quot;,
   &quot;printable&quot;: true,
   &quot;browseable&quot;: false,
   &quot;available&quot;: &quot;yes&quot;,
   &quot;guest ok&quot;: &quot;no&quot;,
   &quot;yast&quot;: true
];</p>
<p>/**
 * default settings for a single printer share
 */
map&lt;string, any&gt; default_printer_share = $[
   &quot;path&quot;: &quot;/var/tmp&quot;,
   &quot;browseable&quot;: true,
   &quot;printable&quot;: true,
   &quot;yast&quot;: true
];</p>
<p>global <code>Read()</code> {</p>
<pre>
    printer_status = $[];
    
//    Progress::off();
    string spooler = Spooler::checkSpoolSystemNoDialog();
    y2milestone (&quot;Spooler: %1&quot;, spooler );
    Spooler::Set(spooler);
    system_printers = Spooler::GetAvailableQueues();
//    Progress::on();</pre>
<pre>
    SambaConfig::Read();</pre>
<pre>
    // setup correctly the printer status
    if (SambaConfig::ExistsShare(&quot;printers&quot;)) {
        // load the system printers
        
        // setup system printer status
        boolean on = SambaServer::IsEnabledShare(&quot;printers&quot;) &amp;&amp; toboolean(SambaConfig::GetGlobal(&quot;load printers&quot;, &quot;Yes&quot;));</pre>
<pre>
        share_printers = on;
        if (system_printers != nil) {
            foreach(string printer, system_printers , ``{
                printer_status[printer] = on;
            });
        }
    }
    
    // update printer_status for printable shares
    foreach(string share, map options, SambaConfig::GetShares(), ``{
        if (share != &quot;printers&quot;) {
            if (toboolean(SambaConfig::GetShare(share, &quot;printable&quot;, &quot;No&quot;))) {
                // if the printer was enabled because of printers and it is commented, skip
                // TODO - handle &quot;available&quot; correctly
                boolean on = SambaConfig::ShareEnabled(share);
                if (!(printer_status[share]:false &amp;&amp; !on)) {
                    printer_status[share] = on;
                    if (on) share_printers = true;
                }
            }
        }
    });
    
    return true;
}</pre>
<p>/** 
 * Turn on/off [printers]
 *
 * @param on 		should be enabled?
 */
global  define void enablePrinters( boolean on ) ``{
    if( share_printers != on ) {
	share_printers = on;</p>
<pre>
        // if they should be turned off and there is no such share, done
        if (!on) {
            disableAllPrinters();
        } else {
            SambaConfig::EnableShare(&quot;printers&quot;);
            enableAllSystemPrinters();
        }</pre>
<pre>
        modified = true;
    }
}</pre>
<p>/** 
 * Turn on all system printers. Will enable [printers] as well.
 */
global define void <code>enableAllSystemPrinters()</code> ``{
    if (system_printers != nil) {	
	foreach(  string printer, system_printers, ``{
	    printer_status[ printer ] = true;
	    share_printers = true;
	});
    }
}</p>
<p>/**
 * Disable all printers.
 */
global define void <code>disableAllPrinters()</code> ``{
    // disable each share with printable = true
    foreach(string share, SambaConfig::GetShares(), {
	if (toboolean(SambaConfig::GetShare(share, &quot;printable&quot;, nil))) 
	    SambaConfig::DisableShare(share);
    });
}</p>
<p>/**
 * Enable printers in a list. If possible, use [printers] section
 *
 * @param enable_names	list of printer names to be enabled
 */
global define void enablePrinterNames( list&lt;string&gt; enable_names ) ``{</p>
<pre>

    y2debug( &quot;System printers are: %1&quot;, system_printers );
    y2debug( &quot;Enable: %1&quot;, enable_names );</pre>
<pre>

    // first, check, if we can use [printers]
    boolean printers = true;
    if (system_printers != nil) {       
        foreach( string name, system_printers, ``{
            // each system printer must be enabled and not disabled
            if( (printer_status[name]:false) &amp;&amp; !contains( enable_names, name ) ) {
                printers = false;
                y2debug( &quot;[printers] can't be used, because of %1&quot;, name );
            }
        });
    }</pre>
<pre>

    enableShare( &quot;printers&quot;, printers );
    // if we can use [printers]
    if( printers ) {
        // filter out printers enabled by [printers]
        enable_names = filter( string name, enable_names, ``( !contains( system_printers, name ) ) );
        // remove yast-defined shares
        shares = filter( string name, map&lt;string,any&gt; options, shares, ``( ! (options[&quot;yast&quot;]:false) ) );
    }</pre>
<pre>

    // update the status of these printers
    if (system_printers != nil) {
        foreach( string name, system_printers, ``{
            printer_status[ name ] = printers;
            // if printers are used, do not use the shares themselves
            if( printers ) {
                enableShare( name, false );
            }
        });
    }</pre>
<pre>

    // work on enable_names
    y2debug( &quot;Now need to work on %1&quot;, enable_names );
    foreach( string name, enable_names, ``{
        if( haskey( shares, name ) ) {
            if( shares[name, &quot;printable&quot;]:false == true ) {
                printer_status[ name ] = true;
                enableShare( name, true );
                y2debug( &quot;Enabling printer %1&quot;, name );
            }
            else 
            {
                // a share with the same name, but without printable!!!
                y2error( &quot;Share '%1' is not printable: %2&quot;, name, shares[name]:$[] );
                // translators: error message. There is a given share, but configured differently
                Report::Error( sformat( _(&quot;There is already a share '%1',
but it is not configured
as a printer.\n
YaST2 will not modify this share.&quot;), name ) );
            }
        }
        else 
        {
            y2debug( &quot;Adding a share for printer %1&quot;, name );
            // no share, create one
            shares[ name ] = eval(default_printer_share);
            printer_status[ name ] = true;
            enableShare( name, true );
        }
    });</pre>
<pre>

    modified = true;
}</pre>
<p>/**
 * Are some of the system printers enabled?
 *
 * @return boolean	true if yes
 */
global define boolean <code>SystemPrintersEnabled()</code> ``{
    boolean result = false;
    if (system_printers != nil) {
	foreach( string printer, system_printers, ``{
	    if( printer_status[ printer ]:false ) result = true;
        });
    }
    
    return result;
}</p>
<p><code>removeShare()</code> {
    ...
// update the printer lists
//    if( haskey( printer_status, name ) ) printer_status = remove( printer_status, name );</p>
<pre>
    ...
}

</pre>
<p><code>enableShare()</code> {
    ...
    // [printers] is coupled with &quot;load printers&quot;
    if( name == &quot;printers&quot; ) 
	global_config[&quot;load printers&quot;] = on;</p>
<pre>
    ...
}
</pre>

</body>

</html>

ACC SHELL 2018