30 #include <glib/gi18n.h>
32 #include "guile-mappings.h"
33 #include "guile-util.h"
34 #include "gnc-guile-utils.h"
38 #include "dialog-utils.h"
41 #include "gnc-component-manager.h"
42 #include "gnc-session.h"
46 #define DIALOG_TAX_INFO_CM_CLASS "dialog-tax-info"
47 #define GNC_PREFS_GROUP "dialogs.tax-info"
48 #define GNC_PREF_PANED_POS "paned-position"
61 SCM payer_name_source;
82 char *combo_box_entry;
88 char *payer_name_source;
99 GtkWidget * entity_name_display;
100 GtkWidget * entity_name_entry;
101 GtkWidget * entity_type_display;
102 GtkWidget * entity_type_combo;
103 GtkWidget * tax_identity_edit_button;
105 GtkWidget * acct_info;
106 GtkWidget * expense_radio;
107 GtkWidget * asset_radio;
108 GtkWidget * liab_eq_radio;
109 GtkWidget * account_treeview;
110 GtkWidget * select_button;
111 GtkWidget * num_acct_label;
113 GtkWidget * txf_info;
114 GtkWidget * tax_related_button;
115 GtkWidget * txf_vbox;
116 GtkWidget * txf_category_view;
117 GtkWidget * txf_help_text;
118 GtkWidget * help_scroll;
119 GtkWidget * payer_vbox;
120 GtkWidget * pns_vbox;
121 GtkWidget * current_account_button;
122 GtkWidget * parent_account_button;
123 GtkWidget * copy_vbox;
124 GtkWidget * copy_spin_button;
126 GList * entity_type_infos;
127 GList * income_txf_infos;
128 GList * expense_txf_infos;
129 GList * asset_txf_infos;
130 GList * liab_eq_txf_infos;
132 const gchar * tax_name;
133 const gchar * tax_type;
134 const gchar * tax_type_combo_text;
135 const gchar * default_tax_type;
140 gboolean tax_type_changed;
146 initialize_getters (
void)
148 getters.payer_name_source = scm_c_eval_string (
"gnc:txf-get-payer-name-source");
149 getters.form = scm_c_eval_string (
"gnc:txf-get-form");
150 getters.description = scm_c_eval_string (
"gnc:txf-get-description");
151 getters.help = scm_c_eval_string (
"gnc:txf-get-help");
152 getters.line_data = scm_c_eval_string (
"gnc:txf-get-line-data");
153 getters.last_year = scm_c_eval_string (
"gnc:txf-get-last-year");
154 getters.copy = scm_c_eval_string (
"gnc:txf-get-multiple");
156 getters.codes = scm_c_eval_string (
"gnc:txf-get-codes");
158 getters.tax_entity_type = scm_c_eval_string (
"gnc:txf-get-tax-entity-type");
159 getters.tax_entity_desc = scm_c_eval_string
160 (
"gnc:txf-get-tax-entity-type-description");
162 getters.tax_entity_types = scm_c_eval_string
163 (
"gnc:txf-get-tax-entity-type-codes");
167 destroy_tax_type_info (gpointer data, gpointer user_data)
171 g_free (tax_type->type_code);
172 tax_type->type_code = NULL;
174 g_free (tax_type->type);
175 tax_type->type = NULL;
177 g_free (tax_type->description);
178 tax_type->description = NULL;
180 g_free (tax_type->combo_box_entry);
181 tax_type->combo_box_entry = NULL;
187 destroy_tax_type_infos (GList *types)
189 g_list_foreach (types, destroy_tax_type_info, NULL);
194 destroy_txf_info (gpointer data, gpointer user_data)
198 g_free (txf_info->code);
199 txf_info->code = NULL;
201 g_free (txf_info->payer_name_source);
202 txf_info->payer_name_source = NULL;
204 g_free (txf_info->form);
205 txf_info->form = NULL;
207 g_free (txf_info->description);
208 txf_info->description = NULL;
210 g_free (txf_info->help);
211 txf_info->help = NULL;
217 destroy_txf_infos (GList *infos)
219 g_list_foreach (infos, destroy_txf_info, NULL);
224 gnc_tax_info_set_changed (
TaxInfoDialog *ti_dialog, gboolean changed)
226 ti_dialog->changed = changed;
237 if (ti_dialog->tax_type == NULL ||
238 (g_strcmp0 (ti_dialog->tax_type,
"") == 0))
240 destroy_txf_infos (infos);
245 tax_entity_type = scm_from_utf8_string (ti_dialog->tax_type);
248 switch (acct_category)
251 category = scm_c_eval_string (
"txf-income-categories");
254 category = scm_c_eval_string (
"txf-expense-categories");
257 category = scm_c_eval_string (
"txf-asset-categories");
260 category = scm_c_eval_string (
"txf-liab-eq-categories");
263 destroy_txf_infos (infos);
267 if (category == SCM_UNDEFINED)
269 destroy_txf_infos (infos);
273 codes = scm_call_2 (getters.codes, category, tax_entity_type);
274 if (!scm_is_list (codes))
276 destroy_txf_infos (infos);
280 while (!scm_is_null (codes))
284 const gchar *last_yr = _(
"Last Valid Year: ");
285 const gchar *form_line = _(
"Form Line Data: ");
286 const gchar *code_line_word = _(
"Code");
287 const gchar *code_line_colon =
": ";
288 const gchar *prefix =
"N";
290 gchar *num_code = NULL;
291 gchar *form_line_data = NULL;
292 gchar *help_text = NULL;
297 code_scm = SCM_CAR (codes);
298 codes = SCM_CDR (codes);
300 scm = scm_call_3 (getters.payer_name_source, category, code_scm,
302 if (scm_is_symbol(scm))
303 str = gnc_scm_symbol_to_locale_string (scm);
306 if (g_strcmp0 (str,
"not-impl") == 0)
312 txf_info = g_new0 (
TXFInfo, 1);
314 if (g_strcmp0 (str,
"none") == 0)
315 txf_info->payer_name_source = NULL;
317 txf_info->payer_name_source = g_strdup (str);
320 if (scm_is_symbol(code_scm))
321 str = gnc_scm_symbol_to_locale_string (code_scm);
324 txf_info->code = g_strdup (str);
325 if (g_str_has_prefix (str, prefix))
327 const gchar *num_code_tmp;
328 num_code_tmp = g_strdup (str);
330 num_code = g_strdup (num_code_tmp);
332 g_free ((gpointer *) num_code_tmp);
335 num_code = g_strdup (str);
338 scm = scm_call_3 (getters.form, category, code_scm, tax_entity_type);
339 if (scm_is_string(scm))
340 txf_info->form = gnc_scm_to_utf8_string(scm);
342 txf_info->form = g_strdup (
"");
344 scm = scm_call_3 (getters.description, category, code_scm, tax_entity_type);
345 if (scm_is_string(scm))
346 txf_info->description = gnc_scm_to_utf8_string(scm);
348 txf_info->description = g_strdup (
"");
350 scm = scm_call_2 (getters.help, category, code_scm);
351 if (scm_is_string(scm))
352 help_text = gnc_scm_to_utf8_string(scm);
354 help_text = g_strdup (
"");
356 scm = scm_call_3 (getters.last_year, category, code_scm, tax_entity_type);
357 year = scm_is_bool (scm) ? 0 : scm_to_int(scm);
358 scm = scm_call_3 (getters.line_data, category, code_scm, tax_entity_type);
359 if (scm_is_list (scm))
361 const gchar *now = _(
"now");
364 until = (gchar *) now;
365 form_line_data = g_strconcat (
"\n",
"\n", form_line, NULL);
366 while (!scm_is_null (scm))
374 year_scm = SCM_CAR (scm);
377 line_year = scm_is_bool (SCM_CAR (year_scm)) ? 0 :
378 scm_to_int (SCM_CAR (year_scm));
379 if (scm_is_string((SCM_CAR (SCM_CDR (year_scm)))))
380 line = gnc_scm_to_utf8_string((SCM_CAR (SCM_CDR
383 line = g_strdup (
"");
384 temp2 = g_strdup_printf (
"%d", line_year);
385 temp = g_strconcat (form_line_data,
"\n", temp2,
" - ",
386 until,
" ", line, NULL);
389 until = g_strdup_printf (
"%d", (line_year - 1));
390 g_free (form_line_data);
391 form_line_data = g_strdup (temp);
396 if (g_strcmp0 (until, now) != 0)
401 gchar *temp = g_strdup_printf(
"%d", year);
402 if (form_line_data != NULL)
403 txf_info->help = g_strconcat (last_yr, temp,
"\n",
"\n",
404 help_text,
"\n",
"\n",
406 code_line_colon, num_code,
407 form_line_data, NULL);
409 txf_info->help = g_strconcat (last_yr, temp,
"\n",
"\n",
410 help_text,
"\n",
"\n",
412 code_line_colon, num_code, NULL);
417 if (form_line_data != NULL)
418 txf_info->help = g_strconcat (help_text,
"\n",
"\n",
420 code_line_colon, num_code,
421 form_line_data, NULL);
423 txf_info->help = g_strconcat (help_text,
"\n",
"\n",
425 code_line_colon, num_code, NULL);
430 g_free (form_line_data);
432 scm = scm_call_3 (getters.copy, category, code_scm, tax_entity_type);
433 cpy = scm_is_bool (scm) ? (scm_is_false (scm) ? FALSE : TRUE) : FALSE;
434 txf_info->copy = cpy;
436 infos = g_list_prepend (infos, txf_info);
438 return g_list_reverse (infos);
446 ? ti_dialog->income_txf_infos :
448 ? ti_dialog->expense_txf_infos :
450 ? ti_dialog->asset_txf_infos :
451 ti_dialog->liab_eq_txf_infos)));
460 ti_dialog->tax_type_combo_text = NULL;
461 tax_types = scm_call_0 (getters.tax_entity_types);
462 if (!scm_is_list (tax_types))
464 destroy_tax_type_infos (types);
468 while (!scm_is_null (tax_types))
475 type_scm = SCM_CAR (tax_types);
476 tax_types = SCM_CDR (tax_types);
478 ti_dialog->default_tax_type = NULL;
482 if (scm_is_symbol(type_scm))
483 tax_type_info->type_code = gnc_scm_symbol_to_locale_string (type_scm);
485 tax_type_info->type_code = g_strdup (
"");
487 scm = scm_call_1 (getters.tax_entity_type, type_scm);
488 if (scm_is_string(scm))
489 tax_type_info->type = gnc_scm_to_utf8_string(scm);
491 tax_type_info->type = g_strdup (
"");
493 scm = scm_call_1 (getters.tax_entity_desc, type_scm);
494 if (scm_is_string(scm))
495 tax_type_info->description = gnc_scm_to_utf8_string(scm);
497 tax_type_info->description = g_strdup (
"");
499 tax_type_info->combo_box_entry = g_strconcat(tax_type_info->type,
501 tax_type_info->description, NULL);
503 if (g_strcmp0 (ti_dialog->tax_type, tax_type_info->type_code) == 0)
504 ti_dialog->tax_type_combo_text = tax_type_info->combo_box_entry;
506 ti_dialog->default_tax_type = tax_type_info->combo_box_entry;
508 types = g_list_prepend (types, tax_type_info);
510 ti_dialog->entity_type_infos = g_list_reverse (types);
521 view = GTK_TREE_VIEW(ti_dialog->txf_category_view);
522 store = GTK_LIST_STORE(gtk_tree_view_get_model(view));
524 gtk_tree_view_set_model(view, NULL);
526 gtk_list_store_clear(store);
528 codes = tax_infos (ti_dialog);
529 for ( ; codes; codes = codes->next)
531 TXFInfo *txf_info = codes->data;
533 gtk_list_store_append(store, &iter);
534 gtk_list_store_set(store, &iter,
536 1, txf_info->description,
540 gtk_tree_view_set_model(view, GTK_TREE_MODEL(store));
541 g_object_unref(store);
548 GtkTreeSelection *selection;
550 gtk_toggle_button_set_active
551 (GTK_TOGGLE_BUTTON (ti_dialog->tax_related_button), FALSE);
553 view = GTK_TREE_VIEW(ti_dialog->txf_category_view);
554 selection = gtk_tree_view_get_selection(view);
555 gtk_tree_selection_unselect_all(selection);
557 gtk_toggle_button_set_active
558 (GTK_TOGGLE_BUTTON (ti_dialog->current_account_button), TRUE);
560 gtk_spin_button_set_value
561 (GTK_SPIN_BUTTON (ti_dialog->copy_spin_button), 1);
565 gnc_tax_info_dialog_account_filter_func (
Account *account,
569 gboolean included = FALSE;
592 txf_infos_find_code (GList *infos,
const char *code)
594 for (; infos; infos = infos->next)
598 if (g_strcmp0 (code, info->code) == 0)
609 GtkTreeSelection *selection;
611 gboolean tax_related;
619 clear_gui (ti_dialog);
624 gtk_toggle_button_set_active
625 (GTK_TOGGLE_BUTTON (ti_dialog->tax_related_button), tax_related);
627 infos = tax_infos (ti_dialog);
630 info = txf_infos_find_code (infos, str);
632 index = g_list_index (infos, info);
637 view = GTK_TREE_VIEW(ti_dialog->txf_category_view);
638 selection = gtk_tree_view_get_selection(view);
639 path = gtk_tree_path_new_from_indices(index, -1);
640 gtk_tree_selection_select_path(selection, path);
641 gtk_tree_view_scroll_to_cell(view, path, NULL, FALSE, 0, 0);
642 gtk_tree_path_free(path);
645 if (g_strcmp0 (str,
"parent") == 0)
646 gtk_toggle_button_set_active
647 (GTK_TOGGLE_BUTTON (ti_dialog->parent_account_button), TRUE);
649 gtk_toggle_button_set_active
650 (GTK_TOGGLE_BUTTON (ti_dialog->current_account_button), TRUE);
652 gtk_spin_button_set_value
653 (GTK_SPIN_BUTTON (ti_dialog->copy_spin_button),
662 GtkTreeSelection *selection;
666 gboolean tax_related;
675 tax_related = gtk_toggle_button_get_active
676 (GTK_TOGGLE_BUTTON (ti_dialog->tax_related_button));
678 infos = tax_infos (ti_dialog);
680 view = GTK_TREE_VIEW(ti_dialog->txf_category_view);
681 selection = gtk_tree_view_get_selection(view);
682 if (!gtk_tree_selection_get_selected(selection, &model, &iter))
684 path = gtk_tree_model_get_path(model, &iter);
685 indices = gtk_tree_path_get_indices(path);
686 info = g_list_nth_data (infos, indices[0]);
687 gtk_tree_path_free(path);
688 g_return_if_fail (info != NULL);
690 code = tax_related ? info->code : NULL;
692 if (tax_related && info->payer_name_source)
696 current = gtk_toggle_button_get_active
697 (GTK_TOGGLE_BUTTON (ti_dialog->current_account_button));
699 pns = current ?
"current" :
"parent";
704 if (tax_related && info->copy)
706 copy_number = gtk_spin_button_get_value_as_int
707 (GTK_SPIN_BUTTON (ti_dialog->copy_spin_button));
713 (GNC_TREE_VIEW_ACCOUNT(ti_dialog->account_treeview));
715 for (node = accounts; node; node = node->next)
729 g_list_free (accounts);
733 identity_edit_destroy_cb (GtkDialog *dialog, gpointer data)
737 ti_dialog->entity_name_entry = NULL;
738 ti_dialog->entity_type_combo = NULL;
740 gtk_widget_destroy(GTK_WIDGET(dialog));
744 window_destroy_cb (GtkObject *
object, gpointer data)
748 gnc_unregister_gui_component_by_data (DIALOG_TAX_INFO_CM_CLASS, ti_dialog);
750 destroy_tax_type_infos (ti_dialog->entity_type_infos);
751 ti_dialog->entity_type_infos = NULL;
753 destroy_txf_infos (ti_dialog->income_txf_infos);
754 ti_dialog->income_txf_infos = NULL;
756 destroy_txf_infos (ti_dialog->expense_txf_infos);
757 ti_dialog->expense_txf_infos = NULL;
759 destroy_txf_infos (ti_dialog->asset_txf_infos);
760 ti_dialog->asset_txf_infos = NULL;
762 destroy_txf_infos (ti_dialog->liab_eq_txf_infos);
763 ti_dialog->liab_eq_txf_infos = NULL;
769 cursor_changed_cb (GtkWidget *widget, gpointer data)
776 account_tree = GNC_TREE_VIEW_ACCOUNT (ti_dialog->account_treeview);
780 gtk_widget_set_sensitive(ti_dialog->select_button, FALSE);
785 gtk_widget_set_sensitive(ti_dialog->select_button, num_children > 0);
789 select_subaccounts_clicked (GtkWidget *widget, gpointer data)
795 account_tree = GNC_TREE_VIEW_ACCOUNT (ti_dialog->account_treeview);
802 gtk_widget_grab_focus (ti_dialog->account_treeview);
806 gnc_tax_info_dialog_response (GtkDialog *dialog, gint response, gpointer data)
810 if (response == GTK_RESPONSE_OK && ti_dialog->changed)
811 gui_to_accounts (ti_dialog);
813 gnc_close_gui_component_by_data (DIALOG_TAX_INFO_CM_CLASS, ti_dialog);
823 tree = GNC_TREE_VIEW_ACCOUNT (ti_dialog->account_treeview);
846 info.include_type[type] = FALSE;
851 load_category_list (ti_dialog);
852 cursor_changed_cb(GTK_WIDGET(tree), ti_dialog);
859 GtkTreeSelection* selection;
864 tree = GNC_TREE_VIEW_ACCOUNT(ti_dialog->account_treeview);
865 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW(tree));
866 num_accounts = gtk_tree_selection_count_selected_rows (selection);
868 label = ti_dialog->num_acct_label;
870 string = g_strdup_printf (
"%d", num_accounts);
871 gtk_label_set_text (GTK_LABEL (label),
string);
874 gtk_widget_set_sensitive (ti_dialog->txf_info, num_accounts > 0);
880 gnc_tax_info_acct_type_cb (GtkWidget *w, gpointer data)
883 const gchar *button_name;
885 if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (w)))
887 button_name = gtk_buildable_get_name(GTK_BUILDABLE(w));
888 if (g_strcmp0 (button_name,
"income_radio") == 0)
890 else if (g_strcmp0 (button_name,
"expense_radio") == 0)
892 else if (g_strcmp0 (button_name,
"asset_radio") == 0)
894 else if (g_strcmp0 (button_name,
"liab_eq_radio") == 0)
898 tax_info_show_acct_type_accounts (ti_dialog);
900 (GNC_TREE_VIEW_ACCOUNT (ti_dialog->account_treeview));
901 gnc_tax_info_update_accounts (ti_dialog);
902 clear_gui (ti_dialog);
909 gnc_tax_info_account_changed_cb (GtkTreeSelection *selection,
917 g_return_if_fail(GTK_IS_TREE_SELECTION(selection));
919 num_accounts = gnc_tax_info_update_accounts (ti_dialog);
920 switch (num_accounts)
923 clear_gui (ti_dialog);
924 gnc_tax_info_set_changed (ti_dialog, FALSE);
930 view = GNC_TREE_VIEW_ACCOUNT(ti_dialog->account_treeview);
932 account_to_gui (ti_dialog, accounts->data);
933 g_list_free(accounts);
935 gnc_tax_info_set_changed (ti_dialog, FALSE);
939 gnc_tax_info_set_changed (ti_dialog, TRUE);
945 txf_code_select_row_cb (GtkTreeSelection *selection,
959 if (!gtk_tree_selection_get_selected(selection, &model, &iter))
961 path = gtk_tree_model_get_path(model, &iter);
962 indices = gtk_tree_path_get_indices(path);
963 txf_info = g_list_nth_data (tax_infos (ti_dialog), indices[0]);
964 gtk_tree_path_free(path);
966 tb = gtk_text_view_get_buffer(GTK_TEXT_VIEW(ti_dialog->txf_help_text));
968 text = (txf_info && txf_info->help) ? txf_info->help :
"";
969 gtk_text_buffer_set_text (tb, text, -1);
971 adj = gtk_scrolled_window_get_vadjustment (GTK_SCROLLED_WINDOW (ti_dialog->help_scroll));
972 gtk_adjustment_set_value (adj, 0.0);
974 vbox = ti_dialog->payer_vbox;
976 if (txf_info && txf_info->payer_name_source)
980 gtk_widget_set_sensitive (vbox, TRUE);
982 current = (strcmp (
"current", txf_info->payer_name_source) == 0);
985 gtk_toggle_button_set_active
986 (GTK_TOGGLE_BUTTON (ti_dialog->current_account_button), TRUE);
988 gtk_toggle_button_set_active
989 (GTK_TOGGLE_BUTTON (ti_dialog->parent_account_button), TRUE);
993 gtk_widget_set_sensitive (vbox, FALSE);
994 gtk_toggle_button_set_active
995 (GTK_TOGGLE_BUTTON (ti_dialog->current_account_button), TRUE);
998 vbox = ti_dialog->copy_vbox;
1000 if (txf_info && txf_info->copy)
1002 gtk_widget_set_sensitive (vbox, TRUE);
1006 gtk_widget_set_sensitive (vbox, FALSE);
1009 gnc_tax_info_set_changed (ti_dialog, TRUE);
1015 if ((ti_dialog->tax_type == NULL) ||
1016 (g_strcmp0 (ti_dialog->tax_type,
"Other") == 0) ||
1017 (g_strcmp0 (ti_dialog->tax_type,
"") == 0))
1019 gtk_widget_grab_focus (ti_dialog->tax_identity_edit_button);
1020 gtk_widget_set_sensitive (ti_dialog->acct_info, FALSE);
1021 gtk_widget_set_sensitive (ti_dialog->txf_info, FALSE);
1022 gtk_widget_hide (ti_dialog->txf_help_text);
1024 else if (ti_dialog->tax_type_changed)
1026 gtk_widget_set_sensitive (ti_dialog->acct_info, TRUE);
1027 gtk_widget_set_sensitive (ti_dialog->txf_info, TRUE);
1028 gtk_widget_grab_focus (ti_dialog->account_treeview);
1032 gtk_widget_set_sensitive (ti_dialog->acct_info, TRUE);
1033 gtk_widget_grab_focus (ti_dialog->account_treeview);
1035 if (ti_dialog->asset_txf_infos == NULL)
1036 gtk_widget_hide (ti_dialog->asset_radio);
1038 gtk_widget_show (ti_dialog->asset_radio);
1039 if (ti_dialog->liab_eq_txf_infos == NULL)
1040 gtk_widget_hide (ti_dialog->liab_eq_radio);
1042 gtk_widget_show (ti_dialog->liab_eq_radio);
1046 identity_edit_response_cb (GtkDialog *dialog, gint response, gpointer data)
1049 const gchar *entry_name = NULL;
1050 const gchar *entry_type = NULL;
1051 gint active_item = 0;
1054 if (response == GTK_RESPONSE_APPLY)
1056 entry_name = gtk_entry_get_text (GTK_ENTRY (ti_dialog->entity_name_entry));
1057 active_item = gtk_combo_box_get_active
1058 (GTK_COMBO_BOX (ti_dialog->entity_type_combo));
1059 if (active_item != -1)
1061 selected_type = g_list_nth_data (ti_dialog->entity_type_infos,
1062 (guint) active_item);
1065 entry_type = selected_type->type_code;
1066 if (!(g_strcmp0 (ti_dialog->tax_type, entry_type) == 0))
1068 ti_dialog->tax_type_changed = TRUE;
1069 gnc_set_current_book_tax_type (entry_type);
1070 ti_dialog->tax_type = entry_type;
1071 if (entry_type != NULL)
1073 gtk_label_set_text (GTK_LABEL (ti_dialog->entity_type_display),
1074 selected_type->combo_box_entry);
1078 gtk_label_set_text (GTK_LABEL (ti_dialog->entity_type_display),
1079 ti_dialog->default_tax_type);
1081 if (ti_dialog->income_txf_infos != NULL)
1082 destroy_txf_infos (ti_dialog->income_txf_infos);
1083 ti_dialog->income_txf_infos = load_txf_info (INCOME, ti_dialog);
1084 if (ti_dialog->expense_txf_infos != NULL)
1085 destroy_txf_infos (ti_dialog->expense_txf_infos);
1086 ti_dialog->expense_txf_infos = load_txf_info (EXPENSE, ti_dialog);
1087 if (ti_dialog->asset_txf_infos != NULL)
1088 destroy_txf_infos (ti_dialog->asset_txf_infos);
1089 ti_dialog->asset_txf_infos = load_txf_info (ASSET, ti_dialog);
1090 if (ti_dialog->liab_eq_txf_infos != NULL)
1091 destroy_txf_infos (ti_dialog->liab_eq_txf_infos);
1092 ti_dialog->liab_eq_txf_infos = load_txf_info (LIAB_EQ, ti_dialog);
1093 gtk_toggle_button_set_active
1094 (GTK_TOGGLE_BUTTON(ti_dialog->expense_radio), TRUE);
1095 tax_info_show_acct_type_accounts (ti_dialog);
1097 (GNC_TREE_VIEW_ACCOUNT (ti_dialog->account_treeview));
1098 gnc_tax_info_update_accounts (ti_dialog);
1099 clear_gui (ti_dialog);
1103 if (!(g_strcmp0 (ti_dialog->tax_name, entry_name) == 0))
1105 gnc_set_current_book_tax_name (entry_name);
1106 ti_dialog->tax_name = g_strdup (entry_name);
1107 gtk_label_set_text (GTK_LABEL (ti_dialog->entity_name_display),
1110 set_focus_sensitivity (ti_dialog);
1111 ti_dialog->tax_type_changed = FALSE;
1113 identity_edit_destroy_cb (GTK_DIALOG (dialog), ti_dialog);
1117 identity_edit_clicked_cb (GtkButton *button,
1122 GtkWidget *content_area;
1123 GtkWidget *name_entry;
1125 GtkWidget *alignment;
1127 GtkListStore *store;
1128 GList *types = NULL;
1130 gint current_item = -1;
1132 GtkCellRenderer *renderer;
1133 GtkWidget *type_combo;
1135 dialog = gtk_dialog_new_with_buttons (_(
"Income Tax Identity"),
1136 (GtkWindow *)ti_dialog->dialog,
1138 GTK_DIALOG_DESTROY_WITH_PARENT,
1140 GTK_RESPONSE_CANCEL,
1145 content_area = gtk_dialog_get_content_area (GTK_DIALOG (dialog));
1146 name_entry = gtk_entry_new();
1147 ti_dialog->entity_name_entry = name_entry;
1148 if (!(g_strcmp0 (ti_dialog->tax_name, NULL) == 0))
1149 gtk_entry_set_text (GTK_ENTRY (name_entry), ti_dialog->tax_name);
1150 label = gtk_label_new (_(
"Name"));
1151 gtk_misc_set_alignment (GTK_MISC (label), 1.00, 0.50);
1152 alignment = gtk_alignment_new(1.00, 0.50, 1.00, 0.00);
1153 gtk_alignment_set_padding (GTK_ALIGNMENT (alignment), 0, 0, 12, 0);
1154 gtk_container_add (GTK_CONTAINER (alignment), label);
1155 table = gtk_table_new (3, 2, FALSE);
1156 gtk_table_attach_defaults (GTK_TABLE (table), alignment, 0, 1, 0, 1);
1157 alignment = gtk_alignment_new(0.00, 0.50, 1.00, 0.00);
1158 gtk_alignment_set_padding (GTK_ALIGNMENT (alignment), 0, 0, 12, 0);
1159 gtk_container_add (GTK_CONTAINER (alignment), name_entry);
1160 gtk_table_attach_defaults (GTK_TABLE (table), alignment, 1, 2, 0, 1);
1161 store = gtk_list_store_new (1, G_TYPE_STRING);
1162 gtk_list_store_clear(store);
1163 types = ti_dialog->entity_type_infos;
1164 for ( ; types; types = types->next)
1168 gtk_list_store_append(store, &iter);
1169 gtk_list_store_set(store, &iter, 0, tax_type_info->combo_box_entry, -1);
1170 if (g_strcmp0 (ti_dialog->tax_type, tax_type_info->type_code) == 0)
1171 current_item = item;
1174 type_combo = gtk_combo_box_new_with_model (GTK_TREE_MODEL(store));
1175 g_object_unref(G_OBJECT (store));
1176 renderer = gtk_cell_renderer_text_new();
1177 gtk_cell_layout_pack_start(GTK_CELL_LAYOUT(type_combo), renderer, TRUE);
1178 gtk_cell_layout_set_attributes(GTK_CELL_LAYOUT(type_combo), renderer,
1180 ti_dialog->entity_type_combo = type_combo;
1181 if (ti_dialog->tax_type)
1183 gtk_combo_box_set_active (GTK_COMBO_BOX (type_combo), current_item);
1187 gtk_combo_box_set_active (GTK_COMBO_BOX (type_combo), -1);
1189 label = gtk_label_new (_(
"Type"));
1190 gtk_misc_set_alignment (GTK_MISC (label), 1.00, 0.50);
1191 alignment = gtk_alignment_new(1.00, 0.50, 1.00, 0.00);
1192 gtk_alignment_set_padding (GTK_ALIGNMENT (alignment), 0, 0, 12, 0);
1193 gtk_container_add (GTK_CONTAINER (alignment), label);
1194 gtk_table_attach_defaults (GTK_TABLE (table), alignment, 0, 1, 1, 2);
1195 alignment = gtk_alignment_new(0.00, 0.50, 1.00, 0.00);
1196 gtk_alignment_set_padding (GTK_ALIGNMENT (alignment), 0, 0, 12, 0);
1197 gtk_container_add (GTK_CONTAINER (alignment), type_combo);
1198 gtk_table_attach_defaults (GTK_TABLE (table), alignment, 1, 2, 1, 2);
1199 label = gtk_label_new (_(
"CAUTION: If you set TXF categories, and later change 'Type', you will need to manually reset those categories one at a time"));
1200 gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
1201 gtk_misc_set_alignment (GTK_MISC (label), 0.50, 0.50);
1202 alignment = gtk_alignment_new(0.50, 0.50, 1.00, 0.00);
1203 gtk_alignment_set_padding (GTK_ALIGNMENT (alignment), 6, 6, 4, 4);
1204 gtk_container_add (GTK_CONTAINER (alignment), label);
1205 gtk_table_attach_defaults (GTK_TABLE (table), alignment, 0, 2, 2, 3);
1206 gtk_container_add (GTK_CONTAINER (content_area), table);
1207 gtk_dialog_set_default_response (GTK_DIALOG (dialog), GTK_RESPONSE_APPLY);
1208 g_signal_connect (G_OBJECT (dialog),
"response",
1209 G_CALLBACK (identity_edit_response_cb), ti_dialog);
1210 g_signal_connect (G_OBJECT (dialog),
"destroy",
1211 G_CALLBACK (identity_edit_destroy_cb), ti_dialog);
1212 gtk_widget_show_all (dialog);
1216 tax_related_toggled_cb (GtkToggleButton *togglebutton,
1224 on = gtk_toggle_button_get_active (togglebutton);
1226 vbox = ti_dialog->txf_vbox;
1227 hbox = ti_dialog->pns_vbox;
1228 gtk_widget_set_sensitive (vbox, on);
1230 gtk_widget_set_sensitive (hbox, on);
1233 gtk_widget_hide (ti_dialog->txf_help_text);
1235 gtk_widget_show (ti_dialog->txf_help_text);
1237 gnc_tax_info_set_changed (ti_dialog, TRUE);
1241 current_account_toggled_cb (GtkToggleButton *togglebutton,
1246 gnc_tax_info_set_changed (ti_dialog, TRUE);
1250 copy_number_value_changed_cb (GtkSpinButton *spinbutton,
1255 gnc_tax_info_set_changed (ti_dialog, TRUE);
1259 gnc_tax_info_dialog_create (GtkWidget * parent,
TaxInfoDialog *ti_dialog)
1262 GtkBuilder *builder;
1263 GtkTreeView *tree_view;
1264 GtkTreeSelection *selection;
1267 builder = gtk_builder_new();
1268 gnc_builder_add_from_file (builder,
"dialog-tax-info.glade",
"copy_spin_adj");
1269 gnc_builder_add_from_file (builder,
"dialog-tax-info.glade",
"Tax Information Dialog");
1271 dialog = GTK_WIDGET(gtk_builder_get_object (builder,
"Tax Information Dialog"));
1272 ti_dialog->dialog = dialog;
1274 initialize_getters ();
1276 g_signal_connect (G_OBJECT (dialog),
"response",
1277 G_CALLBACK (gnc_tax_info_dialog_response), ti_dialog);
1279 g_signal_connect (G_OBJECT (dialog),
"destroy",
1280 G_CALLBACK (window_destroy_cb), ti_dialog);
1284 gtk_window_set_transient_for (GTK_WINDOW (dialog), GTK_WINDOW (parent));
1287 gtk_dialog_set_default_response (GTK_DIALOG(dialog), GTK_RESPONSE_OK);
1292 GtkWidget *edit_button;
1294 ti_dialog->this_book = gnc_get_current_book();
1295 ti_dialog->tax_name = gnc_get_current_book_tax_name();
1296 ti_dialog->tax_type = gnc_get_current_book_tax_type();
1298 label = GTK_WIDGET(gtk_builder_get_object (builder,
"entity_name"));
1299 ti_dialog->entity_name_display = label;
1300 gtk_label_set_text (GTK_LABEL (label), ti_dialog->tax_name);
1301 ti_dialog->entity_name_entry = NULL;
1303 load_tax_entity_type_list (ti_dialog);
1305 label = GTK_WIDGET(gtk_builder_get_object (builder,
"entity_type"));
1306 ti_dialog->entity_type_display = label;
1307 if (ti_dialog->tax_type != NULL)
1308 gtk_label_set_text (GTK_LABEL (label), ti_dialog->tax_type_combo_text);
1309 ti_dialog->entity_type_combo = NULL;
1311 edit_button = GTK_WIDGET(gtk_builder_get_object (builder,
"identity_edit_button"));
1312 ti_dialog->tax_identity_edit_button = edit_button;
1313 g_signal_connect (G_OBJECT (edit_button),
"clicked",
1314 G_CALLBACK (identity_edit_clicked_cb), ti_dialog);
1315 ti_dialog->tax_type_changed = FALSE;
1318 ti_dialog->income_txf_infos = load_txf_info (INCOME, ti_dialog);
1319 ti_dialog->expense_txf_infos = load_txf_info (EXPENSE, ti_dialog);
1320 ti_dialog->asset_txf_infos = load_txf_info (ASSET, ti_dialog);
1321 ti_dialog->liab_eq_txf_infos = load_txf_info (LIAB_EQ, ti_dialog);
1325 GtkListStore *store;
1326 GtkTreeViewColumn *column;
1327 GtkCellRenderer *renderer;
1331 ti_dialog->txf_info = GTK_WIDGET(gtk_builder_get_object (builder,
"tax_info_vbox"));
1332 button = GTK_WIDGET(gtk_builder_get_object (builder,
"tax_related_button"));
1333 ti_dialog->tax_related_button = button;
1335 g_signal_connect (G_OBJECT (button),
"toggled",
1336 G_CALLBACK (tax_related_toggled_cb), ti_dialog);
1338 text = GTK_WIDGET(gtk_builder_get_object (builder,
"txf_help_text"));
1339 gtk_text_view_set_wrap_mode(GTK_TEXT_VIEW(text), GTK_WRAP_WORD);
1340 ti_dialog->txf_help_text = text;
1342 tree_view = GTK_TREE_VIEW(gtk_builder_get_object (builder,
"txf_category_view"));
1343 store = gtk_list_store_new(2, G_TYPE_STRING, G_TYPE_STRING);
1344 gtk_tree_view_set_model(tree_view, GTK_TREE_MODEL(store));
1345 g_object_unref(store);
1346 renderer = gtk_cell_renderer_text_new();
1347 column = gtk_tree_view_column_new_with_attributes
1348 (_(
"Form"), renderer,
"text", 0, NULL);
1349 gtk_tree_view_append_column(tree_view, GTK_TREE_VIEW_COLUMN(column));
1350 renderer = gtk_cell_renderer_text_new();
1351 column = gtk_tree_view_column_new_with_attributes
1352 (_(
"Description"), renderer,
"text", 1, NULL);
1353 gtk_tree_view_append_column(tree_view, GTK_TREE_VIEW_COLUMN(column));
1354 ti_dialog->txf_category_view = GTK_WIDGET(tree_view);
1356 selection = gtk_tree_view_get_selection(tree_view);
1357 g_signal_connect (G_OBJECT (selection),
"changed",
1358 G_CALLBACK (txf_code_select_row_cb), ti_dialog);
1360 label = GTK_WIDGET(gtk_builder_get_object (builder,
"txf_category_label"));
1361 gtk_label_set_mnemonic_widget(GTK_LABEL(label), GTK_WIDGET(tree_view));
1363 button = GTK_WIDGET(gtk_builder_get_object (builder,
"current_account_button"));
1364 ti_dialog->current_account_button = button;
1366 button = GTK_WIDGET(gtk_builder_get_object (builder,
"parent_account_button"));
1367 ti_dialog->parent_account_button = button;
1369 ti_dialog->help_scroll = GTK_WIDGET(gtk_builder_get_object (builder,
"help_scroll"));
1370 ti_dialog->payer_vbox = GTK_WIDGET(gtk_builder_get_object (builder,
"payer_name_source_vbox"));
1371 ti_dialog->copy_vbox = GTK_WIDGET(gtk_builder_get_object (builder,
"copy_number_vbox"));
1372 ti_dialog->txf_vbox = GTK_WIDGET(gtk_builder_get_object (builder,
"txf_categories_vbox"));
1373 ti_dialog->pns_vbox = GTK_WIDGET(gtk_builder_get_object (builder,
"pns_copy_hbox"));
1375 g_signal_connect (G_OBJECT (button),
"toggled",
1376 G_CALLBACK (current_account_toggled_cb),
1379 button = GTK_WIDGET(gtk_builder_get_object (builder,
"copy_spin_button"));
1380 ti_dialog->copy_spin_button = button;
1382 g_signal_connect (G_OBJECT (button),
"value-changed",
1383 G_CALLBACK (copy_number_value_changed_cb),
1389 GtkWidget *income_radio, *expense_radio, *asset_radio,
1390 *liab_eq_radio, *box;
1392 ti_dialog->acct_info = GTK_WIDGET(gtk_builder_get_object (builder,
"acct_info_vbox"));
1393 ti_dialog->num_acct_label = GTK_WIDGET(gtk_builder_get_object (builder,
"num_accounts_label"));
1397 gnc_tax_info_dialog_account_filter_func,
1399 ti_dialog->account_treeview = GTK_WIDGET(tree_view);
1401 selection = gtk_tree_view_get_selection (tree_view);
1402 gtk_tree_selection_set_mode (selection, GTK_SELECTION_EXTENDED);
1403 g_signal_connect (G_OBJECT (selection),
"changed",
1404 G_CALLBACK (gnc_tax_info_account_changed_cb),
1407 gtk_widget_show (ti_dialog->account_treeview);
1408 box = GTK_WIDGET(gtk_builder_get_object (builder,
"account_scroll"));
1409 gtk_container_add (GTK_CONTAINER (box), ti_dialog->account_treeview);
1411 label = GTK_WIDGET(gtk_builder_get_object (builder,
"accounts_label"));
1412 gtk_label_set_mnemonic_widget(GTK_LABEL(label), GTK_WIDGET(tree_view));
1414 income_radio = GTK_WIDGET(gtk_builder_get_object (builder,
"income_radio"));
1415 expense_radio = GTK_WIDGET(gtk_builder_get_object (builder,
"expense_radio"));
1416 ti_dialog->expense_radio = expense_radio;
1417 asset_radio = GTK_WIDGET(gtk_builder_get_object (builder,
"asset_radio"));
1418 ti_dialog->asset_radio = asset_radio;
1419 liab_eq_radio = GTK_WIDGET(gtk_builder_get_object (builder,
"liab_eq_radio"));
1420 ti_dialog->liab_eq_radio = liab_eq_radio;
1422 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(expense_radio), TRUE);
1424 g_signal_connect (G_OBJECT (income_radio),
"toggled",
1425 G_CALLBACK (gnc_tax_info_acct_type_cb),
1427 g_signal_connect (G_OBJECT (expense_radio),
"toggled",
1428 G_CALLBACK (gnc_tax_info_acct_type_cb),
1430 g_signal_connect (G_OBJECT (asset_radio),
"toggled",
1431 G_CALLBACK (gnc_tax_info_acct_type_cb),
1433 g_signal_connect (G_OBJECT (liab_eq_radio),
"toggled",
1434 G_CALLBACK (gnc_tax_info_acct_type_cb),
1442 button = GTK_WIDGET(gtk_builder_get_object (builder,
"select_subaccounts_button"));
1443 ti_dialog->select_button = button;
1445 g_signal_connect (G_OBJECT (button),
"clicked",
1446 G_CALLBACK (select_subaccounts_clicked),
1448 g_signal_connect (G_OBJECT (ti_dialog->account_treeview),
"cursor_changed",
1449 G_CALLBACK (cursor_changed_cb),
1453 tax_info_show_acct_type_accounts (ti_dialog);
1454 gnc_tax_info_update_accounts (ti_dialog);
1455 clear_gui (ti_dialog);
1456 gnc_tax_info_set_changed (ti_dialog, FALSE);
1458 gnc_restore_window_size(GNC_PREFS_GROUP, GTK_WINDOW(ti_dialog->dialog));
1463 GObject *
object = gtk_builder_get_object (builder,
"paned");
1464 gnc_prefs_bind (GNC_PREFS_GROUP, GNC_PREF_PANED_POS,
object,
"position");
1466 g_object_unref (builder);
1470 close_handler (gpointer user_data)
1474 gnc_save_window_size(GNC_PREFS_GROUP, GTK_WINDOW(ti_dialog->dialog));
1475 gtk_widget_destroy (ti_dialog->dialog);
1479 refresh_handler (GHashTable *changes, gpointer user_data)
1483 gnc_tax_info_update_accounts (ti_dialog);
1494 gnc_tax_info_dialog (GtkWidget * parent)
1501 gnc_tax_info_dialog_create (parent, ti_dialog);
1503 component_id = gnc_register_gui_component (DIALOG_TAX_INFO_CM_CLASS,
1504 refresh_handler, close_handler,
1506 gnc_gui_component_set_session (component_id, gnc_get_current_session ());
1508 gnc_gui_component_watch_entity_type (component_id,
1510 QOF_EVENT_MODIFY | QOF_EVENT_DESTROY);
1512 set_focus_sensitivity (ti_dialog);
1514 gtk_widget_show (ti_dialog->dialog);
void gnc_tree_view_account_get_view_info(GncTreeViewAccount *account_view, AccountViewInfo *avi)
gint64 xaccAccountGetTaxUSCopyNumber(const Account *acc)
GList * gnc_tree_view_account_get_selected_accounts(GncTreeViewAccount *view)
Account * gnc_tree_view_account_get_cursor_account(GncTreeViewAccount *view)
utility functions for the GnuCash UI
GNCAccountType xaccAccountGetType(const Account *acc)
void xaccAccountSetTaxRelated(Account *acc, gboolean tax_related)
void gnc_tree_view_account_set_view_info(GncTreeViewAccount *account_view, AccountViewInfo *avi)
void gnc_tree_view_account_set_filter(GncTreeViewAccount *view, gnc_tree_view_account_filter_func func, gpointer data, GSourceFunc destroy)
Account handling public routines.
void gnc_tree_view_account_select_subaccounts(GncTreeViewAccount *view, Account *account)
void gnc_tree_view_account_refilter(GncTreeViewAccount *view)
void gnc_prefs_bind(const gchar *group, const gchar *pref_name, gpointer object, const gchar *property)
GtkTreeView implementation for gnucash account tree.
GtkTreeView * gnc_tree_view_account_new(gboolean show_root)
const char * xaccAccountGetTaxUSPayerNameSource(const Account *acc)
const char * xaccAccountGetTaxUSCode(const Account *acc)
gboolean xaccAccountGetTaxRelated(const Account *acc)
Generic api to store and retrieve preferences.
void xaccAccountSetTaxUSCode(Account *acc, const char *code)
void xaccAccountBeginEdit(Account *acc)
gint gnc_tree_view_account_count_children(GncTreeViewAccount *view, Account *account)
gboolean gnc_prefs_get_bool(const gchar *group, const gchar *pref_name)
void xaccAccountSetTaxUSPayerNameSource(Account *acc, const char *source)
void xaccAccountCommitEdit(Account *acc)
void xaccAccountSetTaxUSCopyNumber(Account *acc, gint64 copy_number)