Branch libreoffice-5-0-4
[LibreOffice.git] / vcl / inc / cupsmgr.hxx
blob96b1c80098d1cc9d2280caea3d117dd4b4f9404c
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_INC_CUPSMGR_HXX
21 #define INCLUDED_VCL_INC_CUPSMGR_HXX
23 #include "vcl/printerinfomanager.hxx"
24 #include "osl/module.h"
25 #include "osl/thread.h"
26 #include "osl/mutex.hxx"
28 namespace psp
31 class PPDParser;
33 struct FPtrHash
35 size_t operator()(const FILE* pPtr) const
36 { return reinterpret_cast<size_t>(pPtr); }
39 class CUPSManager : public PrinterInfoManager
41 std::unordered_map< FILE*, OString, FPtrHash > m_aSpoolFiles;
42 int m_nDests;
43 void* m_pDests;
44 bool m_bNewDests;
45 std::unordered_map< OUString, int, OUStringHash > m_aCUPSDestMap;
47 std::unordered_map< OUString, PPDContext, OUStringHash > m_aDefaultContexts;
49 OString m_aUser;
50 /** this is a security risk, but the CUPS API demands
51 to deliver a pointer to a static buffer containing
52 the password, so this cannot be helped*/
53 OString m_aPassword;
55 osl::Mutex m_aCUPSMutex;
56 oslThread m_aDestThread;
58 osl::Mutex m_aGetPPDMutex;
59 bool m_bPPDThreadRunning;
61 struct PendingJob
63 OUString printerName;
64 OUString jobTitle;
65 JobData jobData;
66 bool banner;
67 OUString faxNumber;
68 OString file;
69 PendingJob( const OUString& printerName_, const OUString& jobTitle_, const JobData& jobData_,
70 bool banner_, const OUString& faxNumber_, const OString& file_ )
71 : printerName( printerName_ ), jobTitle( jobTitle_ ), jobData( jobData_ ), banner( banner_ ), faxNumber( faxNumber_ ), file( file_ )
73 PendingJob() : banner( false ) {}
75 std::list< PendingJob > pendingJobs;
76 bool batchMode;
78 CUPSManager();
79 virtual ~CUPSManager();
81 virtual void initialize() SAL_OVERRIDE;
83 static void getOptionsFromDocumentSetup( const JobData& rJob, bool bBanner, int& rNumOptions, void** rOptions );
84 void runDests();
85 OString threadedCupsGetPPD(const char* pPrinter);
87 bool processPendingJobs();
88 bool printJobs( const PendingJob& job, const std::vector< OString >& files );
89 public:
90 static void runDestThread(void* pMgr);
92 static CUPSManager* tryLoadCUPS();
94 /// wraps cupsGetPPD, so unlink after use !
95 const PPDParser* createCUPSParser( const OUString& rPrinter );
97 const char* authenticateUser( const char* );
99 virtual FILE* startSpool( const OUString& rPrinterName, bool bQuickCommand ) SAL_OVERRIDE;
100 virtual bool endSpool( const OUString& rPrinterName, const OUString& rJobTitle, FILE* pFile, const JobData& rDocumentJobData, bool bBanner, const OUString& rFaxNumber ) SAL_OVERRIDE;
101 virtual void setupJobContextData( JobData& rData ) SAL_OVERRIDE;
103 virtual bool startBatchPrint() SAL_OVERRIDE;
104 virtual bool flushBatchPrint() SAL_OVERRIDE;
105 virtual bool supportsBatchPrint() const SAL_OVERRIDE;
107 /// changes the info about a named printer
108 virtual void changePrinterInfo( const OUString& rPrinter, const PrinterInfo& rNewInfo ) SAL_OVERRIDE;
110 /// check if the printer configuration has changed
111 virtual bool checkPrintersChanged( bool bWait ) SAL_OVERRIDE;
113 // members for administration
114 // disable for CUPS
115 virtual bool addPrinter( const OUString& rPrinterName, const OUString& rDriverName ) SAL_OVERRIDE;
116 virtual bool removePrinter( const OUString& rPrinterName, bool bCheckOnly = false ) SAL_OVERRIDE;
117 virtual bool writePrinterConfig() SAL_OVERRIDE;
118 virtual bool setDefaultPrinter( const OUString& rPrinterName ) SAL_OVERRIDE;
121 } // namespace psp
123 #endif
125 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */