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/prntypes.hxx>
34 #include "jobdata.hxx"
39 class SystemQueueInfo
;
41 struct PrinterInfo
: JobData
44 OUString m_aDriverName
;
47 // a user defined comment
49 // a command line to pipe a PS-file to
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")
56 // auth-info-required, potential [domain],[username],[password] to prompt for to authenticate printing
57 OUString m_aAuthInfoRequired
;
58 PrinterSetupMode meSetupMode
;
62 , meSetupMode(PrinterSetupMode::SingleJob
)
66 class VCL_DLLPUBLIC PrinterInfoManager
69 enum class Type
{ Default
= 0, CUPS
= 1, CPD
= 2 };
71 struct SystemPrintQueue
78 // needed for checkPrintersChanged: files (not necessarily existent)
79 // and their last known modification time
82 // the file in question
84 // the last know modification time or 0, if file did not exist
85 TimeValue m_aModified
;
88 // internal data to describe a printer
91 // configuration file containing this printer
92 // empty means a freshly added printer that has to be saved yet
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
101 std::unordered_map
< OUString
, Printer
> m_aPrinters
;
102 PrinterInfo m_aGlobalDefaults
;
103 std::vector
< WatchFile
> m_aWatchFiles
;
104 OUString m_aDefaultPrinter
;
105 OUString m_aSystemPrintCommand
;
107 std::vector
< SystemPrintQueue
> m_aSystemPrintQueues
;
109 std::unique_ptr
<SystemQueueInfo
>
113 OUString m_aSystemDefaultPaper
;
115 PrinterInfoManager( Type eType
= Type::Default
);
117 virtual void initialize();
119 // fill default paper if not configured in config file
120 // default paper is e.g. locale dependent
121 // if a paper is already set it will not be overwritten
122 void setDefaultPaper( PPDContext
& rInfo
) const;
126 // there can only be one
127 static PrinterInfoManager
& get();
129 // get PrinterInfoManager type
130 Type
getType() const { return m_eType
; }
132 // lists the names of all known printers
133 void listPrinters( std::vector
< OUString
>& rVector
) const;
135 // gets info about a named printer
136 const PrinterInfo
& getPrinterInfo( const OUString
& rPrinter
) const;
138 // gets the name of the default printer
139 const OUString
& getDefaultPrinter() const { return m_aDefaultPrinter
; }
141 virtual void setupJobContextData( JobData
& rData
);
143 // check if the printer configuration has changed
144 // if bwait is true, then this method waits for eventual asynchronous
145 // printer discovery to finish
146 virtual bool checkPrintersChanged( bool bWait
);
148 // abstract print command
149 // returns a stdio FILE* that a postscript file may be written to
150 // this may either be a regular file or the result of popen()
151 virtual FILE* startSpool( const OUString
& rPrinterName
, bool bQuickCommand
);
152 // close the FILE* returned by startSpool and does the actual spooling
153 // set bBanner to "false" will attempt to suppress banner printing
154 // set bBanner to "true" will rely on the system default
155 // returns true on success
156 virtual bool endSpool( const OUString
& rPrinterName
, const OUString
& rJobTitle
, FILE* pFile
, const JobData
& rDocumentJobData
, bool bBanner
, const OUString
&rFaxNumber
);
158 // check whether a printer's feature string contains a subfeature
159 bool checkFeatureToken( const OUString
& rPrinterName
, std::string_view pToken
) const;
161 virtual ~PrinterInfoManager();
166 #endif // INCLUDED_VCL_PRINTERINFOMANAGER_HXX
168 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */