| 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> |
| 11 #include <sys/types.h> | 11 #include <sys/types.h> |
| 12 | 12 |
| 13 #include <string> | 13 #include <string> |
| 14 #include <vector> | 14 #include <vector> |
| 15 | 15 |
| 16 #include "base/file_util.h" | 16 #include "base/file_util.h" |
| 17 #include "base/file_util_proxy.h" | 17 #include "base/file_util_proxy.h" |
| 18 #include "base/logging.h" | 18 #include "base/logging.h" |
| 19 #include "base/utf_string_conversions.h" | 19 #include "base/utf_string_conversions.h" |
| 20 #include "chrome/browser/ui/browser_list.h" | 20 #include "chrome/browser/ui/browser_list.h" |
| 21 #include "chrome/browser/ui/browser_window.h" | 21 #include "chrome/browser/ui/browser_window.h" |
| 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.h" |
| 24 #include "printing/print_settings_initializer_gtk.h" | 25 #include "printing/print_settings_initializer_gtk.h" |
| 25 | 26 |
| 26 using printing::PageRanges; | 27 using printing::PageRanges; |
| 27 using printing::PrintSettings; | 28 using printing::PrintSettings; |
| 28 | 29 |
| 29 namespace { | 30 namespace { |
| 30 | 31 |
| 31 // CUPS ColorModel attribute and values. | 32 // CUPS ColorModel attribute and values. |
| 32 const char kCMYK[] = "CMYK"; | 33 const char kCMYK[] = "CMYK"; |
| 33 const char kCUPSColorModel[] = "cups-ColorModel"; | 34 const char kCUPSColorModel[] = "cups-ColorModel"; |
| (...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 145 gtk_print_settings_set_printer(gtk_settings_, | 146 gtk_print_settings_set_printer(gtk_settings_, |
| 146 gtk_printer_get_name(printer_)); | 147 gtk_printer_get_name(printer_)); |
| 147 page_setup_ = gtk_printer_get_default_page_size(printer_); | 148 page_setup_ = gtk_printer_get_default_page_size(printer_); |
| 148 } | 149 } |
| 149 | 150 |
| 150 if (!page_setup_) | 151 if (!page_setup_) |
| 151 page_setup_ = gtk_page_setup_new(); | 152 page_setup_ = gtk_page_setup_new(); |
| 152 | 153 |
| 153 // No page range to initialize for default settings. | 154 // No page range to initialize for default settings. |
| 154 PageRanges ranges_vector; | 155 PageRanges ranges_vector; |
| 155 InitPrintSettings(ranges_vector); | 156 PrintSettings settings; |
| 157 InitPrintSettings(ranges_vector, &settings); |
| 156 } | 158 } |
| 157 | 159 |
| 158 bool PrintDialogGtk::UpdateSettings(const DictionaryValue& settings, | 160 bool PrintDialogGtk::UpdateSettings(const DictionaryValue& job_settings, |
| 159 const printing::PageRanges& ranges) { | 161 const printing::PageRanges& ranges, |
| 162 printing::PrintSettings* settings) { |
| 160 bool collate; | 163 bool collate; |
| 161 int color; | 164 int color; |
| 162 bool landscape; | 165 bool landscape; |
| 163 bool print_to_pdf; | 166 bool print_to_pdf; |
| 164 int copies; | 167 int copies; |
| 165 int duplex_mode; | 168 int duplex_mode; |
| 166 std::string device_name; | 169 std::string device_name; |
| 167 | 170 |
| 168 if (!settings.GetBoolean(printing::kSettingLandscape, &landscape) || | 171 if (!job_settings.GetBoolean(printing::kSettingLandscape, &landscape) || |
| 169 !settings.GetBoolean(printing::kSettingCollate, &collate) || | 172 !job_settings.GetBoolean(printing::kSettingCollate, &collate) || |
| 170 !settings.GetInteger(printing::kSettingColor, &color) || | 173 !job_settings.GetInteger(printing::kSettingColor, &color) || |
| 171 !settings.GetBoolean(printing::kSettingPrintToPDF, &print_to_pdf) || | 174 !job_settings.GetBoolean(printing::kSettingPrintToPDF, &print_to_pdf) || |
| 172 !settings.GetInteger(printing::kSettingDuplexMode, &duplex_mode) || | 175 !job_settings.GetInteger(printing::kSettingDuplexMode, &duplex_mode) || |
| 173 !settings.GetInteger(printing::kSettingCopies, &copies) || | 176 !job_settings.GetInteger(printing::kSettingCopies, &copies) || |
| 174 !settings.GetString(printing::kSettingDeviceName, &device_name)) { | 177 !job_settings.GetString(printing::kSettingDeviceName, &device_name)) { |
| 175 return false; | 178 return false; |
| 176 } | 179 } |
| 177 | 180 |
| 178 if (!gtk_settings_) | 181 if (!gtk_settings_) |
| 179 gtk_settings_ = gtk_print_settings_new(); | 182 gtk_settings_ = gtk_print_settings_new(); |
| 180 | 183 |
| 181 if (!print_to_pdf) { | 184 if (!print_to_pdf) { |
| 182 scoped_ptr<GtkPrinterList> printer_list(new GtkPrinterList); | 185 scoped_ptr<GtkPrinterList> printer_list(new GtkPrinterList); |
| 183 printer_ = printer_list->GetPrinterWithName(device_name.c_str()); | 186 printer_ = printer_list->GetPrinterWithName(device_name.c_str()); |
| 184 if (printer_) { | 187 if (printer_) { |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 227 } | 230 } |
| 228 } | 231 } |
| 229 if (!page_setup_) | 232 if (!page_setup_) |
| 230 page_setup_ = gtk_page_setup_new(); | 233 page_setup_ = gtk_page_setup_new(); |
| 231 | 234 |
| 232 gtk_print_settings_set_orientation( | 235 gtk_print_settings_set_orientation( |
| 233 gtk_settings_, | 236 gtk_settings_, |
| 234 landscape ? GTK_PAGE_ORIENTATION_LANDSCAPE : | 237 landscape ? GTK_PAGE_ORIENTATION_LANDSCAPE : |
| 235 GTK_PAGE_ORIENTATION_PORTRAIT); | 238 GTK_PAGE_ORIENTATION_PORTRAIT); |
| 236 | 239 |
| 237 InitPrintSettings(ranges); | 240 InitPrintSettings(ranges, settings); |
| 238 return true; | 241 return true; |
| 239 } | 242 } |
| 240 | 243 |
| 241 void PrintDialogGtk::ShowDialog( | 244 void PrintDialogGtk::ShowDialog( |
| 242 PrintingContextCairo::PrintSettingsCallback* callback) { | 245 PrintingContextCairo::PrintSettingsCallback* callback) { |
| 243 callback_ = callback; | 246 callback_ = callback; |
| 244 | 247 |
| 245 GtkWindow* parent = BrowserList::GetLastActive()->window()->GetNativeHandle(); | 248 GtkWindow* parent = BrowserList::GetLastActive()->window()->GetNativeHandle(); |
| 246 // TODO(estade): We need a window title here. | 249 // TODO(estade): We need a window title here. |
| 247 dialog_ = gtk_print_unix_dialog_new(NULL, parent); | 250 dialog_ = gtk_print_unix_dialog_new(NULL, parent); |
| (...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 402 g_object_unref(print_job); | 405 g_object_unref(print_job); |
| 403 base::FileUtilProxy::Delete( | 406 base::FileUtilProxy::Delete( |
| 404 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::FILE), | 407 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::FILE), |
| 405 path_to_pdf_, | 408 path_to_pdf_, |
| 406 false, | 409 false, |
| 407 NULL); | 410 NULL); |
| 408 // Printing finished. Matches AddRef() in PrintDocument(); | 411 // Printing finished. Matches AddRef() in PrintDocument(); |
| 409 Release(); | 412 Release(); |
| 410 } | 413 } |
| 411 | 414 |
| 412 void PrintDialogGtk::InitPrintSettings(const PageRanges& page_ranges) { | 415 void PrintDialogGtk::InitPrintSettings(const PageRanges& page_ranges, |
| 413 PrintSettings settings; | 416 PrintSettings* settings) { |
| 414 printing::PrintSettingsInitializerGtk::InitPrintSettings( | 417 printing::PrintSettingsInitializerGtk::InitPrintSettings( |
| 415 gtk_settings_, page_setup_, page_ranges, false, &settings); | 418 gtk_settings_, page_setup_, page_ranges, false, settings); |
| 416 context_->InitWithSettings(settings); | 419 context_->InitWithSettings(*settings); |
| 417 } | 420 } |
| OLD | NEW |