r15724 - gnucash/trunk/src - In the Print Checks dialog, provide an easy way for users to save the
David Hampton
hampton at cvs.gnucash.org
Thu Mar 15 01:20:59 EDT 2007
Author: hampton
Date: 2007-03-15 01:20:58 -0400 (Thu, 15 Mar 2007)
New Revision: 15724
Trac: http://svn.gnucash.org/trac/changeset/15724
Modified:
gnucash/trunk/src/core-utils/gnc-gkeyfile-utils.c
gnucash/trunk/src/core-utils/gnc-gkeyfile-utils.h
gnucash/trunk/src/engine/gnc-filepath-utils.c
gnucash/trunk/src/gnome/dialog-print-check.c
gnucash/trunk/src/gnome/glade/print.glade
Log:
In the Print Checks dialog, provide an easy way for users to save the
data from the "Custom Format" page to a check format file.
Modified: gnucash/trunk/src/core-utils/gnc-gkeyfile-utils.c
===================================================================
--- gnucash/trunk/src/core-utils/gnc-gkeyfile-utils.c 2007-03-15 03:00:55 UTC (rev 15723)
+++ gnucash/trunk/src/core-utils/gnc-gkeyfile-utils.c 2007-03-15 05:20:58 UTC (rev 15724)
@@ -163,6 +163,20 @@
return double_value;
}
+void
+g_key_file_set_double (GKeyFile *key_file,
+ const gchar *group_name,
+ const gchar *key,
+ gdouble value)
+{
+ gchar result[G_ASCII_DTOSTR_BUF_SIZE];
+
+ g_return_if_fail (key_file != NULL);
+
+ g_ascii_dtostr (result, sizeof (result), value);
+ g_key_file_set_value (key_file, group_name, key, result);
+}
+
gdouble*
g_key_file_get_double_list (GKeyFile *key_file,
const gchar *group_name,
@@ -212,6 +226,34 @@
return double_values;
}
+
+void
+g_key_file_set_double_list (GKeyFile *key_file,
+ const gchar *group_name,
+ const gchar *key,
+ gdouble list[],
+ gsize length)
+{
+ GString *values;
+ gsize i;
+
+ g_return_if_fail (key_file != NULL);
+ g_return_if_fail (list != NULL);
+
+ values = g_string_sized_new (length * 16);
+ for (i = 0; i < length; i++)
+ {
+ gchar result[G_ASCII_DTOSTR_BUF_SIZE];
+
+ g_ascii_dtostr( result, sizeof (result), list[i] );
+
+ g_string_append (values, result);
+ g_string_append_c (values, ';');
+ }
+
+ g_key_file_set_value (key_file, group_name, key, values->str);
+ g_string_free (values, TRUE);
+}
/**********************************************************************
*
* End of copied functions.
Modified: gnucash/trunk/src/core-utils/gnc-gkeyfile-utils.h
===================================================================
--- gnucash/trunk/src/core-utils/gnc-gkeyfile-utils.h 2007-03-15 03:00:55 UTC (rev 15723)
+++ gnucash/trunk/src/core-utils/gnc-gkeyfile-utils.h 2007-03-15 05:20:58 UTC (rev 15724)
@@ -43,9 +43,15 @@
g_key_file_get_double (GKeyFile *key_file, const gchar *group_name,
const gchar *key, GError **error);
+void
+g_key_file_set_double (GKeyFile *key_file, const gchar *group_name,
+ const gchar *key, gdouble value);
gdouble*
g_key_file_get_double_list (GKeyFile *key_file, const gchar *group_name,
const gchar *key, gsize *length, GError **error);
+void
+g_key_file_set_double_list (GKeyFile *key_file, const gchar *group_name,
+ const gchar *key, gdouble list[], gsize length);
#endif
Modified: gnucash/trunk/src/engine/gnc-filepath-utils.c
===================================================================
--- gnucash/trunk/src/engine/gnc-filepath-utils.c 2007-03-15 03:00:55 UTC (rev 15723)
+++ gnucash/trunk/src/engine/gnc-filepath-utils.c 2007-03-15 05:20:58 UTC (rev 15724)
@@ -376,7 +376,7 @@
const gchar *
gnc_dotgnucash_dir (void)
{
- static gchar *dotgnucash = NULL, *books_dir;
+ static gchar *dotgnucash = NULL, *tmp_dir;
const gchar *home;
if (dotgnucash)
@@ -393,9 +393,12 @@
gnc_validate_directory(dotgnucash);
/* Since we're in code that is only executed once.... */
- books_dir = g_build_filename(dotgnucash, "books", (gchar *)NULL);
- gnc_validate_directory(books_dir);
- g_free(books_dir);
+ tmp_dir = g_build_filename(dotgnucash, "books", (gchar *)NULL);
+ gnc_validate_directory(tmp_dir);
+ g_free(tmp_dir);
+ tmp_dir = g_build_filename(dotgnucash, "checks", (gchar *)NULL);
+ gnc_validate_directory(tmp_dir);
+ g_free(tmp_dir);
return dotgnucash;
}
Modified: gnucash/trunk/src/gnome/dialog-print-check.c
===================================================================
--- gnucash/trunk/src/gnome/dialog-print-check.c 2007-03-15 03:00:55 UTC (rev 15723)
+++ gnucash/trunk/src/gnome/dialog-print-check.c 2007-03-15 05:20:58 UTC (rev 15724)
@@ -28,6 +28,7 @@
#include <stdio.h>
#include <libguile.h>
#include <locale.h>
+#include <math.h>
#include "glib-compat.h"
@@ -68,9 +69,11 @@
#define KEY_SHOW_DATE_FMT "show_date_format"
-#define DEFAULT_FONT "sans 12"
-#define CHECK_FMT_DIR "checks"
-#define DEGREES_TO_RADIANS (G_PI / 180.0)
+#define DEFAULT_FONT "sans 12"
+#define CHECK_FMT_DIR "checks"
+#define CUSTOM_CHECK_NAME "custom.chk"
+#define CHECK_NAME_FILTER "*.chk"
+#define DEGREES_TO_RADIANS (G_PI / 180.0)
#define KF_GROUP_TOP "Top"
#define KF_GROUP_POS "Check Positions"
@@ -104,6 +107,7 @@
static void gnc_ui_print_save_dialog(PrintCheckDialog * pcd);
static void gnc_ui_print_restore_dialog(PrintCheckDialog * pcd);
void gnc_ui_print_restore_dialog(PrintCheckDialog * pcd);
+void gnc_print_check_save_button_clicked(GtkButton *button, PrintCheckDialog *pcd);
/** This enum defines the types of items that gnucash knows how to
@@ -128,6 +132,8 @@
DEFINE_ENUM(CheckItemType, ENUM_CHECK_ITEM_TYPE)
FROM_STRING_DEC(CheckItemType, ENUM_CHECK_ITEM_TYPE)
FROM_STRING_FUNC(CheckItemType, ENUM_CHECK_ITEM_TYPE)
+AS_STRING_DEC(CheckItemType, ENUM_CHECK_ITEM_TYPE)
+AS_STRING_FUNC(CheckItemType, ENUM_CHECK_ITEM_TYPE)
/** This data structure describes a single item printed on a check.
* It is build from a description in a text file. */
@@ -369,6 +375,137 @@
}
+/** Save a coordinate pair into a check description file. This function
+ * extracts the values from the spin buttons, adjusts them for the units
+ * multiplies (inch, pixel, etc), and then adds them to the gKeyFile. */
+static void
+pcd_key_file_save_xy (GKeyFile *key_file, const gchar *group_name,
+ const gchar *key_name, gdouble multip,
+ GtkSpinButton *spin0, GtkSpinButton *spin1)
+{
+ gdouble dd[2];
+
+ dd[0] = multip * gtk_spin_button_get_value(spin0);
+ dd[1] = multip * gtk_spin_button_get_value(spin1);
+ /* Clip the numbers to three decimal places. */
+ dd[0] = round(dd[0] * 1000) / 1000;
+ dd[1] = round(dd[1] * 1000) / 1000;
+ g_key_file_set_double_list(key_file, group_name, key_name, dd, 2);
+}
+
+
+/** Save the information about a single printed item into a check description
+ * file. This function uses a helper function to extracts and save the item
+ * coordinates. */
+static void
+pcd_key_file_save_item_xy (GKeyFile *key_file, int index,
+ CheckItemType type, gdouble multip,
+ GtkSpinButton *spin0, GtkSpinButton *spin1)
+{
+ gchar *key;
+ key = g_strdup_printf("Type_%d", index);
+ g_key_file_set_string(key_file, KF_GROUP_ITEMS, key,
+ CheckItemTypeasString(type));
+ g_free(key);
+ key = g_strdup_printf("Coords_%d", index);
+ pcd_key_file_save_xy(key_file, KF_GROUP_ITEMS, key, multip, spin0, spin1);
+ g_free(key);
+}
+
+
+/** Save all of the information from the custom check dialog into a check
+ * description file. */
+static void
+pcd_save_custom_data(PrintCheckDialog *pcd, gchar *filename)
+{
+ GKeyFile *key_file;
+ GError *error = NULL;
+ GtkWidget *dialog;
+ gdouble multip;
+ gint i = 0;
+
+ multip = pcd_get_custom_multip(pcd);
+
+ key_file = g_key_file_new();
+ g_key_file_set_string(key_file, KF_GROUP_TOP, KF_KEY_TITLE,
+ _("Custom Check"));
+ g_key_file_set_boolean(key_file, KF_GROUP_TOP, KF_KEY_SHOW_GRID, FALSE);
+ g_key_file_set_boolean(key_file, KF_GROUP_TOP, KF_KEY_SHOW_BOXES, FALSE);
+ g_key_file_set_double(key_file, KF_GROUP_TOP, KF_KEY_ROTATION,
+ gtk_spin_button_get_value(pcd->check_rotation));
+ pcd_key_file_save_xy(key_file, KF_GROUP_TOP, KF_KEY_TRANSLATION, multip,
+ pcd->translation_x, pcd->translation_y);
+
+ pcd_key_file_save_item_xy(key_file, i++, PAYEE, multip,
+ pcd->payee_x, pcd->payee_y);
+ pcd_key_file_save_item_xy(key_file, i++, DATE, multip,
+ pcd->date_x, pcd->date_y);
+ pcd_key_file_save_item_xy(key_file, i++, AMOUNT_WORDS, multip,
+ pcd->words_x, pcd->words_y);
+ pcd_key_file_save_item_xy(key_file, i++, AMOUNT_NUMBER, multip,
+ pcd->number_x, pcd->number_y);
+ pcd_key_file_save_item_xy(key_file, i++, NOTES, multip,
+ pcd->notes_x, pcd->notes_y);
+
+ if (!gnc_key_file_save_to_file(filename, key_file, &error)) {
+ dialog = gtk_message_dialog_new(GTK_WINDOW(pcd->dialog),
+ GTK_DIALOG_DESTROY_WITH_PARENT,
+ GTK_MESSAGE_ERROR,
+ GTK_BUTTONS_CLOSE,
+ _("Cannot save check format file."));
+ gtk_message_dialog_format_secondary_text(GTK_MESSAGE_DIALOG(dialog),
+ error->message);
+ gtk_dialog_run(GTK_DIALOG(dialog));
+ gtk_widget_destroy(dialog);
+ g_error_free(error);
+ }
+}
+
+
+/** This function is called when the user clicks the "save format" button in
+ * the check printing dialog. It presents another dialog to the user to get
+ * the filename for saving the data. */
+void
+gnc_print_check_save_button_clicked(GtkButton *button, PrintCheckDialog *pcd)
+{
+ GtkFileChooser *chooser;
+ GtkFileFilter *filter;
+ GtkWidget *dialog;
+ gchar *check_dir, *filename;
+
+ dialog = gtk_file_chooser_dialog_new(_("Save Check Description"),
+ GTK_WINDOW(pcd->dialog),
+ GTK_FILE_CHOOSER_ACTION_SAVE,
+ GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
+ GTK_STOCK_SAVE, GTK_RESPONSE_ACCEPT,
+ NULL);
+ chooser = GTK_FILE_CHOOSER(dialog);
+
+ check_dir = g_build_filename(gnc_dotgnucash_dir(), CHECK_FMT_DIR, NULL);
+ gtk_file_chooser_set_current_folder(chooser, check_dir);
+ gtk_file_chooser_set_current_name(chooser, CUSTOM_CHECK_NAME);
+ g_free(check_dir);
+
+ filter = gtk_file_filter_new();
+ gtk_file_filter_set_name(filter, CHECK_NAME_FILTER);
+ gtk_file_filter_add_pattern(filter, CHECK_NAME_FILTER);
+ gtk_file_chooser_add_filter(chooser, filter);
+
+ filter = gtk_file_filter_new();
+ gtk_file_filter_set_name(filter, _("All Files"));
+ gtk_file_filter_add_pattern(filter, "*");
+ gtk_file_chooser_add_filter(chooser, filter);
+
+ if (gtk_dialog_run (GTK_DIALOG (dialog)) == GTK_RESPONSE_ACCEPT) {
+ filename = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(dialog));
+ pcd_save_custom_data(pcd, filename);
+ g_free(filename);
+ }
+
+ gtk_widget_destroy (dialog);
+}
+
+
/** This is an auxiliary debugging function for converting an array of doubles
* into a printable string. */
static gchar *
Modified: gnucash/trunk/src/gnome/glade/print.glade
===================================================================
--- gnucash/trunk/src/gnome/glade/print.glade 2007-03-15 03:00:55 UTC (rev 15723)
+++ gnucash/trunk/src/gnome/glade/print.glade 2007-03-15 05:20:58 UTC (rev 15724)
@@ -257,7 +257,7 @@
<child>
<widget class="GtkTable" id="custom_table">
<property name="visible">True</property>
- <property name="n_rows">11</property>
+ <property name="n_rows">13</property>
<property name="n_columns">3</property>
<property name="homogeneous">False</property>
<property name="row_spacing">0</property>
@@ -938,6 +938,116 @@
<property name="y_options"></property>
</packing>
</child>
+
+ <child>
+ <widget class="GtkLabel" id="label847681">
+ <property name="visible">True</property>
+ <property name="label" translatable="yes"> </property>
+ <property name="use_underline">False</property>
+ <property name="use_markup">False</property>
+ <property name="justify">GTK_JUSTIFY_LEFT</property>
+ <property name="wrap">False</property>
+ <property name="selectable">False</property>
+ <property name="xalign">0</property>
+ <property name="yalign">0.5</property>
+ <property name="xpad">0</property>
+ <property name="ypad">0</property>
+ <property name="ellipsize">PANGO_ELLIPSIZE_NONE</property>
+ <property name="width_chars">-1</property>
+ <property name="single_line_mode">False</property>
+ <property name="angle">0</property>
+ </widget>
+ <packing>
+ <property name="left_attach">0</property>
+ <property name="right_attach">1</property>
+ <property name="top_attach">11</property>
+ <property name="bottom_attach">12</property>
+ <property name="x_options">fill</property>
+ <property name="y_options"></property>
+ </packing>
+ </child>
+
+ <child>
+ <widget class="GtkButton" id="save_button">
+ <property name="visible">True</property>
+ <property name="can_focus">True</property>
+ <property name="relief">GTK_RELIEF_NORMAL</property>
+ <property name="focus_on_click">True</property>
+ <signal name="clicked" handler="gnc_print_check_save_button_clicked" last_modification_time="Thu, 15 Mar 2007 03:09:02 GMT"/>
+
+ <child>
+ <widget class="GtkAlignment" id="alignment1">
+ <property name="visible">True</property>
+ <property name="xalign">0.5</property>
+ <property name="yalign">0.5</property>
+ <property name="xscale">0</property>
+ <property name="yscale">0</property>
+ <property name="top_padding">0</property>
+ <property name="bottom_padding">0</property>
+ <property name="left_padding">0</property>
+ <property name="right_padding">0</property>
+
+ <child>
+ <widget class="GtkHBox" id="hbox1">
+ <property name="visible">True</property>
+ <property name="homogeneous">False</property>
+ <property name="spacing">2</property>
+
+ <child>
+ <widget class="GtkImage" id="image1">
+ <property name="visible">True</property>
+ <property name="stock">gtk-save-as</property>
+ <property name="icon_size">4</property>
+ <property name="xalign">0.5</property>
+ <property name="yalign">0.5</property>
+ <property name="xpad">0</property>
+ <property name="ypad">0</property>
+ </widget>
+ <packing>
+ <property name="padding">0</property>
+ <property name="expand">False</property>
+ <property name="fill">False</property>
+ </packing>
+ </child>
+
+ <child>
+ <widget class="GtkLabel" id="label847682">
+ <property name="visible">True</property>
+ <property name="label" translatable="yes">_Save format</property>
+ <property name="use_underline">True</property>
+ <property name="use_markup">False</property>
+ <property name="justify">GTK_JUSTIFY_LEFT</property>
+ <property name="wrap">False</property>
+ <property name="selectable">False</property>
+ <property name="xalign">0.5</property>
+ <property name="yalign">0.5</property>
+ <property name="xpad">0</property>
+ <property name="ypad">0</property>
+ <property name="ellipsize">PANGO_ELLIPSIZE_NONE</property>
+ <property name="width_chars">-1</property>
+ <property name="single_line_mode">False</property>
+ <property name="angle">0</property>
+ </widget>
+ <packing>
+ <property name="padding">0</property>
+ <property name="expand">False</property>
+ <property name="fill">False</property>
+ </packing>
+ </child>
+ </widget>
+ </child>
+ </widget>
+ </child>
+ </widget>
+ <packing>
+ <property name="left_attach">2</property>
+ <property name="right_attach">3</property>
+ <property name="top_attach">12</property>
+ <property name="bottom_attach">13</property>
+ <property name="x_options">fill</property>
+ <property name="y_options"></property>
+ </packing>
+ </child>
</widget>
<packing>
<property name="tab_expand">False</property>
More information about the gnucash-changes
mailing list