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  // only called by SalData destructor, frees the global instance
131  static void release();
132 
133  // get PrinterInfoManager type
134  Type getType() const { return m_eType; }
135 
136  // lists the names of all known printers
137  void listPrinters( std::vector< OUString >& rVector ) const;
138 
139  // gets info about a named printer
140  const PrinterInfo& getPrinterInfo( const OUString& rPrinter ) const;
141 
142  // gets the name of the default printer
143  const OUString& getDefaultPrinter() const { return m_aDefaultPrinter; }
144 
145  virtual void setupJobContextData( JobData& rData );
146 
147  // check if the printer configuration has changed
148  // if bwait is true, then this method waits for eventual asynchronous
149  // printer discovery to finish
150  virtual bool checkPrintersChanged( bool bWait );
151 
152  // abstract print command
153  // returns a stdio FILE* that a postscript file may be written to
154  // this may either be a regular file or the result of popen()
155  virtual FILE* startSpool( const OUString& rPrinterName, bool bQuickCommand );
156  // close the FILE* returned by startSpool and does the actual spooling
157  // set bBanner to "false" will attempt to suppress banner printing
158  // set bBanner to "true" will rely on the system default
159  // returns true on success
160  virtual bool endSpool( const OUString& rPrinterName, const OUString& rJobTitle, FILE* pFile, const JobData& rDocumentJobData, bool bBanner, const OUString &rFaxNumber );
161 
162  bool getUseIncludeFeature() const { return m_bUseIncludeFeature; }
163  bool getUseJobPatch() const { return m_bUseJobPatch; }
164 
165  // check whether a printer's feature string contains a subfeature
166  bool checkFeatureToken( const OUString& rPrinterName, const char* pToken ) const;
167 
168  virtual ~PrinterInfoManager();
169 };
170 
171 } // namespace
172 
173 #endif // INCLUDED_VCL_PRINTERINFOMANAGER_HXX
174 
175 /* 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