2006-02-07 01:12:56 +00:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* ***** BEGIN LICENSE BLOCK *****
|
2006-02-07 01:14:50 +00:00
|
|
|
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
1999-02-18 22:35:11 +00:00
|
|
|
*
|
2006-02-07 01:14:50 +00:00
|
|
|
* The contents of this file are subject to the Mozilla Public License Version
|
|
|
|
* 1.1 (the "License"); you may not use this file except in compliance with
|
|
|
|
* the License. You may obtain a copy of the License at
|
|
|
|
* http://www.mozilla.org/MPL/
|
1999-02-18 22:35:11 +00:00
|
|
|
*
|
2006-02-07 01:12:56 +00:00
|
|
|
* Software distributed under the License is distributed on an "AS IS" basis,
|
|
|
|
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
|
|
|
* for the specific language governing rights and limitations under the
|
|
|
|
* License.
|
1999-02-18 22:35:11 +00:00
|
|
|
*
|
1999-11-06 03:43:54 +00:00
|
|
|
* The Original Code is mozilla.org code.
|
|
|
|
*
|
2006-02-07 01:14:50 +00:00
|
|
|
* The Initial Developer of the Original Code is
|
2006-02-07 01:12:56 +00:00
|
|
|
* Netscape Communications Corporation.
|
|
|
|
* Portions created by the Initial Developer are Copyright (C) 1998
|
|
|
|
* the Initial Developer. All Rights Reserved.
|
1999-11-06 03:43:54 +00:00
|
|
|
*
|
2006-02-07 01:12:41 +00:00
|
|
|
* Contributor(s):
|
2006-02-07 01:12:44 +00:00
|
|
|
* Roland Mainz <roland.mainz@informatik.med.uni-giessen.de>
|
2006-02-07 01:15:08 +00:00
|
|
|
* Ken Herron <kherron+mozilla@fmailbox.com>
|
2006-02-07 01:15:09 +00:00
|
|
|
* Julien Lafon <julien.lafon@gmail.com>
|
2008-01-21 03:47:25 +00:00
|
|
|
* Michael Ventnor <m.ventnor@gmail.com>
|
2006-02-07 01:12:41 +00:00
|
|
|
*
|
2006-02-07 01:12:56 +00:00
|
|
|
* Alternatively, the contents of this file may be used under the terms of
|
2006-02-07 01:14:50 +00:00
|
|
|
* either of the GNU General Public License Version 2 or later (the "GPL"),
|
|
|
|
* or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
2006-02-07 01:12:56 +00:00
|
|
|
* in which case the provisions of the GPL or the LGPL are applicable instead
|
|
|
|
* of those above. If you wish to allow use of your version of this file only
|
|
|
|
* under the terms of either the GPL or the LGPL, and not to allow others to
|
2006-02-07 01:14:50 +00:00
|
|
|
* use your version of this file under the terms of the MPL, indicate your
|
2006-02-07 01:12:56 +00:00
|
|
|
* decision by deleting the provisions above and replace them with the notice
|
|
|
|
* and other provisions required by the GPL or the LGPL. If you do not delete
|
|
|
|
* the provisions above, a recipient may use your version of this file under
|
2006-02-07 01:14:50 +00:00
|
|
|
* the terms of any one of the MPL, the GPL or the LGPL.
|
2006-02-07 01:12:56 +00:00
|
|
|
*
|
|
|
|
* ***** END LICENSE BLOCK ***** */
|
2006-02-07 01:13:44 +00:00
|
|
|
|
|
|
|
/* Store per-printer features in temp. prefs vars that the
|
|
|
|
* print dialog can pick them up... */
|
|
|
|
#define SET_PRINTER_FEATURES_VIA_PREFS 1
|
|
|
|
#define PRINTERFEATURES_PREF "print.tmp.printerfeatures"
|
|
|
|
|
2006-02-07 01:14:36 +00:00
|
|
|
#ifdef MOZ_LOGGING
|
|
|
|
#define FORCE_PR_LOG 1 /* Allow logging in the release build */
|
|
|
|
#endif /* MOZ_LOGGING */
|
2006-02-07 01:13:44 +00:00
|
|
|
#include "prlog.h"
|
2006-02-07 01:14:36 +00:00
|
|
|
|
2006-02-07 01:14:01 +00:00
|
|
|
#include "plstr.h"
|
1999-02-18 22:35:11 +00:00
|
|
|
|
|
|
|
#include "nsDeviceContextSpecG.h"
|
2006-02-07 01:12:11 +00:00
|
|
|
|
1999-03-31 22:55:29 +00:00
|
|
|
#include "prenv.h" /* for PR_GetEnv */
|
1999-03-31 20:17:01 +00:00
|
|
|
|
2006-02-07 01:13:51 +00:00
|
|
|
#include "nsPrintfCString.h"
|
2006-02-07 01:13:53 +00:00
|
|
|
#include "nsReadableUtils.h"
|
2007-05-06 11:29:41 +00:00
|
|
|
#include "nsStringEnumerator.h"
|
2006-02-07 01:13:53 +00:00
|
|
|
#include "nsIServiceManager.h"
|
2006-02-07 01:13:44 +00:00
|
|
|
|
2006-02-07 01:15:08 +00:00
|
|
|
#include "nsPSPrinters.h"
|
2006-02-07 01:14:44 +00:00
|
|
|
#include "nsPaperPS.h" /* Paper size list */
|
2006-02-07 01:13:44 +00:00
|
|
|
|
2008-01-21 03:47:25 +00:00
|
|
|
#include "nsPrintSettingsGTK.h"
|
2006-11-29 23:40:16 +00:00
|
|
|
|
2007-03-01 00:02:27 +00:00
|
|
|
#include "nsIFileStreams.h"
|
|
|
|
#include "nsILocalFile.h"
|
2009-01-18 20:14:14 +00:00
|
|
|
#include "nsTArray.h"
|
2007-03-01 00:02:27 +00:00
|
|
|
|
2011-05-27 08:15:20 +00:00
|
|
|
#include "mozilla/Preferences.h"
|
|
|
|
|
2008-01-21 03:47:25 +00:00
|
|
|
#include <unistd.h>
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/stat.h>
|
|
|
|
|
2011-05-27 08:15:20 +00:00
|
|
|
using namespace mozilla;
|
|
|
|
|
2006-02-07 01:13:44 +00:00
|
|
|
#ifdef PR_LOGGING
|
|
|
|
static PRLogModuleInfo *DeviceContextSpecGTKLM = PR_NewLogModule("DeviceContextSpecGTK");
|
|
|
|
#endif /* PR_LOGGING */
|
|
|
|
/* Macro to make lines shorter */
|
|
|
|
#define DO_PR_DEBUG_LOG(x) PR_LOG(DeviceContextSpecGTKLM, PR_LOG_DEBUG, x)
|
|
|
|
|
2006-02-07 01:13:12 +00:00
|
|
|
//----------------------------------------------------------------------------------
|
2006-02-07 01:13:27 +00:00
|
|
|
// The printer data is shared between the PrinterEnumerator and the nsDeviceContextSpecGTK
|
2006-02-07 01:13:12 +00:00
|
|
|
// The PrinterEnumerator creates the printer info
|
2006-02-07 01:13:27 +00:00
|
|
|
// but the nsDeviceContextSpecGTK cleans it up
|
2006-02-07 01:13:12 +00:00
|
|
|
// If it gets created (via the Page Setup Dialog) but the user never prints anything
|
|
|
|
// then it will never be delete, so this class takes care of that.
|
|
|
|
class GlobalPrinters {
|
|
|
|
public:
|
|
|
|
static GlobalPrinters* GetInstance() { return &mGlobalPrinters; }
|
|
|
|
~GlobalPrinters() { FreeGlobalPrinters(); }
|
|
|
|
|
|
|
|
void FreeGlobalPrinters();
|
|
|
|
nsresult InitializeGlobalPrinters();
|
|
|
|
|
2011-09-29 06:19:26 +00:00
|
|
|
bool PrintersAreAllocated() { return mGlobalPrinterList != nsnull; }
|
2010-10-06 22:18:52 +00:00
|
|
|
PRUint32 GetNumPrinters()
|
2009-01-18 20:14:14 +00:00
|
|
|
{ return mGlobalPrinterList ? mGlobalPrinterList->Length() : 0; }
|
|
|
|
nsString* GetStringAt(PRInt32 aInx) { return &mGlobalPrinterList->ElementAt(aInx); }
|
2006-02-07 01:13:44 +00:00
|
|
|
void GetDefaultPrinterName(PRUnichar **aDefaultPrinterName);
|
2006-02-07 01:13:12 +00:00
|
|
|
|
|
|
|
protected:
|
|
|
|
GlobalPrinters() {}
|
|
|
|
|
|
|
|
static GlobalPrinters mGlobalPrinters;
|
2009-01-18 20:14:14 +00:00
|
|
|
static nsTArray<nsString>* mGlobalPrinterList;
|
2006-02-07 01:13:12 +00:00
|
|
|
};
|
2006-02-07 01:13:44 +00:00
|
|
|
|
2006-02-07 01:13:46 +00:00
|
|
|
#ifdef SET_PRINTER_FEATURES_VIA_PREFS
|
|
|
|
/* "Prototype" for the new nsPrinterFeatures service */
|
|
|
|
class nsPrinterFeatures {
|
|
|
|
public:
|
|
|
|
nsPrinterFeatures( const char *printername );
|
2007-04-23 14:21:53 +00:00
|
|
|
~nsPrinterFeatures() {}
|
2006-02-07 01:13:46 +00:00
|
|
|
|
2006-02-07 01:14:39 +00:00
|
|
|
/* Does this printer allow to set/change the paper size ? */
|
2011-09-29 06:19:26 +00:00
|
|
|
void SetCanChangePaperSize( bool aCanSetPaperSize );
|
2006-02-07 01:14:39 +00:00
|
|
|
/* Does this Mozilla print module allow set/change the paper size ? */
|
2011-09-29 06:19:26 +00:00
|
|
|
void SetSupportsPaperSizeChange( bool aSupportsPaperSizeChange );
|
2006-02-07 01:13:46 +00:00
|
|
|
/* Set number of paper size records and the records itself */
|
|
|
|
void SetNumPaperSizeRecords( PRInt32 aCount );
|
2011-09-29 06:19:26 +00:00
|
|
|
void SetPaperRecord( PRInt32 aIndex, const char *aName, PRInt32 aWidthMM, PRInt32 aHeightMM, bool aIsInch );
|
2006-02-07 01:13:46 +00:00
|
|
|
|
2006-02-07 01:14:39 +00:00
|
|
|
/* Does this printer allow to set/change the content orientation ? */
|
2011-09-29 06:19:26 +00:00
|
|
|
void SetCanChangeOrientation( bool aCanSetOrientation );
|
2006-02-07 01:14:39 +00:00
|
|
|
/* Does this Mozilla print module allow set/change the content orientation ? */
|
2011-09-29 06:19:26 +00:00
|
|
|
void SetSupportsOrientationChange( bool aSupportsOrientationChange );
|
2006-02-07 01:13:46 +00:00
|
|
|
/* Set number of orientation records and the records itself */
|
|
|
|
void SetNumOrientationRecords( PRInt32 aCount );
|
|
|
|
void SetOrientationRecord( PRInt32 aIndex, const char *aName );
|
2006-02-07 01:14:39 +00:00
|
|
|
|
|
|
|
/* Does this printer allow to set/change the plex mode ? */
|
2011-09-29 06:19:26 +00:00
|
|
|
void SetCanChangePlex( bool aCanSetPlex );
|
2006-02-07 01:14:39 +00:00
|
|
|
/* Does this Mozilla print module allow set/change the plex mode ? */
|
2011-09-29 06:19:26 +00:00
|
|
|
void SetSupportsPlexChange( bool aSupportsPlexChange );
|
2006-02-07 01:14:39 +00:00
|
|
|
/* Set number of plex records and the records itself */
|
|
|
|
void SetNumPlexRecords( PRInt32 aCount );
|
|
|
|
void SetPlexRecord( PRInt32 aIndex, const char *aName );
|
2006-02-07 01:15:09 +00:00
|
|
|
|
|
|
|
/* Does this printer allow to set/change the resolution name ? */
|
2011-09-29 06:19:26 +00:00
|
|
|
void SetCanChangeResolutionName( bool aCanSetResolutionName );
|
2006-02-07 01:15:09 +00:00
|
|
|
/* Does this Mozilla print module allow set/change the resolution name ? */
|
2011-09-29 06:19:26 +00:00
|
|
|
void SetSupportsResolutionNameChange( bool aSupportsResolutionChange );
|
2006-02-07 01:15:09 +00:00
|
|
|
/* Set number of resolution records and the records itself */
|
|
|
|
void SetNumResolutionNameRecords( PRInt32 aCount );
|
|
|
|
void SetResolutionNameRecord( PRInt32 aIndex, const char *aName );
|
|
|
|
|
|
|
|
/* Does this printer allow to set/change the colorspace ? */
|
2011-09-29 06:19:26 +00:00
|
|
|
void SetCanChangeColorspace( bool aCanSetColorspace );
|
2006-02-07 01:15:09 +00:00
|
|
|
/* Does this Mozilla print module allow set/change the colorspace ? */
|
2011-09-29 06:19:26 +00:00
|
|
|
void SetSupportsColorspaceChange( bool aSupportsColorspace );
|
2006-02-07 01:15:09 +00:00
|
|
|
/* Set number of colorspace records and the records itself */
|
|
|
|
void SetNumColorspaceRecords( PRInt32 aCount );
|
|
|
|
void SetColorspaceRecord( PRInt32 aIndex, const char *aName );
|
|
|
|
|
|
|
|
/* Does this device allow to set/change the usage of the internal grayscale mode ? */
|
2011-09-29 06:19:26 +00:00
|
|
|
void SetCanChangePrintInColor( bool aCanSetPrintInColor );
|
2006-02-07 01:15:09 +00:00
|
|
|
/* Does this printer allow to set/change the usage of the internal grayscale mode ? */
|
2011-09-29 06:19:26 +00:00
|
|
|
void SetSupportsPrintInColorChange( bool aSupportPrintInColorChange );
|
2006-02-07 01:15:09 +00:00
|
|
|
|
|
|
|
/* Does this device allow to set/change the usage of font download to the printer? */
|
2011-09-29 06:19:26 +00:00
|
|
|
void SetCanChangeDownloadFonts( bool aCanSetDownloadFonts );
|
2006-02-07 01:15:09 +00:00
|
|
|
/* Does this printer allow to set/change the usage of font download to the printer? */
|
2011-09-29 06:19:26 +00:00
|
|
|
void SetSupportsDownloadFontsChange( bool aSupportDownloadFontsChange );
|
2006-02-07 01:15:09 +00:00
|
|
|
|
|
|
|
/* Does this device allow to set/change the job title ? */
|
2011-09-29 06:19:26 +00:00
|
|
|
void SetCanChangeJobTitle( bool aCanSetJobTitle );
|
2006-02-07 01:15:09 +00:00
|
|
|
/* Does this printer allow to set/change the job title ? */
|
2011-09-29 06:19:26 +00:00
|
|
|
void SetSupportsJobTitleChange( bool aSupportJobTitleChange );
|
2006-02-07 01:14:39 +00:00
|
|
|
|
2006-02-07 01:13:46 +00:00
|
|
|
/* Does this device allow to set/change the spooler command ? */
|
2011-09-29 06:19:26 +00:00
|
|
|
void SetCanChangeSpoolerCommand( bool aCanSetSpoolerCommand );
|
2006-02-07 01:14:39 +00:00
|
|
|
/* Does this printer allow to set/change the spooler command ? */
|
2011-09-29 06:19:26 +00:00
|
|
|
void SetSupportsSpoolerCommandChange( bool aSupportSpoolerCommandChange );
|
2006-02-07 01:14:39 +00:00
|
|
|
|
2006-02-07 01:13:46 +00:00
|
|
|
/* Does this device allow to set/change number of copies for an document ? */
|
2011-09-29 06:19:26 +00:00
|
|
|
void SetCanChangeNumCopies( bool aCanSetNumCopies );
|
2006-02-07 01:14:29 +00:00
|
|
|
|
2006-02-07 01:13:46 +00:00
|
|
|
private:
|
|
|
|
/* private helper methods */
|
2011-09-29 06:19:26 +00:00
|
|
|
void SetBoolValue( const char *tagname, bool value );
|
2006-02-07 01:13:46 +00:00
|
|
|
void SetIntValue( const char *tagname, PRInt32 value );
|
|
|
|
void SetCharValue( const char *tagname, const char *value );
|
|
|
|
|
2006-10-23 15:29:09 +00:00
|
|
|
nsXPIDLCString mPrinterName;
|
2006-02-07 01:13:46 +00:00
|
|
|
};
|
|
|
|
|
2011-09-29 06:19:26 +00:00
|
|
|
void nsPrinterFeatures::SetBoolValue( const char *tagname, bool value )
|
2006-02-07 01:13:46 +00:00
|
|
|
{
|
2012-04-24 18:43:00 +00:00
|
|
|
nsPrintfCString prefName(PRINTERFEATURES_PREF ".%s.%s",
|
2011-05-27 08:15:20 +00:00
|
|
|
mPrinterName.get(), tagname);
|
|
|
|
Preferences::SetBool(prefName.get(), value);
|
2006-02-07 01:13:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void nsPrinterFeatures::SetIntValue( const char *tagname, PRInt32 value )
|
|
|
|
{
|
2012-04-24 18:43:00 +00:00
|
|
|
nsPrintfCString prefName(PRINTERFEATURES_PREF ".%s.%s",
|
2011-05-27 08:15:20 +00:00
|
|
|
mPrinterName.get(), tagname);
|
|
|
|
Preferences::SetInt(prefName.get(), value);
|
2006-02-07 01:13:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void nsPrinterFeatures::SetCharValue( const char *tagname, const char *value )
|
|
|
|
{
|
2012-04-24 18:43:00 +00:00
|
|
|
nsPrintfCString prefName(PRINTERFEATURES_PREF ".%s.%s",
|
2011-05-27 08:15:20 +00:00
|
|
|
mPrinterName.get(), tagname);
|
|
|
|
Preferences::SetCString(prefName.get(), value);
|
2006-02-07 01:13:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
nsPrinterFeatures::nsPrinterFeatures( const char *printername )
|
|
|
|
{
|
|
|
|
DO_PR_DEBUG_LOG(("nsPrinterFeatures::nsPrinterFeatures('%s')\n", printername));
|
|
|
|
mPrinterName.Assign(printername);
|
2011-05-27 08:15:20 +00:00
|
|
|
|
2011-10-03 07:56:21 +00:00
|
|
|
SetBoolValue("has_special_printerfeatures", true);
|
2006-02-07 01:13:46 +00:00
|
|
|
}
|
|
|
|
|
2011-09-29 06:19:26 +00:00
|
|
|
void nsPrinterFeatures::SetCanChangePaperSize( bool aCanSetPaperSize )
|
2006-02-07 01:13:46 +00:00
|
|
|
{
|
|
|
|
SetBoolValue("can_change_paper_size", aCanSetPaperSize);
|
|
|
|
}
|
|
|
|
|
2011-09-29 06:19:26 +00:00
|
|
|
void nsPrinterFeatures::SetSupportsPaperSizeChange( bool aSupportsPaperSizeChange )
|
2006-02-07 01:14:39 +00:00
|
|
|
{
|
|
|
|
SetBoolValue("supports_paper_size_change", aSupportsPaperSizeChange);
|
|
|
|
}
|
|
|
|
|
2006-02-07 01:13:46 +00:00
|
|
|
/* Set number of paper size records and the records itself */
|
|
|
|
void nsPrinterFeatures::SetNumPaperSizeRecords( PRInt32 aCount )
|
|
|
|
{
|
|
|
|
SetIntValue("paper.count", aCount);
|
|
|
|
}
|
|
|
|
|
2011-09-29 06:19:26 +00:00
|
|
|
void nsPrinterFeatures::SetPaperRecord(PRInt32 aIndex, const char *aPaperName, PRInt32 aWidthMM, PRInt32 aHeightMM, bool aIsInch)
|
2006-02-07 01:13:46 +00:00
|
|
|
{
|
2012-04-24 18:43:00 +00:00
|
|
|
SetCharValue(nsPrintfCString("paper.%d.name", aIndex).get(), aPaperName);
|
|
|
|
SetIntValue( nsPrintfCString("paper.%d.width_mm", aIndex).get(), aWidthMM);
|
|
|
|
SetIntValue( nsPrintfCString("paper.%d.height_mm", aIndex).get(), aHeightMM);
|
|
|
|
SetBoolValue(nsPrintfCString("paper.%d.is_inch", aIndex).get(), aIsInch);
|
2006-02-07 01:13:46 +00:00
|
|
|
}
|
|
|
|
|
2011-09-29 06:19:26 +00:00
|
|
|
void nsPrinterFeatures::SetCanChangeOrientation( bool aCanSetOrientation )
|
2006-02-07 01:13:46 +00:00
|
|
|
{
|
|
|
|
SetBoolValue("can_change_orientation", aCanSetOrientation);
|
|
|
|
}
|
|
|
|
|
2011-09-29 06:19:26 +00:00
|
|
|
void nsPrinterFeatures::SetSupportsOrientationChange( bool aSupportsOrientationChange )
|
2006-02-07 01:14:39 +00:00
|
|
|
{
|
|
|
|
SetBoolValue("supports_orientation_change", aSupportsOrientationChange);
|
|
|
|
}
|
|
|
|
|
2006-02-07 01:13:46 +00:00
|
|
|
void nsPrinterFeatures::SetNumOrientationRecords( PRInt32 aCount )
|
|
|
|
{
|
|
|
|
SetIntValue("orientation.count", aCount);
|
|
|
|
}
|
|
|
|
|
|
|
|
void nsPrinterFeatures::SetOrientationRecord( PRInt32 aIndex, const char *aOrientationName )
|
|
|
|
{
|
2012-04-24 18:43:00 +00:00
|
|
|
SetCharValue(nsPrintfCString("orientation.%d.name", aIndex).get(), aOrientationName);
|
2006-02-07 01:13:46 +00:00
|
|
|
}
|
|
|
|
|
2011-09-29 06:19:26 +00:00
|
|
|
void nsPrinterFeatures::SetCanChangePlex( bool aCanSetPlex )
|
2006-02-07 01:14:39 +00:00
|
|
|
{
|
|
|
|
SetBoolValue("can_change_plex", aCanSetPlex);
|
|
|
|
}
|
|
|
|
|
2011-09-29 06:19:26 +00:00
|
|
|
void nsPrinterFeatures::SetSupportsPlexChange( bool aSupportsPlexChange )
|
2006-02-07 01:14:39 +00:00
|
|
|
{
|
|
|
|
SetBoolValue("supports_plex_change", aSupportsPlexChange);
|
|
|
|
}
|
|
|
|
|
|
|
|
void nsPrinterFeatures::SetNumPlexRecords( PRInt32 aCount )
|
|
|
|
{
|
|
|
|
SetIntValue("plex.count", aCount);
|
|
|
|
}
|
|
|
|
|
|
|
|
void nsPrinterFeatures::SetPlexRecord( PRInt32 aIndex, const char *aPlexName )
|
|
|
|
{
|
2012-04-24 18:43:00 +00:00
|
|
|
SetCharValue(nsPrintfCString("plex.%d.name", aIndex).get(), aPlexName);
|
2006-02-07 01:14:39 +00:00
|
|
|
}
|
|
|
|
|
2011-09-29 06:19:26 +00:00
|
|
|
void nsPrinterFeatures::SetCanChangeResolutionName( bool aCanSetResolutionName )
|
2006-02-07 01:15:09 +00:00
|
|
|
{
|
|
|
|
SetBoolValue("can_change_resolution", aCanSetResolutionName);
|
|
|
|
}
|
|
|
|
|
2011-09-29 06:19:26 +00:00
|
|
|
void nsPrinterFeatures::SetSupportsResolutionNameChange( bool aSupportsResolutionNameChange )
|
2006-02-07 01:15:09 +00:00
|
|
|
{
|
|
|
|
SetBoolValue("supports_resolution_change", aSupportsResolutionNameChange);
|
|
|
|
}
|
|
|
|
|
|
|
|
void nsPrinterFeatures::SetNumResolutionNameRecords( PRInt32 aCount )
|
|
|
|
{
|
|
|
|
SetIntValue("resolution.count", aCount);
|
|
|
|
}
|
|
|
|
|
|
|
|
void nsPrinterFeatures::SetResolutionNameRecord( PRInt32 aIndex, const char *aResolutionName )
|
|
|
|
{
|
2012-04-24 18:43:00 +00:00
|
|
|
SetCharValue(nsPrintfCString("resolution.%d.name", aIndex).get(), aResolutionName);
|
2006-02-07 01:15:09 +00:00
|
|
|
}
|
|
|
|
|
2011-09-29 06:19:26 +00:00
|
|
|
void nsPrinterFeatures::SetCanChangeColorspace( bool aCanSetColorspace )
|
2006-02-07 01:15:09 +00:00
|
|
|
{
|
|
|
|
SetBoolValue("can_change_colorspace", aCanSetColorspace);
|
|
|
|
}
|
|
|
|
|
2011-09-29 06:19:26 +00:00
|
|
|
void nsPrinterFeatures::SetSupportsColorspaceChange( bool aSupportsColorspaceChange )
|
2006-02-07 01:15:09 +00:00
|
|
|
{
|
|
|
|
SetBoolValue("supports_colorspace_change", aSupportsColorspaceChange);
|
|
|
|
}
|
|
|
|
|
|
|
|
void nsPrinterFeatures::SetNumColorspaceRecords( PRInt32 aCount )
|
|
|
|
{
|
|
|
|
SetIntValue("colorspace.count", aCount);
|
|
|
|
}
|
|
|
|
|
|
|
|
void nsPrinterFeatures::SetColorspaceRecord( PRInt32 aIndex, const char *aColorspace )
|
|
|
|
{
|
2012-04-24 18:43:00 +00:00
|
|
|
SetCharValue(nsPrintfCString("colorspace.%d.name", aIndex).get(), aColorspace);
|
2006-02-07 01:15:09 +00:00
|
|
|
}
|
|
|
|
|
2011-09-29 06:19:26 +00:00
|
|
|
void nsPrinterFeatures::SetCanChangeDownloadFonts( bool aCanSetDownloadFonts )
|
2006-02-07 01:15:09 +00:00
|
|
|
{
|
|
|
|
SetBoolValue("can_change_downloadfonts", aCanSetDownloadFonts);
|
|
|
|
}
|
|
|
|
|
2011-09-29 06:19:26 +00:00
|
|
|
void nsPrinterFeatures::SetSupportsDownloadFontsChange( bool aSupportDownloadFontsChange )
|
2006-02-07 01:15:09 +00:00
|
|
|
{
|
|
|
|
SetBoolValue("supports_downloadfonts_change", aSupportDownloadFontsChange);
|
|
|
|
}
|
|
|
|
|
2011-09-29 06:19:26 +00:00
|
|
|
void nsPrinterFeatures::SetCanChangePrintInColor( bool aCanSetPrintInColor )
|
2006-02-07 01:15:09 +00:00
|
|
|
{
|
|
|
|
SetBoolValue("can_change_printincolor", aCanSetPrintInColor);
|
|
|
|
}
|
|
|
|
|
2011-09-29 06:19:26 +00:00
|
|
|
void nsPrinterFeatures::SetSupportsPrintInColorChange( bool aSupportPrintInColorChange )
|
2006-02-07 01:15:09 +00:00
|
|
|
{
|
|
|
|
SetBoolValue("supports_printincolor_change", aSupportPrintInColorChange);
|
|
|
|
}
|
|
|
|
|
2011-09-29 06:19:26 +00:00
|
|
|
void nsPrinterFeatures::SetCanChangeSpoolerCommand( bool aCanSetSpoolerCommand )
|
2006-02-07 01:13:46 +00:00
|
|
|
{
|
|
|
|
SetBoolValue("can_change_spoolercommand", aCanSetSpoolerCommand);
|
|
|
|
}
|
|
|
|
|
2011-09-29 06:19:26 +00:00
|
|
|
void nsPrinterFeatures::SetSupportsSpoolerCommandChange( bool aSupportSpoolerCommandChange )
|
2006-02-07 01:14:39 +00:00
|
|
|
{
|
|
|
|
SetBoolValue("supports_spoolercommand_change", aSupportSpoolerCommandChange);
|
|
|
|
}
|
|
|
|
|
2011-09-29 06:19:26 +00:00
|
|
|
void nsPrinterFeatures::SetCanChangeJobTitle( bool aCanSetJobTitle )
|
2006-02-07 01:15:09 +00:00
|
|
|
{
|
|
|
|
SetBoolValue("can_change_jobtitle", aCanSetJobTitle);
|
|
|
|
}
|
|
|
|
|
2011-09-29 06:19:26 +00:00
|
|
|
void nsPrinterFeatures::SetSupportsJobTitleChange( bool aSupportsJobTitle )
|
2006-02-07 01:15:09 +00:00
|
|
|
{
|
|
|
|
SetBoolValue("supports_jobtitle_change", aSupportsJobTitle);
|
|
|
|
}
|
|
|
|
|
2011-09-29 06:19:26 +00:00
|
|
|
void nsPrinterFeatures::SetCanChangeNumCopies( bool aCanSetNumCopies )
|
2006-02-07 01:13:46 +00:00
|
|
|
{
|
|
|
|
SetBoolValue("can_change_num_copies", aCanSetNumCopies);
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif /* SET_PRINTER_FEATURES_VIA_PREFS */
|
|
|
|
|
2006-02-07 01:13:12 +00:00
|
|
|
//---------------
|
|
|
|
// static members
|
|
|
|
GlobalPrinters GlobalPrinters::mGlobalPrinters;
|
2009-01-18 20:14:14 +00:00
|
|
|
nsTArray<nsString>* GlobalPrinters::mGlobalPrinterList = nsnull;
|
2006-02-07 01:13:12 +00:00
|
|
|
//---------------
|
2006-02-07 01:13:09 +00:00
|
|
|
|
2006-02-07 01:13:27 +00:00
|
|
|
nsDeviceContextSpecGTK::nsDeviceContextSpecGTK()
|
2009-03-30 16:15:56 +00:00
|
|
|
: mPrintJob(NULL)
|
|
|
|
, mGtkPrinter(NULL)
|
|
|
|
, mGtkPrintSettings(NULL)
|
|
|
|
, mGtkPageSetup(NULL)
|
1999-02-18 22:35:11 +00:00
|
|
|
{
|
2006-02-07 01:13:44 +00:00
|
|
|
DO_PR_DEBUG_LOG(("nsDeviceContextSpecGTK::nsDeviceContextSpecGTK()\n"));
|
1999-02-18 22:35:11 +00:00
|
|
|
}
|
|
|
|
|
2006-02-07 01:13:27 +00:00
|
|
|
nsDeviceContextSpecGTK::~nsDeviceContextSpecGTK()
|
1999-02-18 22:35:11 +00:00
|
|
|
{
|
2006-02-07 01:13:44 +00:00
|
|
|
DO_PR_DEBUG_LOG(("nsDeviceContextSpecGTK::~nsDeviceContextSpecGTK()\n"));
|
2008-02-13 11:03:43 +00:00
|
|
|
|
|
|
|
if (mGtkPageSetup) {
|
|
|
|
g_object_unref(mGtkPageSetup);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (mGtkPrintSettings) {
|
|
|
|
g_object_unref(mGtkPrintSettings);
|
|
|
|
}
|
1999-02-18 22:35:11 +00:00
|
|
|
}
|
|
|
|
|
2006-11-30 02:12:03 +00:00
|
|
|
NS_IMPL_ISUPPORTS1(nsDeviceContextSpecGTK,
|
|
|
|
nsIDeviceContextSpec)
|
2006-02-07 01:12:13 +00:00
|
|
|
|
2006-02-10 20:44:48 +00:00
|
|
|
#include "gfxPDFSurface.h"
|
2006-02-13 22:37:13 +00:00
|
|
|
#include "gfxPSSurface.h"
|
2006-02-10 20:44:48 +00:00
|
|
|
NS_IMETHODIMP nsDeviceContextSpecGTK::GetSurfaceForPrinter(gfxASurface **aSurface)
|
|
|
|
{
|
2007-08-22 18:07:18 +00:00
|
|
|
*aSurface = nsnull;
|
|
|
|
|
2006-11-29 23:40:16 +00:00
|
|
|
const char *path;
|
2006-02-10 20:44:48 +00:00
|
|
|
GetPath(&path);
|
|
|
|
|
2007-07-16 23:16:48 +00:00
|
|
|
double width, height;
|
|
|
|
mPrintSettings->GetEffectivePageSize(&width, &height);
|
2008-04-08 00:32:48 +00:00
|
|
|
|
2006-02-10 20:44:48 +00:00
|
|
|
// convert twips to points
|
2008-03-19 20:51:42 +00:00
|
|
|
width /= TWIPS_PER_POINT_FLOAT;
|
|
|
|
height /= TWIPS_PER_POINT_FLOAT;
|
2006-02-10 20:44:48 +00:00
|
|
|
|
2007-07-16 23:16:48 +00:00
|
|
|
DO_PR_DEBUG_LOG(("\"%s\", %f, %f\n", path, width, height));
|
2008-01-21 03:47:25 +00:00
|
|
|
nsresult rv;
|
|
|
|
|
|
|
|
// Spool file. Use Glib's temporary file function since we're
|
|
|
|
// already dependent on the gtk software stack.
|
|
|
|
gchar *buf;
|
|
|
|
gint fd = g_file_open_tmp("XXXXXX.tmp", &buf, nsnull);
|
|
|
|
if (-1 == fd)
|
|
|
|
return NS_ERROR_GFX_PRINTER_COULD_NOT_OPEN_FILE;
|
|
|
|
close(fd);
|
|
|
|
|
2011-10-03 07:56:21 +00:00
|
|
|
rv = NS_NewNativeLocalFile(nsDependentCString(buf), false,
|
2008-01-21 03:47:25 +00:00
|
|
|
getter_AddRefs(mSpoolFile));
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
unlink(buf);
|
|
|
|
return NS_ERROR_GFX_PRINTER_COULD_NOT_OPEN_FILE;
|
|
|
|
}
|
2006-02-10 20:44:48 +00:00
|
|
|
|
2008-01-21 03:47:25 +00:00
|
|
|
mSpoolName = buf;
|
|
|
|
g_free(buf);
|
2007-06-17 20:17:23 +00:00
|
|
|
|
2008-01-21 03:47:25 +00:00
|
|
|
mSpoolFile->SetPermissions(0600);
|
2007-03-01 00:02:27 +00:00
|
|
|
|
|
|
|
nsCOMPtr<nsIFileOutputStream> stream = do_CreateInstance("@mozilla.org/network/file-output-stream;1");
|
2008-01-21 03:47:25 +00:00
|
|
|
rv = stream->Init(mSpoolFile, -1, -1, 0);
|
2007-03-01 00:02:27 +00:00
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return rv;
|
|
|
|
|
2007-08-22 18:07:18 +00:00
|
|
|
PRInt16 format;
|
|
|
|
mPrintSettings->GetOutputFormat(&format);
|
|
|
|
|
|
|
|
nsRefPtr<gfxASurface> surface;
|
2008-01-21 03:47:25 +00:00
|
|
|
gfxSize surfaceSize(width, height);
|
|
|
|
|
|
|
|
// Determine the real format with some GTK magic
|
|
|
|
if (format == nsIPrintSettings::kOutputFormatNative) {
|
|
|
|
if (mIsPPreview) {
|
|
|
|
// There is nothing to detect on Print Preview, use PS.
|
|
|
|
format = nsIPrintSettings::kOutputFormatPS;
|
|
|
|
} else {
|
|
|
|
const gchar* fmtGTK = gtk_print_settings_get(mGtkPrintSettings, GTK_PRINT_SETTINGS_OUTPUT_FILE_FORMAT);
|
|
|
|
if (!fmtGTK && GTK_IS_PRINTER(mGtkPrinter)) {
|
|
|
|
// Likely not print-to-file, check printer's capabilities
|
2011-03-25 03:38:59 +00:00
|
|
|
|
|
|
|
// Prior to gtk 2.24, gtk_printer_accepts_pdf() and
|
|
|
|
// gtk_printer_accepts_ps() always returned true regardless of the
|
|
|
|
// printer's capability.
|
|
|
|
if (gtk_major_version > 2 ||
|
|
|
|
(gtk_major_version == 2 && gtk_minor_version >= 24)) {
|
|
|
|
format =
|
|
|
|
gtk_printer_accepts_pdf(mGtkPrinter) ?
|
|
|
|
static_cast<PRInt16>(nsIPrintSettings::kOutputFormatPDF) :
|
|
|
|
static_cast<PRInt16>(nsIPrintSettings::kOutputFormatPS);
|
|
|
|
} else {
|
|
|
|
format = nsIPrintSettings::kOutputFormatPS;
|
|
|
|
}
|
|
|
|
|
2008-01-21 03:47:25 +00:00
|
|
|
} else if (nsDependentCString(fmtGTK).EqualsIgnoreCase("pdf")) {
|
2011-02-01 10:16:46 +00:00
|
|
|
format = nsIPrintSettings::kOutputFormatPDF;
|
2008-01-21 03:47:25 +00:00
|
|
|
} else {
|
2011-02-01 10:16:46 +00:00
|
|
|
format = nsIPrintSettings::kOutputFormatPS;
|
2008-01-21 03:47:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (format == nsIPrintSettings::kOutputFormatPDF) {
|
|
|
|
surface = new gfxPDFSurface(stream, surfaceSize);
|
2007-08-22 18:07:18 +00:00
|
|
|
} else {
|
2011-07-14 17:02:20 +00:00
|
|
|
PRInt32 orientation;
|
|
|
|
mPrintSettings->GetOrientation(&orientation);
|
|
|
|
if (nsIPrintSettings::kPortraitOrientation == orientation) {
|
|
|
|
surface = new gfxPSSurface(stream, surfaceSize, gfxPSSurface::PORTRAIT);
|
|
|
|
} else {
|
|
|
|
surface = new gfxPSSurface(stream, surfaceSize, gfxPSSurface::LANDSCAPE);
|
|
|
|
}
|
2007-08-22 18:07:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!surface)
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
|
|
|
|
surface.swap(*aSurface);
|
2006-02-10 20:44:48 +00:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1999-02-18 22:35:11 +00:00
|
|
|
/** -------------------------------------------------------
|
|
|
|
* Initialize the nsDeviceContextSpecGTK
|
|
|
|
* @update dc 2/15/98
|
1999-03-13 03:21:16 +00:00
|
|
|
* @update syd 3/2/99
|
1999-02-18 22:35:11 +00:00
|
|
|
*/
|
2006-12-09 17:18:56 +00:00
|
|
|
NS_IMETHODIMP nsDeviceContextSpecGTK::Init(nsIWidget *aWidget,
|
|
|
|
nsIPrintSettings* aPS,
|
2011-09-29 06:19:26 +00:00
|
|
|
bool aIsPrintPreview)
|
1999-02-18 22:35:11 +00:00
|
|
|
{
|
2006-02-07 01:13:53 +00:00
|
|
|
DO_PR_DEBUG_LOG(("nsDeviceContextSpecGTK::Init(aPS=%p)\n", aPS));
|
2008-01-21 03:47:25 +00:00
|
|
|
|
|
|
|
if (gtk_major_version < 2 ||
|
|
|
|
(gtk_major_version == 2 && gtk_minor_version < 10))
|
|
|
|
return NS_ERROR_NOT_AVAILABLE; // I'm so sorry bz
|
2006-02-07 01:12:18 +00:00
|
|
|
|
2006-02-07 01:13:12 +00:00
|
|
|
mPrintSettings = aPS;
|
2008-01-21 03:47:25 +00:00
|
|
|
mIsPPreview = aIsPrintPreview;
|
2006-02-07 01:13:09 +00:00
|
|
|
|
2008-01-21 03:47:25 +00:00
|
|
|
// This is only set by embedders
|
2011-09-29 06:19:26 +00:00
|
|
|
bool toFile;
|
2008-01-21 03:47:25 +00:00
|
|
|
aPS->GetPrintToFile(&toFile);
|
2008-01-17 06:27:50 +00:00
|
|
|
|
2008-01-21 03:47:25 +00:00
|
|
|
mToPrinter = !toFile && !aIsPrintPreview;
|
2006-02-07 01:12:41 +00:00
|
|
|
|
2008-01-21 03:47:25 +00:00
|
|
|
nsCOMPtr<nsPrintSettingsGTK> printSettingsGTK(do_QueryInterface(aPS));
|
|
|
|
if (!printSettingsGTK)
|
|
|
|
return NS_ERROR_NO_INTERFACE;
|
|
|
|
|
|
|
|
mGtkPrinter = printSettingsGTK->GetGtkPrinter();
|
|
|
|
mGtkPrintSettings = printSettingsGTK->GetGtkPrintSettings();
|
|
|
|
mGtkPageSetup = printSettingsGTK->GetGtkPageSetup();
|
|
|
|
|
2008-02-13 11:03:43 +00:00
|
|
|
// This is a horrible workaround for some printer driver bugs that treat custom page sizes different
|
|
|
|
// to standard ones. If our paper object matches one of a standard one, use a standard paper size
|
2008-02-13 11:05:09 +00:00
|
|
|
// object instead. See bug 414314 for more info.
|
2008-02-13 11:03:43 +00:00
|
|
|
GtkPaperSize* geckosHackishPaperSize = gtk_page_setup_get_paper_size(mGtkPageSetup);
|
|
|
|
GtkPaperSize* standardGtkPaperSize = gtk_paper_size_new(gtk_paper_size_get_name(geckosHackishPaperSize));
|
|
|
|
|
|
|
|
mGtkPageSetup = gtk_page_setup_copy(mGtkPageSetup);
|
|
|
|
mGtkPrintSettings = gtk_print_settings_copy(mGtkPrintSettings);
|
|
|
|
|
|
|
|
GtkPaperSize* properPaperSize;
|
|
|
|
if (gtk_paper_size_is_equal(geckosHackishPaperSize, standardGtkPaperSize)) {
|
|
|
|
properPaperSize = standardGtkPaperSize;
|
|
|
|
} else {
|
|
|
|
properPaperSize = geckosHackishPaperSize;
|
|
|
|
}
|
|
|
|
gtk_print_settings_set_paper_size(mGtkPrintSettings, properPaperSize);
|
|
|
|
gtk_page_setup_set_paper_size_and_default_margins(mGtkPageSetup, properPaperSize);
|
2011-03-25 03:38:59 +00:00
|
|
|
gtk_paper_size_free(standardGtkPaperSize);
|
2008-02-13 11:03:43 +00:00
|
|
|
|
2008-01-21 03:47:25 +00:00
|
|
|
return NS_OK;
|
1999-02-18 22:35:11 +00:00
|
|
|
}
|
|
|
|
|
2006-02-07 01:13:27 +00:00
|
|
|
NS_IMETHODIMP nsDeviceContextSpecGTK::GetPath(const char **aPath)
|
1999-03-22 21:45:00 +00:00
|
|
|
{
|
2006-02-07 01:13:27 +00:00
|
|
|
*aPath = mPath;
|
1999-03-22 21:45:00 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2006-02-07 01:13:44 +00:00
|
|
|
/* static !! */
|
|
|
|
nsresult nsDeviceContextSpecGTK::GetPrintMethod(const char *aPrinter, PrintMethod &aMethod)
|
2006-02-07 01:12:13 +00:00
|
|
|
{
|
2006-02-07 01:13:43 +00:00
|
|
|
aMethod = pmPostScript;
|
|
|
|
return NS_OK;
|
2006-02-07 01:12:13 +00:00
|
|
|
}
|
|
|
|
|
2008-01-21 03:47:25 +00:00
|
|
|
static void
|
|
|
|
print_callback(GtkPrintJob *aJob, gpointer aData, GError *aError) {
|
|
|
|
g_object_unref(aJob);
|
2011-10-03 07:56:21 +00:00
|
|
|
((nsILocalFile*) aData)->Remove(false);
|
2008-01-21 03:47:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
ns_release_macro(gpointer aData) {
|
|
|
|
nsILocalFile* spoolFile = (nsILocalFile*) aData;
|
|
|
|
NS_RELEASE(spoolFile);
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP nsDeviceContextSpecGTK::BeginDocument(PRUnichar * aTitle, PRUnichar * aPrintToFileName,
|
|
|
|
PRInt32 aStartPage, PRInt32 aEndPage)
|
2006-11-29 23:40:16 +00:00
|
|
|
{
|
2008-01-21 03:47:25 +00:00
|
|
|
if (mToPrinter) {
|
|
|
|
if (!GTK_IS_PRINTER(mGtkPrinter))
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
|
|
|
mPrintJob = gtk_print_job_new(NS_ConvertUTF16toUTF8(aTitle).get(), mGtkPrinter,
|
|
|
|
mGtkPrintSettings, mGtkPageSetup);
|
|
|
|
}
|
|
|
|
|
2006-11-29 23:40:16 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
2007-06-17 20:17:23 +00:00
|
|
|
|
2006-11-29 23:40:16 +00:00
|
|
|
NS_IMETHODIMP nsDeviceContextSpecGTK::EndDocument()
|
|
|
|
{
|
2008-01-21 03:47:25 +00:00
|
|
|
if (mToPrinter) {
|
2009-03-30 16:15:56 +00:00
|
|
|
if (!mPrintJob)
|
|
|
|
return NS_OK; // The operation was aborted.
|
|
|
|
|
2008-02-13 23:14:52 +00:00
|
|
|
if (!gtk_print_job_set_source_file(mPrintJob, mSpoolName.get(), nsnull))
|
2008-01-21 03:47:25 +00:00
|
|
|
return NS_ERROR_GFX_PRINTER_COULD_NOT_OPEN_FILE;
|
|
|
|
|
|
|
|
NS_ADDREF(mSpoolFile.get());
|
|
|
|
gtk_print_job_send(mPrintJob, print_callback, mSpoolFile, ns_release_macro);
|
|
|
|
} else {
|
|
|
|
// Handle print-to-file ourselves for the benefit of embedders
|
|
|
|
nsXPIDLString targetPath;
|
|
|
|
nsCOMPtr<nsILocalFile> destFile;
|
|
|
|
mPrintSettings->GetToFileName(getter_Copies(targetPath));
|
|
|
|
|
|
|
|
nsresult rv = NS_NewNativeLocalFile(NS_ConvertUTF16toUTF8(targetPath),
|
2011-10-03 07:56:21 +00:00
|
|
|
false, getter_AddRefs(destFile));
|
2008-01-21 03:47:25 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
nsAutoString destLeafName;
|
|
|
|
rv = destFile->GetLeafName(destLeafName);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
nsCOMPtr<nsIFile> destDir;
|
|
|
|
rv = destFile->GetParent(getter_AddRefs(destDir));
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
rv = mSpoolFile->MoveTo(destDir, destLeafName);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
// This is the standard way to get the UNIX umask. Ugh.
|
|
|
|
mode_t mask = umask(0);
|
|
|
|
umask(mask);
|
|
|
|
// If you're not familiar with umasks, they contain the bits of what NOT to set in the permissions
|
|
|
|
// (thats because files and directories have different numbers of bits for their permissions)
|
|
|
|
destFile->SetPermissions(0666 & ~(mask));
|
|
|
|
}
|
|
|
|
return NS_OK;
|
2006-11-29 23:40:16 +00:00
|
|
|
}
|
|
|
|
|
2006-02-07 01:13:44 +00:00
|
|
|
/* Get prefs for printer
|
|
|
|
* Search order:
|
|
|
|
* - Get prefs per printer name and module name
|
|
|
|
* - Get prefs per printer name
|
|
|
|
* - Get prefs per module name
|
|
|
|
* - Get prefs
|
|
|
|
*/
|
|
|
|
static
|
2011-05-27 08:15:20 +00:00
|
|
|
nsresult CopyPrinterCharPref(const char *modulename, const char *printername,
|
|
|
|
const char *prefname, nsCString &return_buf)
|
2006-02-07 01:13:44 +00:00
|
|
|
{
|
|
|
|
DO_PR_DEBUG_LOG(("CopyPrinterCharPref('%s', '%s', '%s')\n", modulename, printername, prefname));
|
|
|
|
|
|
|
|
nsresult rv = NS_ERROR_FAILURE;
|
|
|
|
|
|
|
|
if (printername && modulename) {
|
|
|
|
/* Get prefs per printer name and module name */
|
2012-04-24 18:43:00 +00:00
|
|
|
nsPrintfCString name("print.%s.printer_%s.%s", modulename, printername, prefname);
|
2006-02-07 01:13:44 +00:00
|
|
|
DO_PR_DEBUG_LOG(("trying to get '%s'\n", name.get()));
|
2011-05-27 08:15:20 +00:00
|
|
|
rv = Preferences::GetCString(name.get(), &return_buf);
|
2006-02-07 01:13:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
if (printername) {
|
|
|
|
/* Get prefs per printer name */
|
2012-04-24 18:43:00 +00:00
|
|
|
nsPrintfCString name("print.printer_%s.%s", printername, prefname);
|
2006-02-07 01:13:44 +00:00
|
|
|
DO_PR_DEBUG_LOG(("trying to get '%s'\n", name.get()));
|
2011-05-27 08:15:20 +00:00
|
|
|
rv = Preferences::GetCString(name.get(), &return_buf);
|
2006-02-07 01:13:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
if (modulename) {
|
|
|
|
/* Get prefs per module name */
|
2012-04-24 18:43:00 +00:00
|
|
|
nsPrintfCString name("print.%s.%s", modulename, prefname);
|
2006-02-07 01:13:44 +00:00
|
|
|
DO_PR_DEBUG_LOG(("trying to get '%s'\n", name.get()));
|
2011-05-27 08:15:20 +00:00
|
|
|
rv = Preferences::GetCString(name.get(), &return_buf);
|
2006-02-07 01:13:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
/* Get prefs */
|
2012-04-24 18:43:00 +00:00
|
|
|
nsPrintfCString name("print.%s", prefname);
|
2006-02-07 01:13:44 +00:00
|
|
|
DO_PR_DEBUG_LOG(("trying to get '%s'\n", name.get()));
|
2011-05-27 08:15:20 +00:00
|
|
|
rv = Preferences::GetCString(name.get(), &return_buf);
|
2006-02-07 01:13:44 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef PR_LOG
|
|
|
|
if (NS_SUCCEEDED(rv)) {
|
2006-11-06 19:09:39 +00:00
|
|
|
DO_PR_DEBUG_LOG(("CopyPrinterCharPref returning '%s'.\n", return_buf.get()));
|
2006-02-07 01:13:44 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
DO_PR_DEBUG_LOG(("CopyPrinterCharPref failure.\n"));
|
|
|
|
}
|
|
|
|
#endif /* PR_LOG */
|
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
2006-02-07 01:13:27 +00:00
|
|
|
|
2006-02-07 01:13:09 +00:00
|
|
|
// Printer Enumerator
|
|
|
|
nsPrinterEnumeratorGTK::nsPrinterEnumeratorGTK()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMPL_ISUPPORTS1(nsPrinterEnumeratorGTK, nsIPrinterEnumerator)
|
|
|
|
|
2007-05-06 11:29:41 +00:00
|
|
|
NS_IMETHODIMP nsPrinterEnumeratorGTK::GetPrinterNameList(nsIStringEnumerator **aPrinterNameList)
|
1999-02-18 22:35:11 +00:00
|
|
|
{
|
2007-05-06 11:29:41 +00:00
|
|
|
NS_ENSURE_ARG_POINTER(aPrinterNameList);
|
|
|
|
*aPrinterNameList = nsnull;
|
2006-02-07 01:13:09 +00:00
|
|
|
|
2006-02-07 01:13:12 +00:00
|
|
|
nsresult rv = GlobalPrinters::GetInstance()->InitializeGlobalPrinters();
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2010-10-06 22:18:52 +00:00
|
|
|
PRUint32 numPrinters = GlobalPrinters::GetInstance()->GetNumPrinters();
|
2009-01-18 20:14:14 +00:00
|
|
|
nsTArray<nsString> *printers = new nsTArray<nsString>(numPrinters);
|
2007-05-06 11:29:41 +00:00
|
|
|
if (!printers) {
|
2006-02-07 01:13:12 +00:00
|
|
|
GlobalPrinters::GetInstance()->FreeGlobalPrinters();
|
2006-02-07 01:13:09 +00:00
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
2006-02-07 01:13:12 +00:00
|
|
|
}
|
2006-02-07 01:13:09 +00:00
|
|
|
|
2010-10-06 22:18:52 +00:00
|
|
|
PRUint32 count = 0;
|
2006-02-07 01:13:12 +00:00
|
|
|
while( count < numPrinters )
|
2006-02-07 01:13:09 +00:00
|
|
|
{
|
2009-01-18 20:14:14 +00:00
|
|
|
printers->AppendElement(*GlobalPrinters::GetInstance()->GetStringAt(count++));
|
2006-02-07 01:13:09 +00:00
|
|
|
}
|
2006-02-07 01:13:12 +00:00
|
|
|
GlobalPrinters::GetInstance()->FreeGlobalPrinters();
|
2006-02-07 01:13:09 +00:00
|
|
|
|
2007-05-06 11:29:41 +00:00
|
|
|
return NS_NewAdoptingStringEnumerator(aPrinterNameList, printers);
|
2006-02-07 01:12:41 +00:00
|
|
|
}
|
|
|
|
|
2006-02-07 01:13:34 +00:00
|
|
|
/* readonly attribute wstring defaultPrinterName; */
|
2006-02-07 01:13:44 +00:00
|
|
|
NS_IMETHODIMP nsPrinterEnumeratorGTK::GetDefaultPrinterName(PRUnichar **aDefaultPrinterName)
|
2006-02-07 01:13:34 +00:00
|
|
|
{
|
2006-02-07 01:13:44 +00:00
|
|
|
DO_PR_DEBUG_LOG(("nsPrinterEnumeratorGTK::GetDefaultPrinterName()\n"));
|
2006-02-07 01:13:34 +00:00
|
|
|
NS_ENSURE_ARG_POINTER(aDefaultPrinterName);
|
2006-02-07 01:13:44 +00:00
|
|
|
|
|
|
|
GlobalPrinters::GetInstance()->GetDefaultPrinterName(aDefaultPrinterName);
|
|
|
|
|
2006-02-07 01:15:21 +00:00
|
|
|
DO_PR_DEBUG_LOG(("GetDefaultPrinterName(): default printer='%s'.\n", NS_ConvertUTF16toUTF8(*aDefaultPrinterName).get()));
|
2006-02-07 01:13:34 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2006-02-07 01:13:32 +00:00
|
|
|
/* void initPrintSettingsFromPrinter (in wstring aPrinterName, in nsIPrintSettings aPrintSettings); */
|
|
|
|
NS_IMETHODIMP nsPrinterEnumeratorGTK::InitPrintSettingsFromPrinter(const PRUnichar *aPrinterName, nsIPrintSettings *aPrintSettings)
|
|
|
|
{
|
2006-02-07 01:13:44 +00:00
|
|
|
DO_PR_DEBUG_LOG(("nsPrinterEnumeratorGTK::InitPrintSettingsFromPrinter()"));
|
|
|
|
nsresult rv;
|
|
|
|
|
|
|
|
NS_ENSURE_ARG_POINTER(aPrinterName);
|
|
|
|
NS_ENSURE_ARG_POINTER(aPrintSettings);
|
|
|
|
|
2006-02-07 01:13:46 +00:00
|
|
|
NS_ENSURE_TRUE(*aPrinterName, NS_ERROR_FAILURE);
|
|
|
|
NS_ENSURE_TRUE(aPrintSettings, NS_ERROR_FAILURE);
|
2006-02-07 01:13:44 +00:00
|
|
|
|
2006-02-07 01:13:46 +00:00
|
|
|
nsXPIDLCString fullPrinterName, /* Full name of printer incl. driver-specific prefix */
|
|
|
|
printerName; /* "Stripped" name of printer */
|
2006-02-07 01:15:21 +00:00
|
|
|
fullPrinterName.Assign(NS_ConvertUTF16toUTF8(aPrinterName));
|
|
|
|
printerName.Assign(NS_ConvertUTF16toUTF8(aPrinterName));
|
2006-02-07 01:13:44 +00:00
|
|
|
DO_PR_DEBUG_LOG(("printerName='%s'\n", printerName.get()));
|
|
|
|
|
|
|
|
PrintMethod type = pmInvalid;
|
|
|
|
rv = nsDeviceContextSpecGTK::GetPrintMethod(printerName, type);
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return rv;
|
|
|
|
|
|
|
|
/* "Demangle" postscript printer name */
|
|
|
|
if (type == pmPostScript) {
|
2006-02-07 01:15:08 +00:00
|
|
|
/* Strip the printing method name from the printer,
|
2006-02-07 01:13:44 +00:00
|
|
|
* e.g. turn "PostScript/foobar" to "foobar" */
|
2006-02-07 01:15:08 +00:00
|
|
|
PRInt32 slash = printerName.FindChar('/');
|
|
|
|
if (kNotFound != slash)
|
|
|
|
printerName.Cut(0, slash + 1);
|
2006-02-07 01:13:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef SET_PRINTER_FEATURES_VIA_PREFS
|
|
|
|
/* Defaults to FALSE */
|
2012-04-24 18:43:00 +00:00
|
|
|
nsPrintfCString prefName(
|
2011-05-27 08:15:20 +00:00
|
|
|
PRINTERFEATURES_PREF ".%s.has_special_printerfeatures",
|
|
|
|
fullPrinterName.get());
|
2011-10-03 07:56:21 +00:00
|
|
|
Preferences::SetBool(prefName.get(), false);
|
2006-02-07 01:13:44 +00:00
|
|
|
#endif /* SET_PRINTER_FEATURES_VIA_PREFS */
|
|
|
|
|
2006-02-07 01:13:46 +00:00
|
|
|
|
|
|
|
/* Set filename */
|
2011-05-27 08:15:20 +00:00
|
|
|
nsCAutoString filename;
|
|
|
|
if (NS_FAILED(CopyPrinterCharPref(nsnull, printerName, "filename", filename))) {
|
2006-02-07 01:13:46 +00:00
|
|
|
const char *path;
|
|
|
|
|
|
|
|
if (!(path = PR_GetEnv("PWD")))
|
|
|
|
path = PR_GetEnv("HOME");
|
|
|
|
|
|
|
|
if (path)
|
2012-04-24 18:43:00 +00:00
|
|
|
filename = nsPrintfCString("%s/mozilla.pdf", path);
|
2006-02-07 01:13:46 +00:00
|
|
|
else
|
2011-09-23 14:06:21 +00:00
|
|
|
filename.AssignLiteral("mozilla.pdf");
|
2006-02-07 01:13:46 +00:00
|
|
|
}
|
|
|
|
DO_PR_DEBUG_LOG(("Setting default filename to '%s'\n", filename.get()));
|
2006-02-07 01:15:21 +00:00
|
|
|
aPrintSettings->SetToFileName(NS_ConvertUTF8toUTF16(filename).get());
|
2006-02-07 01:13:44 +00:00
|
|
|
|
2011-10-03 07:56:21 +00:00
|
|
|
aPrintSettings->SetIsInitializedFromPrinter(true);
|
2006-02-07 01:14:23 +00:00
|
|
|
|
2006-02-07 01:13:44 +00:00
|
|
|
if (type == pmPostScript) {
|
|
|
|
DO_PR_DEBUG_LOG(("InitPrintSettingsFromPrinter() for PostScript printer\n"));
|
2006-02-07 01:13:46 +00:00
|
|
|
|
|
|
|
#ifdef SET_PRINTER_FEATURES_VIA_PREFS
|
|
|
|
nsPrinterFeatures printerFeatures(fullPrinterName);
|
2006-02-07 01:14:39 +00:00
|
|
|
|
2011-10-03 07:56:21 +00:00
|
|
|
printerFeatures.SetSupportsPaperSizeChange(true);
|
|
|
|
printerFeatures.SetSupportsOrientationChange(true);
|
|
|
|
printerFeatures.SetSupportsPlexChange(false);
|
|
|
|
printerFeatures.SetSupportsResolutionNameChange(false);
|
|
|
|
printerFeatures.SetSupportsColorspaceChange(false);
|
2006-02-07 01:14:39 +00:00
|
|
|
#endif /* SET_PRINTER_FEATURES_VIA_PREFS */
|
2006-02-07 01:13:44 +00:00
|
|
|
|
2006-02-07 01:13:46 +00:00
|
|
|
#ifdef SET_PRINTER_FEATURES_VIA_PREFS
|
2011-10-03 07:56:21 +00:00
|
|
|
printerFeatures.SetCanChangeOrientation(true);
|
2006-02-07 01:13:46 +00:00
|
|
|
#endif /* SET_PRINTER_FEATURES_VIA_PREFS */
|
|
|
|
|
2011-05-27 08:15:20 +00:00
|
|
|
nsCAutoString orientation;
|
|
|
|
if (NS_SUCCEEDED(CopyPrinterCharPref("postscript", printerName,
|
|
|
|
"orientation", orientation))) {
|
2006-11-06 19:09:39 +00:00
|
|
|
if (orientation.LowerCaseEqualsLiteral("portrait")) {
|
2006-02-07 01:13:46 +00:00
|
|
|
DO_PR_DEBUG_LOG(("setting default orientation to 'portrait'\n"));
|
|
|
|
aPrintSettings->SetOrientation(nsIPrintSettings::kPortraitOrientation);
|
|
|
|
}
|
2006-11-06 19:09:39 +00:00
|
|
|
else if (orientation.LowerCaseEqualsLiteral("landscape")) {
|
2006-02-07 01:13:46 +00:00
|
|
|
DO_PR_DEBUG_LOG(("setting default orientation to 'landscape'\n"));
|
|
|
|
aPrintSettings->SetOrientation(nsIPrintSettings::kLandscapeOrientation);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
DO_PR_DEBUG_LOG(("Unknown default orientation '%s'\n", orientation.get()));
|
2006-02-07 01:13:44 +00:00
|
|
|
}
|
|
|
|
}
|
2006-02-07 01:13:46 +00:00
|
|
|
|
|
|
|
#ifdef SET_PRINTER_FEATURES_VIA_PREFS
|
2006-02-07 01:14:44 +00:00
|
|
|
printerFeatures.SetOrientationRecord(0, "portrait");
|
|
|
|
printerFeatures.SetOrientationRecord(1, "landscape");
|
|
|
|
printerFeatures.SetNumOrientationRecords(2);
|
2006-02-07 01:13:46 +00:00
|
|
|
#endif /* SET_PRINTER_FEATURES_VIA_PREFS */
|
2006-02-07 01:14:39 +00:00
|
|
|
|
|
|
|
/* PostScript module does not support changing the plex mode... */
|
|
|
|
#ifdef SET_PRINTER_FEATURES_VIA_PREFS
|
2011-10-03 07:56:21 +00:00
|
|
|
printerFeatures.SetCanChangePlex(false);
|
2006-02-07 01:14:39 +00:00
|
|
|
#endif /* SET_PRINTER_FEATURES_VIA_PREFS */
|
|
|
|
DO_PR_DEBUG_LOG(("setting default plex to '%s'\n", "default"));
|
|
|
|
aPrintSettings->SetPlexName(NS_LITERAL_STRING("default").get());
|
|
|
|
#ifdef SET_PRINTER_FEATURES_VIA_PREFS
|
|
|
|
printerFeatures.SetPlexRecord(0, "default");
|
|
|
|
printerFeatures.SetNumPlexRecords(1);
|
|
|
|
#endif /* SET_PRINTER_FEATURES_VIA_PREFS */
|
2006-02-07 01:15:09 +00:00
|
|
|
|
|
|
|
/* PostScript module does not support changing the resolution mode... */
|
|
|
|
#ifdef SET_PRINTER_FEATURES_VIA_PREFS
|
2011-10-03 07:56:21 +00:00
|
|
|
printerFeatures.SetCanChangeResolutionName(false);
|
2006-02-07 01:15:09 +00:00
|
|
|
#endif /* SET_PRINTER_FEATURES_VIA_PREFS */
|
|
|
|
DO_PR_DEBUG_LOG(("setting default resolution to '%s'\n", "default"));
|
|
|
|
aPrintSettings->SetResolutionName(NS_LITERAL_STRING("default").get());
|
|
|
|
#ifdef SET_PRINTER_FEATURES_VIA_PREFS
|
|
|
|
printerFeatures.SetResolutionNameRecord(0, "default");
|
|
|
|
printerFeatures.SetNumResolutionNameRecords(1);
|
|
|
|
#endif /* SET_PRINTER_FEATURES_VIA_PREFS */
|
|
|
|
|
|
|
|
/* PostScript module does not support changing the colorspace... */
|
|
|
|
#ifdef SET_PRINTER_FEATURES_VIA_PREFS
|
2011-10-03 07:56:21 +00:00
|
|
|
printerFeatures.SetCanChangeColorspace(false);
|
2006-02-07 01:15:09 +00:00
|
|
|
#endif /* SET_PRINTER_FEATURES_VIA_PREFS */
|
|
|
|
DO_PR_DEBUG_LOG(("setting default colorspace to '%s'\n", "default"));
|
|
|
|
aPrintSettings->SetColorspace(NS_LITERAL_STRING("default").get());
|
|
|
|
#ifdef SET_PRINTER_FEATURES_VIA_PREFS
|
|
|
|
printerFeatures.SetColorspaceRecord(0, "default");
|
|
|
|
printerFeatures.SetNumColorspaceRecords(1);
|
|
|
|
#endif /* SET_PRINTER_FEATURES_VIA_PREFS */
|
|
|
|
|
2006-02-07 01:13:46 +00:00
|
|
|
#ifdef SET_PRINTER_FEATURES_VIA_PREFS
|
2011-10-03 07:56:21 +00:00
|
|
|
printerFeatures.SetCanChangePaperSize(true);
|
2006-02-07 01:13:46 +00:00
|
|
|
#endif /* SET_PRINTER_FEATURES_VIA_PREFS */
|
2011-05-27 08:15:20 +00:00
|
|
|
nsCAutoString papername;
|
|
|
|
if (NS_SUCCEEDED(CopyPrinterCharPref("postscript", printerName,
|
|
|
|
"paper_size", papername))) {
|
2006-02-07 01:14:44 +00:00
|
|
|
nsPaperSizePS paper;
|
|
|
|
|
2011-05-27 08:15:20 +00:00
|
|
|
if (paper.Find(papername.get())) {
|
2006-02-07 01:14:44 +00:00
|
|
|
DO_PR_DEBUG_LOG(("setting default paper size to '%s' (%g mm/%g mm)\n",
|
|
|
|
paper.Name(), paper.Width_mm(), paper.Height_mm()));
|
2006-02-07 01:15:20 +00:00
|
|
|
aPrintSettings->SetPaperSizeUnit(nsIPrintSettings::kPaperSizeMillimeters);
|
2006-02-07 01:14:44 +00:00
|
|
|
aPrintSettings->SetPaperWidth(paper.Width_mm());
|
|
|
|
aPrintSettings->SetPaperHeight(paper.Height_mm());
|
2006-02-07 01:15:21 +00:00
|
|
|
aPrintSettings->SetPaperName(NS_ConvertASCIItoUTF16(paper.Name()).get());
|
2006-02-07 01:13:44 +00:00
|
|
|
}
|
2006-02-07 01:13:46 +00:00
|
|
|
else {
|
|
|
|
DO_PR_DEBUG_LOG(("Unknown paper size '%s' given.\n", papername.get()));
|
|
|
|
}
|
|
|
|
#ifdef SET_PRINTER_FEATURES_VIA_PREFS
|
2006-02-07 01:14:44 +00:00
|
|
|
paper.First();
|
|
|
|
int count = 0;
|
|
|
|
while (!paper.AtEnd())
|
2006-02-07 01:13:46 +00:00
|
|
|
{
|
2006-02-07 01:14:44 +00:00
|
|
|
printerFeatures.SetPaperRecord(count++, paper.Name(),
|
|
|
|
(int)paper.Width_mm(), (int)paper.Height_mm(), !paper.IsMetric());
|
|
|
|
paper.Next();
|
2006-02-07 01:13:46 +00:00
|
|
|
}
|
2006-02-07 01:14:44 +00:00
|
|
|
printerFeatures.SetNumPaperSizeRecords(count);
|
2006-02-07 01:13:46 +00:00
|
|
|
#endif /* SET_PRINTER_FEATURES_VIA_PREFS */
|
2006-02-07 01:13:44 +00:00
|
|
|
}
|
|
|
|
|
2011-09-29 06:19:26 +00:00
|
|
|
bool hasSpoolerCmd = (nsPSPrinterList::kTypePS ==
|
2006-02-07 01:15:08 +00:00
|
|
|
nsPSPrinterList::GetPrinterType(fullPrinterName));
|
2006-02-07 01:13:46 +00:00
|
|
|
#ifdef SET_PRINTER_FEATURES_VIA_PREFS
|
2006-02-07 01:15:08 +00:00
|
|
|
printerFeatures.SetSupportsSpoolerCommandChange(hasSpoolerCmd);
|
|
|
|
printerFeatures.SetCanChangeSpoolerCommand(hasSpoolerCmd);
|
2006-02-07 01:15:09 +00:00
|
|
|
|
|
|
|
/* Postscript module does not pass the job title to lpr */
|
2011-10-03 07:56:21 +00:00
|
|
|
printerFeatures.SetSupportsJobTitleChange(false);
|
|
|
|
printerFeatures.SetCanChangeJobTitle(false);
|
2006-02-07 01:15:09 +00:00
|
|
|
/* Postscript module has no control over builtin fonts yet */
|
2011-10-03 07:56:21 +00:00
|
|
|
printerFeatures.SetSupportsDownloadFontsChange(false);
|
|
|
|
printerFeatures.SetCanChangeDownloadFonts(false);
|
2006-02-07 01:15:09 +00:00
|
|
|
/* Postscript module does not support multiple colorspaces
|
|
|
|
* so it has to use the old way */
|
2011-10-03 07:56:21 +00:00
|
|
|
printerFeatures.SetSupportsPrintInColorChange(true);
|
|
|
|
printerFeatures.SetCanChangePrintInColor(true);
|
2006-02-07 01:13:46 +00:00
|
|
|
#endif /* SET_PRINTER_FEATURES_VIA_PREFS */
|
|
|
|
|
2006-02-07 01:15:08 +00:00
|
|
|
if (hasSpoolerCmd) {
|
2011-05-27 08:15:20 +00:00
|
|
|
nsCAutoString command;
|
|
|
|
if (NS_SUCCEEDED(CopyPrinterCharPref("postscript",
|
2006-11-06 19:09:39 +00:00
|
|
|
printerName, "print_command", command))) {
|
2006-02-07 01:15:08 +00:00
|
|
|
DO_PR_DEBUG_LOG(("setting default print command to '%s'\n",
|
|
|
|
command.get()));
|
2006-02-07 01:15:21 +00:00
|
|
|
aPrintSettings->SetPrintCommand(NS_ConvertUTF8toUTF16(command).get());
|
2006-02-07 01:15:08 +00:00
|
|
|
}
|
2006-02-07 01:13:44 +00:00
|
|
|
}
|
2006-02-07 01:13:46 +00:00
|
|
|
|
|
|
|
#ifdef SET_PRINTER_FEATURES_VIA_PREFS
|
2011-10-03 07:56:21 +00:00
|
|
|
printerFeatures.SetCanChangeNumCopies(true);
|
2006-02-07 01:13:46 +00:00
|
|
|
#endif /* SET_PRINTER_FEATURES_VIA_PREFS */
|
|
|
|
|
2006-02-07 01:13:44 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_ERROR_UNEXPECTED;
|
2006-02-07 01:13:32 +00:00
|
|
|
}
|
|
|
|
|
2006-02-07 01:13:44 +00:00
|
|
|
NS_IMETHODIMP nsPrinterEnumeratorGTK::DisplayPropertiesDlg(const PRUnichar *aPrinter, nsIPrintSettings *aPrintSettings)
|
2006-02-07 01:13:09 +00:00
|
|
|
{
|
2006-02-07 01:13:53 +00:00
|
|
|
return NS_OK;
|
2006-02-07 01:13:12 +00:00
|
|
|
}
|
2006-02-07 01:13:09 +00:00
|
|
|
|
2006-02-07 01:13:12 +00:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
nsresult GlobalPrinters::InitializeGlobalPrinters ()
|
|
|
|
{
|
|
|
|
if (PrintersAreAllocated()) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2006-02-07 01:13:09 +00:00
|
|
|
|
2009-01-18 20:14:14 +00:00
|
|
|
mGlobalPrinterList = new nsTArray<nsString>();
|
2006-02-07 01:14:54 +00:00
|
|
|
|
2006-02-07 01:15:08 +00:00
|
|
|
nsPSPrinterList psMgr;
|
2011-08-25 08:46:02 +00:00
|
|
|
if (psMgr.Enabled()) {
|
2006-02-07 01:14:42 +00:00
|
|
|
/* Get the list of PostScript-module printers */
|
2009-01-22 04:15:34 +00:00
|
|
|
// XXX: this function is the only user of GetPrinterList
|
|
|
|
// So it may be interesting to convert the nsCStrings
|
|
|
|
// in this function, we would save one loop here
|
|
|
|
nsTArray<nsCString> printerList;
|
2006-02-07 01:15:08 +00:00
|
|
|
psMgr.GetPrinterList(printerList);
|
2009-01-22 04:15:34 +00:00
|
|
|
for (PRUint32 i = 0; i < printerList.Length(); i++)
|
|
|
|
{
|
|
|
|
mGlobalPrinterList->AppendElement(NS_ConvertUTF8toUTF16(printerList[i]));
|
|
|
|
}
|
2006-02-07 01:13:09 +00:00
|
|
|
}
|
2010-06-28 17:36:17 +00:00
|
|
|
|
2006-02-07 01:14:34 +00:00
|
|
|
/* If there are no printers available after all checks, return an error */
|
2009-01-18 20:14:14 +00:00
|
|
|
if (!mGlobalPrinterList->Length())
|
2006-02-07 01:14:34 +00:00
|
|
|
{
|
|
|
|
/* Make sure we do not cache an empty printer list */
|
|
|
|
FreeGlobalPrinters();
|
|
|
|
|
|
|
|
return NS_ERROR_GFX_PRINTER_NO_PRINTER_AVAILABLE;
|
|
|
|
}
|
2006-02-07 01:13:09 +00:00
|
|
|
|
2006-02-07 01:13:12 +00:00
|
|
|
return NS_OK;
|
2006-02-07 01:13:09 +00:00
|
|
|
}
|
|
|
|
|
2006-02-07 01:13:12 +00:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
void GlobalPrinters::FreeGlobalPrinters()
|
|
|
|
{
|
2006-02-07 01:13:44 +00:00
|
|
|
if (mGlobalPrinterList) {
|
|
|
|
delete mGlobalPrinterList;
|
|
|
|
mGlobalPrinterList = nsnull;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
GlobalPrinters::GetDefaultPrinterName(PRUnichar **aDefaultPrinterName)
|
|
|
|
{
|
|
|
|
*aDefaultPrinterName = nsnull;
|
|
|
|
|
2011-09-29 06:19:26 +00:00
|
|
|
bool allocate = !GlobalPrinters::GetInstance()->PrintersAreAllocated();
|
2006-02-07 01:13:44 +00:00
|
|
|
|
|
|
|
if (allocate) {
|
|
|
|
nsresult rv = GlobalPrinters::GetInstance()->InitializeGlobalPrinters();
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
NS_ASSERTION(GlobalPrinters::GetInstance()->PrintersAreAllocated(), "no GlobalPrinters");
|
|
|
|
|
|
|
|
if (GlobalPrinters::GetInstance()->GetNumPrinters() == 0)
|
|
|
|
return;
|
|
|
|
|
|
|
|
*aDefaultPrinterName = ToNewUnicode(*GlobalPrinters::GetInstance()->GetStringAt(0));
|
|
|
|
|
|
|
|
if (allocate) {
|
|
|
|
GlobalPrinters::GetInstance()->FreeGlobalPrinters();
|
|
|
|
}
|
2006-02-07 01:13:12 +00:00
|
|
|
}
|
|
|
|
|