[Gnucash-changes] Prune three or four layers of complicated code that is only ever used to

David Hampton hampton at cvs.gnucash.org
Sat May 21 00:59:20 EDT 2005


Log Message:
-----------
Prune three or four layers of complicated code that is only ever used
to extract a single value from an account.

Tags:
----
gnucash-gnome2-dev

Modified Files:
--------------
    gnucash/src/app-utils:
        gnc-ui-util.c
        gnc-ui-util.h
    gnucash/src/gnome-utils:
        dialog-account.c
    gnucash/src/scm:
        main-window.scm

Revision Data
-------------
Index: gnc-ui-util.h
===================================================================
RCS file: /home/cvs/cvsroot/gnucash/src/app-utils/gnc-ui-util.h,v
retrieving revision 1.22.2.8
retrieving revision 1.22.2.9
diff -Lsrc/app-utils/gnc-ui-util.h -Lsrc/app-utils/gnc-ui-util.h -u -r1.22.2.8 -r1.22.2.9
--- src/app-utils/gnc-ui-util.h
+++ src/app-utils/gnc-ui-util.h
@@ -68,57 +68,6 @@
 gnc_commodity_table * gnc_get_current_commodities (void);
 
 /*
- * These values are order according to the way they should appear in
- * the register.  If you change this enum, you must also change the
- * acct_tree_defaults data structure in gnc-account-tree.c.
- */
-typedef enum
-{
-  ACCOUNT_NAME = 0,
-  ACCOUNT_TYPE,
-  ACCOUNT_COMMODITY,
-  ACCOUNT_CODE,
-  ACCOUNT_DESCRIPTION,
-  ACCOUNT_PRESENT,
-  ACCOUNT_PRESENT_REPORT,
-  ACCOUNT_BALANCE,        /* with sign reversal */
-  ACCOUNT_BALANCE_REPORT, /* ACCOUNT_BALANCE in default report currency */
-  ACCOUNT_CLEARED,
-  ACCOUNT_CLEARED_REPORT,
-  ACCOUNT_RECONCILED,
-  ACCOUNT_RECONCILED_REPORT,
-  ACCOUNT_FUTURE_MIN,
-  ACCOUNT_FUTURE_MIN_REPORT,
-  ACCOUNT_TOTAL,          /* balance + children's balance with sign reversal */
-  ACCOUNT_TOTAL_REPORT,   /* ACCOUNT_TOTAL in default report currency */
-  ACCOUNT_NOTES,
-  ACCOUNT_TAX_INFO,
-  ACCOUNT_PLACEHOLDER,
-  ACCOUNT_LAST_NUM,
-  NUM_ACCOUNT_FIELDS
-} AccountFieldCode;
-
-/**
- * This routine retrives the content for any given field in the
- * account tree data structure.  The account specifies the "row" and
- * the field parameter specifies the "column".  In essence, this is
- * one giant accessor routine for the Account object where all the
- * results are string values.
- *
- * @param account  The account to retrieve data about.
- * @param field    An indicator of which field in the account tree to return
- * @param negative An indicator that the result was a negative numeric
- *                 value.  May be used by the caller for colorization of the
- *                 returned string.
- * @return         The textual string representing the requested field.
- *
- * @note The caller must free the returned string when done with it.
- */
-char * gnc_ui_account_get_field_value_string (Account *account,
-                                              AccountFieldCode field,
-					      gboolean *negative);
-
-/*
  * This is a wrapper routine around an xaccGetBalanceInCurrency
  * function that handles additional needs of the gui.
  *
Index: gnc-ui-util.c
===================================================================
RCS file: /home/cvs/cvsroot/gnucash/src/app-utils/gnc-ui-util.c,v
retrieving revision 1.39.2.6
retrieving revision 1.39.2.7
diff -Lsrc/app-utils/gnc-ui-util.c -Lsrc/app-utils/gnc-ui-util.c -u -r1.39.2.6 -r1.39.2.7
--- src/app-utils/gnc-ui-util.c
+++ src/app-utils/gnc-ui-util.c
@@ -525,114 +525,6 @@
 }
 
 
-char *
-gnc_ui_account_get_field_value_string (Account *account,
-                                       AccountFieldCode field,
-				       gboolean *negative)
-{
-  g_return_val_if_fail ((field >= 0) && (field < NUM_ACCOUNT_FIELDS), NULL);
-
-  *negative = FALSE;
-  if (account == NULL)
-    return NULL;
-
-  switch (field)
-  {
-    case ACCOUNT_TYPE :
-      return g_strdup (xaccAccountGetTypeStr(xaccAccountGetType(account)));
-
-    case ACCOUNT_NAME :
-      return g_strdup (xaccAccountGetName(account));
-
-    case ACCOUNT_CODE :
-      return g_strdup (xaccAccountGetCode(account));
-
-    case ACCOUNT_DESCRIPTION :
-      return g_strdup (xaccAccountGetDescription(account));
-
-    case ACCOUNT_NOTES :
-      return g_strdup (xaccAccountGetNotes(account));
-
-    case ACCOUNT_COMMODITY :
-      return
-        g_strdup
-        (gnc_commodity_get_printname(xaccAccountGetCommodity(account)));
-
-    case ACCOUNT_PRESENT :
-      return
-	gnc_ui_account_get_print_balance(xaccAccountGetPresentBalanceInCurrency,
-					 account, FALSE, negative);
-
-    case ACCOUNT_PRESENT_REPORT :
-      return
-	gnc_ui_account_get_print_report_balance(xaccAccountGetPresentBalanceInCurrency,
-						account, FALSE, negative);
-
-    case ACCOUNT_BALANCE :
-      return
-	gnc_ui_account_get_print_balance(xaccAccountGetBalanceInCurrency,
-					 account, FALSE, negative);
-
-    case ACCOUNT_BALANCE_REPORT :
-      return
-	gnc_ui_account_get_print_report_balance(xaccAccountGetBalanceInCurrency,
-						account, FALSE, negative);
-
-    case ACCOUNT_CLEARED :
-      return
-	gnc_ui_account_get_print_balance(xaccAccountGetClearedBalanceInCurrency,
-					 account, FALSE, negative);
-
-    case ACCOUNT_CLEARED_REPORT :
-      return
-	gnc_ui_account_get_print_report_balance(xaccAccountGetClearedBalanceInCurrency,
-						account, FALSE, negative);
-
-    case ACCOUNT_RECONCILED :
-      return
-	gnc_ui_account_get_print_balance(xaccAccountGetReconciledBalanceInCurrency,
-					 account, FALSE, negative);
-
-    case ACCOUNT_RECONCILED_REPORT :
-      return
-	gnc_ui_account_get_print_report_balance(xaccAccountGetReconciledBalanceInCurrency,
-						account, FALSE, negative);
-
-    case ACCOUNT_FUTURE_MIN :
-      return
-	gnc_ui_account_get_print_balance(xaccAccountGetProjectedMinimumBalanceInCurrency,
-					 account, FALSE, negative);
-
-    case ACCOUNT_FUTURE_MIN_REPORT :
-      return
-	gnc_ui_account_get_print_report_balance(xaccAccountGetProjectedMinimumBalanceInCurrency,
-						account, FALSE, negative);
-
-    case ACCOUNT_TOTAL :
-      return
-	gnc_ui_account_get_print_balance(xaccAccountGetBalanceInCurrency,
-					 account, TRUE, negative);
-
-
-    case ACCOUNT_TOTAL_REPORT :
-      return
-	gnc_ui_account_get_print_report_balance(xaccAccountGetBalanceInCurrency,
-						account, TRUE, negative);
-
-    case ACCOUNT_TAX_INFO:
-      return gnc_ui_account_get_tax_info_string (account);
-
-    case ACCOUNT_LAST_NUM:
-     return g_strdup(xaccAccountGetLastNum (account));
-
-    default:
-      break;
-  }
-
-  return NULL;
-}
-
-
 /********************************************************************\
  * gnc_get_reconcile_str                                            *
  *   return the i18n'd string for the given reconciled flag         *
Index: dialog-account.c
===================================================================
RCS file: /home/cvs/cvsroot/gnucash/src/gnome-utils/dialog-account.c,v
retrieving revision 1.5.4.21
retrieving revision 1.5.4.22
diff -Lsrc/gnome-utils/dialog-account.c -Lsrc/gnome-utils/dialog-account.c -u -r1.5.4.21 -r1.5.4.22
--- src/gnome-utils/dialog-account.c
+++ src/gnome-utils/dialog-account.c
@@ -501,36 +501,25 @@
 
 /* helper function to perform changes to accounts */
 static void
-change_func (gpointer key, gpointer value, gpointer field_code)
+change_func (gpointer key, gpointer value, gpointer unused)
 {
   Account *account = key;
-  AccountFieldCode field = GPOINTER_TO_INT(field_code);
-
+  int type;
+ 
   if (account == NULL)
     return;
 
   xaccAccountBeginEdit(account);
 
-  switch (field)
-  {
-    case ACCOUNT_TYPE:
-      {
-        int type = GPOINTER_TO_INT(value);
+  type = GPOINTER_TO_INT(value);
 
-        if (type == xaccAccountGetType(account))
-          break;
+  if (type == xaccAccountGetType(account))
+    return;
 
-        /* Just refreshing won't work. */
-        aw_call_destroy_callbacks (account);
+  /* Just refreshing won't work. */
+  aw_call_destroy_callbacks (account);
 
-        xaccAccountSetType(account, type);
-      }
-      break;
-
-    default:
-      PERR ("unexpected account field code");
-      break;
-  }
+  xaccAccountSetType(account, type);
 
   xaccAccountCommitEdit(account);
 }
@@ -541,15 +530,13 @@
 make_account_changes(GHashTable *change_type)
 {
   if (change_type != NULL)
-    g_hash_table_foreach(change_type, change_func,
-                         GINT_TO_POINTER(ACCOUNT_TYPE));
+    g_hash_table_foreach(change_type, change_func, NULL);
 }
 
 
 typedef struct
 {
   Account *account;
-  AccountFieldCode field;
   GtkCList *list;
   guint count;
 } FillStruct;
@@ -563,7 +550,6 @@
   gchar *account_field_name;
   gchar *account_field_value;
   gchar *value_str;
-  gboolean dummy;
 
   if (fs == NULL) return;
   if (fs->account == account) return;
@@ -572,27 +558,16 @@
   if(!full_name)
     full_name = g_strdup("");
 
-  account_field_name = g_strdup(gnc_tree_view_account_get_field_name(fs->field));
+  account_field_name = g_strdup("Type");
   if (!account_field_name)
     account_field_name = g_strdup("");
 
   account_field_value =
-    gnc_ui_account_get_field_value_string(account, fs->field, &dummy);
+    g_strdup (xaccAccountGetTypeStr(xaccAccountGetType(account)));
   if (!account_field_value)
     account_field_value = g_strdup("");
 
-  switch (fs->field)
-  {
-    case ACCOUNT_TYPE:
-      value_str = g_strdup(xaccAccountGetTypeStr(GPOINTER_TO_INT(value)));
-      break;
-    default:
-      g_warning("unexpected field type");
-      g_free(full_name);
-      g_free(account_field_name);
-      g_free(account_field_value);
-      return;
-  }
+  value_str = g_strdup(xaccAccountGetTypeStr(GPOINTER_TO_INT(value)));
 
   {  
     gchar *strings[5];
@@ -615,7 +590,7 @@
 
 static guint
 fill_list(Account *account, GtkCList *list,
-          GHashTable *change, AccountFieldCode field)
+          GHashTable *change)
 {
   FillStruct fs;
 
@@ -623,7 +598,6 @@
     return 0;
 
   fs.account = account;
-  fs.field = field;
   fs.list = list;
   fs.count = 0;
 
@@ -660,7 +634,7 @@
   list = GTK_CLIST(gtk_clist_new_with_titles(4, titles));
 
   size = 0;
-  size += fill_list(account, list, change_type, ACCOUNT_TYPE);
+  size += fill_list(account, list, change_type);
 
   if (size == 0)
   {
@@ -1366,7 +1340,7 @@
   //  group = gnc_book_get_group (gnc_get_current_book ());
   aw->parent_tree = gnc_tree_view_account_new(TRUE);
   gtk_container_add(GTK_CONTAINER(box), GTK_WIDGET(aw->parent_tree));
-  gnc_tree_view_account_configure_columns (GNC_TREE_VIEW_ACCOUNT(aw->parent_tree), NULL);
+  gnc_tree_view_configure_columns (GNC_TREE_VIEW(aw->parent_tree), NULL);
   gtk_widget_show(GTK_WIDGET(aw->parent_tree));
   aw->top_level_account =
     gnc_tree_view_account_get_top_level (GNC_TREE_VIEW_ACCOUNT(aw->parent_tree));
Index: main-window.scm
===================================================================
RCS file: /home/cvs/cvsroot/gnucash/src/scm/main-window.scm,v
retrieving revision 1.23.2.7
retrieving revision 1.23.2.8
diff -Lsrc/scm/main-window.scm -Lsrc/scm/main-window.scm -u -r1.23.2.7 -r1.23.2.8
--- src/scm/main-window.scm
+++ src/scm/main-window.scm
@@ -71,31 +71,6 @@
 	    (list->vector (list 'payable   (N_ "Accounts Payable") ""))
 	    (list->vector (list 'receivable (N_ "Accounts Receivable") "")))))
 
-    (add-option
-     (gnc:make-list-option
-      (N_ "Account Tree") (N_ "Account fields to display")
-      "c" ""
-      (list 'description 'total)
-      (list (list->vector (list 'type           (N_ "Type") ""))
-            (list->vector (list 'code           (N_ "Code") ""))
-            (list->vector (list 'description    (N_ "Description") ""))
-            (list->vector (list 'notes          (N_ "Notes") ""))
-            (list->vector (list 'commodity      (N_ "Commodity") ""))
-            (list->vector (list 'balance        (N_ "Balance") ""))
-            (list->vector (list 'balance_report (N_ "Balance in Report Currency") ""))
-            (list->vector (list 'present        (N_ "Present Balance") ""))
-            (list->vector (list 'present_report (N_ "Present Balance in Report Currency") ""))
-            (list->vector (list 'cleared        (N_ "Cleared Balance") ""))
-            (list->vector (list 'cleared_report (N_ "Cleared Balance in Report Currency") ""))
-            (list->vector (list 'reconciled        (N_ "Reconciled Balance") ""))
-            (list->vector (list 'reconciled_report (N_ "Reconciled Balance in Report Currency") ""))
-            (list->vector (list 'future_min        (N_ "Future Minimum Balance") ""))
-            (list->vector (list 'future_min_report (N_ "Future Minimum Balance in Report Currency") ""))
-            (list->vector (list 'total          (N_ "Total") ""))
-            (list->vector (list 'total_report   (N_ "Total in Report Currency") ""))
-            (list->vector (list 'lastnum        (N_ "Last Number Used") ""))
-            (list->vector (list 'tax-info       (N_ "Tax Info") "")))))
-
     options))
 
 (define (gnc:make-new-acct-tree-window)  


More information about the gnucash-changes mailing list