AUDIT: r17451 - gnucash/trunk/src/gnome-utils - Bug #543780: Scrub the transfer dialog calculation of the "to" amount:

Charles Day cedayiv at cvs.gnucash.org
Sat Aug 2 17:53:23 EDT 2008


Author: cedayiv
Date: 2008-08-02 17:53:23 -0400 (Sat, 02 Aug 2008)
New Revision: 17451
Trac: http://svn.gnucash.org/trac/changeset/17451

Modified:
   gnucash/trunk/src/gnome-utils/dialog-transfer.c
Log:
Bug #543780: Scrub the transfer dialog calculation of the "to" amount:
-Check account value to avoid causing a CRIT message.
-Reorganize function for smaller size and more readability.
-Add some comments (there were none).
BP


Modified: gnucash/trunk/src/gnome-utils/dialog-transfer.c
===================================================================
--- gnucash/trunk/src/gnome-utils/dialog-transfer.c	2008-08-02 18:57:13 UTC (rev 17450)
+++ gnucash/trunk/src/gnome-utils/dialog-transfer.c	2008-08-02 21:53:23 UTC (rev 17451)
@@ -831,48 +831,39 @@
 static void
 gnc_xfer_update_to_amount (XferDialog *xferData)
 {
-  gnc_numeric amount, price, to_amount;
+  GNCAmountEdit *amount_edit, *price_edit, *to_amount_edit;
+  gnc_numeric price, to_amount;
   Account *account;
 
-  account = gnc_transfer_dialog_get_selected_account (xferData, XFER_DIALOG_TO);
-  if (account == NULL)
-    account = gnc_transfer_dialog_get_selected_account (xferData, XFER_DIALOG_FROM);
+  g_return_if_fail(xferData);
 
+  /* Get the amount editing controls of the dialog. */
+  amount_edit     = GNC_AMOUNT_EDIT(xferData->amount_edit);
+  price_edit      = GNC_AMOUNT_EDIT(xferData->price_edit);
+  to_amount_edit  = GNC_AMOUNT_EDIT(xferData->to_amount_edit);
+
+  account = gnc_transfer_dialog_get_selected_account(xferData, XFER_DIALOG_TO);
   if (account == NULL)
-  {
-    GtkEntry *entry;
+    account = gnc_transfer_dialog_get_selected_account(xferData,
+                                                       XFER_DIALOG_FROM);
 
-    gnc_amount_edit_set_amount(GNC_AMOUNT_EDIT(xferData->to_amount_edit),
-                               gnc_numeric_zero ());
-    entry = GTK_ENTRY(gnc_amount_edit_gtk_entry
-                      (GNC_AMOUNT_EDIT(xferData->to_amount_edit)));
-    gtk_entry_set_text(entry, "");
-  }
-
-  gnc_amount_edit_evaluate (GNC_AMOUNT_EDIT (xferData->price_edit));
-
-  amount = gnc_amount_edit_get_amount(GNC_AMOUNT_EDIT(xferData->amount_edit));
-  price = gnc_amount_edit_get_amount(GNC_AMOUNT_EDIT(xferData->price_edit));
-
-  if (gnc_numeric_zero_p (price))
-    to_amount = gnc_numeric_zero ();
+  /* Determine the amount to transfer. */
+  if (account == NULL ||
+      !gnc_amount_edit_evaluate(price_edit) ||
+      gnc_numeric_zero_p(price = gnc_amount_edit_get_amount(price_edit)))
+    to_amount = gnc_numeric_zero();
   else
-    to_amount = gnc_numeric_mul (amount, price,
-                                 xaccAccountGetCommoditySCU (account),
-                                 GNC_RND_ROUND);
+    to_amount = gnc_numeric_mul(gnc_amount_edit_get_amount(amount_edit),
+                                price,
+                                xaccAccountGetCommoditySCU(account),
+                                GNC_RND_ROUND);
 
-  gnc_amount_edit_set_amount(GNC_AMOUNT_EDIT(xferData->to_amount_edit),
-                             to_amount);
+  /* Update the dialog. */
+  gnc_amount_edit_set_amount(to_amount_edit, to_amount);
+  if (gnc_numeric_zero_p(to_amount))
+    gtk_entry_set_text(GTK_ENTRY(gnc_amount_edit_gtk_entry(to_amount_edit)),
+                       "");
 
-  if (gnc_numeric_zero_p (to_amount))
-  {
-    GtkEntry *entry;
-
-    entry = GTK_ENTRY(gnc_amount_edit_gtk_entry
-                      (GNC_AMOUNT_EDIT(xferData->to_amount_edit)));
-    gtk_entry_set_text(entry, "");
-  }
-
   gnc_xfer_dialog_update_conv_info(xferData);
 }
 



More information about the gnucash-changes mailing list