r15719 - gnucash/trunk/src/gnome - Add support for printing the check number, the action, and the real
David Hampton
hampton at cvs.gnucash.org
Wed Mar 14 22:24:08 EDT 2007
Author: hampton
Date: 2007-03-14 22:24:07 -0400 (Wed, 14 Mar 2007)
New Revision: 15719
Trac: http://svn.gnucash.org/trac/changeset/15719
Modified:
gnucash/trunk/src/gnome/dialog-print-check.c
gnucash/trunk/src/gnome/dialog-print-check.h
gnucash/trunk/src/gnome/gnc-plugin-page-register.c
Log:
Add support for printing the check number, the action, and the real
memo line.
Modified: gnucash/trunk/src/gnome/dialog-print-check.c
===================================================================
--- gnucash/trunk/src/gnome/dialog-print-check.c 2007-03-15 00:56:52 UTC (rev 15718)
+++ gnucash/trunk/src/gnome/dialog-print-check.c 2007-03-15 02:24:07 UTC (rev 15719)
@@ -45,6 +45,8 @@
#include "gnc-path.h"
#include "gnc-filepath-utils.h"
#include "gnc-gkeyfile-utils.h"
+#include "Split.h"
+#include "Transaction.h"
#define USE_GTKPRINT HAVE_GTK_2_10
@@ -113,8 +115,13 @@
_(PAYEE,) \
_(DATE,) \
_(NOTES,) \
+ _(CHECK_NUMBER,) \
+ \
+ _(MEMO,) \
+ _(ACTION,) \
_(AMOUNT_NUMBER,) \
_(AMOUNT_WORDS,) \
+ \
_(TEXT,) \
_(PICTURE,)
@@ -193,10 +200,7 @@
GtkWindow * caller_window;
GncPluginPageRegister *plugin_page;
- const char *payee;
- gnc_numeric amount;
- time_t date;
- const char *notes;
+ Split *split;
GtkWidget * format_combobox;
gint format_max;
@@ -837,10 +841,7 @@
void
gnc_ui_print_check_dialog_create(GncPluginPageRegister *plugin_page,
- const char *payee,
- gnc_numeric amount,
- time_t date,
- const char *notes)
+ Split *split)
{
PrintCheckDialog * pcd;
GladeXML *xml;
@@ -851,10 +852,7 @@
pcd = g_new0(PrintCheckDialog, 1);
pcd->plugin_page = plugin_page;
- pcd->payee = payee;
- pcd->amount = amount;
- pcd->date = date;
- pcd->notes = notes;
+ pcd->split = split;
xml = gnc_glade_xml_new ("print.glade", "Print Check Dialog");
glade_xml_signal_autoconnect_full(xml, gnc_glade_autoconnect_full_func, pcd);
@@ -1071,10 +1069,42 @@
}
+#if USE_GTKPRINT
+/** Find and load the specified image. If the specified filename isn't an
+ * absolute path name, this code will also look in the gnucash system check
+ * format directory, and then in the user's private check format
+ * directory.
+ *
+ * NOTE: The gtk_image_new_from_file() function never fails. If it can't
+ * find the specified file, it returs the "broken image" icon. This function
+ * takes advantage of that.
+*/
+static GtkWidget *
+read_image (const gchar *filename)
+{
+ GtkWidget *image;
+ gchar *pkgdatadir, *dirname, *tmp_name;
+
+ if (filename[0] == '/')
+ return gtk_image_new_from_file(filename);
+
+ pkgdatadir = gnc_path_get_pkgdatadir();
+ tmp_name = g_build_filename(pkgdatadir, CHECK_FMT_DIR, filename, (char *)NULL);
+ if (!g_file_exists(tmp_name)) {
+ g_free(tmp_name);
+ dirname = gnc_build_dotgnucash_path(CHECK_FMT_DIR);
+ tmp_name = g_build_filename(dirname, filename, (char *)NULL);
+ g_free(dirname);
+ }
+ image = gtk_image_new_from_file(tmp_name);
+ g_free(tmp_name);
+ return image;
+}
+
+
/** Print a single image to the printed page. This picture will be scaled
* down to fit in the specified size rectangle. Scaling is done with the
* proportions locked 1:1 so as not to distort the image. */
-#if USE_GTKPRINT
static void
draw_picture(GtkPrintContext * context, check_item_t * data)
{
@@ -1088,8 +1118,17 @@
cairo_save(cr);
/* Get the picture. */
- image = GTK_IMAGE(gtk_image_new_from_file(data->filename));
+ image = GTK_IMAGE(read_image(data->filename));
pixbuf = gtk_image_get_pixbuf(image);
+ if (pixbuf) {
+ g_object_ref(pixbuf);
+ } else {
+ g_warning("Filename '%s' cannot be read or understood.",
+ data->filename);
+ pixbuf = gtk_widget_render_icon(GTK_WIDGET(image),
+ GTK_STOCK_MISSING_IMAGE,
+ -1, NULL);
+ }
pix_w = gdk_pixbuf_get_width(pixbuf);
pix_h = gdk_pixbuf_get_height(pixbuf);
@@ -1124,6 +1163,7 @@
} else {
gdk_cairo_set_source_pixbuf(cr, pixbuf, data->x, data->y - pix_h);
}
+ g_object_unref(pixbuf);
cairo_paint(cr);
/* Clean up after ourselves */
@@ -1226,15 +1266,22 @@
gint page_nr, check_format_t * format, gpointer user_data)
{
PrintCheckDialog *pcd = (PrintCheckDialog *) user_data;
- PangoFontDescription *default_desc, *date_desc;
+ PangoFontDescription *default_desc;
+ Transaction *trans;
+ gnc_numeric amount;
GNCPrintAmountInfo info;
const gchar *date_format;
gchar *text = NULL, buf[100];
GSList *elem;
- check_item_t *item, date_item;
+ check_item_t *item;
gdouble width;
GDate *date;
+ trans = xaccSplitGetParent(pcd->split);
+ /* This was valid when the check printing dialog was instantiated. */
+ g_return_if_fail(trans);
+ amount = gnc_numeric_abs(xaccSplitGetAmount(pcd->split));
+
default_desc = pango_font_description_from_string(format->font);
/* Now put the actual data onto the page. */
@@ -1244,7 +1291,7 @@
switch (item->type) {
case DATE:
date = g_date_new();
- g_date_set_time_t(date, pcd->date);
+ g_date_set_time_t(date, xaccTransGetDate(trans));
date_format =
gnc_date_format_get_custom(GNC_DATE_FORMAT
(pcd->date_format));
@@ -1255,21 +1302,33 @@
break;
case PAYEE:
- draw_text(context, pcd->payee, item, default_desc);
+ draw_text(context, xaccTransGetDescription(trans), item, default_desc);
break;
case NOTES:
- draw_text(context, pcd->notes, item, default_desc);
+ draw_text(context, xaccTransGetNotes(trans), item, default_desc);
break;
+ case MEMO:
+ draw_text(context, xaccSplitGetMemo(pcd->split), item, default_desc);
+ break;
+
+ case ACTION:
+ draw_text(context, xaccSplitGetAction(pcd->split), item, default_desc);
+ break;
+
+ case CHECK_NUMBER:
+ draw_text(context, xaccTransGetNum(trans), item, default_desc);
+ break;
+
case AMOUNT_NUMBER:
info = gnc_default_print_info(FALSE);
- draw_text(context, xaccPrintAmount(pcd->amount, info),
+ draw_text(context, xaccPrintAmount(amount, info),
item, default_desc);
break;
case AMOUNT_WORDS:
- text = numeric_to_words(pcd->amount);
+ text = numeric_to_words(amount);
draw_text(context, text, item, default_desc);
g_free(text);
break;
@@ -1434,6 +1493,8 @@
PrintCheckDialog *pcd = (PrintCheckDialog *) user_data;
GNCPrintAmountInfo info;
PangoFontDescription *desc;
+ Transaction *trans;
+ gnc_numeric amount;
#if USE_GTKPRINT
cairo_t *cr;
#endif
@@ -1443,6 +1504,10 @@
gdouble x, y, multip, degrees;
GDate *date;
+ trans = xaccSplitGetParent(pcd->split);
+ /* This was valid when the check printing dialog was instantiated. */
+ g_return_if_fail(trans);
+
desc = pango_font_description_from_string("sans 12");
multip = pcd_get_custom_multip(pcd);
@@ -1466,12 +1531,12 @@
item.x = multip * gtk_spin_button_get_value(pcd->payee_x);
item.y = multip * gtk_spin_button_get_value(pcd->payee_y);
- draw_text(context, pcd->payee, &item, desc);
+ draw_text(context, xaccTransGetDescription(trans), &item, desc);
item.x = multip * gtk_spin_button_get_value(pcd->date_x);
item.y = multip * gtk_spin_button_get_value(pcd->date_y);
date = g_date_new();
- g_date_set_time_t(date, pcd->date);
+ g_date_set_time_t(date, xaccTransGetDate(trans));
date_format = gnc_date_format_get_custom(GNC_DATE_FORMAT(pcd->date_format));
g_date_strftime(buf, 100, date_format, date);
draw_text(context, buf, &item, desc);
@@ -1480,17 +1545,18 @@
item.x = multip * gtk_spin_button_get_value(pcd->words_x);
item.y = multip * gtk_spin_button_get_value(pcd->words_y);
info = gnc_default_print_info(FALSE);
- draw_text(context, xaccPrintAmount(pcd->amount, info), &item, desc);
+ amount = gnc_numeric_abs(xaccSplitGetAmount(pcd->split));
+ draw_text(context, xaccPrintAmount(amount, info), &item, desc);
item.x = multip * gtk_spin_button_get_value(pcd->number_x);
item.y = multip * gtk_spin_button_get_value(pcd->number_y);
- text = numeric_to_words(pcd->amount);
+ text = numeric_to_words(amount);
draw_text(context, text, &item, desc);
g_free(text);
item.x = multip * gtk_spin_button_get_value(pcd->notes_x);
item.y = multip * gtk_spin_button_get_value(pcd->notes_y);
- draw_text(context, pcd->notes, &item, desc);
+ draw_text(context, xaccTransGetNotes(trans), &item, desc);
pango_font_description_free(desc);
}
Modified: gnucash/trunk/src/gnome/dialog-print-check.h
===================================================================
--- gnucash/trunk/src/gnome/dialog-print-check.h 2007-03-15 00:56:52 UTC (rev 15718)
+++ gnucash/trunk/src/gnome/dialog-print-check.h 2007-03-15 02:24:07 UTC (rev 15719)
@@ -31,10 +31,7 @@
typedef struct _print_check_dialog PrintCheckDialog;
void gnc_ui_print_check_dialog_create(GncPluginPageRegister *plugin_page,
- const char *payee,
- gnc_numeric amount,
- time_t date,
- const char *memo);
+ Split *split);
void gnc_ui_print_check_dialog_destroy(PrintCheckDialog * pcd);
#endif
Modified: gnucash/trunk/src/gnome/gnc-plugin-page-register.c
===================================================================
--- gnucash/trunk/src/gnome/gnc-plugin-page-register.c 2007-03-15 00:56:52 UTC (rev 15718)
+++ gnucash/trunk/src/gnome/gnc-plugin-page-register.c 2007-03-15 02:24:07 UTC (rev 15719)
@@ -1805,10 +1805,6 @@
SplitRegister * reg;
Split * split;
Transaction * trans;
- const char * payee;
- const char * memo;
- gnc_numeric amount;
- time_t date;
ENTER("(action %p, plugin_page %p)", action, plugin_page);
@@ -1822,15 +1818,7 @@
if(split && trans)
{
- payee = xaccTransGetDescription(trans);
- memo = xaccTransGetNotes(trans);
- if (memo == NULL)
- memo = "";
- amount = xaccSplitGetAmount(split);
- amount = gnc_numeric_abs (amount);
- date = xaccTransGetDate(trans);
-
- gnc_ui_print_check_dialog_create(plugin_page, payee, amount, date, memo);
+ gnc_ui_print_check_dialog_create(plugin_page, split);
}
LEAVE(" ");
}
More information about the gnucash-changes
mailing list