diff options
Diffstat (limited to 'vcl/unx/generic/printer/cupsmgr.cxx')
-rw-r--r-- | vcl/unx/generic/printer/cupsmgr.cxx | 105 |
1 files changed, 15 insertions, 90 deletions
diff --git a/vcl/unx/generic/printer/cupsmgr.cxx b/vcl/unx/generic/printer/cupsmgr.cxx index 71464d7e9157..2da3bf90e4fc 100644 --- a/vcl/unx/generic/printer/cupsmgr.cxx +++ b/vcl/unx/generic/printer/cupsmgr.cxx @@ -183,8 +183,7 @@ CUPSManager::CUPSManager() : m_nDests( 0 ), m_pDests( nullptr ), m_bNewDests( false ), - m_bPPDThreadRunning( false ), - batchMode( false ) + m_bPPDThreadRunning( false ) { m_aDestThread = osl_createThread( run_dest_thread_stub, this ); } @@ -626,6 +625,8 @@ bool CUPSManager::endSpool( const OUString& rPrintername, const OUString& rJobTi rDocumentJobData.m_nCopies ); + int nJobID = 0; + osl::MutexGuard aGuard( m_aCUPSMutex ); std::unordered_map< OUString, int, OUStringHash >::iterator dest_it = @@ -637,106 +638,32 @@ bool CUPSManager::endSpool( const OUString& rPrintername, const OUString& rJobTi } std::unordered_map< FILE*, OString, FPtrHash >::const_iterator it = m_aSpoolFiles.find( pFile ); - if( it == m_aSpoolFiles.end() ) - return false; - fclose( pFile ); - PendingJob job( rPrintername, rJobTitle, rDocumentJobData, bBanner, rFaxNumber, it->second ); - m_aSpoolFiles.erase( pFile ); - pendingJobs.push_back( job ); - if( !batchMode ) // process immediately, otherwise will be handled by flushBatchPrint() - return processPendingJobs(); - return true; -} - -bool CUPSManager::startBatchPrint() -{ - batchMode = true; - return true; -} - -bool CUPSManager::supportsBatchPrint() const -{ - return true; -} - -bool CUPSManager::flushBatchPrint() -{ - osl::MutexGuard aGuard( m_aCUPSMutex ); - batchMode = false; // reset the batch print mode - return processPendingJobs(); -} - -bool CUPSManager::processPendingJobs() -{ - // Print all jobs that have the same data using one CUPS call (i.e. merge all jobs that differ only in files to print). - PendingJob currentJobData; - bool first = true; - std::vector< OString > files; - bool ok = true; - while( !pendingJobs.empty()) - { - if( first ) - { - currentJobData = pendingJobs.front(); - first = false; - } - else if( currentJobData.printerName != pendingJobs.front().printerName - || currentJobData.jobTitle != pendingJobs.front().jobTitle - || currentJobData.jobData != pendingJobs.front().jobData - || currentJobData.banner != pendingJobs.front().banner ) - { - if( !printJobs( currentJobData, files )) - ok = false; - files.clear(); - currentJobData = pendingJobs.front(); - } - files.push_back( pendingJobs.front().file ); - pendingJobs.pop_front(); - } - if( !first ) + if( it != m_aSpoolFiles.end() ) { - if( !printJobs( currentJobData, files )) // print the last batch - ok = false; - } - return ok; -} - -bool CUPSManager::printJobs( const PendingJob& job, const std::vector< OString >& files ) -{ - std::unordered_map< OUString, int, OUStringHash >::iterator dest_it = - m_aCUPSDestMap.find( job.printerName ); - + fclose( pFile ); rtl_TextEncoding aEnc = osl_getThreadTextEncoding(); // setup cups options int nNumOptions = 0; cups_option_t* pOptions = nullptr; - getOptionsFromDocumentSetup( job.jobData, job.banner, nNumOptions, reinterpret_cast<void**>(&pOptions) ); + getOptionsFromDocumentSetup( rDocumentJobData, bBanner, nNumOptions, reinterpret_cast<void**>(&pOptions) ); - OString sJobName(OUStringToOString(job.jobTitle, aEnc)); + OString sJobName(OUStringToOString(rJobTitle, aEnc)); //fax4CUPS, "the job name will be dialled for you" //so override the jobname with the desired number - if (!job.faxNumber.isEmpty()) + if (!rFaxNumber.isEmpty()) { - sJobName = OUStringToOString(job.faxNumber, aEnc); + sJobName = OUStringToOString(rFaxNumber, aEnc); } cups_dest_t* pDest = static_cast<cups_dest_t*>(m_pDests) + dest_it->second; - - std::vector< const char* > fnames; - for( std::vector< OString >::const_iterator it = files.begin(); - it != files.end(); - ++it ) - fnames.push_back( it->getStr()); - - int nJobID = cupsPrintFiles(pDest->name, - fnames.size(), - fnames.data(), + nJobID = cupsPrintFile(pDest->name, + it->second.getStr(), sJobName.getStr(), nNumOptions, pOptions); SAL_INFO("vcl.unx.print", "cupsPrintFile( " << pDest->name << ", " - << ( fnames.size() == 1 ? files.front() : OString::number( fnames.size()) ).getStr() << ", " << sJobName << ", " << nNumOptions + << it->second << ", " << rJobTitle << ", " << nNumOptions << ", " << pOptions << " ) returns " << nJobID); for( int n = 0; n < nNumOptions; n++ ) SAL_INFO("vcl.unx.print", @@ -748,13 +675,11 @@ bool CUPSManager::printJobs( const PendingJob& job, const std::vector< OString > system( aCmd.getStr() ); #endif - for( std::vector< OString >::const_iterator it = files.begin(); - it != files.end(); - ++it ) - unlink( it->getStr()); - + unlink( it->second.getStr() ); + m_aSpoolFiles.erase( pFile ); if( pOptions ) cupsFreeOptions( nNumOptions, pOptions ); + } return nJobID != 0; } |