diff options
author | Andreia Gaita <avidigal@novell.com> | 2007-01-20 01:41:06 +0300 |
---|---|---|
committer | Andreia Gaita <avidigal@novell.com> | 2007-01-20 01:41:06 +0300 |
commit | d41f32888ec480cff6e629f3f67008350038d3f6 (patch) | |
tree | 4b27c7e8796af06732f7383604cd9d7ae29a95dd /mcs/class/System.Drawing/System.Drawing.Printing | |
parent | 232fb9caac27864f3f090114f5065ebe55332d37 (diff) |
2007-01-19 Andreia Gaita <avidigal@novell.com>
* PrintingServicesUnix.cs: Add is_default flag check for
detecting default printer when cupsGetDefault doesn't return
valid values (mainly ubuntu). Fixes #80198, #80519
svn path=/trunk/mcs/; revision=71372
Diffstat (limited to 'mcs/class/System.Drawing/System.Drawing.Printing')
-rw-r--r-- | mcs/class/System.Drawing/System.Drawing.Printing/ChangeLog | 6 | ||||
-rw-r--r-- | mcs/class/System.Drawing/System.Drawing.Printing/PrintingServicesUnix.cs | 38 |
2 files changed, 40 insertions, 4 deletions
diff --git a/mcs/class/System.Drawing/System.Drawing.Printing/ChangeLog b/mcs/class/System.Drawing/System.Drawing.Printing/ChangeLog index 53afb7d3bc9..1a2d5ddb38f 100644 --- a/mcs/class/System.Drawing/System.Drawing.Printing/ChangeLog +++ b/mcs/class/System.Drawing/System.Drawing.Printing/ChangeLog @@ -1,3 +1,9 @@ +2007-01-19 Andreia Gaita <avidigal@novell.com> + + * PrintingServicesUnix.cs: Add is_default flag check for + detecting default printer when cupsGetDefault doesn't return + valid values (mainly ubuntu). Fixes #80198, #80519 + 2007-01-09 Sebastien Pouliot <sebastien@ximian.com> * PrintingServices.cs: Unify platform detection code. diff --git a/mcs/class/System.Drawing/System.Drawing.Printing/PrintingServicesUnix.cs b/mcs/class/System.Drawing/System.Drawing.Printing/PrintingServicesUnix.cs index 7c9579bc46b..64c3f8d04d2 100644 --- a/mcs/class/System.Drawing/System.Drawing.Printing/PrintingServicesUnix.cs +++ b/mcs/class/System.Drawing/System.Drawing.Printing/PrintingServicesUnix.cs @@ -347,15 +347,45 @@ namespace System.Drawing.Printing str = cupsGetDefault (); if (str != IntPtr.Zero) return Marshal.PtrToStringAnsi (str); - PrinterSettings.StringCollection printers = this.InstalledPrinters; - if (printers.Count > 0) - return printers[0]; - return String.Empty; + + return GetAlternativeDefaultPrinter(); } } // Private functions + /// <summary>
+ /// Due to some weird cups thing, cupsGetDefault does not always return
+ /// the default printer, hence this function, that goes through each
+ /// printer searching for one that has the is_default flag set.
+ /// If there is none with the flag, but there are printers available,
+ /// returns the first one. See #80519, #80198
+ /// </summary>
+ /// <returns></returns> + private string GetAlternativeDefaultPrinter() { + IntPtr printers = IntPtr.Zero; + CUPS_DESTS printer; + string printer_name = String.Empty; + + int cups_dests_size = Marshal.SizeOf(typeof(CUPS_DESTS)); + + int printer_count = cupsGetDests (ref printers); + + for (int i = 0; i < printer_count; i++) { + printer = (CUPS_DESTS) Marshal.PtrToStructure (printers, typeof (CUPS_DESTS)); + + if (printer.is_default != 0 || printer_name.Equals(String.Empty)) { + printer_name = Marshal.PtrToStringAnsi (printer.name); + if (printer.is_default != 0) + break; + } + printers = new IntPtr (printers.ToInt64 () + cups_dests_size); + } + Marshal.FreeHGlobal (printers); + + return printer_name; + } + private string GetPaperSizeName (IntPtr ppd, string name) { string rslt = name; |