| 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 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 148 #if GTK_CHECK_VERSION(2, 14, 0) | 148 #if GTK_CHECK_VERSION(2, 14, 0) |
| 149 page_setup_ = gtk_printer_get_default_page_size(printer_); | 149 page_setup_ = gtk_printer_get_default_page_size(printer_); |
| 150 #endif | 150 #endif |
| 151 } | 151 } |
| 152 | 152 |
| 153 if (!page_setup_) | 153 if (!page_setup_) |
| 154 page_setup_ = gtk_page_setup_new(); | 154 page_setup_ = gtk_page_setup_new(); |
| 155 | 155 |
| 156 // No page range to initialize for default settings. | 156 // No page range to initialize for default settings. |
| 157 PageRanges ranges_vector; | 157 PageRanges ranges_vector; |
| 158 InitPrintSettings(ranges_vector); | 158 DictionaryValue header_footer_info; |
| 159 header_footer_info.SetBoolean(printing::kSettingHeaderFooterEnabled, false); |
| 160 InitPrintSettings(ranges_vector, header_footer_info); |
| 159 } | 161 } |
| 160 | 162 |
| 161 bool PrintDialogGtk::UpdateSettings(const DictionaryValue& settings, | 163 bool PrintDialogGtk::UpdateSettings( |
| 162 const printing::PageRanges& ranges) { | 164 const DictionaryValue& settings, |
| 165 const printing::PageRanges& ranges, |
| 166 const base::DictionaryValue& header_footer_info) { |
| 163 bool collate; | 167 bool collate; |
| 164 bool color; | 168 bool color; |
| 165 bool landscape; | 169 bool landscape; |
| 166 bool print_to_pdf; | 170 bool print_to_pdf; |
| 167 int copies; | 171 int copies; |
| 168 int duplex_mode; | 172 int duplex_mode; |
| 169 std::string device_name; | 173 std::string device_name; |
| 170 | 174 |
| 171 if (!settings.GetBoolean(printing::kSettingLandscape, &landscape) || | 175 if (!settings.GetBoolean(printing::kSettingLandscape, &landscape) || |
| 172 !settings.GetBoolean(printing::kSettingCollate, &collate) || | 176 !settings.GetBoolean(printing::kSettingCollate, &collate) || |
| (...skipping 30 matching lines...) Expand all Loading... |
| 203 break; | 207 break; |
| 204 } | 208 } |
| 205 gtk_print_settings_set(gtk_settings_, kCUPSDuplex, cups_duplex_mode); | 209 gtk_print_settings_set(gtk_settings_, kCUPSDuplex, cups_duplex_mode); |
| 206 } | 210 } |
| 207 | 211 |
| 208 gtk_print_settings_set_orientation( | 212 gtk_print_settings_set_orientation( |
| 209 gtk_settings_, | 213 gtk_settings_, |
| 210 landscape ? GTK_PAGE_ORIENTATION_LANDSCAPE : | 214 landscape ? GTK_PAGE_ORIENTATION_LANDSCAPE : |
| 211 GTK_PAGE_ORIENTATION_PORTRAIT); | 215 GTK_PAGE_ORIENTATION_PORTRAIT); |
| 212 | 216 |
| 213 InitPrintSettings(ranges); | 217 InitPrintSettings(ranges, header_footer_info); |
| 214 return true; | 218 return true; |
| 215 } | 219 } |
| 216 | 220 |
| 217 void PrintDialogGtk::ShowDialog( | 221 void PrintDialogGtk::ShowDialog( |
| 218 PrintingContextCairo::PrintSettingsCallback* callback) { | 222 PrintingContextCairo::PrintSettingsCallback* callback) { |
| 219 DCHECK(!save_document_event_.get()); | 223 DCHECK(!save_document_event_.get()); |
| 220 | 224 |
| 221 callback_ = callback; | 225 callback_ = callback; |
| 222 | 226 |
| 223 GtkWindow* parent = BrowserList::GetLastActive()->window()->GetNativeHandle(); | 227 GtkWindow* parent = BrowserList::GetLastActive()->window()->GetNativeHandle(); |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 308 for (int i = 0; i < num_ranges; ++i) { | 312 for (int i = 0; i < num_ranges; ++i) { |
| 309 printing::PageRange range; | 313 printing::PageRange range; |
| 310 range.from = gtk_range[i].start; | 314 range.from = gtk_range[i].start; |
| 311 range.to = gtk_range[i].end; | 315 range.to = gtk_range[i].end; |
| 312 ranges_vector.push_back(range); | 316 ranges_vector.push_back(range); |
| 313 } | 317 } |
| 314 g_free(gtk_range); | 318 g_free(gtk_range); |
| 315 } | 319 } |
| 316 | 320 |
| 317 PrintSettings settings; | 321 PrintSettings settings; |
| 322 DictionaryValue header_footer_info; |
| 323 header_footer_info.SetBoolean(printing::kSettingHeaderFooterEnabled, |
| 324 false); |
| 318 printing::PrintSettingsInitializerGtk::InitPrintSettings( | 325 printing::PrintSettingsInitializerGtk::InitPrintSettings( |
| 319 gtk_settings_, page_setup_, ranges_vector, false, &settings); | 326 gtk_settings_, page_setup_, ranges_vector, false, header_footer_info, |
| 327 &settings); |
| 320 context_->InitWithSettings(settings); | 328 context_->InitWithSettings(settings); |
| 321 callback_->Run(PrintingContextCairo::OK); | 329 callback_->Run(PrintingContextCairo::OK); |
| 322 callback_ = NULL; | 330 callback_ = NULL; |
| 323 return; | 331 return; |
| 324 } | 332 } |
| 325 case GTK_RESPONSE_DELETE_EVENT: // Fall through. | 333 case GTK_RESPONSE_DELETE_EVENT: // Fall through. |
| 326 case GTK_RESPONSE_CANCEL: { | 334 case GTK_RESPONSE_CANCEL: { |
| 327 callback_->Run(PrintingContextCairo::CANCEL); | 335 callback_->Run(PrintingContextCairo::CANCEL); |
| 328 callback_ = NULL; | 336 callback_ = NULL; |
| 329 return; | 337 return; |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 401 g_object_unref(print_job); | 409 g_object_unref(print_job); |
| 402 base::FileUtilProxy::Delete( | 410 base::FileUtilProxy::Delete( |
| 403 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::FILE), | 411 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::FILE), |
| 404 path_to_pdf_, | 412 path_to_pdf_, |
| 405 false, | 413 false, |
| 406 NULL); | 414 NULL); |
| 407 // Printing finished. Matches AddRef() in PrintDocument(); | 415 // Printing finished. Matches AddRef() in PrintDocument(); |
| 408 Release(); | 416 Release(); |
| 409 } | 417 } |
| 410 | 418 |
| 411 void PrintDialogGtk::InitPrintSettings(const PageRanges& page_ranges) { | 419 void PrintDialogGtk::InitPrintSettings( |
| 420 const PageRanges& page_ranges, |
| 421 const DictionaryValue& header_footer_info) { |
| 412 PrintSettings settings; | 422 PrintSettings settings; |
| 413 printing::PrintSettingsInitializerGtk::InitPrintSettings( | 423 printing::PrintSettingsInitializerGtk::InitPrintSettings( |
| 414 gtk_settings_, page_setup_, page_ranges, false, &settings); | 424 gtk_settings_, page_setup_, page_ranges, false, header_footer_info, |
| 425 &settings); |
| 415 context_->InitWithSettings(settings); | 426 context_->InitWithSettings(settings); |
| 416 } | 427 } |
| OLD | NEW |