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