r21758 - gnucash/trunk/src - Add customer-specific memory of PDF-Export output directory. Makes exporting to PDF rather easy.

Christian Stimming cstim at code.gnucash.org
Mon Dec 19 17:25:56 EST 2011


Author: cstim
Date: 2011-12-19 17:25:56 -0500 (Mon, 19 Dec 2011)
New Revision: 21758
Trac: http://svn.gnucash.org/trac/changeset/21758

Modified:
   gnucash/trunk/src/gnome-utils/print-session.c
   gnucash/trunk/src/gnome-utils/print-session.h
   gnucash/trunk/src/report/report-gnome/gnc-plugin-page-report.c
Log:
Add customer-specific memory of PDF-Export output directory. Makes exporting to PDF rather easy.

Modified: gnucash/trunk/src/gnome-utils/print-session.c
===================================================================
--- gnucash/trunk/src/gnome-utils/print-session.c	2011-12-19 22:25:45 UTC (rev 21757)
+++ gnucash/trunk/src/gnome-utils/print-session.c	2011-12-19 22:25:56 UTC (rev 21758)
@@ -113,3 +113,8 @@
     if (old_page_setup)
         g_object_unref(old_page_setup);
 }
+
+GtkPrintSettings *gnc_print_get_settings()
+{
+    return print_settings;
+}

Modified: gnucash/trunk/src/gnome-utils/print-session.h
===================================================================
--- gnucash/trunk/src/gnome-utils/print-session.h	2011-12-19 22:25:45 UTC (rev 21757)
+++ gnucash/trunk/src/gnome-utils/print-session.h	2011-12-19 22:25:56 UTC (rev 21758)
@@ -62,6 +62,10 @@
  */
 void gnc_ui_page_setup(GtkWindow *parent);
 
+/** Returns the pointer to our static GtkPrintSettings object. Watch out: This
+ * might get modified by other threads. */
+GtkPrintSettings *gnc_print_get_settings(void);
+
 /** Key for saving the PDF-export directory in the print settings */
 #define GNC_GTK_PRINT_SETTINGS_EXPORT_DIR "gnc-pdf-export-directory"
 

Modified: gnucash/trunk/src/report/report-gnome/gnc-plugin-page-report.c
===================================================================
--- gnucash/trunk/src/report/report-gnome/gnc-plugin-page-report.c	2011-12-19 22:25:45 UTC (rev 21757)
+++ gnucash/trunk/src/report/report-gnome/gnc-plugin-page-report.c	2011-12-19 22:25:56 UTC (rev 21758)
@@ -69,6 +69,7 @@
 #include "swig-runtime.h"
 #include "app-utils/business-options.h"
 #include "gnome-utils/gnc-icons.h"
+#include "gnome-utils/print-session.h"
 
 #define WINDOW_REPORT_CM_CLASS "window-report"
 
@@ -1604,6 +1605,13 @@
     }
 }
 
+static GncInvoice *lookup_invoice(GncPluginPageReportPrivate *priv)
+{
+    g_assert(priv);
+    return gnc_option_db_lookup_invoice_option(priv->cur_odb, "General",
+                                               "Invoice Number", NULL);
+}
+
 static gchar *report_create_jobname(GncPluginPageReportPrivate *priv)
 {
     gchar *job_name = NULL;
@@ -1644,8 +1652,7 @@
             report_name = g_strdup(_("Invoice"));
         }
 
-        invoice = gnc_option_db_lookup_invoice_option(priv->cur_odb, "General",
-                  "Invoice Number", NULL);
+        invoice = lookup_invoice(priv);
         if (invoice)
         {
             const gchar *invoice_number = gncInvoiceGetID(invoice);
@@ -1725,16 +1732,68 @@
     g_free (job_name);
 }
 
+#define KVP_OWNER_EXPORT_PDF_DIRNAME "export-pdf-directory"
+
 static void
 gnc_plugin_page_report_exportpdf_cb( GtkAction *action, GncPluginPageReport *report )
 {
     GncPluginPageReportPrivate *priv = GNC_PLUGIN_PAGE_REPORT_GET_PRIVATE(report);
     gchar *job_name = report_create_jobname(priv);
+    GncInvoice *invoice;
+    GncOwner *owner;
+    KvpFrame *kvp;
 
-    g_warning("Setting job name=%s", job_name);
+    // Do we have an invoice report?
+    invoice = lookup_invoice(priv);
+    if (invoice)
+    {
+        // Does this invoice also have an owner?
+        owner = (GncOwner*) gncInvoiceGetOwner(invoice);
+        if (owner)
+        {
+            // Yes. In the kvp, look up the key for the Export-PDF output
+            // directory. If it exists, prepend this to the job name so that
+            // we can export to PDF.
+            kvp = gncOwnerGetSlots(owner);
+            if (kvp)
+            {
+                const char *dirname = kvp_frame_get_string(kvp, KVP_OWNER_EXPORT_PDF_DIRNAME);
+                if (dirname && g_file_test(dirname, G_FILE_TEST_EXISTS | G_FILE_TEST_IS_DIR))
+                {
+                    gchar *tmp = g_build_filename(dirname, job_name, NULL);
+                    g_free(job_name);
+                    job_name = tmp;
+                }
+            }
+        }
+    }
 
+    //g_warning("Setting job name=%s", job_name);
+
     gnc_html_print(priv->html, job_name, TRUE);
 
+    if (owner && kvp)
+    {
+        // As this is an invoice report with some owner, we will try to look up the
+        // chosen output directory from the print settings and store it again in the owner kvp.
+        GtkPrintSettings *print_settings = gnc_print_get_settings();
+        if (print_settings && gtk_print_settings_has_key(print_settings, GNC_GTK_PRINT_SETTINGS_EXPORT_DIR))
+        {
+            const char* dirname = gtk_print_settings_get(print_settings,
+                                                             GNC_GTK_PRINT_SETTINGS_EXPORT_DIR);
+            // Only store the directory if it exists.
+            if (g_file_test(dirname, G_FILE_TEST_EXISTS | G_FILE_TEST_IS_DIR))
+            {
+                QofInstance *qofinstance = qofOwnerGetOwner(owner);
+                //gncOwnerBeginEdit(owner);
+                kvp_frame_set_string(kvp, KVP_OWNER_EXPORT_PDF_DIRNAME, dirname);
+                if (qofinstance)
+                    qof_instance_set_dirty(qofinstance);
+                // shoot... there is no such thing as: gncOwnerCommitEdit(owner);
+            }
+        }
+    }
+
     g_free (job_name);
 }
 



More information about the gnucash-changes mailing list