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

Generated by: LCOV version 1.10