LCOV - code coverage report
Current view: top level - include/vcl - printerinfomanager.hxx (source / functions) Hit Total Coverage
Test: commit e02a6cb2c3e2b23b203b422e4e0680877f232636 Lines: 0 11 0.0 %
Date: 2014-04-14 Functions: 0 21 0.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 INCLUDED_VCL_PRINTERINFOMANAGER_HXX
      21             : #define INCLUDED_VCL_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           0 : 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             : 
      54           0 :     PrinterInfo() :
      55           0 :             JobData()
      56           0 :     {}
      57             : };
      58             : 
      59             : class VCL_DLLPUBLIC PrinterInfoManager
      60             : {
      61             : public:
      62             :     enum Type { Default = 0, CUPS = 1 };
      63             : 
      64           0 :     struct SystemPrintQueue
      65             :     {
      66             :         OUString       m_aQueue;
      67             :         OUString       m_aLocation;
      68             :         OUString       m_aComment;
      69             :     };
      70             : protected:
      71             :     // needed for checkPrintersChanged: files (not necessarily existant)
      72             :     // and their last known modification time
      73           0 :     struct WatchFile
      74             :     {
      75             :         // the file in question
      76             :         OUString         m_aFilePath;
      77             :         // the last know modification time or 0, if file did not exist
      78             :         TimeValue               m_aModified;
      79             :     };
      80             : 
      81             :     // internal data to describe a printer
      82           0 :     struct Printer
      83             :     {
      84             :         // configuration file containing this printer
      85             :         // empty means a freshly added printer that has to be saved yet
      86             :         OUString         m_aFile;
      87             :         // details other config files that have this printer
      88             :         // in case of removal all have to be removed
      89             :         std::list< OUString > m_aAlternateFiles;
      90             :         // group in m_aFile containing the printer
      91             :         // this must be unique over all configuration files
      92             :         // it usually should be the printer name
      93             :         OString          m_aGroup;
      94             :         // whether changes need to be saved
      95             :         bool                    m_bModified;
      96             :         // the corresponding info and job data
      97             :         PrinterInfo             m_aInfo;
      98             :     };
      99             : 
     100             :     boost::unordered_map< OUString, Printer, OUStringHash > m_aPrinters;
     101             :     PrinterInfo                         m_aGlobalDefaults;
     102             :     std::list< WatchFile >            m_aWatchFiles;
     103             :     OUString                     m_aDefaultPrinter;
     104             :     OUString                     m_aSystemPrintCommand;
     105             : 
     106             :     std::list< SystemPrintQueue >     m_aSystemPrintQueues;
     107             : 
     108             :     SystemQueueInfo*                  m_pQueueInfo;
     109             : 
     110             :     Type                              m_eType;
     111             :     bool                              m_bUseIncludeFeature;
     112             :     bool                              m_bUseJobPatch;
     113             :     OUString                     m_aSystemDefaultPaper;
     114             : 
     115             :     PrinterInfoManager( Type eType = Default );
     116             : 
     117             :     virtual void initialize();
     118             : 
     119             :     // fill default paper if not configured in config file
     120             :     // default paper is e.g. locale dependent
     121             :     // if a paper is already set it will not be overwritten
     122             :     void setDefaultPaper( PPDContext& rInfo ) const;
     123             : 
     124             :     void initSystemDefaultPaper();
     125             : public:
     126             : 
     127             :     // there can only be one
     128             :     static PrinterInfoManager& get();
     129             :     // only called by SalData destructor, frees the global instance
     130             :     static void release();
     131             : 
     132             :     // get PrinterInfoManager type
     133           0 :     Type getType() const { return m_eType; }
     134             : 
     135             :     // lists the names of all known printers
     136             :     void listPrinters( std::list< OUString >& rList ) const;
     137             : 
     138             :     // gets the number of known printers
     139             :     int countPrinters() const { return m_aPrinters.size(); }
     140             : 
     141             :     // gets info about a named printer
     142             :     const PrinterInfo& getPrinterInfo( const OUString& rPrinter ) const;
     143             : 
     144             :     // gets the name of the default printer
     145           0 :     const OUString& getDefaultPrinter() const { return m_aDefaultPrinter; }
     146             : 
     147             :     virtual void setupJobContextData( JobData& rData );
     148             : 
     149             :     // changes the info about a named printer
     150             :     virtual void changePrinterInfo( const OUString& rPrinter, const PrinterInfo& rNewInfo );
     151             : 
     152             :     // check if the printer configuration has changed
     153             :     // if bwait is true, then this method waits for eventual asynchronous
     154             :     // printer discovery to finish
     155             :     virtual bool checkPrintersChanged( bool bWait );
     156             : 
     157             :     // members for administration
     158             : 
     159             :     // add a named printer
     160             :     // addPrinter fails if a printer with the same name already exists
     161             :     // or the driver does not exist
     162             :     virtual bool addPrinter( const OUString& rPrinterName, const OUString& rDriverName );
     163             : 
     164             :     // remove a named printer
     165             :     // this fails if the config file belonging to this printer
     166             :     // is not writeable
     167             :     // if bCheckOnly is true, the printer is not really removed;
     168             :     // this is for checking if the removal would fail
     169             :     virtual bool removePrinter( const OUString& rPrinterName, bool bCheckOnly = false );
     170             : 
     171             :     // save the changes to all printers. this fails if there
     172             :     // is no writable config file at all
     173             :     virtual bool writePrinterConfig();
     174             : 
     175             :     // set a new default printer
     176             :     // fails if the specified printer does not exist
     177             :     virtual bool setDefaultPrinter( const OUString& rPrinterName );
     178             : 
     179             :     // primarily used internally
     180             :     // returns the printer queue names
     181             :     virtual const std::list< SystemPrintQueue >& getSystemPrintQueues();
     182             : 
     183             :     // similar but returnse whole commandlines
     184             :     virtual void getSystemPrintCommands( std::list< OUString >& rCommands );
     185             : 
     186             :     // abstract print command
     187             :     // returns a stdio FILE* that a postscript file may be written to
     188             :     // this may either be a regular file or the result of popen()
     189             :     virtual FILE* startSpool( const OUString& rPrinterName, bool bQuickCommand );
     190             :     // close the FILE* returned by startSpool and does the actual spooling
     191             :     // set bBanner to "false" will attempt to suppress banner printing
     192             :     // set bBanner to "true" will rely on the system default
     193             :     // returns true on success
     194             :     virtual bool endSpool( const OUString& rPrinterName, const OUString& rJobTitle, FILE* pFile, const JobData& rDocumentJobData, bool bBanner, const OUString &rFaxNumber );
     195             : 
     196           0 :     bool getUseIncludeFeature() const { return m_bUseIncludeFeature; }
     197           0 :     bool getUseJobPatch() const { return m_bUseJobPatch; }
     198             : 
     199             :     // check whether a printer's feature string contains a subfeature
     200             :     bool checkFeatureToken( const OUString& rPrinterName, const char* pToken ) const;
     201             : 
     202             :     virtual ~PrinterInfoManager();
     203             : };
     204             : 
     205             : } // namespace
     206             : 
     207             : #endif // INCLUDED_VCL_PRINTERINFOMANAGER_HXX
     208             : 
     209             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10