LibreOffice Module vcl (master)  1
printerinfomanager.hxx
Go to the documentation of this file.
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 <memory>
24 #include <vector>
25 #include <unordered_map>
26 #include <unordered_set>
27 
28 #include <vcl/dllapi.h>
29 #include <vcl/jobdata.hxx>
30 #include <vcl/prntypes.hxx>
31 #include <osl/time.h>
32 
33 #include <cstdio>
34 
35 namespace psp
36 {
37 
38 class SystemQueueInfo;
39 
41 {
42  // basename of PPD
43  OUString m_aDriverName;
44  // can be the queue
45  OUString m_aLocation;
46  // a user defined comment
47  OUString m_aComment;
48  // a command line to pipe a PS-file to
49  OUString m_aCommand;
50  // a command line to pipe a PS-file to in case of direct print
51  OUString m_aQuickCommand;
52  // a list of special features separated by ',' not used by psprint
53  // but assigned from the outside (currently for "fax","pdf=","autoqueue","external_dialog")
54  OUString m_aFeatures;
55  // auth-info-required, potential [domain],[username],[password] to prompt for to authenticate printing
58 
60  : JobData()
61  , meSetupMode(PrinterSetupMode::SingleJob)
62  {}
63 };
64 
66 {
67 public:
68  enum class Type { Default = 0, CUPS = 1, CPD = 2 };
69 
71  {
72  OUString m_aQueue;
73  OUString m_aLocation;
74  OUString m_aComment;
75  };
76 protected:
77  // needed for checkPrintersChanged: files (not necessarily existent)
78  // and their last known modification time
79  struct WatchFile
80  {
81  // the file in question
82  OUString m_aFilePath;
83  // the last know modification time or 0, if file did not exist
84  TimeValue m_aModified;
85  };
86 
87  // internal data to describe a printer
88  struct Printer
89  {
90  // configuration file containing this printer
91  // empty means a freshly added printer that has to be saved yet
92  OUString m_aFile;
93  // details other config files that have this printer
94  // in case of removal all have to be removed
95  std::unordered_set< OUString > m_aAlternateFiles;
96  // the corresponding info and job data
98  };
99 
100  std::unordered_map< OUString, Printer > m_aPrinters;
102  std::vector< WatchFile > m_aWatchFiles;
105 
106  std::vector< SystemPrintQueue > m_aSystemPrintQueues;
107 
108  std::unique_ptr<SystemQueueInfo>
110 
111  Type const m_eType;
115 
116  PrinterInfoManager( Type eType = Type::Default );
117 
118  virtual void initialize();
119 
120  // fill default paper if not configured in config file
121  // default paper is e.g. locale dependent
122  // if a paper is already set it will not be overwritten
123  void setDefaultPaper( PPDContext& rInfo ) const;
124 
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  Type getType() const { return m_eType; }
134 
135  // lists the names of all known printers
136  void listPrinters( std::vector< OUString >& rVector ) const;
137 
138  // gets info about a named printer
139  const PrinterInfo& getPrinterInfo( const OUString& rPrinter ) const;
140 
141  // gets the name of the default printer
142  const OUString& getDefaultPrinter() const { return m_aDefaultPrinter; }
143 
144  virtual void setupJobContextData( JobData& rData );
145 
146  // check if the printer configuration has changed
147  // if bwait is true, then this method waits for eventual asynchronous
148  // printer discovery to finish
149  virtual bool checkPrintersChanged( bool bWait );
150 
151  // abstract print command
152  // returns a stdio FILE* that a postscript file may be written to
153  // this may either be a regular file or the result of popen()
154  virtual FILE* startSpool( const OUString& rPrinterName, bool bQuickCommand );
155  // close the FILE* returned by startSpool and does the actual spooling
156  // set bBanner to "false" will attempt to suppress banner printing
157  // set bBanner to "true" will rely on the system default
158  // returns true on success
159  virtual bool endSpool( const OUString& rPrinterName, const OUString& rJobTitle, FILE* pFile, const JobData& rDocumentJobData, bool bBanner, const OUString &rFaxNumber );
160 
161  bool getUseIncludeFeature() const { return m_bUseIncludeFeature; }
162  bool getUseJobPatch() const { return m_bUseJobPatch; }
163 
164  // check whether a printer's feature string contains a subfeature
165  bool checkFeatureToken( const OUString& rPrinterName, const char* pToken ) const;
166 
167  virtual ~PrinterInfoManager();
168 };
169 
170 } // namespace
171 
172 #endif // INCLUDED_VCL_PRINTERINFOMANAGER_HXX
173 
174 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
#define VCL_DLLPUBLIC
Definition: dllapi.h:29
std::vector< WatchFile > m_aWatchFiles
PrinterSetupMode
Definition: prntypes.hxx:85
std::vector< SystemPrintQueue > m_aSystemPrintQueues
std::unordered_set< OUString > m_aAlternateFiles
std::unordered_map< OUString, Printer > m_aPrinters
std::unique_ptr< SystemQueueInfo > m_pQueueInfo
const OUString & getDefaultPrinter() const
PrinterSetupMode meSetupMode