LCOV - code coverage report
Current view: top level - libreoffice/vcl/inc/vcl - printerinfomanager.hxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 6 8 75.0 %
Date: 2012-12-17 Functions: 8 16 50.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2             : /*
       3             :  * This file is part of the LibreOffice project.
       4             :  *
       5             :  * This Source Code Form is subject to the terms of the Mozilla Public
       6             :  * License, v. 2.0. If a copy of the MPL was not distributed with this
       7             :  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
       8             :  *
       9             :  * This file incorporates work covered by the following license notice:
      10             :  *
      11             :  *   Licensed to the Apache Software Foundation (ASF) under one or more
      12             :  *   contributor license agreements. See the NOTICE file distributed
      13             :  *   with this work for additional information regarding copyright
      14             :  *   ownership. The ASF licenses this file to you under the Apache
      15             :  *   License, Version 2.0 (the "License"); you may not use this file
      16             :  *   except in compliance with the License. You may obtain a copy of
      17             :  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
      18             :  */
      19             : 
      20             : #ifndef _PSPRINT_PRINTERINFOMANAGER_HXX_
      21             : #define _PSPRINT_PRINTERINFOMANAGER_HXX_
      22             : 
      23             : #include <boost/unordered_map.hpp>
      24             : #include <list>
      25             : 
      26             : #include "vcl/dllapi.h"
      27             : #include "vcl/helper.hxx"
      28             : #include "vcl/jobdata.hxx"
      29             : #include "vcl/helper.hxx"
      30             : #include "osl/file.hxx"
      31             : 
      32             : #include <cstdio>
      33             : 
      34             : namespace psp
      35             : {
      36             : 
      37             : class SystemQueueInfo;
      38             : 
      39          82 : struct PrinterInfo : JobData
      40             : {
      41             :     // basename of PPD
      42             :     rtl::OUString             m_aDriverName;
      43             :     // can be the queue
      44             :     rtl::OUString             m_aLocation;
      45             :     // a user defined comment
      46             :     rtl::OUString             m_aComment;
      47             :     // a command line to pipe a PS-file to
      48             :     rtl::OUString             m_aCommand;
      49             :     // a command line to pipe a PS-file to in case of direct print
      50             :     rtl::OUString             m_aQuickCommand;
      51             :     // a list of special features separated by ',' not used by psprint
      52             :     // but assigned from the outside (currently for "fax","pdf=","autoqueue","external_dialog")
      53             :     rtl::OUString             m_aFeatures;
      54             :     // a mapping of fonts to other fonts.
      55             :     // this provides a method for the user
      56             :     // to replace arbitrary fonts by printer builtin fonts
      57             :     // currently this is only a mapping between font names
      58             :     // assuming that only adbobe standard encoding fonts are
      59             :     // built into the printer. in future it may be necessary
      60             :     // to map to a font name and UCS2 vector which should be mapped
      61             :     // this vector is currently implicitly given by the adobe
      62             :     // standard encoding
      63             :     bool                        m_bPerformFontSubstitution;
      64             :     boost::unordered_map< rtl::OUString, rtl::OUString, rtl::OUStringHash >
      65             :     m_aFontSubstitutes;
      66             :     boost::unordered_map< fontID, fontID >
      67             :     m_aFontSubstitutions;
      68             : 
      69         122 :     PrinterInfo() :
      70             :             JobData(),
      71         122 :             m_bPerformFontSubstitution( false )
      72         122 :     {}
      73             : };
      74             : 
      75             : class VCL_DLLPUBLIC PrinterInfoManager
      76             : {
      77             : public:
      78             :     enum Type { Default = 0, CUPS = 1 };
      79             : 
      80           0 :     struct SystemPrintQueue
      81             :     {
      82             :         rtl::OUString       m_aQueue;
      83             :         rtl::OUString       m_aLocation;
      84             :         rtl::OUString       m_aComment;
      85             :     };
      86             : protected:
      87             :     // needed for checkPrintersChanged: files (not necessarily existant)
      88             :     // and their last known modification time
      89          12 :     struct WatchFile
      90             :     {
      91             :         // the file in question
      92             :         rtl::OUString         m_aFilePath;
      93             :         // the last know modification time or 0, if file did not exist
      94             :         TimeValue               m_aModified;
      95             :     };
      96             : 
      97             :     // internal data to describe a printer
      98           8 :     struct Printer
      99             :     {
     100             :         // configuration file containing this printer
     101             :         // empty means a freshly added printer that has to be saved yet
     102             :         rtl::OUString         m_aFile;
     103             :         // details other config files that have this printer
     104             :         // in case of removal all have to be removed
     105             :         std::list< rtl::OUString > m_aAlternateFiles;
     106             :         // group in m_aFile containing the printer
     107             :         // this must be unique over all configuration files
     108             :         // it usually should be the printer name
     109             :         rtl::OString          m_aGroup;
     110             :         // whether changes need to be saved
     111             :         bool                    m_bModified;
     112             :         // the corresponding info and job data
     113             :         PrinterInfo             m_aInfo;
     114             :     };
     115             : 
     116             :     boost::unordered_map< rtl::OUString, Printer, rtl::OUStringHash > m_aPrinters;
     117             :     PrinterInfo                         m_aGlobalDefaults;
     118             :     std::list< WatchFile >            m_aWatchFiles;
     119             :     rtl::OUString                     m_aDefaultPrinter;
     120             :     rtl::OUString                     m_aSystemPrintCommand;
     121             : 
     122             :     std::list< SystemPrintQueue >     m_aSystemPrintQueues;
     123             : 
     124             :     SystemQueueInfo*                  m_pQueueInfo;
     125             : 
     126             :     Type                              m_eType;
     127             :     bool                              m_bUseIncludeFeature;
     128             :     bool                              m_bUseJobPatch;
     129             :     rtl::OUString                     m_aSystemDefaultPaper;
     130             : 
     131             :     bool                              m_bDisableCUPS;
     132             : 
     133             :     PrinterInfoManager( Type eType = Default );
     134             : 
     135             :     virtual void initialize();
     136             : 
     137             :     // fill in font substitutions
     138             :     // the resulting boost::unordered_map maps from source to target font ids
     139             :     void fillFontSubstitutions( PrinterInfo& rInfo ) const;
     140             : 
     141             :     // fill default paper if not configured in config file
     142             :     // default paper is e.g. locale dependent
     143             :     // if a paper is already set it will not be overwritten
     144             :     void setDefaultPaper( PPDContext& rInfo ) const;
     145             : 
     146             :     void initSystemDefaultPaper();
     147             : public:
     148             : 
     149             :     // there can only be one
     150             :     static PrinterInfoManager& get();
     151             :     // only called by SalData destructor, frees the global instance
     152             :     static void release();
     153             : 
     154             :     // get PrinterInfoManager type
     155           0 :     Type getType() const { return m_eType; }
     156             : 
     157             :     // lists the names of all known printers
     158             :     void listPrinters( std::list< rtl::OUString >& rList ) const;
     159             : 
     160             :     // gets the number of known printers
     161             :     int countPrinters() const { return m_aPrinters.size(); }
     162             : 
     163             :     // gets info about a named printer
     164             :     const PrinterInfo& getPrinterInfo( const rtl::OUString& rPrinter ) const;
     165             : 
     166             :     // gets the name of the default printer
     167             :     const rtl::OUString& getDefaultPrinter() const { return m_aDefaultPrinter; }
     168             : 
     169             :     virtual void setupJobContextData( JobData& rData );
     170             : 
     171             :     // changes the info about a named printer
     172             :     virtual void changePrinterInfo( const rtl::OUString& rPrinter, const PrinterInfo& rNewInfo );
     173             : 
     174             :     // check if the printer configuration has changed
     175             :     // if bwait is true, then this method waits for eventual asynchronous
     176             :     // printer discovery to finish
     177             :     virtual bool checkPrintersChanged( bool bWait );
     178             : 
     179             :     // members for administration (->padmin)
     180             : 
     181             :     // add a named printer
     182             :     // addPrinter fails if a printer with the same name already exists
     183             :     // or the driver does not exist
     184             :     virtual bool addPrinter( const rtl::OUString& rPrinterName, const rtl::OUString& rDriverName );
     185             : 
     186             :     // remove a named printer
     187             :     // this fails if the config file belonging to this printer
     188             :     // is not writeable
     189             :     // if bCheckOnly is true, the printer is not really removed;
     190             :     // this is for checking if the removal would fail
     191             :     virtual bool removePrinter( const rtl::OUString& rPrinterName, bool bCheckOnly = false );
     192             : 
     193             :     // save the changes to all printers. this fails if there
     194             :     // is no writable config file at all
     195             :     virtual bool writePrinterConfig();
     196             : 
     197             :     // set a new default printer
     198             :     // fails if the specified printer does not exist
     199             :     virtual bool setDefaultPrinter( const rtl::OUString& rPrinterName );
     200             : 
     201             :     // primarily used internally but also by padmin
     202             :     // returns the printer queue names
     203             :     virtual const std::list< SystemPrintQueue >& getSystemPrintQueues();
     204             : 
     205             :     // similar but returnse whole commandlines
     206             :     virtual void getSystemPrintCommands( std::list< rtl::OUString >& rCommands );
     207             : 
     208             :     // abstract print command
     209             :     // returns a stdio FILE* that a postscript file may be written to
     210             :     // this may either be a regular file or the result of popen()
     211             :     virtual FILE* startSpool( const rtl::OUString& rPrinterName, bool bQuickCommand );
     212             :     // close the FILE* returned by startSpool and does the actual spooling
     213             :     // set bBanner to "false" will attempt to suppress banner printing
     214             :     // set bBanner to "true" will rely on the system default
     215             :     // returns a numerical job id
     216             :     virtual int endSpool( const rtl::OUString& rPrinterName, const rtl::OUString& rJobTitle, FILE* pFile, const JobData& rDocumentJobData, bool bBanner );
     217             : 
     218             :     // for spadmin: whether adding or removing a printer is possible
     219             :     virtual bool addOrRemovePossible() const;
     220             : 
     221             :     bool getUseIncludeFeature() const { return m_bUseIncludeFeature; }
     222             :     bool getUseJobPatch() const { return m_bUseJobPatch; }
     223             : 
     224             :     // check whether a printer's feature string contains a subfeature
     225             :     bool checkFeatureToken( const rtl::OUString& rPrinterName, const char* pToken ) const;
     226             : 
     227             :     // set m_bDisableCUPS and update printer config
     228             :     void setCUPSDisabled( bool );
     229             : 
     230             :     // gets m_bDisableCUPS, initialized from printer config
     231             :     bool isCUPSDisabled() const;
     232             : 
     233             :     virtual ~PrinterInfoManager();
     234             : };
     235             : 
     236             : } // namespace
     237             : 
     238             : #endif // _PSPRINT_PRINTERINFOMANAGER_HXX_
     239             : 
     240             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10