Skip to content

Commit

Permalink
PrintPreview: [LINUX] Set color and duplex setting values in print jo…
Browse files Browse the repository at this point in the history
…b ticket.

BUG=79931
TEST=Enable print preview in linux. Preview a webpage. Set the color and duplex settings and print the data. Observe the output.

Review URL: http://codereview.chromium.org/6905007

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@83021 0039d316-1c4b-4281-b951-d872f2087c98
  • Loading branch information
kmadhusu@chromium.org committed Apr 26, 2011
1 parent 16aec87 commit a44b0c1
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 11 deletions.
36 changes: 34 additions & 2 deletions chrome/browser/printing/print_dialog_gtk.cc
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,17 @@ using printing::PrintSettings;

namespace {

// CUPS ColorModel attribute and values.
const char kCUPSColorModel[] = "cups-ColorModel";
const char kColor[] = "Color";
const char kGrayscale[] = "Grayscale";

// CUPS Duplex attribute and values.
const char kCUPSDuplex[] = "cups-Duplex";
const char kDuplexNone[] = "None";
const char kDuplexTumble[] = "DuplexTumble";
const char kDuplexNoTumble[] = "DuplexNoTumble";

// Helper class to track GTK printers.
class GtkPrinterList {
public:
Expand Down Expand Up @@ -179,8 +190,29 @@ bool PrintDialogGtk::UpdateSettings(const DictionaryValue& settings,
return false;
gtk_print_settings_set_collate(gtk_settings_, collate);

// TODO(thestig) Color: gtk_print_settings_set_color() does not work.
// TODO(thestig) Duplex: gtk_print_settings_set_duplex() does not work.
bool is_color;
if (!settings.GetBoolean(printing::kSettingColor, &is_color))
return false;

gtk_print_settings_set(gtk_settings_, kCUPSColorModel,
is_color ? kColor : kGrayscale);
int mode;
if (!settings.GetInteger(printing::kSettingDuplexMode, &mode))
return false;

const char* cups_duplex_mode;
switch (mode) {
case printing::LONG_EDGE:
cups_duplex_mode = kDuplexNoTumble;
break;
case printing::SHORT_EDGE:
cups_duplex_mode = kDuplexTumble;
break;
default:
cups_duplex_mode = kDuplexNone;
break;
}
gtk_print_settings_set(gtk_settings_, kCUPSDuplex, cups_duplex_mode);

InitPrintSettings(ranges);
return true;
Expand Down
2 changes: 1 addition & 1 deletion chrome/browser/resources/print_preview.js
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ function isTwoSided() {
* @return {number} duplex mode.
*/
function getDuplexMode() {
// Constants values matches printing::PrintingContext::DuplexMode enum.
// Constants values matches printing::DuplexMode enum.
const SIMPLEX = 0;
const LONG_EDGE = 1;
const SHORT_EDGE = 2;
Expand Down
7 changes: 7 additions & 0 deletions printing/print_job_constants.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,13 @@ extern const char kSettingPageRangeTo[];
extern const char kSettingPrinterName[];
extern const char kSettingPrintToPDF[];

// Print job duplex mode values.
enum DuplexMode {
SIMPLEX,
LONG_EDGE,
SHORT_EDGE,
};

} // namespace printing

#endif // PRINTING_PRINT_JOB_CONSTANTS_H_
7 changes: 0 additions & 7 deletions printing/printing_context.h
Original file line number Diff line number Diff line change
Expand Up @@ -99,13 +99,6 @@ class PrintingContext {
}

protected:
// Print job duplex mode values.
enum DuplexMode {
SIMPLEX,
LONG_EDGE,
SHORT_EDGE,
};

explicit PrintingContext(const std::string& app_locale);

// Reinitializes the settings for object reuse.
Expand Down
1 change: 1 addition & 0 deletions printing/printing_context_mac.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

#include "base/memory/scoped_nsobject.h"
#include "printing/printing_context.h"
#include "printing/print_job_constants.h"

#ifdef __OBJC__
@class NSPrintInfo;
Expand Down
1 change: 0 additions & 1 deletion printing/printing_context_mac.mm
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
#include "base/mac/scoped_cftyperef.h"
#include "base/sys_string_conversions.h"
#include "base/values.h"
#include "printing/print_job_constants.h"
#include "printing/print_settings_initializer_mac.h"

static const CFStringRef kColorModel = CFSTR("ColorModel");
Expand Down

0 comments on commit a44b0c1

Please sign in to comment.