Home | History | Annotate | Download | only in printing
      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(const base::DictionaryValue& job_settings,
     40                               const printing::PageRanges& ranges,
     41                               printing::PrintSettings* settings) OVERRIDE;
     42   virtual void ShowDialog(
     43       gfx::NativeView parent_view,
     44       bool has_selection,
     45       const PrintingContextGtk::PrintSettingsCallback& callback) OVERRIDE;
     46   virtual void PrintDocument(const printing::Metafile* metafile,
     47                              const string16& document_name) OVERRIDE;
     48   virtual void AddRefToDialog() OVERRIDE;
     49   virtual void ReleaseDialog() OVERRIDE;
     50 
     51  private:
     52   friend struct content::BrowserThread::DeleteOnThread<
     53       content::BrowserThread::UI>;
     54   friend class base::DeleteHelper<PrintDialogGtk>;
     55 
     56   explicit PrintDialogGtk(PrintingContextGtk* context);
     57   virtual ~PrintDialogGtk();
     58 
     59   // Handles dialog response.
     60   CHROMEGTK_CALLBACK_1(PrintDialogGtk, void, OnResponse, int);
     61 
     62   // Prints document named |document_name|.
     63   void SendDocumentToPrinter(const string16& document_name);
     64 
     65   // Handles print job response.
     66   static void OnJobCompletedThunk(GtkPrintJob* print_job,
     67                                   gpointer user_data,
     68                                   GError* error);
     69   void OnJobCompleted(GtkPrintJob* print_job, GError* error);
     70 
     71   // Helper function for initializing |context_|'s PrintSettings with a given
     72   // set of |page_ranges| and |settings|.
     73   void InitPrintSettings(const printing::PageRanges& page_ranges,
     74                          printing::PrintSettings* settings);
     75 
     76   // Printing dialog callback.
     77   PrintingContextGtk::PrintSettingsCallback callback_;
     78   PrintingContextGtk* context_;
     79 
     80   // Print dialog settings. PrintDialogGtk owns |dialog_| and holds references
     81   // to the other objects.
     82   GtkWidget* dialog_;
     83   GtkPrintSettings* gtk_settings_;
     84   GtkPageSetup* page_setup_;
     85   GtkPrinter* printer_;
     86 
     87   base::FilePath path_to_pdf_;
     88 
     89   DISALLOW_COPY_AND_ASSIGN(PrintDialogGtk);
     90 };
     91 
     92 #endif  // CHROME_BROWSER_PRINTING_PRINT_DIALOG_GTK_H_
     93