1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 #ifndef CHROME_BROWSER_PRINTING_PRINT_DIALOG_GTK_H_ 6 #define CHROME_BROWSER_PRINTING_PRINT_DIALOG_GTK_H_ 7 8 #include <gtk/gtk.h> 9 #include <gtk/gtkunixprint.h> 10 11 #include "base/compiler_specific.h" 12 #include "base/files/file_path.h" 13 #include "base/memory/ref_counted.h" 14 #include "base/sequenced_task_runner_helpers.h" 15 #include "content/public/browser/browser_thread.h" 16 #include "printing/print_dialog_gtk_interface.h" 17 #include "printing/printing_context_gtk.h" 18 #include "ui/base/gtk/gtk_signal.h" 19 20 namespace printing { 21 class Metafile; 22 class PrintSettings; 23 } 24 25 using printing::PrintingContextGtk; 26 27 // Needs to be freed on the UI thread to clean up its GTK members variables. 28 class PrintDialogGtk 29 : public printing::PrintDialogGtkInterface, 30 public base::RefCountedThreadSafe< 31 PrintDialogGtk, content::BrowserThread::DeleteOnUIThread> { 32 public: 33 // Creates and returns a print dialog. 34 static printing::PrintDialogGtkInterface* CreatePrintDialog( 35 PrintingContextGtk* context); 36 37 // printing::PrintDialogGtkInterface implementation. 38 virtual void UseDefaultSettings() OVERRIDE; 39 virtual bool UpdateSettings(printing::PrintSettings* settings) OVERRIDE; 40 virtual void ShowDialog( 41 gfx::NativeView parent_view, 42 bool has_selection, 43 const PrintingContextGtk::PrintSettingsCallback& callback) OVERRIDE; 44 virtual void PrintDocument(const printing::Metafile* metafile, 45 const base::string16& document_name) OVERRIDE; 46 virtual void AddRefToDialog() OVERRIDE; 47 virtual void ReleaseDialog() OVERRIDE; 48 49 private: 50 friend struct content::BrowserThread::DeleteOnThread< 51 content::BrowserThread::UI>; 52 friend class base::DeleteHelper<PrintDialogGtk>; 53 54 explicit PrintDialogGtk(PrintingContextGtk* context); 55 virtual ~PrintDialogGtk(); 56 57 // Handles dialog response. 58 CHROMEGTK_CALLBACK_1(PrintDialogGtk, void, OnResponse, int); 59 60 // Prints document named |document_name|. 61 void SendDocumentToPrinter(const base::string16& document_name); 62 63 // Handles print job response. 64 static void OnJobCompletedThunk(GtkPrintJob* print_job, 65 gpointer user_data, 66 GError* error); 67 void OnJobCompleted(GtkPrintJob* print_job, GError* error); 68 69 // Helper function for initializing |context_|'s PrintSettings with a given 70 // |settings|. 71 void InitPrintSettings(printing::PrintSettings* settings); 72 73 // Printing dialog callback. 74 PrintingContextGtk::PrintSettingsCallback callback_; 75 PrintingContextGtk* context_; 76 77 // Print dialog settings. PrintDialogGtk owns |dialog_| and holds references 78 // to the other objects. 79 GtkWidget* dialog_; 80 GtkPrintSettings* gtk_settings_; 81 GtkPageSetup* page_setup_; 82 GtkPrinter* printer_; 83 84 base::FilePath path_to_pdf_; 85 86 DISALLOW_COPY_AND_ASSIGN(PrintDialogGtk); 87 }; 88 89 #endif // CHROME_BROWSER_PRINTING_PRINT_DIALOG_GTK_H_ 90