From 584f16aa3659a458b09906a36bbbecfa29ff0d79 Mon Sep 17 00:00:00 2001 From: Derek Atkins Date: Sun, 19 Feb 2006 18:20:18 +0000 Subject: [PATCH] Remember the last-used account when processing payment (#329725) * src/business/business-core/gncOwner.[ch]: Add api to get owner kvp-slots abstractly. * src/business/business-gnome/dialog-payment.c: Load/save the last-used transfer account whenever the owner changes or the dialog completes. Fixes #329725. git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@13298 57a11ea4-9604-0410-9ed3-97b8803252fd --- ChangeLog | 7 ++ src/business/business-core/gncOwner.c | 16 +++++ src/business/business-core/gncOwner.h | 3 + src/business/business-gnome/dialog-payment.c | 74 ++++++++++++++++++++ 4 files changed, 100 insertions(+) diff --git a/ChangeLog b/ChangeLog index d51d1c2bd3..1503fc5c17 100644 --- a/ChangeLog +++ b/ChangeLog @@ -23,6 +23,13 @@ * src/business/business-reports/fancy-invoice.scm: Brian's patch to add company-id to the company address. + * src/business/business-core/gncOwner.[ch]: Add api to get owner + kvp-slots abstractly. + * src/business/business-gnome/dialog-payment.c: Load/save the + last-used transfer account whenever the owner changes or + the dialog completes. + Fixes #329725. + 2006-02-18 Derek Atkins * intl-scm/xgettext.scm: remove the absolute path from filenames diff --git a/src/business/business-core/gncOwner.c b/src/business/business-core/gncOwner.c index c8447c8f13..2bbecb2859 100644 --- a/src/business/business-core/gncOwner.c +++ b/src/business/business-core/gncOwner.c @@ -464,6 +464,22 @@ gboolean gncOwnerIsValid (GncOwner *owner) return (owner->owner.undefined != NULL); } +KvpFrame* gncOwnerGetSlots(GncOwner* owner) +{ + if (!owner) return NULL; + + switch (gncOwnerGetType(owner)) { + case GNC_OWNER_CUSTOMER: + case GNC_OWNER_VENDOR: + case GNC_OWNER_EMPLOYEE: + return qof_instance_get_slots(QOF_INSTANCE(owner->owner.undefined)); + case GNC_OWNER_JOB: + return gncOwnerGetSlots(gncJobGetOwner(gncOwnerGetJob(owner))); + default: + return NULL; + } +} + /* XXX: Yea, this is broken, but it should work fine for Queries. * We're single-threaded, right? */ diff --git a/src/business/business-core/gncOwner.h b/src/business/business-core/gncOwner.h index c28278eec8..8663988588 100644 --- a/src/business/business-core/gncOwner.h +++ b/src/business/business-core/gncOwner.h @@ -138,6 +138,9 @@ gboolean gncOwnerGetOwnerFromLot (GNCLot *lot, GncOwner *owner); gboolean gncOwnerGetOwnerFromTypeGuid (QofBook *book, GncOwner *owner, QofIdType type, GUID *guid); +/** Get the kvp-frame from the underlying owner object */ +KvpFrame* gncOwnerGetSlots(GncOwner* owner); + #define OWNER_TYPE "type" #define OWNER_TYPE_STRING "type-string" /**< Allows the type to be handled externally. */ #define OWNER_CUSTOMER "customer" diff --git a/src/business/business-gnome/dialog-payment.c b/src/business/business-gnome/dialog-payment.c index 4d220e49fb..57720c251e 100644 --- a/src/business/business-gnome/dialog-payment.c +++ b/src/business/business-gnome/dialog-payment.c @@ -86,10 +86,75 @@ gnc_payment_window_close_handler (gpointer data) gtk_widget_destroy (pw->dialog); } +static void +gnc_payment_dialog_owner_changed(PaymentWindow *pw) +{ + Account *last_acct; + GUID *guid; + KvpValue* value; + KvpFrame* slots = gncOwnerGetSlots(&pw->owner); + + if (!slots) return; + + value = kvp_frame_get_slot_path(slots, "payment", "last_acct", NULL); + if (!value) return; + + guid = kvp_value_get_guid(value); + if (!guid) return; + + last_acct = xaccAccountLookup(guid, pw->book); + + /* Set the last-used transfer account */ + if (last_acct) { + gnc_tree_view_account_set_selected_account(GNC_TREE_VIEW_ACCOUNT(pw->acct_tree), + last_acct); + } +} + +static void +gnc_payment_dialog_remember_account(PaymentWindow *pw, Account *acc) +{ + KvpValue* value; + KvpFrame* slots = gncOwnerGetSlots(&pw->owner); + + if (!acc) return; + if (!slots) return; + + value = kvp_value_new_guid(xaccAccountGetGUID(acc)); + if (!value) return; + + kvp_frame_set_slot_path(slots, value, "payment", "last_acct", NULL); + kvp_value_delete(value); + + /* XXX: FIXME: Need a commit_edit here to save the data! */ +} + + static void gnc_payment_set_owner (PaymentWindow *pw, GncOwner *owner) { gnc_owner_set_owner (pw->owner_choice, owner); + gnc_payment_dialog_owner_changed(pw); +} + +static int +gnc_payment_dialog_owner_changed_cb (GtkWidget *widget, gpointer data) +{ + PaymentWindow *pw = data; + GncOwner owner; + + if (!pw) return FALSE; + + gncOwnerCopy (&(pw->owner), &owner); + gnc_owner_get_owner (pw->owner_choice, &owner); + + /* If this owner really changed, then reset ourselves */ + if (!gncOwnerEqual (&owner, &(pw->owner))) { + gncOwnerCopy (&owner, &(pw->owner)); + gnc_payment_dialog_owner_changed(pw); + } + + return FALSE; } void @@ -164,6 +229,9 @@ gnc_payment_ok_cb (GtkWidget *widget, gpointer data) } gnc_resume_gui_refresh (); + /* Save the transfer account, acc */ + gnc_payment_dialog_remember_account(pw, acc); + gnc_ui_payment_window_destroy (pw); } @@ -285,11 +353,17 @@ new_payment_window (GncOwner *owner, GNCBook *book, gnc_numeric initial_payment) gtk_tree_view_set_headers_visible (GTK_TREE_VIEW(pw->acct_tree), FALSE); gnc_payment_set_account_types (GNC_TREE_VIEW_ACCOUNT (pw->acct_tree)); + /* Set the dialog for the 'new' owner */ + gnc_payment_dialog_owner_changed(pw); + /* Setup signals */ glade_xml_signal_autoconnect_full( xml, gnc_glade_autoconnect_full_func, pw); + g_signal_connect (G_OBJECT (pw->owner_choice), "changed", + G_CALLBACK (gnc_payment_dialog_owner_changed_cb), pw); + /* Register with the component manager */ pw->component_id = gnc_register_gui_component (cm_class,