LCOV - code coverage report
Current view: top level - vcl/inc/vcl - printerinfomanager.hxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 6 8 75.0 %
Date: 2012-08-25 Functions: 8 16 50.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 5 36 13.9 %

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

Generated by: LCOV version 1.10