xref: /aoo4110/main/vcl/inc/cupsmgr.hxx (revision b1cdbd2c)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 #ifndef _PSPRINT_CUPSMGR_HXX_
25 #define _PSPRINT_CUPSMGR_HXX_
26 
27 #include "vcl/printerinfomanager.hxx"
28 #include "osl/module.h"
29 #include "osl/thread.h"
30 #include "osl/mutex.hxx"
31 
32 namespace psp
33 {
34 
35 class CUPSWrapper;
36 class PPDParser;
37 
38 struct FPtrHash
39 {
operator ()psp::FPtrHash40     size_t operator()(const FILE* pPtr) const
41     { return (size_t)pPtr; }
42 };
43 
44 class CUPSManager : public PrinterInfoManager
45 {
46     CUPSWrapper*												m_pCUPSWrapper;
47     std::hash_map< FILE*, rtl::OString, FPtrHash >				m_aSpoolFiles;
48     int															m_nDests;
49     void*														m_pDests;
50     bool														m_bNewDests;
51     std::hash_map< rtl::OUString, int, rtl::OUStringHash >		m_aCUPSDestMap;
52 
53     std::hash_map< rtl::OUString, PPDContext, rtl::OUStringHash > m_aDefaultContexts;
54 
55     rtl::OString												m_aUser;
56     // this is a security risk, but the CUPS API demands
57     // to deliver a pointer to a static buffer containing
58     // the password, so this cannot be helped
59     rtl::OString												m_aPassword;
60 
61     osl::Mutex													m_aCUPSMutex;
62     oslThread													m_aDestThread;
63 
64     CUPSManager( CUPSWrapper* );
65     virtual ~CUPSManager();
66 
67     virtual void initialize();
68 
69     void getOptionsFromDocumentSetup( const JobData& rJob, bool bBanner, int& rNumOptions, void** rOptions ) const;
70     void runDests();
71 public:
72     // public for stub
73     static void runDestThread(void* pMgr);
74 
75     static CUPSManager* tryLoadCUPS();
76 
77     const PPDParser* createCUPSParser( const rtl::OUString& rPrinter );
78 	// wraps cupsGetPPD, so unlink after use !
79 
80     const char* authenticateUser( const char* );
81 
82     virtual FILE* startSpool( const rtl::OUString& rPrinterName, bool bQuickCommand );
83     virtual int endSpool( const rtl::OUString& rPrinterName, const rtl::OUString& rJobTitle, FILE* pFile, const JobData& rDocumentJobData, bool bBanner );
84     virtual void setupJobContextData( JobData& rData );
85 
86     // changes the info about a named printer
87     virtual void changePrinterInfo( const ::rtl::OUString& rPrinter, const PrinterInfo& rNewInfo );
88 
89     // check if the printer configuration has changed
90     virtual bool checkPrintersChanged( bool bWait );
91 
92     // members for administration (->padmin)
93     // disable for CUPS
94     virtual bool addPrinter( const rtl::OUString& rPrinterName, const ::rtl::OUString& rDriverName );
95     virtual bool removePrinter( const rtl::OUString& rPrinterName, bool bCheckOnly = false );
96     virtual bool writePrinterConfig();
97     virtual bool setDefaultPrinter( const rtl::OUString& rPrinterName );
98 
99     virtual bool addOrRemovePossible() const;
100 };
101 
102 } // namespace psp
103 
104 #endif
105