xref: /aoo42x/main/vcl/inc/cupsmgr.hxx (revision cdf0e10c)
1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 #ifndef _PSPRINT_CUPSMGR_HXX_
29 #define _PSPRINT_CUPSMGR_HXX_
30 
31 #include "vcl/printerinfomanager.hxx"
32 #include "osl/module.h"
33 #include "osl/thread.h"
34 #include "osl/mutex.hxx"
35 
36 namespace psp
37 {
38 
39 class CUPSWrapper;
40 class PPDParser;
41 
42 struct FPtrHash
43 {
44     size_t operator()(const FILE* pPtr) const
45     { return (size_t)pPtr; }
46 };
47 
48 class CUPSManager : public PrinterInfoManager
49 {
50     CUPSWrapper*												m_pCUPSWrapper;
51     std::hash_map< FILE*, rtl::OString, FPtrHash >				m_aSpoolFiles;
52     int															m_nDests;
53     void*														m_pDests;
54     bool														m_bNewDests;
55     std::hash_map< rtl::OUString, int, rtl::OUStringHash >		m_aCUPSDestMap;
56 
57     std::hash_map< rtl::OUString, PPDContext, rtl::OUStringHash > m_aDefaultContexts;
58 
59     rtl::OString												m_aUser;
60     // this is a security risk, but the CUPS API demands
61     // to deliver a pointer to a static buffer containing
62     // the password, so this cannot be helped
63     rtl::OString												m_aPassword;
64 
65     osl::Mutex													m_aCUPSMutex;
66     oslThread													m_aDestThread;
67 
68     CUPSManager( CUPSWrapper* );
69     virtual ~CUPSManager();
70 
71     virtual void initialize();
72 
73     void getOptionsFromDocumentSetup( const JobData& rJob, bool bBanner, int& rNumOptions, void** rOptions ) const;
74     void runDests();
75 public:
76     // public for stub
77     static void runDestThread(void* pMgr);
78 
79     static CUPSManager* tryLoadCUPS();
80 
81     const PPDParser* createCUPSParser( const rtl::OUString& rPrinter );
82 	// wraps cupsGetPPD, so unlink after use !
83 
84     const char* authenticateUser( const char* );
85 
86     virtual FILE* startSpool( const rtl::OUString& rPrinterName, bool bQuickCommand );
87     virtual int endSpool( const rtl::OUString& rPrinterName, const rtl::OUString& rJobTitle, FILE* pFile, const JobData& rDocumentJobData, bool bBanner );
88     virtual void setupJobContextData( JobData& rData );
89 
90     // changes the info about a named printer
91     virtual void changePrinterInfo( const ::rtl::OUString& rPrinter, const PrinterInfo& rNewInfo );
92 
93     // check if the printer configuration has changed
94     virtual bool checkPrintersChanged( bool bWait );
95 
96     // members for administration (->padmin)
97     // disable for CUPS
98     virtual bool addPrinter( const rtl::OUString& rPrinterName, const ::rtl::OUString& rDriverName );
99     virtual bool removePrinter( const rtl::OUString& rPrinterName, bool bCheckOnly = false );
100     virtual bool writePrinterConfig();
101     virtual bool setDefaultPrinter( const rtl::OUString& rPrinterName );
102 
103     virtual bool addOrRemovePossible() const;
104 };
105 
106 } // namespace psp
107 
108 #endif
109