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