| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/printing/print_dialog_gtk.h" | 5 #include "chrome/browser/printing/print_dialog_gtk.h" |
| 6 | 6 |
| 7 #include <fcntl.h> | 7 #include <fcntl.h> |
| 8 #include <gtk/gtkpagesetupunixdialog.h> | 8 #include <gtk/gtkpagesetupunixdialog.h> |
| 9 #include <gtk/gtkprintjob.h> | 9 #include <gtk/gtkprintjob.h> |
| 10 #include <sys/stat.h> | 10 #include <sys/stat.h> |
| (...skipping 11 matching lines...) Expand all Loading... |
| 22 #include "printing/metafile.h" | 22 #include "printing/metafile.h" |
| 23 #include "printing/print_job_constants.h" | 23 #include "printing/print_job_constants.h" |
| 24 #include "printing/print_settings_initializer_gtk.h" | 24 #include "printing/print_settings_initializer_gtk.h" |
| 25 | 25 |
| 26 using printing::PageRanges; | 26 using printing::PageRanges; |
| 27 using printing::PrintSettings; | 27 using printing::PrintSettings; |
| 28 | 28 |
| 29 namespace { | 29 namespace { |
| 30 | 30 |
| 31 // CUPS ColorModel attribute and values. | 31 // CUPS ColorModel attribute and values. |
| 32 const char kCMYK[] = "CMYK"; |
| 32 const char kCUPSColorModel[] = "cups-ColorModel"; | 33 const char kCUPSColorModel[] = "cups-ColorModel"; |
| 33 const char kColor[] = "Color"; | 34 const char kColor[] = "Color"; |
| 34 const char kGrayscale[] = "Grayscale"; | 35 const char kGrayscale[] = "Grayscale"; |
| 35 | 36 |
| 36 // CUPS Duplex attribute and values. | 37 // CUPS Duplex attribute and values. |
| 37 const char kCUPSDuplex[] = "cups-Duplex"; | 38 const char kCUPSDuplex[] = "cups-Duplex"; |
| 38 const char kDuplexNone[] = "None"; | 39 const char kDuplexNone[] = "None"; |
| 39 const char kDuplexTumble[] = "DuplexTumble"; | 40 const char kDuplexTumble[] = "DuplexTumble"; |
| 40 const char kDuplexNoTumble[] = "DuplexNoTumble"; | 41 const char kDuplexNoTumble[] = "DuplexNoTumble"; |
| 41 | 42 |
| (...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 150 page_setup_ = gtk_page_setup_new(); | 151 page_setup_ = gtk_page_setup_new(); |
| 151 | 152 |
| 152 // No page range to initialize for default settings. | 153 // No page range to initialize for default settings. |
| 153 PageRanges ranges_vector; | 154 PageRanges ranges_vector; |
| 154 InitPrintSettings(ranges_vector); | 155 InitPrintSettings(ranges_vector); |
| 155 } | 156 } |
| 156 | 157 |
| 157 bool PrintDialogGtk::UpdateSettings(const DictionaryValue& settings, | 158 bool PrintDialogGtk::UpdateSettings(const DictionaryValue& settings, |
| 158 const printing::PageRanges& ranges) { | 159 const printing::PageRanges& ranges) { |
| 159 bool collate; | 160 bool collate; |
| 160 bool color; | 161 int color; |
| 161 bool landscape; | 162 bool landscape; |
| 162 bool print_to_pdf; | 163 bool print_to_pdf; |
| 163 int copies; | 164 int copies; |
| 164 int duplex_mode; | 165 int duplex_mode; |
| 165 std::string device_name; | 166 std::string device_name; |
| 166 | 167 |
| 167 if (!settings.GetBoolean(printing::kSettingLandscape, &landscape) || | 168 if (!settings.GetBoolean(printing::kSettingLandscape, &landscape) || |
| 168 !settings.GetBoolean(printing::kSettingCollate, &collate) || | 169 !settings.GetBoolean(printing::kSettingCollate, &collate) || |
| 169 !settings.GetBoolean(printing::kSettingColor, &color) || | 170 !settings.GetInteger(printing::kSettingColor, &color) || |
| 170 !settings.GetBoolean(printing::kSettingPrintToPDF, &print_to_pdf) || | 171 !settings.GetBoolean(printing::kSettingPrintToPDF, &print_to_pdf) || |
| 171 !settings.GetInteger(printing::kSettingDuplexMode, &duplex_mode) || | 172 !settings.GetInteger(printing::kSettingDuplexMode, &duplex_mode) || |
| 172 !settings.GetInteger(printing::kSettingCopies, &copies) || | 173 !settings.GetInteger(printing::kSettingCopies, &copies) || |
| 173 !settings.GetString(printing::kSettingDeviceName, &device_name)) { | 174 !settings.GetString(printing::kSettingDeviceName, &device_name)) { |
| 174 return false; | 175 return false; |
| 175 } | 176 } |
| 176 | 177 |
| 177 if (!print_to_pdf) { | 178 if (!print_to_pdf) { |
| 178 scoped_ptr<GtkPrinterList> printer_list(new GtkPrinterList); | 179 scoped_ptr<GtkPrinterList> printer_list(new GtkPrinterList); |
| 179 printer_ = printer_list->GetPrinterWithName(device_name.c_str()); | 180 printer_ = printer_list->GetPrinterWithName(device_name.c_str()); |
| 180 if (printer_) { | 181 if (printer_) { |
| 181 g_object_ref(printer_); | 182 g_object_ref(printer_); |
| 182 gtk_print_settings_set_printer(gtk_settings_, | 183 gtk_print_settings_set_printer(gtk_settings_, |
| 183 gtk_printer_get_name(printer_)); | 184 gtk_printer_get_name(printer_)); |
| 184 } | 185 } |
| 185 gtk_print_settings_set_n_copies(gtk_settings_, copies); | 186 gtk_print_settings_set_n_copies(gtk_settings_, copies); |
| 186 gtk_print_settings_set_collate(gtk_settings_, collate); | 187 gtk_print_settings_set_collate(gtk_settings_, collate); |
| 187 gtk_print_settings_set(gtk_settings_, kCUPSColorModel, | 188 |
| 188 color ? kColor : kGrayscale); | 189 const char* color_mode; |
| 190 switch (color) { |
| 191 case printing::COLOR: |
| 192 color_mode = kColor; |
| 193 break; |
| 194 case printing::CMYK: |
| 195 color_mode = kCMYK; |
| 196 break; |
| 197 default: |
| 198 color_mode = kGrayscale; |
| 199 break; |
| 200 } |
| 201 gtk_print_settings_set(gtk_settings_, kCUPSColorModel, color_mode); |
| 202 |
| 189 const char* cups_duplex_mode; | 203 const char* cups_duplex_mode; |
| 190 switch (duplex_mode) { | 204 switch (duplex_mode) { |
| 191 case printing::LONG_EDGE: | 205 case printing::LONG_EDGE: |
| 192 cups_duplex_mode = kDuplexNoTumble; | 206 cups_duplex_mode = kDuplexNoTumble; |
| 193 break; | 207 break; |
| 194 case printing::SHORT_EDGE: | 208 case printing::SHORT_EDGE: |
| 195 cups_duplex_mode = kDuplexTumble; | 209 cups_duplex_mode = kDuplexTumble; |
| 196 break; | 210 break; |
| 197 default: | 211 default: |
| 198 cups_duplex_mode = kDuplexNone; | 212 cups_duplex_mode = kDuplexNone; |
| (...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 380 // Printing finished. Matches AddRef() in PrintDocument(); | 394 // Printing finished. Matches AddRef() in PrintDocument(); |
| 381 Release(); | 395 Release(); |
| 382 } | 396 } |
| 383 | 397 |
| 384 void PrintDialogGtk::InitPrintSettings(const PageRanges& page_ranges) { | 398 void PrintDialogGtk::InitPrintSettings(const PageRanges& page_ranges) { |
| 385 PrintSettings settings; | 399 PrintSettings settings; |
| 386 printing::PrintSettingsInitializerGtk::InitPrintSettings( | 400 printing::PrintSettingsInitializerGtk::InitPrintSettings( |
| 387 gtk_settings_, page_setup_, page_ranges, false, &settings); | 401 gtk_settings_, page_setup_, page_ranges, false, &settings); |
| 388 context_->InitWithSettings(settings); | 402 context_->InitWithSettings(settings); |
| 389 } | 403 } |
| OLD | NEW |