30 #include <glib/gi18n.h> 32 #include "guile-mappings.h" 33 #include "gnc-guile-utils.h" 37 #include "dialog-utils.h" 38 #include "gnc-locale-tax.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 * income_radio;
107 GtkWidget * expense_radio;
108 GtkWidget * asset_radio;
109 GtkWidget * liab_eq_radio;
110 GtkWidget * account_treeview;
111 GtkWidget * select_button;
112 GtkWidget * num_acct_label;
113 GtkWidget * apply_button;
115 GtkWidget * txf_info;
116 GtkWidget * tax_related_button;
117 GtkWidget * txf_vbox;
118 GtkWidget * txf_category_view;
119 GtkWidget * txf_help_text;
120 GtkWidget * help_scroll;
121 GtkWidget * payer_vbox;
122 GtkWidget * pns_vbox;
123 GtkWidget * current_account_button;
124 GtkWidget * parent_account_button;
125 GtkWidget * copy_vbox;
126 GtkWidget * copy_spin_button;
128 GList * entity_type_infos;
129 GList * income_txf_infos;
130 GList * expense_txf_infos;
131 GList * asset_txf_infos;
132 GList * liab_eq_txf_infos;
134 const gchar * tax_name;
135 const gchar * tax_type;
136 const gchar * tax_type_combo_text;
137 const gchar * default_tax_type;
142 gboolean tax_type_changed;
148 initialize_getters (
void)
150 gnc_locale_tax_init();
152 getters.payer_name_source = scm_c_eval_string (
"gnc:txf-get-payer-name-source");
153 getters.form = scm_c_eval_string (
"gnc:txf-get-form");
154 getters.description = scm_c_eval_string (
"gnc:txf-get-description");
155 getters.help = scm_c_eval_string (
"gnc:txf-get-help");
156 getters.line_data = scm_c_eval_string (
"gnc:txf-get-line-data");
157 getters.last_year = scm_c_eval_string (
"gnc:txf-get-last-year");
158 getters.copy = scm_c_eval_string (
"gnc:txf-get-multiple");
160 getters.codes = scm_c_eval_string (
"gnc:txf-get-codes");
162 getters.tax_entity_type = scm_c_eval_string (
"gnc:txf-get-tax-entity-type");
163 getters.tax_entity_desc = scm_c_eval_string
164 (
"gnc:txf-get-tax-entity-type-description");
166 getters.tax_entity_types = scm_c_eval_string
167 (
"gnc:txf-get-tax-entity-type-codes");
171 destroy_tax_type_info (gpointer data)
175 g_free (tax_type->type_code);
176 tax_type->type_code = NULL;
178 g_free (tax_type->type);
179 tax_type->type = NULL;
181 g_free (tax_type->description);
182 tax_type->description = NULL;
184 g_free (tax_type->combo_box_entry);
185 tax_type->combo_box_entry = NULL;
191 destroy_tax_type_infos (GList *types)
193 g_list_free_full (types, destroy_tax_type_info);
197 destroy_txf_info (gpointer data)
201 g_free (txf_info->code);
202 txf_info->code = NULL;
204 g_free (txf_info->payer_name_source);
205 txf_info->payer_name_source = NULL;
207 g_free (txf_info->form);
208 txf_info->form = NULL;
210 g_free (txf_info->description);
211 txf_info->description = NULL;
213 g_free (txf_info->help);
214 txf_info->help = NULL;
220 destroy_txf_infos (GList *infos)
222 g_list_free_full (infos, destroy_txf_info);
226 gnc_tax_info_set_changed (
TaxInfoDialog *ti_dialog, gboolean changed)
228 ti_dialog->changed = changed;
229 gtk_widget_set_sensitive (ti_dialog->apply_button, changed);
240 if (ti_dialog->tax_type == NULL ||
241 (g_strcmp0 (ti_dialog->tax_type,
"") == 0))
243 destroy_txf_infos (infos);
248 tax_entity_type = scm_from_utf8_string (ti_dialog->tax_type);
251 switch (acct_category)
254 category = scm_c_eval_string (
"txf-income-categories");
257 category = scm_c_eval_string (
"txf-expense-categories");
260 category = scm_c_eval_string (
"txf-asset-categories");
263 category = scm_c_eval_string (
"txf-liab-eq-categories");
266 destroy_txf_infos (infos);
270 if (category == SCM_UNDEFINED)
272 destroy_txf_infos (infos);
276 codes = scm_call_2 (getters.codes, category, tax_entity_type);
277 if (!scm_is_list (codes))
279 destroy_txf_infos (infos);
283 while (!scm_is_null (codes))
287 const gchar *last_yr = _(
"Last Valid Year: ");
288 const gchar *form_line = _(
"Form Line Data: ");
290 const gchar *code_line_word = _(
"Code");
291 const gchar *code_line_colon =
": ";
292 const gchar *prefix =
"N";
294 gchar *num_code = NULL;
295 gchar *form_line_data = NULL;
296 gchar *help_text = NULL;
301 code_scm = SCM_CAR (codes);
302 codes = SCM_CDR (codes);
304 scm = scm_call_3 (getters.payer_name_source, category, code_scm,
306 if (scm_is_symbol(scm))
307 str = gnc_scm_symbol_to_locale_string (scm);
310 if (g_strcmp0 (str,
"not-impl") == 0)
316 txf_info = g_new0 (
TXFInfo, 1);
318 if (g_strcmp0 (str,
"none") == 0)
319 txf_info->payer_name_source = NULL;
321 txf_info->payer_name_source = g_strdup (str);
324 if (scm_is_symbol(code_scm))
325 str = gnc_scm_symbol_to_locale_string (code_scm);
328 txf_info->code = g_strdup (str);
329 if (g_str_has_prefix (str, prefix))
331 const gchar *num_code_tmp;
332 num_code_tmp = g_strdup (str);
334 num_code = g_strdup (num_code_tmp);
336 g_free ((gpointer *) num_code_tmp);
339 num_code = g_strdup (str);
342 scm = scm_call_3 (getters.form, category, code_scm, tax_entity_type);
343 if (scm_is_string(scm))
344 txf_info->form = gnc_scm_to_utf8_string(scm);
346 txf_info->form = g_strdup (
"");
348 scm = scm_call_3 (getters.description, category, code_scm, tax_entity_type);
349 if (scm_is_string(scm))
350 txf_info->description = gnc_scm_to_utf8_string(scm);
352 txf_info->description = g_strdup (
"");
354 scm = scm_call_2 (getters.help, category, code_scm);
355 if (scm_is_string(scm))
356 help_text = gnc_scm_to_utf8_string(scm);
358 help_text = g_strdup (
"");
360 scm = scm_call_3 (getters.last_year, category, code_scm, tax_entity_type);
361 year = scm_is_bool (scm) ? 0 : scm_to_int(scm);
362 scm = scm_call_3 (getters.line_data, category, code_scm, tax_entity_type);
363 if (scm_is_list (scm))
365 const gchar *now = _(
"now");
368 until = (gchar *) now;
369 form_line_data = g_strconcat (
"\n",
"\n", form_line, NULL);
370 while (!scm_is_null (scm))
378 year_scm = SCM_CAR (scm);
381 line_year = scm_is_bool (SCM_CAR (year_scm)) ? 0 :
382 scm_to_int (SCM_CAR (year_scm));
383 if (scm_is_string((SCM_CAR (SCM_CDR (year_scm)))))
384 line = gnc_scm_to_utf8_string((SCM_CAR (SCM_CDR
387 line = g_strdup (
"");
388 temp2 = g_strdup_printf (
"%d", line_year);
389 temp = g_strconcat (form_line_data,
"\n", temp2,
" - ",
390 ((year != 0) && (until == now))
391 ? g_strdup_printf(
"%d", year)
396 until = g_strdup_printf (
"%d", (line_year - 1));
397 g_free (form_line_data);
398 form_line_data = g_strdup (temp);
403 if (g_strcmp0 (until, now) != 0)
408 gchar *temp = g_strdup_printf(
"%d", year);
409 if (form_line_data != NULL)
410 txf_info->help = g_strconcat (last_yr, temp,
"\n",
"\n",
411 help_text,
"\n",
"\n",
413 code_line_colon, num_code,
414 form_line_data, NULL);
416 txf_info->help = g_strconcat (last_yr, temp,
"\n",
"\n",
417 help_text,
"\n",
"\n",
419 code_line_colon, num_code, NULL);
424 if (form_line_data != NULL)
425 txf_info->help = g_strconcat (help_text,
"\n",
"\n",
427 code_line_colon, num_code,
428 form_line_data, NULL);
430 txf_info->help = g_strconcat (help_text,
"\n",
"\n",
432 code_line_colon, num_code, NULL);
437 g_free (form_line_data);
439 scm = scm_call_3 (getters.copy, category, code_scm, tax_entity_type);
440 cpy = scm_is_bool (scm) ? (scm_is_false (scm) ? FALSE : TRUE) : FALSE;
441 txf_info->copy = cpy;
443 infos = g_list_prepend (infos, txf_info);
445 return g_list_reverse (infos);
453 ? ti_dialog->income_txf_infos :
455 ? ti_dialog->expense_txf_infos :
457 ? ti_dialog->asset_txf_infos :
458 ti_dialog->liab_eq_txf_infos)));
467 ti_dialog->tax_type_combo_text = NULL;
468 tax_types = scm_call_0 (getters.tax_entity_types);
469 if (!scm_is_list (tax_types))
471 destroy_tax_type_infos (types);
475 while (!scm_is_null (tax_types))
481 type_scm = SCM_CAR (tax_types);
482 tax_types = SCM_CDR (tax_types);
484 ti_dialog->default_tax_type = NULL;
488 if (scm_is_symbol(type_scm))
489 tax_type_info->type_code = gnc_scm_symbol_to_locale_string (type_scm);
491 tax_type_info->type_code = g_strdup (
"");
493 scm = scm_call_1 (getters.tax_entity_type, type_scm);
494 if (scm_is_string(scm))
495 tax_type_info->type = gnc_scm_to_utf8_string(scm);
497 tax_type_info->type = g_strdup (
"");
499 scm = scm_call_1 (getters.tax_entity_desc, type_scm);
500 if (scm_is_string(scm))
501 tax_type_info->description = gnc_scm_to_utf8_string(scm);
503 tax_type_info->description = g_strdup (
"");
505 tax_type_info->combo_box_entry = g_strconcat(tax_type_info->type,
507 tax_type_info->description, NULL);
509 if (g_strcmp0 (ti_dialog->tax_type, tax_type_info->type_code) == 0)
510 ti_dialog->tax_type_combo_text = tax_type_info->combo_box_entry;
512 ti_dialog->default_tax_type = tax_type_info->combo_box_entry;
514 types = g_list_prepend (types, tax_type_info);
516 ti_dialog->entity_type_infos = g_list_reverse (types);
527 view = GTK_TREE_VIEW(ti_dialog->txf_category_view);
528 store = GTK_LIST_STORE(gtk_tree_view_get_model(view));
530 gtk_tree_view_set_model(view, NULL);
532 gtk_list_store_clear(store);
534 codes = tax_infos (ti_dialog);
535 for ( ; codes; codes = codes->next)
537 TXFInfo *txf_info = codes->data;
539 gtk_list_store_append(store, &iter);
540 gtk_list_store_set(store, &iter,
542 1, txf_info->description,
546 gtk_tree_view_set_model(view, GTK_TREE_MODEL(store));
547 g_object_unref(store);
554 GtkTreeSelection *selection;
556 gtk_toggle_button_set_active
557 (GTK_TOGGLE_BUTTON (ti_dialog->tax_related_button), FALSE);
559 view = GTK_TREE_VIEW(ti_dialog->txf_category_view);
560 selection = gtk_tree_view_get_selection(view);
561 gtk_tree_selection_unselect_all(selection);
563 gtk_toggle_button_set_active
564 (GTK_TOGGLE_BUTTON (ti_dialog->current_account_button), TRUE);
566 gtk_spin_button_set_value
567 (GTK_SPIN_BUTTON (ti_dialog->copy_spin_button), 1);
571 gnc_tax_info_dialog_account_filter_func (
Account *account,
576 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, TRUE, 0.5, 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 (GtkWidget *
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)
772 GncTreeViewAccount *account_tree;
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)
792 GncTreeViewAccount *account_tree;
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 (ti_dialog->changed && (response == GTK_RESPONSE_APPLY || response == GTK_RESPONSE_OK))
811 gui_to_accounts (ti_dialog);
813 if (response != GTK_RESPONSE_APPLY)
814 gnc_close_gui_component_by_data (DIALOG_TAX_INFO_CM_CLASS, ti_dialog);
820 GncTreeViewAccount *tree;
821 AccountViewInfo info;
824 tree = GNC_TREE_VIEW_ACCOUNT (ti_dialog->account_treeview);
847 info.include_type[type] = FALSE;
850 info.show_hidden = TRUE;
853 load_category_list (ti_dialog);
854 cursor_changed_cb(GTK_WIDGET(tree), ti_dialog);
860 GncTreeViewAccount *tree;
861 GtkTreeSelection* selection;
866 tree = GNC_TREE_VIEW_ACCOUNT(ti_dialog->account_treeview);
867 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW(tree));
868 num_accounts = gtk_tree_selection_count_selected_rows (selection);
870 label = ti_dialog->num_acct_label;
871 string = g_strdup_printf (_(
"Accounts Selected: %d"), num_accounts);
872 gtk_label_set_text (GTK_LABEL (label),
string);
875 gtk_widget_set_sensitive (ti_dialog->txf_info, num_accounts > 0);
889 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON(ti_dialog->income_radio), TRUE);
891 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON(ti_dialog->expense_radio), TRUE);
893 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON(ti_dialog->asset_radio), TRUE);
896 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON(ti_dialog->liab_eq_radio), TRUE);
905 gnc_tax_info_acct_type_cb (GtkWidget *w, gpointer data)
908 const gchar *button_name;
910 if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (w)))
912 button_name = gtk_buildable_get_name(GTK_BUILDABLE(w));
913 if (g_strcmp0 (button_name,
"income_radio") == 0)
915 else if (g_strcmp0 (button_name,
"expense_radio") == 0)
917 else if (g_strcmp0 (button_name,
"asset_radio") == 0)
919 else if (g_strcmp0 (button_name,
"liab_eq_radio") == 0)
923 tax_info_show_acct_type_accounts (ti_dialog);
925 (GNC_TREE_VIEW_ACCOUNT (ti_dialog->account_treeview));
926 gnc_tax_info_update_accounts (ti_dialog);
927 clear_gui (ti_dialog);
934 gnc_tax_info_account_changed_cb (GtkTreeSelection *selection,
938 GncTreeViewAccount *view;
942 g_return_if_fail(GTK_IS_TREE_SELECTION(selection));
944 num_accounts = gnc_tax_info_update_accounts (ti_dialog);
945 switch (num_accounts)
948 clear_gui (ti_dialog);
949 gnc_tax_info_set_changed (ti_dialog, FALSE);
955 view = GNC_TREE_VIEW_ACCOUNT(ti_dialog->account_treeview);
957 if (accounts == NULL)
959 clear_gui (ti_dialog);
960 gnc_tax_info_set_changed (ti_dialog, FALSE);
963 account_to_gui (ti_dialog, accounts->data);
964 g_list_free (accounts);
966 gnc_tax_info_set_changed (ti_dialog, FALSE);
970 gnc_tax_info_set_changed (ti_dialog, TRUE);
976 txf_code_select_row_cb (GtkTreeSelection *selection,
990 if (!gtk_tree_selection_get_selected(selection, &model, &iter))
992 path = gtk_tree_model_get_path(model, &iter);
993 indices = gtk_tree_path_get_indices(path);
994 txf_info = g_list_nth_data (tax_infos (ti_dialog), indices[0]);
995 gtk_tree_path_free(path);
997 tb = gtk_text_view_get_buffer(GTK_TEXT_VIEW(ti_dialog->txf_help_text));
999 text = (txf_info && txf_info->help) ? txf_info->help :
"";
1000 gtk_text_buffer_set_text (tb, text, -1);
1002 adj = gtk_scrolled_window_get_vadjustment (GTK_SCROLLED_WINDOW (ti_dialog->help_scroll));
1003 gtk_adjustment_set_value (adj, 0.0);
1005 vbox = ti_dialog->payer_vbox;
1007 if (txf_info && txf_info->payer_name_source)
1011 gtk_widget_set_sensitive (vbox, TRUE);
1013 current = (strcmp (
"current", txf_info->payer_name_source) == 0);
1016 gtk_toggle_button_set_active
1017 (GTK_TOGGLE_BUTTON (ti_dialog->current_account_button), TRUE);
1019 gtk_toggle_button_set_active
1020 (GTK_TOGGLE_BUTTON (ti_dialog->parent_account_button), TRUE);
1024 gtk_widget_set_sensitive (vbox, FALSE);
1025 gtk_toggle_button_set_active
1026 (GTK_TOGGLE_BUTTON (ti_dialog->current_account_button), TRUE);
1029 vbox = ti_dialog->copy_vbox;
1031 if (txf_info && txf_info->copy)
1033 gtk_widget_set_sensitive (vbox, TRUE);
1037 gtk_widget_set_sensitive (vbox, FALSE);
1040 gnc_tax_info_set_changed (ti_dialog, TRUE);
1046 if ((ti_dialog->tax_type == NULL) ||
1047 (g_strcmp0 (ti_dialog->tax_type,
"Other") == 0) ||
1048 (g_strcmp0 (ti_dialog->tax_type,
"") == 0))
1050 gtk_widget_grab_focus (ti_dialog->tax_identity_edit_button);
1051 gtk_widget_set_sensitive (ti_dialog->acct_info, FALSE);
1052 gtk_widget_set_sensitive (ti_dialog->txf_info, FALSE);
1053 gtk_widget_hide (ti_dialog->txf_help_text);
1055 else if (ti_dialog->tax_type_changed)
1057 gtk_widget_set_sensitive (ti_dialog->acct_info, TRUE);
1058 gtk_widget_set_sensitive (ti_dialog->txf_info, TRUE);
1059 gtk_widget_grab_focus (ti_dialog->account_treeview);
1063 gtk_widget_set_sensitive (ti_dialog->acct_info, TRUE);
1064 gtk_widget_grab_focus (ti_dialog->account_treeview);
1066 if (ti_dialog->asset_txf_infos == NULL)
1067 gtk_widget_hide (ti_dialog->asset_radio);
1069 gtk_widget_show (ti_dialog->asset_radio);
1070 if (ti_dialog->liab_eq_txf_infos == NULL)
1071 gtk_widget_hide (ti_dialog->liab_eq_radio);
1073 gtk_widget_show (ti_dialog->liab_eq_radio);
1077 identity_edit_response_cb (GtkDialog *dialog, gint response, gpointer data)
1080 const gchar *entry_name = NULL;
1081 const gchar *entry_type = NULL;
1082 gboolean tax_name_changed = FALSE;
1083 gint active_item = 0;
1086 if (response == GTK_RESPONSE_APPLY)
1088 entry_name = gtk_entry_get_text (GTK_ENTRY (ti_dialog->entity_name_entry));
1089 active_item = gtk_combo_box_get_active
1090 (GTK_COMBO_BOX (ti_dialog->entity_type_combo));
1091 if (active_item != -1)
1093 selected_type = g_list_nth_data (ti_dialog->entity_type_infos,
1094 (guint) active_item);
1097 entry_type = selected_type->type_code;
1098 if (!(g_strcmp0 (ti_dialog->tax_type, entry_type) == 0))
1100 if (!((g_strcmp0 (ti_dialog->tax_type,
"") == 0) &&
1101 (g_strcmp0 (entry_type,
"Other") == 0)))
1103 ti_dialog->tax_type_changed = TRUE;
1104 ti_dialog->tax_type = entry_type;
1105 if (entry_type != NULL)
1107 gtk_label_set_text (GTK_LABEL (ti_dialog->entity_type_display),
1108 selected_type->combo_box_entry);
1112 gtk_label_set_text (GTK_LABEL (ti_dialog->entity_type_display),
1113 ti_dialog->default_tax_type);
1115 if (ti_dialog->income_txf_infos != NULL)
1116 destroy_txf_infos (ti_dialog->income_txf_infos);
1117 ti_dialog->income_txf_infos = load_txf_info (INCOME, ti_dialog);
1118 if (ti_dialog->expense_txf_infos != NULL)
1119 destroy_txf_infos (ti_dialog->expense_txf_infos);
1120 ti_dialog->expense_txf_infos = load_txf_info (EXPENSE, ti_dialog);
1121 if (ti_dialog->asset_txf_infos != NULL)
1122 destroy_txf_infos (ti_dialog->asset_txf_infos);
1123 ti_dialog->asset_txf_infos = load_txf_info (ASSET, ti_dialog);
1124 if (ti_dialog->liab_eq_txf_infos != NULL)
1125 destroy_txf_infos (ti_dialog->liab_eq_txf_infos);
1126 ti_dialog->liab_eq_txf_infos = load_txf_info (LIAB_EQ, ti_dialog);
1127 gtk_toggle_button_set_active
1128 (GTK_TOGGLE_BUTTON(ti_dialog->expense_radio), TRUE);
1129 tax_info_show_acct_type_accounts (ti_dialog);
1131 (GNC_TREE_VIEW_ACCOUNT (ti_dialog->account_treeview));
1132 gnc_tax_info_update_accounts (ti_dialog);
1133 clear_gui (ti_dialog);
1136 ti_dialog->tax_type_changed = FALSE;
1139 ti_dialog->tax_type_changed = FALSE;
1142 if (!(g_strcmp0 (ti_dialog->tax_name, entry_name) == 0))
1144 if (!(((ti_dialog->tax_name == NULL) &&
1145 (g_strcmp0 (entry_name,
"") == 0))))
1147 tax_name_changed = TRUE;
1148 ti_dialog->tax_name = g_strdup (entry_name);
1149 gtk_label_set_text (GTK_LABEL (ti_dialog->entity_name_display),
1153 tax_name_changed = FALSE;
1156 tax_name_changed = FALSE;
1157 if (tax_name_changed || ti_dialog->tax_type_changed)
1158 gnc_set_current_book_tax_name_type (tax_name_changed, entry_name,
1159 ti_dialog->tax_type_changed, entry_type);
1160 set_focus_sensitivity (ti_dialog);
1161 ti_dialog->tax_type_changed = FALSE;
1163 identity_edit_destroy_cb (GTK_DIALOG (dialog), ti_dialog);
1167 identity_edit_clicked_cb (GtkButton *button,
1172 GtkWidget *content_area;
1173 GtkWidget *name_entry;
1176 GtkListStore *store;
1177 GList *types = NULL;
1179 gint current_item = -1;
1181 GtkCellRenderer *renderer;
1182 GtkWidget *type_combo;
1184 dialog = gtk_dialog_new_with_buttons (_(
"Income Tax Identity"),
1185 (GtkWindow *)ti_dialog->dialog,
1187 GTK_DIALOG_DESTROY_WITH_PARENT,
1189 GTK_RESPONSE_CANCEL,
1194 content_area = gtk_dialog_get_content_area (GTK_DIALOG (dialog));
1195 name_entry = gtk_entry_new();
1196 ti_dialog->entity_name_entry = name_entry;
1197 if (!(g_strcmp0 (ti_dialog->tax_name, NULL) == 0))
1198 gtk_entry_set_text (GTK_ENTRY (name_entry), ti_dialog->tax_name);
1199 label = gtk_label_new (_(
"Name"));
1200 gnc_label_set_alignment (label, 1.00, 0.50);
1201 table = gtk_grid_new ();
1202 gtk_grid_set_column_spacing (GTK_GRID(
table), 12);
1203 gtk_grid_attach (GTK_GRID(
table), label, 0, 0, 1, 1);
1204 gtk_grid_attach (GTK_GRID(
table), name_entry, 1, 0, 1, 1);
1206 store = gtk_list_store_new (1, G_TYPE_STRING);
1207 gtk_list_store_clear(store);
1208 types = ti_dialog->entity_type_infos;
1209 for ( ; types; types = types->next)
1213 gtk_list_store_append(store, &iter);
1214 gtk_list_store_set(store, &iter, 0, tax_type_info->combo_box_entry, -1);
1215 if (g_strcmp0 (ti_dialog->tax_type, tax_type_info->type_code) == 0)
1216 current_item = item;
1219 type_combo = gtk_combo_box_new_with_model (GTK_TREE_MODEL(store));
1220 g_object_unref(G_OBJECT (store));
1221 renderer = gtk_cell_renderer_text_new();
1222 gtk_cell_layout_pack_start(GTK_CELL_LAYOUT(type_combo), renderer, TRUE);
1223 gtk_cell_layout_set_attributes(GTK_CELL_LAYOUT(type_combo), renderer,
1225 ti_dialog->entity_type_combo = type_combo;
1226 if (ti_dialog->tax_type)
1228 gtk_combo_box_set_active (GTK_COMBO_BOX (type_combo), current_item);
1232 gtk_combo_box_set_active (GTK_COMBO_BOX (type_combo), -1);
1234 label = gtk_label_new (_(
"Type"));
1235 gnc_label_set_alignment (label, 1.00, 0.50);
1236 gtk_grid_attach (GTK_GRID(
table), label, 0, 1, 1, 1);
1237 gtk_grid_attach (GTK_GRID(
table), type_combo, 1, 1, 1, 1);
1239 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"));
1240 gtk_label_set_max_width_chars (GTK_LABEL (label), 50);
1241 gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
1242 gnc_label_set_alignment (label, 0.50, 0.50);
1243 gtk_widget_set_margin_top (GTK_WIDGET(label), 5);
1244 gtk_grid_attach (GTK_GRID(
table), label, 0, 2, 2, 1);
1246 gtk_container_add (GTK_CONTAINER (content_area),
table);
1247 gtk_dialog_set_default_response (GTK_DIALOG (dialog), GTK_RESPONSE_APPLY);
1248 g_signal_connect (G_OBJECT (dialog),
"response",
1249 G_CALLBACK (identity_edit_response_cb), ti_dialog);
1250 g_signal_connect (G_OBJECT (dialog),
"destroy",
1251 G_CALLBACK (identity_edit_destroy_cb), ti_dialog);
1252 gtk_widget_show_all (dialog);
1256 tax_related_toggled_cb (GtkToggleButton *togglebutton,
1264 on = gtk_toggle_button_get_active (togglebutton);
1266 vbox = ti_dialog->txf_vbox;
1267 hbox = ti_dialog->pns_vbox;
1268 gtk_widget_set_sensitive (vbox, on);
1270 gtk_widget_set_sensitive (hbox, on);
1273 gtk_widget_hide (ti_dialog->txf_help_text);
1275 gtk_widget_show (ti_dialog->txf_help_text);
1277 gnc_tax_info_set_changed (ti_dialog, TRUE);
1281 current_account_toggled_cb (GtkToggleButton *togglebutton,
1286 gnc_tax_info_set_changed (ti_dialog, TRUE);
1290 copy_number_value_changed_cb (GtkSpinButton *spinbutton,
1295 gnc_tax_info_set_changed (ti_dialog, TRUE);
1299 gnc_tax_info_dialog_create (GtkWidget * parent,
TaxInfoDialog *ti_dialog)
1302 GtkBuilder *builder;
1303 GtkTreeView *tree_view;
1304 GtkTreeSelection *selection;
1307 builder = gtk_builder_new();
1308 gnc_builder_add_from_file (builder,
"dialog-tax-info.glade",
"copy_spin_adj");
1309 gnc_builder_add_from_file (builder,
"dialog-tax-info.glade",
"tax_information_dialog");
1311 dialog = GTK_WIDGET(gtk_builder_get_object (builder,
"tax_information_dialog"));
1312 ti_dialog->dialog = dialog;
1315 gtk_widget_set_name (GTK_WIDGET(dialog),
"gnc-id-tax-information");
1316 gnc_widget_style_context_add_class (GTK_WIDGET(dialog),
"gnc-class-taxes");
1318 initialize_getters ();
1320 g_signal_connect (G_OBJECT (dialog),
"response",
1321 G_CALLBACK (gnc_tax_info_dialog_response), ti_dialog);
1323 g_signal_connect (G_OBJECT (dialog),
"destroy",
1324 G_CALLBACK (window_destroy_cb), ti_dialog);
1328 gtk_window_set_transient_for (GTK_WINDOW (dialog), GTK_WINDOW (parent));
1331 gtk_dialog_set_default_response (GTK_DIALOG(dialog), GTK_RESPONSE_OK);
1336 GtkWidget *edit_button;
1338 ti_dialog->this_book = gnc_get_current_book();
1339 ti_dialog->tax_name = gnc_get_current_book_tax_name();
1340 ti_dialog->tax_type = gnc_get_current_book_tax_type();
1342 label = GTK_WIDGET(gtk_builder_get_object (builder,
"entity_name"));
1343 ti_dialog->entity_name_display = label;
1344 gtk_label_set_text (GTK_LABEL (label), ti_dialog->tax_name);
1345 ti_dialog->entity_name_entry = NULL;
1347 load_tax_entity_type_list (ti_dialog);
1349 label = GTK_WIDGET(gtk_builder_get_object (builder,
"entity_type"));
1350 ti_dialog->entity_type_display = label;
1351 if (ti_dialog->tax_type != NULL)
1352 gtk_label_set_text (GTK_LABEL (label), ti_dialog->tax_type_combo_text);
1353 ti_dialog->entity_type_combo = NULL;
1355 edit_button = GTK_WIDGET(gtk_builder_get_object (builder,
"identity_edit_button"));
1356 ti_dialog->tax_identity_edit_button = edit_button;
1357 g_signal_connect (G_OBJECT (edit_button),
"clicked",
1358 G_CALLBACK (identity_edit_clicked_cb), ti_dialog);
1359 ti_dialog->tax_type_changed = FALSE;
1362 ti_dialog->income_txf_infos = load_txf_info (INCOME, ti_dialog);
1363 ti_dialog->expense_txf_infos = load_txf_info (EXPENSE, ti_dialog);
1364 ti_dialog->asset_txf_infos = load_txf_info (ASSET, ti_dialog);
1365 ti_dialog->liab_eq_txf_infos = load_txf_info (LIAB_EQ, ti_dialog);
1369 GtkListStore *store;
1370 GtkTreeViewColumn *column;
1371 GtkCellRenderer *renderer;
1375 ti_dialog->txf_info = GTK_WIDGET(gtk_builder_get_object (builder,
"tax_info_vbox"));
1376 button = GTK_WIDGET(gtk_builder_get_object (builder,
"tax_related_button"));
1377 ti_dialog->tax_related_button = button;
1379 g_signal_connect (G_OBJECT (button),
"toggled",
1380 G_CALLBACK (tax_related_toggled_cb), ti_dialog);
1382 text = GTK_WIDGET(gtk_builder_get_object (builder,
"txf_help_text"));
1383 gtk_text_view_set_wrap_mode(GTK_TEXT_VIEW(text), GTK_WRAP_WORD);
1384 ti_dialog->txf_help_text = text;
1386 tree_view = GTK_TREE_VIEW(gtk_builder_get_object (builder,
"txf_category_view"));
1387 store = gtk_list_store_new(2, G_TYPE_STRING, G_TYPE_STRING);
1388 gtk_tree_view_set_model(tree_view, GTK_TREE_MODEL(store));
1389 g_object_unref(store);
1390 renderer = gtk_cell_renderer_text_new();
1391 column = gtk_tree_view_column_new_with_attributes
1392 (_(
"Form"), renderer,
"text", 0, NULL);
1393 gtk_tree_view_append_column(tree_view, GTK_TREE_VIEW_COLUMN(column));
1394 renderer = gtk_cell_renderer_text_new();
1395 column = gtk_tree_view_column_new_with_attributes
1396 (_(
"Description"), renderer,
"text", 1, NULL);
1397 gtk_tree_view_append_column(tree_view, GTK_TREE_VIEW_COLUMN(column));
1398 ti_dialog->txf_category_view = GTK_WIDGET(tree_view);
1400 selection = gtk_tree_view_get_selection(tree_view);
1401 g_signal_connect (G_OBJECT (selection),
"changed",
1402 G_CALLBACK (txf_code_select_row_cb), ti_dialog);
1404 label = GTK_WIDGET(gtk_builder_get_object (builder,
"txf_category_label"));
1405 gtk_label_set_mnemonic_widget(GTK_LABEL(label), GTK_WIDGET(tree_view));
1407 ti_dialog->apply_button = GTK_WIDGET(gtk_builder_get_object (builder,
"apply_button"));
1409 button = GTK_WIDGET(gtk_builder_get_object (builder,
"current_account_button"));
1410 ti_dialog->current_account_button = button;
1412 button = GTK_WIDGET(gtk_builder_get_object (builder,
"parent_account_button"));
1413 ti_dialog->parent_account_button = button;
1415 ti_dialog->help_scroll = GTK_WIDGET(gtk_builder_get_object (builder,
"help_scroll"));
1416 ti_dialog->payer_vbox = GTK_WIDGET(gtk_builder_get_object (builder,
"payer_name_source_vbox"));
1417 ti_dialog->copy_vbox = GTK_WIDGET(gtk_builder_get_object (builder,
"copy_number_vbox"));
1418 ti_dialog->txf_vbox = GTK_WIDGET(gtk_builder_get_object (builder,
"txf_categories_vbox"));
1419 ti_dialog->pns_vbox = GTK_WIDGET(gtk_builder_get_object (builder,
"pns_copy_hbox"));
1421 g_signal_connect (G_OBJECT (button),
"toggled",
1422 G_CALLBACK (current_account_toggled_cb),
1425 button = GTK_WIDGET(gtk_builder_get_object (builder,
"copy_spin_button"));
1426 ti_dialog->copy_spin_button = button;
1428 g_signal_connect (G_OBJECT (button),
"value-changed",
1429 G_CALLBACK (copy_number_value_changed_cb),
1435 GtkWidget *income_radio, *expense_radio, *asset_radio,
1436 *liab_eq_radio, *box;
1438 ti_dialog->acct_info = GTK_WIDGET(gtk_builder_get_object (builder,
"acct_info_vbox"));
1439 ti_dialog->num_acct_label = GTK_WIDGET(gtk_builder_get_object (builder,
"num_accounts_label"));
1443 gnc_tax_info_dialog_account_filter_func,
1445 ti_dialog->account_treeview = GTK_WIDGET(tree_view);
1447 selection = gtk_tree_view_get_selection (tree_view);
1448 gtk_tree_selection_set_mode (selection, GTK_SELECTION_MULTIPLE);
1449 g_signal_connect (G_OBJECT (selection),
"changed",
1450 G_CALLBACK (gnc_tax_info_account_changed_cb),
1453 gtk_widget_show (ti_dialog->account_treeview);
1454 box = GTK_WIDGET(gtk_builder_get_object (builder,
"account_scroll"));
1455 gtk_container_add (GTK_CONTAINER (box), ti_dialog->account_treeview);
1457 label = GTK_WIDGET(gtk_builder_get_object (builder,
"accounts_label"));
1458 gtk_label_set_mnemonic_widget(GTK_LABEL(label), GTK_WIDGET(tree_view));
1460 income_radio = GTK_WIDGET(gtk_builder_get_object (builder,
"income_radio"));
1461 ti_dialog->income_radio = income_radio;
1462 expense_radio = GTK_WIDGET(gtk_builder_get_object (builder,
"expense_radio"));
1463 ti_dialog->expense_radio = expense_radio;
1464 asset_radio = GTK_WIDGET(gtk_builder_get_object (builder,
"asset_radio"));
1465 ti_dialog->asset_radio = asset_radio;
1466 liab_eq_radio = GTK_WIDGET(gtk_builder_get_object (builder,
"liab_eq_radio"));
1467 ti_dialog->liab_eq_radio = liab_eq_radio;
1469 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(expense_radio), TRUE);
1471 g_signal_connect (G_OBJECT (income_radio),
"toggled",
1472 G_CALLBACK (gnc_tax_info_acct_type_cb),
1474 g_signal_connect (G_OBJECT (expense_radio),
"toggled",
1475 G_CALLBACK (gnc_tax_info_acct_type_cb),
1477 g_signal_connect (G_OBJECT (asset_radio),
"toggled",
1478 G_CALLBACK (gnc_tax_info_acct_type_cb),
1480 g_signal_connect (G_OBJECT (liab_eq_radio),
"toggled",
1481 G_CALLBACK (gnc_tax_info_acct_type_cb),
1489 button = GTK_WIDGET(gtk_builder_get_object (builder,
"select_subaccounts_button"));
1490 ti_dialog->select_button = button;
1492 g_signal_connect (G_OBJECT (button),
"clicked",
1493 G_CALLBACK (select_subaccounts_clicked),
1495 g_signal_connect (G_OBJECT (ti_dialog->account_treeview),
"cursor_changed",
1496 G_CALLBACK (cursor_changed_cb),
1500 tax_info_show_acct_type_accounts (ti_dialog);
1501 gnc_tax_info_update_accounts (ti_dialog);
1502 clear_gui (ti_dialog);
1503 gnc_tax_info_set_changed (ti_dialog, FALSE);
1505 gnc_restore_window_size(GNC_PREFS_GROUP,
1506 GTK_WINDOW(ti_dialog->dialog), GTK_WINDOW (parent));
1511 GObject *
object = gtk_builder_get_object (builder,
"paned");
1512 gnc_prefs_bind (GNC_PREFS_GROUP, GNC_PREF_PANED_POS,
object,
"position");
1514 g_object_unref (builder);
1518 close_handler (gpointer user_data)
1522 gnc_save_window_size(GNC_PREFS_GROUP, GTK_WINDOW(ti_dialog->dialog));
1523 gtk_widget_destroy (ti_dialog->dialog);
1527 refresh_handler (GHashTable *changes, gpointer user_data)
1531 gnc_tax_info_update_accounts (ti_dialog);
1542 gnc_tax_info_dialog (GtkWidget * parent,
Account * account)
1549 gnc_tax_info_dialog_create (parent, ti_dialog);
1552 gnc_tax_info_set_acct (ti_dialog, account);
1554 component_id = gnc_register_gui_component (DIALOG_TAX_INFO_CM_CLASS,
1555 refresh_handler, close_handler,
1557 gnc_gui_component_set_session (component_id, gnc_get_current_session ());
1559 gnc_gui_component_watch_entity_type (component_id,
1561 QOF_EVENT_MODIFY | QOF_EVENT_DESTROY);
1563 set_focus_sensitivity (ti_dialog);
1565 gtk_widget_show (ti_dialog->dialog);
void gnc_tree_view_account_get_view_info(GncTreeViewAccount *view, AccountViewInfo *avi)
Given pointers to an account tree and old style filter block, this function will copy the current con...
GNCAccountType xaccAccountTypeGetFundamental(GNCAccountType t)
Convenience function to return the fundamental type asset/liability/income/expense/equity given an ac...
gint64 xaccAccountGetTaxUSCopyNumber(const Account *acc)
Returns copy_number stored in KVP; if KVP doesn't exist or copy_number is zero, returns 1...
GList * gnc_tree_view_account_get_selected_accounts(GncTreeViewAccount *view)
This function returns a list of the accounts associated with the selected items in the account tree v...
Account * gnc_tree_view_account_get_cursor_account(GncTreeViewAccount *view)
This function returns the account in the account tree view at the current location of the cursor...
utility functions for the GnuCash UI
Expense accounts are used to denote expenses.
GNCAccountType xaccAccountGetType(const Account *acc)
Returns the account's account type.
void xaccAccountSetTaxRelated(Account *acc, gboolean tax_related)
DOCUMENT ME!
Mutual Fund accounts will typically be shown in registers which show three columns: price...
stop here; the following types just aren't ready for prime time
void gnc_tree_view_account_set_view_info(GncTreeViewAccount *view, AccountViewInfo *avi)
Given pointers to an account tree and old style filter block, this function will applies the settings...
The cash account type is used to denote a shoe-box or pillowcase stuffed with * cash.
Stock accounts will typically be shown in registers which show three columns: price, number of shares, and value.
void gnc_tree_view_account_set_filter(GncTreeViewAccount *view, gnc_tree_view_account_filter_func func, gpointer data, GSourceFunc destroy)
This function attaches a filter function to the given account tree.
Account handling public routines.
void gnc_tree_view_account_select_subaccounts(GncTreeViewAccount *view, Account *account)
This function selects all sub-accounts of an account in the account tree view.
void gnc_tree_view_account_refilter(GncTreeViewAccount *view)
This function forces the account tree filter to be evaluated.
void gnc_prefs_bind(const gchar *group, const gchar *pref_name, gpointer object, const gchar *property)
Bind a setting to a g_object property.
GtkTreeView implementation for gnucash account tree.
Income accounts are used to denote income.
GtkTreeView * gnc_tree_view_account_new(gboolean show_root)
Create a new account tree view.
const char * xaccAccountGetTaxUSPayerNameSource(const Account *acc)
DOCUMENT ME!
The bank account type denotes a savings or checking account held at a bank.
const char * xaccAccountGetTaxUSCode(const Account *acc)
DOCUMENT ME!
gboolean xaccAccountGetTaxRelated(const Account *acc)
DOCUMENT ME!
asset (and liability) accounts indicate generic, generalized accounts that are none of the above...
GNCAccountType
The account types are used to determine how the transaction data in the account is displayed...
Generic api to store and retrieve preferences.
void xaccAccountSetTaxUSCode(Account *acc, const char *code)
DOCUMENT ME!
void gnc_tree_view_account_set_selected_account(GncTreeViewAccount *view, Account *account)
This function selects an account in the account tree view.
liability (and asset) accounts indicate generic, generalized accounts that are none of the above...
void xaccAccountBeginEdit(Account *acc)
The xaccAccountBeginEdit() subroutine is the first phase of a two-phase-commit wrapper for account up...
gint gnc_tree_view_account_count_children(GncTreeViewAccount *view, Account *account)
This function determines if an account in the account tree view has any visible children.
gboolean gnc_prefs_get_bool(const gchar *group, const gchar *pref_name)
Get a boolean value from the preferences backend.
void xaccAccountSetTaxUSPayerNameSource(Account *acc, const char *source)
DOCUMENT ME!
Equity account is used to balance the balance sheet.
void xaccAccountCommitEdit(Account *acc)
ThexaccAccountCommitEdit() subroutine is the second phase of a two-phase-commit wrapper for account u...
The Credit card account is used to denote credit (e.g.
void xaccAccountSetTaxUSCopyNumber(Account *acc, gint64 copy_number)
Saves copy_number in KVP if it is greater than 1; if copy_number is zero, deletes KVP...