Back to index

lightning-sunbird  0.9+nobinonly
Public Member Functions | Protected Member Functions | Private Attributes | Friends
nsPrintJobCUPS Class Reference

#include <nsPrintJobPS.h>

Inheritance diagram for nsPrintJobCUPS:
Inheritance graph
[legend]
Collaboration diagram for nsPrintJobCUPS:
Collaboration graph
[legend]

List of all members.

Public Member Functions

nsresult StartSubmission (FILE **aHandle)
 Create the final output file and copy the temporary files there.
nsresult FinishSubmission ()
 Finish a print job.
nsresult SetNumCopies (int aNumCopies)
 Set the number of copies for this print job.
void SetJobTitle (const PRUnichar *aTitle)
 Set the print job title.

Protected Member Functions

nsresult Init (nsIDeviceContextSpecPS *)
 Initialize a print-to-CUPS object.
void SetDestHandle (FILE *aHandle)
 Set the destination file handle.
FILEGetDestHandle ()
 Get the current value for the destination file handle.
void SetDestination (const char *aDest)
 Set a string representing the destination.
nsCStringGetDestination ()
 Get the string representing the destination.

Private Attributes

nsCUPSShim mCups
nsCString mPrinterName
nsCString mNumCopies
nsCString mJobTitle

Friends

class nsPrintJobFactoryPS

Detailed Description

Definition at line 168 of file nsPrintJobPS.h.


Member Function Documentation

Finish a print job.

See nsIPrintJobPS.h and nsPrintJobPS.h for details.

Reimplemented from nsPrintJobFilePS.

Definition at line 418 of file nsPrintJobPS.cpp.

{
    NS_ENSURE_TRUE(mCups.IsInitialized(), NS_ERROR_NOT_INITIALIZED);
    NS_PRECONDITION(GetDestHandle(), "No destination file handle");
    NS_PRECONDITION(!GetDestination().IsEmpty(), "No destination");

    fclose(GetDestHandle());
    SetDestHandle(nsnull);

    nsCStringArray printer(3);
    printer.ParseString(mPrinterName.get(),"/");

    cups_dest_t *dests, *dest;
    int num_dests = (mCups.mCupsGetDests)(&dests);
    
    if (printer.Count() == 1) {
        dest = (mCups.mCupsGetDest)(printer.CStringAt(0)->get(), NULL, num_dests, dests);
    } else {
        dest = (mCups.mCupsGetDest)(printer.CStringAt(0)->get(), 
                                    printer.CStringAt(1)->get(), num_dests, dests);
    }

    // Setting result just to get rid of compilation warning
    int result=0;
    if (dest != NULL) {
        if (!mNumCopies.IsEmpty())
            dest->num_options = (mCups.mCupsAddOption)("copies",
                                                       mNumCopies.get(),
                                                       dest->num_options,
                                                       &dest->options);
        const char *title = mJobTitle.IsVoid() ?
            "Untitled Document" : mJobTitle.get();
        result = (mCups.mCupsPrintFile)(printer.CStringAt(0)->get(),
                                            GetDestination().get(), title, 
                                            dest->num_options, dest->options);
    }
    (mCups.mCupsFreeDests)(num_dests, dests);
    unlink(GetDestination().get());

    // cupsPrintFile() result codes below 0x0300 indicate success.
    // Individual success codes are defined in the cups headers, but
    // we're not including those.
    if (dest == NULL)
        return NS_ERROR_GFX_PRINTER_NAME_NOT_FOUND;
    else
        return (result < 0x0300) ? NS_OK : NS_ERROR_GFX_PRINTER_CMD_FAILURE;
}

Here is the call graph for this function:

FILE* nsPrintJobFilePS::GetDestHandle ( ) [inline, protected, inherited]

Get the current value for the destination file handle.

Returns:
the current value for the destination file handle.

Definition at line 100 of file nsPrintJobPS.h.

{ return mDestHandle; }

Here is the caller graph for this function:

nsCString& nsPrintJobFilePS::GetDestination ( ) [inline, protected, inherited]

Get the string representing the destination.

Returns:
The current value of the destination string.

Definition at line 114 of file nsPrintJobPS.h.

{ return mDestination; }

Here is the caller graph for this function:

nsresult nsPrintJobCUPS::Init ( nsIDeviceContextSpecPS aSpec) [protected, virtual]

Initialize a print-to-CUPS object.

See nsIPrintJobPS.h and nsPrintJobPS.h for details.

Reimplemented from nsPrintJobFilePS.

Definition at line 348 of file nsPrintJobPS.cpp.

{
    NS_PRECONDITION(aSpec, "argument must not be NULL");
#ifdef DEBUG
    PRBool toPrinter;
    aSpec->GetToPrinter(toPrinter);
    NS_PRECONDITION(toPrinter, "Wrong class for this print job");
#endif

    NS_ENSURE_TRUE(mCups.Init(), NS_ERROR_NOT_INITIALIZED);

    /* Printer name */
    const char *printerName = nsnull;
    aSpec->GetPrinterName(&printerName);
    NS_ENSURE_TRUE(printerName, NS_ERROR_GFX_PRINTER_NAME_NOT_FOUND);

    const char *slash = strchr(printerName, '/');
    mPrinterName = slash ? slash + 1 : printerName;
    mJobTitle.SetIsVoid(PR_TRUE);
    return NS_OK;
}

Here is the call graph for this function:

void nsPrintJobFilePS::SetDestHandle ( FILE aHandle) [inline, protected, inherited]

Set the destination file handle.

Parameters:
aHandleNew value for the handle.

Definition at line 94 of file nsPrintJobPS.h.

Here is the caller graph for this function:

void nsPrintJobFilePS::SetDestination ( const char *  aDest) [inline, protected, inherited]

Set a string representing the destination.

For print-to-file this is the name of the destination file. Subclasses could store something else here.

Parameters:
aDestDestination filename.

Definition at line 108 of file nsPrintJobPS.h.

Here is the caller graph for this function:

Set the print job title.

Some printing systems accept a job title which is displayed on a banner page, in a print queue listing, etc.

This must be called after Init() and before StartSubmission(). nsIPrintJobPS provides a stub implementation because most classes do not make use of this information.

Parameters:
aTitleThe job title.

Reimplemented from nsIPrintJobPS.

Definition at line 385 of file nsPrintJobPS.cpp.

{
    if (aTitle) {
        LossyCopyUTF16toASCII(aTitle, mJobTitle);
    }
}

Here is the call graph for this function:

nsresult nsPrintJobCUPS::SetNumCopies ( int  aNumCopies) [virtual]

Set the number of copies for this print job.

Some printing systems allow setting this out of band, instead of embedding it into the postscript.

Parameters:
aNumCopiesNumber of copies requested. Values <= 1 are interpreted as "do not specify a copy count to the printing system" when possible, or else as one copy.
Returns:
NS_ERROR_NOT_IMPLEMENTED if this print job class doesn't support the specific copy count requested.
NS_OK The print job class will request the specified number of copies when printing the job.

Reimplemented from nsPrintJobFilePS.

Definition at line 371 of file nsPrintJobPS.cpp.

{
    mNumCopies.Truncate();
    if (aNumCopies > 1)
        mNumCopies.AppendInt(aNumCopies);
    return NS_OK;
}
nsresult nsPrintJobCUPS::StartSubmission ( FILE **  aHandle) [virtual]

Create the final output file and copy the temporary files there.

See nsIPrintJobPS.h and nsPrintJobPS.h for details.

Reimplemented from nsPrintJobFilePS.

Definition at line 394 of file nsPrintJobPS.cpp.

{
    NS_ENSURE_TRUE(mCups.IsInitialized(), NS_ERROR_NOT_INITIALIZED);

    int fd;
    char buf[FILENAME_MAX];

    fd = (mCups.mCupsTempFd)(buf, sizeof buf);
    // The CUPS manual doesn't describe what cupsTempFd() returns to
    // indicate failure. -1 is a likely value.
    NS_ENSURE_TRUE(fd > 0, NS_ERROR_GFX_PRINTER_COULD_NOT_OPEN_FILE);

    SetDestHandle(fdopen(fd, "r+"));
    if (!GetDestHandle()) {
        close(fd);
        return NS_ERROR_GFX_PRINTER_COULD_NOT_OPEN_FILE;
    }
    SetDestination(buf);
    *aHandle = GetDestHandle();
    return NS_OK;
}

Here is the call graph for this function:


Friends And Related Function Documentation

friend class nsPrintJobFactoryPS [friend, inherited]

Definition at line 65 of file nsIPrintJobPS.h.


Member Data Documentation

nsCUPSShim nsPrintJobCUPS::mCups [private]

Definition at line 179 of file nsPrintJobPS.h.

Definition at line 182 of file nsPrintJobPS.h.

Definition at line 181 of file nsPrintJobPS.h.

Definition at line 180 of file nsPrintJobPS.h.


The documentation for this class was generated from the following files: