r21804 - gnucash/trunk/src - Export-to-PDF: Make output file name configurable, at least through gconf keys.
Christian Stimming
cstim at code.gnucash.org
Fri Dec 30 17:06:13 EST 2011
Author: cstim
Date: 2011-12-30 17:06:12 -0500 (Fri, 30 Dec 2011)
New Revision: 21804
Trac: http://svn.gnucash.org/trac/changeset/21804
Modified:
gnucash/trunk/src/gnome/schemas/apps_gnucash_general.schemas.in
gnucash/trunk/src/report/report-gnome/gnc-plugin-page-report.c
Log:
Export-to-PDF: Make output file name configurable, at least through gconf keys.
One gconf setting for the output date format, and another one for the actual
output file name string.
Modified: gnucash/trunk/src/gnome/schemas/apps_gnucash_general.schemas.in
===================================================================
--- gnucash/trunk/src/gnome/schemas/apps_gnucash_general.schemas.in 2011-12-30 21:40:11 UTC (rev 21803)
+++ gnucash/trunk/src/gnome/schemas/apps_gnucash_general.schemas.in 2011-12-30 22:06:12 UTC (rev 21804)
@@ -576,6 +576,46 @@
</schema>
<schema>
+ <key>/schemas/apps/gnucash/general/report/pdf_export/filename_format</key>
+ <applyto>/apps/gnucash/general/report/pdf_export/filename_format</applyto>
+ <owner>gnucash</owner>
+ <type>string</type>
+ <default>%1$s_%2$s_%3$s</default>
+ <locale name="C">
+ <short>PDF export file name format</short>
+ <long>
+ This setting chooses the file name for PDF export. This is a
+ sprintf(3) string with three arguments: "%1$s" is the report
+ name such as "Invoice". "%2$s" is the number of the report,
+ which for an invoice report is the invoice number. "%3$s" is
+ the date of the report, formatted according to the
+ filename_date_format setting. (Note: Any characters that are
+ not allowed in filenames, such as '/', will be replaced with
+ underscores '_' in the resulting file name.)
+ </long>
+ </locale>
+ </schema>
+
+ <schema>
+ <key>/schemas/apps/gnucash/general/report/pdf_export/filename_date_format</key>
+ <applyto>/apps/gnucash/general/report/pdf_export/filename_date_format</applyto>
+ <owner>gnucash</owner>
+ <type>string</type>
+ <default>locale</default>
+ <locale name="C">
+ <short>PDF export file name date format choice</short>
+ <long>
+ This setting chooses the way dates are used in the filename
+ of PDF export.
+ Possible values for this setting are "locale" to use the
+ system locale setting, "ce" for Continental Europe style
+ dates, "iso" for ISO 8601 standard dates , "uk" for United
+ Kingdom style dates, and "us" for United States style dates.
+ </long>
+ </locale>
+ </schema>
+
+ <schema>
<key>/schemas/apps/gnucash/general/tab_position</key>
<applyto>/apps/gnucash/general/tab_position</applyto>
<owner>gnucash</owner>
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-30 21:40:11 UTC (rev 21803)
+++ gnucash/trunk/src/report/report-gnome/gnc-plugin-page-report.c 2011-12-30 22:06:12 UTC (rev 21804)
@@ -1612,15 +1612,58 @@
"Invoice Number", NULL);
}
+#define GCONF_GENERAL_REPORT_PDFEXPORT GCONF_GENERAL_REPORT "/pdf_export"
+
static gchar *report_create_jobname(GncPluginPageReportPrivate *priv)
{
gchar *job_name = NULL;
gchar *report_name = NULL;
- gchar *job_date = qof_print_date( time( NULL ) );
+ const gchar *report_number = "";
+ gchar *job_date;
const gchar *default_jobname = N_("GnuCash-Report");
g_assert(priv);
+ {
+ // Look up the date format that was chosen in the gconf registry
+ QofDateFormat date_format_here;
+ QofDateFormat date_format_old = qof_date_format_get();
+ char *format_code = gnc_gconf_get_string(GCONF_GENERAL_REPORT_PDFEXPORT,
+ "filename_date_format", NULL);
+
+ if (format_code == NULL)
+ {
+ format_code = g_strdup("locale");
+ g_warning("No gconf key found for " GCONF_GENERAL_REPORT_PDFEXPORT
+ "/filename_date_format, using default %s", format_code);
+ }
+ if (*format_code == '\0')
+ {
+ g_free(format_code);
+ format_code = g_strdup("locale");
+ }
+
+ if (gnc_date_string_to_dateformat(format_code, &date_format_here))
+ {
+ PERR("Incorrect date format code");
+ if (format_code != NULL)
+ free(format_code);
+ }
+
+ // To apply this chosen date format, temporarily switch the
+ // process-wide default to our chosen date format. Note: It is a
+ // totally brain-dead implementation of qof_print_date() to not offer a
+ // variation where the QofDateFormat can be passed as an argument.
+ // Hrmpf.
+ qof_date_format_set(date_format_here);
+
+ job_date = qof_print_date( time( NULL ) );
+
+ // Restore to the original general date format
+ qof_date_format_set(date_format_old);
+ }
+
+
if (priv->cur_report == SCM_BOOL_F)
report_name = g_strdup (_(default_jobname));
else
@@ -1655,21 +1698,27 @@
invoice = lookup_invoice(priv);
if (invoice)
{
- const gchar *invoice_number = gncInvoiceGetID(invoice);
- if (invoice_number)
- {
- /* Report is for an invoice. Add the invoice number to
- * the job name. */
- gchar *name_number = g_strjoin ( "_", report_name, invoice_number, NULL );
- g_free (report_name);
- report_name = name_number;
- }
+ // Report is for an invoice. Hence, we get a number of the invoice.
+ report_number = gncInvoiceGetID(invoice);
}
}
- job_name = g_strjoin ( "_", report_name, job_date, NULL );
+ if (report_name && job_date)
+ {
+ // Look up the sprintf format of the output name from the gconf registry
+ char* format = gnc_gconf_get_string(GCONF_GENERAL_REPORT_PDFEXPORT, "filename_format", NULL);
+ if (!format)
+ {
+ // Fallback name format in case the gconf does not contain this key
+ format = g_strdup("%s_%s_%s");
+ g_warning("No gconf key found for " GCONF_GENERAL_REPORT_PDFEXPORT "/filename_format, using default %s", format);
+ }
+
+ job_name = g_strdup_printf(format, report_name, report_number, job_date);
+
+ g_free(format);
+ }
g_free (report_name);
- report_name = NULL;
g_free (job_date);
{
More information about the gnucash-changes
mailing list