Lines 51-82
Link Here
|
51 |
#include "plstr.h" |
51 |
#include "plstr.h" |
52 |
|
52 |
|
53 |
#define NS_CUPS_PRINTER "CUPS/" |
53 |
#define NS_CUPS_PRINTER "CUPS/" |
54 |
#define NS_CUPS_PRINTER_LEN (sizeof(NS_CUPS_PRINTER) - 1) |
54 |
#define NS_CUPS_PRINTER_LEN (sizeof(NS_CUPS_PRINTER) - 1) |
55 |
|
55 |
|
56 |
/* dummy printer name for the gfx/src/ps driver */ |
56 |
/* dummy printer name for the gfx/src/ps driver */ |
57 |
#define NS_POSTSCRIPT_DRIVER_NAME "PostScript/" |
57 |
#define NS_POSTSCRIPT_DRIVER_NAME "PostScript/" |
58 |
|
58 |
|
|
|
59 |
nsCUPSShim gCupsShim; |
60 |
|
59 |
/* Initialize the printer manager object */ |
61 |
/* Initialize the printer manager object */ |
60 |
nsresult |
62 |
nsresult |
61 |
nsPSPrinterList::Init() |
63 |
nsPSPrinterList::Init() |
62 |
{ |
64 |
{ |
63 |
nsresult rv; |
65 |
nsresult rv; |
64 |
|
66 |
|
65 |
mPrefSvc = do_GetService(NS_PREFSERVICE_CONTRACTID, &rv); |
67 |
mPrefSvc = do_GetService(NS_PREFSERVICE_CONTRACTID, &rv); |
66 |
if (NS_SUCCEEDED(rv)) |
68 |
if (NS_SUCCEEDED(rv)) |
67 |
rv = mPrefSvc->GetBranch("print.", getter_AddRefs(mPref)); |
69 |
rv = mPrefSvc->GetBranch("print.", getter_AddRefs(mPref)); |
68 |
NS_ENSURE_SUCCESS(rv, NS_ERROR_NOT_INITIALIZED); |
70 |
NS_ENSURE_SUCCESS(rv, NS_ERROR_NOT_INITIALIZED); |
69 |
|
71 |
|
70 |
// Should we try cups? |
72 |
// Should we try cups? |
71 |
PRBool useCups = PR_TRUE; |
73 |
PRBool useCups = PR_TRUE; |
72 |
rv = mPref->GetBoolPref("postscript.cups.enabled", &useCups); |
74 |
rv = mPref->GetBoolPref("postscript.cups.enabled", &useCups); |
73 |
if (useCups) |
75 |
if (useCups && !gCupsShim.IsInitialized()) |
74 |
mCups.Init(); |
76 |
gCupsShim.Init(); |
75 |
return NS_OK; |
77 |
return NS_OK; |
76 |
} |
78 |
} |
77 |
|
79 |
|
78 |
|
80 |
|
79 |
/* Check whether the PostScript module has been disabled at runtime */ |
81 |
/* Check whether the PostScript module has been disabled at runtime */ |
80 |
PRBool |
82 |
PRBool |
81 |
nsPSPrinterList::Enabled() |
83 |
nsPSPrinterList::Enabled() |
82 |
{ |
84 |
{ |
Lines 94-128
nsPSPrinterList::Enabled()
Link Here
|
94 |
/* Fetch a list of printers handled by the PostsScript module */ |
96 |
/* Fetch a list of printers handled by the PostsScript module */ |
95 |
void |
97 |
void |
96 |
nsPSPrinterList::GetPrinterList(nsTArray<nsCString>& aList) |
98 |
nsPSPrinterList::GetPrinterList(nsTArray<nsCString>& aList) |
97 |
{ |
99 |
{ |
98 |
aList.Clear(); |
100 |
aList.Clear(); |
99 |
|
101 |
|
100 |
// Query CUPS for a printer list. The default printer goes to the |
102 |
// Query CUPS for a printer list. The default printer goes to the |
101 |
// head of the output list; others are appended. |
103 |
// head of the output list; others are appended. |
102 |
if (mCups.IsInitialized()) { |
104 |
if (gCupsShim.IsInitialized()) { |
103 |
cups_dest_t *dests; |
105 |
cups_dest_t *dests; |
104 |
|
106 |
|
105 |
int num_dests = (mCups.mCupsGetDests)(&dests); |
107 |
int num_dests = (gCupsShim.mCupsGetDests)(&dests); |
106 |
if (num_dests) { |
108 |
if (num_dests) { |
107 |
for (int i = 0; i < num_dests; i++) { |
109 |
for (int i = 0; i < num_dests; i++) { |
108 |
nsCAutoString fullName(NS_CUPS_PRINTER); |
110 |
nsCAutoString fullName(NS_CUPS_PRINTER); |
109 |
fullName.Append(dests[i].name); |
111 |
fullName.Append(dests[i].name); |
110 |
if (dests[i].instance != NULL) { |
112 |
if (dests[i].instance != NULL) { |
111 |
fullName.Append("/"); |
113 |
fullName.Append("/"); |
112 |
fullName.Append(dests[i].instance); |
114 |
fullName.Append(dests[i].instance); |
113 |
} |
115 |
} |
114 |
if (dests[i].is_default) |
116 |
if (dests[i].is_default) |
115 |
aList.InsertElementAt(0, fullName); |
117 |
aList.InsertElementAt(0, fullName); |
116 |
else |
118 |
else |
117 |
aList.AppendElement(fullName); |
119 |
aList.AppendElement(fullName); |
118 |
} |
120 |
} |
119 |
} |
121 |
} |
120 |
(mCups.mCupsFreeDests)(num_dests, dests); |
122 |
(gCupsShim.mCupsFreeDests)(num_dests, dests); |
121 |
} |
123 |
} |
122 |
|
124 |
|
123 |
// Build the "classic" list of printers -- those accessed by running |
125 |
// Build the "classic" list of printers -- those accessed by running |
124 |
// an opaque command. This list always contains a printer named "default". |
126 |
// an opaque command. This list always contains a printer named "default". |
125 |
// In addition, we look for either an environment variable |
127 |
// In addition, we look for either an environment variable |
126 |
// MOZILLA_POSTSCRIPT_PRINTER_LIST or a preference setting |
128 |
// MOZILLA_POSTSCRIPT_PRINTER_LIST or a preference setting |
127 |
// print.printer_list, which contains a space-separated list of printer |
129 |
// print.printer_list, which contains a space-separated list of printer |
128 |
// names. |
130 |
// names. |