diff --git a/src/app-utils/gnc-component-manager.c b/src/app-utils/gnc-component-manager.c index e605be767b..640deaa438 100644 --- a/src/app-utils/gnc-component-manager.c +++ b/src/app-utils/gnc-component-manager.c @@ -202,25 +202,23 @@ add_event_type (ComponentEventInfo *cei, GNCIdType entity_type, if (cei == NULL) return; - switch (entity_type) + if (!safe_strcmp (entity_type, GNC_ID_TRANS)) { - case GNC_ID_TRANS: - if (or_in) - cei->trans_event_mask |= event_mask; - else - cei->trans_event_mask = event_mask; - break; - - case GNC_ID_ACCOUNT: - if (or_in) - cei->account_event_mask |= event_mask; - else - cei->account_event_mask = event_mask; - break; - - default: - PERR ("unexpected entity type: %d", entity_type); - break; + if (or_in) + cei->trans_event_mask |= event_mask; + else + cei->trans_event_mask = event_mask; + } + else if (!safe_strcmp (entity_type, GNC_ID_ACCOUNT)) + { + if (or_in) + cei->account_event_mask |= event_mask; + else + cei->account_event_mask = event_mask; + } + else + { + PERR ("unexpected entity type: %s", entity_type); } } @@ -234,41 +232,37 @@ gnc_cm_event_handler (GUID *entity, add_event (&changes, entity, event_type, TRUE); id_type = xaccGUIDType (entity, gnc_get_current_book ()); - switch (id_type) + + if (!safe_strcmp (id_type, GNC_ID_TRANS)) { - case GNC_ID_TRANS: - changes.trans_event_mask |= event_type; - break; - - case GNC_ID_ACCOUNT: - changes.account_event_mask |= event_type; - break; - - case GNC_ID_SPLIT: - /* split events are never generated by the engine, but might be - * generated by a backend (viz. the postgres backend.) - * Handle them just like transactions */ - changes.trans_event_mask |= event_type; - break; - - case GNC_ID_PRICE: - /* hack alert -- FIXME - Price events not currently handled by CM */ - break; - - case GNC_ID_NONE: - break; - - case GNC_ID_SCHEDXACTION: - case GNC_ID_FREQSPEC: - DEBUG( "FIXME for GNC_ID %d", id_type ); - break; - - default: { - char guid_str[GUID_ENCODING_LENGTH+1]; - guid_to_string_buff (entity, guid_str); - PERR ("unexpected id type: %d for guid=%s", id_type, guid_str); - break; - } + changes.trans_event_mask |= event_type; + } + else if (!safe_strcmp (id_type, GNC_ID_ACCOUNT)) + { + changes.account_event_mask |= event_type; + } + else if (!safe_strcmp (id_type, GNC_ID_SPLIT)) + { + /* split events are never generated by the engine, but might be + * generated by a backend (viz. the postgres backend.) + * Handle them just like transactions */ + changes.trans_event_mask |= event_type; + } + else if (!safe_strcmp (id_type, GNC_ID_PRICE)) + { + /* hack alert -- FIXME - Price events not currently handled by CM */ + ; + } + else if (!safe_strcmp (id_type, GNC_ID_SCHEDXACTION) || + !safe_strcmp (id_type, GNC_ID_FREQSPEC)) + { + DEBUG( "FIXME for GNC_ID %s", id_type ); + } + else + { + char guid_str[GUID_ENCODING_LENGTH+1]; + guid_to_string_buff (entity, guid_str); + PERR ("unexpected id type: %s for guid=%s", id_type, guid_str); } got_events = TRUE; @@ -434,10 +428,10 @@ gnc_gui_component_watch_entity_type (gint component_id, { ComponentInfo *ci; - if (entity_type != GNC_ID_TRANS && - entity_type != GNC_ID_ACCOUNT) + if (safe_strcmp (entity_type, GNC_ID_TRANS) && + safe_strcmp (entity_type, GNC_ID_ACCOUNT)) { - PERR ("bad entity type: %d", entity_type); + PERR ("bad entity type: %s", entity_type); return; } diff --git a/src/backend/postgres/events.c b/src/backend/postgres/events.c index bafc007272..1208e6fcd4 100644 --- a/src/backend/postgres/events.c +++ b/src/backend/postgres/events.c @@ -266,89 +266,83 @@ pgendProcessEvents (Backend *bend) /* lets see if the local cache has this item in it */ local_obj_type = xaccGUIDType (&(ev->guid), be->book); - if ((local_obj_type != GNC_ID_NONE) && (local_obj_type != ev->obj_type)) + if ((local_obj_type != GNC_ID_NONE) && (safe_strcmp (local_obj_type, + ev->obj_type))) { - PERR ("ouch! object type mismatch, local=%d, event=%d", + PERR ("ouch! object type mismatch, local=%s, event=%s", local_obj_type, ev->obj_type); g_free (ev); continue; } - switch (ev->obj_type) + if (!safe_strcmp (ev->obj_type, GNC_ID_ACCOUNT)) { - case GNC_ID_NONE: - case GNC_ID_NULL: - PERR ("bad event type"); - break; - case GNC_ID_ACCOUNT: - if (0 < timespec_cmp(&(ev->stamp), &(be->last_account))) - { - be->last_account = ev->stamp; - } - switch (ev->type) - { - default: - PERR ("account: cant' happen !!!!!!!"); - break; - case GNC_EVENT_CREATE: - case GNC_EVENT_MODIFY: - /* if the remote user created an account, mirror it here */ - pgendCopyAccountToEngine (be, &(ev->guid)); - xaccGroupMarkSaved (pgendGetTopGroup (be)); - break; - case GNC_EVENT_DESTROY: { - Account * acc = xaccAccountLookup (&(ev->guid), be->book); - xaccAccountBeginEdit (acc); - xaccAccountDestroy (acc); - xaccGroupMarkSaved (pgendGetTopGroup (be)); - break; - } - } - - break; - - case GNC_ID_TRANS: - if (0 < timespec_cmp(&(ev->stamp), &(be->last_transaction))) - { - be->last_transaction = ev->stamp; - } - switch (ev->type) - { - default: - PERR ("transaction: cant' happen !!!!!!!"); - break; - case GNC_EVENT_CREATE: - /* don't mirror transaction creations. If a register needs - * it, it will do a query. */ - PINFO ("create transaction"); - break; - case GNC_EVENT_MODIFY: - pgendCopyTransactionToEngine (be, &(ev->guid)); - break; - case GNC_EVENT_DESTROY: { - Transaction *trans = xaccTransLookup (&(ev->guid), - be->book); - xaccTransBeginEdit (trans); - xaccTransDestroy (trans); - xaccTransCommitEdit (trans); - break; - } - } - - break; - - case GNC_ID_SPLIT: - if (0 < timespec_cmp(&(ev->stamp), &(be->last_transaction))) - be->last_transaction = ev->stamp; - break; - - case GNC_ID_PRICE: - if (0 < timespec_cmp(&(ev->stamp), &(be->last_price))) - be->last_price = ev->stamp; - break; - - default: - PERR ("unknown guid type %d", ev->obj_type); + if (0 < timespec_cmp(&(ev->stamp), &(be->last_account))) + { + be->last_account = ev->stamp; + } + switch (ev->type) + { + default: + PERR ("account: cant' happen !!!!!!!"); + break; + case GNC_EVENT_CREATE: + case GNC_EVENT_MODIFY: + /* if the remote user created an account, mirror it here */ + pgendCopyAccountToEngine (be, &(ev->guid)); + xaccGroupMarkSaved (pgendGetTopGroup (be)); + break; + case GNC_EVENT_DESTROY: { + Account * acc = xaccAccountLookup (&(ev->guid), be->book); + xaccAccountBeginEdit (acc); + xaccAccountDestroy (acc); + xaccGroupMarkSaved (pgendGetTopGroup (be)); + break; + } + } + } + else if (!safe_strcmp (ev->obj_type, GNC_ID_TRANS)) + { + if (0 < timespec_cmp(&(ev->stamp), &(be->last_transaction))) + { + be->last_transaction = ev->stamp; + } + switch (ev->type) + { + default: + PERR ("transaction: cant' happen !!!!!!!"); + break; + case GNC_EVENT_CREATE: + /* don't mirror transaction creations. If a register needs + * it, it will do a query. */ + PINFO ("create transaction"); + break; + case GNC_EVENT_MODIFY: + pgendCopyTransactionToEngine (be, &(ev->guid)); + break; + case GNC_EVENT_DESTROY: { + Transaction *trans = xaccTransLookup (&(ev->guid), + be->book); + xaccTransBeginEdit (trans); + xaccTransDestroy (trans); + xaccTransCommitEdit (trans); + break; + } + } + } + else if (!safe_strcmp (ev->obj_type, GNC_ID_SPLIT)) + { + if (0 < timespec_cmp(&(ev->stamp), &(be->last_transaction))) + be->last_transaction = ev->stamp; + } + else if (!safe_strcmp (ev->obj_type, GNC_ID_PRICE)) + { + if (0 < timespec_cmp(&(ev->stamp), &(be->last_price))) + be->last_price = ev->stamp; + } + else + { + PERR ("unknown guid type %s", ev->obj_type); } /* get the local type again, since we created guid above */ diff --git a/src/backend/postgres/gncquery.c b/src/backend/postgres/gncquery.c index 81d76c0b46..38d17d30d1 100644 --- a/src/backend/postgres/gncquery.c +++ b/src/backend/postgres/gncquery.c @@ -813,20 +813,11 @@ sqlQuery_build (sqlQuery *sq, Query *q, GNCBook *book) break; case PR_GUID: - switch (pd->guid.id_type) - { - case GNC_ID_ACCOUNT: - need_account = TRUE; - break; - - case GNC_ID_SPLIT: - need_entry = TRUE; - break; - - default: - break; - } - break; + if (!safe_strcmp (pd->guid.id_type, GNC_ID_ACCOUNT)) + need_account = TRUE; + else if (!safe_strcmp (pd->guid.id_type, GNC_ID_SPLIT)) + need_entry = TRUE; + break; case PR_KVP: if (pd->kvp.where & KVP_MATCH_SPLIT) @@ -1064,32 +1055,27 @@ sqlQuery_build (sqlQuery *sq, Query *q, GNCBook *book) sq->pq = stpcpy (sq->pq, " ("); - switch (pd->guid.id_type) - { - default: - case GNC_ID_NULL: - case GNC_ID_NONE: + if (pd->guid.id_type == GNC_ID_NONE || + !safe_strcmp (pd->guid.id_type, GNC_ID_NULL)) sq->pq = stpcpy(sq->pq, "FALSE "); - break; - - case GNC_ID_ACCOUNT: + else if (!safe_strcmp (pd->guid.id_type, GNC_ID_ACCOUNT)) + { sq->pq = stpcpy(sq->pq, "gncAccount.accountGuid = '"); sq->pq = guid_to_string_buff (&pd->guid.guid, sq->pq); sq->pq = stpcpy(sq->pq, "' "); - break; - - case GNC_ID_TRANS: + } + else if (!safe_strcmp (pd->guid.id_type, GNC_ID_TRANS)) + { sq->pq = stpcpy(sq->pq, "gncTransaction.transGuid = '"); sq->pq = guid_to_string_buff (&pd->guid.guid, sq->pq); sq->pq = stpcpy(sq->pq, "' "); - break; - - case GNC_ID_SPLIT: + } + else if (!safe_strcmp (pd->guid.id_type, GNC_ID_SPLIT)) + { sq->pq = stpcpy(sq->pq, "gncEntry.entryGuid = '"); sq->pq = guid_to_string_buff (&pd->guid.guid, sq->pq); sq->pq = stpcpy(sq->pq, "' "); - break; - } + } sq->pq = stpcpy (sq->pq, ") "); diff --git a/src/business/business-core/gncBusiness.h b/src/business/business-core/gncBusiness.h index e937dfba8e..4de260057b 100644 --- a/src/business/business-core/gncBusiness.h +++ b/src/business/business-core/gncBusiness.h @@ -32,7 +32,7 @@ struct _gncBusinessObject { GncBusiness *gncBusinessCreate (GNCBook *book); void gncBusinessDestroy (GncBusiness *business); -/* Return the GNC Session from the Business Object */ +/* Return the GNCBook from the Business Object */ GNCBook * gncBusinessGetBook (const GncBusiness *bus); /* Obtain an object from the type and GUID */ diff --git a/src/engine/GNCId.c b/src/engine/GNCId.c index bef4bb1451..c373671991 100644 --- a/src/engine/GNCId.c +++ b/src/engine/GNCId.c @@ -30,6 +30,8 @@ #include "gnc-engine-util.h" #include "gnc-book-p.h" +#define CACHE_INSERT(str) g_cache_insert(gnc_engine_get_string_cache(), (gpointer)(str)); +#define CACHE_REMOVE(str) g_cache_remove(gnc_engine_get_string_cache(), (str)); /** #defines ********************************************************/ #define GNCID_DEBUG 0 @@ -93,6 +95,7 @@ entity_node_destroy(gpointer key, gpointer value, gpointer not_used) GUID *guid = key; EntityNode *e_node = value; + CACHE_REMOVE (e_node->entity_type); e_node->entity_type = GNC_ID_NONE; e_node->entity = NULL; @@ -156,7 +159,7 @@ print_node(gpointer key, gpointer value, gpointer not_used) GUID *guid = key; EntityNode *node = value; - fprintf(stderr, "%s %d %p\n", + fprintf(stderr, "%s %s %p\n", guid_to_string(guid), node->entity_type, node->entity); } @@ -188,7 +191,6 @@ GNCIdType xaccGUIDTypeEntityTable (const GUID * guid, GNCEntityTable *entity_table) { EntityNode *e_node; - GNCIdType entity_type; if (guid == NULL) return GNC_ID_NONE; @@ -199,11 +201,7 @@ xaccGUIDTypeEntityTable (const GUID * guid, GNCEntityTable *entity_table) if (e_node == NULL) return GNC_ID_NONE; - entity_type = e_node->entity_type; - if ((entity_type <= GNC_ID_NONE) || (entity_type > LAST_GNC_ID)) - return GNC_ID_NONE; - - return entity_type; + return e_node->entity_type; } GNCIdType @@ -272,7 +270,7 @@ xaccLookupEntity (GNCEntityTable *entity_table, if (e_node == NULL) return NULL; - if (e_node->entity_type != entity_type) + if (safe_strcmp (e_node->entity_type, entity_type)) return NULL; return e_node->entity; @@ -290,15 +288,14 @@ xaccStoreEntity (GNCEntityTable *entity_table, gpointer entity, if (guid == NULL) return; - if ((entity_type <= GNC_ID_NONE) || (entity_type > LAST_GNC_ID)) - return; + if (!entity_type) return; if (guid_equal(guid, xaccGUIDNULL())) return; xaccRemoveEntity (entity_table, guid); e_node = g_new(EntityNode, 1); - e_node->entity_type = entity_type; + e_node->entity_type = CACHE_INSERT (entity_type); e_node->entity = entity; new_guid = xaccGUIDMalloc (); @@ -325,7 +322,8 @@ xaccRemoveEntity (GNCEntityTable *entity_table, const GUID * guid) if (g_hash_table_lookup_extended(entity_table->hash, guid, &old_guid, &node)) { e_node = node; - if (e_node->entity_type == GNC_ID_NULL) + + if (!safe_strcmp (e_node->entity_type, GNC_ID_NULL)) return; g_hash_table_remove (entity_table->hash, old_guid); diff --git a/src/engine/GNCId.h b/src/engine/GNCId.h index 58d742fd75..91d926ce10 100644 --- a/src/engine/GNCId.h +++ b/src/engine/GNCId.h @@ -37,7 +37,7 @@ #include "guid.h" #include "gnc-engine.h" -/* Identifiers are 'typed' with integers. The ids used in gnucash are +/* Identifiers are 'typed' with strings. The ids used in gnucash are * defined below. An id with type GNC_ID_NONE does not refer to any * entity, although that may change as new ids are created. An id with * type GNC_ID_NULL does not refer to any entity, and will never refer @@ -45,21 +45,19 @@ * actual entity, but that is not guaranteed. If an id does refer to * an entity, the type of the entity will match the type of the * identifier. */ -typedef enum -{ - GNC_ID_NONE = 0, - GNC_ID_NULL, - GNC_ID_ACCOUNT, - GNC_ID_TRANS, - GNC_ID_SPLIT, - GNC_ID_PRICE, - GNC_ID_BOOK, - GNC_ID_SESSION, - GNC_ID_SCHEDXACTION, - GNC_ID_FREQSPEC, - LAST_GNC_ID = GNC_ID_FREQSPEC -} GNCIdType; +typedef char * GNCIdType; + +#define GNC_ID_NONE NULL +#define GNC_ID_NULL "null" +#define GNC_ID_ACCOUNT "Account" +#define GNC_ID_TRANS "Trans" +#define GNC_ID_SPLIT "Split" +#define GNC_ID_PRICE "Price" +#define GNC_ID_BOOK "Book" +#define GNC_ID_SESSION "Session" +#define GNC_ID_SCHEDXACTION "SchedXaction" +#define GNC_ID_FREQSPEC "FreqSpec" /* Return the type of an identifier. */ GNCIdType xaccGUIDType (const GUID * guid, GNCBook *book); diff --git a/src/engine/Query.c b/src/engine/Query.c index d4a631ea7e..7be9e140a7 100644 --- a/src/engine/Query.c +++ b/src/engine/Query.c @@ -198,7 +198,7 @@ xaccQueryPrint(Query * q) printf ("guid sense=%d\n", qt->data.guid.sense); guid_to_string_buff (&qt->data.guid.guid, buff); printf ("\tguid=%s\n", buff); - printf ("\tid type=%d\n", qt->data.guid.id_type); + printf ("\tid type=%s\n", qt->data.guid.id_type); break; } case PR_KVP: { @@ -1431,7 +1431,7 @@ xaccQueryTermEqual (QueryTerm *qt1, QueryTerm *qt2) case PD_GUID: if (!guid_equal (&qt1->data.guid.guid, &qt2->data.guid.guid)) return FALSE; - if (qt1->data.guid.id_type != qt2->data.guid.id_type) + if (safe_strcmp (qt1->data.guid.id_type, qt2->data.guid.id_type)) return FALSE; break; @@ -2483,24 +2483,19 @@ xaccGUIDMatchPredicate(Split * s, PredicateData * pd) guid = &pd->guid.guid; - switch (pd->guid.id_type) - { - case GNC_ID_NONE: - case GNC_ID_NULL: - default: - return 0; - - case GNC_ID_ACCOUNT: - return (xaccSplitGetAccount (s) == - xaccAccountLookupEntityTable (guid, s->entity_table)); - - case GNC_ID_TRANS: + if (pd->guid.id_type == GNC_ID_NONE || + !safe_strcmp (pd->guid.id_type, GNC_ID_NULL)) + return 0; + else if (!safe_strcmp (pd->guid.id_type, GNC_ID_ACCOUNT)) + return (xaccSplitGetAccount (s) == + xaccAccountLookupEntityTable (guid, s->entity_table)); + else if (!safe_strcmp (pd->guid.id_type, GNC_ID_TRANS)) return (xaccSplitGetParent (s) == xaccTransLookupEntityTable (guid, s->entity_table)); - - case GNC_ID_SPLIT: - return s == xaccSplitLookupEntityTable (guid, s->entity_table); - } + else if (!safe_strcmp (pd->guid.id_type, GNC_ID_SPLIT)) + return s == xaccSplitLookupEntityTable (guid, s->entity_table); + else + return 0; } /******************************************************************* diff --git a/src/engine/engine-helpers.c b/src/engine/engine-helpers.c index b57f1f329e..436734c808 100644 --- a/src/engine/engine-helpers.c +++ b/src/engine/engine-helpers.c @@ -329,18 +329,6 @@ gnc_scm2sort_type (SCM sort_type_scm) return gnc_gw_enum_scm2val ("", sort_type_scm); } -static SCM -gnc_id_type2scm (GNCIdType id_type) -{ - return gnc_gw_enum_val2scm ("", id_type); -} - -static GNCIdType -gnc_scm2id_type (SCM id_type_scm) -{ - return gnc_gw_enum_scm2val ("", id_type_scm); -} - static SCM gnc_bitfield2scm (const char *typestr, int value) { @@ -857,7 +845,7 @@ gnc_queryterm2scm (QueryTerm *qt) case PD_GUID: qt_scm = gh_cons (gnc_guid2scm (qt->data.guid.guid), qt_scm); - qt_scm = gh_cons (gnc_id_type2scm (qt->data.guid.id_type), qt_scm); + qt_scm = gh_cons (gh_str02scm (qt->data.guid.id_type), qt_scm); break; case PD_KVP: @@ -1164,6 +1152,7 @@ gnc_scm2query_term_query (SCM query_term_scm) { GUID guid; GNCIdType id_type; + char *tmp; /* guid */ if (gh_null_p (query_term_scm)) @@ -1179,7 +1168,9 @@ gnc_scm2query_term_query (SCM query_term_scm) scm = gh_car (query_term_scm); query_term_scm = gh_cdr (query_term_scm); - id_type = gnc_scm2id_type (scm); + tmp = gh_scm2newstr (scm, NULL); + id_type = g_strdup (tmp); + if (tmp) free (tmp); xaccQueryAddGUIDMatch (q, &guid, id_type, QUERY_OR); } diff --git a/src/engine/gnc-associate-account.c b/src/engine/gnc-associate-account.c index 038d5cb1ed..e3cedd6d72 100644 --- a/src/engine/gnc-associate-account.c +++ b/src/engine/gnc-associate-account.c @@ -451,9 +451,10 @@ gnc_tracking_dissociate_account(Account *inc_or_expense_account) "associated-stock-account"); stock_account_guid = kvp_value_get_guid(stock_account_kvpval); - if(xaccGUIDTypeEntityTable(stock_account_guid, - inc_or_expense_account->entity_table) == - GNC_ID_NULL) + if(!safe_strcmp + (xaccGUIDTypeEntityTable(stock_account_guid, + inc_or_expense_account->entity_table), + GNC_ID_NULL)) return; category_kvpval = kvp_frame_get_slot(current_account_kvpframe, diff --git a/src/engine/gw-engine-spec.scm b/src/engine/gw-engine-spec.scm index 5c7faaaa92..c53a4e7c04 100644 --- a/src/engine/gw-engine-spec.scm +++ b/src/engine/gw-engine-spec.scm @@ -355,18 +355,6 @@ (gw:wrap-non-native-type mod ' "QueryTerm *" "const QueryTerm *") - (let ((wt (gw:wrap-enumeration mod ' - "GNCIdType" "const GNCIdType"))) - (gw:enum-add-value! wt "GNC_ID_NONE" 'gnc-id-none) - (gw:enum-add-value! wt "GNC_ID_NULL" 'gnc-id-null) - (gw:enum-add-value! wt "GNC_ID_ACCOUNT" 'gnc-id-account) - (gw:enum-add-value! wt "GNC_ID_TRANS" 'gnc-id-trans) - (gw:enum-add-value! wt "GNC_ID_SPLIT" 'gnc-id-split) - (gw:enum-add-value! wt "GNC_ID_PRICE" 'gnc-id-price) - (gw:enum-add-value! wt "GNC_ID_BOOK" 'gnc-id-book) - (gw:enum-add-value! wt "GNC_ID_SCHEDXACTION" 'gnc-id-sched-xaction) - (gw:enum-add-value! wt "GNC_ID_FREQSPEC" 'gnc-id-freq-spec)) - (let ((wt (gw:wrap-enumeration mod ' "QueryOp" "const QueryOp"))) (gw:enum-add-value! wt "QUERY_AND" 'query-and) diff --git a/src/engine/test-core/test-engine-stuff.c b/src/engine/test-core/test-engine-stuff.c index 89b6d12360..6de1f95c43 100644 --- a/src/engine/test-core/test-engine-stuff.c +++ b/src/engine/test-core/test-engine-stuff.c @@ -1250,7 +1250,7 @@ free_random_kvp_path (GSList *path) static GNCIdType get_random_id_type (void) { - return get_random_int_in_range (0, LAST_GNC_ID); + return get_random_string (); } Query * diff --git a/src/gnome/druid-stock-split.c b/src/gnome/druid-stock-split.c index 1f6de33c0c..b3921343fb 100644 --- a/src/gnome/druid-stock-split.c +++ b/src/gnome/druid-stock-split.c @@ -35,6 +35,7 @@ #include "gnc-component-manager.h" #include "gnc-currency-edit.h" #include "gnc-date-edit.h" +#include "gnc-engine-util.h" #include "gnc-exp-parser.h" #include "gnc-gui-query.h" #include "gnc-ui.h" @@ -689,7 +690,7 @@ refresh_handler (GHashTable *changes, gpointer user_data) new_account = xaccAccountLookup (&info->account, gnc_get_current_book ()); - if (id_type == GNC_ID_NULL || old_account == new_account) + if (!safe_strcmp (id_type, GNC_ID_NULL) || old_account == new_account) return; xml = glade_get_widget_tree (info->window); diff --git a/src/gnome/top-level.c b/src/gnome/top-level.c index 68070c3b41..54f756a6e6 100644 --- a/src/gnome/top-level.c +++ b/src/gnome/top-level.c @@ -202,6 +202,7 @@ gnc_html_register_url_cb (const char *location, const char *label, else if (strncmp ("guid=", location, 5) == 0) { GUID guid; + GNCIdType id_type; if (!string_to_guid (location + 5, &guid)) { @@ -209,20 +210,20 @@ gnc_html_register_url_cb (const char *location, const char *label, return FALSE; } - switch (xaccGUIDType (&guid, gnc_get_current_book ())) + id_type = xaccGUIDType (&guid, gnc_get_current_book ()); + if (id_type == GNC_ID_NONE || !safe_strcmp (id_type, GNC_ID_NULL)) { - case GNC_ID_NONE: - case GNC_ID_NULL: result->error_message = g_strdup_printf (_("No such entity: %s"), location); return FALSE; - - case GNC_ID_ACCOUNT: + } + else if (!safe_strcmp (id_type, GNC_ID_ACCOUNT)) + { account = xaccAccountLookup (&guid, gnc_get_current_book ()); reg = regWindowSimple (account); - break; - - case GNC_ID_TRANS: + } + else if (!safe_strcmp (id_type, GNC_ID_TRANS)) + { trans = xaccTransLookup (&guid, gnc_get_current_book ()); split = NULL; @@ -241,9 +242,9 @@ gnc_html_register_url_cb (const char *location, const char *label, } reg = regWindowSimple (xaccSplitGetAccount (split)); - break; - - case GNC_ID_SPLIT: + } + else if (!safe_strcmp (id_type, GNC_ID_SPLIT)) + { split = xaccSplitLookup (&guid, gnc_get_current_book ()); if (!split) { @@ -253,9 +254,9 @@ gnc_html_register_url_cb (const char *location, const char *label, } reg = regWindowSimple (xaccSplitGetAccount (split)); - break; - - default: + } + else + { result->error_message = g_strdup_printf (_("Unsupported entity type: %s"), location); return FALSE; diff --git a/src/register/ledger-core/split-register.c b/src/register/ledger-core/split-register.c index 894654edd4..4d841d8ca8 100644 --- a/src/register/ledger-core/split-register.c +++ b/src/register/ledger-core/split-register.c @@ -856,8 +856,9 @@ gnc_split_register_paste_current (SplitRegister *reg) trans_split_index = gnc_trans_split_index(trans, trans_split); if ((gnc_split_register_get_default_account (reg) != NULL) && - (xaccGUIDType(&copied_leader_guid, - gnc_get_current_book ()) != GNC_ID_NULL)) + (safe_strcmp (xaccGUIDType(&copied_leader_guid, + gnc_get_current_book ()), + GNC_ID_NULL))) { new_guid = &info->default_account; gnc_copy_trans_scm_onto_trans_swap_accounts(copied_item, trans,