Пример #1
0
nsPSPrinterList::nsPSPrinterList()
{
    // Should we try cups?
    if (Preferences::GetBool("print.postscript.cups.enabled", true) &&
        !gCupsShim.IsInitialized()) {
        gCupsShim.Init();
    }
}
Пример #2
0
/* Initialize the printer manager object */
nsresult
nsPSPrinterList::Init()
{
    // Should we try cups?
    PRBool useCups =
        Preferences::GetBool("print.postscript.cups.enabled", PR_TRUE);
    if (useCups && !gCupsShim.IsInitialized()) {
        gCupsShim.Init();
    }
    return NS_OK;
}
Пример #3
0
/* Fetch a list of printers handled by the PostsScript module */
void
nsPSPrinterList::GetPrinterList(nsTArray<nsCString>& aList)
{
    aList.Clear();

    // Query CUPS for a printer list. The default printer goes to the
    // head of the output list; others are appended.
    if (gCupsShim.IsInitialized()) {
        cups_dest_t *dests;

        int num_dests = (gCupsShim.mCupsGetDests)(&dests);
        if (num_dests) {
            for (int i = 0; i < num_dests; i++) {
                nsAutoCString fullName(NS_CUPS_PRINTER);
                fullName.Append(dests[i].name);
                if (dests[i].instance != nullptr) {
                    fullName.Append("/");
                    fullName.Append(dests[i].instance);
                }
                if (dests[i].is_default)
                    aList.InsertElementAt(0, fullName);
                else
                    aList.AppendElement(fullName);
            }
        }
        (gCupsShim.mCupsFreeDests)(num_dests, dests);
    }

    // Build the "classic" list of printers -- those accessed by running
    // an opaque command. This list always contains a printer named "default".
    // In addition, we look for either an environment variable
    // MOZILLA_POSTSCRIPT_PRINTER_LIST or a preference setting
    // print.printer_list, which contains a space-separated list of printer
    // names.
    aList.AppendElement(
            NS_LITERAL_CSTRING(NS_POSTSCRIPT_DRIVER_NAME "default"));

    nsAutoCString list(PR_GetEnv("MOZILLA_POSTSCRIPT_PRINTER_LIST"));
    if (list.IsEmpty()) {
        list = Preferences::GetCString("print.printer_list");
    }
    if (!list.IsEmpty()) {
        // For each printer (except "default" which was already added),
        // construct a string "PostScript/<name>" and append it to the list.
        char *state;

        for (char *name = PL_strtok_r(list.BeginWriting(), " ", &state);
                nullptr != name;
                name = PL_strtok_r(nullptr, " ", &state)
        ) {
            if (0 != strcmp(name, "default")) {
                nsAutoCString fullName(NS_POSTSCRIPT_DRIVER_NAME);
                fullName.Append(name);
                aList.AppendElement(fullName);
            }
        }
    }
}