1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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
25 #include <unordered_map>
26 #include <unordered_set>
28 #include <vcl/dllapi.h>
29 #include <vcl/jobdata.hxx>
30 #include <vcl/prntypes.hxx>
38 class SystemQueueInfo
;
40 struct PrinterInfo
: JobData
43 OUString m_aDriverName
;
46 // a user defined comment
48 // a command line to pipe a PS-file to
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")
55 // auth-info-required, potential [domain],[username],[password] to prompt for to authenticate printing
56 OUString m_aAuthInfoRequired
;
57 PrinterSetupMode meSetupMode
;
61 , meSetupMode(PrinterSetupMode::SingleJob
)
65 class VCL_DLLPUBLIC PrinterInfoManager
68 enum class Type
{ Default
= 0, CUPS
= 1, CPD
= 2 };
70 struct SystemPrintQueue
77 // needed for checkPrintersChanged: files (not necessarily existent)
78 // and their last known modification time
81 // the file in question
83 // the last know modification time or 0, if file did not exist
84 TimeValue m_aModified
;
87 // internal data to describe a printer
90 // configuration file containing this printer
91 // empty means a freshly added printer that has to be saved yet
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
100 std::unordered_map
< OUString
, Printer
> m_aPrinters
;
101 PrinterInfo m_aGlobalDefaults
;
102 std::vector
< WatchFile
> m_aWatchFiles
;
103 OUString m_aDefaultPrinter
;
104 OUString m_aSystemPrintCommand
;
106 std::vector
< SystemPrintQueue
> m_aSystemPrintQueues
;
108 std::unique_ptr
<SystemQueueInfo
>
112 bool m_bUseIncludeFeature
;
114 OUString m_aSystemDefaultPaper
;
116 PrinterInfoManager( Type eType
= Type::Default
);
118 virtual void initialize();
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;
127 // there can only be one
128 static PrinterInfoManager
& get();
129 // only called by SalData destructor, frees the global instance
130 static void release();
132 // get PrinterInfoManager type
133 Type
getType() const { return m_eType
; }
135 // lists the names of all known printers
136 void listPrinters( std::vector
< OUString
>& rVector
) const;
138 // gets info about a named printer
139 const PrinterInfo
& getPrinterInfo( const OUString
& rPrinter
) const;
141 // gets the name of the default printer
142 const OUString
& getDefaultPrinter() const { return m_aDefaultPrinter
; }
144 virtual void setupJobContextData( JobData
& rData
);
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
);
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
);
161 bool getUseIncludeFeature() const { return m_bUseIncludeFeature
; }
162 bool getUseJobPatch() const { return m_bUseJobPatch
; }
164 // check whether a printer's feature string contains a subfeature
165 bool checkFeatureToken( const OUString
& rPrinterName
, const char* pToken
) const;
167 virtual ~PrinterInfoManager();
172 #endif // INCLUDED_VCL_PRINTERINFOMANAGER_HXX
174 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */