[Gnucash-changes] Add entity type to HTML reports.

Linas Vepstas linas at cvs.gnucash.org
Mon May 31 16:10:52 EDT 2004


Log Message:
-----------
Add entity type to HTML reports.  Remove xaccGUIDType usage.
The xaccGUID usage was totally broken, clicking on report links
probably used to core dump; broken report links should now be fixed.

(This change probably conflicts with a jsled change to gnome2;
jsled, since this is the "more correct" long-term change as discussed, 
please reert teh other changes.)

Modified Files:
--------------
    gnucash/src/report/report-system:
        html-utilities.scm
    gnucash/src/gnome:
        top-level.c

Revision Data
-------------
Index: html-utilities.scm
===================================================================
RCS file: /home/cvs/cvsroot/gnucash/src/report/report-system/html-utilities.scm,v
retrieving revision 1.9
retrieving revision 1.10
diff -Lsrc/report/report-system/html-utilities.scm -Lsrc/report/report-system/html-utilities.scm -u -r1.9 -r1.10
--- src/report/report-system/html-utilities.scm
+++ src/report/report-system/html-utilities.scm
@@ -26,17 +26,17 @@
       (cons #f (gnc:html-make-empty-cells (- n 1)))
       '()))
 
-(define (register-guid guid)
-  (gnc:html-build-url gnc:url-type-register (string-append "guid=" guid) #f))
+(define (register-guid type guid)
+  (gnc:html-build-url gnc:url-type-register (string-append type guid) #f))
 
 (define (gnc:account-anchor-text acct)
-  (register-guid (gnc:account-get-guid acct)))
+  (register-guid "acct-guid=" (gnc:account-get-guid acct)))
 
 (define (gnc:split-anchor-text split)
-  (register-guid (gnc:split-get-guid split)))
+  (register-guid "split-guid=" (gnc:split-get-guid split)))
 
 (define (gnc:transaction-anchor-text trans)
-  (register-guid (gnc:transaction-get-guid trans)))
+  (register-guid "trans-guid=" (gnc:transaction-get-guid trans)))
 
 (define (gnc:report-anchor-text report-id)
   (gnc:html-build-url gnc:url-type-report
@@ -45,7 +45,7 @@
 
 (define (gnc:price-anchor-text price)
   (gnc:html-build-url gnc:url-type-price
-		      (string-append "guid=" (gnc:price-get-guid price))
+		      (string-append "price-guid=" (gnc:price-get-guid price))
 		      #f))
 
 ;; Make a new report and return the anchor to it. The new report of
Index: top-level.c
===================================================================
RCS file: /home/cvs/cvsroot/gnucash/src/gnome/top-level.c,v
retrieving revision 1.146
retrieving revision 1.147
diff -Lsrc/gnome/top-level.c -Lsrc/gnome/top-level.c -u -r1.146 -r1.147
--- src/gnome/top-level.c
+++ src/gnome/top-level.c
@@ -137,15 +137,45 @@
   helpWindow (NULL, NULL, HH_GLOBPREFS);
 }
 
+static void
+gnc_commodity_help_cb (void)
+{
+  helpWindow (NULL, _("Help"), HH_COMMODITY);
+}
+
+/* ============================================================== */
+/* HTML Hadler for reports. */
+
+#define IF_TYPE(URL_TYPE_STR,ENTITY_TYPE)                                   \
+  if (strncmp (URL_TYPE_STR, location, strlen (URL_TYPE_STR)) == 0)         \
+  {                                                                         \
+    GUID guid;                                                              \
+    QofCollection *col;                                                     \
+    QofEntity *entity;                                                      \
+    if (!string_to_guid (location + strlen(URL_TYPE_STR), &guid))           \
+    {                                                                       \
+      result->error_message = g_strdup_printf (_("Bad URL: %s"), location); \
+      return FALSE;                                                         \
+    }                                                                       \
+    col = qof_book_get_collection (book, ENTITY_TYPE);                      \
+    entity = qof_collection_lookup_entity (col, &guid);                     \
+    if (NULL == entity)                                                     \
+    {                                                                       \
+      result->error_message = g_strdup_printf (_("Entity Not Found: %s"), location); \
+      return FALSE;                                                         \
+    }                                                                       \
+
+
 static gboolean
 gnc_html_register_url_cb (const char *location, const char *label,
                           gboolean new_window, GNCURLResult *result)
 {
   GNCSplitReg * gsr   = NULL;
   Split       * split = NULL;
-  Account     * account;
+  Account     * account = NULL;
   Transaction * trans;
   GList       * node;
+  QofBook     * book = gnc_get_current_book();
 
   g_return_val_if_fail (location != NULL, FALSE);
   g_return_val_if_fail (result != NULL, FALSE);
@@ -158,137 +188,80 @@
     account = xaccGetAccountFromFullName (gnc_get_current_group (),
                                           location + 8, 
                                           gnc_get_account_separator ());
-    gsr = regWindowSimple (account);
-    gnc_split_reg_raise( gsr );
   }
+
   /* href="gnc-register:guid=12345678901234567890123456789012" */
-  else if (strncmp ("guid=", location, 5) == 0)
-  {
-    GUID guid;
-    GNCIdType id_type;
+  else IF_TYPE ("acct-guid=", GNC_ID_ACCOUNT)
+    account = GNC_ACCOUNT(entity);
+  }
 
-    if (!string_to_guid (location + 5, &guid))
-    {
-      result->error_message = g_strdup_printf (_("Bad URL: %s"), location);
-      return FALSE;
-    }
+  else IF_TYPE ("trans-guid=", GNC_ID_TRANS)
+    trans = (Transaction *) entity;
 
-    id_type = xaccGUIDType (&guid, gnc_get_current_book ());
-    if (id_type == GNC_ID_NONE || !safe_strcmp (id_type, GNC_ID_NULL))
-    {
-        result->error_message = g_strdup_printf (_("No such entity: %s"),
-                                                 location);
-        return FALSE;
-    }
-    else if (!safe_strcmp (id_type, GNC_ID_ACCOUNT))
+    for (node = xaccTransGetSplitList (trans); node; node = node->next)
     {
-        account = xaccAccountLookup (&guid, gnc_get_current_book ());
-        gsr = regWindowSimple( account );
+      split = node->data;
+      account = xaccSplitGetAccount(split);
+      if (account) break;
     }
-    else if (!safe_strcmp (id_type, GNC_ID_TRANS))
-    {
-        trans = xaccTransLookup (&guid, gnc_get_current_book ());
-        split = NULL;
-
-        for (node = xaccTransGetSplitList (trans); node; node = node->next)
-        {
-          split = node->data;
-          if (xaccSplitGetAccount (split))
-            break;
-        }
-
-        if (!split)
-        {
-          result->error_message =
-            g_strdup_printf (_("Transaction with no Accounts: %s"), location);
-          return FALSE;
-        }
 
-        gsr = regWindowSimple( xaccSplitGetAccount(split) );
-    }
-    else if (!safe_strcmp (id_type, GNC_ID_SPLIT))
+    if (!account)
     {
-        split = xaccSplitLookup (&guid, gnc_get_current_book ());
-        if (!split)
-        {
-          result->error_message = g_strdup_printf (_("No such split: %s"),
-                                                   location);
-          return FALSE;
-        }
-
-        gsr = regWindowSimple( xaccSplitGetAccount(split) );
-    }
-    else
-    {
-        result->error_message =
-          g_strdup_printf (_("Unsupported entity type: %s"), location);
-        return FALSE;
+      result->error_message =
+        g_strdup_printf (_("Transaction with no Accounts: %s"), location);
+      return FALSE;
     }
-
-    gnc_split_reg_raise(gsr);
-    if (split)
-      gnc_split_reg_jump_to_split( gsr, split );
+  }
+  else IF_TYPE ("split-guid=", GNC_ID_SPLIT)
+    split = (Split *) entity;
+    account = xaccSplitGetAccount(split);
   }
   else
   {
-    result->error_message = g_strdup_printf (_("Badly formed URL %s"),
-                                             location);
+    result->error_message =
+          g_strdup_printf (_("Unsupported entity type: %s"), location);
     return FALSE;
   }
 
+  gsr = regWindowSimple (account);
+  gnc_split_reg_raise(gsr);
+  if (split)
+      gnc_split_reg_jump_to_split( gsr, split );
+
   return TRUE;
 }
 
+/* ============================================================== */
+
 static gboolean
 gnc_html_price_url_cb (const char *location, const char *label,
-		       gboolean new_window, GNCURLResult *result)
+                       gboolean new_window, GNCURLResult *result)
 {
+  QofBook * book = gnc_get_current_book();
   g_return_val_if_fail (location != NULL, FALSE);
   g_return_val_if_fail (result != NULL, FALSE);
 
   result->load_to_stream = FALSE;
 
   /* href="gnc-register:guid=12345678901234567890123456789012" */
-  if (strncmp ("guid=", location, 5) == 0)
-  {
-      GUID guid;
-      GNCIdType id_type;
-
-      if (!string_to_guid (location + 5, &guid))
-      {
-	  result->error_message = g_strdup_printf (_("Bad URL: %s"), location);
-	  return FALSE;
-      }
-
-      id_type = xaccGUIDType (&guid, gnc_get_current_book ());
-      if (id_type == GNC_ID_NONE || safe_strcmp (id_type, GNC_ID_PRICE))
-      {
-          result->error_message =
-	    g_strdup_printf (_("Unsupported entity type: %s"), location);
-	  return FALSE;
-      }
-      if (!gnc_price_edit_by_guid (NULL, &guid)) {
-          result->error_message = g_strdup_printf (_("No such entity: %s"),
-						 location);
-	  return FALSE;
-      }
+  IF_TYPE ("price-guid=", GNC_ID_PRICE)
+    if (!gnc_price_edit_by_guid (NULL, &guid)) 
+    {
+        result->error_message = g_strdup_printf (_("No such price: %s"),
+                                                 location);
+        return FALSE;
+    }
   }
   else
   {
       result->error_message = g_strdup_printf (_("Badly formed URL %s"),
-					       location);
+                                               location);
       return FALSE;
   }
 
   return TRUE;
 }
 
-static void
-gnc_commodity_help_cb (void)
-{
-  helpWindow (NULL, _("Help"), HH_COMMODITY);
-}
-
 /* ============================================================== */
 
 SCM
@@ -503,8 +476,7 @@
 }
 
 static int
-gnc_x_error (Display	 *display,
-	     XErrorEvent *error)
+gnc_x_error (Display        *display, XErrorEvent *error)
 {
   if (error->error_code)
   {
@@ -860,7 +832,7 @@
 {
   gnc_file_be_set_retention_days
     (gnc_lookup_number_option("General",
-			      "Days to retain log files", 0));
+                              "Days to retain log files", 0));
 }
 
 /* gnc_configure_file_be_retention_days_cb


More information about the gnucash-changes mailing list