Lines 73-83
Link Here
|
73 |
#include <osl/thread.hxx> |
73 |
#include <osl/thread.hxx> |
74 |
#include <osl/mutex.hxx> |
74 |
#include <osl/mutex.hxx> |
75 |
|
75 |
|
|
|
76 |
#ifdef MACOSX |
77 |
#include <sys/stat.h> |
78 |
#endif |
79 |
|
76 |
// filename of configuration files |
80 |
// filename of configuration files |
77 |
#define PRINT_FILENAME "psprint.conf" |
81 |
#define PRINT_FILENAME "psprint.conf" |
78 |
// the group of the global defaults |
82 |
// the group of the global defaults |
79 |
#define GLOBAL_DEFAULTS_GROUP "__Global_Printer_Defaults__" |
83 |
#define GLOBAL_DEFAULTS_GROUP "__Global_Printer_Defaults__" |
80 |
|
84 |
|
|
|
85 |
#ifdef MACOSX |
86 |
// filename of CUPS config file |
87 |
#define MACXP_CUPS_CONF_FILENAME "printers.conf" |
88 |
#define MACXP_CUPS_CONF_DIR "/etc/cups/" |
89 |
#endif |
90 |
|
81 |
using namespace psp; |
91 |
using namespace psp; |
82 |
using namespace rtl; |
92 |
using namespace rtl; |
83 |
using namespace osl; |
93 |
using namespace osl; |
Lines 165-171
Link Here
|
165 |
if( ! bChanged ) |
175 |
if( ! bChanged ) |
166 |
bChanged = m_pQueueInfo->hasChanged(); |
176 |
bChanged = m_pQueueInfo->hasChanged(); |
167 |
if( bChanged ) |
177 |
if( bChanged ) |
|
|
178 |
{ |
179 |
#ifdef MACOSX |
180 |
// For Mac OS X 10.2, the user may change print queues via the Print Center |
181 |
// at any point. Therefore, we need to completely requery the system |
182 |
// for print queues when our watch file changes. |
183 |
sal_Int32 applePrintSystem; |
184 |
|
185 |
applePrintSystem = macxp_GetSystemPrintMethod(); |
186 |
if ( applePrintSystem == kApplePrintingCUPS ) |
187 |
m_aSystemPrintQueues.clear(); |
188 |
#endif |
168 |
initialize(); |
189 |
initialize(); |
|
|
190 |
} |
169 |
|
191 |
|
170 |
return bChanged; |
192 |
return bChanged; |
171 |
} |
193 |
} |
Lines 174-184
Link Here
|
174 |
|
196 |
|
175 |
void PrinterInfoManager::initialize() |
197 |
void PrinterInfoManager::initialize() |
176 |
{ |
198 |
{ |
|
|
199 |
#ifdef MACOSX |
200 |
sal_Int32 applePrintSystem; |
201 |
#endif |
177 |
rtl_TextEncoding aEncoding = gsl_getSystemTextEncoding(); |
202 |
rtl_TextEncoding aEncoding = gsl_getSystemTextEncoding(); |
178 |
m_aPrinters.clear(); |
203 |
m_aPrinters.clear(); |
179 |
m_aWatchFiles.clear(); |
204 |
m_aWatchFiles.clear(); |
180 |
OUString aDefaultPrinter; |
205 |
OUString aDefaultPrinter; |
181 |
|
206 |
|
|
|
207 |
#ifdef MACOSX |
208 |
// Discover the print system to use on Mac OS X/Darwin |
209 |
applePrintSystem = macxp_GetSystemPrintMethod(); |
210 |
#endif |
211 |
|
182 |
// first initialize the global defaults |
212 |
// first initialize the global defaults |
183 |
// have to iterate over all possible files |
213 |
// have to iterate over all possible files |
184 |
// there should be only one global setup section in all |
214 |
// there should be only one global setup section in all |
Lines 220-226
Link Here
|
220 |
m_aGlobalDefaults.m_eOrientation = aValue.EqualsIgnoreCaseAscii( "Landscape" ) ? orientation::Landscape : orientation::Portrait; |
250 |
m_aGlobalDefaults.m_eOrientation = aValue.EqualsIgnoreCaseAscii( "Landscape" ) ? orientation::Landscape : orientation::Portrait; |
221 |
|
251 |
|
222 |
aValue = aConfig.ReadKey( "Scale" ); |
252 |
aValue = aConfig.ReadKey( "Scale" ); |
223 |
m_aGlobalDefaults.m_nScale = aValue.ToInt32(); |
253 |
if ( aValue.Len() ) |
|
|
254 |
m_aGlobalDefaults.m_nScale = aValue.ToInt32(); |
224 |
|
255 |
|
225 |
aValue = aConfig.ReadKey( "MarginAdjust" ); |
256 |
aValue = aConfig.ReadKey( "MarginAdjust" ); |
226 |
m_aGlobalDefaults.m_nLeftMarginAdjust = aValue.GetToken( 0, ',' ).ToInt32(); |
257 |
m_aGlobalDefaults.m_nLeftMarginAdjust = aValue.GetToken( 0, ',' ).ToInt32(); |
Lines 273-278
Link Here
|
273 |
} |
304 |
} |
274 |
fillFontSubstitutions( m_aGlobalDefaults ); |
305 |
fillFontSubstitutions( m_aGlobalDefaults ); |
275 |
|
306 |
|
|
|
307 |
#ifdef MACOSX |
308 |
// For Mac OS X 10.2 with CUPS printing, we also wish to be |
309 |
// notified of queue/printer updates, but these don't necessarily |
310 |
// happen when psprint.conf changes. The user can change settings in |
311 |
// the Print Center which should also make OOo update its queue list. |
312 |
if ( applePrintSystem == kApplePrintingCUPS ) |
313 |
{ |
314 |
// /etc/cups/printers.conf gets modified every time the Print Center printer |
315 |
// list is modified, so we want to watch this file too. |
316 |
INetURLObject aCUPSDir( String(RTL_CONSTASCII_USTRINGPARAM(MACXP_CUPS_CONF_DIR)), INET_PROT_FILE, INetURLObject::ENCODE_ALL ); |
317 |
INetURLObject aCUPSConfFile( aCUPSDir ); |
318 |
aCUPSConfFile.Append( String(RTL_CONSTASCII_USTRINGPARAM(MACXP_CUPS_CONF_FILENAME)) ); |
319 |
|
320 |
// check directory validity |
321 |
OUString aCUPSUniPath; |
322 |
FileBase::getFileURLFromSystemPath( aCUPSDir.PathToFileName(), aCUPSUniPath ); |
323 |
Directory aTestDirectory( aCUPSUniPath ); |
324 |
|
325 |
// If aTestDirectory.open() returns E_None (0), then we are OK. |
326 |
// If not, don't add the watch file because we can't get to it. |
327 |
if( aTestDirectory.open() == FileBase::E_None ) |
328 |
{ |
329 |
aTestDirectory.close(); |
330 |
|
331 |
FileBase::getFileURLFromSystemPath( aCUPSConfFile.PathToFileName(), aCUPSUniPath ); |
332 |
FileStatus aTestStatus( FileStatusMask_All ); |
333 |
DirectoryItem aTestItem; |
334 |
|
335 |
// setup WatchFile list |
336 |
WatchFile aCUPSWatchFile; |
337 |
aCUPSWatchFile.m_aFilePath = aCUPSUniPath; |
338 |
if( ! DirectoryItem::get( aCUPSUniPath, aTestItem ) && |
339 |
! aTestItem.getFileStatus( aTestStatus ) ) |
340 |
{ |
341 |
aCUPSWatchFile.m_aModified = aTestStatus.getModifyTime(); |
342 |
} |
343 |
else |
344 |
{ |
345 |
aCUPSWatchFile.m_aModified.Seconds = 0; |
346 |
aCUPSWatchFile.m_aModified.Nanosec = 0; |
347 |
} |
348 |
m_aWatchFiles.push_back( aCUPSWatchFile ); |
349 |
} |
350 |
} |
351 |
#endif |
352 |
|
276 |
// now collect all available printers |
353 |
// now collect all available printers |
277 |
for( print_dir_it = aDirList.begin(); print_dir_it != aDirList.end(); ++print_dir_it ) |
354 |
for( print_dir_it = aDirList.begin(); print_dir_it != aDirList.end(); ++print_dir_it ) |
278 |
{ |
355 |
{ |
Lines 377-382
Link Here
|
377 |
*/ |
454 |
*/ |
378 |
#if defined SOLARIS || defined(IRIX) |
455 |
#if defined SOLARIS || defined(IRIX) |
379 |
aValue = "lp"; |
456 |
aValue = "lp"; |
|
|
457 |
#elif defined(MACOSX) |
458 |
if ( applePrintSystem == kApplePrintingCUPS ) |
459 |
aValue = "lp"; |
460 |
else if ( applePrintSystem == kApplePrintingPrintCenter ) |
461 |
aValue = kApplePCPrintCommand; |
462 |
else |
463 |
{ |
464 |
// Fallback case is kApplePrintingLPR |
465 |
aValue = "lpr"; |
466 |
} |
380 |
#else |
467 |
#else |
381 |
aValue = "lpr"; |
468 |
aValue = "lpr"; |
382 |
#endif |
469 |
#endif |
Lines 405-415
Link Here
|
405 |
if( aValue.Len() ) |
492 |
if( aValue.Len() ) |
406 |
aPrinter.m_aInfo.m_eOrientation = aValue.EqualsIgnoreCaseAscii( "Landscape" ) ? orientation::Landscape : orientation::Portrait; |
493 |
aPrinter.m_aInfo.m_eOrientation = aValue.EqualsIgnoreCaseAscii( "Landscape" ) ? orientation::Landscape : orientation::Portrait; |
407 |
|
494 |
|
|
|
495 |
aValue = aConfig.ReadKey( "Scale" ); |
408 |
if( aValue.Len() ) |
496 |
if( aValue.Len() ) |
409 |
{ |
|
|
410 |
aValue = aConfig.ReadKey( "Scale" ); |
411 |
aPrinter.m_aInfo.m_nScale = aValue.ToInt32(); |
497 |
aPrinter.m_aInfo.m_nScale = aValue.ToInt32(); |
412 |
} |
|
|
413 |
|
498 |
|
414 |
aValue = aConfig.ReadKey( "MarginAdjust" ); |
499 |
aValue = aConfig.ReadKey( "MarginAdjust" ); |
415 |
if( aValue.Len() ) |
500 |
if( aValue.Len() ) |
Lines 536-541
Link Here
|
536 |
aPrinter.m_bModified = false; |
621 |
aPrinter.m_bModified = false; |
537 |
aPrinter.m_aGroup = ByteString( aPrinterName, aEncoding ); //provide group name in case user makes this one permanent in padmin |
622 |
aPrinter.m_aGroup = ByteString( aPrinterName, aEncoding ); //provide group name in case user makes this one permanent in padmin |
538 |
|
623 |
|
|
|
624 |
#ifdef MACOSX |
625 |
// If we are using OS X 10.2 CUPS printing, we want to grab the PPD that this printer |
626 |
// is associated with from /etc/cups/ppd (it's autocreated by the OS X printing system) and |
627 |
// use those values instead of the ones generated in the merged defaults. We want to make |
628 |
// this system printer just like we assigned it a PPD in padmin. |
629 |
if ( applePrintSystem == kApplePrintingCUPS ) |
630 |
{ |
631 |
aPrinter.m_aInfo.m_aFontSubstitutes.clear(); |
632 |
aPrinter.m_aInfo.m_aFontSubstitutions.clear(); |
633 |
|
634 |
// Printer's autogenerated PPD will be /etc/cups/ppd/<printername-from-lpstat>.ppd |
635 |
aPrinter.m_aInfo.m_aDriverName = String( *it ); |
636 |
aPrinter.m_aInfo.m_pParser = PPDParser::getParser( aPrinter.m_aInfo.m_aDriverName ); |
637 |
aPrinter.m_aInfo.m_aContext.setParser( aPrinter.m_aInfo.m_pParser ); |
638 |
|
639 |
if( aPrinter.m_aInfo.m_pParser ) |
640 |
{ |
641 |
// merge the ppd context keys if the printer has the same keys and values |
642 |
// it is mainly to select default paper sizes for new printers |
643 |
for( int nPPDValueModified = 0; nPPDValueModified < m_aGlobalDefaults.m_aContext.countValuesModified(); nPPDValueModified++ ) |
644 |
{ |
645 |
const PPDKey* pDefKey = m_aGlobalDefaults.m_aContext.getModifiedKey( nPPDValueModified ); |
646 |
const PPDValue* pDefValue = m_aGlobalDefaults.m_aContext.getValue( pDefKey ); |
647 |
// If the default PPD has a certain key, attempt to get that same key in the Printer's PPD |
648 |
const PPDKey* pPrinterKey = pDefKey ? aPrinter.m_aInfo.m_pParser->getKey( pDefKey->getKey() ) : NULL; |
649 |
|
650 |
// The key usually merged is PageSize |
651 |
if( pDefKey && pPrinterKey ) |
652 |
{ |
653 |
// Key exists in both the Default PPD and the printer's specific PPD. |
654 |
if( pDefValue ) |
655 |
{ |
656 |
const PPDValue* pPrinterValue = pPrinterKey->getValue( pDefValue->m_aOption ); |
657 |
// If the printer has a corresponding option for the key, use printer PPD's option |
658 |
if( pPrinterValue ) |
659 |
aPrinter.m_aInfo.m_aContext.setValue( pPrinterKey, pPrinterValue ); |
660 |
} |
661 |
else |
662 |
aPrinter.m_aInfo.m_aContext.setValue( pPrinterKey, NULL ); |
663 |
} |
664 |
} |
665 |
|
666 |
// Some CUPS PPDs on Mac OS X (Epson, HP) don't include the requisite |
667 |
// PageSize information for the value. We have to fudge it from the |
668 |
// margin information. Others (Canon BJC 8200) have the coordinates |
669 |
// but not the "setpagedevice" stuff |
670 |
const PPDKey* pPSizeKey = aPrinter.m_aInfo.m_pParser->getKey( String(RTL_CONSTASCII_USTRINGPARAM("PageSize")) ); |
671 |
if ( pPSizeKey ) |
672 |
{ |
673 |
int psIndex = 0; |
674 |
int nNumValues = pPSizeKey->countValues(); |
675 |
|
676 |
for ( psIndex = 0; psIndex < nNumValues; psIndex++ ) |
677 |
{ |
678 |
const PPDValue* pPSizeValue = pPSizeKey->getValue( psIndex ); |
679 |
|
680 |
// Only take care of PPD values that are not formatted correctly. |
681 |
if ( pPSizeValue && |
682 |
( !(pPSizeValue->m_aValue.Len()) || |
683 |
(pPSizeValue->m_aValue.Len() && (pPSizeValue->m_aValue.SearchAscii("setpagedevice")==STRING_NOTFOUND)) ) |
684 |
) |
685 |
{ |
686 |
// Deal with the two cases: 1) where there is a blank PageSize value and |
687 |
// 2) where there are simply the dimensions as the PageSize value |
688 |
if ( !pPSizeValue->m_aValue.Len() ) |
689 |
{ |
690 |
int paperWidth; |
691 |
int paperHeight; |
692 |
char aWidth[ 32 ]; |
693 |
char aHeight[ 32 ]; |
694 |
|
695 |
// Grab dimensions for this paper size from the "PaperDimension" key of the PPD |
696 |
aPrinter.m_aInfo.m_pParser->getPaperDimension( pPSizeValue->m_aOption, paperWidth, paperHeight ); |
697 |
snprintf( aWidth, 32, "%d", paperWidth ); |
698 |
snprintf( aHeight, 32, "%d", paperHeight ); |
699 |
|
700 |
// Construct a suitable PageSize key value from the PaperDimension values for this paper size |
701 |
pPSizeValue->m_aValue.AppendAscii( "<</PageSize [" ); |
702 |
pPSizeValue->m_aValue.AppendAscii( aWidth ); |
703 |
pPSizeValue->m_aValue.AppendAscii( " " ); |
704 |
pPSizeValue->m_aValue.AppendAscii( aHeight ); |
705 |
pPSizeValue->m_aValue.AppendAscii( "] /ImagingBBox null>> setpagedevice" ); |
706 |
} |
707 |
else |
708 |
{ |
709 |
String aBox( pPSizeValue->m_aValue ); |
710 |
|
711 |
// The PageSize value was just the bounding box, add in the correct postscript |
712 |
pPSizeValue->m_aValue.AssignAscii( "" ); |
713 |
pPSizeValue->m_aValue.AppendAscii( "<</PageSize [" ); |
714 |
pPSizeValue->m_aValue.Append( aBox ); |
715 |
pPSizeValue->m_aValue.AppendAscii( "] /ImagingBBox null>> setpagedevice" ); |
716 |
} |
717 |
} |
718 |
} |
719 |
} |
720 |
} |
721 |
else |
722 |
{ |
723 |
ByteString aBytePrinterName = ByteString( UniString(aPrinter.m_aInfo.m_aDriverName), RTL_TEXTENCODING_UTF8 ); |
724 |
fprintf( stderr, "Could not get Printer PPD from /etc/cups/ppd for printer '%s'! Using simple shared printer PPD...\n", aBytePrinterName.GetBuffer() ); |
725 |
|
726 |
// Some printers don't have the PPDs in /etc/cups/ppd (like Rendezvous-shared ones) |
727 |
// so we have to simply use a stripped down shared printer PPD for them |
728 |
aPrinter.m_aInfo.m_aDriverName = String( RTL_CONSTASCII_USTRINGPARAM("MacShared") ); |
729 |
aPrinter.m_aInfo.m_pParser = PPDParser::getParser( aPrinter.m_aInfo.m_aDriverName ); |
730 |
aPrinter.m_aInfo.m_aContext.setParser( aPrinter.m_aInfo.m_pParser ); |
731 |
if( !(aPrinter.m_aInfo.m_pParser) ) |
732 |
{ |
733 |
fprintf( stderr, "Warning: still couldn't load the PPD, MacShared.ppd may be missing. Will use generic printer PPD.\n" ); |
734 |
aPrinter.m_aInfo.m_aDriverName = String( RTL_CONSTASCII_USTRINGPARAM("SGENPRT") ); |
735 |
aPrinter.m_aInfo.m_pParser = PPDParser::getParser( aPrinter.m_aInfo.m_aDriverName ); |
736 |
aPrinter.m_aInfo.m_aContext.setParser( aPrinter.m_aInfo.m_pParser ); |
737 |
} |
738 |
} |
739 |
} |
740 |
#endif |
741 |
|
539 |
m_aPrinters[ aPrinterName ] = aPrinter; |
742 |
m_aPrinters[ aPrinterName ] = aPrinter; |
540 |
} |
743 |
} |
541 |
} |
744 |
} |
Lines 1017-1022
Link Here
|
1017 |
{ "/usr/sbin/lpc status", "lpr -P \"(PRINTER)\"", "", ":", 0 }, |
1220 |
{ "/usr/sbin/lpc status", "lpr -P \"(PRINTER)\"", "", ":", 0 }, |
1018 |
{ "lpc status", "lpr -P \"(PRINTER)\"", "", ":", 0 }, |
1221 |
{ "lpc status", "lpr -P \"(PRINTER)\"", "", ":", 0 }, |
1019 |
{ "LANG=C;LC_ALL=C;export LANG LC_ALL;lpstat -s", "lp -d \"(PRINTER)\"", "system for ", ": ", 1 } |
1222 |
{ "LANG=C;LC_ALL=C;export LANG LC_ALL;lpstat -s", "lp -d \"(PRINTER)\"", "system for ", ": ", 1 } |
|
|
1223 |
#elif defined(MACOSX) |
1224 |
/* These elements correspond to the constants defined for Apple printing in |
1225 |
* printerinfomanager.hxx and are indexed by those constants. ORDER IS IMPORTANT!!! |
1226 |
*/ |
1227 |
/* Apple LPR printing (kApplePrintingLPR) */ |
1228 |
{ "/usr/bin/lpc status", "lpr -P (PRINTER)", "", ":", 0 }, |
1229 |
/* Apple CUPS printing (kApplePrintingCUPS) */ |
1230 |
{ "LANG=C;LC_ALL=C;export LANG LC_ALL;/usr/bin/lpstat -s", "lp -d (PRINTER)", "device for ", ": ", 1 }, |
1231 |
/* Apple Print Center printing (kApplePrintingPrintCenter) */ |
1232 |
{ kApplePCQueueName, kApplePCPrintCommand, "", ":", 0 } |
1020 |
#else |
1233 |
#else |
1021 |
{ "LANG=C;LC_ALL=C;export LANG LC_ALL;lpstat -s", "lp -d \"(PRINTER)\"", "system for ", ": ", 1 }, |
1234 |
{ "LANG=C;LC_ALL=C;export LANG LC_ALL;lpstat -s", "lp -d \"(PRINTER)\"", "system for ", ": ", 1 }, |
1022 |
{ "/usr/sbin/lpc status", "lpr -P \"(PRINTER)\"", "", ":", 0 }, |
1235 |
{ "/usr/sbin/lpc status", "lpr -P \"(PRINTER)\"", "", ":", 0 }, |
Lines 1033-1041
Link Here
|
1033 |
bool bSuccess = false; |
1246 |
bool bSuccess = false; |
1034 |
std::list< ByteString > aLines; |
1247 |
std::list< ByteString > aLines; |
1035 |
rtl_TextEncoding aEncoding = gsl_getSystemTextEncoding(); |
1248 |
rtl_TextEncoding aEncoding = gsl_getSystemTextEncoding(); |
1036 |
|
|
|
1037 |
OUString aPrintCommand; |
1249 |
OUString aPrintCommand; |
1038 |
|
1250 |
|
|
|
1251 |
#ifdef MACOSX |
1252 |
sal_Int32 applePrintSysType; |
1253 |
|
1254 |
/* Get our OS specific printing scheme for MacOS X */ |
1255 |
applePrintSysType = macxp_GetSystemPrintMethod(); |
1256 |
#endif |
1257 |
|
1258 |
/* Discover which command we can use to get a list of all printer queues */ |
1039 |
for( i = 0; i < sizeof(aParms)/sizeof(aParms[0]) && ! bSuccess; i++ ) |
1259 |
for( i = 0; i < sizeof(aParms)/sizeof(aParms[0]) && ! bSuccess; i++ ) |
1040 |
{ |
1260 |
{ |
1041 |
aLines.clear(); |
1261 |
aLines.clear(); |
Lines 1047-1100
Link Here
|
1047 |
#if OSL_DEBUG_LEVEL > 1 |
1267 |
#if OSL_DEBUG_LEVEL > 1 |
1048 |
fprintf( stderr, "trying print queue command \"%s\" ... ", aParms[i].pQueueCommand ); |
1268 |
fprintf( stderr, "trying print queue command \"%s\" ... ", aParms[i].pQueueCommand ); |
1049 |
#endif |
1269 |
#endif |
1050 |
if( pPipe = popen( aPrtQueueCmd.GetBuffer(), "r" ) ) |
1270 |
#ifdef MACOSX |
|
|
1271 |
/* For Mac OS X 10.1 Print Center printing, we only use the default queue. We do not |
1272 |
* need to discover it. So when it comes up in the list of possible queues, |
1273 |
* recognize it and declare success. |
1274 |
*/ |
1275 |
if ( applePrintSysType == kApplePrintingPrintCenter ) |
1051 |
{ |
1276 |
{ |
1052 |
while( fgets( pBuffer, 1024, pPipe ) ) |
1277 |
if ( strstr(aPrtQueueCmd.GetBuffer(), kApplePCQueueName) != NULL ) |
1053 |
aLines.push_back( ByteString( pBuffer ) ); |
1278 |
bSuccess = TRUE; |
1054 |
if( ! pclose( pPipe ) ) |
1279 |
#ifdef DEBUG |
1055 |
bSuccess = true; |
1280 |
else |
|
|
1281 |
fprintf( stderr, "Ignoring print queue command \"%s\" because using 10.1 Print Center printing.\n", aParms[i].pQueueCommand ); |
1282 |
#endif |
1283 |
} |
1284 |
else |
1285 |
#endif |
1286 |
{ |
1287 |
if( pPipe = popen( aPrtQueueCmd.GetBuffer(), "r" ) ) |
1288 |
{ |
1289 |
while( fgets( pBuffer, 1024, pPipe ) ) |
1290 |
aLines.push_back( ByteString( pBuffer ) ); |
1291 |
if( ! pclose( pPipe ) ) |
1292 |
bSuccess = true; |
1293 |
} |
1056 |
} |
1294 |
} |
1057 |
#if OSL_DEBUG_LEVEL > 1 |
1295 |
#if OSL_DEBUG_LEVEL > 1 |
1058 |
fprintf( stderr, "%s\n", bSuccess ? "success" : "failed" ); |
1296 |
fprintf( stderr, "%s\n", bSuccess ? "success" : "failed" ); |
1059 |
#endif |
1297 |
#endif |
1060 |
} |
1298 |
} |
1061 |
|
1299 |
|
1062 |
if( bSuccess ) |
1300 |
#ifdef MACOSX |
|
|
1301 |
/* Since we only print to the default printer for MacOS X 10.1, |
1302 |
* queue discovery serves no purpose. |
1303 |
*/ |
1304 |
if ( applePrintSysType == kApplePrintingPrintCenter ) |
1063 |
{ |
1305 |
{ |
1064 |
std::list< OUString > aSysPrintQueues; |
1306 |
std::list< OUString > aSysPrintQueues; |
1065 |
|
1307 |
|
1066 |
while( aLines.begin() != aLines.end() ) |
1308 |
aSysPrintQueues.push_back( OUString::createFromAscii(kApplePCQueueName) ); |
|
|
1309 |
#ifdef DEBUG |
1310 |
fprintf( stderr, "printerinfomanager.cxx: using Print Center default print queue.\n" ); |
1311 |
#endif |
1312 |
|
1313 |
MutexGuard aGuard( m_aMutex ); |
1314 |
m_bChanged = true; |
1315 |
m_aQueues = aSysPrintQueues; |
1316 |
m_aCommand = aPrintCommand; |
1317 |
} |
1318 |
else |
1319 |
#endif /* MACOSX */ |
1320 |
{ |
1321 |
/* Normal Unix print queue discovery, also used for Darwin 5 LPR printing |
1322 |
* and MacOS X 10.2/Darwin 6 CUPS printing. |
1323 |
*/ |
1324 |
if( bSuccess ) |
1067 |
{ |
1325 |
{ |
1068 |
int nPos = 0, nAftPos; |
1326 |
std::list< OUString > aSysPrintQueues; |
|
|
1327 |
|
1328 |
while( aLines.begin() != aLines.end() ) |
1329 |
{ |
1330 |
int nPos = 0, nAftPos; |
1069 |
|
1331 |
|
1070 |
ByteString aOutLine( aLines.front() ); |
1332 |
ByteString aOutLine( aLines.front() ); |
1071 |
aLines.pop_front(); |
1333 |
aLines.pop_front(); |
1072 |
|
1334 |
|
1073 |
for( int i = 0; i < nForeTokenCount && nPos != STRING_NOTFOUND; i++ ) |
1335 |
for( int i = 0; i < nForeTokenCount && nPos != STRING_NOTFOUND; i++ ) |
1074 |
{ |
|
|
1075 |
nPos = aOutLine.Search( aForeToken, nPos ); |
1076 |
if( nPos != STRING_NOTFOUND && aOutLine.Len() >= nPos+aForeToken.Len() ) |
1077 |
nPos += aForeToken.Len(); |
1078 |
} |
1079 |
if( nPos != STRING_NOTFOUND ) |
1080 |
{ |
1081 |
nAftPos = aOutLine.Search( aAftToken, nPos ); |
1082 |
if( nAftPos != STRING_NOTFOUND ) |
1083 |
{ |
1336 |
{ |
1084 |
OUString aSysQueue( String( aOutLine.Copy( nPos, nAftPos - nPos ), aEncoding ) ); |
1337 |
nPos = aOutLine.Search( aForeToken, nPos ); |
1085 |
// do not insert duplicates (e.g. lpstat tends to produce such lines) |
1338 |
if( nPos != STRING_NOTFOUND && aOutLine.Len() >= nPos+aForeToken.Len() ) |
1086 |
std::list< OUString >::const_iterator it; |
1339 |
nPos += aForeToken.Len(); |
1087 |
for( it = aSysPrintQueues.begin(); it != aSysPrintQueues.end() && *it != aSysQueue; ++it ) |
1340 |
} |
1088 |
; |
1341 |
if( nPos != STRING_NOTFOUND ) |
1089 |
if( it == aSysPrintQueues.end() ) |
1342 |
{ |
1090 |
aSysPrintQueues.push_back( aSysQueue ); |
1343 |
nAftPos = aOutLine.Search( aAftToken, nPos ); |
|
|
1344 |
if( nAftPos != STRING_NOTFOUND ) |
1345 |
{ |
1346 |
OUString aSysQueue( String( aOutLine.Copy( nPos, nAftPos - nPos ), aEncoding ) ); |
1347 |
// do not insert duplicates (e.g. lpstat tends to produce such lines) |
1348 |
std::list< OUString >::const_iterator it; |
1349 |
for( it = aSysPrintQueues.begin(); it != aSysPrintQueues.end() && *it != aSysQueue; ++it ) |
1350 |
; |
1351 |
if( it == aSysPrintQueues.end() ) |
1352 |
aSysPrintQueues.push_back( aSysQueue ); |
1353 |
} |
1091 |
} |
1354 |
} |
1092 |
} |
1355 |
} |
1093 |
} |
|
|
1094 |
|
1356 |
|
1095 |
MutexGuard aGuard( m_aMutex ); |
1357 |
MutexGuard aGuard( m_aMutex ); |
1096 |
m_bChanged = true; |
1358 |
m_bChanged = true; |
1097 |
m_aQueues = aSysPrintQueues; |
1359 |
m_aQueues = aSysPrintQueues; |
1098 |
m_aCommand = aPrintCommand; |
1360 |
m_aCommand = aPrintCommand; |
|
|
1361 |
} |
1099 |
} |
1362 |
} |
1100 |
} |
1363 |
} |
|
|
1364 |
|
1365 |
#ifdef MACOSX |
1366 |
|
1367 |
/* On Apple systems printing gets more complicated... |
1368 |
* 1) Darwin 5: use straight lpr system, user has to configure lpr correctly |
1369 |
* 2) MacOS X 10.1: use /usr/sbin/Print which prints to default Print Center printer |
1370 |
* 3) MacOS X 10.2: use CUPS duo of lpstat/lp |
1371 |
* 4) Darwin 6: Like MacOS X 10.2, use CUPS |
1372 |
* |
1373 |
* --- FIXME --- We don't support printer choosing on MacOS X 10.1 at this time, |
1374 |
* only printing to default Print Center printer. The user can |
1375 |
* change the default Print Center printer at any point however. |
1376 |
*/ |
1377 |
|
1378 |
/* |
1379 |
* macxp_GetSystemPrintMethod() |
1380 |
* |
1381 |
* Find out which printing system/OS we are using. |
1382 |
* |
1383 |
* Darwin 5 is the fallback case. To check for 10.1 printing we try to see if |
1384 |
* /usr/sbin/Print exists. For 10.2/Darwin 6, we attempt to find lpstat. Users |
1385 |
* might also have installed CUPS on Darwin 5 or MacOS X 10.1, but we default to |
1386 |
* Print Center (/usr/sbin/Print) printing on 10.1. |
1387 |
* |
1388 |
*/ |
1389 |
sal_Int32 macxp_GetSystemPrintMethod( void ) |
1390 |
{ |
1391 |
int applePrintSysType; |
1392 |
int err; |
1393 |
struct stat status; |
1394 |
|
1395 |
/* Attempt to find out which OS we are on... */ |
1396 |
applePrintSysType = kApplePrintingLPR; |
1397 |
|
1398 |
/* Check for MacOS X 10.1 first. */ |
1399 |
err = stat( "/usr/sbin/Print", &status ); |
1400 |
if ( err == 0 ) |
1401 |
{ |
1402 |
applePrintSysType = kApplePrintingPrintCenter; |
1403 |
#ifdef DEBUG |
1404 |
fprintf( stderr, "printerinfomanager.cxx: found MacOS X 10.1-type printing system.\n" ); |
1405 |
#endif |
1406 |
} |
1407 |
else |
1408 |
{ |
1409 |
/* Test for MacOS X 10.2/Darwin6 CUPS printing */ |
1410 |
err = stat( "/usr/bin/lpstat", &status ); |
1411 |
if ( err == 0 ) |
1412 |
{ |
1413 |
applePrintSysType = kApplePrintingCUPS; |
1414 |
#ifdef DEBUG |
1415 |
fprintf( stderr, "printerinfomanager.cxx: found MacOS X 10.2-type CUPS-based printing system.\n" ); |
1416 |
#endif |
1417 |
} |
1418 |
} |
1419 |
|
1420 |
#ifdef DEBUG |
1421 |
if ( applePrintSysType == kApplePrintingLPR ) |
1422 |
fprintf( stderr, "printerinfomanager.cxx: falling back to Darwin5-type LPR printing system.\n" ); |
1423 |
#endif |
1424 |
|
1425 |
return( applePrintSysType ); |
1426 |
} |
1427 |
|
1428 |
/* |
1429 |
* macxp_GetSystemPrintFormat() |
1430 |
* |
1431 |
* There are two ways to print: using PostScript (PS) and using PDF. |
1432 |
* Because MacOS X 10.2 CUPS printing has PDF converts built in for |
1433 |
* almost every printer, it is very easy to print using PDF. For 10.1, |
1434 |
* extra steps must be taken to print with PDF, but it is still more |
1435 |
* compatible. For Darwin 5 and 6, we default to PS printing. |
1436 |
* |
1437 |
* The user may still wish to print PS to PS compatible printers and |
1438 |
* therefore the environment variable OOO_PRINT_PS_DIRECTLY, if set, |
1439 |
* forces OOo to NOT undergo the PS -> PDF translation by default. |
1440 |
*/ |
1441 |
/*sal_Int32 macxp_GetSystemPrintFormat( void ) |
1442 |
{ |
1443 |
int printFormat; |
1444 |
int err; |
1445 |
struct stat status; |
1446 |
sal_Char *pPDFOverride = NULL; |
1447 |
|
1448 |
printFormat = kApplePrintingUsePS; |
1449 |
|
1450 |
/* Check for presence of OSAScript executable, which is |
1451 |
* believed to be MacOS X only (ie not present on Darwin). |
1452 |
* |
1453 |
err = stat( "/usr/bin/osascript", &status ); |
1454 |
if ( err == 0 ) |
1455 |
{ |
1456 |
/* Check to see if the user wants to print PS anyway * |
1457 |
pPDFOverride = getenv( "OOO_PRINT_PS_DIRECTLY" ); |
1458 |
if ( pPDFOverride == NULL ) |
1459 |
{ |
1460 |
/* Now we have to check for ps2pdf to make sure we can do the conversion * |
1461 |
err = stat( kApplePS2PDFLocation, &status ); |
1462 |
if ( err == 0 ) |
1463 |
{ |
1464 |
printFormat = kApplePrintingUsePDF; |
1465 |
#ifdef DEBUG |
1466 |
fprintf( stderr, "printerinfomanager.cxx: Will print in PDF format using PS->PDF coversion filters.\n" ); |
1467 |
#endif |
1468 |
} |
1469 |
} |
1470 |
} |
1471 |
|
1472 |
return( printFormat ); |
1473 |
}*/ |
1474 |
#endif |
1475 |
|