Version 4.3.0.0.beta1, tag libreoffice-4.3.0.0.beta1
[LibreOffice.git] / include / vcl / printerinfomanager.hxx
blob66d5d282f23ac6b24638213679b272d1eb28080d
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 <boost/unordered_map.hpp>
24 #include <list>
26 #include <vcl/dllapi.h>
27 #include <vcl/helper.hxx>
28 #include <vcl/jobdata.hxx>
29 #include <osl/file.hxx>
31 #include <cstdio>
33 namespace psp
36 class SystemQueueInfo;
38 struct PrinterInfo : JobData
40 // basename of PPD
41 OUString m_aDriverName;
42 // can be the queue
43 OUString m_aLocation;
44 // a user defined comment
45 OUString m_aComment;
46 // a command line to pipe a PS-file to
47 OUString m_aCommand;
48 // a command line to pipe a PS-file to in case of direct print
49 OUString m_aQuickCommand;
50 // a list of special features separated by ',' not used by psprint
51 // but assigned from the outside (currently for "fax","pdf=","autoqueue","external_dialog")
52 OUString m_aFeatures;
54 PrinterInfo() :
55 JobData()
59 class VCL_DLLPUBLIC PrinterInfoManager
61 public:
62 enum Type { Default = 0, CUPS = 1 };
64 struct SystemPrintQueue
66 OUString m_aQueue;
67 OUString m_aLocation;
68 OUString m_aComment;
70 protected:
71 // needed for checkPrintersChanged: files (not necessarily existent)
72 // and their last known modification time
73 struct WatchFile
75 // the file in question
76 OUString m_aFilePath;
77 // the last know modification time or 0, if file did not exist
78 TimeValue m_aModified;
81 // internal data to describe a printer
82 struct Printer
84 // configuration file containing this printer
85 // empty means a freshly added printer that has to be saved yet
86 OUString m_aFile;
87 // details other config files that have this printer
88 // in case of removal all have to be removed
89 std::list< OUString > m_aAlternateFiles;
90 // group in m_aFile containing the printer
91 // this must be unique over all configuration files
92 // it usually should be the printer name
93 OString m_aGroup;
94 // whether changes need to be saved
95 bool m_bModified;
96 // the corresponding info and job data
97 PrinterInfo m_aInfo;
100 boost::unordered_map< OUString, Printer, OUStringHash > m_aPrinters;
101 PrinterInfo m_aGlobalDefaults;
102 std::list< WatchFile > m_aWatchFiles;
103 OUString m_aDefaultPrinter;
104 OUString m_aSystemPrintCommand;
106 std::list< SystemPrintQueue > m_aSystemPrintQueues;
108 SystemQueueInfo* m_pQueueInfo;
110 Type m_eType;
111 bool m_bUseIncludeFeature;
112 bool m_bUseJobPatch;
113 OUString m_aSystemDefaultPaper;
115 PrinterInfoManager( Type eType = 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;
124 void initSystemDefaultPaper();
125 public:
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::list< OUString >& rList ) const;
138 // gets the number of known printers
139 int countPrinters() const { return m_aPrinters.size(); }
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 // changes the info about a named printer
150 virtual void changePrinterInfo( const OUString& rPrinter, const PrinterInfo& rNewInfo );
152 // check if the printer configuration has changed
153 // if bwait is true, then this method waits for eventual asynchronous
154 // printer discovery to finish
155 virtual bool checkPrintersChanged( bool bWait );
157 // members for administration
159 // add a named printer
160 // addPrinter fails if a printer with the same name already exists
161 // or the driver does not exist
162 virtual bool addPrinter( const OUString& rPrinterName, const OUString& rDriverName );
164 // remove a named printer
165 // this fails if the config file belonging to this printer
166 // is not writeable
167 // if bCheckOnly is true, the printer is not really removed;
168 // this is for checking if the removal would fail
169 virtual bool removePrinter( const OUString& rPrinterName, bool bCheckOnly = false );
171 // save the changes to all printers. this fails if there
172 // is no writable config file at all
173 virtual bool writePrinterConfig();
175 // set a new default printer
176 // fails if the specified printer does not exist
177 virtual bool setDefaultPrinter( const OUString& rPrinterName );
179 // primarily used internally
180 // returns the printer queue names
181 virtual const std::list< SystemPrintQueue >& getSystemPrintQueues();
183 // similar but returnse whole commandlines
184 virtual void getSystemPrintCommands( std::list< OUString >& rCommands );
186 // abstract print command
187 // returns a stdio FILE* that a postscript file may be written to
188 // this may either be a regular file or the result of popen()
189 virtual FILE* startSpool( const OUString& rPrinterName, bool bQuickCommand );
190 // close the FILE* returned by startSpool and does the actual spooling
191 // set bBanner to "false" will attempt to suppress banner printing
192 // set bBanner to "true" will rely on the system default
193 // returns true on success
194 virtual bool endSpool( const OUString& rPrinterName, const OUString& rJobTitle, FILE* pFile, const JobData& rDocumentJobData, bool bBanner, const OUString &rFaxNumber );
196 bool getUseIncludeFeature() const { return m_bUseIncludeFeature; }
197 bool getUseJobPatch() const { return m_bUseJobPatch; }
199 // check whether a printer's feature string contains a subfeature
200 bool checkFeatureToken( const OUString& rPrinterName, const char* pToken ) const;
202 virtual ~PrinterInfoManager();
205 } // namespace
207 #endif // INCLUDED_VCL_PRINTERINFOMANAGER_HXX
209 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */