Version 5.4.3.2, tag libreoffice-5.4.3.2
[LibreOffice.git] / vcl / inc / printerinfomanager.hxx
blob0bfeab7289d299aa060833e1de5091c878f7c4ec
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #ifndef INCLUDED_VCL_PRINTERINFOMANAGER_HXX
21 #define INCLUDED_VCL_PRINTERINFOMANAGER_HXX
23 #include <memory>
24 #include <list>
25 #include <unordered_map>
27 #include <vcl/dllapi.h>
28 #include <vcl/jobdata.hxx>
29 #include <osl/file.hxx>
30 #include <unx/helper.hxx>
32 #include <cstdio>
34 namespace psp
37 class SystemQueueInfo;
39 struct PrinterInfo : JobData
41 // basename of PPD
42 OUString m_aDriverName;
43 // can be the queue
44 OUString m_aLocation;
45 // a user defined comment
46 OUString m_aComment;
47 // a command line to pipe a PS-file to
48 OUString m_aCommand;
49 // a command line to pipe a PS-file to in case of direct print
50 OUString m_aQuickCommand;
51 // a list of special features separated by ',' not used by psprint
52 // but assigned from the outside (currently for "fax","pdf=","autoqueue","external_dialog")
53 OUString m_aFeatures;
54 bool m_bPapersizeFromSetup;
56 PrinterInfo()
57 : JobData()
58 , m_bPapersizeFromSetup(false)
62 class VCL_DLLPUBLIC PrinterInfoManager
64 public:
65 enum class Type { Default = 0, CUPS = 1 };
67 struct SystemPrintQueue
69 OUString m_aQueue;
70 OUString m_aLocation;
71 OUString m_aComment;
73 protected:
74 // needed for checkPrintersChanged: files (not necessarily existent)
75 // and their last known modification time
76 struct WatchFile
78 // the file in question
79 OUString m_aFilePath;
80 // the last know modification time or 0, if file did not exist
81 TimeValue m_aModified;
84 // internal data to describe a printer
85 struct Printer
87 // configuration file containing this printer
88 // empty means a freshly added printer that has to be saved yet
89 OUString m_aFile;
90 // details other config files that have this printer
91 // in case of removal all have to be removed
92 std::list< OUString > m_aAlternateFiles;
93 // group in m_aFile containing the printer
94 // this must be unique over all configuration files
95 // it usually should be the printer name
96 OString m_aGroup;
97 // whether changes need to be saved
98 bool m_bModified;
99 // the corresponding info and job data
100 PrinterInfo m_aInfo;
103 std::unordered_map< OUString, Printer, OUStringHash > m_aPrinters;
104 PrinterInfo m_aGlobalDefaults;
105 std::list< WatchFile > m_aWatchFiles;
106 OUString m_aDefaultPrinter;
107 OUString m_aSystemPrintCommand;
109 std::list< SystemPrintQueue > m_aSystemPrintQueues;
111 std::unique_ptr<SystemQueueInfo>
112 m_pQueueInfo;
114 Type m_eType;
115 bool m_bUseIncludeFeature;
116 bool m_bUseJobPatch;
117 OUString m_aSystemDefaultPaper;
119 PrinterInfoManager( Type eType = Type::Default );
121 virtual void initialize();
123 // fill default paper if not configured in config file
124 // default paper is e.g. locale dependent
125 // if a paper is already set it will not be overwritten
126 void setDefaultPaper( PPDContext& rInfo ) const;
128 public:
130 // there can only be one
131 static PrinterInfoManager& get();
132 // only called by SalData destructor, frees the global instance
133 static void release();
135 // get PrinterInfoManager type
136 Type getType() const { return m_eType; }
138 // lists the names of all known printers
139 void listPrinters( std::list< OUString >& rList ) const;
141 // gets info about a named printer
142 const PrinterInfo& getPrinterInfo( const OUString& rPrinter ) const;
144 // gets the name of the default printer
145 const OUString& getDefaultPrinter() const { return m_aDefaultPrinter; }
147 virtual void setupJobContextData( JobData& rData );
149 // check if the printer configuration has changed
150 // if bwait is true, then this method waits for eventual asynchronous
151 // printer discovery to finish
152 virtual bool checkPrintersChanged( bool bWait );
154 // members for administration
156 // add a named printer
157 // addPrinter fails if a printer with the same name already exists
158 // or the driver does not exist
159 virtual bool addPrinter( const OUString& rPrinterName, const OUString& rDriverName );
161 // remove a named printer
162 // this fails if the config file belonging to this printer
163 // is not writeable
164 // if bCheckOnly is true, the printer is not really removed;
165 // this is for checking if the removal would fail
166 virtual bool removePrinter( const OUString& rPrinterName, bool bCheckOnly );
168 // save the changes to all printers. this fails if there
169 // is no writable config file at all
170 virtual bool writePrinterConfig();
172 // set a new default printer
173 // fails if the specified printer does not exist
174 virtual bool setDefaultPrinter( const OUString& rPrinterName );
176 // abstract print command
177 // returns a stdio FILE* that a postscript file may be written to
178 // this may either be a regular file or the result of popen()
179 virtual FILE* startSpool( const OUString& rPrinterName, bool bQuickCommand );
180 // close the FILE* returned by startSpool and does the actual spooling
181 // set bBanner to "false" will attempt to suppress banner printing
182 // set bBanner to "true" will rely on the system default
183 // returns true on success
184 virtual bool endSpool( const OUString& rPrinterName, const OUString& rJobTitle, FILE* pFile, const JobData& rDocumentJobData, bool bBanner, const OUString &rFaxNumber );
186 bool getUseIncludeFeature() const { return m_bUseIncludeFeature; }
187 bool getUseJobPatch() const { return m_bUseJobPatch; }
189 // check whether a printer's feature string contains a subfeature
190 bool checkFeatureToken( const OUString& rPrinterName, const char* pToken ) const;
192 virtual ~PrinterInfoManager();
195 } // namespace
197 #endif // INCLUDED_VCL_PRINTERINFOMANAGER_HXX
199 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */