[Gnucash-changes] r13298 - gnucash/trunk - Remember the last-used account when processing payment (#329725)

Derek Atkins warlord at cvs.gnucash.org
Sun Feb 19 13:20:19 EST 2006


Author: warlord
Date: 2006-02-19 13:20:18 -0500 (Sun, 19 Feb 2006)
New Revision: 13298
Trac: http://svn.gnucash.org/trac/changeset/13298

Modified:
   gnucash/trunk/ChangeLog
   gnucash/trunk/src/business/business-core/gncOwner.c
   gnucash/trunk/src/business/business-core/gncOwner.h
   gnucash/trunk/src/business/business-gnome/dialog-payment.c
Log:
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.



Modified: gnucash/trunk/ChangeLog
===================================================================
--- gnucash/trunk/ChangeLog	2006-02-19 16:36:08 UTC (rev 13297)
+++ gnucash/trunk/ChangeLog	2006-02-19 18:20:18 UTC (rev 13298)
@@ -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  <derek at ihtfp.com>
 
 	* intl-scm/xgettext.scm: remove the absolute path from filenames

Modified: gnucash/trunk/src/business/business-core/gncOwner.c
===================================================================
--- gnucash/trunk/src/business/business-core/gncOwner.c	2006-02-19 16:36:08 UTC (rev 13297)
+++ gnucash/trunk/src/business/business-core/gncOwner.c	2006-02-19 18:20:18 UTC (rev 13298)
@@ -464,6 +464,22 @@
   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?
  */

Modified: gnucash/trunk/src/business/business-core/gncOwner.h
===================================================================
--- gnucash/trunk/src/business/business-core/gncOwner.h	2006-02-19 16:36:08 UTC (rev 13297)
+++ gnucash/trunk/src/business/business-core/gncOwner.h	2006-02-19 18:20:18 UTC (rev 13298)
@@ -138,6 +138,9 @@
 
 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"

Modified: gnucash/trunk/src/business/business-gnome/dialog-payment.c
===================================================================
--- gnucash/trunk/src/business/business-gnome/dialog-payment.c	2006-02-19 16:36:08 UTC (rev 13297)
+++ gnucash/trunk/src/business/business-gnome/dialog-payment.c	2006-02-19 18:20:18 UTC (rev 13298)
@@ -87,11 +87,76 @@
 }
 
 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
 gnc_payment_ok_cb (GtkWidget *widget, gpointer data)
 {
@@ -164,6 +229,9 @@
   }
   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 @@
   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,



More information about the gnucash-changes mailing list