diff --git a/ChangeLog b/ChangeLog index 6e9cd205df..bab07b7dda 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,11 @@ +2001-03-28 Dave Peticolas + + * src/gnome/dialog-tax-info.c: more work + + * src/guile/gnc.gwp: wrap more of pricedb api + + * src/engine/gnc-pricedb.c (gnc_pricedb_get_prices): new func + 2001-03-28 Bill Gribble * src/gnome/dialog-column-view.c: set the view dirty on edit diff --git a/src/engine/gnc-pricedb.c b/src/engine/gnc-pricedb.c index 7768e73686..f6caf1cacb 100644 --- a/src/engine/gnc-pricedb.c +++ b/src/engine/gnc-pricedb.c @@ -448,6 +448,31 @@ gnc_pricedb_lookup_latest(GNCPriceDB *db, return result; } +GList * +gnc_pricedb_get_prices(GNCPriceDB *db, + gnc_commodity *commodity, + gnc_commodity *currency) +{ + GList *price_list; + GList *result; + GList *node; + GHashTable *currency_hash; + + if(!db || !commodity || !currency) return NULL; + + currency_hash = g_hash_table_lookup(db->commodity_hash, commodity); + if(!currency_hash) return NULL; + + price_list = g_hash_table_lookup(currency_hash, currency); + if(!price_list) return NULL; + + result = g_list_copy (price_list); + for (node = result; node; node = node->next) + gnc_price_ref (node->data); + + return result; +} + GList * gnc_pricedb_lookup_at_time(GNCPriceDB *db, gnc_commodity *c, @@ -690,7 +715,7 @@ gnc_pricedb_substitute_commodity(GNCPriceDB *db, /* Semi-lame debugging code */ -static void +void gnc_price_print(GNCPrice *p, FILE *f, int indent) { gnc_commodity *commodity; @@ -728,7 +753,7 @@ gnc_price_print(GNCPrice *p, FILE *f, int indent) g_free(istr); } -void +static void gnc_price_print_stdout(GNCPrice *p, int indent) { gnc_price_print(p, stdout, indent); @@ -752,5 +777,3 @@ gnc_pricedb_print_contents(GNCPriceDB *db, FILE *f) gnc_pricedb_foreach_price(db, print_pricedb_adapter, f, FALSE); fprintf(f, "\n"); } - - diff --git a/src/engine/gnc-pricedb.h b/src/engine/gnc-pricedb.h index b7411f4202..4446e20d62 100644 --- a/src/engine/gnc-pricedb.h +++ b/src/engine/gnc-pricedb.h @@ -141,6 +141,10 @@ GNCPrice * gnc_pricedb_lookup_latest(GNCPriceDB *db, gnc_commodity *commodity, gnc_commodity *currency); +GList * gnc_pricedb_get_prices(GNCPriceDB *db, + gnc_commodity *commodity, + gnc_commodity *currency); + /* Return all prices that match the given commodity, currency, and timespec. Prices will be returned as a price_list (see above) */ GList * gnc_pricedb_lookup_at_time(GNCPriceDB *db, diff --git a/src/gnome/dialog-tax-info.c b/src/gnome/dialog-tax-info.c index a72d27c26e..7b7cc4b617 100644 --- a/src/gnome/dialog-tax-info.c +++ b/src/gnome/dialog-tax-info.c @@ -216,7 +216,7 @@ load_txf_info (gboolean income) } static GList * -gnc_tax_info_current_codes (TaxInfoDialog *ti_dialog) +tax_infos (TaxInfoDialog *ti_dialog) { return ti_dialog->income ? @@ -233,7 +233,7 @@ load_category_list (TaxInfoDialog *ti_dialog) gtk_clist_freeze (clist); gtk_clist_clear (clist); - codes = gnc_tax_info_current_codes (ti_dialog); + codes = tax_infos (ti_dialog); for ( ; codes; codes = codes->next) { @@ -259,10 +259,28 @@ clear_gui (TaxInfoDialog *ti_dialog) (GTK_TOGGLE_BUTTON (ti_dialog->current_account_button), TRUE); } +static TXFInfo * +txf_infos_find_code (GList *infos, const char *code) +{ + for (; infos; infos = infos->next) + { + TXFInfo *info = infos->data; + + if (safe_strcmp (code, info->code) == 0) + return info; + } + + return NULL; +} + static void account_to_gui (TaxInfoDialog *ti_dialog, Account *account) { gboolean tax_related; + const char *str; + TXFInfo *info; + GList *infos; + gint index; if (!account) { @@ -273,6 +291,78 @@ account_to_gui (TaxInfoDialog *ti_dialog, Account *account) tax_related = xaccAccountGetTaxRelated (account); gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (ti_dialog->tax_related_button), tax_related); + + infos = tax_infos (ti_dialog); + + str = xaccAccountGetTaxUSCode (account); + info = txf_infos_find_code (infos, str); + if (info) + index = g_list_index (infos, info); + else + index = 0; + if (index < 0) + index = 0; + + gtk_clist_select_row (GTK_CLIST (ti_dialog->txf_category_clist), index, 0); + + str = xaccAccountGetTaxUSPayerNameSource (account); + if (safe_strcmp (str, "parent") == 0) + gtk_toggle_button_set_active + (GTK_TOGGLE_BUTTON (ti_dialog->parent_account_button), TRUE); + else + gtk_toggle_button_set_active + (GTK_TOGGLE_BUTTON (ti_dialog->current_account_button), TRUE); +} + +static void +gui_to_accounts (TaxInfoDialog *ti_dialog) +{ + gboolean tax_related; + const char *code; + const char *pns; + GList *accounts; + TXFInfo *info; + GList *infos; + GList *node; + + tax_related = gtk_toggle_button_get_active + (GTK_TOGGLE_BUTTON (ti_dialog->tax_related_button)); + + infos = tax_infos (ti_dialog); + + info = g_list_nth_data + (infos, GTK_CLIST (ti_dialog->txf_category_clist)->focus_row); + g_return_if_fail (info != NULL); + + code = tax_related ? info->code : NULL; + + if (tax_related && info->payer_name_source) + { + gboolean current; + + current = gtk_toggle_button_get_active + (GTK_TOGGLE_BUTTON (ti_dialog->current_account_button)); + + pns = current ? "current" : "parent"; + } + else + pns = NULL; + + accounts = gnc_account_tree_get_current_accounts + (GNC_ACCOUNT_TREE (ti_dialog->account_tree)); + + for (node = accounts; node; node = node->next) + { + Account *account = node->data; + + xaccAccountBeginEdit (account); + + xaccAccountSetTaxRelated (account, tax_related); + xaccAccountSetTaxUSCode (account, code); + xaccAccountSetTaxUSPayerNameSource (account, pns); + + xaccAccountCommitEdit (account); + } } static void @@ -314,6 +404,9 @@ tax_info_ok_clicked (GtkWidget *widget, gpointer data) { TaxInfoDialog *ti_dialog = data; + if (ti_dialog->changed) + gui_to_accounts (ti_dialog); + gnc_close_gui_component_by_data (DIALOG_TAX_INFO_CM_CLASS, ti_dialog); } @@ -322,7 +415,8 @@ tax_info_apply_clicked (GtkWidget *widget, gpointer data) { TaxInfoDialog *ti_dialog = data; - return; + gui_to_accounts (ti_dialog); + gnc_tax_info_set_changed (ti_dialog, FALSE); } static void @@ -409,9 +503,13 @@ gnc_tax_info_select_account_cb (GNCAccountTree *tree, TaxInfoDialog *ti_dialog = data; if (gnc_tax_info_update_accounts (ti_dialog) != 1) + { + gnc_tax_info_set_changed (ti_dialog, TRUE); return; + } account_to_gui (ti_dialog, account); + gnc_tax_info_set_changed (ti_dialog, FALSE); } static void @@ -423,7 +521,11 @@ gnc_tax_info_unselect_account_cb (GNCAccountTree *tree, accounts = gnc_account_tree_get_current_accounts (tree); - gnc_tax_info_update_accounts (ti_dialog); + if (gnc_tax_info_update_accounts (ti_dialog) != 0) + return; + + clear_gui (ti_dialog); + gnc_tax_info_set_changed (ti_dialog, FALSE); } static void @@ -440,7 +542,7 @@ txf_code_select_row_cb (GtkCList *clist, const char *text; gint pos = 0; - txf_info = g_list_nth_data (gnc_tax_info_current_codes (ti_dialog), row); + txf_info = g_list_nth_data (tax_infos (ti_dialog), row); ge = GTK_EDITABLE (ti_dialog->txf_help_text); @@ -618,8 +720,8 @@ gnc_tax_info_dialog_create (GtkWidget * parent, TaxInfoDialog *ti_dialog) } gnc_tax_info_update_accounts (ti_dialog); - gnc_tax_info_set_changed (ti_dialog, FALSE); clear_gui (ti_dialog); + gnc_tax_info_set_changed (ti_dialog, FALSE); } static void diff --git a/src/gnome/glade-gnc-dialogs.c b/src/gnome/glade-gnc-dialogs.c index f086db5d36..34dc7812d5 100644 --- a/src/gnome/glade-gnc-dialogs.c +++ b/src/gnome/glade-gnc-dialogs.c @@ -5964,7 +5964,7 @@ create_Tax_Information_Dialog (void) gtk_widget_show (apply_button); GTK_WIDGET_SET_FLAGS (apply_button, GTK_CAN_DEFAULT); - gnome_dialog_append_button (GNOME_DIALOG (Tax_Information_Dialog), GNOME_STOCK_BUTTON_CANCEL); + gnome_dialog_append_button (GNOME_DIALOG (Tax_Information_Dialog), GNOME_STOCK_BUTTON_CLOSE); button75 = GTK_WIDGET (g_list_last (GNOME_DIALOG (Tax_Information_Dialog)->buttons)->data); gtk_widget_ref (button75); gtk_object_set_data_full (GTK_OBJECT (Tax_Information_Dialog), "button75", button75, @@ -6821,6 +6821,7 @@ create_Edit_Column_View_Page (void) gtk_widget_show (available_list); gtk_container_add (GTK_CONTAINER (scrolledwindow26), available_list); gtk_clist_set_column_width (GTK_CLIST (available_list), 0, 80); + gtk_clist_set_selection_mode (GTK_CLIST (available_list), GTK_SELECTION_BROWSE); gtk_clist_column_titles_show (GTK_CLIST (available_list)); label847720 = gtk_label_new (_("Available reports")); @@ -6917,6 +6918,7 @@ create_Edit_Column_View_Page (void) gtk_clist_set_column_width (GTK_CLIST (contents_list), 0, 150); gtk_clist_set_column_width (GTK_CLIST (contents_list), 1, 34); gtk_clist_set_column_width (GTK_CLIST (contents_list), 2, 25); + gtk_clist_set_selection_mode (GTK_CLIST (contents_list), GTK_SELECTION_BROWSE); gtk_clist_column_titles_show (GTK_CLIST (contents_list)); label847725 = gtk_label_new (_("Report")); diff --git a/src/gnome/gnc-dialogs.glade b/src/gnome/gnc-dialogs.glade index a30ec0162d..5405290232 100644 --- a/src/gnome/gnc-dialogs.glade +++ b/src/gnome/gnc-dialogs.glade @@ -8492,7 +8492,7 @@ words. button75 True True - GNOME_STOCK_BUTTON_CANCEL + GNOME_STOCK_BUTTON_CLOSE @@ -10054,7 +10054,7 @@ quit without making any changes. True 1 80 - GTK_SELECTION_SINGLE + GTK_SELECTION_BROWSE True GTK_SHADOW_IN @@ -10267,7 +10267,7 @@ quit without making any changes. True 3 150,34,25 - GTK_SELECTION_SINGLE + GTK_SELECTION_BROWSE True GTK_SHADOW_IN