[recipes] Add gr_printer_recipe_get_pdf api to export recipe pdf



commit c83c5f593ad83e123b7523e341bb349460c769af
Author: Ekta Nandwani <mailnandwaniekta gmail com>
Date:   Wed Apr 26 13:09:26 2017 +0530

    Add gr_printer_recipe_get_pdf api to export recipe pdf
    
    Exports pdf to /.local/share/gnome-recipes/ using GTK_PRINT_OPERATION_ACTION_EXPORT

 src/gr-recipe-printer.c |   26 ++++++++++++++++++++++++++
 src/gr-recipe-printer.h |    2 ++
 2 files changed, 28 insertions(+), 0 deletions(-)
---
diff --git a/src/gr-recipe-printer.c b/src/gr-recipe-printer.c
index bc9a834..f5db7b6 100644
--- a/src/gr-recipe-printer.c
+++ b/src/gr-recipe-printer.c
@@ -424,6 +424,32 @@ print_done (GtkPrintOperation       *operation,
         g_object_unref (operation);
 }
 
+GFile *
+gr_recipe_printer_get_pdf (GrRecipePrinter *printer,
+                            GrRecipe        *recipe)
+{
+        GtkPrintOperation *operation = NULL;
+        g_autofree char *path = NULL;
+        g_autofree char *name = NULL;
+
+        name = g_strdup (gr_recipe_get_name (GR_RECIPE (recipe)));
+        g_strdelimit (name, "./", ' ');
+        path = g_strdup_printf ("%s/%s.pdf", get_user_data_dir (), name);
+
+        g_set_object (&printer->recipe, recipe);
+        operation = gtk_print_operation_new ();
+
+        g_signal_connect (operation, "begin-print", G_CALLBACK (begin_print), printer);
+        g_signal_connect (operation, "end-print", G_CALLBACK (end_print), printer);
+        g_signal_connect (operation, "draw-page", G_CALLBACK (draw_page), printer);
+        g_signal_connect (operation, "done", G_CALLBACK (print_done), printer);
+        gtk_print_operation_set_allow_async (operation, TRUE);
+        gtk_print_operation_set_export_filename (operation, path);
+
+        gtk_print_operation_run (operation, GTK_PRINT_OPERATION_ACTION_EXPORT, NULL, NULL);
+        return g_file_new_for_path (path);
+}
+
 void
 gr_recipe_printer_print (GrRecipePrinter *printer,
                          GrRecipe        *recipe)
diff --git a/src/gr-recipe-printer.h b/src/gr-recipe-printer.h
index 7462e4a..0e9cf9b 100644
--- a/src/gr-recipe-printer.h
+++ b/src/gr-recipe-printer.h
@@ -33,5 +33,7 @@ GrRecipePrinter *gr_recipe_printer_new   (GtkWindow       *window);
 
 void             gr_recipe_printer_print (GrRecipePrinter *printer,
                                           GrRecipe        *recipe);
+GFile           *gr_recipe_printer_get_pdf (GrRecipePrinter *printer,
+                                            GrRecipe        *recipe);
 
 G_END_DECLS


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]